Skip to content

Ray tracing: shadow-ray traces and the full structure builder translate on 32-lane GPUs - #156

Open
sedzz wants to merge 2 commits into
fxceless:mainfrom
sedzz:rt/shadow-traces-and-builder-32-lane
Open

sedzz wants to merge 2 commits into
fxceless:mainfrom
sedzz:rt/shadow-traces-and-builder-32-lane

Conversation

@sedzz

@sedzz sedzz commented Nov 24, 2026 •

Copy link
Copy Markdown

What

Two translator/host gaps kept the title's ray-tracing programs from running on a host whose waves are 32 lanes (the console's are 64). This PR closes both.

With VICTORY_HOST_WAVE=32 on a 32-lane card:

  • 4 of the 5 shadow-ray trace compute programs (and their screen-space variants) now translate and validate. The adaptive one still stops (see below).
  • 52 of the 52 ray-tracing structure-builder programs now translate, validate and create a host pipeline. Three of them did not before, and that is exactly why the log said the ray-tracing structure builder stays off ... missing=3.

Changes

1. Buffer views picked from the view heap at a computed index (shader.rs, mod.rs, descriptor/host.rs, lower.rs)

The shadow-ray trace programs read the address of their structure out of a heap descriptor they choose with a per-wave index, then walk the memory behind it. The translator could only take such an address from a fixed table position (view_address refuses a.dynamic).

The host now keeps, after the strides of SLOT_STRIDES, two more dwords per heap slot: the low and high dword of the title address of the buffer view there. They are written where the strides are written. The shader reads them by heap slot (SLOT_ADDRESSES, Lower::slot_address). No new root parameter and no change to draw.rs or the pipeline code.

Cost: the table grows from 8 MB to 24 MB per view heap.

2. lane_uniform proves three more things (lower.rs)

Each only where no lane of a wave can part from the others:

  • tid >> 6 of the entry thread number, in a group whose x size is a multiple of 64, is the same in all lanes of a console wave;
  • an ds_read_b32 at such an address is;
  • a value joined by a phi, also at a loop header, is when its arguments are and every predecessor is entered by all the arriving lanes or none. This is a greatest fixed point over the loop's carried values and lane masks: a loop-carried value is assumed alike and the assumption is dropped once an argument is not.

The structure builder's block-scan programs fetch a wave-uniform running total with v_readfirstlane inside such a loop. Without the proof they asked for an exchange between the two host waves where not every lane runs, which cannot be done (it needs a group barrier).

shortcut: (marked in the code) an LDS read is taken to see what a read by another wave of the same instruction would. A write by another wave between the two host waves' reads is not looked for; the scan programs read after a barrier.

Testing

Hardware: one NVIDIA RTX 3090, Windows 11 (32-lane waves). Nothing else was tried.

  • cargo clippy --release -p victory-shader -p victory-gpu: clean.
  • cargo test --release -p victory-shader -p victory-gpu: 110 + 210 passed, 0 failed.
  • victory translate --validate --pipelines with VICTORY_HOST_WAVE=32 over the structure-builder library: 52 emitted, 52 validated, 52 pipelines.
  • In the game with default settings (builder off): ray-traced shadows from the static world, whose acceleration structures ship pre-built, now show up in the first gameplay scene. Checked by eye on one machine, no automated check.

What this does not do

  • The builder is still opt-in and I would not turn it on yet. With VICTORY_BVH_BUILDER=1 (also with VICTORY_BVH_QUARANTINE=1) the builder now does start (all 53 programs have host pipelines), but in my runs the frame time went from about 0.3 s to about 4 s and the scene came out washed out in white. I did not try it without quarantine. Nothing here changes its default.
  • Still not translating on 32-lane hosts: the adaptive shadow-ray program (a lane mask holding lanes elsewhere read as data) and the two irradiance-cache shading programs (wave reductions where not every lane runs).
  • Specular highlights are not yet occluded by structures.

Does it only work on this GPU?

I only know it on the 3090. By construction:

  • The address table is not GPU specific.
  • The lane_uniform proofs only matter where a console wave64 program runs as two host waves of 32 and would need an exchange between them. On a host with 64-lane waves that path is not taken, so it should be inert there.
  • AMD and Intel hosts are untested. Reports from other cards are welcome, in particular from anything with wave32 (RDNA in wave32 mode, Intel).

🤖 Generated with Claude Code

…ate on 32-lane GPUs

Two gaps kept the ray-tracing programs off on a host whose waves are 32 lanes.

1. Buffer views picked from the view heap at a computed index. The shadow-ray
   trace programs read the address of their structure out of a heap descriptor
   they choose with a per-wave index, and walk the memory behind it. The
   translator could only take such an address from a fixed table position.
   The host now keeps, after the strides of `SLOT_STRIDES`, two more dwords
   per heap slot (low and high of the title address of the buffer view
   there), written where the strides are written, and the shader reads them
   by heap slot (`SLOT_ADDRESSES`). No new root parameter; the table grows
   from 8 MB to 24 MB per view heap.

2. `lane_uniform` proves three more things where no lane of a wave can part
   from the others: `tid >> 6` of the entry thread number (in a group whose x
   size is a multiple of 64) is the same in all lanes of a console wave; an
   `ds_read_b32` at such an address is; and a value joined by a phi, also at
   a loop header, is when its arguments are and every predecessor is entered
   by all the arriving lanes or none (a greatest fixed point over the loop's
   carried values and lane masks). The structure builder's block-scan
   programs fetch a wave-uniform running total with `v_readfirstlane` in
   such a loop; without the proof they asked for an exchange between the two
   host waves where not every lane runs.

