Skip to content

[WebGPU] Add the ability to interop with external textures#9530

Open
AdrianEddy wants to merge 6 commits into
gfx-rs:trunkfrom
AdrianEddy:webgpu-external-textures
Open

[WebGPU] Add the ability to interop with external textures#9530
AdrianEddy wants to merge 6 commits into
gfx-rs:trunkfrom
AdrianEddy:webgpu-external-textures

Conversation

@AdrianEddy
Copy link
Copy Markdown
Contributor

Description
Adds two complementary pieces of public API on the WebGPU backend so external interop crates can read and inject GPUTexture handles without copy:

  1. as_webgpu() accessors on Texture, TextureView, Buffer, Queue, and Device - return Option<&webgpu::Gpu*>, the WebGPU counterpart of as_hal (which always returns None on this backend, since WebGPU is not a wgpu_hal API).
  2. Device::create_texture_from_webgpu_handle(texture, desc) - wraps a foreign webgpu::GpuTexture (e.g. from canvas getCurrentTexture()) as a wgpu::Texture without copy. The wrapped texture is external: its destroy() is a no-op, since the JS handle's lifetime is the caller's responsibility.

The vendored handle types (GpuTexture, GpuTextureView, GpuBuffer, GpuQueue, GpuDevice) are re-exported under a new public module wgpu::webgpu.

The unsafe contract on create_texture_from_webgpu_handle is documented in detail (same-device, descriptor-must-match, lifetime-must-extend); cross-device or descriptor-mismatch surfaces as a WebGPU validation error at first use, which wgpu cannot prevent at construction time because the spec exposes no GPUTexture.device reflection.

Testing
Explain how this change is tested.

Squash or Rebase?

Squash

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

@AdrianEddy AdrianEddy changed the title Add the ability to interop with external textures on WebGPU [WebGPU] Add the ability to interop with external textures May 8, 2026
@inner-daemons inner-daemons self-requested a review May 13, 2026 15:35
@jimblandy
Copy link
Copy Markdown
Member

The description of this sounds really reasonable.

@inner-daemons
Copy link
Copy Markdown
Collaborator

We normally assign PRs to maintainers on Wednesday, but some didn't get assigned this week. I'll try to take a look anyway and it'll most likely be assigned to someone next week.

@inner-daemons inner-daemons self-assigned this May 13, 2026
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