Add support to define descriptor buffer offset and range#947
Add support to define descriptor buffer offset and range#947paulthomson merged 9 commits intogoogle:mainfrom
Conversation
Descriptor buffers can now be bound with byte offset and range via DESCRIPTOR_OFFSET and DESCRIPTOR_RANGE parameters. Descriptor buffer array elements can now point to same buffer. Fixes problem with dynamic uniform/storage buffers: when a dynamic offset is > 0, VK_WHOLE_SIZE must not be used as buffer range.
5eaa131 to
81e1494
Compare
Changes VK_WHOLE_SIZE to -1 as the default value for DESCRIPTOR_RANGE in amber_script.md.
paulthomson
left a comment
There was a problem hiding this comment.
This looks really good, especially all the tests!
However, you have changed a few vectors into unordered_maps, and we iterate over these. We almost never want to iterate over maps because the order is nondeterministic. This can cause errors to become (even more) nondeterministic, when they don't need to be. Thus, we ideally always want to have a vector (containing the keys) available for the cases where we iterate, and possibly a map alongside if needed (or another vector, but maps/sets are good for preventing duplicates). An ordered map is not ideal either; the order can still be nondeterministic (e.g. if storing pointers), and it is more intuitive to iterate in the order that items were added, not some other ordering. Please can you find a way to remove the iteration over maps? Thanks.
Uses vectors when looping over transfer buffers / images.
|
Yeah, that's a good point! So, now it doesn't loop over maps anymore. The transfer images/buffers are still stored in maps for easier inserts and |
|
While doing this PR, I was thinking, that now we can share a buffer between descriptors within a descriptor array, but the same doesn't apply to separate bindings or descriptor sets. e.g. following Amber code is valid, but it will actually create two buffers with same contents: The real problem is with buffers that the shaders can update, like SSBOs, e.g. this doesn't even work: I think that Amber needs some completely different way of handling descriptor buffers to resolve this problem, but that's probably out of this PR's scope. |
|
|
Thanks, I'll fix that. |
paulthomson
left a comment
There was a problem hiding this comment.
Nice work! Left a few minor comments.
| auto transfer_buffer = MakeUnique<TransferBuffer>( | ||
| device_, size_in_bytes, amber_buffer->GetFormat()); |
There was a problem hiding this comment.
The ternary expression above suggests that amber_buffer can be nullptr. But then we use it here anyway. You haven't actually changed this. But it seems odd. Perhaps we should just remove the ternary expression?
There was a problem hiding this comment.
Yeah, that seems odd. amber_buffer is actually used also before the ternary expression:
if (amber_buffer->ValuePtr()->empty())
continue;
I removed the ternary expression.
Oh really!? That is a shame. I think we should fix this, if you can think of a way. But, as you say, not necessarily in this PR. |
Yeah, I have some ideas. I can look into that after this PR. |
e2f2520 to
21dfa45
Compare
Descriptor buffers can now be bound with byte offset and range via DESCRIPTOR_OFFSET and DESCRIPTOR_RANGE parameters.
Descriptor array elements can now point to same buffer.
Fixes problem with dynamic uniform/storage buffers: when a dynamic offset is > 0, VK_WHOLE_SIZE must not be used as buffer range.
Fixes #945