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

Remove lifetime constraints from wgpu::ComputePass methods #5570

Merged
merged 12 commits into from May 14, 2024

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented Apr 20, 2024

Connections

Part of a series towards lifetime removal on compute passes:

Description
Removes the need for lifetime dependency on any resource passed into a ComputePass.
Lifetime constraints to the originating encoder & queries used during creation still apply for the moment (to be addressed in a follow-up.

Directly builds on #5432 by moving the creation of ArcComputeCommand into compute pass methods.

To accomplish this I had to add a HalApi generic dependency on ComputePass. Since I didn't want to introduce a new object to the id/objecttracking system, I instead decided to create a DynComputePass on wgpu/wgpu_core.rs side. Hopefully we can simplify this as part of the generic refactor (#5124). Note that the new lifetime dependency made boxing of the wgpu-core compute pass is unavoidable at this point and DynComputePass allows us to merge the otherwise required gfx_select & type cast into a single trait/virtual call.
An alternative I expolored was to do the type erasure internally on BasePass<ArcComputeCommand<A>> but I found this quite unwieldy, also this wouldn't cover timestamp writes which are intentionally left unaddressed in this PR.

Testing
Added a new test that ensures that resources passed into a ComputePass can be dropped before executing the compute pass.
Proved that the test would crash before these changes and passes with them.

Checklist

  • Run cargo fmt.
  • 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.

@Wumpf Wumpf force-pushed the lifetime-free-computepass branch from b976ff1 to 0d470a9 Compare April 23, 2024 07:06
@Wumpf Wumpf marked this pull request as ready for review April 23, 2024 07:16
@Wumpf Wumpf requested a review from a team as a code owner April 23, 2024 07:16
@Wumpf Wumpf mentioned this pull request May 5, 2024
6 tasks
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.

By and large great - I'd be curious is there is any performance difference, but lets ship this

@Wumpf
Copy link
Member Author

Wumpf commented May 14, 2024

By and large great - I'd be curious is there is any performance difference, but lets ship this

Me too! I really want to add a compute pass benchmark and backport it now that you started that work
The next pr in the track has the potential of making things faster again

@Wumpf Wumpf enabled auto-merge (squash) May 14, 2024 19:45
@Wumpf Wumpf merged commit 77a83fb into gfx-rs:trunk May 14, 2024
25 checks passed
@Wumpf Wumpf deleted the lifetime-free-computepass branch May 14, 2024 20:07
jimblandy pushed a commit to jimblandy/wgpu that referenced this pull request May 23, 2024
…5570)

* basic test setup

* remove lifetime and drop resources on test - test fails now just as expected

* compute pass recording is now hub dependent (needs gfx_select)

* compute pass recording now bumps reference count of uses resources directly on recording

TODO:
* bind groups don't work because the Binder gets an id only
* wgpu level error handling is missing

* simplify compute pass state flush, compute pass execution no longer needs to lock bind_group storage

* wgpu sided error handling

* make ComputePass hal dependent, removing command cast hack. Introduce DynComputePass on wgpu side

* remove stray repr(C)

* changelog entry

* fix deno issues -> move DynComputePass into wgc

* split out resources setup from test
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.

None yet

2 participants