Skip to content

D3D-448: use compute root offsets for ExecuteIndirect dispatch - #5105

Draft
editrice wants to merge 26 commits into
ItsNotRexed:mainfrom
editrice:d3d-448-indirect-compute-offset
Draft

editrice wants to merge 26 commits into
ItsNotRexed:mainfrom
editrice:d3d-448-indirect-compute-offset

Conversation

@editrice

@editrice editrice commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: D3D-448, #4933 (comment 7094567788).

Dependency: #2077 remains draft and must be reconciled with current main before this PR can be unstacked. #4312 (7c225260) has merged. This draft retains #2077's reviewed head (91ba3847) so the four-file ExecuteIndirect follow-up can be tested; once #2077 lands, I will reduce this to its single fix commit and rerun the focused tests.

What and why

build_indirect_signature used graphics user_offset for root arguments even when ExecuteIndirect ended with DISPATCH. With #4312's per-stage root layout, compute constants and root views can occupy different offsets. A synthetic pre-fix indirect dispatch left its output at zero where the CPU oracle expected 0x0055aa01 and subsequent values; direct dispatch passed.

Select compute_offset/compute_ok for DISPATCH, keep user_offset/graphics_ok for draw actions, and reject kNoSgpr or out-of-range offsets before narrowing. Add synthetic constant-subrange, CBV/SRV/UAV, graphics-versus-compute, overflow-sentinel, and native command-signature parity cases.

Tested

Windows 11, NVIDIA RTX 5070, driver 621.01, validation enabled: focused CTest suite 5/5 (root_signature, d3d12_indirect_multiarg, d3d12_m4_compute, d3d12_indirect_rt, d3d12_compute). In d3d12_indirect_multiarg_test, 15 drawn cells and 13 dispatched groups matched the CPU oracle with error 0; 34 CreateCommandSignature cases agreed with native D3D12. tests/test_compute_fixture_shift.py: 8/8. git diff --check: clean.

AI-assisted: yes.

Checklist

  • No game data, keys or decryption, including in logs or reports quoted here.
  • Public fixtures are synthetic.

AlxcBTW and others added 25 commits November 22, 2026 15:41
…ad recording, 5120-SRV table, pipeline cache)

Test d3d12_m5_world_test (D3D12 API only, translator-output shaders, every pixel against a CPU reference):
(a) five ExecuteIndirect calls (DRAW and DRAW_INDEXED signatures, CPU- and GPU-written records at offsets in
placed buffers, count buffer, count 0, count above MaxCommandCount), (b) four threads recording four lists run in
one ExecuteCommandLists, eight rounds, (c) a descriptor table of 5120 SRVs of distinct textures read at a byte
offset from a root constant, (d) a PSO created twice through the device's VkPipelineCache.

Layer gaps fixed on the way:
- ExecuteIndirect draws carry the list's graphics state and replay as whole draws; they used to replay as a bare
  vkCmdDraw*Indirect outside any render pass with no pipeline bound.
- multiDrawIndirect, drawIndirectCount and drawIndirectFirstInstance are enabled on the layer's device where
  present (VulkanDeviceInfo::multi_draw_indirect / draw_indirect_count); without multiDrawIndirect each record
  is its own call.
- One VkPipelineCache per device for every graphics and compute pipeline (was VK_NULL_HANDLE), with
  VkPipelineCreationFeedback hit counting (rt::d3d12::pipeline_cache_stats).

Section 6 M5 row: synthetic part met except mesh shaders (D3D-29).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ature flags, test leniency

- A draw-kind ExecuteIndirect with no graphics state is unsupported at prepare unless it is marked raw
  (ExecuteIndirect::raw, set by the unit tests that wrap the call in rendering themselves).
- Calls take at most VkPhysicalDeviceLimits::maxDrawIndirectCount records (ReplayFunctions, VulkanDeviceInfo).
- VulkanDeviceInfo::draw_indirect_first_instance is recorded; the layer logs once when it is absent.
- VulkanDeviceInfo::draw_indirect_count defaults to false.
- d3d12_m5_world_test: without drawIndirectCount the count-buffer calls are left out; pipeline-cache checks only
  run when the driver returns valid creation feedback, and size equality only when both sizes are known.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	runtime/src/vulkan_replay.h
The fixed-count loops added a full chunk to a 32-bit cursor, so a short final chunk could wrap it and restart at
argument offset 0 (MaxCommandCount UINT32_MAX with maxDrawIndirectCount 0x80000000). Found by @Vonsek in review of
ItsNotRexed#1865. d3d12_state_map now checks the calls (counts and offsets, not records) for both draw kinds with a huge count
and for a limit that does not divide the count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wing without bound

A cursor that wraps again now ends the loop with a failed check rather than
appending until memory runs out. Checked by lowering the cap to 1: the
check fails at the call. Suggested by @Vonsek in ItsNotRexed#1865.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/CMakeLists.txt
#	runtime/src/command_list.h
#	runtime/src/vulkan_replay.h
#	scripts/run_gpu_tests.py
…ce_generated_commands

A command signature with root constants, root CBV/SRV/UAV, vertex or index buffer views per record now replays:
one device-generated-commands token per argument at its record offset (push-constant tokens into the 144-byte user
data block, vertex/index buffer tokens, DRAW/DRAW_INDEXED/DISPATCH), a compute pass that rebases buffer views by
heap_base, a count buffer as the sequence count address. CreateCommandSignature lays the record out and refuses what
D3D12 refuses (compared with the host runtime). d3d12_indirect_multiarg_test draws and dispatches against a CPU
reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Patch pass copies exactly (n - 1) * stride + the arguments (the last record's tail need not exist) in a 2D grid;
indirectAddressSize is that span on both paths. Layout cache is keyed on the record description, bounded to 64 and
evicts only layouts no running submission uses. Preprocess buffers come from a pool per memory-type set and honour
the required alignment. CreateCommandSignature refuses vertex/index buffers in a dispatch signature, a vertex slot
twice, a second index buffer and an index buffer without DRAW_INDEXED (all checked against the host runtime). The
test adds an exact-size argument buffer and says SKIPPED when there is no host runtime to compare with. Documents
that views outside the arena cannot be detected on GPU-written records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed commands read it

D3D12 runs min(count, MaxCommandCount), but the generated commands took the application's count word as the
sequence count address with maxSequenceCount = MaxCommandCount, and
VUID-VkGeneratedCommandsInfoEXT-sequenceCountAddress-11068 wants the value there to be at most maxSequenceCount.
Every count-buffer plan (with views patched or read in place, draw or dispatch) now runs a one-invocation compute pass
(indirect_count.comp) that writes min(count, MaxCommandCount) to scratch, barriered to the commands, and the layer
passes that address. The dispatch path now runs the prepass too. The test's count 100 against MaxCommandCount 2 draws
cells 13 and 14 and leaves cell 15 clear.

Reported-by: Flyander (review of ItsNotRexed#2077)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/src/vulkan_backend.h
#	scripts/run_gpu_tests.py
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ultiarg

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
…mits, doc corrections

- The test sets the list's root constants, vertex buffer and index buffer (graphics) and root constants and UAV
  (compute) before the calls and runs a plain DrawIndexedInstanced / Dispatch after them: each must use the list's
  state, not the last record's. The layer already re-pushes and rebinds everything with every command; the spec says
  the tokens leave that state undefined (vkCmdExecuteGeneratedCommandsEXT, Table 1), and the docs now cite it.
- The limits a signature alone decides (token count, token offset, stride, DXGI index mode, view count) are checked in
  CreateCommandSignature (E_NOTIMPL with a log) and again at replay; replay refusals log their reason once.
- The docs say what was measured for deviceGeneratedCommandsMultiDrawIndirectCount (false on the AMD Windows driver
  26.11.2, true on NVIDIA 617.42) instead of claiming it for AMD, describe the bounded count, and cite vkd3d-proton
  (LGPL-2.1, approach only) for invalidating state after the generated commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/shims/d3d12_com.h
#	runtime/shims/d3d12_vulkan_device.cpp
…ultiarg

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
# Conflicts:
#	runtime/shims/d3d12_com.cpp
#	runtime/src/vulkan_backend.h
…main's translator subtracts BaseVertex/BaseInstance)

After the round-41 merge the non-indexed records (P1) all drew cell 0: they chose their cell by StartVertexLocation,
which the hardware-style zero-based v0 no longer carries. P1 now picks cells through the instance id (InstanceCount),
indexed records still through the index values. The layer and the merge were fine; the test relied on an id semantic
main changed.

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

# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/src/vulkan_backend.h
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/src/vulkan_replay.h
…ultiarg

# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/src/vulkan_replay.h
…the PreparedDraw

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

@Kam471 Kam471 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.

Built and ran at 48b50f51d on Windows 11, RTX 5070 Ti (configured with LEONIDA_LLVM_MC, so the translated shader fixtures built):

  • pytest tests/test_compute_fixture_shift.py tests/test_root_sig_contract.py -q -> 63 passed.
  • d3d12_indirect_multiarg_test -> exit 0: 15 cells drawn by 5 calls ... and 13 groups run by 2 dispatch calls ... matched the CPU reference (error 0); 34 CreateCommandSignature cases agree with the host runtime.
  • d3d12_m5_world_test -> exit 0: 35 cells drawn by 5 ExecuteIndirect calls ... 5120 pixels each drawn from its own texture ... every pixel matched the CPU reference (error 0); the pipeline cache answered 1 of 1 duplicate PSO creations.
  • d3d12_state_map_test -> exit 0 (state map, enhanced barriers, ... OK).
  • git diff --check clean.

The indirect path now applies the compute root-argument offsets per record (root constants and a root UAV per dispatch, with the count-buffer cases), which is what the two new GPU tests exercise end to end; the signature cases also match the host's answers. There is a new MSVC C4456 shadowing warning in d3d12_m5_world_test.cpp at line 418 (counts hides the earlier local) — harmless but worth renaming before the warning-clean branch lands. No functional blocking issue.

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Tested 48b50f51 on Windows 11 (26300), RTX 5060 Ti / 621.14, MSVC 14.51 (VS 2026), Vulkan SDK 1.4.363.0, RelWithDebInfo, clean build with -DLEONIDA_LLVM_MC (translated-shader D3D12 tests included). Full LEONIDA_VK_VALIDATION=1 ctest -j4: 147/147 pass, 0 VUIDs, including the six changed tests (d3d12_compute, d3d12_fspx_compute, d3d12_indirect_multiarg, d3d12_indirect_rt, d3d12_m4_compute, d3d12_m5_world).

AI-assisted (Claude Code). Synthetic data only, no game files.

@editrice

Copy link
Copy Markdown
Author

Synced this draft with current main 561b65a8 at head 54ccfd99; GitHub now reports no merge conflicts. The resolution preserves main's shared DrawViews, seeded pipeline cache and counted-dispatch path alongside #2077's generated-command path and this PR's compute root offsets. On Windows 11 / RTX 5070 / MSVC 19.44 with Vulkan validation, the focused vk_command_replay, d3d12_indirect_multiarg (15 draw cells, 13 compute groups, 34 native signature comparisons), d3d12_pipeline_library, d3d12_m5_world (35 cells, 5120 textures, cache hit), d3d12_state_map, and root_signature CTests passed 6/6. d3d12_indirect_dispatch_count fails its first count=0 case identically on pristine main 561b65a8 and this merged tree (host 6/10, layer 0/0); I am recording that baseline failure explicitly, not attributing it to this PR. The 30-file diff remains a dependency stack. #2077 is still draft and depends on open #1865, so this PR remains draft; after those land I will reduce it to the focused fix and rerun. git diff --check against main and check_no_game_data.py on changed files passed. AI-assisted, synthetic material only.

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.

5 participants