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

Dynamic offsets go past the end of the buffer #1643

Closed
Rua opened this issue Jul 21, 2021 · 0 comments · Fixed by #2103
Closed

Dynamic offsets go past the end of the buffer #1643

Rua opened this issue Jul 21, 2021 · 0 comments · Fixed by #2103

Comments

@Rua
Copy link
Contributor

Rua commented Jul 21, 2021

I noticed that the dynamic-buffers example is giving validation errors:

pDynamicOffsets[0] is 0x4 which when added to the buffer descriptor's range (0xc) is greater then the size of the buffer (0xc) in descriptorSet #0 binding #0 descriptor[0]. The Vulkan spec states: For each dynamic uniform or storage buffer binding in pDescriptorSets, the sum of the effective offset, as defined above, and the range of the binding must be less than or equal to the size of the buffer (https://vulkan.lunarg.com/doc/view/1.2.182.0/linux/1.2-extensions/vkspec.html#VUID-vkCmdBindDescriptorSets-pDescriptorSets-01979)
pDynamicOffsets[0] is 0x8 which when added to the buffer descriptor's range (0xc) is greater then the size of the buffer (0xc) in descriptorSet #0 binding #0 descriptor[0]. The Vulkan spec states: For each dynamic uniform or storage buffer binding in pDescriptorSets, the sum of the effective offset, as defined above, and the range of the binding must be less than or equal to the size of the buffer (https://vulkan.lunarg.com/doc/view/1.2.182.0/linux/1.2-extensions/vkspec.html#VUID-vkCmdBindDescriptorSets-pDescriptorSets-01979)

So I went to investigate, and found the root of the problem. When you attach a buffer to a descriptor set, Vulkan needs you to specify an offset and a range of the buffer to use. Vulkano fills these values in automatically based on the buffer type used. In the example, the buffer is filled with 12 bytes of data, so the offset is 0 and the range is 12.

When the descriptor set is then bound with dynamic offsets, the dynamic offsets get added to the offset of the buffer, but this also moves the end point of the range. So in the example, when you have a dynamic offset of 4, you end up with a buffer slice ranging from 4 to 16, and that includes 4 bytes off the end of the buffer! Nothing bad happens here because the shader only reads a single uint (4 bytes) from the buffer, but it still produces a validation error.

What really should be happening here is that the range should be 4 when the buffer is attached to the descriptor set. Then you have three valid "windows" to feed to the shader: 0-4, 4-8 and 8-12. Unfortunately, Vulkano doesn't let you do this safely at present. You can make a BufferSlice that contains only the first 4 bytes, but then Vulkano is no longer able to tell that the full buffer is 12 bytes long, and can therefore not validate the dynamic offsets properly. I don't believe it does this anyway, but it certainly should.

@Arc-blroth as the person who originally added support for dynamic offsets, do you have any ideas?

Rua added a commit to Rua/vulkano that referenced this issue Dec 13, 2022
@Rua Rua mentioned this issue Dec 13, 2022
AustinJ235 pushed a commit that referenced this issue Dec 16, 2022
* Fix #1643

* Remove old code that was incorrect anyway
hakolao pushed a commit to hakolao/vulkano that referenced this issue Feb 20, 2024
* Fix vulkano-rs#1643

* Remove old code that was incorrect anyway
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants