Shaders: leave loop-count breadcrumbs in a host buffer and name the runaway loops when the device is removed #1081

Closed
iurysf wants to merge 2 commits from upstream-pr/1081 into main
iurysf commented 2026-11-24 15:34:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T15:34:52Z.


When the host GPU is reset after a hang, DRED (and #669) say which command was running, but not where in its shader. This adds an opt-in diagnostic: with VICTORY_SHADER_BREADCRUMBS=1 (diagnostics builds, like VICTORY_SHADER_LOOP_LIMIT), each loop of a translated shader stores its iteration count into a host buffer. The value is the wave's largest, from its first lane, so there is one atomic max per wave and iteration. The buffer has 1,024 slots of 8 words, and a shader's slot comes from its container digest.

  • The buffer is in system memory, so the counts survive the removal. It is cleared before every submission.
  • Shaders reach it through a UAV kept in the last dynamic slot of each host view heap, at an index passed in the first user-data dword past the console's. There is no new root parameter (large signatures are already near the 64-dword limit, #644) and no per-draw binding.
  • On a removal, the failure report lists the five loops that counted most, with the pipelines using their slot.
  • Off, nothing changes: not the DXIL, not the root signature, not the shader cache key.

On hardware: RTX 4070 (driver 32.0.16.2101), main + this, real world hangs. The counts survived the TDR, and crashes.log had shader breadcrumbs: loop 2 of slot 621 ran 512 iterations ([vertex ce57291b5a1750ca, pixel a467d848ace5810d]). That vertex shader is the one in the draws of the list DRED reports as stalled. The count was the same with VICTORY_SHADER_LOOP_LIMIT=2147483647, which ruled out a runaway loop for that hang.

Offline: census of 25,902 programs with dxil.dll 1.9, switch off vs on: identical classes. With it on, 140,150 loop stores are emitted, so the validator accepts the extra UAV and the wave ops in vertex, pixel, compute and mesh shaders. Unit tests cover the emitter (one extra user-data dword, wave ops only with the switch on) and the report. cargo test -p victory-shader and -p victory-gpu pass; clippy -D warnings and cargo xtask policy are clean.

Not yet measured: per-frame cost with it on.

Limits: two shaders may share a slot (the report lists both), at most 8 loops per shader are tracked, and the counts are the largest any lane reached.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6585457148 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1081). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T15:34:52Z. --- When the host GPU is reset after a hang, DRED (and #669) say which command was running, but not where in its shader. This adds an opt-in diagnostic: with `VICTORY_SHADER_BREADCRUMBS=1` (diagnostics builds, like `VICTORY_SHADER_LOOP_LIMIT`), each loop of a translated shader stores its iteration count into a host buffer. The value is the wave's largest, from its first lane, so there is one atomic max per wave and iteration. The buffer has 1,024 slots of 8 words, and a shader's slot comes from its container digest. - The buffer is in system memory, so the counts survive the removal. It is cleared before every submission. - Shaders reach it through a UAV kept in the last dynamic slot of each host view heap, at an index passed in the first user-data dword past the console's. There is no new root parameter (large signatures are already near the 64-dword limit, #644) and no per-draw binding. - On a removal, the failure report lists the five loops that counted most, with the pipelines using their slot. - **Off, nothing changes:** not the DXIL, not the root signature, not the shader cache key. **On hardware:** RTX 4070 (driver 32.0.16.2101), main + this, real world hangs. The counts survived the TDR, and `crashes.log` had `shader breadcrumbs: loop 2 of slot 621 ran 512 iterations ([vertex ce57291b5a1750ca, pixel a467d848ace5810d])`. That vertex shader is the one in the draws of the list DRED reports as stalled. The count was the same with `VICTORY_SHADER_LOOP_LIMIT=2147483647`, which ruled out a runaway loop for that hang. **Offline:** census of 25,902 programs with dxil.dll 1.9, switch off vs on: identical classes. With it on, 140,150 loop stores are emitted, so the validator accepts the extra UAV and the wave ops in vertex, pixel, compute and mesh shaders. Unit tests cover the emitter (one extra user-data dword, wave ops only with the switch on) and the report. `cargo test -p victory-shader` and `-p victory-gpu` pass; clippy `-D warnings` and `cargo xtask policy` are clean. **Not yet measured:** per-frame cost with it on. **Limits:** two shaders may share a slot (the report lists both), at most 8 loops per shader are tracked, and the counts are the largest any lane reached. AI-assisted.
Zipettte commented 2026-11-24 17:04:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T16:29:52Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at ff2dff8: cargo test -p victory-gpu -p victory-shader passes, 174 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137757070 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1081#issuecomment-7137757070). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T16:29:52Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at ff2dff8: `cargo test -p victory-gpu -p victory-shader` passes, 174 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:05:30 +00:00
Marvisak commented 2026-11-25 01:08:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:33:47Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/lib.rs, crates/victory-gpu/src/shader_cache.rs, crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/mod.rs, crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148640181 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1081#issuecomment-7148640181). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:33:47Z. --- <!-- victory-triage v1 head=ff2dff8e4ca60b8894181d319a62c83869760347 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/lib.rs`, `crates/victory-gpu/src/shader_cache.rs`, `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/mod.rs`, `crates/victory-shader/src/emit/valu_tests.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
iurysf commented 2026-11-25 01:08:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-25T01:01:33Z.


Closing this one instead of rebasing it: on the new main it conflicts in seven files (root-view handling in lower.rs, descriptor/host.rs, draw.rs, shader_cache.rs), which is more than a diagnostic is worth right now, and #669 (merged, thank you) already gives most of what we needed from it. If the loop counts are wanted again, I will redo it smaller on top of main.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149128822 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1081#issuecomment-7149128822). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-25T01:01:33Z. --- Closing this one instead of rebasing it: on the new `main` it conflicts in seven files (root-view handling in `lower.rs`, `descriptor/host.rs`, `draw.rs`, `shader_cache.rs`), which is more than a diagnostic is worth right now, and #669 (merged, thank you) already gives most of what we needed from it. If the loop counts are wanted again, I will redo it smaller on top of `main`. AI-assisted.

Pull request closed

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
Marvisak/VIctory!1081
No description provided.