Repository navigation
Shaders, GPU: emulate the BVH intersection instructions, and reach title memory at computed addresses - #1198
powplusplus wants to merge 10 commits into
Conversation
…tersection - An access whose address traces to no root parameter but which the program computes (a pointer it loads, picks or builds) now goes through an address map instead of failing: the host copies of title memory sorted by address, searched in the shader, then read or written through a raw view in the heap. Loads, stores and 32-bit atomics, scalar and vector. An address in an SGPR the hardware fills (the spill table) is still refused. - image_bvh_intersect_ray and image_bvh64_intersect_ray are emulated: the node is read through the map and tested as Microsoft's software model of the instruction does (SoftwareBvhIntersectRay in the XDXR traversal headers): box16 and box32 nodes with sorting, the four triangles of a leaf with the watertight edge rules, both triangle return modes. - A descriptor the program reads as numbers (a buffer's address, an acceleration structure's location) reads the console words of the view heap's slot from a copy the host keeps, 32 bytes a slot. HostShader gets address_map and descriptor_words; the shader cache format moves to VSH2.
- The address map lists the host copies of title memory made so far, each through raw views in dynamic slots of the list's view heap, cut where copies overlap (the innermost wins, as shadow::find picks) and at 512 MiB. It is made once per list and view heap; the copies it lists are brought up to date when the list is submitted. - Each view heap keeps the console words of its slots: buffer views, constant buffers and acceleration structures as buffer descriptors at their title address, written whenever a slot is made. - Pipelines get the two root SRVs their shaders ask for; a draw or dispatch that cannot have them is dropped. What shaders write through the map stays in the host copies.
|
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). 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. |
|
@powplusplus, an independent check of Tests. Windows 11, RTX 5070 as the default adapter, plus WARP, using
That includes Offline count. This used local title data:
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:
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. |
|
Independent verification at
Aggregate counts only; no game data posted. AI-assisted; all builds and GPU tests executed on my machine. |
|
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at fe078c6: Tested with AI assistance (Claude). |
|
On exact fe078c6 I 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. |
The ray-tracing passes keep the lanes still walking the BVH in a lane mask around their loop, push masks on an LDS stack as numbers, and pop them back. Each of these stopped the program. - A lane testing its own bit of a mask (v_and_b32 with 1 << lane from v_mbcnt_lo) takes the mask's per-lane value, with no ballot, so the mask may hold lanes that do not run there. - A mask joined at a block is active (a ballot there gives it) when each incoming mask is active, written in the block it comes from, and all lanes there leave by that edge together: a jump, or a branch on a uniform condition. Wave32 only. - In compute, a number joined with a lane mask takes the mask's ballot, and a lane-mask join of a number takes each lane's bit of it. A GPU test runs such a loop: lanes count the passes they stay in a mask that loses its lowest lane each pass.
…programs - The map search is a fixed 16-step binary search without a loop, and loads, stores and atomics need no branch: a miss, or a lane that does not run the access, goes to an offset past every view, where reads give zero and writes nothing. With a loop and a branch per access the ray-tracing shadow passes had too much control flow for vkd3d-proton's DXIL conversion, which did not finish in 25 minutes; now it takes about 20 seconds. - The map always has an entry; without copies, an empty range over a null view. - Threads that make host pipelines (the pipeline workers, the translate command's workers) get a 256 MiB stack, reserved only. vkd3d-proton converts DXIL on the calling thread, recursively, and overflowed 2 MiB on these programs; under Wine the overflow hung the thread.
|
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? |
vkd3d-proton's DXIL conversion keeps one back edge per loop header, as DXC's code has. With several, the others stay in the header's forward predecessors and form a cycle, and in programs with wave shuffles its dominator search then recursed without end: the thread overflowed its stack and, under Wine, hung. 11 of the ray-tracing programs this branch translates did. The back edges of a header with several now go through one new block that joins their phi values.
|
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
+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:
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 No game data; counts and program names only. |
|
One in-title data point for this branch, and why it still cannot be judged in the game from here. Build: 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 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 ( For reference, a public fork that carries the same ray-intersection work ( No game data; counts only. |
A descriptor that an s_buffer_load uses (a constant or structured buffer) and that the program also reads as numbers (its record count, for bounds) stopped the program, as did a constant buffer's. Both now read the console words the host keeps for the view heap, whose buffer descriptors carry the address and record count. 221 more programs in shaders.rpf emit (89 mesh, 103 pixel, 12 vertex, 17 compute), none fewer.
A descriptor read as data was refused as a sampler's when any sampler shared its root slot, static samplers included, so view tables in a slot with a static sampler could not be read as data. Only samplers from a table count now. 196 more programs in shaders.rpf emit (174 mesh, 21 vertex, 1 compute), none fewer.
A join of an SGPR that holds a lane mask on one path and a number on another was refused outside compute when the program read it. In the skinned mesh and pedestrian programs it is a register the compiler reuses on a path that does not read it. Outside compute the mask's dword is now the host wave's ballot, as compute already takes the console's. 253 more programs in shaders.rpf emit (125 mesh, 117 pixel, 11 vertex), none fewer.
|
RX 6750 XT (RDNA2, gfx1031, AMD driver 32.0.21045.29003), Windows 11, Rust 1.98.1 MSVC. At ad558cd and again at bc6479d (both on main ffe310e), The program is wave32 ( Unit tests only, no game files. AI-assisted (Claude; I ran it on my machine). |
…eusing side The join that took the host ballot of a lane mask in graphics now takes zero there, which also covers masks that hold lanes elsewhere. The same goes for a sampler's words joined with other values: in the pixel programs the other side unpacks constant buffer bytes into the same SGPRs. A program reading the mask or the sampler's words directly still stops. 237 more programs in shaders.rpf emit (214 pixel, 15 mesh, 5 compute, 3 vertex), none fewer.
The console compiler spills SGPRs, saved EXEC masks among them, to lanes of a VGPR with v_writelane_b32 and reads them back with v_readlane_b32. Resource tracking already followed such spills; the lane-mask passes and the lowering did not, so a spilled mask was read as a number and the program stopped. The IR now gives a v_readlane_b32 at a constant lane the value v_writelane_b32 stored in that lane on every path, and drops the spill writes and joins nothing else reads. 667 more programs in shaders.rpf emit (473 compute, 138 pixel, 56 mesh), none fewer: the ray tracing resolve passes, tiled shadow cascades, irradiance cache and primary shading, sky and cloud lighting caches.
|
Automated triage for the maintainers. Closing because this change is already in comments still cite the SDK's XDXR traversal headers by name ( 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. |
Update: 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 Ray tracing: what Leonida measured about XboxBvhBuilder and the console BVH format #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.By 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.