Skip to content

vulkan_replay, d3d12: keep indexed BLAS primitive count from falling back to vertex_count - #8146

Open
CourtyardGames wants to merge 1 commit into
ItsNotRexed:mainfrom
CourtyardGames:fix/khr-blas-indexed-prim-count
Open

CourtyardGames wants to merge 1 commit into
ItsNotRexed:mainfrom
CourtyardGames:fix/khr-blas-indexed-prim-count

Conversation

@CourtyardGames

Copy link
Copy Markdown

Claimed in the coordination issue as: #8047 (comment)

What and why

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:

(t.index_type != 0 && t.index_count >= 3) ? (t.index_count / 3u) : (t.vertex_count / 3u)

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

  • 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.)

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.

1 participant