LDS bounds exemption: whole 16-digit hashes only, and with_program restores the thread state (follow-up to #938) #2368

Manually merged
github merged 1 commit from github-bot/gh-2368 into main 2026-11-30 14:17:00 +00:00 AGit
Owner

@⁠Victorywillbeours222 on GitHub · 2026-11-29 12:24 UTC · original
Victorywillbeours222:lds-exempt-exact-keys → main · +144 −22 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Follow-up to #938 (face programs exempt from VICTORY_LDS_BOUNDS). It fixes the two points @⁠Yuanzer raised in the review there, which were still open on main.

1. VICTORY_LDS_BOUNDS_EXEMPT matches whole hashes, not prefixes

Before this, lds_bounds_exempt() used starts_with, so VICTORY_LDS_BOUNDS_EXEMPT=a took the bounds off every program whose hash starts with a.

Now:

  • Each entry has to be exactly 16 ASCII hex digits. It is compared to the program's hash with case-insensitive equality (eq_ignore_ascii_case).
  • Any other entry (a shorter prefix, a non-hex string) is ignored. One eprintln! line names the ignored entries when the list is first read, so this happens once per process.
  • 0, empty and all mean what they meant before: none, none, and every program.
  • Parsing and matching are split into two small pure functions (exempt_list, exempt), so they can be tested without setting the env var.

2. with_program restores the thread state on return and on unwind

with_program now saves what was on the thread (the program hash, plus the lds_clamped / lds_clamped_mesh counts it resets) and puts it back from a small Drop guard. So:

  • a nested call gives the outer program, and its count, back when it returns;
  • a translation that panics no longer leaves its hash behind on a reused worker thread.

It still allocates nothing at the top level (the saved outer hash is empty there). Only a nested call clones the outer hash.

Tests

New tests in emit/lower/analysis.rs:

  • an_lds_bounds_exempt_entry_names_a_whole_program_hash: an exact hash matches, in either case. Prefixes (38a6, 3, 15 digits) and a 16-character non-hex entry match nothing and are reported as ignored.
  • lds_bounds_exempt_zero_is_none_and_unset_is_the_face_programs: 0 and empty exempt nothing. Unset gives the 25 face programs and only those. all exempts everything.
  • a_nested_with_program_gives_the_outer_program_back: the hash and the clamped count come back after an inner call.
  • a_panicking_translation_leaves_the_program_it_found: under std::panic::catch_unwind, at the top level and nested.

cargo test -p victory-shader (Windows, Rust 1.98.1): 466 passed, 0 failed, 9 ignored.

cargo clippy -p victory-shader --all-targets: no new warnings. Four warnings are already on main, all outside this change, and they would fail -D warnings (line numbers as on main):

  • emit/lower/analysis.rs:6: unused import PAIR_MEETINGS
  • emit/lower.rs:594: unused import analysis::lane_regions
  • emit/lower/analysis.rs:467: while_immutable_condition (the while loads loop)
  • native.rs:1655: too_many_arguments (the test helper record, 8 arguments)

Not changed

  • The default list of 25 face hashes is the same, so the measured face fix from #938 is unchanged when the variable is unset.
  • VICTORY_WAVE_WIDE_FALLBACK_SKIP (documented as taking hash prefixes) and VICTORY_LDS_LAST_RESORT still match by prefix. The review was only about the LDS exemption, so I left them alone.
**@⁠Victorywillbeours222** on GitHub · 2026-11-29 12:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2368) `Victorywillbeours222:lds-exempt-exact-keys` → `main` · +144 −22 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC Follow-up to #938 (face programs exempt from `VICTORY_LDS_BOUNDS`). It fixes the two points @⁠Yuanzer raised in the review there, which were still open on main. ## 1. `VICTORY_LDS_BOUNDS_EXEMPT` matches whole hashes, not prefixes Before this, `lds_bounds_exempt()` used `starts_with`, so `VICTORY_LDS_BOUNDS_EXEMPT=a` took the bounds off every program whose hash starts with `a`. Now: - Each entry has to be exactly 16 ASCII hex digits. It is compared to the program's hash with case-insensitive equality (`eq_ignore_ascii_case`). - Any other entry (a shorter prefix, a non-hex string) is ignored. One `eprintln!` line names the ignored entries when the list is first read, so this happens once per process. - `0`, empty and `all` mean what they meant before: none, none, and every program. - Parsing and matching are split into two small pure functions (`exempt_list`, `exempt`), so they can be tested without setting the env var. ## 2. `with_program` restores the thread state on return and on unwind `with_program` now saves what was on the thread (the program hash, plus the `lds_clamped` / `lds_clamped_mesh` counts it resets) and puts it back from a small `Drop` guard. So: - a nested call gives the outer program, and its count, back when it returns; - a translation that panics no longer leaves its hash behind on a reused worker thread. It still allocates nothing at the top level (the saved outer hash is empty there). Only a nested call clones the outer hash. ## Tests New tests in `emit/lower/analysis.rs`: - `an_lds_bounds_exempt_entry_names_a_whole_program_hash`: an exact hash matches, in either case. Prefixes (`38a6`, `3`, 15 digits) and a 16-character non-hex entry match nothing and are reported as ignored. - `lds_bounds_exempt_zero_is_none_and_unset_is_the_face_programs`: `0` and empty exempt nothing. Unset gives the 25 face programs and only those. `all` exempts everything. - `a_nested_with_program_gives_the_outer_program_back`: the hash and the clamped count come back after an inner call. - `a_panicking_translation_leaves_the_program_it_found`: under `std::panic::catch_unwind`, at the top level and nested. `cargo test -p victory-shader` (Windows, Rust 1.98.1): 466 passed, 0 failed, 9 ignored. `cargo clippy -p victory-shader --all-targets`: no new warnings. Four warnings are already on main, all outside this change, and they would fail `-D warnings` (line numbers as on main): - `emit/lower/analysis.rs:6`: unused import `PAIR_MEETINGS` - `emit/lower.rs:594`: unused import `analysis::lane_regions` - `emit/lower/analysis.rs:467`: `while_immutable_condition` (the `while loads` loop) - `native.rs:1655`: `too_many_arguments` (the test helper `record`, 8 arguments) ## Not changed - The default list of 25 face hashes is the same, so the measured face fix from #938 is unchanged when the variable is unset. - `VICTORY_WAVE_WIDE_FALLBACK_SKIP` (documented as taking hash prefixes) and `VICTORY_LDS_LAST_RESORT` still match by prefix. The review was only about the LDS exemption, so I left them alone.
Follow-up to #938, for the two points in Yuanzer's review:

- VICTORY_LDS_BOUNDS_EXEMPT entries have to be exactly 16 hex digits and
  are compared whole, ignoring case, instead of as prefixes. Any other
  entry is ignored, with one warning when the list is first read. `0`,
  empty and `all` mean what they did, and the default list of 25 face
  programs is unchanged.
- with_program saves the thread's program and its LDS counts and puts
  them back from a Drop guard. A nested call gets the outer program back,
  and a translation that panics leaves no stale hash on the thread.

Tests: an exact hash matches while prefixes and non-hex entries do not;
`0`, unset and `all`; a nested call; catch_unwind at the top level and
nested.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 12:27:24 +00:00
github manually merged commit dade61e4a8 into main 2026-11-30 14:17:00 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2368
No description provided.