Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vkGetBufferMemoryRequirements2KHR crash #1216

Closed
f32by opened this issue Jan 25, 2021 · 7 comments
Closed

vkGetBufferMemoryRequirements2KHR crash #1216

f32by opened this issue Jan 25, 2021 · 7 comments
Labels
SDK Issue Please re-submit to SDK

Comments

@f32by
Copy link
Collaborator

f32by commented Jan 25, 2021

I'm using Vulkan Memory Allocator and the program crashes when calling vkGetBufferMemoryRequirements2KHR(https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/blob/master/src/vk_mem_alloc.h#L16489).

Following code is taken from VMA with some modifications:

VkBuffer hBuffer;

VkBufferCreateInfo creator = {
      .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
      .size = 256,
      .usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
      .sharingMode = VK_SHARING_MODE_EXCLUSIVE
  };

// success
vkCreateBuffer(m_hDevice, &creator, nullptr, &buffer);

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);

// crash
vkGetBufferMemoryRequirements2KHR(m_hDevice, &memReqInfo, &memReq2);

I'm using a MacBook Pro 16-inch 2019 and the program is linked against MoltenVK statically.

@billhollings
Copy link
Contributor

billhollings commented Feb 2, 2021

After modifying your code to the code below, to replace VmaPnextChainPushFront, and then adding it to cube.c in the Cube Demo in MoltenVK, I do not encounter a crash.

What is the nature of the crash? Can you provide a stack call trace?

	VkBuffer hBuffer;

	VkBufferCreateInfo creator = {
		.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
		.size = 256,
		.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
		.sharingMode = VK_SHARING_MODE_EXCLUSIVE
	};

	// success
	vkCreateBuffer(demo->device, &creator, NULL, &hBuffer);

	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);
	memReq2.pNext = &memDedicatedReq;

	// crash
	vkGetBufferMemoryRequirements2KHR(demo->device, &memReqInfo, &memReq2);

@f32by
Copy link
Collaborator Author

f32by commented Feb 3, 2021

On my Mac the created hBuffer is 0x0000290000000029 which is an invalid address and the program crashes when casting pInfo->buffer to MVKBuffer.

@billhollings
Copy link
Contributor

Can you provide some further context?

Is that crash report a result of running my code above? Or your code above, which doesn't set hBuffer before using it in VkBufferMemoryRequirementsInfo2KHR. Or VMA?

Specifically, is the pInfo->buffer value assigned directly from what is returned from vkCreateBuffer()? In other words...is the value returned from vkCreateBuffer() that same bad 0x0000290000000029 pointer?

@billhollings
Copy link
Contributor

And just to be certain, when you say you link against MoltenVK statically, are you linking directly to MoltenVK, or through the Vulkan SDK?

@f32by
Copy link
Collaborator Author

f32by commented Feb 3, 2021

It's linked through the Vulkan SDK.
vkCreateBuffer() returns 0x0000290000000029.

I tried the latest Vulkan SDK(MoltenVK version 1.1.2. Vulkan version 1.1.162) and it still crashes.

@billhollings
Copy link
Contributor

Okay. It's likely an SDK issue then.

Each layer in the SDK has different Vulkan handle types, so that 0x0000290000000029 handle is probably arising in one of the layers. It needs to be submitted back to that same layer for interpretation. It's possible that somewhere in the mix of VMA and SDK, the object is being submitted to the wrong layer and ending up coming into MoltenVK incorrectly.

Can you post a link to this issue in the Vulkan SDK issue list, please, so they can have a look?

BTW...Vulkan SDK 1.2.162 should be using MoltenVK 1.1.1, not 1.1.2.

@billhollings billhollings added SDK Issue Please re-submit to SDK and removed Requested more info labels Feb 3, 2021
@f32by
Copy link
Collaborator Author

f32by commented Mar 9, 2021

Hi, finally I found this is 100% my mistake. I linked against both MoltenVK and the official Vulkan SDK. Now the problem is solved. Thank you for your help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK Issue Please re-submit to SDK
Projects
None yet
Development

No branches or pull requests

2 participants