Skip to content

gfx: a plain textured program for the image program's no-card exit - #983

Merged
GLinnik21 merged 5 commits into
mainfrom
gfx/plain-image-program
Oct 24, 2026
Merged

GLinnik21 merged 5 commits into
mainfrom
gfx/plain-image-program

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

fs_img.frag (the image program, IPROG) has an early exit for any draw that is not a rounded card: u_card.z < 0.5 writes vec4(tex*u_tint.rgb, ta*u_tint.a), about 2 arithmetic words and 1 texture word a fragment. Midgard sizes registers and occupancy for the whole shader, so that exit was charged the card chain's footprint it never runs. The two Home hero photographs (radius 0) take it over about 2.1M px a frame, and so does every resting card's interior piece (card_cut splits it off with the card flag off). Measured on the device 2026-10-24.

This adds fs_tex.frag, that exit as a whole program, linked with the unchanged vs_img.vert.

  • Body: the same declarations at the same precision and the same three statements as the exit. It reads u_tex, v_cuv and u_tint and nothing else (no premultiply, scrim, crop clamp or colour-space flag stands behind that exit), so nothing had to be carried over or excluded.
  • Routing, in draw_tex_core_in, by the pure plain_texture_program(plain, overridden, radius): a draw goes to the new program when it carries no focus/still program override and radius < 0.5 (the packed u_card.z). A rim, shadow pad or tint do not matter: the shader never reads them past that exit, so a radius-0 Class::Card hero with a shadow pad routes there too. A split card's interior piece (drawn last, radius 0) routes there as well; its four ring pieces stay on IPROG. A still-program card's interior stays on the still program (its exit is stillOver, not the plain write).
  • The program is optional like FOCUS_IMAGE: if it does not link, IPROG draws the same picture as before and a line is logged.
  • Every uniform it reads (u_trect, u_uvrect, u_tint) is sent on every bind from one helper; u_tscreen and the sampler unit are set once at link.
  • The overdraw/drawmask ledger is untouched: gate() still runs first, note_card_path still books the same paths. The program is chosen after both.

Expected saving (an ESTIMATE, not a result): 0.5-1.0M GPU cycles a frame on hero-pong and 0.2-0.4M on grid-pong.

Identity evidence (macOS simulator, raw 3840x2160 PNGs)

Captured with tools/screenshots.py --keep on home, home-shelves, library-grid (the demo library), comparing the raw shot.png the sim writes, before JPEG encoding. A canary build (the new program halving its colour) changed 7.6M of home's 8.3M pixels, so these scenes do run through the new program for most of the page. Desktop GL ignores precision qualifiers, so this proves the routing and the arithmetic, not Mali's fp16 rounding; that rests on the identical declarations the new test pins.

Run-to-run noise on origin/main (20 home captures of origin/main, one of them the reference): home differs by 0 to 2880 px (max channel delta 1, or 2 in 98 px), home-shelves by 0 to 2 px, library-grid by 0.

Branch vs main:

  • library-grid: 0 differing pixels in every run.
  • home-shelves: 0 to 2 px in all runs but one (below).
  • home: in 17 of 19 branch captures, 0 to 3445 px against the main reference, max delta 1 or 2, in the same bottom-left region the main-vs-main noise sits in (identical bounding box (222,1425)-(790,1559) for branch-vs-main and main-vs-main). Three of them were pixel-identical to the main reference or within 4 px.
  • Two of the 19 branch home captures (the first one after building, and one more) showed a different pattern: about 10-11k px, max delta 1-2, scattered over the hero photograph region. Neither reproduced in 17 further branch captures (home-only and full runs), and none of the 20 origin/main captures showed it. I could not tie it to the change: the new program's output is a pure function of its inputs and 17 captures match, which points at a differing input (an animation caught at a slightly different value under load, the failure mode tools/screenshots.py itself documents) rather than the program, but that is an inference, not a measurement. It is the one thing the reviewer should weigh.

Local tests

  • make test-crate C=plx_gfx T=plain: test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 157 filtered out
  • make test-crate C=plx_gfx: test result: ok. 163 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  • Mutation check: changing fs_tex.frag's alpha term, or the rule to radius < 0.6, fails 3 of the new tests.
  • The release-config hook's cargo check --lib --no-default-features stayed silent after the last edit. make check was not run locally (congested machine); CI gates it.

Device measurement

Measured on the dev TV (Mali-T820, webOS 4.5) on 2026-10-24:

scene build GPU_ACTIVE p50 p95 missed, cycles 2-60
hero-pong control 10.27M 11.86M 14, 7, 9
hero-pong this PR 9.16M (-1.11M) 10.96M 12, 5, 5
grid-pong control 9.93M 11.54M 15, 11, 9
grid-pong this PR 9.80M (-0.13M) 11.41M 14, 14, 12
  • Hero gained more than the estimate.
  • Grid gained less: its resting card interiors are a small share of the frame.
  • Grid misses are unchanged within run-to-run noise, since 9.8M is still well above the ~8M knee where misses fall off.
  • Not yet done: a pixel diff of this build on the device.

