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

vkBindImageMemory validation error when exporting an Android HardwareBuffer #2004

Closed
liaxim opened this issue Jul 8, 2020 · 8 comments · Fixed by #2014
Closed

vkBindImageMemory validation error when exporting an Android HardwareBuffer #2004

liaxim opened this issue Jul 8, 2020 · 8 comments · Fixed by #2014
Milestone

Comments

@liaxim
Copy link

liaxim commented Jul 8, 2020

Passing VkExportMemoryAllocateInfo and handleType VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID to vkAllocateMemory.

The subsequent vkBindImageMemory call produces this error:

[16:51:42.826][Error  ] ERROR: (DEVICE_MEMORY 0xd) [Validation]  [ VUID-vkBindImageMemory-memoryOffset-01046 ]
Object: 0xd (Type = 8) | In vkBindImageMemory(), attempting to bind VkDeviceMemory 0xd[] to VkImage 0xc[],
memoryOffset=0x0 must be less than the memory allocation size 0x0. The Vulkan spec states: memoryOffset must be less than
the size of memory (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkBindImageMemory-memoryOffset-01046)

If VkMemoryAllocateInfo.allocationSize is set to anything other than 0 the previous error goes away but then this one pops up:

[17:10:42.288][Error  ] ERROR: (DEVICE 0x6f9798b9c0) [Validation]  [ VUID-VkMemoryAllocateInfo-pNext-01874 ] Object:
0x6f9798b9c0 (Type = 3) | vkAllocateMemory: pNext chain indicates a dedicated Android Hardware Buffer export allocation, but
allocationSize is non-zero. The Vulkan spec states: If the parameters do not define an import operation, and the pNext chain
contains an instance of VkExportMemoryAllocateInfo with
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID included in its handleTypes
member, and the pNext contains an instance of VkMemoryDedicatedAllocateInfo with image not equal to VK_NULL_HANDLE, then allocationSize must be 0, otherwise allocationSize must be greater than 0. (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkMemoryAllocateInfo-pNext-01874)
@sfricke-samsung
Copy link
Contributor

Just confirming, what version of the Validation Layers you are using? There has been some recent fixes to AHB and want to make sure you aren't using an older version where this might have been fixed

@liaxim
Copy link
Author

liaxim commented Jul 8, 2020

How to determine the version?

I am using whatever NDK 21.0.6113669 includes. I don't see any version info in the logs.

I believe this is what the NDK includes https://android.googlesource.com/platform/external/vulkan-validation-layers/+/691254d74159549cf5ef8d2a69bb02c062b28a0c.

@sfricke-samsung
Copy link
Contributor

NDK 21.0.6113669 is good enough, something I could look up, but those are not as up to date (to my knowledge without looking) as https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/tag/sdk-1.2.141.0 (or Top of tree), but idk if VUID-vkBindImageMemory-memoryOffset-01046 was fixed since then or not

Also just as a sanity check, if you are trying to create an VkImage to export to an AHB your code should look roughly like

VkExternalMemoryImageCreateInfo external_memory_info = {};
external_memory_info.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;

VkImageCreateInfo image_Info = {};
image_Info.pNext = &external_memory_info;
// ...
vkCreateImage(device, &image_Info, nullptr, &myImage));

VkMemoryDedicatedAllocateInfo dedicated_info = {};
dedicated_info.image                         = myImage;

VkExportMemoryAllocateInfo export_info = {};
export_info.pNext                      = &dedicated_info;
export_info.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;

VkMemoryAllocateInfo allocate_info = {}
// "When allocating new memory for an image that can be exported to an Android hardware buffer, the memory allocationSize must be zero":
memoryAllocateInfo.allocationSize = 0;
memoryAllocateInfo.pNext          = &export_info;
vkAllocateMemory(device, &allocate_info, nullptr, &myMemory));

vkBindImageMemory(device, myImage, myMemory, 0));

Sorry for thinking out loud, but we don't have a Positive Test to check ... when I find time later today, I will write some AHB positive test to confirm this case as you might have found a bug with how 01046 is checked for exported images

@liaxim
Copy link
Author

liaxim commented Jul 8, 2020

I am missing the VkExternalMemoryImageCreateInfo part. Will try that and also top-of-the-tree validation layer. Thank you.

@liaxim
Copy link
Author

liaxim commented Jul 8, 2020

We added the following but still the same validation error:

            VkExternalFormatANDROID externalFormat{VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID};
            externalFormat.externalFormat = 0;
            VkExternalMemoryImageCreateInfo externalMemoryImageCreateInfo{
                    VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO};
            externalMemoryImageCreateInfo.pNext = &externalFormat;
            externalMemoryImageCreateInfo.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;

@liaxim
Copy link
Author

liaxim commented Jul 8, 2020

Built the validation layer off master and still getting it.

@sfricke-samsung
Copy link
Contributor

Ok, for now, assume its a false positive from the Validation Layers, I will take on looking into this more

@sfricke-samsung
Copy link
Contributor

So wrote two positive tests for exporting AHB, indeed hit same error with 01046!

I added simple patch to fix it and will get PR soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants