Skip to content

Runtime: primitive restart from the PSO's IBStripCutValue (D3D-57) - #572

Closed
ezwinxdlmao wants to merge 13 commits into
ItsNotRexed:mainfrom
ezwinxdlmao:d3d-primitive-restart
Closed

ezwinxdlmao wants to merge 13 commits into
ItsNotRexed:mainfrom
ezwinxdlmao:d3d-primitive-restart

Conversation

@ezwinxdlmao

@ezwinxdlmao ezwinxdlmao commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #313 as a new item (claim); listed there as D3D-57.

What and why

Until now, #291's graphics path logged a PSO's IBStripCutValue as index-buffer strip cuts (primitive restart) are not modelled, and docs/d3d12_vulkan.md listed primitive restart as a known gap. An indexed strip with cut indices therefore drew the cut index as a vertex, which bridges strips that should be separate. This PR maps IBStripCutValue to Vulkan primitive restart on #291's draw path.

Pipeline.

  • The PSO keeps its cut value.
  • A value outside the enum is refused with E_INVALIDARG, as the host runtime refuses it.
  • VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE (core in Vulkan 1.3) is dynamic in every graphics pipeline.

Replay.

  • vkCmdSetPrimitiveRestartEnable runs at every draw.
  • Restart is on for an indexed strip (line or triangle, with or without adjacency) whose cut value is Vulkan's restart index for the bound format: 0xFFFF with 16-bit indices, 0xFFFFFFFF with 32-bit ones.
  • Otherwise restart is off.

Measured rules. D3D12 compares each index with the cut value; Vulkan restarts at all ones for the index type. To see where they differ, I drew the same geometry with a standalone probe on the host PC D3D12 runtime. The probe is not committed; it uses HLSL compiled at run time and no game data. I ran it on all three adapters on this machine:

Draw (index format, PSO cut value, index in the buffer) Radeon 680M RTX 3050 Laptop WARP This PR
strip, 16-bit, 0xFFFF, 0xFFFF cut cut cut cut
strip, 32-bit, 0xFFFFFFFF, 0xFFFFFFFF cut cut cut cut
strip, either format, no cut value drawn drawn drawn drawn
strip, 16-bit, 0xFFFFFFFF, 0xFFFF drawn drawn drawn drawn
strip, 32-bit, 0xFFFF, 0xFFFFFFFF drawn drawn drawn drawn
strip, 32-bit, 0xFFFFFFFF, 0x0000FFFF drawn drawn drawn drawn
strip, 32-bit, 0xFFFF, 0x0000FFFF cut cut cut drawn
triangle list, either format, matching cut value drawn cut cut drawn
strip without an index buffer, cut value 0xFFFF drawn drawn drawn drawn
line strip, cut / no cut value cut / drawn cut / drawn cut / drawn cut / drawn
line list, 16-bit, 0xFFFF drawn cut cut drawn
PSO with IBStripCutValue 3 E_INVALIDARG E_INVALIDARG E_INVALIDARG E_INVALIDARG

("Drawn" means the cut index became a vertex.) Two rows differ, and both are listed under known gaps in docs/d3d12_vulkan.md:

  • 0xFFFF with 32-bit indices. D3D12 cuts at index 0x0000FFFF, but Vulkan restarts only at 0xFFFFFFFF, so the strip is drawn uncut. Matching it would mean rewriting the index buffer.
  • Lists. The drivers disagree here. AMD's draws the cut index as a vertex. NVIDIA's and WARP end the list there, as the D3D11.3 functional spec (section 8.12) describes. This PR never restarts a list, as AMD's driver and vkd3d-proton do. It therefore needs no VK_EXT_primitive_topology_list_restart. The spec also notes that no application would author a cut in a list.

Not covered. IASetIndexBufferStripCutValue (CommandList9, for PSOs with the dynamic strip-cut flag) is not implemented, since the proxy has no CommandList9 yet.

