You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vulkan_replay, d3d12: keep indexed BLAS primitive count from falling back to vertex_count - #8146
Both KHR BLAS triangle paths (runtime/src/vulkan_replay.h in emit() and runtime/shims/d3d12_vulkan_device.cpp in GetRaytracingAccelerationStructurePrebuildInfo()) computed the triangle primitive count as:
When an indexed triangle geometry (VK_INDEX_TYPE_UINT16 / VK_INDEX_TYPE_UINT32) has index_count < 3 (for example index_count == 0 for an empty submesh sharing a non-empty vertex buffer), tr.indexType remains indexed while the primitive count fell back to vertex_count / 3, asking Vulkan to build triangles from an out-of-bounds or null index buffer (and inflating prebuild sizes). Conversely, an unknown index_type that mapped to VK_INDEX_TYPE_NONE_KHR still took the indexed branch if index_count >= 3.
This matches the XDXR path (runtime/src/vulkan_backend.h:1314,1324) and derives primitive count directly from whether tr.indexType != VK_INDEX_TYPE_NONE_KHR: index_count / 3 when indexed, vertex_count / 3 when non-indexed.
Also adds a portable CPU mock test (runtime/test/replay_blas_prim_count_test.cpp, registered as replay_blas_prim_count in runtime/CMakeLists.txt) covering UINT16 with 0 indices, UINT32 with 2 indices, UINT16 with 9 indices, non-indexed geometry, and unknown index_type.
Tested
Windows x64, MSVC 19.51.36260.0 (RelWithDebInfo, Ninja); CPU mock tests need no GPU or game files (d3d12_dxr_validation also compiled and passed).
Verified replay_blas_prim_count_test fails on unpatched main on all three buggy cases (UINT16 with 0 indices, UINT32 with 2 indices, and unknown index_type).
After the fix: ctest --test-dir runtime/build -R "^(replay_blas_prim_count|replay_clear_gate|replay_copy_offset|replay_query_edges|d3d12_dxr_validation)$" --output-on-failure — 5/5 passed.
No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — runtime D3D12/Vulkan replay fix, not a shader-translator rule.)
Tested 630f9eec8 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release: pass. Merged onto main77fa308f9 together with #8187 and #8176 (no conflicts; #8187 also touches vulkan_replay.h).
Tested 630f9eec8 on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6 with the MSVC 14.44 STL, RelWithDebInfo: pass.
Built replay_blas_prim_count_test and ran ctest -R ^replay_blas_prim_count$: passes. With main's runtime/src/vulkan_replay.h and runtime/shims/d3d12_vulkan_device.cpp it fails on the three cases named in the description (UINT16 with 0 indices emits 0 primitives, UINT32 with 2 indices emits 0 primitives, unknown index_type falls back to VK_INDEX_TYPE_NONE_KHR and vertex_count / 3). The prebuild-info half in d3d12_vulkan_device.cpp is not reached by this test, only by a code read.
Tested 630f9ee (on maindde82f2) on Linux 7.2.15, native GCC/CMake build of the portable runtime subset (NVIDIA RTX 3080, 615.78.08): pass, with a negative control. This adds Linux/GCC next to the two Windows checks.
replay_blas_prim_count_test: "KHR BLAS primitive counts match indexType", exit 0.
Negative control: the same test built against main's runtime/src/vulkan_replay.h (only that header swapped back) prints:
FAIL: UINT16 with 0 indices emits 0 primitives
FAIL: UINT32 with 2 indices emits 0 primitives
FAIL: unknown index_type falls back to VK_INDEX_TYPE_NONE_KHR and vertex_count / 3
ctest (everything that builds on Linux): 65/65 passed. main passes the 64 that exist there.
check_no_game_data.py on the four files: clean.
Not run: the d3d12_vulkan_device.cpp prebuild-info half, which is Windows-only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: #8047 (comment)
What and why
Both KHR BLAS triangle paths (
runtime/src/vulkan_replay.hinemit()andruntime/shims/d3d12_vulkan_device.cppinGetRaytracingAccelerationStructurePrebuildInfo()) computed the triangle primitive count as:When an indexed triangle geometry (
VK_INDEX_TYPE_UINT16/VK_INDEX_TYPE_UINT32) hasindex_count < 3(for exampleindex_count == 0for an empty submesh sharing a non-empty vertex buffer),tr.indexTyperemains indexed while the primitive count fell back tovertex_count / 3, asking Vulkan to build triangles from an out-of-bounds or null index buffer (and inflating prebuild sizes). Conversely, an unknownindex_typethat mapped toVK_INDEX_TYPE_NONE_KHRstill took the indexed branch ifindex_count >= 3.This matches the XDXR path (
runtime/src/vulkan_backend.h:1314,1324) and derives primitive count directly from whethertr.indexType != VK_INDEX_TYPE_NONE_KHR:index_count / 3when indexed,vertex_count / 3when non-indexed.Also adds a portable CPU mock test (
runtime/test/replay_blas_prim_count_test.cpp, registered asreplay_blas_prim_countinruntime/CMakeLists.txt) coveringUINT16with 0 indices,UINT32with 2 indices,UINT16with 9 indices, non-indexed geometry, and unknownindex_type.Tested
RelWithDebInfo, Ninja); CPU mock tests need no GPU or game files (d3d12_dxr_validationalso compiled and passed).replay_blas_prim_count_testfails on unpatchedmainon all three buggy cases (UINT16with 0 indices,UINT32with 2 indices, and unknownindex_type).ctest --test-dir runtime/build -R "^(replay_blas_prim_count|replay_clear_gate|replay_copy_offset|replay_query_edges|d3d12_dxr_validation)$" --output-on-failure— 5/5 passed.python -I scripts/check_no_game_data.py runtime/src/vulkan_replay.h runtime/shims/d3d12_vulkan_device.cpp runtime/CMakeLists.txt runtime/test/replay_blas_prim_count_test.cpp— passed (exit 0).AI-assisted: yes
Checklist
docs/design.md, with how it was confirmed. (N/A — runtime D3D12/Vulkan replay fix, not a shader-translator rule.)