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

Closed
github-bot wants to merge 2 commits from gh-pr/1081/head into gh-pr/1081/base
Owner

@⁠iurysf on GitHub · 2026-11-24 15:34 UTC · original
iurysf:shader-breadcrumbs → main · +386 −11 · 11 files · 2 commits · closed without merging

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.

**@⁠iurysf** on GitHub · 2026-11-24 15:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1081) `iurysf:shader-breadcrumbs` → `main` · +386 −11 · 11 files · 2 commits · closed without merging 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.
With `VICTORY_SHADER_BREADCRUMBS=1` in a diagnostics build, every loop of a
translated shader stores its iteration count (`atomicMax`) in a host buffer:
1,024 slots of 8 words, a shader's slot taken from its container's digest.
The buffer is a shared (system memory) one, so what the GPU wrote survives a
device removal; it is cleared before each submission. The shader reaches it
through a UAV in the last dynamic slot of each host view heap, at the index
the host passes in the first user-data dword past the console's: no new root
parameter and no per-draw binding. When the device is removed the failure
report names the five loops that counted most and the pipelines of their
slots, which says which shader's loop ran away where the removal data only
names a command.

Off, nothing changes: not the DXIL, nor the root signature, nor the shader
cache's key. On, the census translates and validates the same programs (the
validator accepts the extra UAV in vertex, pixel, compute and mesh shaders;
140,150 loop stores emitted in the 25,902 programs).

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
The breadcrumb of a loop was one `atomicMax` a lane a back edge: a wave of 32
or 64 lanes made that many atomic operations on the same word every
iteration. The loop count now goes through a wave maximum (`WaveActiveMax`,
unsigned) and the first active lane stores it, so the word still holds the
largest count any lane reached, with one atomic a wave. The store ends the
block of the back edge, so the block the loop's phis take as the edge's source
is the one where the edge ends.

The census (25,902 programs, validator) is unchanged with the switch on:
the same programs validate as with it off.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:19:16 +00:00
github-bot closed this pull request 2026-11-26 04:19:16 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 16:29 UTC · original

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).

**@⁠Zipettte** on GitHub · 2026-11-24 16:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1081#issuecomment-7137757070) 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)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:33 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1081#issuecomment-7148640181) <!-- 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)_
Author
Owner

@⁠iurysf on GitHub · 2026-11-25 01:01 UTC · original

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.

**@⁠iurysf** on GitHub · 2026-11-25 01:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1081#issuecomment-7149128822) 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

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