Skip to content

XDXR builder follow-up: small-build sort, and MSVC C4456 in vulkan_replay.h (D3D-178) - #1743

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
romainveurrier:rt/xdxr-followup
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
romainveurrier:rt/xdxr-followup

Conversation

@romainveurrier

Copy link
Copy Markdown
Contributor

Item: D3D-178 (#313), a follow-up to #1572 and #1667. The 13:35 merge round took those two at their older heads (51a0281 and 1c58d6c). These are the two commits that came after, rebased onto main 89b047c.

1. MSVC C4456 in vulkan_replay.h (6e8a140)

emit had two const auto* build = std::get_if<BuildAccelerationStructure>(&command) in one else if chain. The second hides the first, and MSVC /W4 warns in every file that includes the header (reported by @zneel on #1667). The XDXR branch's binding is now xdxr_build. No behaviour change.

2. Small builds: one-workgroup sort, 256-element radix tiles (fa2712e)

The radix sort's fixed latency dominated small builds. This is the 10k regression @exhawk measured on #1572 (0.44 → 0.63 ms on an RTX 3090 Ti). On an RTX 2050, 2,000 triangles took 0.81 ms with the sort and 0.08 ms without it.

  • Up to 1,024 keys are sorted in one workgroup's shared memory, in one dispatch: a bitonic sort with ties broken by element index, which gives the stable order. It uses 8 KiB; with the radix arrays the shader stays under the 16 KiB every Vulkan device must allow.
  • Radix tiles are 256 elements instead of 2,048, so each workgroup walks 4 chunks instead of 32.

RTX 2050, best of 3, device-local memory:

Triangles before after
1,000 ~0.8 ms 0.24 ms
2,000 0.83 ms 0.28 ms
10,000 0.81 ms 0.38 ms
100,000 2.51 ms 2.32 ms
1,000,000 20.3 ms 21.9 ms

Large builds lose about 8%, because the digit-count scan grows with the tile count. Small and medium builds are the ones a game rebuilds every frame, so the trade favours them. A 512-element tile gave 0.45 ms at 10k and 21.2 ms at 1M, if a reviewer prefers the other balance. The 5,000-triangle case now spans 20 radix tiles, and the 1,000-triangle cases take the shared-memory path.

Tested (Fedora 44)

  • Native ctest: 28/28 on an RTX 2050 (NVIDIA 620.70.06), an Iris Xe (Mesa 26.2.7 ANV) and llvmpipe. xdxr_build and its check give 0 differing rays.
  • Wine 11.21 with clang-cl 22.1.8 and xwin:
    • xdxr_build, d3d12_xdxr_rt (with their checks) and d3d12_indirect_rt pass on both GPUs.
    • Full suite: the same 5 failures as main (fsr_dispatch and bvh_builder are the clang 22.1.8 crash; device_proxy, d3d12_present and d3d12_indirect_zero fail on main under Wine too).
  • python -I tests/test_xdxr_bvh.py OK, and xdxr_build.inc matches glslc --target-env=vulkan1.2 -O -mfmt=c xdxr_build.comp.
  • Not run: MSVC, an AMD GPU, validation layers.

No game files. AI-assisted (Claude Code).

🤖 Generated with Claude Code

romainveurrier and others added 2 commits November 22, 2026 14:41
…R one

Two `const auto* build` in one else-if chain: the second hides the first
and MSVC /W4 warns (C4456) in every file that includes the header
(reported by @zneel on ItsNotRexed#1667).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The radix sort's fixed latency dominated small builds (2,000 triangles: 0.81
ms with the sort, 0.08 ms without, on an RTX 2050; the 10k regression
@exhawk measured on ItsNotRexed#1572). Up to 1,024 keys are now sorted in one
workgroup's shared memory (bitonic, ties by element index: the stable
order; 8 KiB, within the 16 KiB minimum with the radix arrays), and the
radix tiles are 256 elements (4 chunks instead of 32 per workgroup).

RTX 2050: 1,000 triangles 0.24 ms, 2,000 0.28 ms (0.83), 10,000 0.38 ms
(0.81), 100,000 2.3 ms (2.5); 1M 21.9 ms (20.3, the larger scan).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revu le head fa2712e. Le tri bitonique garde un ordre stable via l’indice en départage et le padding à une puissance de deux est sûr puisque les clés Morton restent sur 30 bits. Le seuil 1 024 et les tailles partagées respectent la limite device indiquée; la régression mesurée sur gros builds est documentée, et les runs RTX/Iris/llvmpipe rapportent zéro rayon divergent. Checks CI en attente.

@Vonsek

Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested fa2712e on AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, driver 26.10.1, subgroup 32..64) and NVIDIA RTX 5080 (616.92), Windows 11 with MSVC (RelWithDebInfo, glslang from a local install): pass on both.

  • Built vk_xdxr_build_test (-j 4) from the PR head.
  • LEONIDA_VK_DEVICE=radeon|5080 vk_xdxr_build_test <out>: "built every case" on both (including blas_three_sort_tiles, 5000 triangles / 1670 nodes, and blas_empty).
  • python -I tools/xdxr_bvh.py check-build <out> --rays 1000: all cases match on both devices, 0 validation errors, 0/1000 rays differ (e.g. blas_transform 452 hits, tlas 565 hits).
  • python -I tests/test_xdxr_bvh.py: 27 tests OK.
  • Not run: the full ctest, validation layers, red-on-main, and the xdxr_build.inc regeneration check (no glslc here).

AI-assisted.

@exhawk

exhawk commented Nov 22, 2026

Copy link
Copy Markdown

Tested fa2712e2b00f639906d4de63aa5ec326a1fa2b37 against its parent 6e8a1400 on an RTX 3090 Ti, NVIDIA 617.42, Windows 11 25H2, MSVC 19.44.35228.0 x64 (RelWithDebInfo).

Median BLAS build time fell by 56.7% at 10,000 triangles and rose by 12.2% at 2,000,000.

Triangles Parent (ms) PR (ms) Change in time Pairs
1,024 0.390 0.200 −48.7% 6
1,025 0.400 0.230 −42.5% 6
2,000 0.600 0.235 −60.8% 6
10,000 0.635 0.275 −56.7% 6
100,000 1.050 0.810 −22.9% 6
500,000 3.140 3.250 +3.5% 6
1,000,000 5.880 6.310 +7.3% 24
2,000,000 11.505 12.910 +12.2% 24

Each pair ran the stock harness once per commit, with each commit going first equally often. Each invocation warmed up once and reported its best of three wall-clock builds, including submission and wait. Validation was off for timings.

  • Stock tests. xdxr_build and xdxr_build_check passed all 10 scenes. All 9,200 rays matched brute force.
  • Equal Morton keys. Across the sort cutoff, every primitive ID read back from the GPU matched the stable reference order (1,024/1,024 and 1,025/1,025). All 1,000 rays per scene matched brute force. The stock and cutoff tests ran with Khronos synchronization validation enabled and logged zero validation errors.
  • MSVC. A clean /W4 build of d3d12_xdxr_rt_test and d3d12_indirect_rt_test emitted zero C4456 warnings.

Synthetic inputs only. AI-assisted (Codex).

@crastinator

Copy link
Copy Markdown
Contributor

Tested fa2712e merged into main 003e7812 (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 161/170 native, 161/170 with LEONIDA_W64_EMULATE=1. The only skips are the eight *_m* D3D12 fixtures and ps_w64x_readlane (RADV can't require a 64-wide fragment subgroup), the same as on main.
  • xdxr_build and xdxr_build_check pass in ctest (33/33).

No game files. AI-assisted (Claude Code).

@HQasper

HQasper commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested fa2712e on NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 Pro build 10.0.26300.9974 (26H2), MSVC 14.51.36231 with Visual Studio 18 BuildTools, RelWithDebInfo, Vulkan SDK 1.4.363.0: pass, and this is the first runtime build I have seen with no C4456 anywhere.

What I ran, from the PR head fa2712e2b00f639906d4de63aa5ec326a1fa2b37 in its own worktree (no game files, no game copy):

  • cmake -S runtime -B out/build -G "Visual Studio 18 2026" -A x64, full build: exit 0, 0 warnings in the whole tree (warning C count 0).
  • Red control for the warning: the same target (gta6rt_d3d12_com --clean-first) with runtime/src/vulkan_replay.h taken from the base 89b047cd reports 4 × vulkan_replay.h(2960,32): warning C4456: declaration of 'build' hides previous local declaration; with this PR's header it reports none. That is the warning every runtime build here has been carrying, gone.
  • ctest -C RelWithDebInfo: 98 tests, 97 pass. d3d12_draw fails with bundle blend pixel (0, 0): got 255,0,0,255, expected red 64 — not this PR: a d3d12_draw_test built from the base 89b047cd (separate worktree and build) fails with the identical line and the runtime's fence signal 4 is not above 20; Vulkan timelines cannot go back, which is exactly what Tests: wait for the bundle blend draws in d3d12_draw (fence 21, not 4) #1793 fixes.
  • xdxr_build and xdxr_build_check pass here (0.34 s and 16.83 s) with the committed xdxr_build.inc, including blas_three_sort_tiles (5,000 triangles, many radix tiles) and blas_empty.

The include check @Vonsek could not run (glslc is installed on this machine):

  • glslc --target-env=vulkan1.2 -O -mfmt=c xdxr_build.comp on the new .comp gives 14,567 words; the committed xdxr_build.inc has 14,568; the base .comp gives 13,762. So the include is a fresh build of the new shader, not a stale one.
  • spirv-val passes on both the committed module and the fresh build. spirv-diff finds exactly one optimizer difference (the committed module does OpSelect(cond, a, b) | c, the fresh one OpSelect(cond, c, 0x80000006) — one fewer OpConstant, one more OpBitwiseOr) plus a 2-id bound shift. Recording the glslc version next to the flags in runtime/src/xdxr_build_spv.h:6 would make it bit-reproducible; today only the flags are written down.

Read of the shader change: padding to the next power of two writes INVALID into both key and value, so padding sorts last; ties break on the element index, which is the same stable order the radix path produced; every loop bound is uniform across the workgroup, so all 64 invocations reach each barrier(); p ≤ SMALL_SORT_MAX whenever n ≤ 1024, so the two 1,024-word arrays are enough; dispatch(cb, s, 64) is one workgroup. RADIX_TILE 2048 → 256 only changes how many workgroups cover the keys per dispatch, and XdxrLayout::radix_tile moves with the shader constant. docs/bvh.md's step 2 matches what the code does.

AI-assisted review.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested fa2712e on Windows 11 (26200), MSVC 19.4x (VS 2022 Build Tools), Ninja RelWithDebInfo: pass on both GPUs of a two-GPU PC.

  • NVIDIA GeForce RTX 5080, driver 616.92 (LEONIDA_VK_DEVICE=nvidia): ctest 94/94 passed, including vk_xdxr_build.
  • AMD Radeon RDNA2 iGPU, driver 32.0.21045.16010 (LEONIDA_VK_DEVICE=radeon, LEONIDA_HOST_ADAPTER=radeon): ctest 94/94 passed.
  • The build has no C4456 left from vulkan_replay.h. On main 89b047c, vulkan_replay.h(2960) still warns in every translation unit that includes it.

No game files. AI-assisted check (Claude Code), Vonsek3.

@ItsNotRexed
ItsNotRexed merged commit 445e79b into ItsNotRexed:main Nov 22, 2026
6 of 9 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…ulkan_replay.h)

The test's global `constexpr UINT extent = 64` is hidden by a local `extent` in runtime/src/vulkan_replay.h,
so every MSVC build of the runtime prints `warning C4459: declaration of 'extent' hides global declaration`.
It came in with #907, whose earlier fix renamed the global `size` to `extent` for the same reason. The
global is now `target_extent`, a name nothing under runtime/ uses; the test is otherwise unchanged.

Tested on Windows 11 Pro 25H2, MSVC 14.51 + Ninja (scripts/build_runtime.ps1), RTX 5070 Ti / 621.24: the
build has no C4459 (main's 49x C4456 in vulkan_replay.h remain; #1743 handles them). d3d12_translated_draw_test
passes with validation off and on: three draws, 4064/4096 exact, 32 edge pixels, 0 VUIDs. Full ctest with
validation: 106/107; the one failure is d3d12_draw's bundle-blend check, which fails on main too (#1793).
No game files. AI-assisted.

Co-Authored-By: Claude Opus 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.

7 participants