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

Expose StagingBelt allocation directly. #6900

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Jan 13, 2025

Connections

Description
Added a method StagingBelt::allocate(). This allows using StagingBelt for copying to textures or any other operation where copying to an existing buffer is not the desired outcome.

One unfortunate feature of the API is that allocate() returns the entire buffer and an offset, so applications could accidentally touch parts of the belt buffer outside the intended allocation. It might make more sense to return wgpu::BufferSlice, but that struct cannot be used in operations like copy_buffer_to_texture and does not have getters, so it is not currently suitable for that purpose.

I also moved Exclusive into a module so that its unsafe-to-access field is properly private, and made various improvements to the StagingBelt documentation, such as acknowledging that write_buffer_with() exists.

Testing
I have manually tested the new function with my application which uses StagingBelt heavily. There are no unit-tests of StagingBelt and I did not add any.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • 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 January 13, 2025 04:52
This allows using `StagingBelt` for copying to textures or any other
operation where copying to an existing buffer is not the desired outcome.

One unfortunate feature of the API is that `allocate()` returns the entire
buffer and an offset, so applications could accidentally touch parts of
the belt buffer outside the intended allocation. It might make more sense
to return `wgpu::BufferSlice`, but that struct cannot be used in
operations like `copy_buffer_to_texture` and does not have getters, so it
is not currently suitable for that purpose.

I also moved `Exclusive` into a module so that its unsafe-to-access field
is properly private, and made various improvements to the `StagingBelt`
documentation, such as acknowledging that `write_buffer_with()` exists.
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