Skip to content

Runtime: mesh-shader PSOs from pipeline state streams and DispatchMesh (D3D-29) - #1712

Open
LloydNicholson wants to merge 2 commits into
ItsNotRexed:mainfrom
LloydNicholson:runtime/mesh-shaders
Open

LloydNicholson wants to merge 2 commits into
ItsNotRexed:mainfrom
LloydNicholson:runtime/mesh-shaders

Conversation

@LloydNicholson

@LloydNicholson LloydNicholson commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-29 (claim)

What and why

9,282 of the 26,503 translated shaders are mesh shaders, but the layer reported D3D12_MESH_SHADER_TIER_NOT_SUPPORTED and had no way to create or draw a mesh PSO. This adds both, on VK_EXT_mesh_shader, on top of #291's graphics pipelines.

  • Device:
    • Enables VK_EXT_mesh_shader with meshShader where the GPU has it (VulkanDeviceInfo::mesh_shader).
    • No taskShader: the corpus has no amplification shaders.
    • OPTIONS7.MeshShaderTier is 1 only then.
  • ID3D12Device2::CreatePipelineState:
    • Parses pipeline state streams in the d3dx12.h layout into the descriptions CreateGraphicsPipelineState and CreateComputePipelineState already take. Missing subobjects take the runtime's defaults.
    • E_INVALIDARG, as on the PC runtime: a duplicate, unknown or truncated subobject, MS with VS, CS with graphics stages, or no stage at all.
    • E_NOTIMPL with a log: AS, depth-bounds tests, separate front and back stencil masks, view instancing.
  • Mesh PSO:
    • MS + PS, with no vertex input or input assembly, and no dynamic topology or strides (VUID-…-07065/07066).
    • The index's max_vertices/max_primitives (now read by ShaderLibrary) and the workgroup size are checked against VkPhysicalDeviceMeshShaderPropertiesEXT.
  • DispatchMesh:
    • Records a Draw with mesh set, with the same state snapshot as DrawInstanced, and replays as vkCmdDrawMeshTasksEXT.
    • A grid above D3D12's limits fails at Close. An empty grid records nothing.
    • A draw of the wrong kind for its pipeline fails at execution with the new ReplayResult::invalid_draw.
  • Docs: docs/d3d12_vulkan.md §3.6 has the details. The Xbox-ABI proxy already forwards device slots in PC order, so nothing changed there.

Tested

AMD Radeon RX 9060 XT (RDNA4), RADV on Mesa 27.0.0-devel, Fedora 44 (Linux 7.3). The Windows build is clang-cl 22.1.8 with xwin SDK 10.0.26100, run under Wine 11.22.

  • New d3d12_mesh_test: passes, matching all 4096 pixels.
    • Draws: DispatchMesh 2×2×1 and 1×1×2 (so all three counts reach the shader), plus a VS PSO built from a stream.
    • Refusals: 6 invalid streams → E_INVALIDARG, AS and depth bounds → E_NOTIMPL, wrong-kind draws → invalid_draw, oversized grids → Close fails.
    • Without the extension: the tier is NOT_SUPPORTED and a mesh PSO is E_NOTIMPL.
  • Validation: run with the host's Khronos validation layer (VK_INSTANCE_LAYERS), the mesh path is clean. The only messages are vkCreateDevice ones about VK_KHR_shader_fma, which this older layer doesn't know; d3d12_draw_test on main gives the same ones.
  • Full suites, rebased onto main a0acd33:
    • Wine ctest: 8 failures. main at the same commit, built the same way, fails the same ones:
    • Native Linux ctest with validation: the same 3 failures as main (depth24_convert and the two occlusion tests).
    • d3d12_mesh, d3d12_draw and d3d12_vulkan_device pass.
  • Rebased again onto main 89b047c (75ef6e19, conflicts only in neighbouring fields):
    • d3d12_mesh, d3d12_compute and d3d12_vulkan_device pass under Wine.
    • Native Linux ctest still has the same 3 failures.
    • d3d12_draw now fails its new "bundle blend" check (pixel (0, 0): got 255,0,0,255, expected red 64), and main at 89b047c fails it the same way, so it isn't from this PR.
    • The full Wine suite above was run at a0acd33, not at this commit.
  • Rebase conflicts: this rebase met main's primitive restart and graphics bindless set. A mesh PSO now skips the strip-cut check and the dynamic restart state (it has no index buffer or input assembly). The bindless set layout is VK_SHADER_STAGE_ALL, so it already covers the mesh stage.
  • Not tested:
    • Windows with MSVC and Microsoft's runtime.
    • A GPU without VK_EXT_mesh_shader (only simulated, by leaving the flag off).
    • Translated mesh shaders from the game: the test shader is GLSL written to the translator's contract.
    • Whether the console flattens a 3D grid the same way, which is still open in docs/design.md.

Checklist

  • No game data
  • Tests run
  • AI-assisted (Claude Code)

🤖 Generated with Claude Code

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted verification of D3D-29 on native Windows 11 Pro (build 26200). I checked the open PR head 75ef6e193826f0ecec13fb325e02478941f30dcc against upstream main at 89b047cd8fab50675a43d76722a6a8a881f55dc2, which is also the head's merge base.

