Proposal: run the title's ray/node test on the hardware instruction instead of emulating it (AMD) #110

Open
opened 2026-11-26 05:24:46 +00:00 by github-bot · 1 comment
Owner

@⁠Fran-co-F on GitHub · 2026-11-26 03:45 UTC · original

The title traverses its own acceleration structures in compute shaders and uses the console GPU's per-node test, image_bvh_intersect_ray / image_bvh64_intersect_ray. Here that instruction is emulated in DXIL (crates/victory-shader/src/emit/intersect.rs): four slab tests plus a sorting network per box node, and a watertight test per triangle node. AMD GPUs from RDNA2 to RDNA4 still have the instruction, and the AMD driver already exposes it to D3D12 shaders. So the emulation could be swapped for the real thing at one point in the translator, leaving the title's builder and traversal loops as they are.

Evidence

  • Windows, AMD driver: the AMD D3D12 driver extension has AmdExtD3DShaderIntrinsics_IntersectBvhNode (opcode 0x22), documented as "Intersects a ray with a HW-format BVH node", available in all stages, returning uint4. It takes a 64-bit node pointer, ray extent, origin, direction, inverse direction, flags (BoxSortEnable, ReturnBarycentrics) and boxExpansionUlp. It ships in the FidelityFX SDK's AmdExtD3DShaderIntrinsics.hlsl, called through the magic-UAV InterlockedCompareExchange pattern, and gated by CheckSupport(AmdExtD3DShaderIntrinsicsSupport_IntersectBvhNode).
  • RDNA4 keeps the RDNA2-format instruction: llvm-mc -mcpu=gfx1201 assembles both image_bvh_intersect_ray and image_bvh64_intersect_ray. On an RX 9070 XT, RADV with RADV_DEBUG=bvh4 traverses with image_bvh64_intersect_ray over the older node format (confirmed in the ACO disassembly) and matched a CPU reference exactly: 0 hit/miss and 0 primitive mismatches over 65,536 rays.
  • Speed: same GPU, same BVH in VRAM, 1M rays through a full ray-query traversal. The hardware test is 2.0–2.7× faster than RADV's own ALU emulation (RADV_EXPERIMENTAL=emulate_rt): 1.57–2.71 ms against 3.64–7.30 ms. The emulation here also reads nodes through the guest-page directory, so the gap may be larger.
  • Linux: dxil-spirv (vkd3d-proton) already parses the AGS magic UAV and declares opcode 0x22 in dxil_ags.hpp, but does not implement it. With a small RADV extension that lowers a new SPIR-V op to nir_intrinsic_bvh64_intersect_ray_amd, the same DXIL would run on Linux too. Nobody exposes that op today, so it is more work than the Windows path.

What it needs

  1. Emit the AGS intrinsic from intersect.rs when the device reports support, and keep the emulation as the fallback (NVIDIA, Intel, unsupported drivers).
  2. Node pointers are title addresses. Each call needs the host GPU address of the node, through the same directory lookup the emulation already does. A 128-byte box node must not straddle two host copies.
  3. The returned child pointers stay title pointers. The title's loop follows them, not the hardware, so no translation is needed there.

Open questions: the 16-bit box node format and the exact rounding and tie order against the console (bvh.rs and the GPU tests that compare with it would settle that), and how the driver's built-in descriptor handles flags the title sets in its T#.

How much ray tracing costs here (measured). This fork on Linux (RX 9070 XT, RADV), play.ps1 settings, same street scene (~5,200 draws/frame), VICTORY_GPU_TIMING=1, which times each list on its own and so inflates absolute numbers:

card time per frame
without -RayTracing ~62 ms
with -RayTracing ~164–205 ms