No linked issue.

🤖 Generated with Claude Code

GLinnik21 and others added 5 commits October 24, 2026 12:56
Every textured quad runs the image program (fs_img.frag). Its first exit,
`u_card.z < 0.5`, is `vec4(tex*u_tint.rgb, ta*u_tint.a)`: about 2 arithmetic
words and 1 texture word a fragment. Midgard sizes registers and occupancy
for the whole shader, so that exit was charged the card chain's footprint it
never runs. The two Home hero photographs (radius 0) take that exit over
about 2.1M px a frame, and so does every resting card's interior piece
(`card_cut` splits it off with the card flag off). Measured on the device
2026-10-24.

fs_tex.frag is that exit as a whole program: the same declarations at the
same precision and the same three statements, paired with the unchanged
vs_img.vert. It reads u_tex, v_cuv and u_tint and nothing else, so no
premultiply, scrim or crop clamp had to be carried over. draw_tex_core_in
routes a draw to it when plain_texture_program() says so: the draw is not
overridden by the focus or still program and its radius takes the exit
(`radius < 0.5`, the packed u_card.z), and for a split card's interior piece
(drawn last, radius 0). The ring pieces stay on the image program. The
program is optional: if it does not link, IPROG draws the same picture as
before. gate() and the card-path ledger book exactly what they booked.

Expected saving (an ESTIMATE to be measured on the TV, not a result):
0.5-1.0M GPU cycles a frame on hero-pong and 0.2-0.4M on grid-pong.

Tests: fs_tex.frag is pinned line for line to fs_img.frag's plain exit and
sits in the dither-free hot-path list; the routing rule is a pure function
graded against the shader replica over every card shape and a ladder of
radii; the source-shape tests pin the choice after the ledger's gate and the
uniforms the bind sends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	rust-modules/gfx/src/gfx.rs
The exactness test matched fs_img's lines as a subsequence, so a statement
inserted into main before the plain exit passed. It now compares fs_img's main
from its brace through the u_card.z < 0.5 exit as one contiguous block of
normalized statements against fs_tex's main, and requires vs_img.vert to
declare exactly u_trect, u_tscreen and u_uvrect (a pad or inflation uniform
would fail it).

The argument wiring is pinned as whole statements: both bind_plain_image call
sites, its signature and uniform writes, and the init's PlainUniforms mapping
(quad and uv are both [f32; 4], so a swap compiled).

Prose that the program made false is corrected: the pad is not free (its
fragments run the exit in both programs), the focus specialization's exit is
the same plain write (only the still's differs), a fused still's split
interior stays on the still program and exits through stillOver, and the
blur reductions, warm_tex, FrameCache quads and field chain moved off IPROG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The takes_plain_exit doc now says only that a square-cornered draw draws no rim
and no shadow and that its pad fragments still run the exit in either program;
what the pad samples is not claimed. The unfocused-program test doc no longer
lists the draws that moved to the plain texture program as running the image
program.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 marked this pull request as ready for review October 24, 2026 12:55
@GLinnik21
GLinnik21 merged commit 8c638b9 into main Oct 24, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the gfx/plain-image-program branch October 24, 2026 12:55
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
…n/main

The first version of the pad exit (#985) wrote `vec4(0, 0, 0, sh)` from its own
copy of the body's shadow expression. On the TV (Mali-T820, release build,
2026-10-24) that was not the same picture: against the pre-change build the
Home shelves differed in 1,118 px and the library grid in 20 px, every one the
red channel lower by 1/255, 1-5 px outside a resting card's edge.

fs_img.frag now has no exit there. `m` is computed once, before a gate
`if (d < 1.0) { ... }` that wraps only the work that changes `tex` (the lit
glass in the focus program, and the rim); the shadow and the closing write are
written once after it, so a pad fragment runs the body's own instructions with
`tex`/`ta` the raw sample. The focus program's fully-transparent early exit is
main's again, verbatim.

the_card_shaders_pad_exit_is_the_shadow_alone and
..._pad_exit_tail_and_inputs_are_untouched are replaced by
the_card_shaders_pad_path_runs_the_bodys_shadow_tail: the coverage, shadow and
closing write each appear once per program, the lit work only inside the gate,
the gate neither returns, writes a fragment nor assigns anything but `tex` among
the values the tail reads, and what follows it is exactly the shadow and the
closing write.

Merges origin/main (#983): the two comment conflicts (the FOCUS_IMAGE test doc
and fs_img.frag's header) take both versions.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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