Skip to content

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

Open
HailLucifer666 wants to merge 1 commit into
fxceless:mainfrom
HailLucifer666:perf/indirect-clamp-bypass
Open

HailLucifer666 wants to merge 1 commit into
fxceless:mainfrom
HailLucifer666:perf/indirect-clamp-bypass

Conversation

@HailLucifer666

@HailLucifer666 HailLucifer666 commented Nov 24, 2026 •

Copy link
Copy Markdown

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

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.

RicerBoy added a commit to RicerBoy/DropItLikeItsHot that referenced this pull request Nov 24, 2026
…DIRECT_CLAMP=0 opt-out to bypass per-draw argument clamping

Part of #16
@dkdknight

Copy link
Copy Markdown

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

@HailLucifer666

Copy link
Copy Markdown
Author

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
HailLucifer666 force-pushed the perf/indirect-clamp-bypass branch from 5805143 to eb56807 Compare November 25, 2026 11:12
@HailLucifer666

Copy link
Copy Markdown
Author

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:

/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 HailLucifer666 changed the title GPU: add VICTORY_INDIRECT_CLAMP=0 opt-out to bypass per-draw argument clamping Refuse VICTORY_INDIRECT_CLAMP=0: it kills the run, and hoisting is the answer to the cost Nov 25, 2026
@HailLucifer666
HailLucifer666 force-pushed the perf/indirect-clamp-bypass branch from c4f3bb8 to ffda299 Compare November 25, 2026 14:32
@HailLucifer666

Copy link
Copy Markdown
Author

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:

@HailLucifer666
HailLucifer666 force-pushed the perf/indirect-clamp-bypass branch from 8e35e16 to 6555675 Compare November 25, 2026 20:20
PiloteCode added a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
…witch, its lowerings of instructions the title does not run, and 16-bit results by MODE

Ported from Marvisak/VIctory into emit/official.rs, a child module of the
lowering; lower.rs and the instruction modules (valu, valu16, salu, buffer,
interp, image, export) only call it (lower.rs: 129 bytes more, for the module
and the round-mode state).

On by default, `VICTORY_<NAME>=0` gives the translation as before (each is
part of the shader cache key):
- VICTORY_MESH_EDGE_FLAGS (#1718, c0228d9): a mesh primitive's corners are
  9-bit indices, the edge flag above each (bits 9, 19, 29) no part of it.
  Ours took 10 bits, so a flagged corner named vertex 512+ and the triangle
  was culled as naming a vertex past the program's count. Every mesh
  program's DXIL (the mask constant).
- VICTORY_NORM_ENDS (fxceless#169, 645391b): a normalized buffer format's ends load
  as exactly 1.0 and -1.0 whatever the host's division gives there (vertex
  fetch, typed-format loads of compute programs): 9,764 programs.
- VICTORY_CUBE_GRAD_LEVEL (4f57f46; the same fix as 9ee9adf of
  fxceless#767, flagged by amdsh): a cube sample with gradients takes log2
  of the longer gradient in texels (DXIL's Log is base 2, ours multiplied it
  by log2(e) again: 1.44 times the level, blurrier cube reads), at least the
  _cl clamp: 29 pixel programs.
- VICTORY_SMINMAX_SCC (77053a0's scalar part): s_min/s_max set SCC to
  whether the first operand was chosen (RDNA2 ISA); ours set result != 0.
- VICTORY_INTERP_F16_MODIFIERS (#1696, e29391f): v_interp_p2_f16 honours
  op_sel[3] (the high half), omod and clamp; only an instruction that has
  one of them translates differently (the title's have none).
- VICTORY_DEAD_PHI_LATCHES (#1471, be3202d): an empty loop latch whose phis
  are all unread folds as an empty one does.
- VICTORY_BRANCH_FALLTHROUGH (#1282, 1ed26e5): a conditional branch to the
  next instruction is a jump. As a branch it gave its block the same
  successor twice, and the join's phi the wrong value (the official test
  fails on ours without it, on WARP).

Off by default:
- VICTORY_OMOD_ZERO=1 (77053a0): an output multiplier reads a denormal
  operand as a zero of its sign and gives +0 for a zero product, as RDNA2
  measured with IEEE mode off. Compilers fold every x2, x4, x0.5 into one:
  12,276 programs would gain its eight instructions, for the sign of a zero.
- 16-bit results by MODE (77053a0), under our VICTORY_F16_NEAREST=1: every
  f32 to f16 result of a VALU operation (v_cvt_f16_f32, v_fma_mixlo/hi_f16,
  packed and scalar f16 arithmetic, f16 interpolation) rounds as the
  console's MODE says where it is: toward zero after
  `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3` (the title writes it
  6,694 times, around its 16-bit interpolation), to nearest even elsewhere;
  the switch covered 16-bit arithmetic only, at nearest even everywhere.

Without switches (no program of the title runs them): s_quadmask_b32/b64
(#1443), v_cvt_off_f32_i4 (#1391), v_sad_u8/hi_u8/u16/u32 and v_msad_u8
(fxceless#162), v_mul_hi_u32_u24/i32_i24 (fxceless#156), tbuffer_load_format_d16_* packed two
channels a VGPR (fxceless#169, c430b1d), a signed 64-bit operand's literal
sign-extended (fxceless#447, 7d04943), v_cndmask_b32 on an inline constant mask or a
mask the structurisation keeps among its other masks (#1221, 67c4f53;
Structured::other exported), and v_cmp_f/tru as constants (`fcmp false/true`
removed the WARP device; 77053a0). format_load and write_half became
pub(super), for official.rs.

Tests: the official ones of these (valu_tests on the hardware adapter and
WARP: quad masks, cvt_off, tbuffer d16, normalized ends, i64 literals,
branch to fallthrough), its instruction tests fxceless#1052, fxceless#1050 and fxceless#990 (they
pass on ours unchanged), CPU models of the SAD, 24-bit high multiply and
s_min/s_max SCC results, and the MODE rounding under VICTORY_F16_NEAREST.

Census (CPU, against wave5's own): with every switch off, every program's
DXIL is byte for byte as before; with the defaults, 10,711 programs change
(Ms 8,765, Cs 1,077, Vs 840, Ps 29) and none is lost or gained (25,953 of
25,953 pass either way).
PiloteCode added a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
…same output, mesh stage data without the vertex inputs (#1366), mesh primitive indices of 9 bits (#1718, VICTORY_MESH_EDGE_FLAGS), normalized ends exactly +-1 (fxceless#169, VICTORY_NORM_ENDS), cube gradient level (4f57f46, VICTORY_CUBE_GRAD_LEVEL), the official semantics suite, SP3 text and s_atc_probe (fxceless#661, fxceless#1021)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants