Skip to content

feat(napi): texImage2D and texSubImage2D take a WebGPU canvas - #191

Merged
triniwiz merged 1 commit into
masterfrom
fix/napi-webgpu-canvas-tex-source
Nov 7, 2026
Merged

triniwiz merged 1 commit into
masterfrom
fix/napi-webgpu-canvas-tex-source

Conversation

@triniwiz

@triniwiz triniwiz commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Finishes #188: a WebGPU canvas is now a WebGL texture source on the Node-API hosts (Windows, and Linux once #189 lands), instead of texImage2D throwing and texSubImage2D throwing (previously panicking).

What it does

  • texImage2D / texSubImage2D with a WebGPU canvas read its frame and upload it, the same way a 2D canvas source does. The frame is the current texture if getCurrentTexture() handed one out, otherwise the last presented frame, matching toDataURL.
  • Pixels arrive as unpremultiplied RGBA8: BGRA surfaces are swizzled, and frames configured with alphaMode: 'premultiplied' are unpremultiplied.
  • rgba16float canvases, and canvases that were never configured, still throw, with a message saying there is no 8-bit frame to read.

canvas-c

  • toDataURL's copy-texture-to-buffer-and-map step is pulled out into with_mapped_texture, which both toDataURL and the new read_rgba8 use. toDataURL's encoding is unchanged.
  • New canvas_native_webgl_tex_image2d_webgpu / canvas_native_webgl_tex_sub_image2d_webgpu. They return false when there is no 8-bit frame; the binding throws on that. Header regenerated.
  • The iOS and Android bindings don't call these yet; their texImage2D still has no WebGPU-canvas case.

Testing

  • New spec webgpu.canvas "toDataURL reads back the current frame": clears a WebGPU canvas to blue, decodes the PNG and checks the pixel. It covers the refactored readback on every platform.
  • New specs canvassource.webgl "texImage2D / texSubImage2D accepts a webgpu canvas", which render the uploaded texture and check for blue. They're gated to Windows for now.
  • iOS 26.4 simulator, with this change: webgpu 20/20 (including the new toDataURL test), canvassource 9/9, offscreen 64/64. The new toDataURL test also passes on the previous binary.
  • Not run: the Node-API path itself. There's no Windows or Linux GPU host here. canvas-napi on master doesn't build on macOS (the Windows-only callbacks that feat: Linux support #189 fixes), so it was type-checked here despite those two pre-existing errors, with a deliberate type error in base.rs confirming that file is checked. Please run --suite canvassource.webgl on Windows.

A WebGPU canvas used as a WebGL texture source threw (texImage2D) or, before
#188, panicked (texSubImage2D). Both now read the canvas's frame (the current
texture if one is out, else the last presented frame) as unpremultiplied RGBA8
and upload it, like a 2D canvas source.

canvas-c: toDataURL's copy-and-map step is now with_mapped_texture, shared with
the new read_rgba8; canvas_native_webgl_tex_{,sub_}image2d_webgpu return false
when there is no 8-bit frame, which the binding throws for.

Specs: toDataURL pixel check for a WebGPU canvas (all platforms), and
texImage2D/texSubImage2D from a WebGPU canvas (Windows for now).
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fe7084c8-cde2-49fe-aac2-f03bde00a294

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@triniwiz
triniwiz merged commit 7ec6c93 into master Nov 7, 2026
14 of 23 checks passed
@triniwiz
triniwiz deleted the fix/napi-webgpu-canvas-tex-source branch November 7, 2026 19:58
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.

1 participant