Skip to content

feat(webgpu): add instanced rect 2D rendering and raise texture limit - #55

Open
jimwei wants to merge 1 commit into
moonbit-community:mainfrom
jimwei:codex/rect-inst-2d-max-texture
Open

feat(webgpu): add instanced rect 2D rendering and raise texture limit#55
jimwei wants to merge 1 commit into
moonbit-community:mainfrom
jimwei:codex/rect-inst-2d-max-texture

Conversation

@jimwei

@jimwei jimwei commented Aug 13, 2026

Copy link
Copy Markdown

Adds a compact instanced-rectangle 2D path to the WebGPU backend, plus a requestDevice texture-limit fix.

What changed

  1. src/canvas.mbt - new runtime API rt.pushRectInst2d(rects, colors, palette, pipelineCode), a rectInst render command, two storage buffers (rect vec4<f32> + palette index), a dedicated bind group, pipelines for pipeline code 12/13, and a single pass.draw(6, rectCount) submission.
  2. src/shader_sources.mbt - new instance-rect WGSL shader (index 10) that expands the 6 triangle corners in the vertex shader and samples the palette.
  3. src/canvas.mbt - request maxTextureDimension2D from the adapter when calling requestDevice, so large glyph atlases (for example 12,288 px) are not rejected by the default device limit.

Motivation

The spreadsheet PoC renders >100k visible cells. The previous path expanded every rectangle into 6 vertices in JS and uploaded that vertex buffer every frame. The new path uploads 20 bytes per instance (rect + palette index) and submits all rectangles in one draw call.

Benchmarks (Chrome headless + WebGPU, 118,604-cell grid):

Scenario pushColor2d baseline pushRectInst2d
Large grid ~69 ms/frame, 1.72 M cells/s ~31.9 ms/frame, 3.72 M cells/s
Text pressure, 100 frames 925.9 ms 368.5 ms

Compatibility

The consuming app checks for rt.pushRectInst2d and falls back to the existing pushColor2d vertex-expansion path, so unpatched versions of the runtime remain supported.

Verification

The patched package is consumed and verified in the spreadmb PoC (verify_selene.py, verify_selene_unicode_edge.py, verify_cjk_selene.py). A standalone moon check --target js in selene-webgpu currently hits unrelated dependency parse errors in moonbitlang/x@0.4.45 under the latest MoonBit toolchain, so the runtime validation was done through the consuming project.

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