Skip to content

gfx: a two-stop ramp program for square unfocused gradients (off fs_src's flat path) - #981

Merged
GLinnik21 merged 2 commits into
mainfrom
gfx/ramp-program
Oct 24, 2026
Merged

GLinnik21 merged 2 commits into
mainfrom
gfx/ramp-program

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

What / why

Home's hero backdrop draws two full-width "ramp band" quads (~1.37M px a frame) through gfx::draw_rect. They land in fs_src.frag's flat fast path (mix(u_colTop, u_colBot, vy) behind a uniform branch), which HWCNT measured at ~3 arithmetic words per pixel on the TV (2026-10-24) where a bare mix is ~1-1.5: the branch runs on every fragment, and Midgard sizes the register file for the whole 12 KB shader, which lowers occupancy.

This adds shaders/fs_ramp.frag: that one expression and nothing else, same precision qualifiers as fs_src.frag, undithered like the path it replaces. Linked beside FS_FLAT with the same fallback on a failed link.

Routing is a pure function, rect_fill(radius, focus, one_colour): radius < 0.5 && focus < 0.001 is fs_src.frag's own flat-path test, so a rect leaves that program only when the shader would have skipped the SDF for it. One colour goes to the flat program, two colours to the ramp program, everything else stays on the fill program. The quad is exactly the rect's bounds (aa = 0, as on that path) and gate(Class::Rect, ..) still books the draw before a program is chosen.

  • draw_rect routes. draw_rrect is single-colour (no ramp case). draw_rect_sheened / draw_rect_shaped are left alone: they always inflate the quad by AA_BLEED, so a ramp quad would not draw the same fringe.
  • The ambient program is not touched (routing the ramps through it measured 0.6M cycles dearer on 2026-09-02, and it is not pixel-identical).
  • Stale prose in fs_src.frag (it said scrims take that path) corrected; comment-only.
  • Estimated saving (an ESTIMATE, to be measured on the TV): 0.7-1.3M GPU cycles a frame on the hero-pong bench (budget ~11.2M).

Identity evidence (macOS simulator, desktop GL)

tools/screenshots.py --only home,home-shelves --keep, raw shot.png (3840x2160) compared with Pillow; origin/main captured twice, this branch once.

pair scene max channel delta (R,G,B) differing px
main vs main home 0,0,0 0
main vs main home-shelves 0,1,0 2
branch vs main (both main captures) home 1,1,1 2879
branch vs main home-shelves 0,1,0 and 0,0,0 2 and 0
  • Does the capture exercise the new program? Yes for home: with the ramp shader temporarily replaced by a solid colour, 3,814,203 px changed. home-shelves has NO ramp draw (0 px changed), so it only shows the flat/fill routing is undisturbed.
  • Not a clean pass on home. The max delta is 1, as in the main-vs-main noise bound, but main-vs-main on home is 0 differing px and the branch differs in 2879 px (0.075% of the 3.8M-px ramp region). All 2879 lie inside the ramp region (0 outside), the sign is mixed (2080 brighter, 784 darker), spread over 617 rows (at most 63 a row). That is the signature of the driver compiling the same mix differently in a different program (rounding order), not of a geometry change, but the simulator cannot tell us what the Mali compiler does with fp16 mix. Same expression and same qualifiers on device are pinned by a unit test; a device pixel-diff of the hero is the real check and is pending.

Local tests

  • make test-crate C=plx_gfx T=ramp: test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 159 filtered out
  • make test-crate C=plx_gfx: test result: ok. 161 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (includes the dither-prelude-free shader list, now with fs_ramp.frag, and the LOC_RGB_CAP source test)
  • make check-nodef: finished clean.
  • make check was not run locally (congested machine); CI is the gate.

Device measurement

Measured on the dev TV (Mali-T820, webOS 4.5) on 2026-10-24. The build was make ARM_PROFILE=release deploy of 503562c, run with tests/run.py --fps --mock, the panel off and no sampler. The control is the same base plus #980 (the late-probe gate), measured the same day. The counters come from plxnative-hwcnt=frame.ui, GPU_ACTIVE per frame after the first 60 frames are discarded. Misses come from separate runs without the 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.58M (-0.69M) 11.39M 8, 7, 7
grid-pong control 9.93M 11.54M 15, 11, 9
grid-pong this PR 9.93M (no ramp bands on that page) 11.56M not run

No linked issue.

🤖 Generated with Claude Code

GLinnik21 and others added 2 commits October 24, 2026 12:26
…rc's flat path)

Home's hero backdrop draws two full-width ramp bands (~1.37M px a frame)
through gfx::draw_rect. They land in fs_src.frag's flat fast path
(`mix(u_colTop, u_colBot, vy)` behind a uniform branch), which HWCNT put
at ~3 arithmetic words per pixel on the TV (2026-10-24) where a bare mix
is ~1-1.5: the branch runs on every fragment, and Midgard sizes the
register file for the whole 12 KB shader, which lowers occupancy.

shaders/fs_ramp.frag is that one expression and nothing else, with the
same precision qualifiers as fs_src.frag, undithered like the path it
replaces. It is linked beside FS_FLAT with the same fallback on a failed
link (fs_src's flat path, as before). The routing is a pure function,
rect_fill(radius, focus, one_colour): radius < 0.5 && focus < 0.001 is
fs_src.frag's own flat-path test, so a rect leaves that program only when
the shader would have skipped the SDF for it; one colour goes to the flat
program, two to the ramp program. The quad is exactly the rect's bounds
(aa = 0, as on that path), and gate(Class::Rect, ..) still books the draw
before a program is chosen. draw_rrect is single-colour, and
draw_rect_sheened/shaped always inflate the quad by AA_BLEED, so neither
routes.

Expected saving is an ESTIMATE, to be measured on the TV: 0.7-1.3M GPU
cycles a frame on the hero-pong bench (budget ~11.2M).

Tests: the routing function and its thresholds from both sides (NaN
included); fs_ramp.frag's expression and qualifiers read out of both
shaders and compared; the draw keeps the exact bounds, the ledger gate
before the routing, and the fallback; fs_ramp.frag joins the
dither-prelude-free list. Stale prose in fs_src.frag (scrims no longer
take that path) corrected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
link_program exits the process on a compile rejection, so the ramp program's fallback to fs_src's flat path was unreachable for exactly that failure. RPROG now links through link_optional_program, and the comments say compile or link. The source-shape test cuts the Flat and Ramp arms out of draw_rect's routing and requires each to call its own program (a swap kept both calls in the function and passed the old check), and requires RPROG to be built from VS_SRC + FS_RAMP optionally. rect_fill's doc notes that the shader's u_focus compare may run in fp16, and two shader comments no longer claim what the routing made false.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 marked this pull request as ready for review October 24, 2026 10:34
@GLinnik21
GLinnik21 merged commit 65e976b into main Oct 24, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the gfx/ramp-program branch October 24, 2026 10:34
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
## What broke

#981 (65e976b) added `rust-modules/gfx/src/shaders/fs_ramp.frag`, whose line-8 comment spells the dev-trigger name `plxnative-hwcnt`. `glsl!` embeds a shader source whole (`concat!(include_str!(..), "\0")`, comments included; nothing strips them), so the name was compiled into the binary. The Nightly workflow's `make ipk` step then failed `ci/check-package.py`'s packaged-binary scan:

`the com.beb.plxnative.nightly package carries no dev-trigger surface ... (found plxnative-hwcnt)`

(seen on PR #991's "ARM build + gates / build + verify" job). #981's only other `plxnative-hwcnt` is a plain `//` comment in `gfx.rs`, which is not compiled in.

## The fix

- `fs_ramp.frag`: line 8 now reads `(HWCNT, 2026-10-24)` instead of naming the trigger. A comment only, so the compiled program is unchanged.
- New test `gfx::tests::no_shader_source_names_a_dev_trigger` reads EVERY file under `rust-modules/gfx/src/shaders/` (it lists the directory, so a new shader is covered by being added; that is the only `shaders/` directory in the tree) and fails on any `plxnative-`. The scan matches the dev-trigger catalog's names (`dev.rs` `DIAG` + `devtrig.rs` `CONTROLLED`, minus the release-legitimate allowlist); the test matches the whole prefix, a superset that nothing in a shader needs, and the failure message says why.

## Red / green

Red, before the reword (`make test-crate C=plx_gfx T=no_shader_source_names_a_dev_trigger`):

```
test gfx::tests::no_shader_source_names_a_dev_trigger ... FAILED
.../rust-modules/gfx/src/shaders/fs_ramp.frag:8: // arithmetic words (`plxnative-hwcnt`, 2026-10-24) where one `mix` is 1-1.5: the three uniform
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 163 filtered out; finished in 0.00s
```

Green, after:

```
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 163 filtered out; finished in 0.00s
```

Whole crate (`make test-crate C=plx_gfx`): `test result: ok. 164 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out`. `make check-nodef` passes. Full `make check` is left to CI.

No linked issue.

Co-Authored-By: Claude Opus 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