Skip to content

fix(runtime): support IBStripCutValue via dynamic primitive restart - #1583

Closed
evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:ag/d3d12-strip-cut
Closed

evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:ag/d3d12-strip-cut

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

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

What and why

CreateGraphicsPipelineState previously logged index-buffer strip cuts (primitive restart) are not modelled and left primitive restart disabled on all graphics pipelines.

This change:

  • Loads core Vulkan 1.3 vkCmdSetPrimitiveRestartEnable in runtime/src/vulkan_backend.h and wires it into ReplayCallbacks.
  • Adds VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE to graphics pipelines in runtime/shims/d3d12_vulkan_device.cpp (before VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE so pipelines with no vertex bindings still omit only the stride state) and records IBStripCutValue on leonida::GraphicsPipeline.
  • In runtime/src/vulkan_replay.h, calls vkCmdSetPrimitiveRestartEnable on every draw, enabling primitive restart only when the draw is indexed, the dynamic topology is a strip (LINE_STRIP, TRIANGLE_STRIP, or their adjacency forms), and the bound index format matches the PSO's IBStripCutValue (0xFFFF with VK_INDEX_TYPE_UINT16, 0xFFFFFFFF with VK_INDEX_TYPE_UINT32).
  • Adds a synthetic GPU draw test in runtime/test/d3d12_draw_test.cpp drawing two disjoint quads (top-left and bottom-right) in a single TRIANGLESTRIP DrawIndexedInstanced call with 0xFFFF (UINT16), 0xFFFFFFFF (UINT32), and a no-cut negative control (DISABLED).

AI-assisted (Antigravity / Gemini, operated by Vonsek).

Tested

Synthetic scene only (no game files or game shaders were run). Built from commit 432d9ab1 (based on upstream/main 99f99890) on Windows 11 with VS 2022 Build Tools (MSVC 19.44.35230.0), Ninja, -DLEONIDA_VULKAN_HEADERS_FETCH=ON, and Khronos glslang 16.6.0. VK_LOADER_LAYERS_DISABLE=~implicit~ was set; VK_LAYER_KHRONOS_validation is not installed locally on this host (CI runs validation).

Before the fix (99f99890): CreateGraphicsPipelineState logged index-buffer strip cuts (primitive restart) are not modelled and left primitive restart disabled.

Commands and measured outcomes on 432d9ab1:

  • NVIDIA GeForce RTX 5080 (0x10de:0x2c02), driver 616.92, Vulkan 1.4.351 (LEONIDA_VK_DEVICE=5080):
    • ctest --test-dir build-strip-cut -R "^(d3d12_draw|d3d12_vulkan_device)$" --output-on-failure -V -> 2/2 passed.
    • strip cut (0xFFFF & 0xFFFFFFFF): 4096/4096 pixels matched each (no-cut negative control painted 256 bridge pixels in bottom-left)
  • AMD Radeon(TM) Graphics (0x1002:0x13c0), driver 26.10.1, Vulkan 1.4.315 (LEONIDA_VK_DEVICE=Radeon):
    • ctest --test-dir build-strip-cut -R "^d3d12_draw$" --output-on-failure -V -> 1/1 passed.
    • strip cut (0xFFFF & 0xFFFFFFFF): 4096/4096 pixels matched each (no-cut negative control painted 256 bridge pixels in bottom-left)
  • Negative control: drawing the same two quads as a continuous triangle strip without a strip cut painted the predicted 256 bridge pixels in the bottom-left quadrant red (matching the analytical triangle ((-1,0), (0,0), (1,-1))), whereas both 0xFFFF and 0xFFFFFFFF strip-cut draws kept all 1,024 bottom-left pixels pure blue (0, 0, 255, 255) on both GPUs.

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 graphics pipeline/replay change only.)

CreateGraphicsPipelineState previously logged that index-buffer strip cuts (primitive restart) were not modelled and left primitiveRestartEnable disabled.

Load Vulkan 1.3 vkCmdSetPrimitiveRestartEnable in vulkan_backend.h, declare VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE on graphics pipelines, record IBStripCutValue on GraphicsPipeline, and enable primitive restart during replay only for indexed strip topologies whose index format matches the PSO strip-cut value (0xFFFF with UINT16, 0xFFFFFFFF with UINT32). Add synthetic 16-bit/32-bit triangle-strip cut and no-cut negative-control GPU draw tests in d3d12_draw_test.
@Flyander

Copy link
Copy Markdown
Contributor

Coordination check: this covers the same D3D-57 / IBStripCutValue primitive-restart behavior as the still-open #572. #572 is stale against the post-#291 main and carries the larger restart test matrix; this PR is a fresh targeted branch on current main. Please mark one explicitly as the successor and port any unique tests before both stay active, so maintainers don't review or merge the same runtime change twice.

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Closing in favor of #572 (D3D-57) by @ezwinxdlmao, which already owns IBStripCutValue primitive restart. Thanks @Flyander for catching the overlap! (AI-assisted, operated by Vonsek.)

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. ctest: 87/87 on the RTX 4080 SUPER. The Intel UHD 770 failures are known and unrelated: d3d12_vulkan_device (line 3768, reported in #1548), d3d12_descriptor (min-LOD), d3d12_present (#1548) and d3d12_copy_xfmt.

ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
#1583's strip-cut passes leave the fence at 20, and #1660's bundle blend
block then signalled 4. SetEventOnCompletion(4) returns at once when the
fence has already passed 4, on native D3D12 too, so the check read the
readback buffer before the draws had run. It saw the last strip-cut
pass's red quad: "bundle blend pixel (0, 0): got 255,0,0,255, expected
red 64", on every GPU.

Signal 21 instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants