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

Open
JohnNajar wants to merge 2 commits from upstream-pr/2993 into main
JohnNajar commented 2026-11-29 19:15:59 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by JohnNajar on 2026-11-29T19:15:59Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554164969 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993). Originally posted by [JohnNajar](https://github.com/JohnNajar) on 2026-11-29T19:15:59Z. --- 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.
AimLogin commented 2026-11-29 20:46:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AimLogin on 2026-11-29T20:46:16Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262344269 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993#issuecomment-7262344269). Originally posted by [AimLogin](https://github.com/AimLogin) on 2026-11-29T20:46:16Z. --- 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._
JohnNajar commented 2026-11-29 22:34:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by JohnNajar on 2026-11-29T22:34:10Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7263777313 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993#issuecomment-7263777313). Originally posted by [JohnNajar](https://github.com/JohnNajar) on 2026-11-29T22:34:10Z. --- 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.
davemathews12 commented 2026-11-30 18:57:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by davemathews12 on 2026-11-30T18:57:27Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7288623205 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2993#issuecomment-7288623205). Originally posted by [davemathews12](https://github.com/davemathews12) on 2026-11-30T18:57:27Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2993:upstream-pr/2993'
git switch 'upstream-pr/2993'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2993'
git switch 'upstream-pr/2993'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2993'
git switch 'upstream-pr/2993'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2993'
git switch 'main'
git merge --squash 'upstream-pr/2993'
git switch 'main'
git merge --ff-only 'upstream-pr/2993'
git switch 'main'
git merge 'upstream-pr/2993'
git push origin 'main'
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!2993
No description provided.