Vertex strides. Earlier heads of this PR also stopped pipelines without vertex input from declaring VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE (VUID-vkCmdDraw-pStrides-04913). #291's merge candidate now has that fix, so this PR no longer carries it.

Docs. docs/d3d12_vulkan.md is updated in four places:

  • the mapping table;
  • the graphics-pipeline bullets (dynamic state, primitive restart);
  • known gaps;
  • the test list.

Depends on: #291. This branch is rebased onto #291's merge candidate, Ryx69#6 (70178d3: #291 merged with main at 426023a), plus one commit, ec72ca0. Only that commit is this PR's. Against today's main (c0ac5fd), this branch conflicts only where the candidate itself does: d3d12_vulkan_device.cpp and vulkan_replay.h. It also overlaps #469 in four files: d3d12_vulkan_device.cpp, vulkan_replay.h, CMakeLists.txt and the doc. I'll rebase again once #291 lands.

Tested

Windows 11 Pro 26300, MSVC 19.44, Vulkan SDK 1.4.363.0, CMake + Ninja.

After the rebase onto 70178d3 (same GPUs and drivers as below):

  • Build: clean at /W4, no warnings.
  • ctest: 61 of 62 pass. The failure is d3d12_sampler2, which fails on main (e7584c5) too, on both GPUs: the host runtime reports no non-normalized samplers, so its answers differ from the layer's.
  • RTX 3050, with LEONIDA_VK_VALIDATION=1:
    • d3d12_restart_test: every case matches.
    • d3d12_draw_test and d3d12_state_map_test pass.
    • 0 validation errors.
  • Radeon 680M, with validation:

The results below are from the pre-rebase head (3e94617):

  • Build: clean at /W4, no warnings. ctest: 15/15 pass.

  • d3d12_state_map_test (CPU, so it runs in CI) checks when restart is on: every strip and list topology against both index types and each cut value.

  • New d3d12_restart_test: every draw goes through the Xbox-ABI proxy and is read back.

    • Each case draws two quads with a cut-valued index between them. An index that does not cut becomes a vertex between the quads, so an uncut strip bridges them.
    • Triangles are checked pixel by pixel: cut means exactly the two quads; drawn means the quads plus a pixel between them. Lines are checked by which columns they reach.
    • 14 cases cover every draw row of the table except the line list (the triangle lists test that rule), plus a check that an invalid cut value is refused.
  • NVIDIA GeForce RTX 3050 Laptop GPU (D3D12 driver 32.0.16.2101, Vulkan 621.01): all 14 cases pass with LEONIDA_VK_VALIDATION=1, with 0 validation errors. d3d12_draw_test, d3d12_compute_test, d3d12_vulkan_device_test, d3d12_descriptor_test, d3d12_present_test and vk_command_replay_test also pass under validation.

  • AMD Radeon 680M (D3D12 driver 31.0.14084.6002, Vulkan 22.40.84.06, selected with VK_LOADER_DRIVERS_SELECT=amd-vulkan64.json):

  • Mutation check. I made six wrong versions in a scratch build, and the tests failed every one:

    Wrong version What failed
    restart never on the 4 cut cases and the CPU check
    restart for any cut value, whatever the format the 2 mismatched-format cases and the CPU check
    lists restart too the 2 list cases, the CPU check, and a validation error (list restart without the feature)
    0xFFFFFFFF stored as 0xFFFF 3 cases
    an invalid cut value accepted the E_INVALIDARG check
    the old stride state 11 validation errors (VUID-vkCmdDraw-pStrides-04913)

AI-assisted (Claude Code, Claude Opus 5.5).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The test shaders are GLSL written for this test.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)

🤖 Generated with Claude Code

@rafaelpssz

Copy link
Copy Markdown
Contributor

