Skip to content

d3d12: refuse command signatures with arguments before the draw (D3D-INDIRECT-STATE-REFUSE) - #1737

Open
potatoe0100 wants to merge 1 commit into
ProjectLeonida:mainfrom
potatoe0100:d3d12-indirect-state-refuse
Open

potatoe0100 wants to merge 1 commit into
ProjectLeonida:mainfrom
potatoe0100:d3d12-indirect-state-refuse

Conversation

@potatoe0100

@potatoe0100 potatoe0100 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-INDIRECT-STATE-REFUSE

Depends on: none. #1620 (INDIRECT-STATE-ARGS) touches the same function; whichever lands second drops the VERTEX/INDEX_BUFFER_VIEW part of this refusal once those arguments are replayed.

What and why

On main, CreateCommandSignature accepts a valid signature that puts arguments before its draw or dispatch (root constants, root CBV/SRV/UAV, vertex and index buffer views). But the CommandSignature object keeps only its kind and stride, and ExecuteIndirect reads the draw arguments at the start of each record. So [VERTEX_BUFFER_VIEW, DRAW] or [CONSTANT, DRAW] was accepted and then drew with the state argument's bytes as its vertex and instance counts, with no message.

Until per-command state is replayed (section 4.7 of docs/d3d12_vulkan.md), CreateCommandSignature now answers E_NOTIMPL for a signature with more than one argument, and logs it once per first argument type, the way other unimplemented features are refused. Invalid descriptions are still E_INVALIDARG as on the host, since the checks run first. One-argument signatures are unchanged, and the title's five startup signatures (section 4.9) each have one argument.

  • runtime/shims/d3d12_vulkan_device.cpp: the refusal.
  • runtime/test/d3d12_execute_indirect_validation_test.cpp: a layer-only check that eight such shapes (VBV+draw, IBV+draw indexed, constant+draw, constant+dispatch, CBV+draw, SRV+draw indexed, UAV+dispatch, VBV+constant+draw) are refused with no object, that their invalid neighbours (no root signature, short stride) stay E_INVALIDARG, and that a one-argument signature with a root signature is still created.
  • docs/d3d12_vulkan.md section 4.7: says so.

Tested

Built with VS 2022 Build Tools (MSVC 19.44), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, RelWithDebInfo, on main 57ba40bd6. No game files.

  • ctest -R ^d3d12_execute_indirect_validation$ with LEONIDA_VK_VALIDATION=1: passes (state-argument signatures: 8 shapes refused with E_NOTIMPL; 51 parity cases against live WARP and the RTX 4060, 0 validation errors). With only the shim change reverted, it fails at the first shape: hr=0x00000000, object created.
  • Full ctest -j 6: 384 of 384 passed, 13 skipped (game-data and optional tests).

GPUs tested: NVIDIA GeForce RTX 4060, driver 621.14, Windows 11 Pro build 26300

AI-assisted: yes (Claude Code). Posted by a non-developer tester.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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: D3D12 layer, no translator change)

🤖 Generated with Claude Code

…INDIRECT-STATE-REFUSE)

A CommandSignature keeps only its kind and stride, and ExecuteIndirect reads
the draw or dispatch arguments at the start of each record. A valid signature
that puts root constants, root views or vertex/index buffer views first was
accepted, so its draws read those bytes as their counts. Until per-command
state is replayed, CreateCommandSignature answers E_NOTIMPL for a signature
with more than one argument and logs it once per first argument type.
Invalid descriptions are still E_INVALIDARG. One-argument signatures, which
are all the title creates at startup, are unchanged.

d3d12_execute_indirect_validation checks eight such shapes are refused with
no object, that the invalid neighbours stay E_INVALIDARG, and that a
one-argument signature with a root signature is still created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean-Room & Technical Verification

  • Mergeability: 3-way merge against upstream main (bcaa13dad) is 100% clean with zero merge conflicts.
  • Clean-Room Compliance: 100% clean-room. D3D12 command signature validation logic and synthetic layer tests only; zero retail files, game data, or keys (check_no_game_data.py clean).
  • Technical Correctness & Behavioral Parity:
    • CreateCommandSignature currently preserves only kind and stride, and ExecuteIndirect consumes draw/dispatch arguments at offset 0 of each record.
    • Signatures with leading state arguments (VERTEX_BUFFER_VIEW, INDEX_BUFFER_VIEW, CONSTANT, CBV, SRV, UAV) were previously accepted, causing indirect draws to misinterpret state arguments as vertex/instance counts.
    • Refusing multi-argument command signatures with E_NOTIMPL and rate-limited logging (log_once) maintains strict conformance until per-command state replay lands (docs/d3d12_vulkan.md §4.7), while preserving standard E_INVALIDARG validation on malformed inputs and leaving single-argument startup signatures intact.
    • Verified across 8 distinct argument shapes in runtime/test/d3d12_execute_indirect_validation_test.cpp.

LGTM! Approved.

@Tyrannys

Copy link
Copy Markdown
Contributor

