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

@lohant27-netizen

Copy link
Copy Markdown

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 main 77fa308f9 together with #8187 and #8176 (no conflicts; #8187 also touches vulkan_replay.h).

@AirKyzzZ

Copy link
Copy Markdown
Contributor

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.

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

@rojasruiz

Copy link
Copy Markdown

Tested 630f9ee (on main dde82f2) 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.

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.

4 participants