Skip to content

Conversation

@kpreid
Copy link
Collaborator

@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.

Copy link
Collaborator

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes StagingBelt much more compelling for me as a user of wgpu.

}

struct Chunk {
buffer: Arc<Buffer>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still need to be Arc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't. There also doesn't need to be a size field any more. Removed those things.

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, looks good otherwise

@cwfitzgerald
Copy link
Member

@kpreid is this rebaseable? If so I can rebase away the merge commit

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.
`Buffer` now implements `Clone` on its own.
@kpreid
Copy link
Collaborator Author

kpreid commented Feb 13, 2025

I’m not sure what you mean by “rebaseable” but I’ve rebased it.

@cwfitzgerald
Copy link
Member

I mean, mergable by rebase-and-merge as opposed to squash and merge

@kpreid
Copy link
Collaborator Author

kpreid commented Feb 13, 2025

Oh, sorry. Yes, this one does not need squashing. Not much would be lost by squashing it, but the commits are individually coherent and should pass tests. In general, I don't publish broken commits. I’ll make sure to specify this in future PR descriptions.

@cwfitzgerald
Copy link
Member

Sounds good!

We have a change to the pull request template in #6879 which will also explicitly ask this.

@cwfitzgerald cwfitzgerald enabled auto-merge (rebase) February 13, 2025 17:45
@cwfitzgerald cwfitzgerald merged commit 2f50426 into gfx-rs:trunk Feb 13, 2025
34 checks passed
@kpreid kpreid deleted the belt branch March 14, 2025 17:33
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.

3 participants