Skip to content

Allow obtaining custom implementation from wgpu api types #7541

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

Merged
merged 5 commits into from
Apr 18, 2025

Conversation

sagudev
Copy link
Collaborator

@sagudev sagudev commented Apr 15, 2025

Connections
Fixes #7533

Description
When implementing custom beckend, one was not be able to extract actual custom type from descriptors. This is now possible by introducing as_custom method on each wgpu API type (and Dispatch* type) that are analogues to as_hal. They try to return actual concrete custom type that is stored inside custom backend and return None if backend is not custom (or user wanted wrong T).

Testing
Example is modified to cover obtaining original custom type from dynamic custom backend type.

Squash or Rebase? Squash, but it's reviewable per commit.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

sagudev added 2 commits April 15, 2025 10:30
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
@sagudev sagudev marked this pull request as ready for review April 15, 2025 08:55
@sagudev sagudev requested a review from a team as a code owner April 15, 2025 08:55
@cwfitzgerald cwfitzgerald self-assigned this Apr 16, 2025
@raphaelhetzel
Copy link

I already use the changes in this pr to run the compute hello_world example inside wasmtime (custom backend passing the calls to wgpu running on the host).
So i can confirm that this is needed and useful.
Thanks @sagudev.

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.

Small note but otherwise fine. Just wanted to clue you in I would like to have a unified interface for as_hal, as_custom, and a potential future as_webgpu. I'm not sure exactly what this would look like, but I think having a single entry point would probably good for api consistency. This is fine to have for the mean time however.

Signed-off-by: sagudev <[email protected]>
@cwfitzgerald cwfitzgerald merged commit 6666d52 into gfx-rs:trunk Apr 18, 2025
37 checks passed
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.

Custom Backend: No api to get custom buffer during create_bind_group.
3 participants