Tested 3e94617 on Windows 11, RTX 3060 (NVIDIA 616.64), clang-cl 23 + lld-link with the MSVC 14.44 CRT and Windows SDK 10.0.26100 (no MSVC compiler): pass for the CPU and existing GPU tests; d3d12_restart_test not run.

  • Built the PR head as-is, which is Runtime: compute path and graphics draws on Vulkan (D3D-3, D3D-4, milestone M1) #291's b18aedf plus 3e94617. It conflicts with main, as expected until Runtime: compute path and graphics draws on Vulkan (D3D-3, D3D-4, milestone M1) #291 lands.
  • ctest: 15/15.
  • d3d12_state_map_test: "... memory types and primitive restart OK". Mutation check: with primitive_restart() reduced to strip_cut != 0, it fails at line 337 (!primitive_restart(0xFFFFFFFF, VK_INDEX_TYPE_UINT16, strip)), so the test covers the index-width rule.
  • On the RTX 3060: d3d12_vulkan_device_test, d3d12_present_test (70 frames), vk_command_replay_test, d3d12_descriptor_test and d3d12_com_test all exit 0.
  • Not run: d3d12_restart_test, d3d12_draw_test, d3d12_compute_test (no glslangValidator here), and no Vulkan validation layer on this machine, so the VUID-vkCmdDraw-pStrides-04913 fix isn't confirmed under validation. An NVIDIA desktop run of d3d12_restart_test with LEONIDA_VK_VALIDATION=1 is still open.
  • Read the diff (primitive_restart()/emit() in vulkan_replay.h, the IBStripCutValue switch and dynamic states): strip_cut is per PSO, the device already requires Vulkan 1.3 for the dynamic restart state, vulkan_backend.h is the only ReplayFunctions initializer and sets the new pointer, and list topologies never enable restart. No problems found.

Ryx69 added 10 commits November 22, 2026 04:54
- vulkan_present.h: VulkanPresenter blits a back buffer (an ordinary texture
  in D3D12's PRESENT state, layout tracked like any other) to an acquired
  swapchain image and presents it on the same VkQueue, after the
  application's work. Two frames in flight, a present semaphore per image,
  FIFO for vsync else MAILBOX/IMMEDIATE, swapchain recreated on resize or
  out-of-date/suboptimal, minimised windows skip presents.
- rt::d3d12::create_window_presenter / WindowPresenter: Win32 surface for a
  Vulkan device created with presentation; holds the device. This is the back
  end a DXGI shim or PresentX would call; the game's own front end is still
  open (docs question 6), so neither is invented here.
- Standalone device enables VK_KHR_surface/win32_surface and VK_KHR_swapchain
  when present; the test helper can too.

Test: d3d12_present_test opens a window and presents 60 frames through the
Xbox-ABI proxy (reset, PRESENT->RENDER_TARGET, clear, ->PRESENT, execute,
present, fence), resizes the window (swapchain recreated, scaled blit),
switches to unsynchronised presents, and reads the screen with GDI:
51,153,229 for a 51,153,230 clear. Clean under the Khronos validation layer,
as are the other GPU tests; 6/6 ctest.
The debug messenger in test/vk_test_device.h counted every error-severity
message, so a broken third-party implicit layer (ReShade's, reported on an
RTX 5090) failed every GPU test. Only VALIDATION-type errors are counted now;
general loader and layer messages are still printed, marked "not counted".
A real validation error still fails the test (checked by replaying part B of
vk_command_replay_test without the layout tracker). runtime/README.md says
so and mentions VK_LOADER_LAYERS_DISABLE.
…s only shown frames (review)

From VictorJulianiR's review of the presenter, with Vonsek's measurements:
- A failed blit submission left the frame's fence reset with nothing to signal it, so the next present waited
  forever (Vonsek: the retry reached vkWaitForFences with UINT64_MAX). An empty batch now takes the acquire
  semaphore and signals the fence, and the swapchain is recreated next time to give back the image that was
  never presented. If that batch fails too, or a fence wait or reset fails, the presenter stops (ok() is
  false). A back buffer the device does not know is refused before an image is acquired for it.
- A swapchain recreation published the new swapchain before its per-image semaphores existed, so a failed
  semaphore left a presenter that could submit with a null one. The images and semaphores are now built in
  local storage and published only when all exist; on a failure the partial objects are released and the next
  present tries again.
- An out-of-date present was counted as presented (Vonsek: 69 VK_SUCCESS and one VK_ERROR_OUT_OF_DATE_KHR
  reached 70). presented() now counts VK_SUCCESS and VK_SUBOPTIMAL_KHR only; the caller still gets VK_SUCCESS.

d3d12_present_test gives the device and presenter their functions through a driver double that forwards to the
real driver. It counts real out-of-date presents (the frame counts allow for them) and live binary semaphores.
It reports one present as out of date and one as suboptimal, fails the second semaphore of a recreation, and
fails one blit submission. Against the old presenter the test fails at the frame count after the resize, where
this RTX 5060 Ti reported a real out-of-date present.

Docs: the presenter is named as leonida::VulkanPresenter, made by rt::d3d12::create_window_presenter, and the
test is described as 60 frames then 10 after a resize (AlxcBTW).
First pieces of D3D-3 (compute path), no pipelines wired up yet:
- shader_library.h: FSSM extraction from the DXBC container (DXIL, XDAT
  0x0D, XBCH, zlib), SHA-256, a minimal JSON reader and the
  spirv/index.json lookup by fssm_sha256. Self-contained inflate, no
  dependencies.
- IR Dispatch with user data captured at record time; replay binds the
  pipeline, pushes the 144-byte block (s0..s31, heap base, code base) and
  dispatches. Arena buffers get a buffer_offset that copies honour.
- Root signatures use main's model (runtime/src/root_signature.h); the docs
  say so.

Tests: shader_library_test (FIPS 180-4 vectors; stored, fixed and dynamic
deflate blocks; corrupt and truncated streams; FSSM from a synthetic
container) joins ctest; command_list_test covers dispatch recording.
… compute PSOs, Dispatch)

