Validate binding ranges against buffer size #7911
Merged
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.
Reprise of #7875, which was reverted in #7905.
This tightens up the validation of binding sizes. I have added a helper on the wgpu_core Buffer type to resolve implicit remainder-of-buffer sizes and validate the binding offset and size against the size of the buffer. This helper is now the preferred way of constructing a hal::BufferBinding. Direct construction is no longer allowed in wgpu_core. There is an unsafe new_unchecked helper for cases where direct construction is necessary.
This fixes a small but critical typo in the previous change: 14a5abd
It also stays even closer to the original behavior for zero-size bindings than the previous change. When we validate a binding with implicit remainder-of-buffer size, we preserve the information that it is sized as such, and resolve it again in the backends.
I've divided the changes into meaningful independent commits. Since #7875 was reverted, the PR diff is against the state prior to those changes. The diff against the state after #7875 may also be informative: https://github.com/gfx-rs/wgpu/compare/e5b03ffa1defc0b760a8c0bd8c54aa9b98c78002...andyleiserson:wgpu:buffer-size-fixes?expand=1.
Testing
Enables some CTS tests that were broken by the previous change.
The following CTS tests are still failing, but are also relevant:
Squash or Rebase? Undecided
Checklist
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.