Skip to content

Shaders: the ray-tracing structure builder's three wave64 programs on 32-lane hosts (exact, no write-only shortcut) - #1700

Merged
trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
L-696:wave32-structure-builder
Nov 29, 2026
Merged

trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
L-696:wave32-structure-builder

Conversation

@L-696

@L-696 L-696 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #1475

What it changes

On a 32-lane host (NVIDIA), three of the ray-tracing structure builder's 53 compute programs are refused ("no wave32 lowering for this wave64 program"). The builder's stages run all or none, so the builder stays off (missing=3 of=53). This PR translates the three with exact forms. It does not use the LDS write-only shortcut, so no approximation is involved.

  • 28918b7150a7aad5, caa78b8ca62bc3d6 (groups of 64): their per-lane loops write LDS that other lanes read, inside per-lane skips (s_cbranch_execz). Only widen() translates them, with 3 branches taken wave-wide in each. Each group is a single console wave, so the group barriers meet exactly its two host waves. Both shaders join the programs that are widened by default.
    • Those defaults now live in wide_by_default(digest, threads), keyed by group size: 64, 128 or 512.
    • The existing entries are unchanged, including CS_CollisionRaytraced. water_portals and the DefragHeap with_half_meets path are untouched.
  • e63d22c4def9ba6a (groups of 512, eight console waves): 8 rounds of a 4-bit ballot. Each console wave's first lane counts the ballot with s_bcnt1 inside a skip.
    • The mask's halves have to be exchanged at the tail of a block that has already been lowered. With pair meetings that was refused, because the meeting would split the block.
    • The new once_per_thread marks the blocks that every thread of the group runs exactly once: blocks that post-dominate the entry and are on no cycle. They are combined with all_lane_blocks_of(st, true).
    • In such a block, the exchange takes the existing group-barrier path, so every console wave reaches the barrier exactly once. Everywhere else the exchange is still refused with its own message.

Synthetic regression tests (wave64_tests.rs, no game code):

  • lds_exchange_in_a_loop_inside_a_lane_skip_needs_the_skip_wave_wide: the 28918b71/caa78b8c shape. Run on the card, the result matches the console model.
  • a_ballot_before_a_first_lane_skip_is_exchanged_with_the_whole_group: the e63d shape, in a group of 128 (two console waves).
    • Run on the card, every tested s0 (0, 1, 31, 32, 37, 64, 65, 100, 127, 128) gives [min(s0,64), min(s0-64,64)], the console's counts.
    • With the new path disabled, this test fails with e63d's error.
  • a_ballot_inside_a_wave_wide_branch_of_several_console_waves_stays_refused: the same code inside a branch that console waves may take differently is still refused, with the exact message.
  • the_structure_builders_programs_are_widened_by_default: each digest is enabled only at its own group size.

How it was tested

  • GPU and profile: RTX 4060 8 GB, driver 621.40, Windows 11 26100. Series S profile, DLSS and frame generation (MFG), ray tracing with VICTORY_BVH_BUILDER=1, cold shader cache.
  • Before (main 32ecacf):
    WARN victory_gpu::pipeline: the ray-tracing structure builder stays off: not all of its programs have a host pipeline, and its stages run all or none missing=3 of=53 which=["e63d22c4def9ba6a", "caa78b8ca62bc3d6", "28918b7150a7aad5"]
    
  • After (the same change on 32ecacf; this rebase onto d4b5d51 has not been run in-game):
    INFO victory_gpu::pipeline: shader translated stage="compute" hash=e63d22c4def9ba6a user_data=16 samplers=0
    INFO victory_gpu::pipeline: shader translated stage="compute" hash=caa78b8ca62bc3d6 user_data=9 samplers=0
    INFO victory_gpu::pipeline: shader translated stage="compute" hash=28918b7150a7aad5 user_data=9 samplers=0
    INFO victory_gpu::pipeline: the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53
    
    About 13 minutes of play followed. The log has no ERROR, TDR or device-removed lines, and the run ended with a normal exit.
  • Offline, on this branch (d4b5d51 + this commit):
    • Before the patch, all three are refused here too. After it, all three translate (31608 / 41148 / 67776 bytes of DXIL), and the driver creates a compute pipeline for each.
    • Census of all 2,734 compute programs, with and without the patch: 2,692 → 2,695 translate. Only these three change; the other 2,731 have identical results and byte-identical DXIL.
  • Wave sizes tested: 32-lane host. On 64-lane hosts nothing changes: the new paths apply only when the host's maximum wave is 32.
  • cargo test: yes. victory-shader --lib 352 passed, 0 failed, 9 ignored; victory-gpu --lib 550 passed, 43 ignored; cargo build --release -p victory succeeds.
  • cargo clippy --workspace --all-targets -- -D warnings: fails on two findings that are already on main and not in this diff: lower.rs spare / per (manual checked division) and the unused colour. It reports nothing for this diff.

Not verified, and help is welcome

  • Whether the traced image is fully correct with the builder on. Lighting, reflections, foliage and materials were not compared frame by frame against a reference.
  • Other NVIDIA cards, especially the RTX 30 series. NVIDIA RTX 3060: device hung/removed entering the world: view heap cap at 1M, wave64-only compute shaders Marvisak/VIctory#3330 reports a 3060 hanging on 64-thread programs of this kind under a different split. These kernels use group barriers and per-console-wave meetings, so review of the synchronisation reasoning (once_per_thread, and the exchange in exchange_halves) is welcome.
  • The performance and VRAM cost of running the builder.

Checked for overlap

