Skip to content

d3d12: fix DXR prebuild vertex formats, ALLOW_COMPACTION, and NO_DUPLICATE_ANYHIT_INVOCATION - #8695

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-dxr-prebuild-vertex-format-compaction
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-dxr-prebuild-vertex-format-compaction

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Fixes #8504 (claim: #8504 (comment))

Summary

  • All 6 DXR triangle vertex formats in GetRaytracingAccelerationStructurePrebuildInfo (runtime/shims/d3d12_vulkan_device.cpp):
    Maps R32G32B32_FLOAT, R32G32_FLOAT, R16G16B16A16_FLOAT, R16G16_FLOAT, R16G16B16A16_SNORM, and R16G16_SNORM to their exact VkFormat (matching d3d12_com.cpp:913-921). Previously, all 16-bit formats fell through to VK_FORMAT_R32G32B32_SFLOAT, which under-sized scratch buffers on NVIDIA hardware and triggered VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexStride-03735 on 4-byte R16G16_FLOAT/R16G16_SNORM strides.
  • Clean refusal of unsupported VertexFormat:
    Any other DXGI_FORMAT (e.g., DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM) returns zeroed D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO in both XDXR and KHR paths instead of passing an invalid format/stride to vkGetAccelerationStructureBuildSizesKHR.
  • ALLOW_COMPACTION build flag forwarding:
    Forwards D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_ALLOW_COMPACTION -> VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR (matching d3d12_com.cpp:885-886), preventing AS and scratch buffer under-allocation when compaction is enabled.
  • NO_DUPLICATE_ANYHIT_INVOCATION geometry flag forwarding (prebuild + KHR replay parity):
    Forwards D3D12_RAYTRACING_GEOMETRY_FLAG_NO_DUPLICATE_ANYHIT_INVOCATION -> VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR in both GetRaytracingAccelerationStructurePrebuildInfo (runtime/shims/d3d12_vulkan_device.cpp) and vkCmdBuildAccelerationStructuresKHR replay (runtime/src/vulkan_replay.h:3985) so KHR GPU builds sized from prebuild info match without VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-10126.
  • Strict non-overlap: Leaves prims calculation (d3d12_vulkan_device.cpp) untouched (#8146) and d3d12_com.cpp untouched (#8217).

Empirical Live Windows 11 Probe (WARP Tier 11 + NVIDIA GeForce RTX 5090 Tier 12)

  • On native RTX 5090 D3D12 (300 verts): R32G32B32_FLOAT reports res=8832, scratch=2432, whereas R32G32_FLOAT, R16G16B16A16_FLOAT, R16G16_FLOAT (stride 4), R16G16B16A16_SNORM, and R16G16_SNORM (stride 4) all report res=8832, scratch=6784 (nearly 3x larger scratch).
  • On native RTX 5090 D3D12 (3000 verts): FLAGS=NONE reports res=62592, scratch=11008, while ALLOW_COMPACTION increases both to res=62848, scratch=11904 (FAST_TRACE|ALLOW_COMPACTION: res=67200, scratch=16256).
  • On native RTX 5090 D3D12 (3000 verts): NO_DUPLICATE_ANYHIT_INVOCATION changes prebuild sizes (res=60928, scratch=9856 vs res=62592, scratch=11264 for NONE).

Tests

Added runtime/test/d3d12_dxr_prebuild_test.cpp registered in runtime/CMakeLists.txt as d3d12_dxr_prebuild (XDXR) and d3d12_dxr_prebuild_khr (LEONIDA_RT_AS=khr) with SKIP_RETURN_CODE 77 and FAIL_REGULAR_EXPRESSION "Validation Error;VUID-".

Verified on NVIDIA GeForce RTX 5090 with LEONIDA_VK_VALIDATION=1 (0 VUIDs):

  • d3d12_dxr_prebuild: Passed
  • d3d12_dxr_prebuild_khr: Passed
  • d3d12_dxr_validation: Passed
  • d3d12_dxr_validation_khr: Passed
  • d3d12_com: Passed

AI-assisted (Gemini 4 Neon).

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified head 328ea1a44 merged onto main (867d922f0) on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo, Vulkan SDK 1.4.363.0) across both GPUs and both xdxr and khr RT modes with LEONIDA_VK_VALIDATION=1:

  • python -I scripts/check_no_game_data.py on all 4 changed files: clean (exit 0)
  • cmake --build runtime/build --target d3d12_dxr_prebuild_test --parallel: built cleanly
  • NVIDIA GeForce RTX 5060 Ti (driver 610.88, Vulkan 1.4.341):
    • LEONIDA_VK_VALIDATION=1 .\runtime\build\d3d12_dxr_prebuild_test.exe (mode=xdxr): passed, 0 validation errors (native WARP tier 11, native HW tier 12, Leonida Vulkan mode=xdxr)
    • LEONIDA_VK_VALIDATION=1 LEONIDA_RT_AS=khr .\runtime\build\d3d12_dxr_prebuild_test.exe (mode=khr): passed, 0 validation errors
  • AMD Radeon(TM) Graphics (driver 24.10.24, Vulkan 1.3.280):
    • LEONIDA_VK_VALIDATION=1 LEONIDA_VK_DEVICE=Radeon .\runtime\build\d3d12_dxr_prebuild_test.exe (mode=xdxr): passed, 0 validation errors
    • LEONIDA_VK_VALIDATION=1 LEONIDA_VK_DEVICE=Radeon LEONIDA_RT_AS=khr .\runtime\build\d3d12_dxr_prebuild_test.exe (mode=khr): passed, 0 validation errors