- GPU address arena (docs 3.3), when the device has bufferDeviceAddress: one
  host-visible, device-addressable buffer (LEONIDA_ARENA_MB, default 256,
  max 4095 so VAs fit 32-bit table pointers). Default-heap buffers are
  64 KiB-aligned ranges with VA = offset, zeroed through the mapping;
  shader-visible descriptor heaps live there (CPU handle = mapping, GPU
  handle = VA); upload/readback buffers get VA = device address - heap
  base; GetGPUVirtualAddress returns these.
- CreateRootSignature on main's model (rt::rootsig): parse_rts0, then
  pack() for each parameter's place in the 32 user-data dwords; what pack()
  refuses is refused with its reason. CreateComputePipelineState (PC slot
  11, Xbox slot 62 via the proxy) finds the shader by the SHA-256 of its
  FSSM program in the translator's index (VulkanDeviceInfo::shader_dir or
  LEONIDA_SHADERS); its FSSM blob is copied into the arena as the code base.
  Shaders that declare set-0 bindings are refused with a log until the
  bindless set exists (M2).
- Command list: root signatures (arguments cleared on change), pipeline
  state, constant / root view / descriptor-table setters for compute and
  graphics, SetDescriptorHeaps, Dispatch recording the user data as it is,
  ClearState (which also resets ItsNotRexed#164's stencil references); misuse makes
  Close return E_INVALIDARG.
- Test helper and standalone device enable bufferDeviceAddress.

Test: d3d12_compute_test (through the proxy) creates the root signature
from the PC serializer's blob and the PSO through slot 62 in the measured
(desc, 0, 0, riid, out) shape (28cf235) from a container shaped like the
game's, sets root constants, a root UAV and a table whose
application-written entry points at an upload buffer, runs two dispatches
that each keep their own arguments, and reads the results back: 64/64
twice. Its shader is GLSL written to the translator's push-constant and
address contract, compiled with glslangValidator. Clean under the Khronos
validation layer, as are the other GPU tests; 13/13 ctest.
- CreateGraphicsPipelineState (PC slot 10): VS and PS found by the SHA-256
  of their FSSM programs in the translator's index. Input-layout elements are
  matched to the VS input signature by semantic name and index; location =
  the element's register (the translator's vertex-fetch rule); a layout that
  leaves an input unfed is refused, as D3D12 does. Rasterizer, blend and
  depth-stencil state map one to one; viewport, scissor, topology, vertex
  strides, stencil references and blend factor are dynamic; dynamic
  rendering takes the RTV/DSV formats. Hull/domain/geometry, stream output,
  MSAA, set-0 bindings and two code-base stages (question 14) are refused
  with a log.
