Skip to content

Tracking: WebGL 2 capabilities unblocked by the WebGL2-only baseline (#1509 scope C) #1556

Closed

Description

@obiot

Summary

Tracking issue for the WebGL 2 features that became available once #1509 made the renderer WebGL 2 only. Kept as one ticket rather than five, because some of these are concrete cleanups and others enable capabilities we have not decided to build — splitting one out when it is actually picked up keeps the tracker honest about which is which.

Already split out

Status Item Ticket
✅ done (20.0, #1571) Mesh instancing — InstancedMesh on both GPU backends, plus glTF EXT_mesh_gpu_instancing #1508
✅ done (20.0) Static-mesh VBO caching #1507
✅ done (20.0, #1564) Mipmapped minification + anisotropic filtering #1511
✅ done (20.0) Lighting uniform buffer (raise MAX_LIGHTS) #1552
🔶 half done Shared frame-globals uniform buffer — the WebGPU backend ships this shape (bind-group-0 frame globals). The WebGL half is blocked on a compatibility promise, not merely unfinished: GL uniform blocks need GLSL ES 3.00 while user shaders are contractually ES 1.00 — written up in #1568, deliberately not scheduled #1555 / #1568
✅ done (20.0, #1566) Text / gradient texture sizing (fixed-resolution gradient ramps + 32px text buckets) — glyph atlas follow-up: #1565 #1554
✅ done (20.0) Backend-neutral vertex formats + topologies #1551

Concrete, no design question — ✅ both done (20.0, #1567)

texStorage2D immutable textures + sized internal formats. Allocate once with texStorage2D, update with texSubImage2D. Immutable storage lets drivers skip per-upload completeness validation, and sized formats (RGBA8 etc.) remove format-inference guesswork. Touches MaterialBatcher.createTexture2D and therefore every upload path — compressed textures, FBO attachments, and the video re-upload path added in 19.9.1 — so it is a texture-pipeline change rather than an addition.

Done in #1567. Every non-resource texture allocates immutable sized storage once and updates through texSubImage2D. The payoff turned out to be larger than the driver-validation saving this entry anticipated: a same-size content update (ticking Text, Gradient re-bake, video frame) was creating a fresh texture object every time, because CanvasRenderTarget.invalidate dropped the batcher's binding record and sent the next upload down the allocate path. Invalidation now marks the unit content-dirty instead, so with the #1554 size buckets the steady state of dynamic text and gradients allocates nothing at all.

MSAA framebuffers via blitFramebuffer. renderbufferStorageMultisample + resolve-blit gives antialiased post-effect passes, which WebGL 1 could not do at all. Currently antiAlias only affects the default framebuffer, so any scene using post-effects loses edge AA. Changes what post-effect FBOs produce, so it needs visual re-baselining.

Done in #1567, on both GPU backends — it became a paired change once WebGPU shipped, since the same gap existed there. Post-effect capture targets are multisampled (4× color + depth-stencil renderbuffers resolved via blitFramebuffer on WebGL; a per-target multisampled texture resolved by the render pass on WebGPU); ping-pong intermediates stay 1×, since effect blits are screen-aligned quads with no geometric edges to antialias. The WebGPU multisampled half is per-target rather than shared, because nested effect brackets interleave passes and a mid-frame load-back would otherwise read another target's stored samples. toFrameTexture() resolves an active multisampled target before copying and rebinds it afterwards.

The visual re-baselining this entry called for was done with a headed edge probe on both backends: with an effect active, MSAA now produces the identical intermediate-coverage signature as the no-effect control (3 distinct levels — the 4× quantization), while antiAlias: false measures a hard step. Cost is documented in the CHANGELOG: roughly 28 B/px extra on WebGL (~55 MB at 1080p) and ~16 B/px on WebGPU, allocated only when antiAlias is on.

Speculative — enables features not yet decided

Multiple Render Targets (MRT). drawBuffers writing colour + normal + depth in one pass. The enabler for deferred lighting and G-buffer effects; only worth doing if we want those, since the current forward path is fine for 2D and light 3D.

Texture arrays / 3D textures. TEXTURE_2D_ARRAY would let the GPU tilemap sample one array instead of juggling several atlases, and would relieve the texture-unit pressure that TextureCache works around today. Interacts with #1410 (renderer-agnostic texture cache) — worth designing together rather than separately.

Transform feedback. Capture vertex-shader output into a buffer; the groundwork for GPU skinning and GPU particle simulation. Note #1404 already covers GPU-instanced particles by a different route.

What is left

Everything concrete on this tracker is now done. What remains is #1568
(the GL frame-globals variant, deferred by decision — it is blocked on the
ES 1.00 user-shader guarantee, not merely unfinished) and the three
speculative items below. None are scheduled, and two of them (texture
arrays, MRT) are worth designing against #1410 / the WebGPU backend rather
than in isolation.

Notes

Unblocked by #1509.

Activity

  1. obiot commented on Aug 6, 2026

    @obiot
    MemberAuthor

    Status update now that #1564 (the WebGPU backend completion) is merged:

    One correction to the Notes section: "implementing them in GL first informs the backend-neutral abstraction" has inverted since the WebGPU backend shipped. MRT, texture arrays and transform feedback all have first-class WebGPU counterparts (transform feedback's modern equivalent being compute), so these should now be designed WebGPU-first with the GL implementation following — the same principle the 20.0 renderer work followed. Texture arrays in particular should be designed together with #1410 (renderer-agnostic texture cache), which is next on the 20.0 cleanup list.

  2. obiot commented on Aug 6, 2026

    @obiot
    MemberAuthor

    Update: #1554 shipped in #1566 (superseding the note above that listed it as open). As re-scoped, gradients now bake into a fixed 256×256 shared target — allocated once, never resized, every re-bake a same-size texture update, memory capped, verified pixel-identical on all three backends — and Text canvases round to 32-pixel grow-only buckets instead of powers of two (waste bounded at 31 px per axis). The structural follow-up (dynamic glyph atlas, so text changes allocate nothing) is #1565, gated on #1410.

    Remaining from this tracker: #1508 (instancing) and the WebGL half of #1555 among the split-outs, plus the items listed in the body (texStorage2D + sized formats, MSAA post-effect targets — now naturally a paired both-backends change — and the three speculative WebGPU-first items).

  3. obiot commented on Aug 6, 2026

    @obiot
    MemberAuthor

    Both concrete items are done and merged for 20.0 in #1567 — ee0e93444. They landed together because they touch the same texture / render-target machinery, and the MSAA half turned out to be a two-backend change rather than a WebGL one.

    texStorage2D + sized formats. The anticipated win (drivers skipping per-upload completeness validation) is real but driver-dependent and too small to isolate in-frame, so no number is claimed for it. The unanticipated one is larger and structural: same-size content updates were allocating a new texture object every time. CanvasRenderTarget.invalidate discarded the batcher's binding record, so the next upload took the allocate path — meaning a score counter updating every frame cycled ~60 texture allocations per second through the driver. Invalidation now marks the unit content-dirty, the upload lands as a pure texSubImage2D, and combined with the #1554 buckets the dynamic-text/gradient steady state allocates nothing. Found because a test asserted the cheap path and failed.

    MSAA under post effects. Verified rather than assumed: a headed edge probe on both backends counts intermediate edge intensities across antiAlias × post-effect combinations. With an effect active the coverage signature is now identical to the no-effect control on both backends (3 distinct levels, the 4× quantization); antiAlias: false measures a hard step. The memory cost is documented in the CHANGELOG rather than left implicit — ~28 B/px on WebGL (≈55 MB at 1080p), ~16 B/px on WebGPU where the multisampled depth attachment is shared with the canvas, and nothing at all when antiAlias is off.

    On the #1555 row. The GL half is not simply unfinished work: GL uniform blocks require GLSL ES 3.00, and ShaderEffect bodies / raw GLShader sources are contractually ES 1.00 — a guarantee reaffirmed in the 20.0 upgrade notes. A full conversion would break user shaders; only a built-ins-only variant is viable, and it costs maintaining two forms of the same globals. Since frame globals upload once per shader-program switch (not per draw), the win is modest and should be measured before the complexity is taken on. Written up as #1568 and deliberately left unscheduled.

    That leaves #1508, #1568 and the three speculative items on this tracker, none of them scheduled.

  4. obiot commented on Aug 7, 2026

    @obiot
    MemberAuthor

    Mesh instancing (#1508) is merged for 20.0 — ed2f8d3d8, via #1571. That was the last concrete item on this tracker.

    InstancedMesh draws one geometry many times in a single call on both GPU backends, and glTF EXT_mesh_gpu_instancing loads authored scatters with no user code (static and animated paths alike). The new Instanced Forest example renders 100 000 trees from one 52-vertex geometry in one drawElementsInstanced, at 60 fps on WebGL and WebGPU — though that figure is vsync-capped, so it says "not the bottleneck" rather than establishing a limit.

    Two things are worth recording here rather than leaving in the PR:

    The refactor underneath was the risky part, not the feature. Both backends assumed a single vertex buffer; WebGLVertexState and the WebGPU pipeline cache now take a list of buffer layouts with step modes. Existing callers stay byte-identical by construction — divisors are only issued for instance groups, and WebGPU omits stepMode for vertex groups since that is the default — and that is pinned by tests rather than asserted in a comment. Every batcher on the GL backend depends on this file, so the 41 pre-existing VAO tests were kept passing unedited as the baseline.

    Three independent code reviews found six bugs the tests could not. The suite asserted CPU-side records and GL call counts, which is structurally blind to "the right call, made with the wrong state". The most instructive: the group was frustum-culled by the prototype's bounding box, because Camera3d culls on getBounds() and never on getBounds3d() — so a scatter spanning thousands of units presented an ~80 px sphere and the entire forest vanished the moment the group origin left the frustum. My getBounds3d() union was dead code whose doc comment claimed otherwise. Also found: draw() ignoring the viewport, a custom shader able to leave the transform rows unbound (singular matrix, mesh collapses to a point), one dirty span drained by whichever batcher drew first, recycled slots inheriting the dead instance's emissive, and one animation clip anywhere in an asset silently dropping all instancing. All fixed with regression tests that fail against the reviewed code.

    Remaining on this tracker: #1568 (deferred by decision — blocked on the ES 1.00 user-shader guarantee, not merely unfinished) and the three speculative items. Nothing scheduled.

  5. obiot commented on Aug 7, 2026

    @obiot
    MemberAuthor

    Closing: every concrete item on this tracker is done, and the remaining ones have been given proper homes.

    Shipped for 20.0 — #1507 (retained mesh), #1511 (mipmaps + anisotropy), #1552 (light uniform buffer, 8 → 32 lights), #1551 (backend-neutral vertex formats), #1554 (gradient/text texture sizing), #1508 (mesh instancing), plus the two items that lived only in this issue's body: texStorage2D immutable textures with sized formats, and MSAA framebuffers that survive post-effect chains.

    Not closed, deliberately — each now has a home:

    • WebGL: frame-globals uniform block, engine-owned shaders only (the GL half of #1555) #1568 — the GL frame-globals uniform block. Split out and left unscheduled by decision, not by neglect: it is blocked on the ES 1.00 guarantee for user shaders, and the only viable variant (built-ins only) costs maintaining two forms of the same globals for a modest win. The ticket records why, so it is not rediscovered.
    • Texture arrays / 3D textures — noted on Refactor TextureCache and Batcher base class for renderer-agnostic abstraction #1410, which is where they actually bear: the array shape is a constraint on the renderer-agnostic texture abstraction rather than a feature layered on top of it.
    • Transform feedback — overlaps GPU-instanced particle rendering #1404 (GPU-instanced particles), which reaches the same goal by a different route.
    • MRT / drawBuffers — the enabler for deferred lighting and G-buffer effects, with a direct WebGPU equivalent. Genuinely undecided and not worth a placeholder ticket; it belongs with the backend work if and when deferred shading is wanted. Searchable here in the meantime.

    Keeping this open solely for three undecided ideas would misrepresent the WebGL-2 baseline work as unfinished when it is not. Reopen or split one out if any of them becomes real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions