WebGPU immediates, external textures and MediaStreamTrack speech
I wanted to test three newer Chrome APIs against HTML-in-canvas: binding a GPUTextureView from a drawn DOM card straight to a WGSL texture_external slot alongside a video, pushing per-card uniforms with pass.setImmediateData(), and feeding a video's audio track into SpeechRecognition.start(track) to drive a drawn DOM caption banner. Each section reports the path your browser took and falls back when a feature isn't there.
1. GPUTextureView bound to texture_external
One WGSL shader with a single texture_external binding samples either a playing video (importExternalTexture()) or the live DOM card's GPUTextureView (drawElementImageToTexture()), or both in split screen inside the same render pass.
Show the code single texture_external shader, GPUTextureView bind group and hit geometry
- The drawable DOM card inside the canvas. Its texture view is handed to the same
externalTexturebinding as the video. - One WGSL shader with one
texture_externalbinding. Both sources are sampled throughtextureSampleBaseClampToEdge()with optional chroma shift and scanlines. - Probing
GPUTextureViewinexternalTextureand updating hit boxes. If validation rejects the view or WebGPU isn't usable, the stage switches to a 2D canvas.
2. Per-element uniforms with pass.setImmediateData()
Four interactive drawable DOM cards are drawn in one render pass on a subdivided mesh. Each card's offset, tilt, wave phase and highlight (48 bytes) are pushed straight onto the render pass with setImmediateData() (or setImmediates() where Chrome exposes the earlier name) and zero uniform buffers.
Show the code 48-byte var<immediate> block, mesh warp shader and uniform buffer fallback
- Four interactive drawable cards in one canvas. Each has its own control and keeps its hit box synced as it moves.
- Subdivided wave mesh with
var<immediate>. Packing the canvas size into the 48-byte immediate block removes every uniform buffer from the pass. - One render pass for all four cards. Calls
pass.setImmediateData()(orsetImmediates()) before each draw, or binds a 256-byte dynamic offset in the fallback buffer.
3. SpeechRecognition.start(track) into drawn DOM captions
Plays /media/talk.webm, captures its audio track with video.captureStream().getAudioTracks()[0], and passes that track to recognition.start(audioTrack). The recognised text (or /media/talk.vtt cues when track recognition isn't available or returns nothing) writes straight into a selectable, editable DOM banner drawn over the video in one 2D canvas.
Show the code captureStream() audio track, SpeechRecognition.start(track) and 2D caption draw
- Video and editable DOM banner inside one 2D canvas. Drawing the banner after the video puts it on top for taps, text selection and editing.
- Capturing the audio track and falling back to
talk.vtt. Reports whetherstart(audioTrack)was accepted, errored or timed out without results. - Painting both elements at their layout size. Every
drawElementImage()call passes width and height so HiDPI phone screens scale correctly.
How it works
All three demos share the page's single WebGPU device from webgpu() in /shared/backend.js (no extra device is opened, and nothing calls adapter.requestDevice() directly). When WebGPU isn't available or rejects a newer binding, Demos 1 and 2 switch to a 2D canvas with drawElementImage() so every control stays usable.
| Capability | In this browser | How the page uses it |
|---|---|---|
navigator.gpu + drawElementImageToTexture() | Checking… | Uploads drawable HTML cards straight into rgba8unorm WebGPU textures. |
GPUTextureView in externalTexture | Checking… | Lets one WGSL texture_external pipeline sample both a <video> and a drawn DOM element. |
pass.setImmediateData() / setImmediates() | Checking… | Pushes 48 bytes of offset, tilt, wave phase and highlight per card with zero uniform buffers. |
SpeechRecognition + captureStream() | Checking… | Sends the playing video's audio MediaStreamTrack to recognition.start(audioTrack), falling back to /media/talk.vtt. |
Live checks
Each check builds its own isolated fixture on a bench panel at the bottom of the screen and retires its canvas afterwards. The visible demos above aren't touched while the checks run.
| Result | Experiment | Detail |
|---|
Findings
This page hasn't been measured in a browser yet; press "Run these checks" above to measure your browser, and see findings/webgpu-immediates.md for the verification checklist.
GPUTextureViewintexture_externalavoids duplicating shaders. When a browser accepts a single-mip 2Drgba8unormview in anexternalTexturebinding, one WGSL pipeline usingtextureSampleBaseClampToEdge()can draw bothimportExternalTexture({ source: video })and adrawElementImageToTexture()card in the same render pass. Not verified on desktop Chrome or Android yet.- Immediates method naming differs across Chrome builds. Chromium 157 exposed
GPURenderPassEncoder.prototype.setImmediateswithmaxImmediateSizeof 64 bytes (measured infindings/webgpu-features.mdon 2026-11-21), while the WebGPU spec renamed the call tosetImmediateData(). Demo 2 checkssetImmediateDatafirst and falls back tosetImmediates, then to a 256-byte dynamic-offset uniform buffer, reporting whichever name the browser exposes. SpeechRecognition.start(audioTrack)needs a live speech backend and unmuted audio. Headless Chromium 157 exposesSpeechRecognition,processLocallyandavailable()without a speech service (measured infindings/live-captions.mdon 2026-11-21). Muting the<video>also silencescaptureStream()in Chrome, so playback starts unmuted on user tap and falls back to/media/talk.vttcues if recognition errors or produces no words within 2.5 s.- Hit testing after WebGPU draws requires
updateElementGeometry(). Every time a card moves or resizes in Demo 1 or Demo 2, the page passes a newDOMMatrixtocanvas.updateElementGeometry()and toggles an attribute on the element to clear Chromium's hit-test cache. - Not verified: live WebGPU presentation of
GPUTextureView-as-texture_external,pass.setImmediateData()pixel parity against uniform buffers, and real audio track transcription from/media/talk.webmon Chrome desktop and Chrome for Android.