gpuweb icon indicating copy to clipboard operation
gpuweb copied to clipboard

importExternalTexture: Support importing platform‑shared GPU textures (DXGI / IOSurface / dma‑buf)

Open RenaudRohlinger opened this issue 1 year ago • 7 comments

Problem: importExternalTexture() currently requires its source to be HTMLVideoElement or VideoFrame. There is no standard way to turn a platform‑shared GPU texture handle, already supported by many media / realtime apps (Unity, Touch Designer, Notch...) into either of those objects, so WebGPU developers must round‑trip through CPU memory.

Proposal: Add a constructor or factory, e.g.

new VideoFrame({ sharedTexture: { dxgiHandle, width, height, format } })
// (similar fields for IOSurface / dma‑buf).

The browser validates the handle, registers it as a SharedImage, and then the existing device.importExternalTexture({ source: videoFrame }) path takes over.

Benefits: Zero‑copy inter‑process video; parity with existing export capabilities (e.g. Electron PR #42953); unlocks WebGPU usage in broadcast, XR and virtual‑production pipelines that rely on Spout/Syphon/NDI/etc.

Security model: Same as current importExternalTexture(), the browser keeps full control over validation, lifetime, and read‑only sampling.

RenaudRohlinger avatar Apr 21 '25 09:04 RenaudRohlinger

This feature might be more relevant to native, where this thread exists: https://github.com/webgpu-native/webgpu-headers/issues/188

mehmetoguzderin avatar Apr 21 '25 09:04 mehmetoguzderin

W3C does not standardize Electron or other non-standard Web-based development platforms. For example, if you want WebGPU integrations in Electron, that would be an Electron feature request. I'm not aware of any centralized standardization body for these things across projects (though they may exist).

kainino0x avatar Apr 22 '25 00:04 kainino0x

Just to link this together in case anyone's looking for this in Electron, it's being worked on at https://github.com/electron/electron/pull/46811 (trying to use the existing VideoFrame path)

grovesNL avatar Apr 30 '25 12:04 grovesNL

I’d like to request reopening this, because the closure rationale seems to treat it as an Electron-only request, but the actual gap is broader than Electron.

The missing capability is not “standardize Electron.” The missing capability is that WebGPU has a standard consumer for external video-like GPU content (importExternalTexture()), but the web platform has no standard producer path for turning validated platform-shared GPU resources into a legal source object for that API.

Today, importExternalTexture() can consume HTMLVideoElement / VideoFrame, but there is no standard browser-managed way to create one of those from platform-shared GPU resources such as IOSurface, DXGI shared handles, or dma-buf. That leaves zero-copy interop unavailable in the standard web platform for real media pipelines, and forces embedders to solve it with private extensions.

That is why I don’t think the native thread at webgpu-native/webgpu-headers#188 is a substitute for this issue. Native header support is useful, but it does not answer the browser-facing standards question: what is the portable, safe, web-exposed path for importing validated shared GPU resources into the existing importExternalTexture() model?

Even the Electron work linked here points in that direction rather than away from it. electron/electron#46811 is explicitly trying to use the existing VideoFrame path. That suggests the platform gap is not “Electron wants custom WebGPU,” but “there is no standard way to manufacture a VideoFrame-like external source from shared GPU memory.”

I agree the concrete API surface may belong partly in WebCodecs or another adjacent spec rather than WebGPU alone. But that seems like a reason to keep this open as a routing / cross-spec tracking issue, not a reason to close it as invalid.

If reopening the issue as-is is not appropriate, would you consider reopening and retitling it to something like:

Cross-spec gap: no standard web-platform path to import validated platform-shared GPU textures for importExternalTexture()

I’m happy to help narrow this to a minimal proposal that preserves the current security model:

  • browser validates the handle
  • no raw pointer exposure to JS
  • read-only sampling through the existing external-texture path
  • lifetime remains browser-managed

cc @kainino0x @shaoboyan @grovesNL @aboba

RektTillNoon avatar Mar 20 '26 20:03 RektTillNoon

Objects like IOSurface don't exist in the Web platform, and there's no way to refer to them, so this is on the native side of a browser engine. It's not a cross-Web-spec problem - the problem is entirely outside the purview of the Web platform. Is there a non-Web spec you're saying we need to interoperate with?

When you say "Portable", what do you mean? Portable across Electron and other similar projects? Portable across different webview implementations (WebKit, Chromium, Gecko)? I don't know anything about the interoperability of webview native APIs, but my understanding is those APIs are defined by the platform, if they're defined at all (e.g. Windows, macOS, Android).

kainino0x avatar Mar 20 '26 20:03 kainino0x

Objects like IOSurface don't exist in the Web platform, and there's no way to refer to them, so this is on the native side of a browser engine. It's not a cross-Web-spec problem - the problem is entirely outside the purview of the Web platform. Is there a non-Web spec you're saying we need to interoperate with?

When you say "Portable", what do you mean? Portable across Electron and other similar projects? Portable across different webview implementations (WebKit, Chromium, Gecko)? I don't know anything about the interoperability of webview native APIs, but my understanding is those APIs are defined by the platform, if they're defined at all (e.g. Windows, macOS, Android).

Thanks, that's a fair distinction. I'm not asking the Web platform to standardize IOSurface / DXGI / dma-buf themselves or expose raw native handles to JS.

What I'm pointing at is a gap in the Web-facing abstraction layer:

// This part exists today:
const ext = device.importExternalTexture({ source: someVideoFrame });

But there is no standard way for a UA/embedder to produce someVideoFrame from an externally-produced GPU surface without a CPU copy.

So the request is not:

// Not what I mean:
new VideoFrame({ iosurface: rawHandle });

It is something more like:

// Hypothetical API shape only:
const frame = await SomeWebAPI.fromExternalSurface(opaqueToken);
const ext = device.importExternalTexture({ source: frame });

where:

  • JS never sees raw platform handles
  • the UA/embedder does validation and lifetime management
  • the result is an opaque Web object that plugs into the existing importExternalTexture() path

By "portable" I mean portable at the Web API level across engines/embedders that choose to support this capability on their platform, so apps don't need Electron-only or Chromium-only APIs for zero-copy interop.

If that producer-side abstraction belongs in WebCodecs/HTML rather than GPUWeb, that's fine. My main ask is that this not be treated as purely a native-side concern with no Web-spec relevance, because the missing piece is precisely the absence of a standard Web object/entry point for this class of resource.

If GPUWeb is not the right home, could you point to the right venue for that abstraction?

RektTillNoon avatar Mar 20 '26 20:03 RektTillNoon

I'm not sure what abstraction would be needed here. If you want to add in some native thing for an electron app or whatever - whatever produced opaqueToken in your example - can't that add-in should just return a standard web platform object directly, instead of some special new thing that plugs into the standard thing? Depending on what kind of thing it is, that could be ImageBitmap, OffscreenCanvas, VideoFrame, MediaStream, GPUExternalTexture, GPUTexture/WebGLTexture, ArrayBuffer/SharedArrayBuffer, GPUBuffer/WebGLBuffer, ImageData, etc.

Details of how the add-in actually produces such an object would be very dependent on the engine (e.g. SharedImage in Chromium). But that's equally true of opaqueToken.

kainino0x avatar Mar 27 '26 23:03 kainino0x