KhronosGroup / Vulkan-ValidationLayers

Vulkan Validation Layers (VVL)
https://vulkan.lunarg.com/doc/sdk/latest/linux/khronos_validation_layer.html
Other
727 stars 396 forks source link

Descriptor buffers size issues #8203

Open Agrael1 opened 2 weeks ago

Agrael1 commented 2 weeks ago

Hi, I have reverted to using bytes for descriptor tables.

However there is a validation problem. If I bind and set offset 0 for a simple layout it starts making noisy messages in validation.

The offsets in pOffsets must be small enough such that any descriptor binding referenced by layout without the VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT flag computes a valid address inside the underlying VkBuffer

But if I change the size of the buffer to 256, the error goes away. I am using a huge buffer for bindless and bindful tests, so I may or may not be able to query the size of the descriptor layout. The layout itself does not exceed a single uniform binding, so allocating a buffer for 1 uniform should be enough. May this be a rule, that I missed, or is it a validation false positive?

spencer-lunarg commented 1 week ago

@Agrael1 so this would be for VUID-VkSetDescriptorBufferOffsetsInfoEXT-pOffsets-08063/VUID-vkCmdSetDescriptorBufferOffsetsEXT-pOffsets-08063

Can you print the entire Validation error message? What version of the SDK did you use (this seems like an older message)

Agrael1 commented 1 week ago

@spencer-lunarg

[Validation layer]: VUID-vkCmdSetDescriptorBufferOffsetsEXT-pOffsets-08063
 [Message]:Validation Error: [ VUID-vkCmdSetDescriptorBufferOffsetsEXT-pOffsets-08063 ] Object 0: handle = 0x27fa20378c0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x22ff52a9 | vkCmdSetDescriptorBufferOffsetsEXT(): pOffsets[0] 0 must be small enough such that any descriptor binding referenced by layout without the VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT flag computes a valid address inside the underlying VkBuffer. The Vulkan spec states: The offsets in pOffsets must be small enough such that any descriptor binding referenced by layout without the VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT flag computes a valid address inside the underlying VkBuffer (https://vulkan.lunarg.com/doc/view/1.3.280.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdSetDescriptorBufferOffsetsEXT-pOffsets-08063)

The SDK version I run is 1.3.280, the real implemented version is 1.3.275 on NVidia 555.99 RTX driver The only thing I change to see the error is I change the descriptor buffer size from 256 to 3 * (mutable_desc_size), which is 3*16=48. Buffer is allocated using Vulkan Memory Allocator

spencer-lunarg commented 1 week ago

@Agrael1 I am still looking into this, what my "guess" is going on is the VVL is throwing a real error, but giving a terrible message (so needs to be fixed regardless)

If you call vkGetDescriptorSetLayoutSizeEXT on your layout, is it over 3 * (mutable_desc_size), if see the issue is not the offset, but that the offset (0) plus the pLayoutSizeInBytes is too large for your buffer

Agrael1 commented 1 week ago

@spencer-lunarg The thing is, it is not registering as an error, VkResult is fine, and rendering is fine as well. 3 * (mutable_desc_size) is enough to fit all descriptors, but pLayoutSizeInBytes is not giving adequate size. 256 is something worth mentioning in documentation of VK_EXT_descriptor_buffer, since it makes use of desc buffers challenging. I have tested it on several cards, none have any problems reading descriptors.

My guess is that pLayoutSizeInBytes gives minimal buffer size to allocate, with regards to buffer memory size alignment, but does not reflect the actual memory descriptors consume.

spencer-lunarg commented 1 week ago

but pLayoutSizeInBytes is not giving adequate size

Just to confirm, did you query the size and what did it return for you here... this is what the validation layers is currently using to decide (if that is correct or not, is something I am still trying to figure out)

Agrael1 commented 1 week ago

yes, it returns 256.

Agrael1 commented 1 week ago

Create a VkBuffer, size equal to NumDescriptors multiplied by the descriptor size within it

https://github.com/KhronosGroup/Vulkan-Docs/blob/main/proposals/VK_EXT_descriptor_buffer.adoc Paragraph 4.1. Now it seems that the check is incorrect, and the buffer should be indeed 3 * (mutable_desc_size)