Shaders, GPU: emulate the BVH intersection instructions, and reach title memory at computed addresses #1198
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1198
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1198/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@powplusplus on GitHub · 2026-11-24 16:24 UTC · original
powplusplus:shader/ray-tracing→main· +3025 −34 · 24 files · 10 commits · closed without mergingUpdate: main at
70564aenow has its own BVH intersection, title memory through a page table and lane masks spilled in compute, and this branch conflicts with it. On top of main, what is left of this is in #1883 (the lane masks the traversal keeps as numbers, which every RT shadow pass on main still stops at) and #1885 (the two vkd3d-proton hangs those passes then hit). The rest of this description is about the branch againstffe310e.The title's ray-tracing passes (RT shadows, GI probes, reflections, particle collision) walk the BVH themselves: they follow pointers through title memory, test each node with
image_bvh_intersect_ray, and keep the lanes still walking in a lane mask around their loop. None of that translated. Their addresses trace to no root parameter, the TLAS address comes out of a descriptor read as data, no host shader model has the instruction (see #274), and the loop's masks stopped the program.What this adds
image_bvh_intersect_rayandimage_bvh64_intersect_rayread the node through the map and test it as Microsoft's software model of the instruction does (SoftwareBvhIntersectRay,TestXboxBvh4Node,TestXboxBvh4Leafin the XDXR traversal headers; node layouts as in #274): box16 and box32 nodes with sorting, the four triangles of a leaf with the watertight edge rules, both triangle return modes.v_and_b32with1 << lane) takes the mask's per-lane value without a ballot. A mask joined at a block is active when each incoming mask is active, written in the block it comes from, and every lane there leaves by that edge together. In compute, a number joined with a lane mask takes its ballot, and a lane-mask join of a number takes each lane's bit (the traversal pushes masks on an LDS stack as numbers).HostShadergetsaddress_mapanddescriptor_words; the shader cache format moves toVSH2.Results
translate --validateover shaders.rpf againstffe310e: 659 more programs emit, none lost.ffe310eBy what they failed on before: 374 "a descriptor read only as data", 218 "a scalar memory read as data", 34 "a descriptor's address or format read as data", 33 "an address not from a root parameter". Most new graphics programs are pedestrians' and skinned meshes'. VS + PS and MS validation is low on
ffe310ebecause of the PSV0 mismatch that #1208 fixes; with it, all 659 validate.On an RTX 3080 (vkd3d-proton) 652 of the 659 create pipelines, each run on its own with a 120 s limit; the largest,
CS_RTShadowTrace32HQ(about 1 MB of DXIL), takes about 20 s. The other 7 require wave size 64, which the card does not support.30 of the 64 programs that use the BVH instructions now translate and validate, among them every RT shadow trace pass:
CS_RTShadowTrace32HQ,CS_RTShadowTrace32HQFarOnly,CS_RTShadowTrace32TemporalHQ(and its FarOnly, OneOver4RPP and OneOver8RPP variants),CS_RTDistantShadowTrace32_Tiled(4 variants),CS_RTDistantLODLightShadow,CS_TraceShadowRays_*(4),CS_RaytraceShadows_Mixedand_Shared,CS_LaserLightShadowRaytracing,CS_IrradianceCache_ShadowTrace(2),CS_DeferredGather_*(4),CS_GatherAlphaVBuffer(2),CS_PPR_Raytrace,CS_CollisionRaytraced,CS_ComputeClosestDepth. 25 of the 30 create pipelines on the RTX 3080; the other 5 need wave size 64. Most of the 34 left are the ray-binning passes, which stop at "a whole-wave section step the simulation does not follow" (14).The builder's own programs (
XboxBvhBuilder.dll) still stop at the spill table. With #302 merged locally, 1 of 38 emits and the next blocker is root UAVs (27), which the map could also serve.Testing
image_bvh_intersect_rayon hand-built box32, box16 and leaf nodes, and stores the results through the map; compared with a Rust transcription of Microsoft's model (both descriptor modes, sorted and unsorted, a shared edge, parallel and backward rays, back faces, random boxes);cargo test -p victory-shader -p victory-gpuunder Proton, apart from the known Proton-only failures (stub_pipeline_is_created,a_rejected_blob_gives_an_empty_library).Known limits
0x890003ff, as @r4tedx found), so the mode 0 path (the leaf's id dword and a hit flag) is not reached; an earlier version of this description said mode 0, which was wrong.@LooperSalty on GitHub · 2026-11-24 16:37 UTC · original
From a tester working with Claude (AI-assisted); measured on my own machine (i7-13700KF, RTX 4070 Super). No game data involved.
A cheaper, diagnostic-only complement we use while real BVH emulation is not there (this PR is the real thing; ours does not replace it).
VICTORY_RT_MISS=1(opt-in, off by default, part of the shader cache key): in a program that containsimage_bvh_intersect_ray, as_load/global_loadat an address that cannot be traced (the acceleration structure, whose address comes out of a descriptor read as data) reads a null view (0),image_bvh_intersect_rayreturns 0xFFFFFFFF (the ISA's invalid node pointer), and the branches decided by those zeros (the BVH header's node count at +48 = 0 skips the traversal loop) are folded. Without the variable the named refusal is unchanged.Measured on an integration tree, ray-tracing corpus (47 containers): emitted 18 -> 38, emitted and validated with dxil.dll 18 -> 36. Programs that go through: the shadow/reflection/GI trace passes whose hashes are 32ed072b, 0873f80d, e8c96235, afeea48b, a1b20bc4, 17829ac7. Still refused: 8 RaytraceVBuffer* ("whole-wave section step"), TraceShadowRays_Half (lane mask), _FullAdaptive (join of an untracked mask).
It lets the world run past ray-tracing passes (no shadows or bounces from RT) while testing other work. It needs the translate-options plumbing that is not on main yet, so I am not publishing a branch; happy to rebase it onto this PR if you want it.
@r4tedx on GitHub · 2026-11-24 17:09 UTC · original
@powplusplus, an independent check of
fe078c6on native Windows (no Proton), plus one point about the descriptor.Tests. Windows 11, RTX 5070 as the default adapter, plus WARP, using
cargo test --locked -p victory-shader -p victory-gpu -- --test-threads=4:That includes
bvh_intersection_matches_the_model_on_the_gpu, which ran on both the hardware adapter and WARP with neither skipped, and the threeaddress_mapunit tests.stub_pipeline_is_createdpasses here, which fits it being Proton-only for you.Offline count. This used local title data:
victory translate --validate --listovershaders.rpf, SDK 10.0.26100dxil.dll, CPU only, matched program by program againstffe310e.ffe310eis lost.ffe310enone of them emits.Entry function performs some operation that is incompatible with the shader stage. That's the implicit-derivative-in-compute case, which the 1.8 validator rejects and newer ones accept. So compute validates 1,676 of 1,772 here, against your 1,772 / 1,772. It's an environment difference, not a defect in the PR, but it's worth stating whichdxil.dllthe table used. Under this validator the gain is +259 compute and +62 pixel programs validated.Triangle return mode. The description says "The title's BVH descriptor asks for triangle return mode 0". The code decodes bit 120 (dword 3, bit 24) at run time, so the result format follows whatever the descriptor holds. The evidence I have points to mode 1, though:
0x890003ff. Bit 24 is set: type 8, return mode 1, big_page set, size all ones.triangle_return_mode 1at all 716 intersection sites, withbox_grow 0andbox_sort_en 1.If that holds, the unconfirmed mode-0 modelling (id dword plus hit flag) is never reached by the title. How did you arrive at mode 0? A program that builds dword 3 differently would be worth knowing about.
For context: I had a separate lowering of the same two instructions written from AMD's GPURT layouts (IP 1.1). I'm not proposing it. Yours models the Xbox leaf format and handles the computed addresses, which mine didn't, and on this pack mine translated none of the 64.
AI-assisted (Claude Code). Local title data was used for the offline count only (counts and reasons reported, no names or game files). The title was not run.
@MartinIndra02 on GitHub · 2026-11-24 17:25 UTC · original
Independent verification at
fe078c6on Windows 11, NVIDIA GeForce RTX 3080 (driver621.24, 32-32 wave lanes) + WARP, Rust1.98.1:cargo test -p victory-shader --lib -- --test-threads=1: 123 passed, 0 failed, 1 ignored (includingemit::bvh_tests::gpu::bvh_intersection_matches_the_model_on_the_gpuon both RTX 3080 and WARP).cargo test -p victory-gpu --lib -- --test-threads=1: 53 passed, 0 failed, 1 ignored.VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1: 56 passed, 0 failed, 1 ignored (0 debug-layer errors).cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings(default +--features diagnostics): 0 warnings.cargo xtask policy: 159 files ok.victory translateon retail 1.0.2.1, 26,084 programs, release build vsmainffe310e):12,231 → 12,300(+69)1,441 → 1,772(+331)8,214 → 8,214(0regressions)21,886 → 22,286(+400)Aggregate counts only; no game data posted. AI-assisted; all builds and GPU tests executed on my machine.
@Zipettte on GitHub · 2026-11-24 18:00 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
fe078c6:cargo test -p victory-gpu -p victory-shaderpasses, 176 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@aycow on GitHub · 2026-11-24 18:17 UTC · original
On exact
fe078c6I routed the address-map builder to a native shared backing in an isolated fixture. Original translated scalar/vector reads, stores, atomics, remap recordings and unmapped input passed AMD/NVIDIA/WARP with full GBV. The same native map descriptor route can address either backing.A separate bounds control failed identically on all three: a dwordx4 starting in an outer map piece returned [31,37,41,43], even though the last three dwords belong to a higher-priority overlapping piece and should be [47,53,59]. The native raw view is large enough, so this is silent host-view-valid misrouting.
global_readcurrently looks up the first address once. The reproducible negative test is enabled by VICTORY_MAP_TEST_OVERLAP in the fixture. I'd like to coordinate the intended cross-piece read and store semantics here before changing lowering.@aycow on GitHub · 2026-11-24 18:57 UTC · original
I rechecked the bounds regression on exact
ad558cd. The outer view still supplies every component of a cross-piece vector. The expanded reproduction checks overlapping source and destination ranges, a hole, and unaligned/partial atomics. The straight-line candidate resolves each complete dword to the highest-priority piece and passes AMD and WARP with full GBV. NVIDIA RTX 5070 Laptop accepts DXIL validation but rejects native PSO creation with this candidate, both with and without GBV. The exact baseline PSO builds on that device and produces the incorrect overlap readback. An earlier vector/split variant reported 0x8007000E there.The test branch is available to diagnose the lowering size and driver behavior. It stays separate from #1198 and default-off allocation routing. Do you have a preferred way to represent the next mapped dword compactly in the current straight-line lookup?
@rocobalt1 on GitHub · 2026-11-24 19:53 UTC · original
Offline coverage of this branch on the retail shader pack, since the in-tree merge is not cheap to test here.
Method: a clean worktree at
bc6479d(this PR's head, onffe310e),cargo build --release -p victory, thenvictory translate <shaders.rpf> --validate --list --jobs 20on the same package and the same Windows SDK validator. Compared program by program (container offset + name) with the same command onffe310e+ #1271, which validates the same 21 724 programs asmainalone.mainbaseline+334 newly validate, 0 newly failing. The largest single-PR coverage gain I have measured on this pack (the combo of #136 + #307 + #566 was 238 fixed and 276 broken).
What the 334 are, by family:
CS_RaytracingResolve_*- the RTGI probe resolve, many material variants (standard_pv_v2,standard_clearcoat_flakes,standard_2lyr_roadsign,standard_2lyr_anisotropy,standard_doublesided_dirt, ...);CS_LaserLightShadowRaytracing_*(deferred_tiled);PS_PuddleDetect_*,PS_VehicleLiveryOffOnlyDeferred_NoDeform_*and similar pixel programs that read through the same address paths.That is precisely the set #1533 names as the reason the 2560x1440 RGBA16F accumulation stays flat: the direct lighting, RTGI resolve and directional shadow passes.
I could not test it in the title here: merging this branch onto the integration tree at
2b1a569conflicts in 11 files (emit/lower.rs,emit/mod.rs,native.rs,structure.rs,descriptor/host.rs,draw.rs,list.rs, ...), and I will not hand-resolve the translator. If a head exists that carries this on top of the tree, I will run it and report the world numbers.No game data; counts and program names only.
@rocobalt1 on GitHub · 2026-11-24 20:03 UTC · original
One in-title data point for this branch, and why it still cannot be judged in the game from here.
Build:
mainffe310e+ this branch (bc6479d), plusd6897fa(the 1440x target present fallback) adapted by hand tomain's single-texturepresent- one conflict, inqueue.rs, resolved by presenting the candidate instead of the title's first plane's texture. Diag build, freshVICTORY_DATA_DIR,VICTORY_NO_WATCHDOG=1,VICTORY_SHADER_LOOP_LIMIT=32,VICTORY_PRESENT_1440P=1, driven withVICTORY_KEYS.It runs, and the fallback does fire:
but the frame is dominated by the copy path that the tree here does not have:
So on
mainthe gain this branch gives (the +334 programs in my comment above) is invisible: at 0.3 fps with 2.9 s of copying, and with a device removal half a minute in, there is nothing to look at.That is not a criticism of the branch - it is an argument for landing it on the integration tree, where copying is ~66 ms/frame and a world run lasts 15 minutes. Merging it there conflicts in 11 files (
emit/lower.rs,emit/mod.rs,native.rs,structure.rs,descriptor/host.rs,draw.rs,list.rs,emit/host.rs,emit/shader.rs,valu_tests.rs,waterfall_tests.rs), which is more than I am willing to hand-resolve on someone else's translator.For reference, a public fork that carries the same ray-intersection work (
fxceless/victory-gta6,intersect.rs+bvh.rs) renders the prologue with characters, sky and shadows at 1-3 fps on the same card, which is what the tree would look like with this landed.No game data; counts only.
@rocobalt1 on GitHub · 2026-11-24 20:03 UTC · original
One in-title data point for this branch, and why it still cannot be judged in the game from here.
Build:
mainffe310e+ this branch (bc6479d), plusd6897fa(the 1440x target present fallback) adapted by hand tomain's single-texturepresent- one conflict, inqueue.rs, resolved by presenting the candidate instead of the title's first plane's texture. Diag build, freshVICTORY_DATA_DIR,VICTORY_NO_WATCHDOG=1,VICTORY_SHADER_LOOP_LIMIT=32,VICTORY_PRESENT_1440P=1, driven withVICTORY_KEYS.It runs, and the fallback does fire:
but the frame is dominated by the copy path that the tree here does not have:
So on
mainthe gain this branch gives (the +334 programs in my comment above) is invisible: at 0.3 fps with 2.9 s of copying, and with a device removal half a minute in, there is nothing to look at.That is not a criticism of the branch - it is an argument for landing it on the integration tree, where copying is ~66 ms/frame and a world run lasts 15 minutes. Merging it there conflicts in 11 files (
emit/lower.rs,emit/mod.rs,native.rs,structure.rs,descriptor/host.rs,draw.rs,list.rs,emit/host.rs,emit/shader.rs,valu_tests.rs,waterfall_tests.rs), which is more than I am willing to hand-resolve on someone else's translator.For reference, a public fork that carries the same ray-intersection work (
fxceless/victory-gta6,intersect.rs+bvh.rs) renders the prologue with characters, sky and shadows at 1-3 fps on the same card, which is what the tree would look like with this landed.No game data; counts only.
@wwwwwwww3333333 on GitHub · 2026-11-24 21:51 UTC · original
RX 6750 XT (RDNA2, gfx1031, AMD driver 32.0.21045.29003), Windows 11, Rust 1.98.1 MSVC. At
ad558cdand again atbc6479d(both on mainffe310e),emit::bvh_tests::gpu::a_loop_carried_lane_mask_is_tested_per_lanepasses on the hardware adapter. On WARP it panics at bvh_tests.rs:688,warp: The parameter is incorrect(E_INVALIDARG fromcompute_pipeline). The rest of victory-shader passes: 123 passed, 1 failed. victory-gpu passes: 53 passed.The program is wave32 (
vcc_lo,s_ff1_i32_b32), and WARP's lane range is 4..=4. This looks like the same thing #1275 hit and fixed incdbe178: WARP refuses a WaveSize(32) pipeline. Skipping WARP whencompute_pipelinefails there, as that test now does, would leave the hardware check intact.4767603, pushed since, only changes the scalar descriptor loads in lower.rs. It doesn't touch this test or its WARP path, so I expect the same result there, but I haven't run it.Unit tests only, no game files. AI-assisted (Claude; I ran it on my machine).
@Marvisak on GitHub · 2026-11-25 00:34 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.comments still cite the SDK's XDXR traversal headers by name (
SoftwareBvhIntersectRay,TestXboxBvh4Node,XboxBvh4Node16) in lower/bvh.rs, bvh_tests.rs and docs/architecture.md (rule 2), and main has the BVH instruction and title memory at raw addresses (emit/lower/bvh.rs, Lower::memory,27c3dc9d).If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed