Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 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
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
67 changes: 65 additions & 2 deletions docs/d3d12_vulkan.md

Large diffs are not rendered by default.

87 changes: 85 additions & 2 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,69 @@ 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)
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}"
$<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
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}/../tools/rdna2spirv.py
COMMENT "Translating ms_m5, ps_m5_mesh, vs_m3 and ps_m5_flat 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})
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}")
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)
set_tests_properties(d3d12_m5_mesh d3d12_m5_mesh_fallbacks d3d12_m5_mesh_chunks 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 +2211,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 +2550,28 @@ 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)
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 and d3d12_mesh_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
27 changes: 27 additions & 0 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ struct VulkanDeviceInfo {
// samplerAnisotropy, samplerMirrorClampToEdge and samplerFilterMinmax enabled; without them such samplers are
// approximated.
bool sampler_anisotropy = false;
// multiDrawIndirect is enabled: ExecuteIndirect hands all its commands to one vkCmdDraw*Indirect. Without it the
// layer issues one call per command (a drawCount above 1 is invalid without the feature).
bool multi_draw_indirect = false;
// drawIndirectCount (Vulkan 1.2) is enabled: ExecuteIndirect with a count buffer. Without it such a call is
// unsupported.
bool draw_indirect_count = false;
// drawIndirectFirstInstance is enabled: indirect records may have a StartInstanceLocation other than 0. Without
// it such a record is invalid Vulkan (the layer cannot see inside the GPU buffer, so it only says so once).
bool draw_indirect_first_instance = false;
// VkPhysicalDeviceLimits::maxDrawIndirectCount (a call takes at most this many records); 0 means unknown, no cap.
std::uint32_t max_draw_indirect_count = 0;
bool sampler_mirror_clamp_to_edge = false;
bool sampler_filter_minmax = false;
// VK_KHR_calibrated_timestamps or VK_EXT_calibrated_timestamps is enabled on `device` (QueueClock).
Expand Down Expand Up @@ -169,6 +180,10 @@ struct VulkanDeviceInfo {
// VkAccelerationStructureKHR; needs buffer_device_address and the GPU address arena. The standalone device sets it
// unless LEONIDA_RT_AS=khr (docs/d3d12_vulkan.md 4.8); with it set, ray_tracing is not enabled.
bool xdxr_acceleration_structures = false;
// VK_EXT_mesh_shader with its meshShader feature is enabled on `device` (taskShader is not needed: the game's
// shaders have no amplification stage). Mesh-shader PSOs and DispatchMesh work, and CheckFeatureSupport reports
// D3D12_MESH_SHADER_TIER_1; without it mesh PSOs are refused and the tier is NOT_SUPPORTED.
bool mesh_shader = false;
// The core features enabled on `device`. Graphics PSOs that need independentBlend, fillModeNonSolid,
// depthBiasClamp or dualSrcBlend are refused unless it is set here.
VkPhysicalDeviceFeatures features{};
Expand Down Expand Up @@ -262,6 +277,18 @@ VkDescriptorSetLayout bindless_set_layout(ID3D12Device* device);
// The bindless index the descriptor hash table holds for the 8 key dwords of a T# (or the 4 of an S# followed by
// 0xFFFFFFFF x4), 0 (the fallback) when it has none or `device` has no such set. For tests.
std::uint32_t bindless_hash_lookup(ID3D12Device* device, const std::uint32_t (&key)[8]);
// The device's VkPipelineCache: how many Vulkan pipelines were created through it (graphics, compute and the draw-time
// variants of a graphics PSO), how many of those the cache answered (VkPipelineCreationFeedback's application-cache
// hit bit), and the size of its data. `available` is false without Vulkan 1.3 feedback or without the cache; then the
// counts stay 0. For tests.
struct PipelineCacheStats {
bool available = false;
std::uint32_t created = 0;
std::uint32_t hits = 0;
std::size_t bytes = 0;
};
PipelineCacheStats pipeline_cache_stats(ID3D12Device* device);

// The free indices of that set's 2D image and sampler arrays: how many more distinct 2D T#s and S#s
// CreateShaderResourceView and CreateSampler can register before they log that the array is full. Zeros when
// `device` has no such set. For tests.
Expand Down
Loading