AI-assisted.

@lohant27-netizen

Copy link
Copy Markdown

Tested 328ea1a44 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #8777, #8763, #8762, #8754, #8711 and #8695 (no conflicts): pass.

@MartinIndra02

Copy link
Copy Markdown

Independent build + test: PASS (one note)

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo, NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124 (host D3D12 tier 1.2, Vulkan layer in XDXR and KHR modes), WARP.

Head 328ea1a44, based on current main 867d922f0. Reconfigured for the new target.

Test PR shim + vulkan_replay.h reverted to main
d3d12_dxr_prebuild_test.exe with LEONIDA_VK_VALIDATION=1 exit 0: native WARP (tier=11) ... OK, native HW (NVIDIA GeForce RTX 3080) (tier=12) ... OK, Leonida Vulkan (tier=0, mode=xdxr): all 6 vertex formats, ALLOW_COMPACTION, NO_DUPLICATE_ANYHIT_INVOCATION, and invalid format refusal OK exit 1
ctest -R ^d3d12_dxr (d3d12_dxr_validation, ..._khr, d3d12_dxr_prebuild, ..._khr) 4/4 passed

Note: on the KHR path the prebuild now passes the real format (for example VK_FORMAT_R16G16B16A16_SNORM) to vkGetAccelerationStructureBuildSizesKHR. Vulkan requires VK_FORMAT_FEATURE_ACCELERATION_STRUCTURE_VERTEX_BUFFER_BIT_KHR for the vertex format, and the 16-bit SNORM formats aren't guaranteed on every device (they are on this RTX 3080). Checking vkGetPhysicalDeviceFormatProperties for that bit, and refusing (zeroed prebuild info) like an unknown format, would keep a GPU without it away from a VUID. The emit side uses t.vertex_format from recording, so whatever check is added should apply there too.

@h0useadv

Copy link
Copy Markdown

Tested 328ea1a44 (based on main 867d922f0) natively on Windows: AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32029.2010, Windows 11 Pro build 26300: pass, no new failures. Built with clang-cl 23.1.6 + lld-link against an xwin splat (MSVC 14.44, SDK 10.0.26100), RelWithDebInfo; synthetic, no game files.

  • d3d12_dxr_prebuild_test, exit 0:
    • native WARP (tier=11): all 6 vertex formats, ALLOW_COMPACTION, and NO_DUPLICATE_ANYHIT_INVOCATION OK
    • native HW (AMD Radeon RX 9070 XT) (tier=11): all 6 vertex formats, ALLOW_COMPACTION, and NO_DUPLICATE_ANYHIT_INVOCATION OK
    • Leonida Vulkan (tier=0, mode=xdxr): all 6 vertex formats, ALLOW_COMPACTION, NO_DUPLICATE_ANYHIT_INVOCATION, and invalid format refusal OK
  • Full ctest -j8, failures rerun with -j1: 268/273; the 5 that fail are the same 5 as on main on this GPU.

AI-assisted (Claude Code).

@MiguelMatMar

MiguelMatMar commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested 328ea1a on NVIDIA GeForce RTX 4080 SUPER, driver 621.24 (Vulkan 1.4.357), Windows 11 Pro 26300, MSVC 14.44, Ninja RelWithDebInfo (fresh build folder), applied on main 867d922, no game data: pass.

  • ctest -R ^d3d12_dxr_prebuild$: passed. The comparison is against native WARP (tier=11: all 6 vertex formats, ALLOW_COMPACTION, and NO_DUPLICATE_ANYHIT_INVOCATION OK), with the layer on this NVIDIA device.
  • Negative control: only the test-side files applied (no source change): d3d12_dxr_prebuild fails.

(AI-assisted check, 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.

Coordinating who works on what (52) (moved to #8683)

6 participants