Skip to content

Implement initial Pyodide WebGPU backend - #1

Draft
MathItYT wants to merge 31 commits into
mainfrom
feature/pyodide-webgpu-backend
Draft

MathItYT wants to merge 31 commits into
mainfrom
feature/pyodide-webgpu-backend

Conversation

@MathItYT

@MathItYT MathItYT commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements the browser-native js_webgpu backend for Pyodide and integrates its presentation context with rendercanvas.

Included

  • navigator.gpu adapter/device acquisition
  • JavaScript Promise → GPUPromise bridge
  • Python snake_case → WebGPU camelCase descriptor conversion
  • GPU resource wrappers
  • Buffers, textures, views, samplers, bind groups and layouts
  • Shader modules and compilation information
  • Render/compute pipelines and async pipeline creation
  • GPUCommandEncoder copy/clear/query operations
  • Render/compute pass commands, indirect dispatch/draw, occlusion queries and bundles
  • Browser GPUCanvasContext
  • rendercanvas-compatible presentation context
    • configure()
    • unconfigure()
    • get_current_texture()
    • get_preferred_format()
    • physical-size propagation
    • present()
    • explicit resource release
  • Initial API-shape tests

rendercanvas flow

rendercanvas.PyodideRenderCanvas supplies:

{
    "method": "screen",
    "platform": "browser",
    "window": HTMLCanvasElement,
}

The rendercanvas WgpuContextToScreen then calls wgpu.gpu.get_canvas_context(). The Pyodide backend wraps the native browser canvas.getContext("webgpu"), while keeping the public wgpu-py context API expected by rendercanvas.

Browser WebGPU presents automatically after queue submission; there is intentionally no native swapBuffers() equivalent.

Next

The next step is a real browser integration test with Pyodide + rendercanvas, including an actual render pass to an HTML canvas. After that, API parity and browser CI can be expanded systematically.

@Vipitis

Vipitis commented Oct 5, 2026 •

Copy link
Copy Markdown

hey, I stumbled across this due to an issue search I have setup.

I really like the approach with call and getattr looks really clean. Since it took me several months (on and off) to figure out the quirks around pyodide ffi, I can offer you my solution (which makes use of wgpu.structs for descriptors) here: pygfx#753 (mainly _helpers.py things), feel free to have a look!

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.

2 participants