The stock d3d12_mesh_test target built with MSVC x64 19.38.33145, Windows SDK 10.0.26100.0, CMake 4.4.4 and Ninja 1.13.2. Vulkan SDK 1.4.363.0 glslang 16.6.0 compiled the three synthetic shaders. SPIRV-Tools 2026.4 spirv-val passed for ms_draw at Vulkan 1.2 and for ps_draw and vs_fullscreen at Vulkan 1.3. CTest registers the stock executable as d3d12_mesh with SKIP_RETURN_CODE=77. I inspected that registration and used a separate ignored valid-only copy for execution.

Native adapter DispatchMesh(2,2,1) red DispatchMesh(1,1,2) green VS stream control yellow Clear blue Total matching
GeForce RTX 3080, NVIDIA 616.64, Vulkan 1.4.351 1,024 512 1,024 1,536 4,096/4,096
Radeon(TM) Graphics iGPU (1002:13c0), AMD 25.10.30.02, Vulkan 1.4.315 1,024 512 1,024 1,536 4,096/4,096

Both physical adapters exposed VK_EXT_mesh_shader and meshShader=1. Before creating the PSOs, the harness checked the dispatch axes and total, the 32×1×1 local size, the 4-vertex/2-primitive outputs, the output storage, the 144-byte push constants and the RGBA8 target. NVIDIA reported dispatch-axis limits of 4,194,304 / 65,535 / 65,535 and total 4,194,304, and AMD reported 4,294,967,295 / 65,535 / 65,535 and total 4,294,966,272. Local invocation limits were 128 and 256 respectively, and both reported limits of 256 output vertices and 256 output primitives. The successfully created devices had the extension and meshShader enabled, taskShader=0, and a resolved vkCmdDrawMeshTasksEXT. The layer reported Mesh Shader Tier 1 and created both the mesh and VS state-stream PSOs.

The two headless runs were serial, each with a single process-local ICD, an empty implicit-layer search path and Khronos synchronization validation 1.4.363. Both exited 0 with zero validation warnings or errors through cleanup. The GPU scope was the two legal mesh grids and one ordinary VS draw through Leonida's D3D12-to-Vulkan path via the Xbox ABI proxy. The stock executable, refusal and wrong-kind cases, empty and oversized dispatches, amplification, the standalone device path and Microsoft's D3D12 GPU backend were outside the execution scope. Both physical adapters supported the feature, so the capability-only unsupported-adapter skip did not trigger. The fixtures used synthetic shaders and the detached review worktree has no tracked changes.

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

Revu le head 75ef6e1 : le parseur de stream aligne et borne les sous-objets, les PSO MS omettent bien vertex-input/input-assembly et DispatchMesh conserve les comptes x/y/z; le test synthétique couvre sorties pixel, limites et mauvais type de draw. Les rapports RX 9060 XT et validation sont positifs, CI encore en attente. Limite à garder visible : D3D12_MESH_SHADER_TIER_1 déclare supportés les mesh shaders et les amplification shaders, tandis que ce code refuse AS; Microsoft le définit ainsi : https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_mesh_shader_tier. La portée est donc la compatibilité de la charge actuelle, dont le rapport indique qu’elle n’a pas d’AS.

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

The stream parser's duplicate check uses the raw enum. In a CPU fixture built from the exact parser at 75ef6e1, one depth-stencil object was accepted and two identical depth-stencil objects returned E_INVALIDARG. A stream containing DEPTH_STENCIL and DEPTH_STENCIL1 returned S_OK in both orders.

Microsoft's pipeline-state-stream contract explicitly lists those versions as duplicates. Could the seen check use the base subobject type for versioned depth-stencil and rasterizer objects while payload parsing still uses the original type? A mixed-version negative case would cover this.

MSVC 19.44 on Windows, parser only, synthetic data, no GPU. AI-assisted.

@Gen800

Gen800 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent verification of 75ef6e193826f0ecec13fb325e02478941f30dcc against its base 89b047cd8fab50675a43d76722a6a8a881f55dc2 (both built from scratch). These results cover only those two commits, not newer main.

Setup: NVIDIA GeForce RTX 5060 Ti, driver 621.14 (Vulkan 1.4.357), Windows 11; MSVC 19.44, Ninja 1.13.2, CMake 4.4.4, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8. VK_EXT_mesh_shader with meshShader is available. Implicit layers disabled (VK_LOADER_LAYERS_DISABLE=~implicit~).

Results

Check base 89b047cd PR 75ef6e19
d3d12_mesh n/a pass, 4096/4096 pixels
d3d12_mesh with LEONIDA_VK_VALIDATION=1 n/a pass, 0 validation messages (VK_LAYER_KHRONOS_validation confirmed inserted via VK_LOADER_DEBUG=layer)
full ctest 97/98 98/99 (the new d3d12_mesh passes)
D3D12/Vulkan ctest subset under validation 50/51 51/52, no new validation messages
scripts/run_gpu_tests.py 127/166, 39 skipped, 0 failed 127/166, 39 skipped, 0 failed; the same verdict for every one of the 166 tests
tests/semantic n/a 1,450 OK, 2 skipped

