Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
820b2a2
M5 synthetic gate: d3d12_m5_world_test (ExecuteIndirect draws, 4-thre…
AlxcBTW Nov 22, 2026
77d86d0
M5 review fixes: raw indirect flag, maxDrawIndirectCount chunking, fe…
AlxcBTW Nov 22, 2026
354a7c3
Merge remote-tracking branch 'origin/main' into m5-synthetic-gate
AlxcBTW Nov 22, 2026
1ca74c0
emit_indirect: 64-bit chunk cursor advanced by the count each call drew
AlxcBTW Nov 22, 2026
e9ef1ed
d3d12_state_map: the chunking mock fails after 8 calls instead of gro…
AlxcBTW Nov 22, 2026
275e506
Merge remote-tracking branch 'origin/main' into m5-synthetic-gate
AlxcBTW Nov 22, 2026
01a7c65
Merge remote-tracking branch 'origin/main' into m5-synthetic-gate
AlxcBTW Nov 22, 2026
00a23e0
vulkan_backend.h: restore the line continuation after the merge
AlxcBTW Nov 22, 2026
9517769
Merge remote-tracking branch 'origin/main' into m5-synthetic-gate
AlxcBTW Nov 22, 2026
773202b
Merge remote-tracking branch 'origin/main' into m5-synthetic-gate
AlxcBTW Nov 22, 2026
dd0b40a
d3d12_m5_world_test: the vertex and instance ids are zero-based now (…
AlxcBTW Nov 22, 2026
9a74588
Merge remote-tracking branch 'origin/main' into m5-synthetic-gate
AlxcBTW Nov 23, 2026
e18b26b
Runtime: mesh-shader PSOs from pipeline state streams and DispatchMes…
LloydNicholson Nov 22, 2026
c237639
D3D-29: versioned depth-stencil/rasterizer subobjects count as duplic…
LloydNicholson Nov 22, 2026
1bb6673
Merge remote-tracking branch 'pr/1712' into m5-mesh-rb3
zneel Nov 23, 2026
7ca3311
Merge remote-tracking branch 'pr/1865' into m5-mesh-rb3
zneel Nov 23, 2026
7c6d99a
DispatchMesh in a bundle: record through defer, as DrawInstanced does
zneel Nov 23, 2026
8fc39ab
Runtime: ExecuteIndirect with DISPATCH_MESH signatures, and the M5 me…
zneel Nov 22, 2026
132e780
docs, tests: DISPATCH_MESH signatures and the M5 mesh gate; build.py …
zneel Nov 22, 2026
5cbe1c6
command_list.h: rewrap the ExecuteIndirect state comment
zneel Nov 22, 2026
5944fec
M5 mesh test: require 64-wide mesh subgroups, skip where unavailable;…
zneel Nov 22, 2026
b8c0e06
docs: the M5 mesh row names the fallback run and the required subgrou…
zneel Nov 22, 2026
b45b41d
Review fixes for the DISPATCH_MESH path and the M5 mesh test
zneel Nov 22, 2026
340fad0
M5 mesh test: the fallback run covers every GPU that runs the test, n…
zneel Nov 22, 2026
f8b1978
M5 mesh test: skip before the mesh PSOs, an exact clear, first-instan…
zneel Nov 23, 2026
ccd3e38
Runtime: mesh PSOs and DispatchMesh without VK_EXT_mesh_shader, throu…
DaniSBR1 Nov 23, 2026
3d46c2b
Mesh compute: review fixes (subgroup guarantee, compute queue, f16 su…
DaniSBR1 Nov 23, 2026
f14cde2
Runtime: ExecuteIndirect(DISPATCH_MESH) without VK_EXT_mesh_shader, t…
flapwarp Nov 23, 2026
cc1285b
d3d12_m5_mesh_test: DISPATCH_MESH arguments a compute shader writes i…
flapwarp Nov 23, 2026
88a1430
mesh_indirect_prepare: address each record in 64 bits
flapwarp Nov 23, 2026
be2a10e
d3d12_m5_mesh_test: build cs_m5_args with the D3D-448 compute user-da…
flapwarp Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 112 additions & 2 deletions docs/d3d12_vulkan.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/design.md

Large diffs are not rendered by default.

160 changes: 158 additions & 2 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,21 @@ if(BUILD_TESTING)
add_test(NAME shader_library COMMAND shader_library_test)
add_executable(spirv_f16_halves_test test/spirv_f16_halves_test.cpp)
add_test(NAME spirv_f16_halves COMMAND spirv_f16_halves_test)
# The vertex shader that draws --mesh-compute slots (mesh_compute_vs.h). The test writes its modules to a folder;
# where the Vulkan SDK's spirv-val is found, each is validated after it.
add_executable(mesh_compute_vs_test test/mesh_compute_vs_test.cpp)
set(LEONIDA_MESH_VS_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated/mesh_compute_vs)
file(MAKE_DIRECTORY ${LEONIDA_MESH_VS_DIR})
add_test(NAME mesh_compute_vs COMMAND mesh_compute_vs_test ${LEONIDA_MESH_VS_DIR})
find_program(LEONIDA_SPIRV_VAL spirv-val HINTS "$ENV{VULKAN_SDK}/Bin" "$ENV{VULKAN_SDK}/bin")
if(LEONIDA_SPIRV_VAL)
set_tests_properties(mesh_compute_vs PROPERTIES FIXTURES_SETUP mesh_compute_vs_modules)
foreach(module small corpus distances f16)
add_test(NAME mesh_compute_vs_val_${module}
COMMAND ${LEONIDA_SPIRV_VAL} --target-env vulkan1.2 ${LEONIDA_MESH_VS_DIR}/${module}.spv)
set_tests_properties(mesh_compute_vs_val_${module} PROPERTIES FIXTURES_REQUIRED mesh_compute_vs_modules)
endforeach()
endif()
# Optional: skips unless LEONIDA_SHADERS names a translated work folder (<work>/shaders/spirv).
add_executable(shader_library_corpus_test test/shader_library_corpus_test.cpp)
add_test(NAME shader_library_corpus COMMAND shader_library_corpus_test)
Expand Down Expand Up @@ -2086,6 +2101,108 @@ if(TARGET Vulkan::Headers)
add_test(NAME d3d12_m3_first_pass COMMAND d3d12_m3_frame_test --first-pass-only)
set_tests_properties(d3d12_m3_frame d3d12_m3_first_pass PROPERTIES SKIP_RETURN_CODE 77)

# M5 (synthetic part, without mesh shaders): ExecuteIndirect draws, command lists recorded on four threads, a
# descriptor table of 5120 SRVs, and a PSO created twice through the device's pipeline cache. vs_m5/ps_m5_inst
# (indirect cells), vs_m3/ps_m5_flat (rectangles from root constants), vs_m2/ps_m5_tex (T# at a byte offset).
set(LEONIDA_M5_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated/m5_shaders)
set(LEONIDA_M5_FILES ${LEONIDA_M5_DIR}/spirv/index.json ${LEONIDA_M5_DIR}/fssm/vs_m5.fssm
${LEONIDA_M5_DIR}/fssm/ps_m5_inst.fssm ${LEONIDA_M5_DIR}/fssm/vs_m3.fssm
${LEONIDA_M5_DIR}/fssm/ps_m5_flat.fssm ${LEONIDA_M5_DIR}/fssm/vs_m2.fssm
${LEONIDA_M5_DIR}/fssm/ps_m5_tex.fssm)
add_custom_command(
OUTPUT ${LEONIDA_M5_FILES}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${LEONIDA_M5_DIR}
COMMAND ${CMAKE_COMMAND} -E env "LLVM_MC=${LEONIDA_LLVM_MC}" "LEONIDA_SPIRV_TOOLS=${LEONIDA_SPIRV_TOOLS_NATIVE}"
$<TARGET_FILE:Python3::Interpreter> -I ${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/build.py
${LEONIDA_M5_DIR} vs_m5 ps_m5_inst vs_m3 ps_m5_flat vs_m2 ps_m5_tex
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/build.py
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/compute_fixture.py
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/vs_m5.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ps_m5_inst.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/vs_m3.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ps_m5_flat.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/vs_m2.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ps_m5_tex.asm
${CMAKE_CURRENT_SOURCE_DIR}/../tools/rdna2spirv.py
COMMENT "Translating vs_m5, ps_m5_inst, vs_m3, ps_m5_flat, vs_m2 and ps_m5_tex for the M5 world test"
VERBATIM)
add_executable(d3d12_m5_world_test test/d3d12_m5_world_test.cpp shims/d3d12_xs_device.cpp ${LEONIDA_M5_FILES})
target_link_libraries(d3d12_m5_world_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(d3d12_m5_world_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX
LEONIDA_TEST_M5_DIR="${LEONIDA_M5_DIR}")
target_compile_options(d3d12_m5_world_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_m5_world COMMAND d3d12_m5_world_test)
set_tests_properties(d3d12_m5_world PROPERTIES SKIP_RETURN_CODE 77)
# M5, the mesh part: ms_m5.asm (a translated NGG wave64 mesh shader; build.py makes its PSV0 container from the
# "psv0:" header) with ps_m5_mesh.asm, drawn by DispatchMesh and by ExecuteIndirect with DISPATCH_MESH
# signatures; vs_m3/ps_m5_flat make the VS PSO of the wrong-kind checks. Exits 77 without VK_EXT_mesh_shader.
set(LEONIDA_M5_MESH_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated/m5_mesh_shaders)
set(LEONIDA_M5_MESH_FILES ${LEONIDA_M5_MESH_DIR}/spirv/index.json ${LEONIDA_M5_MESH_DIR}/fssm/ms_m5.fssm
${LEONIDA_M5_MESH_DIR}/fssm/ps_m5_mesh.fssm ${LEONIDA_M5_MESH_DIR}/fssm/vs_m3.fssm
${LEONIDA_M5_MESH_DIR}/fssm/ps_m5_flat.fssm
${LEONIDA_M5_MESH_DIR}/fssm/cs_m5_args.fssm)
add_custom_command(
OUTPUT ${LEONIDA_M5_MESH_FILES}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${LEONIDA_M5_MESH_DIR}
COMMAND ${CMAKE_COMMAND} -E env "LLVM_MC=${LEONIDA_LLVM_MC}" "LEONIDA_SPIRV_TOOLS=${LEONIDA_SPIRV_TOOLS_NATIVE}"
LEONIDA_USER_DATA_SHIFT=4
$<TARGET_FILE:Python3::Interpreter> -I ${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/build.py
${LEONIDA_M5_MESH_DIR} ms_m5 ps_m5_mesh vs_m3 ps_m5_flat cs_m5_args
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/build.py
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/compute_fixture.py
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ms_m5.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ps_m5_mesh.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/vs_m3.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ps_m5_flat.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/cs_m5_args.asm
${CMAKE_CURRENT_SOURCE_DIR}/../tools/rdna2spirv.py
# LEONIDA_USER_DATA_SHIFT=4 shifts cs_m5_args only (the cs_ fixtures): a D3D12 compute PSO gets its root
# arguments from s4 (D3D-448), as for the M4 shaders.
COMMENT "Translating ms_m5, ps_m5_mesh, vs_m3 and ps_m5_flat for the M5 mesh test"
VERBATIM)
# The same shaders translated with --mesh-compute and --wave64-emulate: the test's --mesh-compute mode runs the
# same draws on a device without VK_EXT_mesh_shader (the layer's own device is created without it, so every
# GPU runs it), DispatchMesh through the mesh-as-compute pass and ExecuteIndirect(DISPATCH_MESH) through the
# prepass of vulkan_mesh_indirect.h.
set(LEONIDA_M5_MESH_COMPUTE_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated/m5_mesh_compute_shaders)
set(LEONIDA_M5_MESH_COMPUTE_FILES ${LEONIDA_M5_MESH_COMPUTE_DIR}/spirv/index.json
${LEONIDA_M5_MESH_COMPUTE_DIR}/fssm/ms_m5.fssm
${LEONIDA_M5_MESH_COMPUTE_DIR}/fssm/ps_m5_mesh.fssm
${LEONIDA_M5_MESH_COMPUTE_DIR}/fssm/vs_m3.fssm
${LEONIDA_M5_MESH_COMPUTE_DIR}/fssm/ps_m5_flat.fssm
${LEONIDA_M5_MESH_COMPUTE_DIR}/fssm/cs_m5_args.fssm)
add_custom_command(
OUTPUT ${LEONIDA_M5_MESH_COMPUTE_FILES}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${LEONIDA_M5_MESH_COMPUTE_DIR}
COMMAND ${CMAKE_COMMAND} -E env "LLVM_MC=${LEONIDA_LLVM_MC}" "LEONIDA_SPIRV_TOOLS=${LEONIDA_SPIRV_TOOLS_NATIVE}"
"LEONIDA_MESH_COMPUTE=1" "LEONIDA_W64_EMULATE=1"
LEONIDA_USER_DATA_SHIFT=4
$<TARGET_FILE:Python3::Interpreter> -I ${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/build.py
${LEONIDA_M5_MESH_COMPUTE_DIR} ms_m5 ps_m5_mesh vs_m3 ps_m5_flat cs_m5_args
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/build.py
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/compute_fixture.py
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ms_m5.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ps_m5_mesh.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/vs_m3.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/ps_m5_flat.asm
${CMAKE_CURRENT_SOURCE_DIR}/test/shaders/cs_m5_args.asm
${CMAKE_CURRENT_SOURCE_DIR}/../tools/rdna2spirv.py
COMMENT "Translating ms_m5, ps_m5_mesh, vs_m3 and ps_m5_flat with --mesh-compute for the M5 mesh test"
VERBATIM)
add_executable(d3d12_m5_mesh_test test/d3d12_m5_mesh_test.cpp shims/d3d12_xs_device.cpp ${LEONIDA_M5_MESH_FILES}
${LEONIDA_M5_MESH_COMPUTE_FILES})
target_link_libraries(d3d12_m5_mesh_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(d3d12_m5_mesh_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX
LEONIDA_TEST_M5_MESH_DIR="${LEONIDA_M5_MESH_DIR}"
LEONIDA_TEST_M5_MESH_COMPUTE_DIR="${LEONIDA_M5_MESH_COMPUTE_DIR}")
target_compile_options(d3d12_m5_mesh_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_m5_mesh COMMAND d3d12_m5_mesh_test)
add_test(NAME d3d12_m5_mesh_fallbacks COMMAND d3d12_m5_mesh_test --single-calls --no-count-buffers)
add_test(NAME d3d12_m5_mesh_chunks COMMAND d3d12_m5_mesh_test --max-draw-indirect-count 3)
add_test(NAME d3d12_m5_mesh_compute COMMAND d3d12_m5_mesh_test --mesh-compute)
add_test(NAME d3d12_m5_mesh_compute_single COMMAND d3d12_m5_mesh_test --mesh-compute --single-calls)
set_tests_properties(d3d12_m5_mesh d3d12_m5_mesh_fallbacks d3d12_m5_mesh_chunks d3d12_m5_mesh_compute
d3d12_m5_mesh_compute_single PROPERTIES SKIP_RETURN_CODE 77)
# M4 (synthetic part): compute PSOs, a UAV table (structured and raw buffers, an R32_UINT storage image), an indirect
# dispatch from arguments a first dispatch wrote, and a copy queue that streams the input in and reads the results
# back across queue fences. cs_m4_fill.asm and cs_m4_indirect.asm go through the same build; build.py publishes
Expand Down Expand Up @@ -2148,7 +2265,7 @@ if(TARGET Vulkan::Headers)
add_test(NAME d3d12_buffer_uav COMMAND d3d12_buffer_uav_test)
set_tests_properties(d3d12_buffer_uav PROPERTIES SKIP_RETURN_CODE 77)
else()
message(STATUS "llvm-mc (set LLVM_MC) or the SDK's spirv-as/spirv-val not found: d3d12_translated_draw_test, d3d12_m2_textured_test, d3d12_m2_formats_test, d3d12_m3_frame_test, d3d12_m4_compute_test and d3d12_buffer_uav_test are not built")
message(STATUS "llvm-mc (set LLVM_MC) or the SDK's spirv-as/spirv-val not found: d3d12_translated_draw_test, d3d12_m2_textured_test, d3d12_m2_formats_test, d3d12_m3_frame_test, d3d12_m4_compute_test, d3d12_buffer_uav_test, d3d12_m5_world_test and d3d12_m5_mesh_test are not built")
endif()
# ID3D12Resource::GetHeapProperties and ID3D12DescriptorHeap::GetDesc (node masks, resolved heap flags) against the
# host runtime and WARP; run explicitly on a Vulkan GPU.
Expand Down Expand Up @@ -2487,8 +2604,47 @@ if(TARGET Vulkan::Headers)
target_compile_options(d3d12_stores_atomics_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_stores_atomics COMMAND d3d12_stores_atomics_test)
set_tests_properties(d3d12_stores_atomics PROPERTIES SKIP_RETURN_CODE 77)

# D3D-29: mesh-shader PSOs from pipeline state streams and DispatchMesh (skips without VK_EXT_mesh_shader).
set(LEONIDA_TEST_MS ${CMAKE_CURRENT_BINARY_DIR}/generated/ms_draw.spv)
add_custom_command(
OUTPUT ${LEONIDA_TEST_MS}
# Vulkan 1.2 (SPIR-V 1.5), the translator's target: 1.3 would emit LocalSizeId, which needs maintenance4.
COMMAND ${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE} -V --target-env vulkan1.2 -o ${LEONIDA_TEST_MS}
${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ms_draw.mesh
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ms_draw.mesh
COMMENT "Compiling the mesh test shader ms_draw.mesh"
VERBATIM)
add_executable(d3d12_mesh_test test/d3d12_mesh_test.cpp shims/d3d12_xs_device.cpp ${LEONIDA_TEST_MS}
${LEONIDA_TEST_PS} ${LEONIDA_TEST_VS_FULLSCREEN})
target_link_libraries(d3d12_mesh_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(d3d12_mesh_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX
LEONIDA_TEST_MS_SPV="${LEONIDA_TEST_MS}" LEONIDA_TEST_PS_SPV="${LEONIDA_TEST_PS}"
LEONIDA_TEST_VS_FULLSCREEN_SPV="${LEONIDA_TEST_VS_FULLSCREEN}")
target_compile_options(d3d12_mesh_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_mesh COMMAND d3d12_mesh_test)
set_tests_properties(d3d12_mesh PROPERTIES SKIP_RETURN_CODE 77)
# Mesh PSOs and DispatchMesh without VK_EXT_mesh_shader, through --mesh-compute (runs on every GPU: the layer's
# device is made without the extension).
set(LEONIDA_TEST_MS_COMPUTE ${CMAKE_CURRENT_BINARY_DIR}/generated/ms_draw_compute.spv)
add_custom_command(
OUTPUT ${LEONIDA_TEST_MS_COMPUTE}
COMMAND ${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE} -V --target-env vulkan1.2 -o ${LEONIDA_TEST_MS_COMPUTE}
${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ms_draw_compute.comp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ms_draw_compute.comp
COMMENT "Compiling the --mesh-compute test shader ms_draw_compute.comp"
VERBATIM)
add_executable(d3d12_mesh_compute_test test/d3d12_mesh_compute_test.cpp shims/d3d12_xs_device.cpp
${LEONIDA_TEST_MS_COMPUTE} ${LEONIDA_TEST_PS})
target_link_libraries(d3d12_mesh_compute_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(d3d12_mesh_compute_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX
LEONIDA_TEST_MS_COMPUTE_SPV="${LEONIDA_TEST_MS_COMPUTE}"
LEONIDA_TEST_PS_SPV="${LEONIDA_TEST_PS}")
target_compile_options(d3d12_mesh_compute_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_mesh_compute COMMAND d3d12_mesh_compute_test)
set_tests_properties(d3d12_mesh_compute PROPERTIES SKIP_RETURN_CODE 77)
else()
message(STATUS "glslangValidator not found: d3d12_compute_test, d3d12_draw_test and d3d12_set0_compute_test are not built")
message(STATUS "glslangValidator not found: d3d12_compute_test, d3d12_draw_test, d3d12_set0_compute_test, d3d12_mesh_test and d3d12_mesh_compute_test are not built")
endif()

# Native D3D12 SV_InnerCoverage reference; its HLSL is compiled at runtime, so glslang is not needed.
Expand Down
51 changes: 47 additions & 4 deletions runtime/shims/d3d12_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const char* name(leonida::ReplayResult result) {
case leonida::ReplayResult::invalid_copy: return "invalid copy or resolve";
case leonida::ReplayResult::invalid_query: return "invalid query";
case leonida::ReplayResult::invalid_indirect_arguments: return "invalid indirect argument or count buffer range";
case leonida::ReplayResult::invalid_draw: return "draw kind does not match the pipeline (mesh or vertex)";
case leonida::ReplayResult::unsupported: return "unsupported";
}
return "?";
Expand Down Expand Up @@ -433,6 +434,16 @@ class GraphicsCommandList final
record_draw(true, indices, instances, first_index, base_vertex, first_instance);
}

// ID3D12GraphicsCommandList6: a mesh draw. The bound graphics pipeline must have a mesh shader (checked at
// execution, where the pipeline is resolved). D3D12 caps each count at 65535 and their product at 2^22
// (D3D12_MS_DISPATCH_MAX_THREAD_GROUPS_PER_GRID); a larger grid is a recording error.
void STDMETHODCALLTYPE DispatchMesh(UINT x, UINT y, UINT z) override {
d3d12_trace::record("ID3D12GraphicsCommandList6::DispatchMesh");
if (x > 65535 || y > 65535 || z > 65535 || std::uint64_t(x) * y * z > (1u << 22)) return check(false);
if (defer([=](GraphicsCommandList& l) { l.record_mesh_draw(x, y, z); }, true)) return;
record_mesh_draw(x, y, z);
}

void STDMETHODCALLTYPE ResourceBarrier(UINT count, const D3D12_RESOURCE_BARRIER* barriers) override {
d3d12_trace::record("ID3D12GraphicsCommandList::ResourceBarrier");
if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false);
Expand Down Expand Up @@ -750,6 +761,17 @@ class GraphicsCommandList final
if (!command_signature_info(signature, kind, stride) || !argument_buffer)
return check(false);
leonida::ExecuteIndirect cmd{};
// A draw takes the list's graphics state, as DrawInstanced does; with nothing to rasterize it is dropped. A
// list with no pipeline, root signature or topology yet records the bare call (it closes, as on the PC
// runtime; it is not a call replay can run).
// A DISPATCH_MESH signature takes the state DispatchMesh does: no topology, vertex or index buffers.
const bool mesh = kind == leonida::IndirectKind::dispatch_mesh;
if (kind != leonida::IndirectKind::dispatch && max_command_count && graphics_pipeline_ && graphics_.layout &&
(topology_ || mesh)) {
if (!(viewport_.width > 0) || !(viewport_.height > 0)) return;
cmd.state = std::make_shared<const leonida::Draw>(
mesh ? make_mesh_draw(0, 0, 0) : make_draw(kind == leonida::IndirectKind::draw_indexed, 0, 0, 0, 0, 0));
}
cmd.kind = kind;
cmd.stride = stride;
cmd.max_count = max_command_count;
Expand Down Expand Up @@ -1179,16 +1201,37 @@ class GraphicsCommandList final
return draw_views_;
}

// A mesh draw needs a graphics pipeline and a graphics root signature; it has no topology or vertex input.
void record_mesh_draw(UINT x, UINT y, UINT z) {
if (!graphics_pipeline_ || !graphics_.layout) return check(false);
if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; // as record_draw: nothing is rasterized
check(list_.draw(make_mesh_draw(x, y, z)));
}

// A draw needs a graphics pipeline, a graphics root signature and a topology.
void record_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex, UINT first_instance) {
if (!graphics_pipeline_ || !graphics_.layout || !topology_) return check(false);
// No viewport (never set, or unbound with RSSetViewports(0)) or an empty one: D3D12 rasterizes nothing,
// and Vulkan forbids a 0x0 viewport, so the draw is not recorded.
if (!(viewport_.width > 0) || !(viewport_.height > 0)) return;
leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, index_, topology_, viewport_,
scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, indexed, count, instances,
first, base_vertex, first_instance};
check(list_.draw(std::move(draw)));
check(list_.draw(make_draw(indexed, count, instances, first, base_vertex, first_instance)));
}

// The list's graphics state as a mesh draw: no vertex input or input assembly; the group counts go in
// count/instances/first.
leonida::Draw make_mesh_draw(UINT x, UINT y, UINT z) {
leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, {}, 0, viewport_, scissor_,
blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0};
draw.mesh = true;
return draw;
}

// The list's graphics state as a draw (see record_draw for what has to be set).
leonida::Draw make_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex,
UINT first_instance) {
return {graphics_pipeline_, graphics_.data, draw_views(), depth_, index_, topology_, viewport_,
scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, indexed, count, instances, first,
base_vertex, first_instance};
}
};

Expand Down
Loading