Repository navigation
Conversation
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>
With LEONIDA_RT_AS=khr, a top-level BuildRaytracingAccelerationStructure from D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS handed the driver the pointer array as if it were the instance descs. The pointers are console VAs, so arrayOfPointers=VK_TRUE would not help either. The KHR path now reuses ItsNotRexed#3944's gather: the pointer array is read when the list is prepared, the descs are copied into the first khr_instance_gather_bytes of the scratch (64 bytes each, rounded up to 256), and the build reads them as an ARRAY with the driver's scratch after them. The prebuild scratch sizes add that room for an ARRAY_OF_POINTERS TLAS. The XDXR path is unchanged apart from the shared helper's name and the barrier's destination stage being a parameter. d3d12_indirect_rt_test builds the same TLAS from a pointer array (desc 192 bytes into its own buffer) and checks the prebuild sizes and a ray query hit. Depends on: ItsNotRexed#3944 AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Un5pGpp5KpKY7WQpY15RFK
|
Overlap to compare: #4060 ( |
|
Tested 438fd4a on Windows 11, AMD Radeon iGPU gfx1036 (driver 26.10.1) and RTX 5080 (driver 616.92): No negative control run. AI-assisted. |
|
Closing in favour of #4060 by @sds-228, which claimed D3D-425 first and doesn't depend on #3944. I missed the earlier claims in #3918 when I claimed it; sorry for the duplicate, and thanks @Kam471 for the flag. Tested #4060 on RTX 5070 / driver 621.14 / Windows 11: pass, in both XDXR and |
|
Reviewed statically (no compiler here) and the KHR/XDXR split is coherent: gather runs only in the KHR branch ( Two things to state in the body: the head stacks two still-open #3944 commits ( AI-assisted review, no game files, no GPU. |
|
Tested
AI-assisted (Claude). No game files. |
|
Windows + GPU check: NVIDIA GeForce RTX 5080 (driver 621.01) + AMD Radeon 610M iGPU (driver 32.0.13018.6), Windows 11, MSVC (VS BuildTools 18) + Ninja, RelWithDebInfo, Vulkan SDK headers fetched. Tested head Build: clean, 181 targets. Targeted, default XDXR mode,
KHR path (the
Python:
Full suite (
The PR's unstable CI state did not reproduce locally. Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine. |
Claimed in the coordination issue as: D3D-425 (#3918)
Depends on: #3944
This branch is on top of #3944's two commits; only the last commit (
d3d12 KHR builds: gather ARRAY_OF_POINTERS instance descs (D3D-425)) is new here. Once #3944 is merged, this rebases to that one commit.What and why
With
LEONIDA_RT_AS=khr, a top-levelBuildRaytracingAccelerationStructurefromD3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERShanded the driver the pointer array as if it were the instance descs (vulkan_replay.h, KHR build branch,arrayOfPointers = VK_FALSEoninstances_va). SettingarrayOfPointers = VK_TRUEwouldn't fix it either: the pointers are console VAs, not device addresses.The KHR path now uses #3944's gather:
vulkan_backend.h:xdxr_gatherbecomesgather_instances(build, dst_va, gather), the same code with the destination passed in, andrecord_xdxr_gatherbecomesrecord_instance_gather(..., build_stage). The XDXR path calls them exactly as before, withscratch_va + gather_offandCOMPUTE_SHADER. The KHR path gets two newReplayFunctionshooks that call them with the start of the scratch andACCELERATION_STRUCTURE_BUILD_BIT_KHR.vulkan_replay.h: when the list is prepared, an ARRAY_OF_POINTERS TLAS resolves the pointer array; a bad pointer refuses the list before anything runs, as on the XDXR path. When the build is recorded, the descs are copied into the firstkhr_instance_gather_bytes(n)bytes of the scratch (64 per desc, rounded up to 256 so the driver's scratch keeps D3D12's 256-byte alignment). The build then reads them as an ARRAY, with the driver's scratch starting after them.d3d12_vulkan_device.cpp: for an ARRAY_OF_POINTERS TLAS,GetRaytracingAccelerationStructurePrebuildInfoadds that room toScratchDataSizeInBytesandUpdateScratchDataSizeInBytes.d3d12_indirect_rt_test.cpp: builds the same TLAS from a pointer array, with the desc 192 bytes into its own buffer and the pointer in another buffer. It checks the prebuild sizes (ARRAY + 256 scratch bytes) and runs the existing ray query against both TLASes. Read the old way, the pointer buffer is an instance withInstanceMask0, so the ray misses.docs/d3d12_vulkan.md§4.8: one sentence on the KHR gather.Tested
Windows 11, NVIDIA GeForce RTX 5070, driver 621.14, MSVC (VS 2022 17.14),
scripts\build_runtime.ps1, RelWithDebInfo:d3d12_indirect_rt_test: both[PASS] BLAS + TLAS ... (hit=1, miss=0)and[PASS] BLAS + TLAS from ARRAY_OF_POINTERS ... (hit=1, miss=0), withLEONIDA_VK_VALIDATION=1and without; 0 validation errors.ctest -R "d3d12_xdxr_rt|d3d12_indirect_rt|d3d12_vulkan_device": 4/4 passed. The XDXR pointer-array tests from XDXR builds: ARRAY_OF_POINTERS instances and the 16-bit vertex formats #3944 are unchanged.replay_*CPU tests pass.AI-assisted (Claude).
Checklist
docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code
https://claude.ai/code/session_01Un5pGpp5KpKY7WQpY15RFK