-1

When attempting to allocate memory using VulkanMemoryAllocator, I receive an access violation on line 14781 of vk_mem_alloc.h. The error happens when the code reaches the vkGetBufferMemoryRequirements2KHR function, and when I attempt to add it outside of VulkanMemoryAllocator, I receive a linker error. I am using Vulkan Version 1.3, and from my understanding, I shouldn't need any extensions to use this function.

Here is my implementation of the code that is causing the access violation:

void VmaAllocator_T::GetBufferMemoryRequirements(
    VkBuffer hBuffer,
    VkMemoryRequirements& memReq,
    bool& requiresDedicatedAllocation,
    bool& prefersDedicatedAllocation) const
{
#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
    if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
    {
        VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR };
        memReqInfo.buffer = hBuffer;

        VkMemoryDedicatedRequirementsKHR memDedicatedReq = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR };

        VkMemoryRequirements2KHR memReq2 = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR };
        VmaPnextChainPushFront(&memReq2, &memDedicatedReq);
       
        (*m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2);
        //Access violation here:
        memReq = memReq2.memoryRequirements;
        
        requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
        prefersDedicatedAllocation  = (memDedicatedReq.prefersDedicatedAllocation  != VK_FALSE);
    }
    else
#endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
    {
        (*m_VulkanFunctions.vkGetBufferMemoryRequirements)(m_hDevice, hBuffer, &memReq);
        requiresDedicatedAllocation = false;
        prefersDedicatedAllocation  = false;
    }
oli2
  • 73
  • 1
  • 7
  • Don't "suspect", just find out. Getting debugging details of a crash is trivial. Especially if it is header-only library. – krOoze Jun 17 '23 at 14:55
  • I have the call stack, and I know that in the struct that the vkGetBufferMemoryRequirements2KHR function is supposed to fill in, it is filled with zeros in the size, alignment, and memorytypebits. Also, before the function is called, it is completely possible to read values from the memReq2 struct, however after it is called, reading values from this struct will result in an access violation. – oli2 Jun 17 '23 at 15:09
  • There is nothing noteworthy at the line you point out. That could only result in a crash if you passed the function some evil broken reference, which should not happen under ordinary circumstances. – krOoze Jun 17 '23 at 20:43
  • That's why I'm asking this question. I'm not passing this function an evil broken reference, so I'm trying to figure out what has gone wrong with my program. If I run `memReq = memReq2.memoryRequirements;` above `(*m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR)(m_hDevice, &memReqInfo, &memReq2);`, it works just fine, but once I pass it through that function, it breaks and results in an access violation, instead of filling in the struct. – oli2 Jun 17 '23 at 21:26
  • There's not much I can think of that could cause a crash on basic read of local stack variable. Only thing I can come up with is if the `memReq` reference is `nullptr` or otherwise dead, which takes some effort to achieve. I find it somewhat more likely this is not the offending line. Anyway, no point aimlessly scratching our heads. You could try `VK_LAYER_LUNARG_api_dump` so we can unambiguously see the concrete values we are dealing with here. You should also check in the debugger if the `m_VulkanFunctions` and `.vkGetBufferMemoryRequirements2KHR` are non-null variables in the first place. – krOoze Jun 17 '23 at 21:53
  • Additionally `vkGetBufferMemoryRequirements2KHR` requires `VK_KHR_get_memory_requirements2`. And `VkMemoryDedicatedRequirementsKHR` requires a `VK_KHR_dedicated_allocation` or 1.1. VMA docs should probably instruct you to do something on this matter if they use those. – krOoze Jun 17 '23 at 22:02
  • I seem to have fixed it by telling VMA that my vulkan version is 1.0, which makes it downgrade to only the functions that Vulkan 1.0 has available. The extensions that you mentioned should've been promoted to vulkan 1.1, so I should have no problem using them, but when I put a function like vkGetBufferMemoryRequirements2KHR in visual studio, it tells me it exists in vulkan.h, but it throws a linker error when I link against vulkan-1.dll. If you have any ideas I'd like to hear them, but otherwise I'm fine with telling VMA I have a lower vulkan version. – oli2 Jun 18 '23 at 12:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254129/discussion-between-oli2-and-krooze). – oli2 Jun 18 '23 at 14:13

1 Answers1

0

After multiple days of looking at my source and trying to figure out why this didn’t work, I finally figured it out. There was a problem in my VkApplicationInfo struct, which is used to create the Vulkan instance. In the engine version parameter of the struct, I put VK_VERSION_1_3. It should’ve been VK_API_VERSION_1_3.

oli2
  • 73
  • 1
  • 7