Shaders: console threads of 2-D groups on 32-lane hosts come from a group counter (fixes #1243) #1258

Open
Garu667 wants to merge 1 commit from upstream-pr/1261 into main
Garu667 commented 2026-11-26 04:49:50 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T04:49:50Z.


Fixes #1243.

Problem

For a program with console lanes, thread_id / console_thread (outside the wave64-in-halves path) took the console thread as the flat id of the wave's first lane rounded down to the wave size, plus the lane. That is only a bijection if every host wave holds a wave-aligned run of flat ids. NVIDIA (and RDNA in 32-lane waves) fill 2-D groups from 16 x 2 tiles, so in a 32 x 2 group both host waves round down to the same base and half the threads take the ids of the other half. #1243 found three such programs in the title's pack (32 x 2 sky ambient-map compute passes).

Change

crates/victory-shader/src/emit/lower.rs: programs with console lanes in a group larger than one host wave (and not on the halves path) get one more LDS dword (ticket) and take their threads from it through wave_base, as wave64 programs in host waves of 32 already did:

  • every thread zeroes the dword, the group meets, each wave's first active lane adds for its wave;
  • a full wave takes the next aligned block of w from the low 16 bits;
  • a wave with fewer lanes (the group's last, partial one) adds its lane count to the high 16 bits and is placed past the full blocks, so it cannot push a full wave off its alignment whatever order the waves arrive in. This also covers the halves path for groups whose size is not a multiple of 32, where each wave used to add a fixed 32 (the caveat in #1243);
  • lanes are placed by their rank among the active lanes (wavePrefixOp sum of 1).

VICTORY_THREAD_TICKET=0 keeps the old rounding. The switch is read by the translator, so it is part of the translation's fingerprint.

Verification (RTX 3080 10 GB, Windows 11, diagnostics build)

  • New test the_console_threads_of_a_two_dimensional_group_are_each_given_once (wave64_tests.rs): a console wave32 program with v_mbcnt in a 32 x 2 group stores 1 at dword 32y + x. On the 3080 the old rounding writes 32 of 64 dwords; with the counter 64 of 64, each once. Without a hardware device the test still checks that the counter is used and that the DXIL validates.
  • cargo test --release -p victory-shader: 218 passed, 0 failed. cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • Whole shader pack (translate shaders.rpf --warm all, 32-lane host): 25,635 translated, 254 do not translate, the same counts as without the change.
  • In game, first boat mission, character left standing, 2 to 3 min, one capture every 64 frames: no device loss, no measurable frame cost (8.6 fps with the change against 8.6 to 9.4 in the runs without).
  • The picture: with the change the sky came out paler (mean sky RGB of the last 12 captures 214/222/231, against 196 to 199 / 208 to 210 / 221 to 222 in four runs without it, and 209/217/227 in a fifth). That is one launch with the change against five without, and one launch without was already paler, so I would not lean on it. Which look is right needs a console reference.

Diff: 2 files, about +140 / -16.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:5504189771 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T04:49:50Z. --- Fixes #1243. ## Problem For a program with console lanes, `thread_id` / `console_thread` (outside the wave64-in-halves path) took the console thread as the flat id of the wave's first lane rounded down to the wave size, plus the lane. That is only a bijection if every host wave holds a wave-aligned run of flat ids. NVIDIA (and RDNA in 32-lane waves) fill 2-D groups from 16 x 2 tiles, so in a 32 x 2 group both host waves round down to the same base and half the threads take the ids of the other half. #1243 found three such programs in the title's pack (32 x 2 sky ambient-map compute passes). ## Change `crates/victory-shader/src/emit/lower.rs`: programs with console lanes in a group larger than one host wave (and not on the halves path) get one more LDS dword (`ticket`) and take their threads from it through `wave_base`, as wave64 programs in host waves of 32 already did: - every thread zeroes the dword, the group meets, each wave's first active lane adds for its wave; - a full wave takes the next aligned block of w from the low 16 bits; - a wave with fewer lanes (the group's last, partial one) adds its lane count to the high 16 bits and is placed past the full blocks, so it cannot push a full wave off its alignment whatever order the waves arrive in. This also covers the halves path for groups whose size is not a multiple of 32, where each wave used to add a fixed 32 (the caveat in #1243); - lanes are placed by their rank among the active lanes (`wavePrefixOp` sum of 1). `VICTORY_THREAD_TICKET=0` keeps the old rounding. The switch is read by the translator, so it is part of the translation's fingerprint. ## Verification (RTX 3080 10 GB, Windows 11, diagnostics build) - New test `the_console_threads_of_a_two_dimensional_group_are_each_given_once` (`wave64_tests.rs`): a console wave32 program with `v_mbcnt` in a 32 x 2 group stores 1 at dword 32y + x. On the 3080 the old rounding writes **32 of 64** dwords; with the counter **64 of 64**, each once. Without a hardware device the test still checks that the counter is used and that the DXIL validates. - `cargo test --release -p victory-shader`: 218 passed, 0 failed. `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - Whole shader pack (`translate shaders.rpf --warm all`, 32-lane host): 25,635 translated, 254 do not translate, the same counts as without the change. - In game, first boat mission, character left standing, 2 to 3 min, one capture every 64 frames: no device loss, no measurable frame cost (8.6 fps with the change against 8.6 to 9.4 in the runs without). - The picture: with the change the sky came out paler (mean sky RGB of the last 12 captures 214/222/231, against 196 to 199 / 208 to 210 / 221 to 222 in four runs without it, and 209/217/227 in a fifth). That is one launch with the change against five without, and one launch without was already paler, so I would not lean on it. Which look is right needs a console reference. Diff: 2 files, about +140 / -16. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Ym1r1710 commented 2026-11-26 06:07:03 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Ym1r1710 on 2026-11-26T05:12:52Z.


Ran this on an RTX 5080 (Series X profile, first room), four runs on the same binary, two with the counter and two with VICTORY_THREAD_TICKET=0: no device loss, nothing new refused or left untranslated, median frame 102.7 / 100.6 ms with it vs 101.6 / 111.4 without, so no cost I can see. The room looks the same either way here, the affected sky passes probably don't show much indoors.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7183282890 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261#issuecomment-7183282890). Originally posted by [Ym1r1710](https://github.com/Ym1r1710) on 2026-11-26T05:12:52Z. --- Ran this on an RTX 5080 (Series X profile, first room), four runs on the same binary, two with the counter and two with VICTORY_THREAD_TICKET=0: no device loss, nothing new refused or left untranslated, median frame 102.7 / 100.6 ms with it vs 101.6 / 111.4 without, so no cost I can see. The room looks the same either way here, the affected sky passes probably don't show much indoors.
Garu667 commented 2026-11-26 07:03:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T06:10:36Z.


Thanks a lot for running it on the 5080, super helpful! Makes sense the room looks the same, the passes it fixes are the sky ambient ones so indoors you barely see them. On my 3080 the sky came out a bit paler outside with the fix, but that's 1 launch vs 5 so could just be noise. If you ever get a sec to grab an outdoor shot with the sky in view, with and without VICTORY_THREAD_TICKET=0, that'd settle it 🙏

<!-- greyfinch-sync:fxceless/victory-fork:comment:7184166506 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261#issuecomment-7184166506). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T06:10:36Z. --- Thanks a lot for running it on the 5080, super helpful! Makes sense the room looks the same, the passes it fixes are the sky ambient ones so indoors you barely see them. On my 3080 the sky came out a bit paler outside with the fix, but that's 1 launch vs 5 so could just be noise. If you ever get a sec to grab an outdoor shot with the sky in view, with and without `VICTORY_THREAD_TICKET=0`, that'd settle it 🙏
CuteBooty commented 2026-11-26 09:08:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CuteBooty on 2026-11-26T08:28:54Z.


RTX 3070 8 GB, Series S: ported and compared from one street with the fill light off; shade is as black with it as without it

A test report, in case a negative one is useful.

  • Machine: RTX 3070 8 GB (driver 621.24, 32-lane waves), Ryzen 5 3600, 32 GB, Windows 11, Series S, 1080p.
  • Tree: CuteBooty/victory-8gb plus a hand port of this PR behind a switch (on by default, part of the shader fingerprint, so each setting translated its own shaders from cold). Same exe, same save, VICTORY_AMBIENT unset in both runs.
  • With the PR: vehicle sides, roadside hedges and cast shadows on bright pavement nearly solid black. 210-227 ms a frame at 8,200-9,100 draws, no errors.
  • Without it: the same things looked no worse; the player judged that run slightly better. One run each, at different moments of the in-game day, so "worse with the PR" is not shown; "no visible help for the black shade" is.
  • The eight compute programs this card refuses are still refused, as expected: the PR does not claim them.

So on this card the three sky ambient-map passes taking wrong thread ids are not what makes shade black, or not alone. The port compiled and ran cleanly (full tests of the tree: 639 passed), so this is no argument against the PR's correctness, only a data point on what it does not fix.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7186645793 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261#issuecomment-7186645793). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-26T08:28:54Z. --- **RTX 3070 8 GB, Series S: ported and compared from one street with the fill light off; shade is as black with it as without it** A test report, in case a negative one is useful. - Machine: RTX 3070 8 GB (driver 621.24, 32-lane waves), Ryzen 5 3600, 32 GB, Windows 11, Series S, 1080p. - Tree: CuteBooty/victory-8gb plus a hand port of this PR behind a switch (on by default, part of the shader fingerprint, so each setting translated its own shaders from cold). Same exe, same save, `VICTORY_AMBIENT` unset in both runs. - With the PR: vehicle sides, roadside hedges and cast shadows on bright pavement nearly solid black. 210-227 ms a frame at 8,200-9,100 draws, no errors. - Without it: the same things looked no worse; the player judged that run slightly better. One run each, at different moments of the in-game day, so "worse with the PR" is not shown; "no visible help for the black shade" is. - The eight compute programs this card refuses are still refused, as expected: the PR does not claim them. So on this card the three sky ambient-map passes taking wrong thread ids are not what makes shade black, or not alone. The port compiled and ran cleanly (full tests of the tree: 639 passed), so this is no argument against the PR's correctness, only a data point on what it does not fix.
Garu667 commented 2026-11-26 09:08:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T08:39:28Z.


Thanks for porting and running it, negative results help too. Agreed: the PR only claims the thread ids are right (32/64 → 64/64 on the 3080 test); it was never expected to fix the black shade, which comes from the ray-traced lighting not running. Good to know it ran cleanly on a 3070 and on Series S.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7186861114 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261#issuecomment-7186861114). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T08:39:28Z. --- Thanks for porting and running it, negative results help too. Agreed: the PR only claims the thread ids are right (32/64 → 64/64 on the 3080 test); it was never expected to fix the black shade, which comes from the ray-traced lighting not running. Good to know it ran cleanly on a 3070 and on Series S.
Garu667 commented 2026-11-26 17:05:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T17:05:11Z.


Rebased onto e4245f3 (489fd6b): the test file conflicted with #646's new test, both kept. 234 shader tests pass, the fix itself is unchanged. The size check stays red as it is on main (lower.rs over 512 KiB, see #1322). The branch also lives in my fork if anyone wants to pull it: https://github.com/Garu667/victory-fork/tree/fix/thread-ticket-1243

<!-- greyfinch-sync:fxceless/victory-fork:comment:7198476861 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261#issuecomment-7198476861). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-26T17:05:11Z. --- Rebased onto `e4245f3` (489fd6b): the test file conflicted with #646's new test, both kept. 234 shader tests pass, the fix itself is unchanged. The size check stays red as it is on main (`lower.rs` over 512 KiB, see #1322). The branch also lives in my fork if anyone wants to pull it: https://github.com/Garu667/victory-fork/tree/fix/thread-ticket-1243
cafeoh commented 2026-11-26 20:18:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by cafeoh on 2026-11-26T20:18:04Z.


RTX 2080 Ti (Turing, 32-lane waves), Windows 10, Series S: with this PR, close-ups get dark blocky squares on faces and hair glows bright orange; removing only this commit makes both go away.

  • Tree: a private tree on a recent main plus a hand port of this PR (same lower.rs change as the current head). Same switches, warm shader cache.
  • With the PR: in the first café close-ups, darker square blocks in a screen grid on faces (forehead, brows, cheeks); in the prison cell, the hair at the back of the head glows orange instead of dark brown. Seen in every run with it, none without. Adding only this commit to a clean build brings both back.
  • VICTORY_THREAD_TICKET=0 does not remove them. Translating the same shaders offline with and without the PR (ticket off): 121 of 2,743 programs differ, all compute. With the ticket off, the wave64-in-halves path still uses the new wave_base() counter, so my guess is that path rather than the new ticket case.
  • Not tested: other cards, which of the 121 programs makes the squares.

AI use: found and tested with Claude Code (offline shader diff, then one run with only this commit added).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7202511406 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261#issuecomment-7202511406). Originally posted by [cafeoh](https://github.com/cafeoh) on 2026-11-26T20:18:04Z. --- **RTX 2080 Ti (Turing, 32-lane waves), Windows 10, Series S: with this PR, close-ups get dark blocky squares on faces and hair glows bright orange; removing only this commit makes both go away.** - Tree: a private tree on a recent main plus a hand port of this PR (same `lower.rs` change as the current head). Same switches, warm shader cache. - With the PR: in the first café close-ups, darker square blocks in a screen grid on faces (forehead, brows, cheeks); in the prison cell, the hair at the back of the head glows orange instead of dark brown. Seen in every run with it, none without. Adding only this commit to a clean build brings both back. - `VICTORY_THREAD_TICKET=0` does not remove them. Translating the same shaders offline with and without the PR (ticket off): 121 of 2,743 programs differ, all compute. With the ticket off, the wave64-in-halves path still uses the new `wave_base()` counter, so my guess is that path rather than the new ticket case. - Not tested: other cards, which of the 121 programs makes the squares. AI use: found and tested with Claude Code (offline shader diff, then one run with only this commit added).
cafeoh commented 2026-11-26 21:32:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by cafeoh on 2026-11-26T21:32:47Z.


Follow-up from the RTX 2080 Ti: the squares are not wrong ids. They come from how the wave64-in-halves wave_base() is written. The pre-PR form for halves programs, with the ticket on, removes them.

  • Card tests (tiny console compute programs run on the 2080 Ti in many group shapes, ids checked for gaps and doubles): with this PR every thread gets its id exactly once, on the ticket path and the halves path. The only form that fails here is the old rounding, in a 32x2 group. So the PR's ids are right on Turing too.
  • In the game, a test switch gives only the halves programs the pre-PR wave_base() (lane index read before and after the barrier, lane 0 adds 32, no & 0xffff) while the ticket stays on. Result: no squares on the café faces and normal hair in the cell. With the PR's halves form: squares, ticket on or off.
  • So the same ids written the new way seem to trip the Turing driver's shader compiler in some of the ~120 halves programs. My earlier guess had the right place (the halves path) but the wrong reason (it is not the ids).
  • Suggestion: keep the pre-PR wave_base() for halves programs and use the counter only for the new console-wave32 case. Happy to test a branch on this card.

Tested: RTX 2080 Ti, Windows 10, Series S, café and cell scenes, one run each way, warm shader cache.
Not tested: which of the ~120 programs shows it, which of the form changes trips the driver, other Turing cards.

AI use: Claude Code (card tests, offline shader diff, test switch, runs).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7203829113 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1261#issuecomment-7203829113). Originally posted by [cafeoh](https://github.com/cafeoh) on 2026-11-26T21:32:47Z. --- **Follow-up from the RTX 2080 Ti: the squares are not wrong ids. They come from how the wave64-in-halves `wave_base()` is written. The pre-PR form for halves programs, with the ticket on, removes them.** - Card tests (tiny console compute programs run on the 2080 Ti in many group shapes, ids checked for gaps and doubles): with this PR every thread gets its id exactly once, on the ticket path and the halves path. The only form that fails here is the old rounding, in a 32x2 group. So the PR's ids are right on Turing too. - In the game, a test switch gives only the halves programs the pre-PR `wave_base()` (lane index read before and after the barrier, lane 0 adds 32, no `& 0xffff`) while the ticket stays on. Result: no squares on the café faces and normal hair in the cell. With the PR's halves form: squares, ticket on or off. - So the same ids written the new way seem to trip the Turing driver's shader compiler in some of the ~120 halves programs. My earlier guess had the right place (the halves path) but the wrong reason (it is not the ids). - Suggestion: keep the pre-PR `wave_base()` for halves programs and use the counter only for the new console-wave32 case. Happy to test a branch on this card. Tested: RTX 2080 Ti, Windows 10, Series S, café and cell scenes, one run each way, warm shader cache. Not tested: which of the ~120 programs shows it, which of the form changes trips the driver, other Turing cards. AI use: Claude Code (card tests, offline shader diff, test switch, runs).
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/1261:upstream-pr/1261'
git switch 'upstream-pr/1261'

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/1261'
git switch 'upstream-pr/1261'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1261'
git switch 'upstream-pr/1261'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1261'
git switch 'main'
git merge --squash 'upstream-pr/1261'
git switch 'main'
git merge --ff-only 'upstream-pr/1261'
git switch 'main'
git merge 'upstream-pr/1261'
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
fxceless/victory-fork!1258
No description provided.