A reproducible validation error: PIPELINE_STATISTICS + DispatchMesh

A pipeline-statistics query open around a mesh draw trips VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076. The statistics query pool is always created with kPipelineStatistics = 0x7ff (d3d12_vulkan_device.cpp:2980), which includes the input-assembly, vertex, geometry, clipping and tessellation counters that Vulkan forbids in an active query during vkCmdDrawMeshTasksEXT. D3D12 allows the query; those counters just read 0 for mesh work.

Synthetic repro, a local scratch edit of d3d12_mesh_test.cpp (no game data):

  • set info.pipeline_statistics_query = d.pipeline_statistics_query in device_info, so the heap can be created;
  • CreateQueryHeap(D3D12_QUERY_HEAP_TYPE_PIPELINE_STATISTICS, 1), then BeginQuery(..., D3D12_QUERY_TYPE_PIPELINE_STATISTICS, 0) / EndQuery around the existing DispatchMesh(2, 2, 1);
  • run with LEONIDA_VK_VALIDATION=1: one error, VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076, and the test exits 1.

The PR's own test doesn't open a statistics query, so it doesn't reach this. Would you rather handle it in this PR, or track it as a follow-up? Possible approaches: end and restart the statistics query around mesh draws with a mesh-compatible pool, reporting 0 for the IA/VS/GS fields; or refuse it with a log, as for amplification shaders.

Not from this PR: d3d12_draw fails intermittently on both the base and the PR (bundle blend pixel (0, 0): got 255,0,0,255, expected red 64): 26/30 runs on 89b047cd, 29/30 with this PR. It comes from a fence-value race in the bundle-blend check that #1660 added, which #1793 addresses.

AI-assisted (Claude Code).

@IAmNotSiob

Copy link
Copy Markdown
Contributor

rebased this onto current main for you ^^ branch: IAmNotSiob:mesh-rebase (a383037, your commits + a merge of main + one fix). i didn't push to your branch:

git fetch https://github.com/IAmNotSiob/Leonida mesh-rebase
git merge FETCH_HEAD
  • conflicts: d3d12_vulkan_device.cpp (your CreatePipelineState next to main's new CreatePipelineLibrary, kept both) and CMakeLists.txt (your d3d12_mesh_test block next to main's d3d12_set0_compute_test, kept both, skip message lists all four)
  • one fix git didn't flag: vk_test_device.h chained the mesh features off enable13.pNext, but main replaced enable13 with leonida::Vulkan13Features. it now goes through *v13_.next(), which the header documents as the replacement

tested, Windows 10 22H2, NVIDIA RTX 6000 Ada (582.70), MSVC 2022, llvm-mc 23.1.5, glslang + SPIRV-Tools built from main:

  • d3d12_mesh pass
  • full ctest: 117/117 (the skips are the game-file tests)

with #1865 (also rebased, see there) this would be M5's whole synthetic part \o/

TL;DR: rebased onto main, fixed one silent break (a renamed feature-chain variable), and mesh shaders pass on Win10 + RTX 6000 Ada with the full suite green. AI-assisted (Claude Code).

@LloydNicholson

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews and the Windows runs. I've rebased onto main 4eb6155 and pushed:

  • Rebase: CreatePipelineState now sits next to main's CreatePipelineLibrary, and the d3d12_mesh_test CMake block next to d3d12_set0_compute_test / d3d12_pipeline_library_test.
    • Thanks, IAmNotSiob: your branch showed the change git didn't flag. vk_test_device.h now chains the mesh features through *v13_.next(), like you did. I rebased rather than merging, so the PR stays as two commits.
  • Vonsek, versioned duplicates: fixed in 6895f1b.
    • The seen check now uses the base type for DEPTH_STENCIL1/2 and RASTERIZER1/2, and the payload is still parsed by the original type.
    • d3d12_mesh_test adds four cases: DEPTH_STENCIL with DEPTH_STENCIL1 in both orders, and RASTERIZER with RASTERIZER2, each giving E_INVALIDARG; and each of the four descriptions alone, giving S_OK.
    • With the old check put back, the test fails at the first mixed case.
  • Windows CI: d3d12_mesh failed on the runner without a GPU at d.create(). It now exits 77 there, like d3d12_draw_test. The other failed jobs fail on main too: linux-gpu-tools doesn't compile vk_test_device.h (VkPhysicalDeviceSwapchainMaintenance1FeaturesKHR), and check fails the AssetsPoolsTest path-separator tests.
  • Gen800, pipeline statistics with DispatchMesh (VUID 07076): thanks for the repro. I'd rather keep it out of this PR and post it in the coordination issue as a follow-up.
    • D3D12 allows the query and reads 0 for the IA/VS/GS/HS/DS counters on mesh work.
    • A Vulkan pool with those bits can't be active around vkCmdDrawMeshTasksEXT. Fixing it means either a second, mesh-compatible pool, or ending and restarting the query around mesh draws and merging the results.
    • Neither is small, and refusing would break a legal D3D12 pattern.
  • Flyander, tier 1 vs amplification: agreed. Tier 1 promises AS too, and this PR refuses AS with E_NOTIMPL. That's fine for the current corpus, which has 9,282 mesh shaders and no AS. docs/d3d12_vulkan.md §3.6 says so, and adding AS is a separate item.

