Skip to content

GPU: add VICTORY_INDIRECT_CLAMP=0 opt-out to bypass per-draw argument clamping - #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

Copy link
Copy Markdown

Problem

  • Every ExecuteIndirect call (even when batched via VICTORY_INDIRECT_WINDOW=1) runs a clamp compute shader between two global UAV barriers and state transitions, and invalidates cached host compute pipeline and root-signature state.
  • In gameplay, thousands of indirect mesh draws per frame pay compute/graphics mode switches, scratch copies, barrier stalls, and state rebinds even when the title's argument buffers are valid.

Fix

  • Add VICTORY_INDIRECT_CLAMP (enabled by default; 0 / false / no / off disables clamping).
  • When disabled, draw::State::indirect validates record alignment/stride via indirect::validate_layout, refreshes the argument/count shadow ranges, emits a single UAV barrier (indirect::wait_direct), and executes ExecuteIndirect directly from the title's argument buffer without running the clamp compute pass, scratch copy, state transitions, or pipeline invalidation.

Verification

  • Added unit tests parse_clamp_enabled_defaults_on_and_respects_explicit_disable and validate_layout_rejects_misaligned_or_overflowing_direct_arguments.
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test -p victory-gpu indirect:: --locked -- --test-threads=1 (9/9 passed)
  • cargo test -p xtask --locked (4/4 passed)

… clamping

THE BUG.
Every ExecuteIndirect call (even when batched via VICTORY_INDIRECT_WINDOW=1) runs a clamp compute shader between two global UAV barriers and state transitions and invalidates cached host compute pipeline/root-signature state.

WHY NOT HYPOTHETICAL.
In gameplay, thousands of indirect mesh draws per frame pay compute/graphics mode switches, scratch-buffer copies, barrier stalls, and state rebinds even when the title argument buffers are already valid.

THE FIX.
Add VICTORY_INDIRECT_CLAMP (enabled by default; 0/false/no/off disables clamping). When disabled, draw::State::indirect validates record alignment/stride via indirect::validate_layout, refreshes the argument/count shadow ranges, emits a single UAV barrier (indirect::wait_direct), and executes ExecuteIndirect directly from the title argument buffer without running the clamp shader, scratch copy, state transitions, or pipeline invalidation.

SCOPE.
Only the indirect argument clamping path in indirect.rs and draw.rs. Default behavior (clamping enabled) is unchanged.
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.)

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