feat(webgpu): add instanced rect 2D rendering and raise texture limit - #55
feat(webgpu): add instanced rect 2D rendering and raise texture limit#55jimwei wants to merge 1 commit into
Conversation
|
Thanks for the contribution and for including the benchmark results. The instanced-rectangle direction is useful, and requesting the adapter-reported There are several implementation issues that need to be addressed before this can be merged:
The preferred implementation is to pack the pass into contiguous rectangle/color/palette data and submit one batch where compatible. If clipping or pipeline changes require separate draws, each draw needs explicit aligned buffer ranges or base indices, plus non-overlapping palette storage. Please also add a browser-level regression covering at least two |
Adds a compact instanced-rectangle 2D path to the WebGPU backend, plus a
requestDevicetexture-limit fix.What changed
src/canvas.mbt- new runtime APIrt.pushRectInst2d(rects, colors, palette, pipelineCode), arectInstrender command, two storage buffers (rectvec4<f32>+ palette index), a dedicated bind group, pipelines for pipeline code 12/13, and a singlepass.draw(6, rectCount)submission.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.src/canvas.mbt- requestmaxTextureDimension2Dfrom the adapter when callingrequestDevice, 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):
pushColor2dbaselinepushRectInst2dCompatibility
The consuming app checks for
rt.pushRectInst2dand falls back to the existingpushColor2dvertex-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 standalonemoon check --target jsinselene-webgpucurrently hits unrelated dependency parse errors inmoonbitlang/x@0.4.45under the latest MoonBit toolchain, so the runtime validation was done through the consuming project.