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

Merged
Victorywillbeours222 merged 1 commit from upstream-pr/2368 into main 2026-11-30 14:12:03 +00:00
Victorywillbeours222 commented 2026-11-29 12:24:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Victorywillbeours222 on 2026-11-29T12:24:39Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5550676195 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2368). Originally posted by [Victorywillbeours222](https://github.com/Victorywillbeours222) on 2026-11-29T12:24:39Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
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.

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