Refuse VICTORY_INDIRECT_CLAMP=0: it kills the run, and hoisting is the answer to the cost #169

Open
github-bot wants to merge 1 commit from github-bot/gh-169 into main AGit
Owner

@⁠HailLucifer666 on GitHub · 2026-11-24 22:06 UTC · original
HailLucifer666:perf/indirect-clamp-bypass → main · +90 −1 · 1 files · 1 commits · open

What changed, and why the title changed

This PR no longer adds a bypass. It refuses one.

The bypass was meant to answer a real, measured cost: dkdknight's Nsight capture on an RTX 5080 shows about 5,000 one-record indirect mesh draws per frame, GR active ~75%, SMs ~28%, SM issue ~4% — the machine is waiting on per-record work, and the per-record clamp pass is part of that work.

He then set VICTORY_INDIRECT_CLAMP=0 and both runs died with 0xc0000005 writing 0x0, within seconds, twice out of two. The title's argument buffer holds records whose bounds the pass is what enforces. Removing the check does not make it faster; it makes the process stop.

So 0 now means "I read the complaint, and no":

  • clamp_setting returns (clamp on, say so); the clamp is on for every value.
  • A run that asked gets one warning naming the crash and naming what actually answers the cost.
  • clamp_is_on is consulted where the clamp is first made, so even a run that never reaches the pass is told.

With no path left that could honour it, the dead half is deleted rather than left unreachable: the if !clamped branch, the two if clamped teardowns, and wait_direct, which existed only to barrier an unclamped execute.

What answers the cost

Hoisting the clamps out of the per-record path — VICTORY_HOIST_CLAMPS, Phase I (perf/hoist-indirect-clamps, switch landed, default off). That keeps the bounds check and stops paying for it once per record. When hoisting is the default and survives hardware, deleting the per-record pass becomes a conversation with evidence behind it. This is not that conversation.

