Skip to content

Renderer: zIndex quads flush all queued text, splitting titled tiles into one draw call each (38.9 → 3.8 draws/frame with a fix) #81

Open

Description

@avijit213

Versions: @solidtv/renderer 2.0.7, @solidtv/solid 1.7.1, solid-js 1.9.12. Chrome for Testing (Playwright build 1248), ANGLE/Metal, Apple M2 Pro.

Scene: the bench rows scene (Column of 10 Rows × 20 tiles, 185×278) with the bench thumbnail style (borderRadius: 16, outside focus border, focus scale: 1.1, zIndex: 2), plus a <text> title under each tile.

What happens

In ScenePass.emit, a non-text quad with a non-zero zIndex calls flushText() whenever text is queued:

if (this.pendingCount > 0 && s.f64[fo + F_Z_INDEX] !== 0) {
    this.flushText();

With the demo app's Thumbnail style (zIndex: 2) on titled tiles, every tile flushes the previous tile's title, so a row draws as rounded box, SDF text, rounded box, SDF text…, one program switch per tile.

I counted why OpList.add started a new op over 20 Right/Left presses:

Count
Op splits 4,656
of which Sdf → rounded 4,449
Draw calls / frame 38.9
useProgram calls / frame 38.1

Dropping zIndex from the tiles gives 3.8 draw calls per frame, which confirms the flush is the cause.

Proposed fix

Flush only when a queued text node's bounds intersect the zIndex quad's bounds (F_BX0..F_BY1, already computed before emit). Text the quad doesn't cover keeps its place in the queue and batches with the rest, so layering stays correct.

Patch against the compiled dist/src/core/scene/ScenePass.js (the source repo listed on npm, solid-tv/renderer, isn't publicly reachable, so I couldn't open a PR); the same change applies to ScenePass.ts:

@@ -730,7 +730,8 @@
         const fo = id * F_STRIDE;
         const o = id * I_STRIDE;
-        if (this.pendingCount > 0 && s.f64[fo + F_Z_INDEX] !== 0) {
+        if (this.pendingCount > 0 && s.f64[fo + F_Z_INDEX] !== 0 &&
+            this.pendingOverlaps(fo) === true) {
             this.flushText();
             if (s.i32[o + I_UID] === 0) {
                 return;
@@ -838,6 +839,29 @@
             this.hooks.perOpMatch(id, ops.node[last]);
         ops.add(program, params, texture, clip, id, quad, match);
         this.emitted++;
+    }
+    /**
+     * Does any queued text node's bounds intersect node `fo`'s bounds? A quad
+     * with a non-zero zIndex must draw above the queued text it covers (spec
+     * 7.3); text it does not touch keeps its place in the queue and batches
+     * with the rest, where flushing unconditionally drew every titled tile as
+     * box, text, box, text (one program switch per tile).
+     */
+    pendingOverlaps(fo) {
+        const f64 = this.nodes.f64;
+        const bx0 = f64[fo + F_BX0];
+        const by0 = f64[fo + F_BY0];
+        const bx1 = f64[fo + F_BX1];
+        const by1 = f64[fo + F_BY1];
+        const queue = this.pendingText;
+        for (let i = 0; i < this.pendingCount; i++) {
+            const to = queue[i] * F_STRIDE;
+            if (f64[to + F_BX0] < bx1 && f64[to + F_BX1] > bx0 &&
+                f64[to + F_BY0] < by1 && f64[to + F_BY1] > by0) {
+                return true;
+            }
+        }
+        return false;
     }
     queueText(id) {

Result

Original Patched
Draw calls / frame 38.9 3.8
useProgram / frame 38.1 3.8
Texture binds / 20 keys 9,274 492
Screenshot after Right, Right, Down baseline byte-identical

On this machine main-thread script time barely moves (about 1–10%, within run-to-run noise), which is expected on a fast GPU. The gain should matter on low-end TV GPUs, where each draw call and program switch is expensive. I haven't measured it on TV hardware.

Caveats

  • The check loops over the queued text for each zIndex quad. With many queued titles, a cheaper test (for example a running bounds box of the queue, checked before the loop) may be preferable.
  • I only tested this scene. A case where queued text and a zIndex quad overlap partially should still flush, and does with this check, but it's worth a test in the renderer suite.

Activity

  1. chiefcll commented on Nov 20, 2026

    @chiefcll
    Contributor

    Thanks for the report - working on a fix!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions