feat(webgpu): add instanced rect 2D rendering and raise texture limit - #55
Open
jimwei wants to merge 1 commit into
Open
feat(webgpu): add instanced rect 2D rendering and raise texture limit#55jimwei wants to merge 1 commit into
jimwei wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.