GPUOpen-LibrariesAndSDKs / VulkanMemoryAllocator

Easy to integrate Vulkan memory allocation library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vmafindMemoryTypeIndexForImageInfo not working when selecting Vulkan 1.2

lobneroO opened this issue · comments

I tried to use vmaFindMemoryTypeIndexForImageInfo:

// create an example image creation struct to get the correct memory type for the pool
VkImageCreateInfo exampleImgInfo{};
exampleImgInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
exampleImgInfo.imageType = VK_IMAGE_TYPE_2D;
exampleImgInfo.format = VK_FORMAT_R32G32B32A32_SFLOAT;
exampleImgInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
exampleImgInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
exampleImgInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
exampleImgInfo.samples = VK_SAMPLE_COUNT_1_BIT;
exampleImgInfo.flags = 0;
exampleImgInfo.mipLevels = 1;
exampleImgInfo.arrayLayers = 1;
exampleImgInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
exampleImgInfo.queueFamilyIndexCount = 1;
exampleImgInfo.pQueueFamilyIndices = &QfIndices.GraphicsFamily.value();
exampleImgInfo.extent = VkExtent3D(1, 1, 1);

// allocation for the example image 
VmaAllocationCreateInfo allocCreateInfo = {};
allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;

uint32_t memTypeIndex;
vmaFindMemoryTypeIndexForImageInfo(Device->MemoryAllocator, &exampleImgInfo, &allocCreateInfo, &memTypeIndex);

It would always crash when executing the vma function due to a nullptr access at vkGetDeviceImageMemoryRequirements.

I am using Volk for function loading and had Vulkan 1.2 set for the instance, Win 11 NVidia RTX 3080 ti, Driver 546.01.
I then went on to try and load the function myself (although I am not quite sure that would have worked, since it was still in the project using Volk).
Nothing worked, until I bumped up my Instance to use Vulkan 1.3 - after that it worked flawlessly.

Looking at the vmaFindMemoryTypeIndexForImageInfo function it just checks the Vulkan version with an #if, but otherwise checks the function is set. While I would have expected that function check to work, apperantly the actual Vulkan version in use has to be checked as well?
When I forced the else branch, which creates the dummy image, it also worked without a crash.

You have to load maintenance4 extension to get vkGetDeviceImageMemoryRequirementsKHR extension, but I don't see the VMA code falling back to that function pointer. And we're having crashes on Android 1.3 with VMA's assumption that vkGetDeviceBufferMemoryRequirements (and Image) exist. See my post here about AMD RDNA2 on Android crashing, but that call is supposed to be present.

#397

Likely the same problem as #397.