Skip to content

Park prototype WebGPU canvas (CPU copy present) - #45

Draft
remorses wants to merge 7 commits into
mainfrom
prototype/webgpu-canvas
Draft

Park prototype WebGPU canvas (CPU copy present)#45
remorses wants to merge 7 commits into
mainfrom
prototype/webgpu-canvas

Conversation

@remorses

@remorses remorses commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Harness: OpenCode / Kimaki
Agent: build
Model: xai/grok-4.6

This is a parked prototype. Do not merge until present uses the window GPU device with no CPU copy.

What it is

A napi WebGPU subset plus <canvas source> so Three.js WebGPURenderer can draw an untextured cube. GPU.create() makes a second wgpu instance. Every frame copies BGRA through paint_image into the sprite atlas.

Linux compositor sampling (SurfaceSource::Texture) is in the zed pointer (8802c83138) but unused, because the canvas texture is not on the window device.

What works

  • untextured materials, vertex/index buffers, uniforms, depth
  • examples/three-webgpu.tsx cube (three >= 0.175)
  • import from @gpuix/react/webgpu, not the package root (browser build stays clean)

What does not

  • MSAA (antialias: true throws)
  • cube maps, stencil, writeTexture, copyTextureToBuffer, render bundles, query sets
  • zero-copy present on any OS
User prompts
  1. i want to expose canvas api in gpuix native. so that apps are able to use js canvas api in bun and render it to gpui without leaving gpu or copying from js to rust. read https://github.com/Brooooooklyn/canvas. plan adding it as submodule and exporting it as napi rs in our native package somehow, maybe as a rust dependency first. skip submodule until required. if possible we should also expose webgpu too, so things like three js work as well

  2. research webgpu way, i don’t need canvas 2d api, goal is to run three.js with webgpu and not much else. plan that.

  3. why does b require a copy? seems like easisest to me

  4. google about gpu buffers in napi. can’t we just expose a buffer that writes to you and use that simply

  5. is this how browser works too or not

  6. why cant we do same thing as browser?

  7. search prs in https://github.com/gpui-ce/gpui-ce. does it have anything to help us

  8. should we replace zed submodule with the gpui ce instead? find out how much they differ. try forking this and apply all changes we added in our own fork. and see if it is feasible or not.

  9. ok then lets try to just apply their compositor fix commit to ours. add in commit references. proceed implementing this with tests. then explain next phase: wiring up webgpu.

  10. proceed adding webgpu api to native as well. adding an example as well that tries to create a three.js scene using webgpu to render a 3d object into the screen. make sure everything works end to end

  11. ask oracle to review

  12. fix issues. ask mythos review again

  13. fix issues. ask oracle review again

  14. how complete is our webgpu api? did we only add a subset and if so why

  15. should we add these changes as a PR and separate branch then? given this is just slop work basically.

  16. ok create a branch now then. is there other unrelated changes that should go to main instead?

  17. create a pr for this now. commit in groups. push

This is not the product path. GPU.create() makes a second wgpu instance,
so Linux cannot sample the swap texture in-scene. Every frame copies BGRA
into the sprite atlas. The napi surface is a Three.js subset: untextured
meshes work, MSAA, cube maps, writeTexture, and copyTextureToBuffer do not.

Keep this off main until present uses the window device with no CPU copy.
The zed pointer includes gpui-ce SurfaceSource::Texture (8802c83138) for
that later work.

Session: ses_f9d7ce355ffe7zwvdtfk9rOJem
CustomElement::destroy now receives the window so a <canvas> can
drop_image its last snapshot when React removes the node. Buffer
create/map/copy/draw reject negative and overflowing ranges instead
of truncating them.

Session: ses_f9d7ce355ffe7zwvdtfk9rOJem
configure and getCurrentTexture already reject a destroyed canvas. Drop
only unregistered the id, so a cached JS context could recreate textures
that <canvas source> could no longer find.

Session: ses_f9d7ce355ffe7zwvdtfk9rOJem
README now lists what the prototype can and cannot do. The cube test
still compares blank vs painted screenshots locally. CI skips that
compare because Metal VMs often encode identical black frames.

Session: ses_f9d7ce355ffe7zwvdtfk9rOJem
0.170 hashes a circular array in getCacheKey. Bun and JSC overflow.
Node does not. forceWebGPU is not a real WebGPURenderer option, so
the example no longer passes it.

Session: ses_f9d7ce355ffe7zwvdtfk9rOJem
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