Repository navigation
Conversation
Measured on the TV 2026-10-24: Home's grid-pong bench runs at a p50 of 9.93M GPU cycles a frame against a budget of about 11.2M, and misses climb above about 8M. The card draws cost 3.58M of it; the focus program alone about 1.82M, at roughly 13 arithmetic words a pixel on about 258K px a frame. A card is drawn as one quad inflated by its shadow pad, and every fragment of the pad, outside the rounded body, ran the whole card path (glow, glare, gloss, rim, texture mix) before the coverage mask zeroed it. From d >= 1.0, m = 1.0 - smoothstep(-1.0, 1.0, d) is exactly 0 (smoothstep clamps to exactly 1.0 past its top edge), so the closing vec4(tex*m, ta*m + sh) is vec4(0, 0, 0, sh) whatever the lit glass made of tex: the glow, glare, gloss and rim reach only tex, never the alpha. Both programs now compute only the shadow there, with the body's own shadow text, and return: the PLX_FOCUS one, which had a bare vec4(0.0) exit for the part of the pad the shadow's box proxy had already cleared, and the plain one, which every resting card's ring pieces run. The still-ground specialisation gets the same value (its scrim is ramp*m, zero). A new source-shape test pins the threshold against the coverage smoothstep's top edge, the closing expressions, the shadow text shared by the exit and the body, and that no card work sits in the exit; it also replays the identity in f32 over d >= 1. Expected saving: 0.3-0.8M GPU cycles a frame on grid-pong. That is an estimate from the pad's share of the card's fragments, not a measurement; it is to be measured on the TV (hwcnt and the miss legs). The simulator renders desktop GL and ignores mediump, so it cannot show the device's rounding. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d shader claims Review of the pad exit: - fs_img.frag: drop the "Midgard branches per 2x2 quad" sentence (the file and gfx.rs say branching is per-thread) and say the fast-path draws "never execute" the plain pad exit instead of claiming they "pay nothing" for it. - the_card_shaders_pad_exit_is_the_shadow_alone: the focus program's box-proxy zero-write must be nested inside `if (d >= 1.0)`, once, before the exit's `length(qs)` and shadow-alone write (hoisting it out stayed green). - the_card_shaders_pad_exit_tail_and_inputs_are_untouched: in every variant the statements after the body's last `sh = ... (1.0 - m);` are exactly the closing gl_FragColor expression, and neither `d` after the exit nor `m` after its definition is assigned again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21
added a commit
that referenced
this pull request
Oct 24, 2026
) ## 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: - **Build:** `make ARM_PROFILE=release deploy` of 6bea562. - **Runner:** `tests/run.py --fps --mock`, panel off, no sampler. - **Control:** the same base plus #980. - **GPU counters:** `plxnative-hwcnt=frame.ui`, GPU_ACTIVE per frame, first 60 frames discarded. - **Misses:** from separate runs with no counters. | 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. TV pixel check (2026-10-24, release build of main + this + #985, UI-plane GRAPHIC capture on the mock catalog, the TV's own OSD masked): Home with the hero is 0 px different from the pre-work build (3e6665a); on the Home shelves and the library grid the only differing pixels (1118 and 20, each 1/255 in red) sit in the card shadow pad, which only #985 touches. Nothing this change draws differs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
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.
Outcome: closed without merging (TV-measured, 2026-10-24)
This version is pixel-identical, but it saves nothing net, so it does not land.
Pixels. UI-plane capture on the TV, release build, synthetic mock:
shader compile FAILED/link failedlines in every run.GPU. HWCNT
GPU_ACTIVEp50 per frame. Base and this head were run alternately on one set in one session (base, head, head, base). Base isorigin/mainfbafac6, which is this head's own base, so the comparison includes #980, #981 and #983.Both pairs point the same way on both scenes. With the pad back on the body's shared tail, the plain program only skips the rim's
max/abs/mul/mixon pad fragments. That is worth less than what the bigger program costs the hero's otherIPROGdraws, which is the register-pressure risk named below; the first version's hero row (no change) did not show it. Neither scene gets near the ~8M miss knee on this lever.The first version (d54cac1, the separate pad exit) saved 0.26M on grid but is NOT picture-identical: red was 1/255 lower on 1,118 shelves px and 20 library px. Whether that trade is acceptable is the owner's decision, so it is not landed either.
What
fs_img.frag(the card composite) no longer runs the lit-glass and rim work for a fragment withd >= 1.0, i.e. outside the rounded card body. This is lever F1 of the grid-pong GPU budget. It applies to thePLX_FOCUSprogram (the focused or risen card) and to the plain program (a resting card's ring pieces, and a card drawn whole).PLX_STILL_GROUNDshares the plain text.Correction to the first version of this PR. That version said the picture was identical. It was not: its pad exit wrote
vec4(0, 0, 0, sh)from its own copy of the body's shadow expression, and on the TV (Mali-T820, release build, 2026-10-24, UI-plane capture, deterministic across boots) a build with it differed from the pre-change build in 1,118 px on the Home shelves screen and 20 px on the library grid. Every differing pixel is the red channel lower by exactly 1/255, and every one sits 1-5 px outside a resting card's edge (the shadow pad,d >= 1.0). Nothing else differs; Home with the hero is 0 px. The simulator evidence below could not see this: it is desktop GL, which ignoresmediump.This version. There is no exit any more.
m = 1.0 - smoothstep(-1.0, 1.0, d)is computed once for every fragment, thenif (d < 1.0) { ... }wraps only the work that changestex(the glow, glare and gloss of the focus program, and the rim). The shadow and the closinggl_FragColorwrite exist once after the gate, so a pad fragment runs the body's own instructions withtexandtathe raw sample, instead of a second transcription of them. The focus program's fully-transparent early exit (d >= 1.0and the shadow's box proxy past its falloff) is main's again, verbatim. TV re-verification of this version is pending; the device tables below were measured on the first version.Why (measured on the TV 2026-10-24)
Class::Card) cost 3.58M of it. The focus program alone costs about 1.82M, at roughly 13 arithmetic words a pixel on about 258K px a frame.vec4(0.0)exit for the part of the pad the shadow's box proxy had cleared; the rest of the pad, where the shadow still reaches, did not.What the saving is now, and what it costs
mix(a handful of arithmetic ops; nomalioccount was taken). The first version also skippedsmoothstepfor these fragments; they pay it again here, and they pay the shadow they always paid.texnow merges from two paths into the tail andsmoothstepruns on pad fragments. Sharing the tail's text is what the first version lacked, but it does not by itself guarantee the Mali compiler schedules or rounds the tail the same as the pre-change build, so this is not claimed bit-exact until the TV shows it.Why the picture should be identical
For
d >= 1.0,mis0.0wheresmoothstepclamps to its top edge, sotex*mis0whatever the glow, glare, gloss and rim made oftex: they reach onlytex, never the alpha. Nothing else adds in outside the body (no outer glow halo, focus ring or drop-shadow tint).stillOver(tex*m, ta*m + sh, m, ramp)has scrimramp*mandkeep = (ta*m + sh)*(1 - scrim). The gate writes no fragment, never returns and assigns nothing buttexamong the values the tail reads, so a fragment on either side ofd = 1takes the same tail with the samem,ta,dand shadow inputs; onlytexdiffers, andmzeroes it.Simulator evidence for the FIRST version (cannot show the difference above)
Evidence on the macOS simulator (settled raw 3840x2160
shot.pngfromtools/screenshots.py --keep, sceneshome-shelves,library-grid,home; the simulator is desktop GL and ignoresmediump, so it cannot show the device's rounding, which is the manager's device half):home-shelvesshows 843,932 magenta px (10.2% of the frame) andlibrary-grid811,738 px (9.8%). The magenta rings every resting card (plain program) and the focused card's whole inflated quad (focus program). Inlibrary-gridthe pixels that changed against the real branch capture are exactly the magenta ones (811,738 of 811,738). Inhome-shelves3,310 changed pixels are not magenta; all lie in one 600x150 px box (x 365-964, y 1263-1413) at the "8m left" label under the focused card (its text is drawn over the pad, so the glyph edges blend with magenta there). The binary fingerprints differ as expected: the main binary has noif (d >= 1.0) {, the branch and magenta ones do.library-grid: bit-identical. 7 captures (4 on main, 3 on this branch): every pair 0 differing px, max delta 0.home-shelves: main1 = main(m1) = branch = branch(b1), all four bit-identical (0 differing px). Run-to-run noise exists on main itself: main1 vs main2 341 px (max delta 1), main1 vs m2 1,145 px (max delta 1). One branch run (b2) differs from every other run by 7,807 to 8,952 px, max delta 1; against the identical quartet the difference is confined to x 1317-1543, y 131-231, the top nav pill's Home tab area, far from any card. Counted against the magenta pad mask, the differing pixels that fall ON a pad are 0 for every branch-vs-main pair except those against the main run m2; the same 67 on-pad pixels (max delta 1) separate m2 from main1, from main2 and from every branch run, so they are main's own noise.home: the whole hero frame is not deterministic on main either. 5 main and 4 branch captures: main-vs-main differs by 449 to 1,802 px in the Resume button (x 182-790, y 1425-1559, max delta 2), and one main capture (main3) differs from every other capture, main and branch alike, by 9.9K to 11.7K px over the whole frame (max delta 2). Branch-vs-main (main3 aside) differs by 2 to 2,399 px in the same Resume-button box (max delta 2); branch-vs-branch is 833 to 2,397 px there. With the magenta pad mask ofhome(221,277 px, all below y 1650), the pad-pixel count is 0 for every pair I counted among main1, main2, main4 and the branch runs (and for the branch against main5); only the pairs with main3 have any (79 px, identical for main1-vs-main3 and branch-vs-main3). The Resume button is outside every pad.So branch-vs-main shows no difference outside the noise main-vs-main already has, and no difference on a pad pixel at all.
Tests
the_card_shaders_pad_path_runs_the_bodys_shadow_tailreplacesthe_card_shaders_pad_exit_is_the_shadow_aloneand..._pad_exit_tail_and_inputs_are_untouched. For the plain, still and focus programs it pins: the coverage, the shadow and the closing write each appear once (oneu_shcol.a, onesmoothstep); the lit work (glow,gloss,glareTop,glareZone,ease,topDist,chh,rim,u_rimcol,u_rimw) appears only inside theif (d < 1.0)gate; the gate follows the coverage directly, contains noreturn,gl_FragColor,elseordiscard, and assigns none ofm,ta,d,sh,dShadow; what follows the gate is exactly the shadow (dShadow/dShadowBox/qsas the body has them in the focus program) and the closing write; and the focus program's transparent early exit is main's, once, ahead of the shadow'slength().make test-crate C=plx_gfx T=pad_path_runs, the branch's oldfs_img.fragunder the new test):assertion `left == right` failed: plain: the shadow's strength is read in more than one place(left: 2,right: 1), thentest result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 168 filtered out.test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 168 filtered out; finished in 0.00s. A temporaryta *= 0.5;inside the gate fails it (the pad gate assigns `ta`, which the tail reads on both paths); reverted.make test-crate C=plx_gfxon the committed tree:test result: ok. 169 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 4.21s.make check-nodef: exit 0.make checkon the committed tree (head 01d80ab): exit 0,==== check: 106 steps — all ok (300s wall, 405s cpu, 4 at once ...), and itsplx_gfxline istest result: ok. 169 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 49.33s. A first run failed only onci/check-rust-inputs.py(No module named tomllib: the non-login shell resolvespython3to 3.9.6); the passing run had a Python 3.12 first onPATH.PLX_FOCUSvariant would makeFOCUS_IMAGEfail to link and fall back silently to the plain program, so the TV run must confirm from the log that both programs linked, not only compare resting-card pixels.Header and test-doc prose
fs_img.frag's header (and thean_unfocused_program_carries_none_of_the_focus_codedoc) said the plain program is byte-for-byte the pre-focus program. It is now that program plus ONE later addition, its pad path, and both say so. This branch mergesorigin/main(#983,fs_tex.frag); the two comment conflicts take both versions.Risk to watch on the device
The plain program (
IPROG) also runs glyphs, blur reductions andFrameCachequads. They leave through theu_card.z < 0.5fast path above the gate, so the gate is reached only by rounded cards, but the shader header records a TV A/B where growingIPROGcost every draw. Please check non-cardIPROGdraws and the program's register use, not only theClass::Cardcycles.To verify on the TV before this leaves draft
Device measurement (TV, 2026-10-24) - the FIRST version (the exit), not this head
Release build (
ARM_PROFILE=release), panel off, sound off, synthetic mock. The control is #980's build on the same base (it changes nothing the GPU draws). HWCNTGPU_ACTIVEper frame (plxnative-hwcnt=frame.ui, ~3,100 frames, the first 60 discarded):IPROGdrawsMissed refreshes on grid-pong, separate runs with no counters armed, cycles 2-60: this PR 12, 15, 11; control 15, 11, 9. Each run also has one cycle-1 miss. This branch predates #980, and in all three runs the frame right after the
egl surface (after 120 presents)line is aFRAMEDROPwithswap=13.2, 13.2 and 12.7 ms: thelate_probeblock #980 removed. At 9.67M the grid is still above the ~8M knee, so the miss count is not expected to move on this lever alone. The saving is measured; whether it shows in misses depends on the other levers.maliocregister counts were not taken (no Mali Offline Compiler on this host). The hero row is the device-side answer to theIPROGregister-pressure question above: its draws do not get slower.No linked issue.
🤖 Generated with Claude Code