Skip to content

Runtime tests: run the M5 mesh gate on 32-wide GPUs through --wave64-emulate (depends on #3777) - #4236

Open
tedin7 wants to merge 25 commits into
ItsNotRexed:mainfrom
tedin7:m5-mesh-wave64-emulate
Open

tedin7 wants to merge 25 commits into
ItsNotRexed:mainfrom
tedin7:m5-mesh-wave64-emulate

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new D3D item (claim). Item ID: TBD.

Depends on: #3777 (D3D-394, the mesh half of M5)

This branch is #3777 at 536cb939 plus one commit. Only that commit is for review: git diff 536cb939..HEAD.

What and why

On a GPU that cannot give the mesh stage 64 lanes (NVIDIA, Intel, Apple: 32 only), d3d12_m5_mesh, d3d12_m5_mesh_fallbacks and d3d12_m5_mesh_chunks exited 77 and skipped, so the M5 mesh gate never ran on most PC GPUs. This makes them run there.

  • The tests pick the shader build at run time. CMakeLists.txt now also translates ms_m5, ps_m5_mesh, vs_m3 and ps_m5_flat with --wave64-emulate into generated/m5_mesh_shaders_w64e. The test asks decide_subgroup_size about the native ms_m5 with the device's real limits. Where the answer is unavailable, it loads the emulated build, which is exact on any subgroup size and asks the driver for nothing. Where 64 lanes exist, nothing changes.
  • The one mismatch was not the mesh path. Forcing emulation on a 32-wide GPU (LEONIDA_W64_EMULATE=1 for the build) made all three tests fail with DispatchMesh ... 2816 mismatched pixels, got 127,127,127,255 want 128,128,128,255, while ExecuteIndirect DISPATCH_MESH had 0. 2816 is 4096 minus the 20 drawn cells of 64 pixels: every background pixel, no pixel inside a mesh cell. The background is a clear to 0.5, and 0.5 * 255 = 127.5 is a rounding tie. vkCmdClearColorImage rounds it down to 127 on the RTX 5080, WARP up to 128. The ExecuteIndirect part clears to 0, which has no tie. Clears are D3D-45's (Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) #521), so this test now clears to 128/255, which has no tie, and the oracle (exact, error 0) stays as it was. After the change the same emulated build gives 0 mismatches.
  • Docs. docs/testing.md, in the 32-wide GPUs section, says how the tests choose the build and records the RTX 5080 result.

How it was tested

RTX 5080 16 GB, driver 580.65.06, Ubuntu 22.04 (RunPod), no display: runtime cross-built with clang-cl 21 and lld-link against an xwin SDK 10.0.26100, run under Wine 11.0 on Xvfb (docs/testing.md, "The Windows runtime on Linux"). -DVulkan_INCLUDE_DIR pointed at Vulkan-Headers (the host's are older) and LEONIDA_SPIRV_AS/LEONIDA_SPIRV_VAL at the SDK 1.4.363.1 tools.

ctest -R m5_mesh -V
  before (#3777 536cb939):                 3 skipped ("the wave64 mesh shader cannot run 64-wide here")
  before, build with LEONIDA_W64_EMULATE=1: 3 failed (2816 mismatched pixels, 127 vs 128)
  after:                                    3 passed, 0 mismatched pixels in DispatchMesh and in ExecuteIndirect DISPATCH_MESH
ctest -R "d3d12|dxgi" -j3 --timeout 200    (whole d3d12/dxgi set, 67 tests on this branch)
  after: 49 passed, 13 skipped, 5 failed

The 5 failures are the host-comparison tests, which compare with Wine's vkd3d instead of Microsoft's runtime and fail the same way without this change: d3d12_fence_timing, d3d12_private_data, d3d12_descriptor, d3d12_subresource_copy, d3d12_compute (its host == layer check on cached PSOs; its reference-count check passes). #3023 and #3679 cover them. The other 13 skips are tests that skip under Wine's host.

Not run: Windows with MSVC, any AMD GPU (so the native 64-wide choice is unchanged by construction, not measured here), Vulkan validation layers (Wine does not expose them), and the mesh tests against WARP.

Findings, not fixed here

No game files were used. AI-assisted.

AlxcBTW and others added 23 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
…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>
…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:
#	runtime/CMakeLists.txt
#	runtime/src/vulkan_replay.h
#	runtime/test/vk_test_device.h
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/src/vulkan_backend.h
#	runtime/src/vulkan_replay.h
…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>
…128/255 so the background has no rounding tie

On a GPU that cannot give the mesh stage 64 lanes the three d3d12_m5_mesh tests skipped. They now load a --wave64-emulate build of the same shaders where decide_subgroup_size says the native one is unavailable. The only mismatch that build had (2816 background pixels, 127 vs 128) was the 0.5 clear, a rounding tie.

@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 this at 8b6be57f on Windows 11, RTX 5070 Ti (32-wide subgroup only, Vulkan 1.4.357), with LLVM 21 llvm-mc and the SDK spirv-as/spirv-val:

  • ctest -R '^d3d12_m5_' -> 4/4 passed: d3d12_m5_world 1.55 s, d3d12_m5_mesh 0.53 s, d3d12_m5_mesh_fallbacks 0.36 s, d3d12_m5_mesh_chunks 0.33 s.
  • d3d12_m5_mesh_test -> exit 0: "mesh tier 1, translated wave64 mesh shader (128 threads, wave64 emulation): DispatchMesh 4x2x2, 3x1x1, 1x1x1 and an empty grid, 0 mismatched pixels; ExecuteIndirect DISPATCH_MESH, 30 records drawn (count buffers included), 0 mismatched pixels; wrong-kind indirect draws fail at execution".
  • ctest -R '^d3d12_mesh$' -> 1/1 passed (0.45 s).

This is the exact 32-wide case the PR targets, and the wave64 mesh gate now runs through emulation instead of skipping. No blocking issue.

@whattheflop

Copy link
Copy Markdown
Contributor

Added native Windows positive-draw parity at 8b6be57. Radeon iGPU selected native wave64 and RTX 3080 selected emulation. Base and chunked modes matched all direct and indirect pixels on both, with 30 indirect records and zero validation errors per run. AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 8b6be57 on AMD Radeon(TM) Graphics (gfx1036, driver 26.10.1) and NVIDIA GeForce RTX 5080 (driver 616.92), Windows 11, MSVC RelWithDebInfo: d3d12_m5_mesh_test in its three ctest modes (default, --single-calls --no-count-buffers, --max-draw-indirect-count 3), each with LEONIDA_VK_DEVICE=radeon and =5080 (device line confirmed), shaders built with the repo's llvm-mc/spirv-tools. All six exit 0 with 0 mismatched pixels for DispatchMesh (4x2x2, 3x1x1, 1x1x1, empty grid) and ExecuteIndirect DISPATCH_MESH (30 records with count buffers, 25 without). The RTX 5080 (subgroup 32 only) takes the new wave64-emulation build; the Radeon runs the native wave64 mesh shader (default subgroup 64, mesh stage not requirable, so no emulation needed there). AI-assisted.

Conflicts resolved: a draw's views follow main's shared DrawViews block (mesh draws use it too); main's counted
dispatch prepass is replayed inside the ExecuteIndirect path this branch moved into emit_indirect, and a
DISPATCH_MESH count signature is still checked for its entry point; one pipeline cache (main's seeded one) serves
the branch's create_pipeline wrapper, which keeps counting creations; create_graphics keeps main's GS wording plus
the mesh overload.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Commit 0de6338 merges origin/main into the branch (no rebase). Seven files conflicted. Main's shared DrawViews block is used for mesh draws too. Main's counted-dispatch prepass is replayed inside the ExecuteIndirect path this branch moved into emit_indirect, and a DISPATCH_MESH count signature is still checked for its entry point. Main's seeded pipeline cache now serves this branch's create_pipeline wrapper (the branch's own cache members are removed; creations are still counted). create_graphics keeps main's GS wording plus the mesh overload. Checked on the RunPod (clang-cl, Wine, llvmpipe): everything compiles. The CPU tests (command_list, shader_library, vk replay unit tests, state_map) pass. The GPU tests (d3d12_m5_mesh*, d3d12_mesh, indirect, vk_command_replay) did not give a result there: the mesh shader fixtures fail spirv-val on the pod's older SPIR-V tools (Invalid capability MeshShadingEXT) and the others timed out at 120 s on llvmpipe. Please run those on a GPU before merging. AI-assisted.

Both sides rewrote ExecuteIndirect replay in vulkan_replay.h. Kept: this
branch's split (an indirect draw or DISPATCH_MESH with recorded graphics state
goes through the Draw path, the rest through detail::emit_indirect, which
covers draw, draw count, dispatch, counted dispatch and the mesh kinds with the
maxDrawIndirectCount chunking), with main's bindless fix for the recorded
dispatch pipeline (set 0 is the device's current generation when there is one)
and main's statistics bracket around the counted-dispatch prepass. ReplayResult
lives where main moved it, with this branch's invalid_draw. Device functions:
main's render pass, framebuffer and sparse entries plus this branch's mesh
draws and vkGetPipelineCacheData. DeviceState: main's subgroups_once plus the
mesh properties. CMake: main's d3d12_stores_atomics_test and this branch's
d3d12_mesh_test. docs: main's pipeline library text plus the pipeline cache
feedback paragraph.

Tested on an RTX 5080, clang-cl build (all 655 targets) under Wine: d3d12_m5_mesh,
d3d12_m5_mesh_fallbacks, d3d12_m5_mesh_chunks, d3d12_m5_world, d3d12_mesh,
d3d12_state_map, vk_command_replay, the replay_* tests, d3d12_draw,
d3d12_compute, d3d12_m3_*, d3d12_m4_compute, d3d12_pipeline_library(+host),
d3d12_subgroup, d3d12_translated_draw pass (26 of 28); d3d12_indirect_rt and
d3d12_indirect_dispatch_count fail the same way on main. Linux: ctest
replay/queue/indirect/predication 16 of 16; run_gpu_tests.py 183 of 238
passed, 54 skipped, 1 failed (ms_wave_info_s3, failing on main too).
tests/test_shader_build_mesh.py and tests/test_docs_*.py pass.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review

Reviewed test coverage in PR #4236: Runtime tests: run the M5 mesh gate on 32-wide GPUs through --wave64-emulate (depends on #3777).

Scope: docs/d3d12_vulkan.md, docs/testing.md, runtime/CMakeLists.txt, +24 more
Diff: +3038 / -100 across 27 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @tedin7 - I went through Runtime tests: run the M5 mesh gate on 32-wide GPUs through --wave64-emulate (depends o... and the diff around docs/d3d12_vulkan.md. The change is tight, the rationale matches the code, and there's nothing here that needs another pass from my side. Approved and squash-merging it into main now. Nice work.

ASTROWwwW pushed a commit to ASTROWwwW/Leonida that referenced this pull request Nov 23, 2026
vulkan_replay: the stencil clear by buffer copy (ItsNotRexed#5489)
ran under predication, where a transfer command ignores the predicate and
cleared a stencil the title asked to skip. Under predication the clear
stays on the attachment path, as before that change.

descriptor_table: reserve_changes_locked (ItsNotRexed#5569) asked
for the exact size on every insert, erase and replace, so each call
reallocated and copied the change list. It now grows geometrically.

command_list: draw(Draw&&), the overload DispatchMesh takes
(ItsNotRexed#4236), recorded a mesh draw with no thread groups;
it is dropped like in the const& overload.

descriptor_table_test and command_list_test build and pass with clang on
Linux. vulkan_replay.h was not compiled: no Windows toolchain here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UkEUa9YfGQH4p9g1Guw9gq
@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit abe4af37)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

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.

10 participants