Shaders: CS_TraceShadowRays_FullAdaptive translates (joins fed by a scalar load are data, on the retry only) #2993

Open
github-bot wants to merge 2 commits from github-bot/gh-2993 into main AGit
Owner

@⁠JohnNajar on GitHub · 2026-11-29 19:15 UTC · original
JohnNajar:fix/loaded-join-masks → main · +102 −1 · 4 files · 2 commits · open

Makes the last untranslated program in shaders.rpf translate: shadowmask:CS_TraceShadowRays_FullAdaptive (#dbdbf36298727135), the ray-traced shadow pass. It failed with "a lane mask holding lanes elsewhere read as data" at 0xae80.

The cause

At 0xae74 the program compares s35 with each lane: v_cmp_ne_u32 vcc_lo, s35, v62. s35 is plain data:

  • s31 = s27 & 0x001fffff (0x9a38)
  • s32 = (s23 << 5) & 0xffe00000 (0x9a80, 0x9a94)
  • s35 = s32 | s31 (0x9c84)

The structurizer still records s35 as a lane mask. s27 reaches 0x9a38 through a join: one value comes from s_buffer_load_dwordx2 s[26:27] (0x8838), and the other is an earlier join that holds a saved EXEC, left in the same register. Since that join counts as derived, the bit-field arithmetic becomes a mask, and lower::mask_dword refuses its numeric read in a block where not every lane runs.

The change

Only after that refusal, the program is translated once more with joins that have a value straight from s_load_* / s_buffer_load_* taken as data (structure::with_loaded_joins_data). Lane masks come from compares and EXEC, never from a constant buffer. The retry is in emit::translate, which is what a run uses, and in victory translate, so the listing says what a run does.

Because it is a retry, no program that translated before changes.

Checked

  • victory translate --list shaders.rpf: 25,694 of 25,694 programs emit. The other 25,693 emit byte-identical DXIL to the build without the change, compared by hash per program.
  • #dbdbf36298727135 emits (1fd0654fbc824f1d), passes dxil.dll's validator (--validate), and makes a pipeline (--pipelines) on an RTX 3090 (driver 621.40). Rebuilt and rechecked on this branch (on top of f889bb07).
  • Not seen running in the game yet. Ray tracing froze at start on this PC (#2973). With the workaround it runs, but the scenes reached in those runs did not use this program. Testing in a scene with ray-traced shadows would be welcome.

Earlier reports

  • #2843 "GFX10 code at 0xae80" may be the same program.
**@⁠JohnNajar** on GitHub · 2026-11-29 19:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993) `JohnNajar:fix/loaded-join-masks` → `main` · +102 −1 · 4 files · 2 commits · open Makes the last untranslated program in `shaders.rpf` translate: `shadowmask:CS_TraceShadowRays_FullAdaptive` (`#dbdbf36298727135`), the ray-traced shadow pass. It failed with "a lane mask holding lanes elsewhere read as data" at 0xae80. ### The cause At 0xae74 the program compares `s35` with each lane: `v_cmp_ne_u32 vcc_lo, s35, v62`. `s35` is plain data: - `s31 = s27 & 0x001fffff` (0x9a38) - `s32 = (s23 << 5) & 0xffe00000` (0x9a80, 0x9a94) - `s35 = s32 | s31` (0x9c84) The structurizer still records `s35` as a lane mask. `s27` reaches 0x9a38 through a join: one value comes from `s_buffer_load_dwordx2 s[26:27]` (0x8838), and the other is an earlier join that holds a saved EXEC, left in the same register. Since that join counts as derived, the bit-field arithmetic becomes a mask, and `lower::mask_dword` refuses its numeric read in a block where not every lane runs. ### The change Only **after** that refusal, the program is translated once more with joins that have a value straight from `s_load_*` / `s_buffer_load_*` taken as data (`structure::with_loaded_joins_data`). Lane masks come from compares and EXEC, never from a constant buffer. The retry is in `emit::translate`, which is what a run uses, and in `victory translate`, so the listing says what a run does. Because it is a retry, no program that translated before changes. ### Checked - `victory translate --list shaders.rpf`: **25,694 of 25,694** programs emit. The other 25,693 emit **byte-identical** DXIL to the build without the change, compared by hash per program. - `#dbdbf36298727135` emits (`1fd0654fbc824f1d`), passes `dxil.dll`'s validator (`--validate`), and makes a pipeline (`--pipelines`) on an RTX 3090 (driver 621.40). Rebuilt and rechecked on this branch (on top of `f889bb07`). - **Not seen running in the game yet.** Ray tracing froze at start on this PC (#2973). With the workaround it runs, but the scenes reached in those runs did not use this program. Testing in a scene with ray-traced shadows would be welcome. ### Earlier reports - #2843 "GFX10 code at 0xae80" may be the same program.
shadowmask:CS_TraceShadowRays_FullAdaptive (#dbdbf36298727135), the one program of
shaders.rpf that did not translate ("a lane mask holding lanes elsewhere read as data" at
0xae80), compares s35 with each lane at 0xae74. s35 is data: two bit fields of values loaded
from a constant buffer (0x9a38, 0x9a80/0x9a94, joined at 0x9c84). The structurizer still made it
a lane mask, through a join whose other value is a saved EXEC left in the same register
(the compiler reuses s27 for both).

Only after that refusal, translate once more with joins of which one value comes straight from
s_load_*/s_buffer_load_* taken as data (structure::with_loaded_joins_data), in emit::translate
and in `victory translate`. Every program that translated before is untouched: on shaders.rpf
all 25,693 others emit byte-identical DXIL; this one now emits, passes dxil.dll's validator
and makes a pipeline (RTX 3090).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 19:19:25 +00:00
Author
Owner

@⁠AimLogin on GitHub · 2026-11-29 20:46 UTC · original

Review note (read at head 491656bf, not run):

The new thread-local LOADED_JOINS_DATA is set and reset by hand (replace(true) … set(was)). Once #2917 lands, translator panics are caught and the worker thread goes on translating. A panic inside this scope would then leave the flag set, and every later program on that worker would treat loaded joins as data without anyone noticing. Routing it through #2917's with_flag guard, as the other translator switches now do, would close that.

Two small asks for confidence:

  • a census diff over a corpus showing only the intended program's module changes;
  • a test with a control that fails without the change.

AI-assisted review.

**@⁠AimLogin** on GitHub · 2026-11-29 20:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993#issuecomment-7262344269) Review note (read at head 491656bf, not run): The new thread-local `LOADED_JOINS_DATA` is set and reset by hand (`replace(true)` … `set(was)`). Once #2917 lands, translator panics are caught and the worker thread goes on translating. A panic inside this scope would then leave the flag set, and every later program on that worker would treat loaded joins as data without anyone noticing. Routing it through #2917's `with_flag` guard, as the other translator switches now do, would close that. Two small asks for confidence: - a census diff over a corpus showing only the intended program's module changes; - a test with a control that fails without the change. _AI-assisted review._
Review of #2993: with_loaded_joins_data set and reset its thread-local by hand, so a translator panic
caught further up (#2917) would leave it on for every later program on that worker. A guard now puts
it back on unwind too (the_switch_is_put_back_after_a_panic); it can become #2917's with_flag once
that lands.

a_join_fed_by_a_scalar_load_is_data_on_the_retry rebuilds CS_TraceShadowRays_FullAdaptive's case in
fourteen words: a saved EXEC on one path and s_buffer_load_dword on the other, joined, cut to a bit
field and read as a number where not every lane runs. Without the retry it is refused with
MASK_ELSEWHERE (the test checks that as its control); with it, it lowers. With the rule disabled the
test fails with that same refusal. cargo test -p victory-shader: 464 passed, 0 failed, 9 ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠JohnNajar on GitHub · 2026-11-29 22:34 UTC · original

Thanks for the review. All three points are addressed in 960088ce:

The switch is now put back on unwind. with_loaded_joins_data restores the thread-local through a Drop guard, so a panic inside the retry, as caught by #2917, no longer leaves it on for later programs on that worker. Test: structure::loaded_joins_tests::the_switch_is_put_back_after_a_panic (catch_unwind around a panicking scope, then checks the switch is off). When #2917 lands, this can become its with_flag.

A test with a control: emit::lower::tests::a_join_fed_by_a_scalar_load_is_data_on_the_retry. It rebuilds the case in fourteen words:

  • a saved EXEC (s_mov_b32 s27, exec_lo) on one path, s_buffer_load_dword s27 on the other
  • joined, cut to a bit field (s_and_b32 s31, s27, 0x1fffff)
  • read as a number (v_mov_b32 v0, s31) inside an s_and_saveexec

Control: without the retry it must be refused with MASK_ELSEWHERE, and it is. With with_loaded_joins_data it lowers. With the rule disabled (if false && loaded_data), the test fails with "a lane mask holding lanes elsewhere read as data" at the same place.

cargo test -p victory-shader: 464 passed, 0 failed, 9 ignored.

Census diff, victory translate --list shaders.rpf (GTA VI 1.0.2.1), without and with the change, compared by emitted-DXIL hash per program:

programs emitted changed hash lost new
without 25,694 25,693
with 25,694 25,694 0 0 1: #dbdbf36298727135 → 1fd0654fbc824f1d

So only the intended program's module changes. It also passes dxil.dll's validator and makes a pipeline on an RTX 3090 (--validate --pipelines). This census is from the first version of the retry. The guard commit does not change what is emitted, and the retry path is the same.

**@⁠JohnNajar** on GitHub · 2026-11-29 22:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993#issuecomment-7263777313) Thanks for the review. All three points are addressed in 960088ce: **The switch is now put back on unwind.** `with_loaded_joins_data` restores the thread-local through a `Drop` guard, so a panic inside the retry, as caught by #2917, no longer leaves it on for later programs on that worker. Test: `structure::loaded_joins_tests::the_switch_is_put_back_after_a_panic` (`catch_unwind` around a panicking scope, then checks the switch is off). When #2917 lands, this can become its `with_flag`. **A test with a control:** `emit::lower::tests::a_join_fed_by_a_scalar_load_is_data_on_the_retry`. It rebuilds the case in fourteen words: - a saved EXEC (`s_mov_b32 s27, exec_lo`) on one path, `s_buffer_load_dword s27` on the other - joined, cut to a bit field (`s_and_b32 s31, s27, 0x1fffff`) - read as a number (`v_mov_b32 v0, s31`) inside an `s_and_saveexec` Control: without the retry it must be refused with `MASK_ELSEWHERE`, and it is. With `with_loaded_joins_data` it lowers. With the rule disabled (`if false && loaded_data`), the test fails with "a lane mask holding lanes elsewhere read as data" at the same place. `cargo test -p victory-shader`: 464 passed, 0 failed, 9 ignored. **Census diff**, `victory translate --list shaders.rpf` (GTA VI 1.0.2.1), without and with the change, compared by emitted-DXIL hash per program: | | programs | emitted | changed hash | lost | new | |---|---|---|---|---|---| | without | 25,694 | 25,693 | | | | | with | 25,694 | **25,694** | **0** | **0** | **1**: `#dbdbf36298727135` → `1fd0654fbc824f1d` | So only the intended program's module changes. It also passes `dxil.dll`'s validator and makes a pipeline on an RTX 3090 (`--validate --pipelines`). This census is from the first version of the retry. The guard commit does not change what is emitted, and the retry path is the same.
Author
Owner

@⁠davemathews12 on GitHub · 2026-11-30 18:57 UTC · original

Checked against the full retail shaders.rpf (1.0.2.1), with victory translate --list and VICTORY_EMIT_DUMP. Base: main at 84bd61e2 plus #3687 (so it runs on Linux; that changes nothing on Windows).

main main + this PR
programs translated 26,084 of 26,084 26,084 of 26,084
vertex + pixel DXIL 14,247 of 14,247 14,247 of 14,247
compute DXIL 2,681 of 2,682 2,682 of 2,682
mesh DXIL 8,765 of 8,765 8,765 of 8,765
  • The one refusal on main is the one this targets: CS_TraceShadowRays_FullAdaptive (dbdbf36298727135), "a lane mask holding lanes elsewhere read as data". With this PR it translates.
  • Every other output is byte-identical: 25,693 of 25,693 DXIL containers hash the same with and without the PR. That backs the doc comment's "no program that translated before changes".
  • All 25,694 outputs also pass LLVM's IR verifier (opt -passes=verify, LLVM 18, after replacing DXIL's data layout to get past its i8:32). That's not the DXIL validator, but it means no malformed IR.

Not checked: the DXIL validator, and the shadows on a card.

One note for merging: this conflicts in emit/lower/tests.rs with current main (both add tests at the end of the module). The translator files merge cleanly.

**@⁠davemathews12** on GitHub · 2026-11-30 18:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993#issuecomment-7288623205) Checked against the full retail `shaders.rpf` (1.0.2.1), with `victory translate --list` and `VICTORY_EMIT_DUMP`. Base: main at 84bd61e2 plus #3687 (so it runs on Linux; that changes nothing on Windows). | | main | main + this PR | |---|---|---| | programs translated | 26,084 of 26,084 | 26,084 of 26,084 | | vertex + pixel DXIL | 14,247 of 14,247 | 14,247 of 14,247 | | compute DXIL | **2,681 of 2,682** | **2,682 of 2,682** | | mesh DXIL | 8,765 of 8,765 | 8,765 of 8,765 | - The one refusal on main is the one this targets: `CS_TraceShadowRays_FullAdaptive` (`dbdbf36298727135`), "a lane mask holding lanes elsewhere read as data". With this PR it translates. - **Every other output is byte-identical:** 25,693 of 25,693 DXIL containers hash the same with and without the PR. That backs the doc comment's "no program that translated before changes". - All 25,694 outputs also pass LLVM's IR verifier (`opt -passes=verify`, LLVM 18, after replacing DXIL's data layout to get past its `i8:32`). That's not the DXIL validator, but it means no malformed IR. Not checked: the DXIL validator, and the shadows on a card. One note for merging: this conflicts in `emit/lower/tests.rs` with current main (both add tests at the end of the module). The translator files merge cleanly.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower/tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2993/head:github-bot/gh-2993'
git switch 'github-bot/gh-2993'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2993'
git switch 'github-bot/gh-2993'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2993'
git switch 'github-bot/gh-2993'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2993'
git switch 'main'
git merge --squash 'github-bot/gh-2993'
git switch 'main'
git merge --ff-only 'github-bot/gh-2993'
git switch 'main'
git merge 'github-bot/gh-2993'
git push origin 'main'
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!2993
No description provided.