Skip to content

Runtime: fix KHR TLAS ARRAY_OF_POINTERS handling (D3D-425) - #4301

Open
mtrw00w wants to merge 1 commit into
ItsNotRexed:mainfrom
mtrw00w:fix/d3d-425-khr-pointer-array
Open

mtrw00w wants to merge 1 commit into
ItsNotRexed:mainfrom
mtrw00w:fix/d3d-425-khr-pointer-array

Conversation

@mtrw00w

@mtrw00w mtrw00w commented Nov 23, 2026

Copy link
Copy Markdown

What and why

The opt-in KHR acceleration-structure path recorded a TLAS ARRAY_OF_POINTERS layout as inline instance descriptions. The pointer table contains console GPU virtual addresses, so passing it directly to Vulkan makes the driver read invalid data.

This change:

  • records the D3D12 instance layout in BuildAccelerationStructure;
  • snapshots and validates the pointer table during replay preparation;
  • rebases each console VA using heap_base;
  • stages the rebased table at the start of the D3D12 scratch buffer;
  • keeps the driver scratch correctly aligned;
  • includes the pointer-table prefix in KHR prebuild scratch sizes;
  • adds CPU regression coverage;
  • changes the KHR GPU/RayQuery test to use a pointer-array TLAS.

The host snapshot has the same limitation as the XDXR gather path: a pointer table written by the GPU earlier in the same submission is not visible.

Related to #313 and the KHR follow-up noted in #3944.

Testing

Windows 11, MSVC RelWithDebInfo, AMD Radeon RX 6800 XT, Vulkan SDK 1.4.363.0.

  • Focused regression set: 12/12 tests passed.
  • d3d12_indirect_rt: pointer-array TLAS, RayQuery hit=1, miss=0.
  • LEONIDA_VK_VALIDATION=1 d3d12_indirect_rt_test.exe: PASS with 0 validation errors.
  • git diff --check: clean.

No game files or extracted assets are included.

AI assistance

OpenAI Codex assisted with investigation, implementation and review. The result was compiled and tested locally on the GPU listed above.

Depois de preencheres, confirma que o destino no topo é:

ItsNotRexed/Leonida ← mtrw00w/Leonida

@Kam471

Kam471 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Overlap check: this is the third open implementation of D3D-425's KHR ARRAY_OF_POINTERS path. #4060 (\cc4b3744) and #4105 (\438fd4a0) both also record the layout and build the instance descs; I tested #4060 on an RTX 5070 Ti (ARRAY and ARRAY_OF_POINTERS TLAS, RayQuery hit=1/miss=0, null pointer refused, 0 validation errors) and #4105 additionally touches the XDXR builder. This branch's snapshot/validate/rebase step looks like the most defensive of the three, and it also updates
eplay_acceleration_structure_test. Please have the coordinator compare them and pick one; the other two should rebase or close. No test result from me yet beyond reading the diff.

@molodayamama

Copy link
Copy Markdown

Independent NVIDIA check of f309fbc41a857f908694a422e859431aee4d65e6 on RTX 4060 (driver 32.0.16.1088), Windows 10 Pro 22H2 (19045.7058). Built the two test targets with MSVC 19.40 / Ninja RelWithDebInfo, Windows SDK headers 10.0.26100.0, and glslang 16.6.0. Synthetic test scene, no game files.

  • replay_acceleration_structure: passed. The test reports both TLAS ARRAY and ARRAY_OF_POINTERS layouts preserved.
  • d3d12_indirect_rt: passed. The GPU reported BLAS + pointer-array TLAS ... RayQueryKHR (hit=1, miss=0). The ExecuteIndirect count-buffer check also passed.
  • Re-ran the GPU test with LEONIDA_VK_VALIDATION=1 and Khronos Validation Layer advertising Vulkan 1.4.369. Confirmed the test printed NVIDIA GeForce RTX 4060 (validation on), the same hit/miss result, and 0 validation errors.

AI-assisted (Codex).

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested f309fbc on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "replay_acceleration|indirect_rt|xdxr" (7 tests: xdxr_descs, xdxr_build, xdxr_build_check, d3d12_xdxr_rt, d3d12_xdxr_rt_check, d3d12_indirect_rt, replay_acceleration_structure): 7/7 pass on each GPU. d3d12_indirect_rt reports "BLAS + pointer-array TLAS BuildRaytracingAccelerationStructure + RayQueryKHR (hit=1, miss=0)" on both. No game files.

AI-assisted.

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Tested f309fbc4 on Linux (RTX 3080 + RTX 5080, driver 615.71.09, Vulkan 1.4.351, GCC 13.3, no game files).
main is not in this branch's history, so I measured it twice: as it stands, and merged onto current main
(03b09a08) with git merge --no-ff --no-commit — clean, no conflicts.

GPU suite, same numbers in all three states:

State with LEONIDA_W64_EMULATE=1 without failures
your head f309fbc4 (RTX 3080) 195/210 passed, 15 skipped 164/210, 46 skipped 0
merged on main (RTX 3080) 195/210, 15 skipped 164/210, 46 skipped 0
merged on main (RTX 5080) 195/210, 15 skipped — 0
plain main 03b09a08 (RTX 3080) 195/210, 15 skipped 164/210, 46 skipped 0

So your changes to vulkan_backend.h, vulkan_replay.h and command_list.h compile with GCC on Linux and leave
the 210-program suite exactly where it was.

What this does not cover, so the row is not mistaken for a full pass: the test you added or extended is
runtime/test/d3d12_indirect_rt_test.cpp, and the d3d12_* test executables are built only inside the MSVC block
of runtime/CMakeLists.txt (/W4 /permissive- /utf-8 around line 1600). On Linux the KHR_TLAS
ARRAY_OF_POINTERS path you are fixing is therefore never executed — none of the 210 programs reaches it. This is
a Linux build-and-suite check, not a verification of the D3D-425 behaviour; that row still needs a Windows result.

python -m compileall -q make_game.py tools tests: clean. The RTX 5080 was busy (only ~186 MiB free) during the
other two runs, so it appears only where it actually ran. AI-assisted testing, counts read through by hand.

@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.

P2 — GPU-written pointer tables are consumed as stale host data (runtime/shims/d3d12_vulkan_device.cpp:1519,1657)

I traced the replay order on f309fbc4: execute_now prepares every list before it records and emits the commands, while host_at accepts any mapped resource. Repro: place a TLAS ARRAY_OF_POINTERS table in a DEFAULT buffer, then update that table with CopyBufferRegion earlier in the same submission. Preparation reads the old CPU mapping before the GPU copy runs; if the old entries are still valid, it succeeds and silently builds the TLAS from stale pointers. The added tests only populate an UPLOAD table from the CPU.

The PR documents this limitation, but the runtime does not refuse the unsupported input. Only expose ResourceBinding::host for sources known to be current on the CPU, and make host_at fail otherwise (or track earlier GPU writes). Please add a regression that verifies the GPU-written case fails instead of building from stale contents.

@zNvsty

zNvsty commented Nov 23, 2026

Copy link
Copy Markdown

Tested f309fbc4 (base main aa2988cc) on NVIDIA GeForce RTX 3060 Ti (Ampere), driver 621.14, Windows 11 26200, MSVC 19.44, Windows SDK 10.0.26100, Vulkan SDK / validation layer 1.4.363.0, Ninja RelWithDebInfo: pass. This is the first NVIDIA run of this PR (the author's run was on an RX 6800 XT).

  • Full ctest: 146/146 pass. On main aa2988cc on the same machine: 145/145, with the same skips. The only difference is the new replay_acceleration_structure.
  • ctest -R 'indirect_rt|acceleration|xdxr_rt|d3d12_vulkan_device' --repeat until-fail:3 with LEONIDA_VK_VALIDATION=1: 5/5 pass. I ran it twice: on the default (XDXR) path, and with LEONIDA_RT_AS=khr (there the two d3d12_xdxr_rt* tests skip as designed).
    • d3d12_indirect_rt: [PASS] BLAS + pointer-array TLAS ... RayQueryKHR (hit=1, miss=0) and PASS (0 validation errors) on both paths.
    • replay_acceleration_structure: TLAS ARRAY and ARRAY_OF_POINTERS layouts preserved.
    • 0 VUID- messages in either log.

For the comparison @Kam471 asked for: on the same machine with the same steps, #4060 at its new head 77f00b60 also passes everything (report on #4060). One difference in coverage: this PR changes d3d12_indirect_rt's TLAS from ARRAY to ARRAY_OF_POINTERS, so that GPU test no longer builds an ARRAY TLAS. #4060 keeps the ARRAY case and adds ARRAY_OF_POINTERS next to it, plus the null-entry and GPU-written-list refusal cases. I only ran the tests and didn't review the rebase/staging logic.

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

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