AI assistance: written and tested with Claude (Anthropic); the in-game run was done by hand on the card above.

🤖 Generated with Claude Code

… 32-lane hosts

Three of the builder's 53 compute programs were refused on NVIDIA ("no wave32
lowering for this wave64 program"), so the builder stayed off (missing=3).

- 28918b7150a7aad5 and caa78b8ca62bc3d6: groups of 64 whose per-lane loops write
  LDS inside execz skips. Only widen() translates them; they join the programs
  widened by default (now `wide_by_default`, keyed by group size).
- e63d22c4def9ba6a: groups of 512 (eight console waves). A 4-bit ballot is counted
  by each console wave's first lane inside a skip, so the mask halves must be
  exchanged at the tail of a block already lowered, which pair meetings refused.
  Where that block is one every thread of the group runs exactly once
  (post-dominates the entry, on no cycle: `once_per_thread`), the exchange now
  uses the group-barrier path; everywhere else it stays refused.

Synthetic tests: an LDS exchange in a loop inside a lane skip needs the skip
wave-wide; a ballot before a first-lane skip in a group of two console waves
is exchanged with the whole group (matches the console on the card); the same
ballot inside a wave-wide branch stays refused; the default widening policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 28, 2026
@github-actions github-actions Bot changed the title [pr-fix] Shaders: the ray-tracing structure builder's three wave64 programs on 32-lane hosts (exact, no write-only shortcut) Shaders: the ray-tracing structure builder's three wave64 programs on 32-lane hosts (exact, no write-only shortcut) Nov 28, 2026
@eleboucher

Copy link
Copy Markdown
Contributor

On an RTX 4070 Ti SUPER (32 lanes) this PR gets the builder running. The runs that died ran out of memory; nothing points at this change.

Setup: Ryzen 7 9800X3D, 16 GB RAM, Windows 11 build 26300. Native 1440p, VICTORY_BVH_BUILDER=1 VICTORY_ACTIVATE_RAYS=1, diagnostics build. Base is main f9dfb76 + #1640 + this PR. Conflict with main: emit/mod.rs, where main had added the four CS_Tree_BatchCull digests to the inline list. I kept your wide_by_default and added those four to GROUPS_OF_64.

  • Builder: e63d22c4, caa78b8c and 28918b71 translate, and the builder runs: structure builder lines throughout, no TDR line.
  • Dropped dispatches: "dropped without a host pipeline" falls from ~350 a frame (builder kept off on main) to 2-10.
  • Tests: 1388 passed. The same 2 tests fail on plain main (crash::tests::memory_at_names_what_an_access_hit, policy::tests::repository_passes_policy).
  • Start 1: ran through the unpack burst (0.4-2.6 fps at 120-180 s), then 14.4 / 14.4 / 13.7 fps at 240 / 300 / 420 s. It died between 420 and 600 s with device removed (0x887A0004). Shared GPU memory rose 6540 → 6994 MB against Windows' 7224 MB cap on a 16 GB PC, with 0.2-0.4 GB of RAM free.
  • Start 2: died at ~120 s in the burst, device removed (relay fence not reached, 0x887A0005).
  • Without this PR: the builder stays off, and the same base runs 10 minutes at ~25 fps.

So on 16 GB the builder fits only briefly. Trying the windows-in-card-memory / texture-room trade next.

optimax94 added a commit to optimax94/VIctory-NVIDIA-ultimate that referenced this pull request Nov 29, 2026
…1, VIctory Play

On trustno1-coder/VIctory-NVIDIA's main:

- RT CORES (VICTORY_HW_RT): native DXR 1.1 structures for the title's
  builder, Rockstar's compressed geometry decoded, BVH walks lifted to
  inline RayQuery (from dakisback2/VIctory-Nvidia-Linux, ported).
- Release build with thin LTO, one codegen unit, x86-64-v3 and mimalloc
  (from KyleS98/VIctory-Neo); SPEED tab: card kept awake off, stores
  beside the guards on (their measurements).
- The structure builder's wave64 programs on 32-lane cards (pull request
  trustno1-coder#1700); VICTORY_LDS_WRITE_ONLY_OK on by default (issue trustno1-coder#1435).
- F1 menu in tabs (IMAGE, CONTROLS, LIGHT/RT, SPEED, EXPERT); SPEED:
  streaming and texture ports, texture room at low render sizes.
- VIctory Play (apps/victory-play): a launcher that follows the game
  through its warm-up and F1 restarts, prepares shaders with progress,
  edits F1's settings by the same tabs, purges caches.
- RT capture diagnostics (VICTORY_RT_CAPTURE) and the ray-tracing research
  notes (docs/hardware-ray-tracing.md).

README rewritten for this build; the base's README is kept in docs/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trustno1-coder
trustno1-coder merged commit e19b4ca into trustno1-coder:main Nov 29, 2026
1 check passed
@NotADonky43

Copy link
Copy Markdown
Contributor

RTX 5070 Ti / Series X: on a cumulative descendant with the reflection fold scoped separately, asking for RT left the builder off, missing 1 of 53 stages (the 512-thread ballot). With the shader changes from this PR integrated, both ballot tests passed and the real game explicitly activated all 53 stages. In an exact-executable warmed release with #1878 and BVH_SIZE_COPY also enabled, six settled heavy reports ranged from 0.5 to 15.1 rendered FPS. This verifies builder activation, not visual parity or sustained performance. Static-sampler and GPU wait safeguards retained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray-tracing structure builder stays off at 32ecacfa on a 32-lane host: three builder programs refused; they translate with VICTORY_LDS_WRITE_ONLY_OK=1

4 participants