Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,15 @@ if(TARGET Vulkan::Headers)
add_test(NAME d3d12_indirect_zero COMMAND d3d12_indirect_zero_test)
set_tests_properties(d3d12_indirect_zero PROPERTIES SKIP_RETURN_CODE 77)
set_tests_properties(d3d12_node_mask PROPERTIES SKIP_RETURN_CODE 77)
set_tests_properties(d3d12_indirect_zero PROPERTIES SKIP_RETURN_CODE 77)

# GPU-driven graphics ExecuteIndirect (DRAW / DRAW_INDEXED, fixed & count buffer) against host D3D12.
add_executable(d3d12_indirect_draw_test test/d3d12_indirect_draw_test.cpp)
target_link_libraries(d3d12_indirect_draw_test PRIVATE gta6rt_d3d12_com d3d12 dxgi dxguid)
target_compile_definitions(d3d12_indirect_draw_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_options(d3d12_indirect_draw_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_indirect_draw COMMAND d3d12_indirect_draw_test)
set_tests_properties(d3d12_indirect_draw PROPERTIES SKIP_RETURN_CODE 77
FAIL_REGULAR_EXPRESSION "Validation Error;VUID-")

# CopyResource / CopyTextureRegion between BC and its uncompressed equivalent (and depth <-> colour) against the
# host runtime and WARP; run explicitly on a Vulkan GPU.
Expand Down
9 changes: 9 additions & 0 deletions runtime/shims/d3d12_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,15 @@ class GraphicsCommandList final
if (!compute_pipeline_ || !compute_.layout) return check(false);
cmd.pipeline = compute_pipeline_;
cmd.user_data = compute_.data;
} else if ((kind == leonida::IndirectKind::draw || kind == leonida::IndirectKind::draw_indexed) &&
max_command_count && graphics_pipeline_ && graphics_.layout && topology_) {
note_direct_heap_indexing(graphics_.layout);
if (!any_nonempty_viewport()) return; // as record_draw: nothing is rasterized
cmd.has_draw = true;
cmd.draw = leonida::Draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, index_, topology_,
viewport_, scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_,
kind == leonida::IndirectKind::draw_indexed, 0, 0, 0, 0, 0};
cmd.draw.viewports = draw_viewports();
}
check(list_.execute_indirect(cmd));
}
Expand Down
4 changes: 4 additions & 0 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ struct VulkanDeviceInfo {
// writes the layer or viewport declares ShaderLayer / ShaderViewportIndex (the index's `features`).
bool shader_output_layer = false;
bool shader_output_viewport_index = false;
// Vulkan 1.2 drawIndirectCount is enabled on `device`: graphics ExecuteIndirect with a GPU CountBuffer uses
// vkCmdDrawIndirectCount / vkCmdDrawIndexedIndirectCount. Without it, counted graphics draws are refused at
// replay rather than calling those commands without the feature enabled.
bool draw_indirect_count = false;
// The translator's output folder for pipeline creation. An empty value uses LEONIDA_SHADERS or the packaged path.
std::string shader_dir;
// VK_EXT_custom_border_color (with customBorderColors and customBorderColorWithoutFormat) is enabled on
Expand Down
5 changes: 5 additions & 0 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5163,6 +5163,8 @@ class Device final
info.buffer_device_address);
state_.context->mesh_queries = info.mesh_shader_queries;
state_.context->set_depth_range_unrestricted(info.depth_range_unrestricted);
state_.context->configure_indirect_draw(info.features.multiDrawIndirect == VK_TRUE,
info.draw_indirect_count);
if (info.physical && state_.format_properties) {
state_.context->set_color_attachment_format(
[physical = info.physical, get_props = state_.format_properties](VkFormat format) {
Expand Down Expand Up @@ -9611,6 +9613,8 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
VkPhysicalDeviceVulkan12Features enable12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, &enable11};
enable12.timelineSemaphore = VK_TRUE;
enable12.separateDepthStencilLayouts = VK_TRUE;
info.draw_indirect_count = chosen12.drawIndirectCount == VK_TRUE;
enable12.drawIndirectCount = info.draw_indirect_count ? VK_TRUE : VK_FALSE;
info.buffer_device_address = chosen12.bufferDeviceAddress == VK_TRUE;
enable12.bufferDeviceAddress = info.buffer_device_address ? VK_TRUE : VK_FALSE;
info.storage_buffer_8bit = chosen12.storageBuffer8BitAccess == VK_TRUE;
Expand Down Expand Up @@ -9855,6 +9859,7 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
enable.logicOp = chosen_features.logicOp;
enable.depthClamp = chosen_features.depthClamp;
enable.multiViewport = chosen_features.multiViewport;
enable.multiDrawIndirect = chosen_features.multiDrawIndirect;
enable.geometryShader = chosen_features.geometryShader; // translated geometry shaders (195 in the corpus)
// What translated shaders declare (the index's `features`): 64-bit integers in most of the corpus (25,803 of
// 26,503 entries), doubles, 16-bit integers, clip and cull distances in a few vertex shaders, image stores
Expand Down
6 changes: 6 additions & 0 deletions runtime/src/command_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ struct ExecuteIndirect {
// as it is.
std::uintptr_t pipeline = 0;
std::array<std::uint32_t, 32> user_data{};
// kind == draw / draw_indexed: snapshot of the graphics state in effect at ExecuteIndirect, as Draw records it, so
// replay begins dynamic rendering and binds the pipeline, targets, viewport/scissor, push constants and
// vertex/index buffers before vkCmdDraw*Indirect*. When has_draw is false (e.g. max_count == 0 or a bare IR test
// that opened its own render pass), replay emits only the indirect call.
bool has_draw = false;
Draw draw{};
};

// Triangle geometry descriptor for a BLAS build (ID3D12GraphicsCommandList4::BuildRaytracingAccelerationStructure).
Expand Down
16 changes: 14 additions & 2 deletions runtime/src/vulkan_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,12 @@ class VulkanContext {
replay_.update_buffer = vk.vkCmdUpdateBuffer;
replay_.draw_indirect = vk.vkCmdDrawIndirect;
replay_.draw_indexed_indirect = vk.vkCmdDrawIndexedIndirect;
replay_.draw_indirect_count = vk.vkCmdDrawIndirectCount;
replay_.draw_indexed_indirect_count = vk.vkCmdDrawIndexedIndirectCount;
// Gated on enabled device features via configure_indirect_draw(): vkGetDeviceProcAddr still hands out core
// Vulkan 1.2 drawIndirectCount entry points when the feature is off, and multiDrawIndirect defaults to the
// drawCount=1 fallback until enabled.
replay_.draw_indirect_count = nullptr;
replay_.draw_indexed_indirect_count = nullptr;
replay_.multi_draw_indirect = false;
replay_.dispatch_indirect = vk.vkCmdDispatchIndirect;
if (conditional_rendering) { // a driver may hand out these pointers even when the extension is off
replay_.begin_conditional_rendering = vk.vkCmdBeginConditionalRenderingEXT;
Expand Down Expand Up @@ -1136,6 +1140,14 @@ class VulkanContext {
std::unique_lock lock(resource_mutex_);
counted_dispatch_ = std::make_unique<IndirectDispatchCounter>(get, device_, memory, limits);
}
// Gates graphics ExecuteIndirect replay on the Vulkan features enabled on `device`: without multiDrawIndirect,
// fixed multi-draw falls back to drawCount=1 calls; without drawIndirectCount, counted draws are rejected with
// ReplayResult::unsupported rather than invoking vkCmdDrawIndirectCount / vkCmdDrawIndexedIndirectCount.
void configure_indirect_draw(bool multi_draw_indirect, bool draw_indirect_count) {
replay_.multi_draw_indirect = multi_draw_indirect;
replay_.draw_indirect_count = draw_indirect_count ? vk.vkCmdDrawIndirectCount : nullptr;
replay_.draw_indexed_indirect_count = draw_indirect_count ? vk.vkCmdDrawIndexedIndirectCount : nullptr;
}
VkDevice device() const { return device_; }

// Debug markers become labels from here on; call before any queue or list uses the context. Incomplete sets
Expand Down
Loading
Loading