- Command list: IASetPrimitiveTopology / VertexBuffers / IndexBuffer,
  RSSetViewports / ScissorRects (first of each), OMSetRenderTargets (views
  read at the call, single-range handles too), OMSetBlendFactor,
  OMSetStencilRef and CommandList8's front/back references (now applied),
  DrawInstanced / DrawIndexedInstanced recording a copy of that state.
  CreateCommandList's initial pipeline state is applied. Reset and
  ClearState share one state reset.
- Replay: vertex/index views resolve to buffers by VA (arena or upload),
  attachments move to attachment layouts through the tracker (first use
  zero-fills), the draw runs in a dynamic-rendering scope with a flipped
  viewport (translated VS write D3D clip coordinates), stencil references
  per face, then vkCmdDraw / vkCmdDrawIndexed. Render-target views take the
  pipeline's formats (the view cache keys on format).
- shader_library.h reads the index's input_signature and PS outputs.

Test: d3d12_draw_test (through the proxy) builds a VS+PS PSO whose input
layout order differs from the VS registers, uploads a vertex buffer into the
arena, reads indices from an upload heap, and draws two indexed quads with
different root constants and root CBVs plus a back-facing triangle: all 4096
read-back pixels match (which also checks the viewport flip and winding).
Shaders are GLSL written to the translator's contract. d3d12_com_test now
uses SetMarker as its unimplemented-method example, since DrawInstanced is
implemented. 13/13 ctest; all six GPU tests clean under the Khronos
validation layer.
…n (arena without Resizable BAR)

Without Resizable BAR the only DEVICE_LOCAL | HOST_VISIBLE memory type sits in a heap of 256 MiB or less
(214 MiB on an RTX 3090, driver 616.56). The 256 MiB default arena preferred that type, so vkAllocateMemory
was asked for more than the heap holds (VUID-vkAllocateMemory-pAllocateInfo-01713). The NVIDIA driver still
returned VK_SUCCESS, so the fallback to plain host-visible memory never ran, and d3d12_compute_test and
d3d12_draw_test failed under validation. Reported by CharlyRien.

memory_type_order (vulkan_backend.h) now leaves out every type whose heap is smaller than the allocation,
so the preference falls through to system memory there. DeviceState::allocate uses it for every allocation.
d3d12_state_map_test checks the order on that card's heap layout and with Resizable BAR on.
… stages from the stage table

Review feedback from IAmNotSiob:
- Both PSO paths declared a 144-byte push-constant range without consulting ItsNotRexed#224's limit. On a device with
  maxPushConstantsSize 128 (the Vulkan minimum) that breaks VUID-VkPushConstantRange-size-00298 and returns a
  bare E_FAIL. Both paths now refuse with E_NOTIMPL and log the limit until the uniform-buffer tail exists.
  d3d12_compute_test checks this with a device that reports 128 bytes.
- The graphics range's stage flags are now the whole stage table create_graphics accepts, kept in
  GraphicsPipeline::push_stages, and the replay pushes with the same flags. A geometry or mesh stage added to
  the table is covered without another change.

docs/d3d12_vulkan.md section 5.2 now counts code-base readers per stage with the current translator: of the 662
shaders with s_getpc_b64, 53 VS, 92 PS, 246 MS and 263 CS read the code base. VS+PS pairs are only known at
PSO creation.
Shader library
- fssm_program takes the last XDAT 0x0D payload, as tools/fssm_unpack.py does by default (195 of 26,503
  containers have two different ones, and fssm_sha256 is computed from the last).
