xshader: keep no local arrays in the console node test #520

Merged
NickStallman merged 1 commit from upstream-pr/520 into main 2026-11-29 21:04:36 +00:00
NickStallman commented 2026-11-29 19:06:38 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T19:06:38Z.


For #509.

Summary

The console BVH node test filled a 32-word array in a loop and indexed vectors at run time, so each inlined copy kept 296 bytes of local arrays. One ProjectScarlett program holds 72 copies, 21,408 bytes a lane. On an RTX 5090, only creating such a pipeline makes another program lose the device (#509); the signs match a known NVIDIA bug, and this keeps clear of it.

The node's words are now read at constant indices and vector components picked by comparison, which DXC turns into plain values. A type 5 node reads its upper 64 bytes only when it needs them. The largest local array in the recorded programs is 96 bytes a lane.

Measured

before after
largest local arrays, bytes a lane 21,408 96
distinct translations over 8 KiB / 16 KiB 8 / 4 0 / 0
DXIL bytes of the 104 translations with such arrays 43.9 M 41.6 M
DXC time for the same (once, on a loaded machine) 851 s 901 s

Of the compute requests recorded, 200 translations change, all of them console walks; 9,868 stay the same; no request changes whether it translates. (Other stages were not translated; the changed text is only added to programs that contain the call.)

brcly measured all 125 recorded BVH programs (2 passes): private memory 21,408 to 96 bytes a thread, programs over 8 KiB 16 to 0, DXIL 63.6 to 59.1 MB, DXC time 598 to 610 s (+2%). My counts above are of distinct translations.

Tested

  • A DXC test (tests/test_bvh_node_scratch.py, skipped without dxc) that no local array is left; seven mutations each fail it.
  • 200,000 random node tests on lavapipe, old against new: the same, except 6 triangle results where both are NaN with different sign or payload bits.
  • Translator unit tests (630), python tuxbox.py check --no-gpu.
  • Native comparison on a gfx1036 Radeon (AMD only): the native control in tools/reference/bvh-node/native passed, and its nine synthetic dumps (48 box and 492 triangle cases) were compared with node.hlsl from main (2d6dc338) and from this branch (4564db59), on RADV (Mesa 26.0.8) through GE-Proton11-14, default and --strict. Both versions return identical words in all 540 cases in both modes. Against the native instruction both differ in the same 222 cases by default and 161 with --strict, so this neither fixes nor adds a mismatch. I used check_native_bvh_hlsl.py with its NVIDIA half removed and its case limit raised, so that it takes the edge, degenerate, scale, mixed and underflow dumps. The box code compiles to the same DXIL, so only the triangle cases exercise this change. It doesn't cover the node loading in bvh_node.rs, NVIDIA, or recorded nodes.
  • Full python tuxbox.py check of 4564db59 on an RTX 5090 (10de:2b85, 620.70.10, GE-Proton11-14): exit 0, 192 pass, 0 fail.
  • The same on an AMD iGPU (1002:13c0, RADV, Mesa 26.0.8): exit 0, 191 pass, 0 fail.
  • Game (RTX 5090, 620.70.10, 090cf6ce plus our diagnostics and this change): in the one conclusive run (warm cache; the log shows both suspect programs requested, and the run's failure report lists neither, so I take them as created), the loss this targets did not happen. The run presented for 501 s after the story starts loading; the 12 earlier runs with these programs on that base were lost within 54 s. It was then lost anyway, with an Xid 13 MMU fault in mesh draws (no fault address reported), not on the d7674d99… dispatch the earlier ones died on. The first mesh program of that crash region also leads the one in a run on an older build without 18189694, so I believe it is a separate, older fault; I haven't proved that. Two earlier game runs were inconclusive (a cold driver cache, and one that reached the story with under 10 s left). One run is not many.
  • Not run: Windows.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5554083023 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/520). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T19:06:38Z. --- For #509. ## Summary The console BVH node test filled a 32-word array in a loop and indexed vectors at run time, so each inlined copy kept 296 bytes of local arrays. One ProjectScarlett program holds 72 copies, 21,408 bytes a lane. On an RTX 5090, only creating such a pipeline makes another program lose the device (#509); the signs match a known NVIDIA bug, and this keeps clear of it. The node's words are now read at constant indices and vector components picked by comparison, which DXC turns into plain values. A type 5 node reads its upper 64 bytes only when it needs them. The largest local array in the recorded programs is 96 bytes a lane. ## Measured | | before | after | |---|---|---| | largest local arrays, bytes a lane | 21,408 | 96 | | distinct translations over 8 KiB / 16 KiB | 8 / 4 | 0 / 0 | | DXIL bytes of the 104 translations with such arrays | 43.9 M | 41.6 M | | DXC time for the same (once, on a loaded machine) | 851 s | 901 s | Of the compute requests recorded, 200 translations change, all of them console walks; 9,868 stay the same; no request changes whether it translates. (Other stages were not translated; the changed text is only added to programs that contain the call.) brcly measured all 125 recorded BVH programs (2 passes): private memory 21,408 to 96 bytes a thread, programs over 8 KiB 16 to 0, DXIL 63.6 to 59.1 MB, DXC time 598 to 610 s (+2%). My counts above are of distinct translations. ## Tested - A DXC test (`tests/test_bvh_node_scratch.py`, skipped without `dxc`) that no local array is left; seven mutations each fail it. - 200,000 random node tests on lavapipe, old against new: the same, except 6 triangle results where both are NaN with different sign or payload bits. - Translator unit tests (630), `python tuxbox.py check --no-gpu`. - Native comparison on a gfx1036 Radeon (AMD only): the native control in `tools/reference/bvh-node/native` passed, and its nine synthetic dumps (48 box and 492 triangle cases) were compared with `node.hlsl` from `main` (2d6dc338) and from this branch (4564db59), on RADV (Mesa 26.0.8) through GE-Proton11-14, default and `--strict`. Both versions return identical words in all 540 cases in both modes. Against the native instruction both differ in the same 222 cases by default and 161 with `--strict`, so this neither fixes nor adds a mismatch. I used `check_native_bvh_hlsl.py` with its NVIDIA half removed and its case limit raised, so that it takes the edge, degenerate, scale, mixed and underflow dumps. The box code compiles to the same DXIL, so only the triangle cases exercise this change. It doesn't cover the node loading in `bvh_node.rs`, NVIDIA, or recorded nodes. - Full `python tuxbox.py check` of 4564db59 on an RTX 5090 (`10de:2b85`, 620.70.10, GE-Proton11-14): exit 0, 192 pass, 0 fail. - The same on an AMD iGPU (`1002:13c0`, RADV, Mesa 26.0.8): exit 0, 191 pass, 0 fail. - **Game (RTX 5090, 620.70.10, 090cf6ce plus our diagnostics and this change):** in the one conclusive run (warm cache; the log shows both suspect programs requested, and the run's failure report lists neither, so I take them as created), the loss this targets did not happen. The run presented for 501 s after the story starts loading; the 12 earlier runs with these programs on that base were lost within 54 s. It was then lost anyway, with an Xid 13 MMU fault in mesh draws (no fault address reported), not on the `d7674d99…` dispatch the earlier ones died on. The first mesh program of that crash region also leads the one in a run on an older build without `18189694`, so I believe it is a separate, older fault; I haven't proved that. Two earlier game runs were inconclusive (a cold driver cache, and one that reached the story with under 10 s left). One run is not many. - **Not run:** Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
brcly commented 2026-11-29 19:45:01 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T19:45:01Z.


Thanks for this. I measured it against main on all 125 recorded BVH programs (DXC 1.9, same flags as the runtime, 2 passes each, 3 jobs at a time):

main #520
largest private memory in the DXIL, bytes a thread 21,408 96
programs over 8 KiB 16 0
DXIL, total 63.6 MB 59.1 MB (−7%)
DXC time 598 s 610 s (+2%; +4% on the 16 largest)

All 125 translate and compile. I couldn't time the NVIDIA driver on these: the standalone pipeline timer can't create d29efb84's root signature, so the driver side is still unmeasured.

To offset the extra DXC time, I've pushed one commit onto your branch (e1d5b043): structured loops now count their 65536-iteration watchdog at the top of a while (true) body instead of in a for header. The header's induction variable gives DXC's loop passes a trip count to work out for every loop. Same cap, including through continue. On the 30 slowest of 600 random compute requests: 3.6% less DXC (5–27% on loop-heavy programs), with the same DXIL. It passed the full check on an RTX 4070 Ti SUPER and a Radeon 610M on its own. On top of your commit, the 630 translator unit tests and tests/test_bvh_node_scratch.py pass; I haven't run the GPU checks on the combination.

If you're happy with the idea, we can merge both together once your checks are through; if you'd rather keep the PR to the node test, say so and I'll take it back off and land it separately.

<!-- greyfinch-sync:brcly/TuxBox:comment:7261525099 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/520#issuecomment-7261525099). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T19:45:01Z. --- Thanks for this. I measured it against `main` on all 125 recorded BVH programs (DXC 1.9, same flags as the runtime, 2 passes each, 3 jobs at a time): | | main | #520 | |---|---|---| | largest private memory in the DXIL, bytes a thread | 21,408 | 96 | | programs over 8 KiB | 16 | 0 | | DXIL, total | 63.6 MB | 59.1 MB (−7%) | | DXC time | 598 s | 610 s (+2%; +4% on the 16 largest) | All 125 translate and compile. I couldn't time the NVIDIA driver on these: the standalone pipeline timer can't create d29efb84's root signature, so the driver side is still unmeasured. To offset the extra DXC time, I've pushed one commit onto your branch (e1d5b043): structured loops now count their 65536-iteration watchdog at the top of a `while (true)` body instead of in a `for` header. The header's induction variable gives DXC's loop passes a trip count to work out for every loop. Same cap, including through `continue`. On the 30 slowest of 600 random compute requests: 3.6% less DXC (5–27% on loop-heavy programs), with the same DXIL. It passed the full check on an RTX 4070 Ti SUPER and a Radeon 610M on its own. On top of your commit, the 630 translator unit tests and `tests/test_bvh_node_scratch.py` pass; I haven't run the GPU checks on the combination. If you're happy with the idea, we can merge both together once your checks are through; if you'd rather keep the PR to the node test, say so and I'll take it back off and land it separately.
NickStallman commented 2026-11-29 19:49:51 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T19:49:51Z.


Thanks for measuring it. Your 16 programs over 8 KiB are the 8 at 21,408 and the 8 at 10,752; mine counted distinct translations, so that settles the difference. I'll use your numbers in the description.

Please take e1d5b043 off and land it separately. The idea looks fine to me, but:

  • The game runs with this fix use only the node test, so they say nothing about the combination. The 5090 check was of 4564db59 as well; the AMD one is still queued.
  • It changes the HLSL of programs with structured loops, so they recompile. This one changes 200 console walks of the compute requests recorded.
  • It keeps the separate cap for each structured loop, which I reported on #489 (nested loops can run 65,536 × 65,536), and #522 touches the same line. Settling those together seems easier away from this PR.

I haven't reviewed e1d5b043 in detail. I won't push to the branch while it's there.

<!-- greyfinch-sync:brcly/TuxBox:comment:7261590672 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/520#issuecomment-7261590672). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T19:49:51Z. --- Thanks for measuring it. Your 16 programs over 8 KiB are the 8 at 21,408 and the 8 at 10,752; mine counted distinct translations, so that settles the difference. I'll use your numbers in the description. Please take e1d5b043 off and land it separately. The idea looks fine to me, but: - The game runs with this fix use only the node test, so they say nothing about the combination. The 5090 check was of 4564db59 as well; the AMD one is still queued. - It changes the HLSL of programs with structured loops, so they recompile. This one changes 200 console walks of the compute requests recorded. - It keeps the separate cap for each structured loop, which I reported on #489 (nested loops can run 65,536 × 65,536), and #522 touches the same line. Settling those together seems easier away from this PR. I haven't reviewed e1d5b043 in detail. I won't push to the branch while it's there.
brcly commented 2026-11-29 19:51:06 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T19:51:06Z.


Done: the branch is back at your 4564db59, and I won't push to it again. I'll land the loop header change separately, after #522's loop limits are settled. The per-loop caps multiplying when loops nest (65,536 × 65,536) is a fair point; I'll take that up with the header change rather than here.

Once your AMD check and game runs are through and the PR is out of draft, I'll merge it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7261608738 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/520#issuecomment-7261608738). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T19:51:06Z. --- Done: the branch is back at your 4564db59, and I won't push to it again. I'll land the loop header change separately, after #522's loop limits are settled. The per-loop caps multiplying when loops nest (65,536 × 65,536) is a fair point; I'll take that up with the header change rather than here. Once your AMD check and game runs are through and the PR is out of draft, I'll merge it.
NickStallman commented 2026-11-29 20:46:09 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T20:46:09Z.


Out of draft: full checks are through on an RTX 5090 (192 pass) and an AMD iGPU (191 pass), and one conclusive game run is in. The loss this targets didn't happen: 501 s past the point where the 12 earlier runs died within 54 s. That run was still lost later, in mesh draws, with an Xid 13 MMU fault and no address. The crash region's first program is one that also leads the region of a loss on a build without 18189694, so I think it's an older fault, but I haven't proved that. Details are in the description. It isn't a claim that the game no longer crashes.

<!-- greyfinch-sync:brcly/TuxBox:comment:7262342770 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/520#issuecomment-7262342770). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T20:46:09Z. --- Out of draft: full checks are through on an RTX 5090 (192 pass) and an AMD iGPU (191 pass), and one conclusive game run is in. The loss this targets didn't happen: 501 s past the point where the 12 earlier runs died within 54 s. That run was still lost later, in mesh draws, with an Xid 13 MMU fault and no address. The crash region's first program is one that also leads the region of a loss on a build without `18189694`, so I think it's an older fault, but I haven't proved that. Details are in the description. It isn't a claim that the game no longer crashes.
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
brcly/TuxBox!520
No description provided.