Tested after the rebase: RX 9060 XT, RADV (Mesa 27.0.0-devel), Wine 11.22, clang-cl 22 cross-build.

  • d3d12_mesh passes, all 4096/4096 pixels, with 9 streams refused as invalid and 2 as not implemented. It has no validation messages under VK_LAYER_KHRONOS_validation.
  • Of the 33 d3d12_* tests, 4 fail. All 4 fail on main 4eb6155 in the same run: d3d12_clear, d3d12_draw (bundle blend, Tests: wait for the bundle blend draws in d3d12_draw (fence 21, not 4) #1793), d3d12_present and d3d12_xdxr_rt. The rest pass or skip.
  • Not tested: Windows/MSVC after this rebase. The earlier Windows runs above were on 75ef6e1.

AI-assisted (Claude Code).

@enzornd19

Copy link
Copy Markdown

Tested 6895f1b on RTX 5060 Ti (Blackwell), NVIDIA 621.01, Windows 11 Pro (build 26300), MSVC 19.44 + Ninja, on top of main 4eb6155: pass.

  • d3d12_mesh: mesh tier 1; mesh and VS PSOs from pipeline state streams (9 refused as invalid, 2 as not implemented); DispatchMesh over X, Y and Z and a stream VS draw matched all 4096 pixels; --repeat until-fail:5 passes 5/5. The 9 refusals include the new versioned-duplicate cases.
  • Full ctest: 110/111; the only failure is d3d12_draw's bundle blend check, which fails the same way on plain main (fence 21 vs 30, see fix(test): use monotonic fence value (31) for bundle blend pass in d3d12_draw_test #1807). With that line at 31, d3d12_draw passes 5/5 with this PR too.
  • Builds clean apart from MSVC C4324 (structure padded due to alignment) on the Subobject<DEPTH_STENCIL1, D3D12_DEPTH_STENCIL_DESC1> instantiation in d3d12_mesh_test.cpp:44, harmless.

No game files. AI-assisted.

@RipcuBAN

Copy link
Copy Markdown
Contributor

Tested head 6895f1bd on Windows 10 22H2, MSVC (VS 2026, v180), Vulkan-Headers fetched, glslang from MSYS2. Same build of current main (49475796) for comparison.

RTX 3060, driver 621.14 (wave32, 256 B push constants): d3d12_mesh passes: tier 1, "DispatchMesh over X, Y and Z and a stream VS draw matched all 4096 pixels". Full ctest: 100/102, failing d3d12_draw and d3d12_depth_resolve. On main both pass (main fails only d3d12_vulkan_device). d3d12_draw stops at:

bundle blend pixel (0, 0): got 127,0,127,255, expected red 64

The PR is based on 4eb6155d and conflicts with main, so this may be the old base rather than the PR. Worth checking after the rebase.

AMD Radeon iGPU (Raphael, gfx1036, 23.40.02, wave64, maxPushConstantsSize = 128): d3d12_mesh fails at line 206 (create(mesh_stream)), although the extension and meshShader are present and tier 1 is reported. The log shows why:

[rt] d3d12: pipelines need 144 bytes of push constants (uniform-buffer fallback not built yet); maxPushConstantsSize 128
[rt] d3d12: mesh-shader PSOs need VK_EXT_mesh_shader, which the device has not enabled; stage 1

So the refusal comes from the push-constant limit, but the message blames the extension. Suggestion: return 77 (skip) when the device is under 144 B, as the other pipeline tests do on such devices, and make the log line name the actual reason. On main the same device fails d3d12_compute, d3d12_draw, d3d12_pipeline_library and others for the same 128 B reason, so that limit is not caused by this PR.

@Gabzinnn12

Copy link
Copy Markdown

Tested 47e8b42 on AMD Radeon RX 7600 (RDNA3), AMD 26.11.2 (LLPC), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8: pass.

  • d3d12_mesh_test: exit 0 with and without LEONIDA_VK_VALIDATION=1 (+ VK_LAYER_VALIDATE_SYNC=1), no Vulkan validation errors reported. Mesh tier 1; 9 stream PSOs refused as invalid and 2 as not implemented; DispatchMesh over X, Y and Z and a stream VS draw matched all 4096 pixels; wrong-kind draws fail at execution and oversized grids at Close.
  • d3d12_m2_textured, d3d12_m3_frame, d3d12_m4_compute, d3d12_translated_draw, d3d12_buffer_uav, d3d12_draw, d3d12_compute, d3d12_vulkan_device, d3d12_indirect_rt, d3d12_state_map: exit 0 in both modes, no validation errors reported.
  • ctest: 0 failed out of 125 (119 passed, 6 skipped: shader_library_corpus, bink_decode, fsr_dispatch, bvh_builder, bink_audio, vk_sync_validation; gameinput disabled). Main 4947579 on this machine: 0 failed out of 124 (118 passed, the same 6 skipped).

AI-assisted (Claude Code, reviewed with Codex). No game files.

@RipcuBAN

Copy link
Copy Markdown
Contributor

Retest of the rebased head 47e8b421 on the Ryzen 5 7600X iGPU requested earlier. This replaces my report on the older 6895f1bd. AI-assisted run; synthetic shaders only, no game files.

Hardware / environment. Windows 10 build 19045, VS 2026 Community (Visual Studio 18 2026, x64), MSVC 19.51.36260, CMake 4.5.0-rc3, MSYS2 glslangValidator. Fresh build in a new build directory, 0 errors. main 49475796 was built and run on the same machine for comparison.

  • AMD Radeon(TM) Graphics, Ryzen 5 7600X iGPU (Raphael, gfx1036 / RDNA2), driver 23.40.02, wave64, maxPushConstantsSize = 128.
  • NVIDIA GeForce RTX 3060, driver 621.14, wave32, maxPushConstantsSize = 256.

Full ctest -C RelWithDebInfo -j 6 --output-on-failure:

tree AMD iGPU (128 B) RTX 3060 (256 B)
main 49475796 99/107; 8 failed 106/107; 1 failed
PR 47e8b421 99/108; 9 failed 107/108; 1 failed

RTX 3060: d3d12_mesh passes: mesh tier 1; mesh and VS PSOs from pipeline state streams (9 refused as invalid, 2 as not implemented); DispatchMesh over X, Y and Z and a stream VS draw matched all 4096 pixels. The only full-suite failure is d3d12_vulkan_device, exactly as on main. The older d3d12_draw bundle-blend failure did not reproduce in this run; it is the known intermittent fence race (#1793).

AMD iGPU: d3d12_mesh still fails at d3d12_mesh_test.cpp:206 (SUCCEEDED(create(device.p, mesh_stream, mesh_pso))) with pipelines need 144 bytes of push constants (uniform-buffer fallback not built yet); maxPushConstantsSize 128. The other eight failures are unchanged from main.

One correction to my earlier report: mesh-shader PSOs need VK_EXT_mesh_shader, which the device has not enabled; stage 1 is not the reason the real-device PSO fails. It comes from the intentional no-extension device created at d3d12_mesh_test.cpp:170-181; the real device here has VK_EXT_mesh_shader, meshShader=1 and reports tier 1. The new if (!d.mesh_shader) return 77 at lines 185-189 only skips a device that lacks the extension (or has no device), not a device below 144 push-constant bytes.

So the requested 128-byte skip still needs to be added after the tier check (query device_push_constants_need_fallback(device.p) / max_push_constants_size, print the push-constant reason and return 77), or the mesh fixture needs a --pc-tail-ubo variant. This is not a regression: on AMD the PR adds one failing test while all eight pre-existing failures remain identical.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head 47e8b42 merged onto main 4947579 (clean merge), full build, full ctest -C Release -j 4: 100% tests passed out of 117 | new failures vs main: none. The main baseline on the same machine passes 116/116, so nothing regresses here.

AI-assisted (Claude Code); runs on my machine.

@zneel

zneel commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Update to my earlier note (no action needed from me): main has moved to 3faac557, and this PR now conflicts with it in 7 files. I resolved it again for #3777. The merge is 64e51cce on zneel:m5-mesh; I haven't pushed anything to your branch. Two parts go beyond keeping both sides:

  • DispatchMesh (runtime/shims/d3d12_com.cpp): main moved the render targets, vertex buffers and render_target_count out of Draw into a shared DrawViews block (draw_views()). Bundles now record through defer(...) and replay at ExecuteBundle.
    • DispatchMesh keeps your grid checks, then if (defer([=](GraphicsCommandList& l) { l.record_mesh_draw(x, y, z); }, true)) return; record_mesh_draw(x, y, z);, as DrawInstanced does.
    • record_mesh_draw has your pipeline and viewport checks and builds Draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, {}, 0, viewport_, ...} with mesh = true.
    • Without the defer, a DispatchMesh in a bundle would be recorded into the bundle's own list instead of being replayed.
  • runtime/src/command_list.h: Draw keeps your bool mesh after first_instance. Your comment goes on Draw, main's on the new DrawViews.

Both sides kept:

  • d3d12_vulkan_device.cpp: create_graphics has main's comment (it is now VS (+ GS) (+ PS)), then your mesh paragraph and signature.
  • shader_library.h: your max_vertices/max_primitives next to main's literal_samplers, in the entry and in the JSON reading.
  • The rest: vulkan_backend.h (with vkCmdDrawMeshTasksEXT), vulkan_replay.h (as in the last note), CMakeLists.txt and vk_test_device.h.

Built on top of that, on an RX 9070 XT (AMD 26.11.2, Windows 11, Ryzen 7 9800X3D / 64 GB):

  • d3d12_mesh passes, also with the validation layer.
  • Full ctest of the stacked branch: 180/180, without d3d12_present.

AI-assisted (Claude Code).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 9c4bff4 on NVIDIA GeForce RTX 4080, driver 617.42, Windows 11 (clang-cl cross-build, a native Windows run rather than Wine): d3d12_mesh_test, d3d12_draw_test and d3d12_vulkan_device_test all exit 0. None of the three prints a pass summary, so the pass rests on exit codes, and the "all 4096 pixels" check is not visible in this run. d3d12_mesh_test logs the refusals "unknown pipeline state stream subobject type: 23", "amplification shaders are not supported" and "draw kind does not match the pipeline (mesh or vertex); nothing was submitted". I did not run main.

AI-assisted.

@dracbat

dracbat commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 9c4bff42 merged with main 3faac557 for the test (clean merge) on an AMD Radeon RX 5700 (RDNA1, gfx1010: no VK_EXT_mesh_shader, no fragmentShaderBarycentric), AMD Adrenalin 26.11.2 (Windows driver 32.0.21045.29003, Vulkan 1.4.315), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.1, llvm-mc 21.1.8, Ninja, RelWithDebInfo: pass. The earlier AMD runs here were on RDNA3/RDNA4 GPUs, which have the extension. This one is the AMD Windows driver on a GPU that doesn't.

  • Build: clean. The only new warnings are the two C4324 at runtime/test/d3d12_mesh_test.cpp:44 mentioned above.

  • d3d12_mesh: its no-extension check passes (MeshShaderTier is NOT_SUPPORTED, and the MS + PS stream PSO is refused with E_NOTIMPL), then it skips (77). Same with and without LEONIDA_VK_VALIDATION=1.

  • Neighbouring tests, with and without LEONIDA_VK_VALIDATION=1: all pass, 0 VUID lines.

    • d3d12_draw (M1, strip cut, 4x MSAA, step rate);
    • d3d12_translated_draw (M1.5: 4064 of 4096 exact, 32 edge pixels);
    • d3d12_pipeline_library, d3d12_vulkan_device and replay_cpu_bench_selftest.
  • Full ctest -j 2 -E "d3d12_present|vk_presenter_sync|xbox_present":

    • Without validation: 176 of 176 (166 passed, 10 skipped). The skips are the game-file and optional-tool tests, vk_sync_validation, d3d12_rgb9e5_rtv (no RGB9E5 render targets on this GPU) and d3d12_mesh.
    • With LEONIDA_VK_VALIDATION=1: 176 of 176 (167 passed, 9 skipped), 0 VUID lines.
    • main 3faac557 on this machine: 175 of 175, with the same skips.
    • tests/test_docs_links.py, test_ctest_registration.py and test_docs_repo_paths.py: 12 passed. git diff --check is clean.
  • A coverage gap on GPUs like this one (checked locally, not part of the PR): without the extension the test returns 77 before it creates the VS + PS stream PSO. So CreatePipelineState for an ordinary vertex pipeline never runs on RDNA1, Pascal or Intel UHD, where every stream PSO a title creates takes that path. I built a copy of the test whose no-extension branch runs the VS half instead of returning:

    • the same root signature and VS + PS stream;
    • five streams that need no extension, each refused with E_INVALIDARG: a PS twice, a CS with graphics stages, a stream cut 4 bytes short, subobject type 23, and an MS with a VS;
    • DEPTH_STENCIL1 and RASTERIZER2 alone, both accepted;
    • the stream VS draw through the bottom-left viewport over a blue clear.

    All 4,096 pixels matched, with and without validation (0 messages). Running that half on every GPU and skipping only the mesh part would keep the stream path covered where mesh shaders are missing.

AI-assisted (Claude Code).

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

Validation: Windows 11, MSVC 19.44.35228, Ninja, Vulkan 1.4.363

Head 9c4bff4 (OPEN, MERGEABLE), detached worktree under %TEMP%\opencode\review-1712; main 3faac55.

Configure/build cmake -S runtime -B <build> -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DVulkan_INCLUDE_DIR=C:/VulkanSDK/1.4.363.0/Include -DVulkan_LIBRARY=C:/VulkanSDK/1.4.363.0/Lib/vulkan-1.lib -DVulkan_GLSLANG_VALIDATOR_EXECUTABLE=C:/VulkanSDK/1.4.363.0/Bin/glslangValidator.exe (added so d3d12_mesh_test builds). cmake --build <build> --target d3d12_mesh_test d3d12_draw_test d3d12_vulkan_device_test d3d12_compute_test replay_cpu_bench: exit 0 (only C4324 alignas warnings).

Tests LEONIDA_VK_DEVICE='RTX 5070 Ti' ctest -R "^(d3d12_mesh|d3d12_draw|d3d12_compute|d3d12_vulkan_device)$" --output-on-failure: 4/4 passed, exit 0. d3d12_mesh_test directly: exit 0, "mesh tier 1", 4096/4096 pixels, 9 invalid + 2 E_NOTIMPL stream refusals, wrong-kind draws invalid_draw, oversized grids fail Close. Validation on (LEONIDA_VK_VALIDATION=1): exit 0, no validation messages. replay_cpu_bench --self-test: exit 0. git diff --check: exit 0.

Tier finding: MeshShaderTier lives in D3D12_FEATURE_DATA_D3D12_OPTIONS7, not OPTIONS5 (OPTIONS5 has no mesh field). Main's hardcode at runtime/shims/d3d12_vulkan_device.cpp:6469 was inside the OPTIONS7 case; this PR sets D3D12_MESH_SHADER_TIER_1 when info.mesh_shader, NOT_SUPPORTED otherwise. Verified independently: a probe against create_vulkan_device_standalone (the D3D12XboxCreateDevice path under LEONIDA_D3D12=vulkan) returned OPTIONS7 hr=0 MeshShaderTier=10 (D3D12_MESH_SHADER_TIER_1 is 10, not 1). So the tier is genuinely non-zero on the game path, not only in the test.

Coverage: verified direct MS+PS PSO from a d3dx12 stream, 3D DispatchMesh counts (X, Y, Z), a VS PSO from a stream, and pixel output. Not verified: translated game mesh shaders or any game data (test is synthetic), 3D-grid flattening (open), amplification shaders (refused despite TIER_1 nominally including them — fine for this corpus, not spec-complete), and ExecuteIndirect DISPATCH_MESH (CreateCommandSignature still returns E_NOTIMPL). runtime/test/shaders/ms_* were not run: they are translator GPU tests and need llvm-mc, absent here; they do not touch this diff.

Overlaps: git merge-tree --write-tree --name-only vs #4408 (draft, already CONFLICTING, head fdd4667): 9 content conflicts — docs/d3d12_vulkan.md, docs/design.md, runtime/CMakeLists.txt, d3d12_com.cpp, d3d12_vulkan_device.cpp, command_list.h, shader_library.h, vulkan_backend.h, vulkan_replay.h. Vs #3777 (MERGEABLE, head a7b25c6): 5 conflicts — docs/d3d12_vulkan.md, runtime/CMakeLists.txt, d3d12_com.cpp, vulkan_backend.h, vulkan_replay.h. #3777's indirect mesh is complementary and still needed if the game uses it; #4408 remains the no-extension fallback and will need a rebase.

Verdict: no blocker for the direct VK_EXT_mesh_shader path; tier is reported TIER_1 on the RTX 5070 Ti and the implementation is internally consistent. Mergeable, but #3777/#4408 must be rebased, and end-to-end game rendering remains unverified.

LloydNicholson and others added 2 commits November 23, 2026 13:41
…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>

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

Retest at c237639 (OPEN, MERGEABLE): confirms it contains current main 561b65a83.

Delta 9c4bff4..c237639: 868 files, but that is main moving 3faa→561b under the rebase. PR-only content is unchanged: both patches are 13 files, +929/−34; the second commit is identical (range-diff shows =), the first differs only in surrounding context, and d3d12_mesh_test.cpp/ms_draw.mesh are byte-identical. Tier code is still D3D12_FEATURE_D3D12_OPTIONS7 → D3D12_MESH_SHADER_TIER_1 (line 7139); DispatchMesh/draw_mesh_tasks/invalid_draw are intact.

Commands: rebuilt d3d12_mesh_test d3d12_draw_test d3d12_vulkan_device_test d3d12_compute_test — exit 0. LEONIDA_VK_DEVICE='RTX 5070 Ti' ctest -R "^(d3d12_mesh|d3d12_draw|d3d12_compute|d3d12_vulkan_device)$" — 4/4 passed, exit 0. d3d12_mesh_test direct — exit 0, 4096/4096 pixels, "mesh tier 1". Validation-on rerun — exit 0, no messages. git diff --check — exit 0.

Standalone/game path probe against the rebuilt library: OPTIONS7 hr=0 MeshShaderTier=10 (D3D12_MESH_SHADER_TIER_1), unchanged.

Verdict: earlier verdict still holds — no blocker for the direct mesh path; #3777 (indirect mesh) and #4408 (no-extension fallback) still need coordination. No new issues from the rebase.

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Tested c2376390's ID3D12Device2::CreatePipelineState for graphics PSOs with a differential fuzzer: #5637's d3d12_pso_fuzz_test in its new --stream mode, claimed in #313. RTX 5060 Ti / 621.14, Windows 11 26300, MSVC 14.51, Vulkan SDK 1.4.363.0. The reference is the host's D3D12 on the same GPU, and the layer is the runtime's standalone device.

Each seed draws 1-5 batches through PSOs with random state:

  • blend: every non-dual-source factor and op, write masks, a second target with IndependentBlendEnable, and the sixteen logic ops on UINT targets;
  • depth-stencil: every function and stencil op, on both faces;
  • rasterizer: cull, winding, depth clip.

In --stream mode every PSO is built from a pipeline-state stream on both sides. The stream has:

  • subobjects: root signature, VS, PS, input layout, topology, RT formats, blend, sample mask, rasterizer, depth-stencil, DSV format and sample desc;
  • order: random;
  • omissions: a subobject equal to its default is left out half the time, so the defaults are exercised;
  • depth-stencil: DEPTH_STENCIL or DEPTH_STENCIL1 (depth bounds off), alternately.
1,000 seeds on this PR's head result
--stream against NVIDIA's D3D12 0 differ, 0 refused
--stream against the same seeds through CreateGraphicsPipelineState on the layer identical, seed for seed (1,000 of 1,000 lines)
--stream on main 3faac557 every PSO refused (expected: no CreatePipelineState there)

So the stream parser gives exactly what the desc path gives, over every combination the fuzzer reaches, including the omitted-subobject defaults and DEPTH_STENCIL1. Not exercised: mesh streams, AS, depth bounds on, DEPTH_STENCIL2, view instancing (this PR refuses the last three by design) and cached PSOs.

AI-assisted (Claude Code).

Exopus-0x65f7ad0 added a commit to Exopus-0x65f7ad0/Leonida that referenced this pull request Nov 23, 2026
…State; exact clears

--stream creates each PSO from a pipeline-state stream (d3dx12.h layout) on both the layer and the
reference: subobjects in a random order, one equal to its default left out half the time, and
DEPTH_STENCIL or DEPTH_STENCIL1 alternately. The stream layout comes from its own generator, so the
programs are the same as without --stream. On main every PSO is refused (no CreatePipelineState
yet). On ItsNotRexed#1712 (D3D-29), 1,000 seeds give 0 differences, and the results match the desc path seed
for seed.

UNORM targets are now cleared to 0 or 1 per channel. A clear value between two codes rounds by the
clear's rules, which d3d12_clear_fuzz_test checks and where NVIDIA's D3D12 and D3D12's ties-to-even
part (a 2-bit alpha of 0.5); this test checks the draws.

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

Copy link
Copy Markdown

Verified c2376390a on the integrated Radeon of a Ryzen 7 9800X3D, explicitly selected on a dual-GPU CachyOS machine. RADV reports RAPHAEL_MENDOCINO, Mesa 26.3.1, mesh tier 1, and a default subgroup size of 64. I cross-built d3d12_mesh_test with clang-cl 23.1.5 and xwin.

The same test executable passed under Wine 11.22 and GE-Proton10-34 (umu-launcher 1.4.3). For both runs, the X/Y/Z mesh dispatches and the vertex-shader draw matched the reference on all 4,096 pixels, with host exit 0. The test also exercised its nine invalid and two unimplemented pipeline-stream cases and its wrong-pipeline and oversized-grid checks.

Synthetic fixtures only. AI-assisted.

@zneel

zneel commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks for rebasing onto main 561b65a8. #3777 now merges c2376390 unchanged (a clean merge), so your two commits are ancestors there and #3777 carries no second copy of them.

One point from my earlier note isn't in this head: DispatchMesh doesn't go through defer().

  • main's bundles record their commands through defer(...) and replay them at ExecuteBundle, as DrawInstanced does.
  • Without it, a DispatchMesh in a bundle goes into the bundle's own command list and is never replayed.
  • Runtime: ExecuteIndirect with DISPATCH_MESH signatures and the M5 mesh gate (translated mesh shader) #3777 carries the fix as 7c6d99a2 (runtime/shims/d3d12_com.cpp, +12/-6). DispatchMesh keeps your grid checks, then if (defer([=](GraphicsCommandList& l) { l.record_mesh_draw(x, y, z); }, true)) return; record_mesh_draw(x, y, z);. record_mesh_draw has your pipeline and viewport checks and builds the same Draw.

Please take it if you agree; if you do, I'll drop it from #3777.

On an RX 9070 XT (AMD 26.11.2, Windows 11, Ryzen 7 9800X3D / 64 GB), with it applied: d3d12_mesh and d3d12_bundle pass with the validation layer.

AI-assisted (Claude Code).

@lines9686-rgb

Copy link
Copy Markdown
Contributor

Tested c237639 (it already contains main 561b65a8) on Windows 11 (26200), RTX 3060 Ti (Ampere, NVIDIA 610.88), MSVC, Ninja RelWithDebInfo: pass, no regression. ctest 246/248 on the PR and 245/247 on main alone at the same commit; the only difference is the PR's d3d12_mesh, which passes. The two failures are on main too and not from this PR: d3d12_indirect_dispatch_count (#5792) and d3d12_indirect_rt (the ARRAY_OF_POINTERS overflow check from cc4b374; fix in a separate PR). Same 12 skips on both (package-gated, gameinput disabled, vk_sync_validation, d3d12_rgb9e5_rtv, d3d12_boot_movie, d3d12_first_light). No game files. AI-assisted (Claude Code).

@Stalkerino

Copy link
Copy Markdown

I checked whether the bundle fix from #3777 can move into this PR on its own. On #1712 at c2376390, the synthetic test fails at bundle->Close(). Applying just zneel's 7c6d99a2 to that same base makes the test pass, with 4,096/4,096 pixels matching the CPU reference under Wine 11.22.

The test-only commit c44f6e3b is based directly on this PR and can be cherry-picked with the fix. It records DispatchMesh(1,1,1) once and executes the same closed bundle twice. The parent changes the two position constants and the tint CBV between executions. Readback checks the two distinct 16×16 tiles, the clear pixels between them, and the existing direct draws.

I also ran the fixture on the parent of the fix (7ca3311ff) and the rebased #3777 (f8b197868) under both Wine and Proton-CachyOS 11.0-20261015 SLR. Both runners fail at bundle close on the parent and pass the full readback on the rebased PR. CachyOS, Ryzen 7 9800X3D integrated Radeon, RADV RAPHAEL_MENDOCINO, Mesa 26.3.1. Synthetic shaders only. 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.