- The JSON reader parses numbers with from_chars and \u escapes as exactly four hex digits, so a malformed
  index is refused instead of throwing into the shim. Integer fields outside 0..2^32-1 read as 0.
- Index entries that share a program are all kept; CreateGraphicsPipelineState takes the VS whose input
  signature the input layout feeds.

Command list
- Setting the root signature that is already bound keeps the root arguments, as D3D12 does.
- A draw with no viewport (never set, or RSSetViewports(0, ...)) or an empty one is not recorded: D3D12
  rasterizes nothing and Vulkan forbids a 0x0 viewport.
- More than eight render targets is an invalid call, in OMSetRenderTargets and in a PSO.

Device
- Buffers of 0 bytes, or with a size that wraps when aligned, are E_INVALIDARG. The arena refuses zero-size
  ranges, and its fit test cannot wrap.
- A shader-visible descriptor heap the arena cannot hold is E_OUTOFMEMORY instead of a host heap with GPU
  handle 0.
- A failed arena releases its buffer and memory, so other buffers do not get raw device addresses as VAs.
- Graphics PSOs that need independentBlend, fillModeNonSolid, depthBiasClamp or dualSrcBlend are refused
  unless VulkanDeviceInfo::features has them. The standalone device enables those the GPU supports.
- A draw that leaves a slot unbound where the PSO names a format uses a pipeline variant with that format
  undefined (built on first use, kept with the PSO), instead of breaking
  dynamicRenderingUnusedAttachments-08912.
- Instance step rate 0 reads element 0 for every instance (stride 0 at draw time).
- The Vulkan 1.0 graphics entry points are required; the 1.3 ones are checked before a graphics PSO is made.

Replay
- An unbound vertex slot, or an indexed draw with no index buffer, reads the arena's reserved first 64 KiB,
  which is kept zero, as D3D12 reads zeros. A view that runs past its buffer is cut at the buffer's end
  instead of failing the whole ExecuteCommandLists.
- The rendering layer count is the smallest layer count of the bound views.

Tests: shader_library_test covers two payloads, malformed JSON and duplicate programs. d3d12_draw_test
covers an unbound RT and DSV, a rebound root signature, step rate 0, an unbound vertex slot, a draw with no
viewport, the feature and count refusals, and bad buffer and heap sizes. Each of the rebind, step-rate and
variant fixes, undone on its own, makes the test fail.

Still open, documented: instance step rates above 1, read-only DSV layouts, and the index buffer's view size.
…rs after the rebase onto main

From the reviews and test runs on ItsNotRexed#291:
- A pipeline without vertex bindings (a full-screen pass from SV_VertexID) no longer declares the vertex-stride
  dynamic state, which nothing would set (VUID-vkCmdDraw-pStrides-04913; aslan2142, AlxcBTW, ezwinxdlmao).
- Logic ops are applied from RenderTarget[0] instead of being logged and ignored (Vonsek's XOR case), and
  DepthClipEnable = FALSE is depth clamping (AlxcBTW). Both need their feature (logicOp, depthClamp), or the
  PSO is refused.
- The standalone device also enables shaderInt64, shaderFloat64, shaderInt16, shaderClipDistance and
  shaderCullDistance where the GPU has them (AlxcBTW, whattheflop: VUID-...-pCode-08740), plus logicOp and
  depthClamp.
- Among index entries for one program, a PSO takes the first that fits and declares no set-0 bindings, as
  pipelines do not bind set 0 yet. This covers the compute group in poke900310's corpus count, where an entry
  with 10 bindings shadowed a binding-free one.
- The command list holds a reference to every root signature and pipeline state it is given until Reset or
  its release, so releasing them right after Set* (as D3D12 allows) no longer leaves dangling layouts or drops
  the submission (AlxcBTW).

After the rebase onto main: main's SetPredication reads the predicate through the resource's VkBuffer, so a
default-heap buffer (a range of the GPU address arena) adds its offset in the arena, and the arena gets the
conditional-rendering usage when the extension is on (lahlousaad4's integration note).

Tests: d3d12_draw_test has a second pass with a full-screen triangle first in its submission and an XOR quad,
and a depth-clamp refusal. d3d12_compute_test releases its root signature and PSO right after setting them,
sets the signature again after the arguments, and has a bound entry ahead of the binding-free one in its
index. Each new fix, undone on its own, fails a test: pStrides-04913, wrong XOR pixels, a heap-corruption
crash without the hold, a refused PSO without the binding-free choice.

Documented as known gaps, not fixed here: wave64 subgroup size (AlxcBTW's follow-up in ItsNotRexed#313), cross-queue
waits on one VkQueue and CPU fence signals below a pending GPU signal (woreksami), and the linear buffer_at.
Resolved along the lines in ItsNotRexed#291 (comment by ItsNotRexed, 2026-11-22 08:27):

- Default-heap buffers stay in the GPU address arena: a VA is an arena offset,
  and every buffer's device address is heap_base + VA (upload and readback
  buffers: device address minus heap_base, as before).
- Acceleration structures: a buffer created in RAYTRACING_ACCELERATION_STRUCTURE
  state on a ray-tracing device stays out of the arena and keeps main's model,
  its VA being the VkAccelerationStructureKHR's device address, so BLAS
  addresses in TLAS instance descriptions are what Vulkan reads. It is
  registered by that VA. BuildRaytracingAccelerationStructure turns build
  inputs and scratch into heap_base + VA, and the arena gets the build-input
  usage on ray-tracing devices. Resource keeps one va_ (gpu_va_/buffer_va_
  removed).
- buffer_at keeps the size& signature; main's only caller (WriteBufferImmediate)
  is the branch's version, and ExecuteIndirect resolves its buffers by id.
- ~Resource keeps arena_release and main's defer_destroy.
- Main's split context locks: pipeline registration and heap_base/zero page
  take resource_mutex_ (prepare looks pipelines up under its shared lock);
  VulkanPresenter takes resource_mutex_ shared, plus tracker_mutex_ while it
  records the back buffer's transition.
- Standalone device: main's single instance-extension list and DXGI swapchain
  enable; info.presentation follows the same swapchain/surface condition, so
  create_window_presenter keeps working. Main's DeferredDeletionQueue,
  calibrated timestamps and ray-tracing extensions are kept next to the
  branch's presentation and feature enables.
- Command IR: Dispatch and Draw follow main's DebugMarker, ExecuteIndirect and
  BuildAccelerationStructure in the variant.
@evilclanker9000

Copy link
Copy Markdown
Contributor

I checked index-view changes within one command list on 3e94617620329bc1faf7441ce55931e376b8cc01. The stock d3d12_restart_test passed on Windows RTX 5080 and AMD Radeon Graphics. For the additional draw I kept one triangle-strip PSO with IBStripCutValue=0xFFFF, one render target and the stock VS/PS. Three indexed draws with scissors covering rows [0,20), [20,44), [44,64) bound R16 → R32 → R16. Each view contained indices 0–3, its own all-ones index, then 4–7. The middle draw therefore had to turn restart off even though the PSO never changed.

An independent CPU triangle rasterization using pixel centres and the top-left rule predicted 1,824 opaque green pixels. All 4,096 RGBA pixels matched on both GPUs. In the negative control I changed only the middle index view to the first R16 view: its bridge disappeared and exactly 288 formerly green pixels became clear, leaving 1,536 green. All four readbacks matched with validation enabled. Source-built fixture; AI-assisted verification.

D3D12 cuts an indexed strip where an index equals the PSO's
IBStripCutValue. Vulkan restarts where an index is all ones for its type.
- The PSO keeps the cut value. A value outside the enum is refused with
  E_INVALIDARG, as the host runtime refuses it.
- Primitive restart is dynamic in every graphics pipeline. Replay sets it
  at each draw: on for an indexed strip (line or triangle, with or without
  adjacency) whose cut value is Vulkan's restart index for the bound
  format, otherwise off.

The rules come from the host PC D3D12 runtime, measured with the same
geometry on a Radeon 680M, an RTX 3050 Laptop GPU and WARP. All three cut
only where an index equals the cut value: 0xFFFFFFFF never cuts 16-bit
indices, and 0xFFFF leaves a 32-bit 0xFFFFFFFF uncut. Draws without an
index buffer are never cut.

Two cases cannot follow every driver:
- 0xFFFF with 32-bit indices: D3D12 cuts at 0x0000FFFF, which Vulkan
  cannot express. It is drawn uncut.
- Lists: AMD's driver draws the cut index as a vertex, while NVIDIA's and
  WARP end the list (D3D11.3 functional spec 8.12). Lists never restart
  here, as on AMD and in vkd3d-proton.

Tests:
- d3d12_restart_test: 14 cases through the proxy, read back. Triangle and
  line strips with 16-bit and 32-bit indices, each cut value and none, the
  mismatched pairings, lists, and a draw without an index buffer.
- d3d12_state_map_test checks when restart is on, for every topology.
- docs/d3d12_vulkan.md describes the mapping and the two gaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ezwinxdlmao
ezwinxdlmao force-pushed the d3d-primitive-restart branch from 3e94617 to ec72ca0 Compare November 22, 2026 09:56
@ezwinxdlmao

Copy link
Copy Markdown
Contributor Author

Rebased onto #291's merge candidate, Ryx69#6 (70178d3), as asked. The commit is now ec72ca0. Against today's main, the branch conflicts only in the two files the candidate itself conflicts in. The candidate has the vertex-stride fix, so I dropped this PR's copy.

With validation on, d3d12_restart_test passes every case on the RTX 3050 with 0 validation errors. On the 680M it checks the PSO refusal (#224). The description has the details.

@evilclanker9000

Copy link
Copy Markdown
Contributor

I checked the order of index-strip restart and signed base-vertex adjustment on the rebased head ec72ca0a59f08254d5fb044cccbdece79548e9f5. The source-built test used a single R16 indexed triangle-strip PSO (IBStripCutValue=0xFFFF). In each draw I changed only the index separating the two quads for the control.

BaseVertexLocation Ordinary raw indices Separator Green pixels / 4,096
−32,768 32,769–32,776 0xffff 1,536
−32,768 32,769–32,776 0xfffe 1,920
+1 0–7 0xffff 1,536
+1 0–7 0xfffe 1,920

The last row distinguishes the ordering: 0xfffe + 1 equals 65,535, yet that vertex reaches the shader and forms a bridge. Conversely, the raw 0xffff marker cuts the strip even with the negative base. The VS assigns the ordinary post-offset indices 1–8 to the eight known corners and all other values to the middle. I compared every RGBA pixel against a separate CPU triangle rasterizer using pixel centers and the top-left rule. All four frames matched on both RTX 5080 (616.92) and integrated Radeon (26.10.1), Windows 11 26200, with validation enabled. This tests the matched R16 restart path.

@Flyander

Copy link
Copy Markdown
Contributor

Coordination check: the new open #1583 implements the same D3D-57 / IBStripCutValue primitive-restart behavior on post-#291 main. Your PR is the older stacked implementation and has the broader restart matrix; #1583 is a small rebased candidate with a new draw test. Please coordinate which is canonical and port unique coverage so both branches don't carry the same runtime fix.

@ezwinxdlmao

Copy link
Copy Markdown
Contributor Author

Closing as superseded: main now has the same behaviour from 432d9ab ("support IBStripCutValue via dynamic primitive restart"): restart is dynamic state, enabled only for indexed strip topologies when the cut value is all ones for the bound index type, which is the rule this PR implemented. Nothing left to rebase. The branch stays on the fork if the separate d3d12_restart_test coverage is wanted later. 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.

6 participants