Skip to content

Fix: Out-of-boounds memory type index allocation for discrete GPUs#84

Merged
SpinnerX merged 2 commits into
mainfrom
fix_memory_bits
Jun 9, 2026
Merged

Fix: Out-of-boounds memory type index allocation for discrete GPUs#84
SpinnerX merged 2 commits into
mainfrom
fix_memory_bits

Conversation

@SpinnerX

@SpinnerX SpinnerX commented Jun 9, 2026

Copy link
Copy Markdown
Member

Issue Overview

The way vulkan-cpp allows for specifying for memory allocations is managed by the vk::physical_device to retrieve the bit masks of the available memory properties. The physical device to determine the capabilities themask to determine where resources should live in.

On integrated physical device types, these masks overlap. Whereas on discrete physical device types have a varied different memory type and heap configurations.

Which caused cases where the buffers memory requirements and the requested device property mask had no common bits.

  • Resulting in the bitmasking to be 0.
  • Passing 0 to std::countr_zero caused to return 32.
  • Passing an invalid index type of 32 to the Vulkan vkAllocateMemory APIs.

Fixes

To fix this, I added a fallback to handle such edge case for specifying std::countr_zero and passing in the memoryTypeBits provided by the buffer memory requirements.

The fallback will evaluate the supported memory indexes and choose the first bit that represents the available supported memory index for allocation for the specific device type.

@SpinnerX SpinnerX added the bug Something isn't working label Jun 9, 2026

@SpinnerX SpinnerX left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this PR.

@SpinnerX SpinnerX merged commit 36fab78 into main Jun 9, 2026
5 checks passed
@SpinnerX SpinnerX deleted the fix_memory_bits branch June 9, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant