Skip to content

XDXR builds: ARRAY_OF_POINTERS instances and the 16-bit vertex formats - #3944

Open
shelbykb2 wants to merge 2 commits into
ItsNotRexed:mainfrom
shelbykb2:fix/xdxr-as-inputs
Open

shelbykb2 wants to merge 2 commits into
ItsNotRexed:mainfrom
shelbykb2:fix/xdxr-as-inputs

Conversation

@shelbykb2

Copy link
Copy Markdown
Contributor

New D3D item, claimed in #313. AI-assisted (Claude Code).

What and why

Two inputs BuildRaytracingAccelerationStructure accepted and then got wrong on the XDXR path:

  1. Top-level builds ignored DescsLayout. With D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS, InstanceDescs is the address of an array of GPU addresses, one per 64-byte instance desc. The shim recorded it as the descs themselves, so the builder read pointers as instances.
  2. Four of the six vertex formats were mapped and then refused. The shim mapped R16G16B16A16_FLOAT, R16G16_FLOAT, R16G16B16A16_SNORM and R16G16_SNORM, but the builder accepted only the two R32 formats, so prebuild info returned sizes for a build that replay refused.

Changes

  • Array of pointers. The builder shader adds one bias to every address and cannot refuse a list, so the pointers are resolved while the list is prepared (xdxr_gather, runtime/src/vulkan_backend.h): the pointer array is read through its buffer's host mapping (new ResourceBinding::host), each pointer must name 64 bytes inside one known buffer, and a null pointer, one into no resource, or one whose desc runs past its buffer refuses the list (unresolved_resource) before the GPU reads anything. The descs are then copied on the GPU into the build's scratch (XdxrLayout::gather_off) and built as an ARRAY; the ARRAY path is unchanged.
  • Scratch size. A top-level build's scratch grows by 64 * N for both layouts, so GetRaytracingAccelerationStructurePrebuildInfo, which sees only the count, gives one answer. Result sizes do not change.
  • Vertex formats. xdxr_build.comp decodes the four 16-bit formats (pc.arg1 2–5; the 0/1 branch is textually unchanged). Halves are converted from their bits, exact including denormals. SNORM16 is max(c / 32767, -1) by integer long division, since a SPIR-V float division need not be correctly rounded. Two-component formats read z = 0; A is never read. A 16-bit format with an odd address or stride, or a stride below its element size, is refused.
  • xdxr_build.inc regenerated with the command in its header (glslc from shaderc v2026.4, which first reproduced main's .inc byte for byte from main's .comp). The shader follows the header's MoltenVK rule: the new decode only loads from the vertex buffer and stores to the destination.
  • tools/xdxr_bvh.py: the reference decodes the same formats; check-build compares every leaf's vertex bits against the case's source vertex buffer.
  • docs/d3d12_vulkan.md §4.8, docs/bvh.md §7a.

Tested

AMD Radeon RX 6800 (gfx1030), AMD driver 26.11.2, Windows 11, MSVC, on main aa2988c. New checks are in d3d12_xdxr_rt_test and tests/test_xdxr_bvh.py:

Check On main Now
Pointer-layout TLAS equals the ARRAY build byte for byte (descs out of order, one in a default-heap buffer filled earlier in the same list) fails passes
Null / past-the-end / no-resource pointer refuses the list and nothing runs 6 fail pass
A flat grid in all 6 formats and a cube in the 3 formats with z equal their R32G32B32_FLOAT builds 6 fail (refused) pass
Random halves (with denormals) and random SNORM16 values equal their R32 builds — (written after the fix) pass
Prebuild sizes equal across layouts and formats passes passes
PERFORM_UPDATE through the pointer layout with scratch of exactly UpdateScratchDataSizeInBytes and guard bytes after it: equals the ARRAY update, guards intact — pass (fails when the update size is under-reported, as a negative control)
Python: SNORM16 rounding against exact fractions for all 65,536 values; check-build on the new cases 6 error 39/39
  • ctest: 145/145 run tests pass (6 self-skipped, 1 disabled), LEONIDA_GAME_DIR set.
  • The 42 existing xdxr_build / d3d12_xdxr_rt case files are byte-identical to main's.
  • d3d12_xdxr_rt_test under the Khronos validation layer with synchronization validation: nothing reported.
  • python -m compileall -q make_game.py tools tests, docs-links and line-ending tests: OK.
  • Only tested on this GPU.

Limits

  • The pointers are their values when the list is submitted, and the array must be in a host-mapped buffer (arena, upload/readback or placed). A pointer array the GPU writes in the same submission is not seen.
  • The short-stride refusal for the 16-bit formats may be stricter than D3D12, which I believe only requires alignment to the component size. The R32 formats have no stride check on main and I left that alone.
  • The opt-in KHR path (LEONIDA_RT_AS=khr) still reads a pointer array as descs (arrayOfPointers is VK_FALSE in vulkan_replay.h). The fix is not small, because the pointer values need heap_base added before the driver can use them. I'll post it as a finding.
  • Procedural (AABB) geometry is still refused. Nothing here touches RT-148, RT-214 or XDXR builder: BOX16 nodes for MINIMIZE_MEMORY BLASes, and TRI1 pairing #3315.

No game data.

🤖 Generated with Claude Code

shelbykb2 and others added 2 commits November 22, 2026 15:34
Two input gaps in BuildRaytracingAccelerationStructure on the XDXR path.

A top-level build recorded InstanceDescs as the descs whatever DescsLayout
said, so with ARRAY_OF_POINTERS the builder read the pointer array as
instance descs. The shader cannot validate an address (every VA is
heap_base + VA) and only replay prepare can refuse a list, so the pointers
are resolved there. The array is read through its buffer's host mapping
(new ResourceBinding::host: the arena range, or the upload/readback
mapping), and each pointer must name 64 bytes of one known buffer; a null
pointer, one into no resource or one past its buffer's end refuses the list
(unresolved_resource) before the GPU reads anything. The descs are then
copied on the GPU into the build's scratch (XdxrLayout::gather_off) and
built as an ARRAY, so the ARRAY path is unchanged. The TLAS scratch size
counts that room for both layouts, and prebuild sizes stay equal. The
pointers are their values at submission; an array the GPU writes in the
same submission is not seen.

The shim mapped R16G16B16A16_FLOAT, R16G16_FLOAT, R16G16B16A16_SNORM and
R16G16_SNORM, but xdxr_inputs refused them, so prebuild answered for builds
replay refused. xdxr_build.comp now decodes them (pc.arg1 2..5): halves of
aligned words, half from its bits (exact, denormals too), SNORM16 as
max(c / 32767, -1) by an integer long division, because SPIR-V division
need not be correctly rounded. Two-component formats read z = 0, A is not
read. A 16-bit format with an odd address or stride, or a stride below its
element size, is refused. The R32 branch is untouched, and the 42 existing
case files of xdxr_build and d3d12_xdxr_rt are byte-identical to main's.
xdxr_build.inc is regenerated with the header's command (glslc 2026.4, which
reproduces main's .inc byte for byte).

d3d12_xdxr_rt_test: the pointer TLAS (descs out of order, one in a
default-heap buffer filled by a copy in the same list) equals the ARRAY
build byte for byte with equal prebuild sizes; three bad pointer arrays are
refused and the list does not run; a plane in all six formats, a cube in the
three with z, and random halves and SNORM16 values equal their
R32G32B32_FLOAT builds byte for byte; four bad strides or addresses are
refused. The format cases carry their source vertex buffers, and
tools/xdxr_bvh.py check-build decodes them itself and compares every leaf's
vertex bits (new tests in tests/test_xdxr_bvh.py, including SNORM16
rounding against exact fractions for all 65536 values).

The KHR path (LEONIDA_RT_AS=khr) still builds a pointer TLAS as an ARRAY.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
…t exact prebuild sizes

Review follow-up on the ARRAY_OF_POINTERS gather: an application sizes an
update's scratch from UpdateScratchDataSizeInBytes. On the XDXR path that is
layout.scratch, the same as ScratchDataSizeInBytes, which for a TLAS already
ends at gather_off + 64 * N, and the update pass (instances, refit, header)
only writes scratch below gather_off. So no code change is needed; this adds
the test that was missing.