So with ray tracing on, its passes take about 100–140 ms of card time per frame, more than everything else together. (Without the timing switch the frame is ~50 ms and CPU-bound; the frame recorder's replay puts the drawing queue at ~22 ms of card time.)

How much the instruction buys depends on the split I couldn't get: how much of those 100–140 ms is traversal (the ~64 programs that use the instruction) and how much is the builder, resolve and denoise passes, which don't speed up. If traversal is half, a 2–3× faster node test saves roughly 35–45 ms of card time per frame. The pipelines in the timing log and the replay aren't named, and the replay leaves out the async compute queue, where this work probably runs, so a per-pass split needs a tool that sees all queues (RGP on Windows, or a replay that records the other queues).

Related, for the memory side: #95.

**@⁠Fran-co-F** on GitHub · 2026-11-26 03:45 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/110) The title traverses its own acceleration structures in compute shaders and uses the console GPU's per-node test, `image_bvh_intersect_ray` / `image_bvh64_intersect_ray`. Here that instruction is emulated in DXIL (`crates/victory-shader/src/emit/intersect.rs`): four slab tests plus a sorting network per box node, and a watertight test per triangle node. AMD GPUs from RDNA2 to RDNA4 still have the instruction, and the AMD driver already exposes it to D3D12 shaders. So the emulation could be swapped for the real thing at one point in the translator, leaving the title's builder and traversal loops as they are. **Evidence** - **Windows, AMD driver:** the AMD D3D12 driver extension has `AmdExtD3DShaderIntrinsics_IntersectBvhNode` (opcode `0x22`), documented as "Intersects a ray with a HW-format BVH node", available in all stages, returning `uint4`. It takes a 64-bit node pointer, ray extent, origin, direction, inverse direction, flags (`BoxSortEnable`, `ReturnBarycentrics`) and `boxExpansionUlp`. It ships in the FidelityFX SDK's `AmdExtD3DShaderIntrinsics.hlsl`, called through the magic-UAV `InterlockedCompareExchange` pattern, and gated by `CheckSupport(AmdExtD3DShaderIntrinsicsSupport_IntersectBvhNode)`. - **RDNA4 keeps the RDNA2-format instruction:** `llvm-mc -mcpu=gfx1201` assembles both `image_bvh_intersect_ray` and `image_bvh64_intersect_ray`. On an RX 9070 XT, RADV with `RADV_DEBUG=bvh4` traverses with `image_bvh64_intersect_ray` over the older node format (confirmed in the ACO disassembly) and matched a CPU reference exactly: 0 hit/miss and 0 primitive mismatches over 65,536 rays. - **Speed:** same GPU, same BVH in VRAM, 1M rays through a full ray-query traversal. The hardware test is **2.0–2.7× faster** than RADV's own ALU emulation (`RADV_EXPERIMENTAL=emulate_rt`): 1.57–2.71 ms against 3.64–7.30 ms. The emulation here also reads nodes through the guest-page directory, so the gap may be larger. - **Linux:** dxil-spirv (vkd3d-proton) already parses the AGS magic UAV and declares opcode `0x22` in `dxil_ags.hpp`, but does not implement it. With a small RADV extension that lowers a new SPIR-V op to `nir_intrinsic_bvh64_intersect_ray_amd`, the same DXIL would run on Linux too. Nobody exposes that op today, so it is more work than the Windows path. **What it needs** 1. Emit the AGS intrinsic from `intersect.rs` when the device reports support, and keep the emulation as the fallback (NVIDIA, Intel, unsupported drivers). 2. Node pointers are title addresses. Each call needs the host GPU address of the node, through the same directory lookup the emulation already does. A 128-byte box node must not straddle two host copies. 3. The returned child pointers stay title pointers. The title's loop follows them, not the hardware, so no translation is needed there. **Open questions:** the 16-bit box node format and the exact rounding and tie order against the console (`bvh.rs` and the GPU tests that compare with it would settle that), and how the driver's built-in descriptor handles flags the title sets in its T#. **How much ray tracing costs here (measured).** This fork on Linux (RX 9070 XT, RADV), `play.ps1` settings, same street scene (~5,200 draws/frame), `VICTORY_GPU_TIMING=1`, which times each list on its own and so inflates absolute numbers: | | card time per frame | |---|---| | without `-RayTracing` | ~62 ms | | with `-RayTracing` | ~164–205 ms | So with ray tracing on, its passes take about **100–140 ms of card time per frame, more than everything else together**. (Without the timing switch the frame is ~50 ms and CPU-bound; the frame recorder's replay puts the drawing queue at ~22 ms of card time.) **How much the instruction buys depends on the split I couldn't get:** how much of those 100–140 ms is traversal (the ~64 programs that use the instruction) and how much is the builder, resolve and denoise passes, which don't speed up. If traversal is half, a 2–3× faster node test saves roughly 35–45 ms of card time per frame. The pipelines in the timing log and the replay aren't named, and the replay leaves out the async compute queue, where this work probably runs, so a per-pass split needs a tool that sees all queues (RGP on Windows, or a replay that records the other queues). Related, for the memory side: #95.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:46 +00:00
Author
Owner

@⁠Jrjy3 on GitHub · 2026-11-27 02:14 UTC · original

A data point on where the ray-tracing time goes on RDNA 4 (Radeon AI PRO R9700, Windows 11, Ryzen 9 9950X3D). Build: main 014d52d + #55. Scene: idle at the boat, 2560x1440 output.

Frame time: 73.5 ms with RT off and 108.3 ms with VICTORY_BVH_BUILDER=1, about 35 ms more.

RT off RT on
GPU ~55 ms ~86 ms
Preparing ~14 ms ~21 ms
Copying back ~10 ms ~17 ms

Per-dispatch GPU time with RT on: diagnostics build, VICTORY_RT_STAMPS=1, 145.7 ms frame with the stamps on.

GPU time Dispatches
Structure builder ~1 ms ~105
Programs that walk the structures ~27 ms 16
Other compute ~39.5 ms ~2,345

Of the walking programs, 6d7fe7745ab9c6d8 takes 10 ms in 3 dispatches. The others (b58eb3ca6ee46427, 3592426e3e9142d8, f22a76fcb967ee59, f607780aa8e502d0, 36f04a4ed0ad1d9b) take 2.5-4.4 ms each.

So on this card the builder is nearly free. The cost is the walking itself, which reads title memory by address. Moving that work onto the hardware node test, or onto port RT's views, would help most.

🤖 Generated with Claude Code

**@⁠Jrjy3** on GitHub · 2026-11-27 02:14 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/110#issuecomment-7207946675) A data point on where the ray-tracing time goes on RDNA 4 (Radeon AI PRO R9700, Windows 11, Ryzen 9 9950X3D). Build: main 014d52d + #55. Scene: idle at the boat, 2560x1440 output. **Frame time:** 73.5 ms with RT off and 108.3 ms with `VICTORY_BVH_BUILDER=1`, about 35 ms more. | | RT off | RT on | |---|---|---| | GPU | ~55 ms | ~86 ms | | Preparing | ~14 ms | ~21 ms | | Copying back | ~10 ms | ~17 ms | **Per-dispatch GPU time with RT on:** diagnostics build, `VICTORY_RT_STAMPS=1`, 145.7 ms frame with the stamps on. | | GPU time | Dispatches | |---|---|---| | Structure builder | ~1 ms | ~105 | | Programs that walk the structures | ~27 ms | 16 | | Other compute | ~39.5 ms | ~2,345 | Of the walking programs, `6d7fe7745ab9c6d8` takes 10 ms in 3 dispatches. The others (`b58eb3ca6ee46427`, `3592426e3e9142d8`, `f22a76fcb967ee59`, `f607780aa8e502d0`, `36f04a4ed0ad1d9b`) take 2.5-4.4 ms each. So on this card the builder is nearly free. The cost is the walking itself, which reads title memory by address. Moving that work onto the hardware node test, or onto port RT's views, would help most. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/avatarmanz--VIctory-7900XTX#110
No description provided.