Evidence

  • Probe: clamp_setting returns parse_clamp_enabled(asked) again → the new test fails with left: (false, true), right: (true, true) → restored byte-identical (indirect.rs sha256 ade38ee886e354e5).
  • cargo test -p victory-gpu --lib: 161 passed, 1 failed — warp_budget_saturates_without_wraparound_and_preserves_draw_fields, the known flake (#847/#849), untouched by this commit.
  • cargo clippy -p victory-gpu --lib -D warnings: only the two pre-existing #841 errors (placed_filler_twins, sort_unstable_by_key) remain.

Not covered

Native D3D12 — no GPU here. The refusal is proven by its decision and its message, not by a frame. Anyone who genuinely wants the old behaviour keeps it by running an older build, which is the honest place for a switch that crashes.

⚠️ This is a behaviour change: VICTORY_INDIRECT_CLAMP=0 no longer does anything except print a warning. If that was in a launch script, it can come out.

**@⁠HailLucifer666** on GitHub · 2026-11-24 22:06 UTC · [original](https://github.com/fxceless/victory-fork/pull/169) `HailLucifer666:perf/indirect-clamp-bypass` → `main` · +90 −1 · 1 files · 1 commits · open ## What changed, and why the title changed This PR no longer adds a bypass. It refuses one. The bypass was meant to answer a real, measured cost: `dkdknight`'s Nsight capture on an RTX 5080 shows **about 5,000 one-record indirect mesh draws per frame**, GR active ~75%, SMs ~28%, **SM issue ~4%** — the machine is waiting on per-record work, and the per-record clamp pass is part of that work. He then set `VICTORY_INDIRECT_CLAMP=0` and **both runs died** with `0xc0000005` writing `0x0`, within seconds, twice out of two. The title's argument buffer holds records whose bounds the pass is what enforces. Removing the check does not make it faster; it makes the process stop. So `0` now means *"I read the complaint, and no"*: - `clamp_setting` returns `(clamp on, say so)`; the clamp is on for every value. - A run that asked gets one warning naming the crash and naming what actually answers the cost. - `clamp_is_on` is consulted where the clamp is first made, so even a run that never reaches the pass is told. With no path left that could honour it, the dead half is deleted rather than left unreachable: the `if !clamped` branch, the two `if clamped` teardowns, and `wait_direct`, which existed only to barrier an unclamped execute. ## What answers the cost Hoisting the clamps out of the per-record path — `VICTORY_HOIST_CLAMPS`, Phase I (`perf/hoist-indirect-clamps`, switch landed, default **off**). That keeps the bounds check and stops paying for it once per record. When hoisting is the default and survives hardware, deleting the per-record pass becomes a conversation with evidence behind it. This is not that conversation. ## Evidence - Probe: `clamp_setting` returns `parse_clamp_enabled(asked)` again → the new test fails with `left: (false, true), right: (true, true)` → restored byte-identical (`indirect.rs` sha256 `ade38ee886e354e5`). - `cargo test -p victory-gpu --lib`: 161 passed, 1 failed — `warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, the known flake (#847/#849), untouched by this commit. - `cargo clippy -p victory-gpu --lib -D warnings`: only the two pre-existing #841 errors (`placed_filler_twins`, `sort_unstable_by_key`) remain. ## Not covered Native D3D12 — no GPU here. The refusal is proven by its decision and its message, not by a frame. Anyone who genuinely wants the old behaviour keeps it by running an older build, which is the honest place for a switch that crashes. ⚠️ **This is a behaviour change**: `VICTORY_INDIRECT_CLAMP=0` no longer does anything except print a warning. If that was in a launch script, it can come out.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:28 +00:00
github-bot referenced this pull request from a commit 2026-11-26 03:40:07 +00:00
Author
Owner

@⁠dkdknight on GitHub · 2026-11-25 00:31 UTC · original

Tested this on GTA VI (Series X build), RTX 5080, Windows 11, with VICTORY_RELAY=2 VICTORY_LATE_WAIT=3. Build: this PR merged onto our integration branch (#71, #81, #77, #38, #80, #63 on top of main).

With VICTORY_INDIRECT_CLAMP=0 the title crashes while the story loads, 2 launches out of 2:

VIctory: unhandled exception 0xc0000005 at victory-image-….dll+0x23cf683 (write 0x0: nothing mapped there)

The title's own crash reporter then starts (blocked upload to backtrace.io). That is a deliberate null write: the game's own fatal path, not a fault in VIctory. Both runs died about 90 s after launch, during the load into the world, before any gameplay frame. The same binary with the clamp left on (the default) loads and plays normally.

So on GTA VI at least, some indirect arguments the title produces need the clamp, presumably group counts the clamp zeroes or bounds. Running ExecuteIndirect straight from the title buffer is not safe there. I'd keep the default as it is in this PR (clamp on) and document that 0 crashes GTA VI.

One caveat for honesty: the same crash site showed up once before, on a first launch of a build with the BVH builder (#36), which then loaded fine on relaunch. Here it reproduced on the relaunch too, with a warm shader cache, which is why I attribute it to the switch.

Context, in case it helps anyone working on GPU time: on this card the frame is front-end bound (Nsight Systems GPU metrics during gameplay: GR active ~75%, SMs active ~28%, SM issue ~4%), with ~5,000 one-record indirect mesh draws per frame, each with its clamp pass. So the cost of the clamp + ExecuteIndirect pairs is worth attacking, but by a route that keeps the bounds check.

(Tested and written with the help of an AI assistant, Claude Code; numbers above are from our own runs.)

**@⁠dkdknight** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/169#issuecomment-7148596369) Tested this on GTA VI (Series X build), RTX 5080, Windows 11, with `VICTORY_RELAY=2 VICTORY_LATE_WAIT=3`. Build: this PR merged onto our integration branch (#71, #81, #77, #38, #80, #63 on top of `main`). **With `VICTORY_INDIRECT_CLAMP=0` the title crashes while the story loads, 2 launches out of 2:** ``` VIctory: unhandled exception 0xc0000005 at victory-image-….dll+0x23cf683 (write 0x0: nothing mapped there) ``` The title's own crash reporter then starts (blocked upload to backtrace.io). That is a deliberate null write: the game's own fatal path, not a fault in VIctory. Both runs died about 90 s after launch, during the load into the world, before any gameplay frame. The same binary with the clamp left on (the default) loads and plays normally. So on GTA VI at least, some indirect arguments the title produces need the clamp, presumably group counts the clamp zeroes or bounds. Running `ExecuteIndirect` straight from the title buffer is not safe there. I'd keep the default as it is in this PR (clamp on) and document that `0` crashes GTA VI. One caveat for honesty: the same crash site showed up once before, on a first launch of a build with the BVH builder (#36), which then loaded fine on relaunch. Here it reproduced on the relaunch too, with a warm shader cache, which is why I attribute it to the switch. Context, in case it helps anyone working on GPU time: on this card the frame is front-end bound (Nsight Systems GPU metrics during gameplay: GR active ~75%, SMs active ~28%, SM issue ~4%), with ~5,000 one-record indirect mesh draws per frame, each with its clamp pass. So the cost of the clamp + `ExecuteIndirect` pairs is worth attacking, but by a route that keeps the bounds check. (Tested and written with the help of an AI assistant, Claude Code; numbers above are from our own runs.)
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-25 09:44 UTC · original

Thanks — this is the most useful telemetry on this PR, and I am taking both findings as they are.

The flag is diagnostic only. VICTORY_INDIRECT_CLAMP=0 is not a supported setting. Your two launches show the title writing a null through arguments the clamp would have zeroed or bounded, so running ExecuteIndirect straight from the title's argument buffer is unsafe there — and the clamp is exactly what stops it. The default stays on; I have noted the crash in the description so nobody reads 0 as a tuning knob. Expect a crash during the load into the world with it off.

The bottleneck is the one this PR was aimed at, but bypassing is the wrong route. ~5,000 one-record indirect mesh draws a frame with GR active ~75%, SMs ~28% and SM issue ~4% says the frame is front-end bound on the compute↔graphics switches, not on the clamp's arithmetic. Removing the switches by removing the clamp also removes the safety, which is not a trade worth making.

The next step is to batch the clamp itself: one clamp dispatch, or a few windowed ones, covering a whole run of consecutive indirect records instead of one pass per record — every bounds check kept, and the 0xFFFF_FFFF zeroing for unfilled tail slots kept without charging their budget. That is where the ~5,000 switches go without giving up the clamp. It goes up as its own PR; I will tag you for a run if you are willing.

Also noted that the same crash site appeared once on an earlier build and did not reproduce on relaunch — thank you for saying so rather than leaving it as clean attribution. It does not change the conclusion for the flag.

**@⁠HailLucifer666** on GitHub · 2026-11-25 09:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/169#issuecomment-7158745194) Thanks — this is the most useful telemetry on this PR, and I am taking both findings as they are. **The flag is diagnostic only.** `VICTORY_INDIRECT_CLAMP=0` is not a supported setting. Your two launches show the title writing a null through arguments the clamp would have zeroed or bounded, so running `ExecuteIndirect` straight from the title's argument buffer is unsafe there — and the clamp is exactly what stops it. The default stays on; I have noted the crash in the description so nobody reads `0` as a tuning knob. Expect a crash during the load into the world with it off. **The bottleneck is the one this PR was aimed at, but bypassing is the wrong route.** ~5,000 one-record indirect mesh draws a frame with GR active ~75%, SMs ~28% and SM issue ~4% says the frame is front-end bound on the compute↔graphics switches, not on the clamp's arithmetic. Removing the switches by removing the clamp also removes the safety, which is not a trade worth making. The next step is to batch the clamp itself: one clamp dispatch, or a few windowed ones, covering a whole run of consecutive indirect records instead of one pass per record — every bounds check kept, and the `0xFFFF_FFFF` zeroing for unfilled tail slots kept without charging their budget. That is where the ~5,000 switches go without giving up the clamp. It goes up as its own PR; I will tag you for a run if you are willing. Also noted that the same crash site appeared once on an earlier build and did not reproduce on relaunch — thank you for saying so rather than leaving it as clean attribution. It does not change the conclusion for the flag.
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-25 11:12 UTC · original

Rebased onto f85101b6. It conflicted because #220 landed the indirect draw windows in the same region of execute_indirect — the resolution keeps both: your window block (including its VICTORY_INDIRECT_WINDOW_CHECK check on the held path) is now the clamped arm, and VICTORY_INDIRECT_CLAMP=0 is the bypass arm around it, so the bypass composes with the window instead of replacing it.

Two things worth knowing before merge:

  • The opt-out is still diagnostic only, as the body says: turning it off crashed twice during the load into the world.
  • Merge order against #862 (perf/indirect-window-batching) matters — both edit execute_indirect. Landing this first is the order that works; #862 will be rebased on top of it.

/kee probes on this rebase: forcing parse_clamp_enabled to always return true fails parse_clamp_enabled_defaults_on_and_respects_explicit_disable at "0" must disable indirect clamp; dropping the alignment checks from validate_layout fails its test. Both red for the right reason, both restored byte-identical.

Gate on eb568071: cargo test -p victory-gpu --locked → 161 passed, 0 failed, 4 ignored; indirect:: with --test-threads=1 → 14 passed, 2 ignored and warp_budget_saturates_without_wraparound_and_preserves_draw_fields red, which is the known budget race #849 fixes (it fails 5 runs in 6); both clippy passes red only on main's own three lints; xtask 4 passed.

**@⁠HailLucifer666** on GitHub · 2026-11-25 11:12 UTC · [original](https://github.com/fxceless/victory-fork/pull/169#issuecomment-7160738425) Rebased onto `f85101b6`. It conflicted because #220 landed the indirect draw windows in the same region of `execute_indirect` — the resolution keeps both: your window block (including its `VICTORY_INDIRECT_WINDOW_CHECK` check on the held path) is now the `clamped` arm, and `VICTORY_INDIRECT_CLAMP=0` is the bypass arm around it, so the bypass composes with the window instead of replacing it. Two things worth knowing before merge: - The opt-out is still **diagnostic only**, as the body says: turning it off crashed twice during the load into the world. - Merge order against #862 (`perf/indirect-window-batching`) matters — both edit `execute_indirect`. Landing this first is the order that works; #862 will be rebased on top of it. `/kee` probes on this rebase: forcing `parse_clamp_enabled` to always return true fails `parse_clamp_enabled_defaults_on_and_respects_explicit_disable` at `"0" must disable indirect clamp`; dropping the alignment checks from `validate_layout` fails its test. Both red for the right reason, both restored byte-identical. Gate on `eb568071`: `cargo test -p victory-gpu --locked` → 161 passed, 0 failed, 4 ignored; `indirect::` with `--test-threads=1` → 14 passed, 2 ignored and `warp_budget_saturates_without_wraparound_and_preserves_draw_fields` red, which is the known budget race #849 fixes (it fails 5 runs in 6); both clippy passes red only on `main`'s own three lints; `xtask` 4 passed.
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-25 14:33 UTC · original

Rebased onto current main (0b0074e0) — clean, no conflicts — so this is now draw.rs and indirect.rs against today's tree rather than seven commits behind it.

Re-verified after the rebase, since a probe on an old tree proves nothing about the new one: clamp_setting returning parse_clamp_enabled(asked) again fails left: (false, true), right: (true, true); restored byte-identical (indirect.rs sha256 c5707c8b7898490a). Suite: 173 passed, 0 failed, 5 ignored. kee preflight --base main: FAIL 0, all six CHECK rows answered with evidence.

Two corrections to what this PR body says above:

  • Clippy now reports three errors on this branch, not two, and all three are main's — checked by running clippy on victory-fork/main alone: placed_filler_twins, sort_unstable_by_key, and manual_is_multiple_of (shadow.rs:2675). None is introduced here and none is fixed here; riding an unrelated clippy fix inside this PR is how a diff stops being readable.
  • Merge after #970. This branch still carries main's index-exact warp-budget assertion, so until #970 lands its suite can fail for a reason that has nothing to do with this change. #970 makes that test accept both legal orders; then this one rebases and its evidence is its own.
**@⁠HailLucifer666** on GitHub · 2026-11-25 14:33 UTC · [original](https://github.com/fxceless/victory-fork/pull/169#issuecomment-7165450679) Rebased onto current `main` (`0b0074e0`) — clean, no conflicts — so this is now `draw.rs` and `indirect.rs` against today's tree rather than seven commits behind it. Re-verified after the rebase, since a probe on an old tree proves nothing about the new one: `clamp_setting` returning `parse_clamp_enabled(asked)` again fails `left: (false, true), right: (true, true)`; restored byte-identical (`indirect.rs` sha256 `c5707c8b7898490a`). Suite: **173 passed, 0 failed, 5 ignored**. `kee preflight --base main`: **FAIL 0**, all six CHECK rows answered with evidence. Two corrections to what this PR body says above: - Clippy now reports **three** errors on this branch, not two, and all three are `main`'s — checked by running clippy on `victory-fork/main` alone: `placed_filler_twins`, `sort_unstable_by_key`, and `manual_is_multiple_of` (`shadow.rs:2675`). None is introduced here and none is fixed here; riding an unrelated clippy fix inside this PR is how a diff stops being readable. - **Merge after #970.** This branch still carries `main`'s index-exact warp-budget assertion, so until #970 lands its suite can fail for a reason that has nothing to do with this change. #970 makes that test accept both legal orders; then this one rebases and its evidence is its own.
github-bot force-pushed github-bot/gh-169 from 65556753f3 to d41db98d8c 2026-11-26 14:05:53 +00:00 Compare
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-26 14:01 UTC · original

Rebased onto main a20809de; head is now d41db98d (no conflicts — the bypass composition with the landed window block still applies cleanly). Verified: victory-gpu indirect:: --test-threads=1 20 passed, 0 failed, 2 ignored; clippy -D warnings on victory-gpu clean. The default stays clamped, as the title says; 0 is refused.

**@⁠HailLucifer666** on GitHub · 2026-11-26 14:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/169#issuecomment-7194172580) Rebased onto `main` `a20809de`; head is now `d41db98d` (no conflicts — the bypass composition with the landed window block still applies cleanly). Verified: `victory-gpu indirect:: --test-threads=1` 20 passed, 0 failed, 2 ignored; `clippy -D warnings` on victory-gpu clean. The default stays clamped, as the title says; `0` is refused.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/169/head:github-bot/gh-169'
git switch 'github-bot/gh-169'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-169'
git switch 'github-bot/gh-169'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-169'
git switch 'github-bot/gh-169'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-169'
git switch 'main'
git merge --squash 'github-bot/gh-169'
git switch 'main'
git merge --ff-only 'github-bot/gh-169'
git switch 'main'
git merge 'github-bot/gh-169'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.