Effect, with `VICTORY_HOST_WAVE=32` on a 32-lane card:
- 4 of the 5 shadow-ray trace programs (and their screen-space variants) now
  translate and validate; the adaptive one still stops at a lane mask read
  as data.
- 52 of the 52 structure-builder programs now translate, validate and
  create a host pipeline (3 did not).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sedzz sedzz changed the title Ray tracing: shadow-ray traces and the whole structure builder transl… Ray tracing: shadow-ray traces and the full structure builder translate on 32-lane GPUs Nov 24, 2026
@ryotdev

ryotdev commented Nov 24, 2026

Copy link
Copy Markdown

I found a wrong-code case in lane_uniform on ebc2c91. A wave-uniform condition can be false for every lane. If a guarded write to a VGPR is skipped, the register keeps its old value in each lane.

The regression initializes v1 to the thread ID, conditionally overwrites it, restores EXEC, and reads the first lane of v1. When the condition is false, console lane 0 holds 0 and lane 32 holds 32. Marking v1 uniform lets the upper host wave use 32 where the 64-lane read should broadcast 0. The test hits this with a constant move, a thread-ID shift, and a same-address LDS load.

I put a fix and the synthetic test in fb57dd0, directly on your PR head. All three divergent cases failed before the change and pass afterward. The paired cases still take the optimization when the old VGPR is uniform too.

AI-assisted. Tested the shader library on Linux with cargo test --locked --offline -p victory-shader --lib (171 passed, 2 ignored) and ran the repository asset policy. The test covers the compiler proof; the effect on the game’s shaders is unmeasured.

@simplesmenterafael

Copy link
Copy Markdown

Tested ebc2c91 together with ryotdev's fb57dd0 on another 32-lane card, on Windows 10. Counts only, no title data.

Machine: Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 3050 8 GB (driver 32.0.16.2124), AMD Ryzen 5 3600, 16 GB. D3D12 Agility SDK 1.620.2 (Marvisak/VIctory#175/#362, needed on Windows 10 for SM 6.6). rustc 1.98.1.

victory translate --validate --pipelines over the structure builder's DLL, VICTORY_HOST_MAX_WAVE=32:

build emitted validated pipelines not emitted
without this PR 49 of 52 49 49 3: a first-lane read where not every lane runs (at 0x23c, 0x23c, 0x258)
this PR + fb57dd0 52 of 52 52 52 none

The three that failed before are the same three the runtime names on this machine as the stages that keep the builder off (missing=3 of=53).

Without VICTORY_HOST_MAX_WAVE (64-lane translation) both builds give 52 emitted, 52 validated and 43 pipelines (9 refused with E_INVALIDARG on this card), unchanged by the PR.

Tests: cargo test --workspace --locked --no-fail-fast 499 passed, 0 failed, 7 ignored (including a_guarded_uniform_write_can_keep_different_values_in_each_lane); both clippy runs from CI clean; cargo xtask policy ok.

Not done yet: a title run with VICTORY_BVH_BUILDER=1. A 20-minute run (cold shader cache after the rebuild) did not reach the point where the builder is first dispatched, so I have no in-game verdict, frame time or picture to report for it yet. No device removal in that run.

Tested and written with Claude Code (Claude Opus 5.5).

@adamMasMusic

Copy link
Copy Markdown

In-game result with the builder on, RTX 3070 8 GB, Windows 10 22H2 + Agility 1.620, Series X profile. Tree: main at 4e17478 + #81 + #150 + this PR + ryotdev's fb57dd0 (+ #40, #51, #52, #63 and a local save-folder fix). Diagnostics build, VICTORY_BVH_BUILDER=1, no quarantine.

  • The runtime logs the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53.
  • The first world frame took 1.8 s (713 draws). About 25 s later the title crashed: first-chance access violations in title code reading 0xffffffffffffffff (outside the address space), then reads of 0x8 / 0x28. That looks like the garbage-bounds case the fork's ray-tracing notes describe. No device removal.
  • Only five dispatches per frame were dropped at that point: f133e35efed2a48a, plus the four refused 02384a60fda6f2d0, 2cc4c197ee29e291, 2da4beb386509b77 and 369cbe906ea72764.

With the builder off (default), the same tree runs fine, at ~1.8 fps in a diagnostics build. Faces in cutscene close-ups come out black with only the eye rims lit, in every run. They also go black in a dark shot without this PR, so I read it as the missing ray-traced bounce light rather than a bug here.

@YeokiNoewChi

Copy link
Copy Markdown

RTX 3070 Ti, fork main 4e17478 + #23 #24 #25 #51 #52 #32 #58 #71 + #92 #115 + this PR, VICTORY_HOST_WAVE=32 VICTORY_BVH_BUILDER=1, loop limit 256.

  • The log reports "the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53", so the missing-3 case is fixed on this card.
  • About 6 s later, still behind the loading card, the title dies with 0xc0000005 at +0x44bac6c reading 0xbe0b35d3 (a pointer read from title memory, r14 = 0xbe0b35cb).
  • The same run with VICTORY_BVH_QUARANTINE=1 added gets past that point (no access violation in the next ~2 minutes), so one of the builder's stages appears to store into title memory it should not.
  • With quarantine the run then ends on the title's own breakpoint, 0x80000003 at +0x4da6315, as the quarantine switch's comment predicts (the title reads back sizes/counters the quarantined stages never deliver).

AI-assisted (Claude Code).

Keep both export lists in emit/mod.rs: main's view_heap_limit and this branch's SLOT_ADDRESSES and SLOT_STRIDES_DWORDS.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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