Mutable bind groups in DX12 and Vulkan within wgpu-hal #6842
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
Link to the issues addressed by this PR, or dependent PRs in other repositories
Description
Describe what problem this is solving, and how it's solved.
Implements mutable bind groups in wgpu-hal. When you create a bind group with the
ALLOW_UPDATES
flag, you can callupdate_bind_group
in the device, which has a similar API tocreate_bind_group
and will update the existing descriptors in DX12 and Vulkan (not implemented in other backends). This allows you to have much more efficient bindless texturing, because you can use a single large bind group and change its descriptors at runtime, without having to recreate the large bind group.In order to make this more usable in DX12, I also implemented partial resources, by storing the descriptor offsets of every value in
entries
for the different heap types, then doing a CopyDescriptors call that fills in every handle as a range with 1 value instead of doing them all as a single big range.And finally I added
array_element_offset
toBindGroupEntry
, which allows the user to write to a specific array element, useful when you have a bind group entry with a largecount
and you want to do bindless writing to it.Testing
Explain how this change is tested.
Edited the halmark example in wgpu-hal to update the bind group every 100 frames when MUTABLE_BIND_GROUP is true, and ran the test in DX12 and Vulkan, as well as all the other tests using xtask test.
Checklist
cargo fmt
.taplo format
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.