Repository navigation
D3D-635: run compute-translated mesh shaders on mesh-capable GPUs - #6241
Stalkerino wants to merge 32 commits into
Conversation
…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>
…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.
Use the compute and vertex pipelines for mesh programs built with --mesh-compute even when native mesh support is enabled. Prefer a native translation when both forms exist on a mesh-capable device. Exercise direct, indirect and GPU-written mesh commands with the extension exposed. AI-assisted.
|
Tested
Once in that full run, Wine printed an unhandled page fault at process exit after the test had already reported (in |
|
Independent Windows check of ab7f46b6 on 561b65a8, stacked on #5899 at be2a10e4. Windows 11 x64, RTX 3080 Ti, MSVC 19.44, LLVM MC 23.1.6, Vulkan SDK 1.4.363.0.
These runs covered the compute path with wave64 emulation and one shader entry at a time. The test fixture omitted invalid-signature and wrong-pipeline probes. Runtime code and shader sources matched the published revision. Synthetic inputs only. AI-assisted. |
Hiiva
left a comment
There was a problem hiding this comment.
Scoped Windows review at ab7f46b6256c46edae9f1efcdf0dc2005e340c0d, against the exact #5899 parent be2a10e4f439bc159f11fcb661f2109c696bbe66. The compute translation now runs successfully with VK_EXT_mesh_shader exposed on an RTX 4080. No actionable finding in this selection change.
Environment: Windows 11 Pro build 26200, NVIDIA GeForce RTX 4080 driver 610.62 (32.0.16.1062), MSVC 19.44.35228, Windows SDK 10.0.26100, Vulkan SDK 1.4.363. The normal LLVM 21.1.8 AMDGPU plus SPIRV-Tools fixture pipeline was used. Core and synchronization validation were requested, the logs confirm the selected RTX 4080 and validation enabled, and all four GPU processes produced zero VUID, synchronization-hazard, or validation-error diagnostics.
| Control | Result |
|---|---|
Unmodified d3d12_m5_mesh_compute_with_ext CTest |
Pass. Direct DispatchMesh: 0 mismatched pixels. ExecuteIndirect: 30 records, 0 mismatches. Compute-written arguments: 6 records, 0 mismatches. Wrong-kind indirect draws are rejected as the fixture expects. |
Unmodified d3d12_m5_mesh CTest |
Expected skip: the stock module requires 64-wide mesh subgroups; this RTX reports 32..32. This is not counted as native-mesh execution coverage. |
| Native mesh control | Pass with the same unedited synthetic assembly rebuilt through build.py using LEONIDA_W64_EMULATE=1. The MS entry remains MeshEXT, not GLCompute. The unchanged test executable reports the same direct/30-record/6-record zero-mismatch results. |
| Parent selection negative control | The exact parent plus the head's test selects stage 0x80 (MESH_EXT) for entry model 5 (GLCompute), with mesh support exposed and mesh_compute metadata present. A review-only diagnostic returns immediately before vkCreateShaderModule, so no invalid module/pipeline is submitted. The test then exits 1 at its first mesh-PSO assertion, as expected. |
The head's tracked source and test are unchanged. The parent adaptation consists only of that diagnostic stop and the exact head test needed for --mesh-compute-with-ext; the underlying selection logic is untouched. All 28 generated SPIR-V/FSSM binary files used by the two stock builds match byte-for-byte. For the additional native control, only ignored generated inputs were temporarily exchanged, then restored with every original file hash checked. Its five synthetic FSSM programs also match the stock programs exactly. Both stock five-shader sets and the five-shader emulated-native set passed spirv-val.
This review covers the single D3D-635 selection commit and these bounded controls, not approval of the full #3777/#4408/#5899 dependency stack. The native mesh-stage control uses wave64 emulation on 32-wide Vulkan subgroups; it is not native AMD ISA evidence. No game data, performance claim, mixed-index run, or production fix. AI-assisted.
D3D-635. Coordination claim.
Depends on: #5899, which carries #4408 and #3777. This draft adds one commit on top of #5899 at
be2a10e4. Review the D3D-635 commit.What and why
A library built with
make_game.py --mesh-computestores the MS program as a SPIR-V compute entry point. On a device exposingVK_EXT_mesh_shader, graphics PSO creation picked the native mesh stage before reading the translated entry. This matters when a build is moved between GPUs or a player explicitly chooses the compute translation on a mesh-capable GPU.PSO creation now picks the form of the translated MS program first. A compute entry goes through the compute pass and the generated vertex shader. When both forms of the same program are present, a mesh-capable device prefers the native entry. A device lacking native mesh support prefers the compute entry. The existing compute subgroup, Direct queue and 152-byte push-constant checks still apply.
The new CTest case
d3d12_m5_mesh_compute_with_extexercises direct draws, counted indirect draws and compute-written arguments while exposing native mesh support to Leonida.Tested
CachyOS, Ryzen 7 9800X3D integrated Radeon (RADV RAPHAEL_MENDOCINO, Mesa 26.3.1). Windows RelWithDebInfo cross-built using clang-cl/xwin. Synthetic fixtures only.
be2a10e4with the new test and a diagnostic check immediately before Vulkan shader module creation, the selected graphics stage wasMESH_EXTwhile the SPIR-V entry point wasGLCompute. The diagnostic stopped there.AI-assisted: yes.