ALLOW_UPDATE builds of the three instances through ARRAY and
ARRAY_OF_POINTERS use a scratch of exactly ScratchDataSizeInBytes, then
PERFORM_UPDATE in place from moved instances (the pointer descs out of order)
uses one of exactly UpdateScratchDataSizeInBytes. Each scratch is followed by
256 guard bytes in the same buffer. The two layouts must give the same bytes
after the build and after the update, the update must change the structure,
and both guards must be intact. With the update size reported without the
gather room (a temporary change, not committed), the update guard check
fails.

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

Copy link
Copy Markdown

Tested 82bcd9a on NVIDIA GeForce RTX 3070 (Ampere), driver 617.42, Windows 11 24H2 (26100), MSVC 19.44 RelWithDebInfo + Ninja: pass.

  • Focused CTest: xdxr_descs, xdxr_build, xdxr_build_check (xdxr_bvh.py check-build ... --rays 1000 on the GPU-built BVHs), d3d12_xdxr_rt, d3d12_xdxr_rt_check: pass. bvh_builder skipped (needs the package's DLL).
  • Full CTest: 154/154 passed.
  • With LEONIDA_VK_VALIDATION=1 (VK_LAYER_KHRONOS_validation 1.4.350), no validation messages:
    • d3d12_xdxr_rt_test: pointer TLAS: ARRAY_OF_POINTERS compared with ARRAY (build and update), three bad pointer arrays; vertex formats: plane in 6 formats, cube in 3, 4 refused strides or addresses; BLAS 48768 bytes (prebuild 48768), TLAS (prebuild 640).
    • vk_xdxr_build_test: built every case (refits in place and into another buffer, clone/compact copies, 4-instance TLAS).
  • python -I tests/test_xdxr_bvh.py: OK.

No game files. AI-assisted (Claude).

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 82bcd9a on Windows 11, AMD Radeon iGPU gfx1036 (driver 26.10.1) and RTX 5080 (driver 616.92), MSVC RelWithDebInfo build of this head, LEONIDA_VK_DEVICE set per run with the device line confirmed, VK_LOADER_LAYERS_DISABLE=~implicit~ (no validation layer installed):

  • ctest -R "^(xdxr_descs|xdxr_build|xdxr_build_check|d3d12_xdxr_rt|d3d12_xdxr_rt_check)$": 5/5 on each GPU. d3d12_xdxr_rt printed pointer TLAS: ARRAY_OF_POINTERS compared with ARRAY (build and update), three bad pointer arrays and vertex formats: plane in 6 formats, cube in 3, 4 refused strides or addresses on both.
  • d3d12_vulkan_device: passed on both.
  • python -I tests/test_xdxr_bvh.py: 43/43 OK.

No negative control run.

AI-assisted.

@requiemsnkrp

Copy link
Copy Markdown

Tested 82bcd9a1 (merged onto main aa2988cc) on NVIDIA GeForce RTX 3060, driver 32.0.16.1714, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0: pass.

  • With LEONIDA_VK_VALIDATION=1: d3d12_xdxr_rt ... Passed (pointer TLAS: ARRAY_OF_POINTERS compared with ARRAY (build and update), three bad pointer arrays; vertex formats: plane in 6 formats, cube in 3, 4 refused strides or addresses).
  • d3d12_xdxr_rt_check ... Passed 18.35 sec: every case reports 0 validation errors, 0/1000 rays differ, including all new 16-bit formats, e.g. d3d12_fmt_cube_R16G16B16A16_SNORM: 5504 bytes, 0 validation errors, 0/1000 rays differ (66 hits) and d3d12_fmt_plane_R16G16_FLOAT: ... 0/1000 rays differ (14 hits), and d3d12_tlas: 640 bytes, ... 0/1000 rays differ (725 hits).
  • xdxr_build, xdxr_descs and xdxr_build_check (71 s, 17 cases, all 0 validation errors, 0/N rays differ) pass; python -I tests/test_xdxr_bvh.py: Ran 43 tests ... OK.
  • Full ctest (-E "present|swapchain|frame_pacer", llvm-mc build): 100% tests passed, 0 tests failed out of 148 (9 skipped/disabled, same set as main: shader_library_corpus, bink_decode, bink_play_headless, fsr_dispatch, bvh_builder, bink_audio, gameinput, d3d12_rgb9e5_rtv, d3d12_first_light).

AI-assisted (Claude). No game files.

@justr4mzi

Copy link
Copy Markdown
Contributor

Tested 82bcd9a1 on discrete AMD Radeon RX 6700 XT (gfx1031, driver 26.11.2, no Resizable BAR, Windows 11 25H2 26200.9974, MSVC 19.44.35230.0 RelWithDebInfo + Ninja, Vulkan SDK 1.4.363.0) with Vulkan validation enabled on AMD: pass.

  • ctest --output-on-failure -R "xdxr_descs|xdxr_build|d3d12_xdxr_rt": 5/5 passed (96.17 s: xdxr_descs 0.04 s, xdxr_build 1.10 s, xdxr_build_check 74.86 s, d3d12_xdxr_rt 1.18 s, d3d12_xdxr_rt_check 18.90 s).
  • With LEONIDA_VK_VALIDATION=1 (1.4.363.0):
    • ctest -R "xdxr_build$|d3d12_xdxr_rt$": 2/2 passed (0.85 s, 0 validation errors).
    • Direct vk_xdxr_build_test: AMD Radeon RX 6700 XT (validation on), vk_xdxr_build_test: built every case (0 validation errors).
    • Direct d3d12_xdxr_rt_test: pointer TLAS: ARRAY_OF_POINTERS compared with ARRAY (build and update), three bad pointer arrays; vertex formats: plane in 6 formats, cube in 3, 4 refused strides or addresses; BLAS 48768 bytes (prebuild 48768), TLAS (prebuild 640); expected negative-control refusals (3 unknown resource, 4 unsupported) with 0 validation errors.
    • xdxr_descs_test: xdxr_descs: ok (checked against d3d12.h).
  • Python/docs suites: tests/test_xdxr_bvh.py (43 tests OK, 3.573 s), test_docs_cli_flags.py (3 OK), test_docs_repo_paths.py (2 OK), test_docs_design_rows.py (2 OK), test_docs_list_items.py (2 OK).

No game data. AI-assisted (Gemini, Antigravity).

@ricardotanaka

Copy link
Copy Markdown

Also tested 82bcd9a1 (merged onto main aa2988cc) on AMD Radeon RX 7600 (RDNA3), AMD driver 26.11.2, Windows 11 26200.9457, MSVC 19.44 RelWithDebInfo: pass, same as the checks above, and the first RDNA3 run. xdxr_descs, xdxr_build, xdxr_build_check, d3d12_xdxr_rt and d3d12_xdxr_rt_check pass (bvh_builder skips without game files); every case 0/1000 rays differ, 0 validation errors with LEONIDA_VK_VALIDATION=1; full ctest 153/153.

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

@AirKyzzZ

Copy link
Copy Markdown

Tested 82bcd9a1 on RTX 2060, NVIDIA 566.14, Windows 10 22H2 (19045), clang-cl 23.1.6 + SDK 10.0.26100: pass.

Second GPU vendor after your RX 6800. ctest -R xdxr: 5/5 passed. d3d12_xdxr_rt prints pointer TLAS: ARRAY_OF_POINTERS compared with ARRAY (build and update), three bad pointer arrays and vertex formats: plane in 6 formats, cube in 3, 4 refused strides or addresses, and both check-build runs say all cases match. python -I tests/test_xdxr_bvh.py: 43 tests OK. Full ctest: 129 passed / 10 skipped / 1 failed, identical to main aa2988cc: the one failure is d3d12_vulkan_device at line 5124, the known Windows 10 host comparison that #3557 fixes. One thing I noticed while reading: xdxr_buffer_holding scans every resource, and xdxr_gather calls it again whenever a pointer leaves the cached source buffer, so a TLAS whose pointers alternate between buffers costs instances × resources at list prepare. Probably fine for now, but worth a follow-up if a title's instance arrays turn out to be scattered. AI-assisted.

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