Independent verification of head cc642e6a4b0c080b2eb2618c26a019feaf56c268, with current main (a73a57e13) merged in. The merge conflicts only in docs/d3d12_vulkan.md (I took main's side for the test build); the code merges cleanly.

Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo.

Result: not ready. This confirms the finding fiestorra posted in #1608 (comment): main now implements arguments before the draw (stateful indirect), and this PR's NumArgumentDescs > 1 refusal turns that off.

  • Full suite with the PR: 469/477 pass. 6 new failures, all at indirect pixels line 117: SUCCEEDED(device->CreateCommandSignature(...)), log CreateCommandSignature refused (not implemented): arguments before the draw or dispatch, first argument type 3:
    d3d12_stateful_indirect_pixels, _multi_pixels, _counted_pixels, _nonindexed_pixels, _nonindexed_multi_pixels, _nonindexed_counted_pixels.
  • Plain main on the same machine: 475/477; the other two failures (xbox_present, d3d12_set_descriptor_heaps) fail there too.
  • The PR's own d3d12_execute_indirect_validation passes.

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

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 26, 2026
@fiestorra

Copy link
Copy Markdown
Contributor

A measurement your guard needs: with it, the replay PR's six tests fail; narrowed to dispatch, they pass

I built the runtime on Windows (MSVC 14.44.35207, CMake + Ninja, Vulkan SDK 1.4.363.0, RTX 4090) and ran the tests against a merge of main d1dff794 + this PR cc642e6a4 + #1937 3d1dadbd:

tree ctest -R '^d3d12_stateful_indirect' (6) d3d12_execute_indirect_validation
main + this PR + #1937 0/6, all failed passed
the same merge, guard narrowed to compound dispatch 6/6 passed failed at (vertex buffer view, draw): hr=0x00000000, object created

The middle row fails with your guard's own line:

[rt] d3d12: CreateCommandSignature refused (not implemented): arguments before the draw or dispatch, first argument type 3
indirect pixels line 127: SUCCEEDED(device->CreateCommandSignature(&sd, nullptr, IID_PPV_ARGS(&sig.p)))

type 3 is VERTEX_BUFFER_VIEW: #1937 replays exactly the draw shapes this refuses, so the two cannot both land. Your reasoning — "accepted, their bytes would be read as the draw's arguments" — is right for main and stops being true once the replay is in.

The narrowing that keeps your guard where it still has work to do is to refuse only the dispatch shapes, which have no replay behind them:

if (desc->NumArgumentDescs > 1) {
    const D3D12_INDIRECT_ARGUMENT_TYPE last = desc->pArgumentDescs[desc->NumArgumentDescs - 1].Type;
    if (last != D3D12_INDIRECT_ARGUMENT_TYPE_DRAW && last != D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED) {
        log_once("CreateCommandSignature refused (not implemented): arguments before a dispatch, "
                 "first argument type", int(desc->pArgumentDescs[0].Type));
        return E_NOTIMPL;
    }
}

That changes refuses_state_arguments: the six graphics shapes are created (and covered by the six d3d12_stateful_indirect* tests), while {constant, dispatch} and {UAV, dispatch} still come back E_NOTIMPL with no object. E_INVALIDARG for a root argument with no root signature and for a stride that cannot hold the record is untouched, and still checked before the refusal — that part passed in every tree I built.

The build is reproducible: candidate/1937-1737-narrowed (5a6b4bb1) on fiestorra/leonida-carry, main + this PR + #1937 + the narrowing. I have not pushed anything onto your branch; if you want the narrowing there, say so and I will put it on top of cc642e6a4 with the test flipped.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor

The complete matrix for the shapes your guard refuses, and what the replay does with each

Same machine as above (MSVC 14.44.35207, Vulkan SDK 1.4.363.0, RTX 4090), four trees from main d1dff794. Your refuses_state_arguments shapes, printed instead of asserted:

shape main main+#1737 main+#1937 both, refusal narrowed to dispatch
{VBV, DRAW} created E_NOTIMPL created created
{IBV, DRAW_INDEXED} created E_NOTIMPL created created
{CONSTANT, DRAW} created E_NOTIMPL created created
{VBV, CONSTANT, DRAW} created E_NOTIMPL created created
{CBV, DRAW} created E_NOTIMPL created created
{SRV, DRAW_INDEXED} created E_NOTIMPL created created
{CONSTANT, DISPATCH} created E_NOTIMPL created E_NOTIMPL
{UAV, DISPATCH} created E_NOTIMPL created E_NOTIMPL

And the point that decides it: the replay decodes every one of the six graphics shapes — VERTEX_BUFFER_VIEW, INDEX_BUFFER_VIEW, CONSTANT_BUFFER_VIEW, SHADER_RESOURCE_VIEW, UNORDERED_ACCESS_VIEW, CONSTANT, plus the incrementing constant — so with the narrowing nothing is accepted and then silently dropped. The replay skips only for reasons that are not about the signature: no pipeline or topology, an unmappable argument or count buffer, a vertex-buffer slot outside the bound ones, and a CONSTANT outside D3D12_MAX_ROOT_COST. The two dispatch shapes are the only ones with no replay behind them, and they are the ones the narrowed guard keeps refusing.

Execution, with #1937's own test file in every tree (its file, not main's weaker one):

Full ctest on the narrowed candidate: 491 tests, 489 passed, 2 failed (xbox_present, d3d12_set_descriptor_heaps), and both fail the same way on main and on #1937 alone here — this machine's, not either branch's.

What is still untested, so nobody reads more into this than it says: {CONSTANT, DRAW}, {CBV, DRAW}, {SRV, DRAW_INDEXED} and {VBV, CONSTANT, DRAW} are created and decoded but no test draws through them. The table is creation-time evidence for those four.

Written with an AI assistant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants