Skip to content

Runtime: ExecuteIndirect(DISPATCH_MESH) without VK_EXT_mesh_shader, through --mesh-compute - #5899

Draft
flapwarp wants to merge 31 commits into
ItsNotRexed:mainfrom
flapwarp:indirect-mesh-compute
Draft

flapwarp wants to merge 31 commits into
ItsNotRexed:mainfrom
flapwarp:indirect-mesh-compute

Conversation

@flapwarp

@flapwarp flapwarp commented Nov 23, 2026 •

Copy link
Copy Markdown

Item: new D3D item, ExecuteIndirect with DISPATCH_MESH without VK_EXT_mesh_shader (claim; noted as a follow-up by @Kam471 on #3777).

Depends on: #3777
Depends on: #4408

This branch is the help rebase of #4408 onto #3777's current head f8b19786 (flapwarp:assist-4408-on-3777, 3d46c2b7; offered to @DaniSBR1 on #4408) plus four commits. Only those are for review: git diff 3d46c2b7..be2a10e4.

  • f14cde26 the indirect path, cc1285b0 compute-written arguments (case (d)), 88a14305 64-bit record addresses (@Flyander's review), be2a10e4 cs_m5_args built with the D3D-448 compute user-data shift (without it, on a base with D3D-448, case (d) read its table from the wrong SGPRs and the submission never completed).

What and why

Without the extension, #4408 draws DispatchMesh through --mesh-compute, but ExecuteIndirect(DISPATCH_MESH) stayed E_NOTIMPL: the group counts are GPU data, so the fallback's draw vertex count is too. On Pascal, RDNA1 on AMD's Windows driver and Intel UHD, an indirectly drawn mesh pass had no path at all.

  • Prepass (runtime/src/mesh_indirect_prepare.comp, host side vulkan_mesh_indirect.h, modelled on vulkan_indirect_dispatch_count.h): reads each record (and the count, with a count buffer) and writes a VkDispatchIndirectCommand and a VkDrawIndirectCommand (groups × max_primitives × 3, in 64 bits) into a private buffer the batch keeps until the submission completes.
  • Replay: per record vkCmdDispatchIndirect of the mesh-as-compute pipeline, one compute-write → vertex-read barrier, then in the rendering scope vkCmdDrawIndirect, each record in its own region of slots. The translated module flattens its slot index from NumWorkgroups (tools/rdna2spirv.py, mesh_compute_epilogue), which the indirect dispatch fills. No drawIndirectCount or multiDrawIndirect needed.
  • Limit: regions are sized before the counts exist: 64 MiB per call split over MaxCommandCount records, at most 2^22 groups each. A record that doesn't fit draws nothing, and the batch logs "dropped records" when the submission retires; a call that can't give each record one slot is ReplayResult::unsupported.
  • D3D12: CreateCommandSignature(DISPATCH_MESH) and CheckFeatureSupport's mesh tier now share one mesh_compute_tier(), so they can't disagree.
  • Fix found on the way: a pipeline of the wrong kind (VS PSO under DISPATCH_MESH) was unsupported instead of invalid_draw on a device without mesh shaders, because the entry-point check came first. Now invalid_draw everywhere.
  • Test: build.py takes LEONIDA_MESH_COMPUTE=1; d3d12_m5_mesh_test --mesh-compute (d3d12_m5_mesh_compute, d3d12_m5_mesh_compute_single) runs M5's DispatchMesh and ExecuteIndirect cases (I1–I5: count buffers, count 0, count above MaxCommandCount, stride 24, GPU-written arguments) on a layer device created without the extension, with ms_m5 translated with --mesh-compute --wave64-emulate. Same CPU reference, error 0.
  • Docs: docs/d3d12_vulkan.md replaces the "Not built" bullet with the path, the limit and the results.

Tested

NVIDIA GeForce GTX 1050 Ti (Pascal, no VK_EXT_mesh_shader), driver 580.196.07, Linux; runtime cross-built with clang-cl 21 + xwin (SDK 10.0.26100), run under Wine 10.0.

  • d3d12_m5_mesh_test --mesh-compute and --mesh-compute --single-calls: DispatchMesh 0 mismatched pixels; ExecuteIndirect DISPATCH_MESH, 30 records drawn (count buffers included), 0 mismatched pixels; wrong-kind draws fail at execution.
  • ctest -R 'indirect|mesh|m5|m4|m3|m2|draw|state_map' (26): all pass or skip as on the base, except d3d12_indirect_dispatch_count, which exits 1 with no output identically on the base without this commit on this machine (pre-existing, not investigated here).
  • Linux CPU ctest 55/55 (the replay tests compile vulkan_replay.h); the Python tests around build.py and the docs tests pass.

Not covered: a Windows build with MSVC on a Windows driver. d3d12_m5_mesh_compute runs on any GPU (the layer's device is created without the extension), so a Windows run on any RTX or Radeon would cover it. Also not run: the native mesh tests on a GPU with the extension (they should be unaffected: the new path is taken only for --mesh-compute PSOs).

No game files. AI-assisted.

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
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/src/vulkan_backend.h
#	scripts/run_gpu_tests.py
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
# 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>
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/src/vulkan_replay.h
…h (D3D-29)

The device enables VK_EXT_mesh_shader (meshShader) where the GPU has it
and reports MeshShaderTier 1 only then.

ID3D12Device2::CreatePipelineState parses pipeline state streams in the
d3dx12.h layout into the descriptions the existing PSO creators take, with
the runtime's defaults for missing subobjects. Streams the PC runtime
refuses are E_INVALIDARG; AS, depth bounds, split stencil masks and view
instancing are E_NOTIMPL with a log.

A mesh PSO is MS + PS with no vertex input or input assembly, and no
dynamic topology or strides. Its output sizes and workgroup are checked
against VkPhysicalDeviceMeshShaderPropertiesEXT.

DispatchMesh records a Draw with mesh set and replays as
vkCmdDrawMeshTasksEXT; a draw of the wrong kind for its pipeline fails
with ReplayResult::invalid_draw.

d3d12_mesh_test covers the refusals and checks a 2x2x1 and a 1x1x2 mesh
grid plus a VS PSO from a stream, pixel by pixel.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ates; mesh test skips without Vulkan

The stream parser keyed its duplicate check on the raw subobject type, so DEPTH_STENCIL with DEPTH_STENCIL1
(either order) or RASTERIZER with RASTERIZER2 was accepted; D3D12_PIPELINE_STATE_STREAM_DESC counts versions of
one subobject as the same one. The check now uses the base type, while the payload still follows the original
type. d3d12_mesh_test covers both mixed orders, RASTERIZER + RASTERIZER2, and each description alone.
Reported by Vonsek in review.

d3d12_mesh_test failed on a machine without a Vulkan device (the Windows CI runner) instead of exiting 77; it
now skips there like d3d12_draw_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/shims/d3d12_com.cpp
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/src/vulkan_backend.h
#	runtime/src/vulkan_replay.h
main's bundles record their commands through defer() and replay them at
ExecuteBundle. Without it, a DispatchMesh in a bundle went into the
bundle's own command list and was never replayed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sh gate with a translated mesh shader

CreateCommandSignature takes DISPATCH_MESH where VK_EXT_mesh_shader is enabled (E_NOTIMPL without it).
ExecuteIndirect records it with the state DispatchMesh takes, and replay issues
vkCmdDrawMeshTasksIndirectEXT, or vkCmdDrawMeshTasksIndirectCountEXT with a count buffer, split by
multiDrawIndirect and maxDrawIndirectCount as the draw kinds are.

build.py makes the PSV0 container of a mesh shader whose header has a psv0: line, so translated mesh
shaders can be layer-test fixtures. d3d12_m5_mesh_test draws ms_m5.asm (NGG wave64, 128 threads, the
corpus's v5/s3 idioms) by DispatchMesh and by ExecuteIndirect, error 0.

AI-assisted (Claude Code).

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

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… fallback-path ctest; run_gpu_tests reads the psv0 header

- Pass the device's subgroup caps to the layer, so the wave64 mesh stage asks for 64; exit 77 where the
  device cannot run it 64-wide, or has fewer than 144 push-constant bytes.
- --single-calls / --no-count-buffers turn multiDrawIndirect / drawIndirectCount off on the layer's
  device; registered as d3d12_m5_mesh_fallbacks. Without drawIndirectCount a count-buffer call must be
  ReplayResult::unsupported.
- scripts/run_gpu_tests.py translates every .asm itself: give a mesh shader with a psv0: header its
  PSV0 there too (ms_m5 failed translation in the GPU suite without it).

AI-assisted (Claude Code).

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From two review passes (one adversarial):
- CreateCommandSignature refuses DISPATCH_MESH after root arguments (E_NOTIMPL, as before this
  branch) instead of accepting it and reading the group counts from the record's first bytes.
- CommandList::execute_indirect refuses a mesh dispatch without DispatchMesh's state, and a draw
  kind with it.
- The test fails on validation errors, as its siblings do; asserts the mesh stage's subgroup request
  was found (and fails on an undecided one).
- I5 runs at stride 24 without a count buffer, zero-padded, 1 to 4 groups per record; new
  d3d12_m5_mesh_chunks lowers the layer's maxDrawIndirectCount to 3 so the calls are split.
  Mutations caught: chunks that don't advance (chunks run), a stride hard-coded to 12 (both).
- Docs and comments: one-argument signatures only; maxDrawIndirectCount applies without a count
  buffer; invalid_draw for a draw signature with a mesh PSO needs a topology; only a record's group
  total is visible; ms_m5 sends GS_ALLOC_REQ from every thread; whitespace restored.

AI-assisted (Claude Code).

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ce caps; build.py psv0 error

From review on ItsNotRexed#3777:
- The wave64 skip is decided from the library entry and the device's subgroup caps (decide_subgroup_size,
  as the layer decides it) before any mesh PSO is created, so a device that cannot run ms_m5 skips even if
  its PSO creation would fail. The PSO's own mesh-stage request must match that prediction. (whattheflop)
- The DispatchMesh part clears to 128/255 instead of 0.5: 0.5 is 127.5 in UNORM8 and some GPUs store 127.
  The emulated RTX 5070 / 5080 runs differed only there. (kacper-serewis, tedin7)
- The layer's device info gets drawIndirectFirstInstance, as d3d12_m5_world_test does, which silences its
  "not enabled" log. (ddm-j)
- build.py: an ms_ shader without a psv0 header raises a clear ValueError instead of a TypeError when
  translate_tests is called directly. (tupacfan04)

AI-assisted (Claude Code).

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

Copy link
Copy Markdown
Contributor

Independent Windows verification of head e994cd04aac833c415d307a90b7a2cec7002ef93 (own delta 6d03e8554..e994cd04): RTX 4070 Ti, NVIDIA 610.88, Windows 10.0.26300, MSVC 19.44.35230 / VS 2022 Build Tools 17.14.45, Vulkan SDK 1.4.363.0, LLVM AMDGPU 23.1.6. Synthetic fixtures only; no game files. AI-assisted.

Built d3d12_m5_mesh_test, d3d12_mesh_test, d3d12_mesh_compute_test and vk_sync_validation_selftest in RelWithDebInfo with CMake/Ninja and native MSVC. Ran ctest -V -R ^(d3d12_m5_mesh|d3d12_m5_mesh_fallbacks|d3d12_m5_mesh_chunks|d3d12_m5_mesh_compute|d3d12_m5_mesh_compute_single|d3d12_mesh|d3d12_mesh_compute|vk_sync_validation)$ --timeout 120 with LEONIDA_VK_VALIDATION=1, VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1, the RTX selected and overlay layers disabled: 5 passed, 3 skipped. The self-test deliberately produced a write-after-write error without a barrier and none with one, confirming sync validation is active. The four passing mesh tests reported no validation errors.

  • d3d12_m5_mesh_compute and _single: both passed; direct DispatchMesh and ExecuteIndirect had 0 mismatched pixels, with 30 records in the indirect reference (including an empty record). I1–I5 cover count buffers, count zero, count 7 above max 2, strides 12 and 24, and arguments and count copied on the GPU from upload staging before use. This is GPU-copy-written data, not a compute-shader-generated argument test. Wrong-kind draws were rejected as expected.
  • d3d12_mesh_compute: direct compute-fallback fixture matched all 4096 pixels. d3d12_mesh: native VK_EXT_mesh_shader direct DispatchMesh fixture matched all 4096 pixels; this is not a native indirect M5 check.
  • d3d12_m5_mesh, _fallbacks and _chunks: skipped before mesh PSO creation because this RTX exposes subgroup sizes 32..32; the translated native M5 fixture requires wave64. Consequently native ExecuteIndirect M5 was not checked.

The compute fallback was forced by passing mesh_shader=false to the layer on this RTX; the underlying Vulkan test device requests/enables the extension where available. This is not a test on hardware lacking VK_EXT_mesh_shader, nor proof of a Vulkan device created without the extension. No physical no-extension GPU or compute-shader-written argument case was tested.

Comment thread runtime/src/mesh_indirect_prepare.comp Outdated
if (k >= p.records) return;
uint x = 0u, y = 0u, z = 0u, vertices = 0u;
if (p.has_count == 0u || k < p.count.data[0]) {
const uint source = k * p.stride_words;

@Flyander Flyander Nov 23, 2026 •

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.

Synthetic repro (source-level; not GPU-run): with ByteStride = 0x40000000 bytes and MaxCommandCount = 17, record k = 16 should start at word 0x1_0000_0000, but this 32-bit multiplication wraps to word 0, so the prepass reads arguments from record zero again. CreateCommandSignature currently accepts that stride (multiple of 4 and >= 12), and indirect_range() checks the full range with VkDeviceSize. Promoting source and its indexing to 64 bits, or rejecting a stride/count product that overflows, would prevent this alias. It needs a roughly 16 GiB argument buffer to exercise end-to-end, so this is low priority; the wrapped offset itself is deterministic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks: fixed in 90b7cbc. The record is now a buffer reference built from its 64-bit address (arguments + uint64(k) * stride_words * 4), so a large ByteStride can't wrap to an earlier record; the output indices (k·3, k·4) stay 32-bit, which mesh_indirect_capacity keeps safe by refusing calls with more than a few million records. Re-run on the GTX 1050 Ti: unchanged, 0 mismatched pixels; not exercised with a 16 GiB buffer.

@flapwarp

Copy link
Copy Markdown
Author

Follow-up for @SirKingg's note on compute-written arguments (0a8a097): case (d) — cs_m5_args writes 8 DISPATCH_MESH records and the count 6 in the same list, then ExecuteIndirect with the count buffer. GTX 1050 Ti (no VK_EXT_mesh_shader), --mesh-compute and --single-calls: 6 records drawn, 0 mismatched pixels.

Barrier checks on that GPU: without the prepass's trailing barrier (prepass → indirect commands), (b) and (d) draw nothing, so the test guards it. Without the leading barrier (app writes → prepass), everything still passes, so I can't show it's needed here; it stays as a cheap guard. Synchronization validation through Wine didn't report even a known hazard, so I can't use it as evidence. @SirKingg, since your Windows setup has working sync validation, a run with the leading before barrier in MeshIndirectPreparer::emit removed would settle whether it's redundant. No game files. AI-assisted.

@memorypressure

Copy link
Copy Markdown

FAIL to merge as it stands, verified at your newest head 90b7cbc: merge-tree against current main 561b65a conflicts in docs/d3d12_vulkan.md, docs/design.md, runtime/CMakeLists.txt, runtime/shims/d3d12_vulkan_device.cpp, runtime/src/shader_library.h, runtime/src/vulkan_backend.h and runtime/src/vulkan_replay.h — the branch bases on 3faac55 (pre-round-44) and round 44 merged and reverted across exactly those files, so a real rebase is needed. The substance survives the rebase: the Python side merges clean and passes (test_shader_build_mesh 4/4 with PSV0 byte-exactness against run_gpu_tests, shader_checks and shader_meta green, compileall clean), and the diff carries no references to the reverted #4247/#3369/#2490 work. Fixtures are hand-written listings. The PR reports no CI checks at all — worth triggering after the rebase so the C++/mesh half gets its first real build. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

DaniSBR1 and others added 6 commits November 23, 2026 15:02
…gh --mesh-compute

On a device without VK_EXT_mesh_shader (RDNA1, NVIDIA Pascal, Intel UHD) a mesh PSO was E_NOTIMPL. With mesh
shaders translated by --mesh-compute (ItsNotRexed#1053) the layer now runs them, the runtime side docs/design.md listed as
the follow-up:

- PSO: the MS module becomes a compute pipeline (152-byte push constants, set 0 where it has bindings, its
  translated subgroup size). The graphics pipeline gets, in place of the mesh stage, the vertex shader that draws
  the slots, built from the index's mesh_compute layout by runtime/src/mesh_compute_vs.h: the module
  tools/mesh_compute_vs.py writes, instruction for instruction.
- DispatchMesh: groups x slot_bytes of the queue's scratch (now with a device address), vkCmdDispatch, a
  compute-write -> vertex-read barrier, and vkCmdDraw(groups x max_primitives x 3) in the draw's rendering scope.
- MeshShaderTier is 1 without the extension where the index has --mesh-compute mesh shaders and the device can
  run them. A mesh shader without a layout, a PS reading f16 halves elsewhere than the layout exports them, or a
  device under 152 bytes of push constants is E_NOTIMPL with a log. ExecuteIndirect DISPATCH_MESH is not built.

Tests: mesh_compute_vs_test (four layouts, refusals; spirv-val on the modules), d3d12_mesh_compute_test (a
stand-in for ms_draw.mesh written to the --mesh-compute contract, drawn through a stream PSO on a device made
without the extension: every pixel checked), shader_library_test (the layout). RX 5700 XT, AMD 26.11.2,
Windows 11: ctest 164/164 (the four VK_EXT_mesh_shader tests skip); the new D3D12 test also passes under the
Khronos validation layer.

Depends on: ItsNotRexed#1712, ItsNotRexed#3777

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b990f5e)
…bset, clang-cl)

- A --mesh-compute PSO is refused unless the compute stage is guaranteed the mesh shader's subgroup size
  (emulated, required by the stage, or the device's only size); OPTIONS7 reports tier 1 only where every
  --mesh-compute mesh shader in the index passes (Flyander, P1).
- The path needs VK_QUEUE_COMPUTE_BIT on the Direct queue's family, for the PSO and the tier (Flyander, P2).
- A PS reading the f16 halves of some of the exported params links; only halves read where the layout doesn't
  export them are refused (tupacfan04).
- The graphics push-constant range size is an explicit uint32_t (clang-cl narrowing; ligmaSec, ddm-j).
- d3d12_mesh_compute_test covers the refusals: 144 push-constant bytes and subgroup sizes that can't be required
  hide the tier and refuse the PSO (an emulated mesh shader is still created), plus the f16 subset and mismatch.

RX 5700 XT, AMD 26.11.2, Windows 11: ctest 164/164; d3d12_mesh_compute clean under the validation layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fdd4667)
…hrough --mesh-compute

The group counts of an indirect DISPATCH_MESH record are GPU data, so the --mesh-compute fallback's draw
vertex count is too. A prepass (mesh_indirect_prepare.comp, vulkan_mesh_indirect.h) reads each record and
the count, and writes a VkDispatchIndirectCommand and a VkDrawIndirectCommand (groups * max_primitives * 3,
in 64 bits) into a private buffer the batch keeps until the submission completes. The replay issues per
record vkCmdDispatchIndirect of the mesh-as-compute pipeline, a barrier, and vkCmdDrawIndirect in the
rendering scope, each record in its own region of slots (the module flattens its slot from NumWorkgroups).

Regions are sized before the counts exist: 64 MiB per call over MaxCommandCount records, at most 2^22
groups each; a record that does not fit is dropped and the batch logs it when the submission retires.

CreateCommandSignature(DISPATCH_MESH) and CheckFeatureSupport's mesh tier share one mesh_compute_tier().
A pipeline of the wrong kind is now invalid_draw before the entry-point checks, so it is on a device
without mesh shaders too. build.py takes LEONIDA_MESH_COMPUTE=1, and d3d12_m5_mesh_test --mesh-compute
(d3d12_m5_mesh_compute, _single) runs M5's DispatchMesh and ExecuteIndirect cases on a device without the
extension: GTX 1050 Ti (Pascal), 30 records, 0 mismatched pixels.
…n the same list

Case (d): cs_m5_args.asm writes 8 records { 1 + (k & 3), 1, 1 } and the count 6 into two raw UAV buffers;
after a UAV -> INDIRECT_ARGUMENT transition, ExecuteIndirect(DISPATCH_MESH) with the count buffer reads them
(the GPU-culling pattern). Runs with count buffers, natively and under --mesh-compute, every pixel against
the CPU reference. GTX 1050 Ti (no VK_EXT_mesh_shader), --mesh-compute and --single-calls: 6 records drawn,
0 mismatched pixels.

Barriers, on that GPU: without the prepass's trailing barrier (prepass -> indirect commands), (b) and (d)
draw nothing, so the test guards it. Without its leading barrier (application writes -> prepass) the case
still passes (5 runs), so it does not show that one is needed; synchronization validation is the check for
that.
k * stride_words was a 32-bit word index: with a large ByteStride (0x40000000 bytes, which
CreateCommandSignature accepts as a multiple of 4 of at least 12) and MaxCommandCount 17, record 16 starts at
word 2^32, the index wrapped to 0 and the prepass read record 0 again; indirect_range() checks the whole range in
64 bits, so nothing caught it. The record is now a buffer reference built from its 64-bit address. The outputs
(k * 3, k * 4 words) stay small: mesh_indirect_capacity leaves no slot for a call with more than a few million
records. Found in review by Flyander.

GTX 1050 Ti, --mesh-compute and --single-calls: unchanged, 0 mismatched pixels.
…ta shift

On a base with D3D-448, a D3D12 compute PSO gets its root arguments from s4, and the cs_ fixtures are built
with LEONIDA_USER_DATA_SHIFT=4 (as the M4 shaders are). Without it cs_m5_args read its descriptor table from
the wrong SGPRs and the submission never completed (case (d) hung on a GTX 1050 Ti). The shift touches the
cs_ fixture only; ms_m5 and the pixel and vertex shaders are unchanged.
@flapwarp
flapwarp force-pushed the indirect-mesh-compute branch from 90b7cbc to be2a10e Compare November 23, 2026 13:21
@flapwarp

Copy link
Copy Markdown
Author

@memorypressure thanks, rebased as you suggested: #4408 onto #3777's current head f8b19786 (on main 561b65a8) as a help branch for @DaniSBR1, and this PR's four commits on top (head be2a10e4); GitHub now reports it mergeable. The conflicts were in the files you listed, all "both sides added" (details on #4408).

The rebase surfaced one real change: on a base with D3D-448 a compute PSO's root arguments start at s4, so cs_m5_args is now built with LEONIDA_USER_DATA_SHIFT=4 like the M4 shaders (be2a10e4); without it case (d) read its table from the wrong SGPRs and the submission never completed.

GTX 1050 Ti (no VK_EXT_mesh_shader, NVIDIA 580.196.07, Linux, clang-cl 21 + Wine 10.0): d3d12_m5_mesh_test --mesh-compute and --single-calls give 0 mismatched pixels (DispatchMesh, 30 indirect records, 6 compute-written records); ctest -R 'mesh|m5|draw|indirect|state_map' 20/21, the one failure (d3d12_indirect_dispatch_count) identical without these commits on this machine. CI on the rebased head would indeed be the next useful check. No game files. AI-assisted.

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.

8 participants