Skip to content

shader, gpu: port 32-lane BVH builder lowering, structure views, and GPURT node answer - #403

Open
Kikoarl wants to merge 1 commit into
trustno1-coder:mainfrom
Kikoarl:feat/bvh-builder-32lane
Open

Kikoarl wants to merge 1 commit into
trustno1-coder:mainfrom
Kikoarl:feat/bvh-builder-32lane

Conversation

@Kikoarl

@Kikoarl Kikoarl commented Nov 27, 2026

Copy link
Copy Markdown

Summary

Ports the portable 32-lane BVH builder lowering fixes, placed acceleration-structure view_address (Location), and GPURT [u32::MAX; 4] node answer from fxceless/victory-fork commits 17533c5, 1170216, 1320dfd, and 9a9091d (GPL-3.0-or-later), rebased onto main (df2daaf).

VICTORY_BVH_BUILDER remains opt-in (=1, off by default).

Changes

  • crates/victory-shader/src/emit/lower.rs, emit/wave64_tests.rs: Enables USER_DISPATCH_THREADS_X guarding (partial_active, effect_guard) for spilled 1D compute programs on 32-lane waves and programs with barriers instead of returning early; refines lane_uniform dword tracking, uniform ds_read checks, and v_readfirstlane_b32 masking when halves match or are guarded.
  • crates/victory-shader/src/bvh.rs, emit/intersect.rs: Returns [u32::MAX; 4] (-1 per AMD GPURT) for instance and procedural BVH nodes (kinds 6 and 7), and applies effect_guard to BVH intersection loads.
  • crates/victory-gpu/src/descriptor/host.rs: Extracts Location (words 4–5) for placed as well as shader acceleration-structure views in view_address, returning None when zero.
  • Adaptations for main: Omits 17533c5 (VICTORY_WAVE_PAIRS_SPILLED, paired.rs is absent on main) and omits 9a9091d written-page tracking because main uses Shadow::by_address sync (preserving PR Ray tracing: no arena storm when the low range is full (the 30 s watchdog crash); reserve the arenas' room at the start #88 and PR descriptor: placed views ignore padding words (views leak, confetti on faces) #58).

Verification

Verified on Windows (x86_64-pc-windows-msvc) against main (df2daaf):

  • git diff --check main..HEAD — clean
  • cargo test -p xtask --locked — 6 passed, 0 failed (asset policy: 287 files ok)
  • cargo clippy -p victory-shader -p victory-gpu --all-targets --locked — exit 0, 0 warnings in changed files (main has pre-existing clippy warnings in untouched files)
  • cargo test -p victory-shader --locked emit::wave64_tests — 17 passed, 0 failed
  • cargo test -p victory-gpu --locked descriptor:: — 62 passed, 0 failed

…GPURT node answer

Port the portable pieces of fxceless/victory-fork commits 17533c5, 1170216, 1320dfd, and 9a9091d onto trustno1 main (f3534e6):

- victory-shader: enable USER_DISPATCH_THREADS_X guarding for spilled 1D compute programs on 32-lane waves and programs with barriers by adding partial_active/effect_guard instead of early return when threads must stay for s_barrier or two-wave exchanges (after 1320dfd).

- victory-shader: check exact operand dwords in lane_uniform (full dwords on scalars, exact VGPR dwords except v_movrel/v_swap), widen ordered/stable uniform ds_read checks beyond ds_read_b32, and mask v_readfirstlane_b32 with partial_active when halves are alike or guarded (after 1170216, 1320dfd).

- victory-shader: return [u32::MAX; 4] (-1 per AMD GPURT) for instance and procedural BVH nodes (kinds 6 and 7) in bvh::intersect and emit::intersect, and use effect_guard for BVH intersection loads (after 9a9091d).

- victory-gpu: extract Location (words 4-5) for placed as well as shader acceleration-structure views in view_address, returning None when zero (after 9a9091d).

Adaptations for main: 17533c5 (VICTORY_WAVE_PAIRS_SPILLED) is inapplicable because main uses halves/exchange/pairs without paired.rs; 9a9091d memory sync/written-page tracking is omitted because main already uses arena Shadow::by_address sync (preserving PR trustno1-coder#88 and PR trustno1-coder#58) and VICTORY_BVH_BUILDER remains opt-in (=1).
@Castyan

Castyan commented Nov 27, 2026

Copy link
Copy Markdown

i'm on it for testing

@Castyan

Castyan commented Nov 27, 2026 •

Copy link
Copy Markdown

#388 + #403 merged on main (df2daaf): no conflict, no new failure. Windows, RTX 5060, cargo test --workspace --no-fail-fast: 1070 passed (main 1064, the +6 are #403's new tests), 2 failed (victory-gpu indirect::tests, the same 2 on main). The clippy error at victory-formats/src/texture.rs:1346 is on main too. Not tested in game or with translate --list.

In game (RTX 5060 8 GB, 15 GB RAM, below the README's 32 GB): CS_CollectTriangles_Meshlets translates and gets its host pipeline. Series S + 2x frame gen ran 11 min, then device removed (0x887A0007). Series X runs out of memory after 2-3 min (E_OUTOFMEMORY), with main too (driver access violation in nvwgf2umx.dll). So the crashes look like this PC's memory, not these PRs. Not a like-for-like comparison.

@CowboyBingus

Copy link
Copy Markdown

A/B in game: with this PR, 1,626 of 1,635 static structures with header 0x80020006 are sound; without it, 138 of 1,332.

Setup: two builds that differ only by this PR's 5 files (git diff --stat between the arms):

  • base: main 8fc2254 + 2 window-focus test commits;
  • A: base + this PR's head a265798 merged + 3 diagnostics commits;
  • B: base + the same 3 diagnostics commits.

Each arm was one run with VICTORY_BVH_BUILDER=1, VICTORY_BVH_CALLS, VICTORY_MEMORY_DUMP, VICTORY_MEMORY_DUMP_BUFFERS=4 and VICTORY_NO_ACTIVATE=1, the same scripted key presses, and a dump of title memory (23 arenas) started at 104.3 s (A) and 104.1 s (B) after launch. Counted: static structures (packed entries last given at least 16 frames before the dump's first copy). "Sound" means every reachable node is in the dump and in bounds, no box child is of kind 6/7, and at least one triangle node is reached (walks capped at 200,000 nodes).

headers 0x80020006 sound triangle nodes still packed (0x81020006)
A, with this PR 1,635 1,626 1,715,219 14
B, without 1,332 138 276 51

Two earlier dumps, from different builds and runs, split the same way: with this PR 1,845 of 1,912 sound (2,222,662 triangle nodes); without it 140 of 1,437 (294).

This is one run per arm.

Still open with this PR (measured, not attributed to it):

  • Of the 14 still packed in run A, 2 were rehydrated once and 12 twice before their arena was copied; the 12 twice-rehydrated call pairs were 11-46 frames apart.
  • In an earlier with-PR dump, 596 of the 2,301 enabled instances (of 4,464) in one top-level structure name 184 bases that the dump lists as built (not packed), with no version-6 header.

🤖 Generated with Claude Code

@ANDREANIADS

Copy link
Copy Markdown

I added a two-line regression check on a265798 that expects [u32::MAX; 4] directly for instance and procedural nodes (kinds 6 and 7), independently of the CPU reference. With the same test file on both revisions, all four D3D12 readback tests failed on df2daaf at the first kind-6 case and passed on this PR’s head using Windows WARP. The runner had no SM 6.6 hardware adapter. This check covers synthetic node readbacks only.

Two-line test · Windows job with before/after results

whoalin1 added a commit to whoalin1/victory-altracing-prs that referenced this pull request Nov 28, 2026
…artial groups with barriers, ray-box test answers)

From trustno1-coder#403 (Kikoarl; ports of fxceless/victory-fork 1170216,
1320dfd). Its core (threads past a DispatchX count kept under partial_active) was
already here from avatarmanz 06fe22a (9f9eff4); what was missing:

- counted_in_threads no longer leaves out programs with s_barrier: their lanes past
  the count used to run everything, stores included. Where a barrier, a two-wave
  exchange, a ticket, split LDS or a loop back to the entry keeps the group's
  threads together they stay under partial_active; otherwise they leave at entry.
- image_bvh64_intersect_ray takes memory_guard: those threads no longer read (and
  note faults on) stray pages.
- Kinds 6 and 7 (instance, procedural) answer [u32::MAX; 4] as the hardware does
  (AMD GPURT IntersectCommon.hlsl), in the CPU reference and the DXIL lowering.
- lane_uniform reads only an operand's own registers (not an old destination value
  kept for guards), every dword of a scalar operand, and any ordered ds_read from a
  uniform address (not _d16 or addtid).
- view_address reads the structure's location from placed views too.

Tests (PR trustno1-coder#403's, appended): the_builders_prefix_sum_lowers_exactly_on_32_lane_waves,
..._as_a_spilled_dispatch_x_program, threads_past_a_dispatch_x_count_do_nothing,
the first-lane LDS read tests, structure_views_report_their_location_as_view_address,
instances_and_procedural_nodes_return_all_ones.
cargo test -p victory-shader --release: 297 passed, 4 ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eleboucher

Copy link
Copy Markdown

Measured on an RTX 4070 Ti SUPER (32-lane waves), with the title's own ray tracing (VICTORY_RT_NATIVE=1). This is a data point for the USER_DISPATCH_THREADS_X part of this PR.

Without it, the gate in counted_in_threads (!wave64 || host_max_wave() >= 64) leaves the wave64 builder stages caa78b8c and 28918b71 uncounted on NVIDIA. The last group of each DispatchX runs all 64 lanes. Those lanes store past the structure's end, and s_bcnt1_i32_b64 exec returns 64 instead of n, which moves every lane's read.

With a fix for that part alone, a card dump of the ray-tracing memory read with bvhwalk changes like this:

before after
packed (static) instances with a valid root 1 of 50 55 of 55
triangles reachable from the roots 43,458 102,624
ray misses whose first anomaly is an inverted box 2,318 100

In the prison-cell scene at the start, the room is no longer lit evenly by rays that pass through missing walls. Light now comes only through the window.

If it helps review, the fix for that one part is a single commit on top of main: eleboucher@ff74e1c0. It keeps the lanes past the count in the wave and outside EXEC on entry, so the two halves can still exchange through LDS. victory-shader --lib passes on the card: 295 passed. I'm not opening a separate PR, to avoid a duplicate of this one.

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.

5 participants