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

Add getters and From implementations to BufferSlice. #7148

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Feb 15, 2025

Connections
Part of addressing #6974

Description
This PR adds functions to make BufferSlice usable in more situations.

  • BufferSlice::buffer(), BufferSlice::offset() and BufferSlice::size() allow decomposing a BufferSlice. This allows a function which receives a BufferSlice to use it, for example, in texture copy operations. I'd like to have a more ergonomic interface to that, but I haven’t thought of one; adding these getters ensures that there is never any unavoidable inexpressiveness. However,
    • It is arguably undesirable to allow going from a BufferSlice to its Buffer and accessing data outside the slice. I think that this is worth considering, but that on net it is more important to be flexible than to be strict, here, particularly as buffers are interior mutable and clonable so there is no fundamental mutability-xor-sharing like &mut [u8] would have.
    • BufferSlice::size() returns a BufferSize rather than an Option<BufferSize>. See Refactor: eliminate unnecessary Option<BufferSize> #7147 for context on why I think this is the right choice — the Option should, I think, be considered an obsolete implementation detail.
  • impl From<BufferSlice> for BufferBinding
  • impl From<BufferSlice> for BindingResource

Please merge this PR without squashing; the commits are self-contained.

Testing
Added and ran API tests.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@kpreid kpreid requested a review from a team as a code owner February 15, 2025 01:58
@nical nical merged commit 9da04c2 into gfx-rs:trunk Feb 17, 2025
34 checks passed
marcpabst pushed a commit to marcpabst/wgpu that referenced this pull request Feb 19, 2025
* Add getters to `BufferSlice` to obtain its parts.

* Add conversions from `BufferSlice` to `BufferBinding` and `BindingResource`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants