Skip to content

Runtime: validate XDXR build and refit buffer ranges (D3D-483) - #4640

Open
gabrielsteglich wants to merge 2 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/xdxr-build-buffer-ranges
Open

gabrielsteglich wants to merge 2 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/xdxr-build-buffer-ranges

Conversation

@gabrielsteglich

@gabrielsteglich gabrielsteglich commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed as D3D-483 in #4571.

Depends on: #3944, #4494, #4098, #3315

The branch builds directly on main. These are merge conflicts with parallel XDXR work in vulkan_backend.h or d3d12_xdxr_rt_test.cpp, listed for coordination.

What and why

Before recording an XDXR build, check that the result, scratch, any separate refit source, and the contiguous TLAS instance array each fit within one registered buffer. The range lookup accepts valid offsets and can find an enclosing placed-buffer alias. Builds with an empty TLAS and in-place refits remain supported. Replay returns unsupported for incomplete spans during preparation.

Tested

Windows 11 Pro 26300, MSVC 19.44.35229, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, RelWithDebInfo, NVIDIA GeForce RTX 3090 with driver 621.01. Vulkan validation enabled with LEONIDA_VK_VALIDATION=1 and VK_LOADER_LAYERS_DISABLE=~implicit~.

  • Base d0835dd9: 5/5 XDXR tests passed. Initial commit 18e8c895: 7/7 focused tests passed. All 21 synthetic GPU cases matched the base in BVH sizes and traversal results, with zero Vulkan validation errors. The D3D12 fixture exercises 256-byte offsets and exact-fit result and TLAS instance spans.
  • CPU replay regression: 18 scenarios, including nine rejections before the recording callback. With the old preflight, eight of those invalid cases reached the mock recording callback. Invalid cases run entirely in CPU mocks.
  • Initial full runtime suite: 139 passed, eight skipped, one disabled, zero failures. Documentation links, CTest registration, CI registration, and the no-game-data check passed.
  • After integrating main at 7b7d73f8, commit 995c55c1 passed all seven focused tests on the same RTX 3090. The 21 synthetic GPU cases produced identical results with zero Vulkan validation errors. The full runtime suite recorded 156 passed, eight skipped, one disabled and zero failures. The integration reuses the range-aware VA lookup from main and requires full containment for XDXR.
  • Independent tests on 18e8c895 passed on an RTX 4090 and AMD Radeon Graphics. Test results

AI-assisted: yes. Independently reviewed before submission.

Checklist

  • No game data, keys or decryption. GPU tests use synthetic geometry.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 18e8c89 on Windows 11 with the NVIDIA GeForce RTX 4090 (32.0.16.2101) and AMD Radeon Graphics (32.0.21043.5001): the focused XDXR checks pass.

I built the RelWithDebInfo targets with MSVC 14.51. I ran ctest --test-dir build -C RelWithDebInfo -R "^(d3d12_xdxr_rt(_check)?|replay_xdxr_build_ranges)$" -V with each adapter selected. All three tests pass on each run. The device log confirms each selection.

The existing buffer_va_index_test also passes. I compared 100,000 range lookups across 240 overlapping buffers with a linear scan. The scan and index select the same resource for every request. A control that checks only the first byte fails the same comparison. These checks use synthetic data.

AI-assisted.

@DiazE117

Copy link
Copy Markdown
Contributor

Tested 995c55c1 (the head after the merge with main; the earlier run was on 18e8c895) on Windows 11 Pro 10.0.26320, NVIDIA GeForce RTX 4070 SUPER, driver 610.88, MSVC 19.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0: pass.

  • Build of the PR head: no warnings in vulkan_backend.h, buffer_va_index.h or the new test.
  • ctest with LEONIDA_VK_VALIDATION=1: 164/164 passed (the usual skips), 0 VUIDs. buffer_va_index, xdxr_descs, xdxr_build, xdxr_build_check, d3d12_xdxr_rt, d3d12_xdxr_rt_check and replay_xdxr_build_ranges pass.
  • d3d12_xdxr_rt_test on its own: BLAS 48768 bytes (prebuild 48768), TLAS prebuild 640, arena peak 0.4 MiB, 0 refused.
  • Negative control: with the result/scratch contains() check in xdxr_build_supported() turned off, replay_xdxr_build_ranges fails 4 cases (BLAS destination cannot continue into an adjacent buffer, rejects an unregistered destination, a scratch span one byte short, an unregistered scratch address: replay 0 instead of 9, recorded 1 instead of 0), and passes again with the PR's code.

Code read: contains() rejects empty, wrapping and over-longest_ spans before find(), and checks the hit holds the whole span, so an aliasing buffer that holds it is still found. xdxr_check runs from replay like buffer_at, under resource_mutex_, so reading buffer_vas_ there needs no new lock. One question, not blocking: the BLAS geometry inputs (vertex_va, index_va, and a transform if any) are still only checked for non-null in xdxr_inputs(), not for their byte range, though the builder reads them at heap_base + VA too. Is that left for a follow-up?

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

@rgvxsthi

Copy link
Copy Markdown

Tested 995c55c1 merged onto main 0db7fed5 (6 commits behind; merges cleanly) on AMD Radeon RX 9070 (RDNA4), AMD 26.11.2 (LLPC), Windows 11 Pro 10.0.26300, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo: pass.

  • ctest -R "replay_xdxr_build_ranges|d3d12_xdxr_rt": 3/3 passed, including the new replay_xdxr_build_ranges.

Built only the targets this PR touches (replay_xdxr_build_ranges_test, d3d12_xdxr_rt_test). Not checked: the merge with the PRs listed under "Depends on". No game files. AI-assisted (Claude Code).

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

Built and ran both at 995c55c10 on Windows 11, RTX 5070 Ti:

  • replay_xdxr_build_ranges_test -> exit 0, XDXR build ranges: exact spans replay and invalid ranges stop before recording.
  • d3d12_xdxr_rt_test <out> -> exit 0, d3d12_xdxr_rt: BLAS 48768 bytes (prebuild 48768), TLAS (prebuild 640).

The runtime now validates the XDXR build/refit buffer ranges through the range-aware VA lookup, and an invalid range stops before recording; the added replay test covers exact spans and the invalid case. git diff --check clean. No blocking issue.

@memorypressure

Copy link
Copy Markdown

Verified on current main: the net delta over main is a 7-line BufferVaIndex::contains riding on main's range-aware find (b8273c0, present on main — verified), plus xdxr_build_supported upgrading the null-only xdxr_check to real per-build range checks, the new CPU test and CMake/docs lines; all hunks apply cleanly and compileall plus the docs path/flag tests pass. One trap worth flagging to reviewers: cherry-picking the raw commit silently replaces main's alias-preferring find from the #2823 review with a simpler version — the merge is clean and correct, but do not merge the bare commit. The runtime tests could not be built here (no cmake build). AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Exopus-0x65f7ad0

Copy link
Copy Markdown

Tested 995c55c1 on Windows 11 (26300), RTX 5060 Ti / 621.14, MSVC 14.51 (VS 2026), Vulkan SDK 1.4.363.0, RelWithDebInfo, clean build with -DLEONIDA_LLVM_MC (translated-shader D3D12 gate tests included), full LEONIDA_VK_VALIDATION=1 ctest -j4: 162/162 passed, 0 VUIDs, 0 build errors. 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