diff --git a/layers/chassis/dispatch_object_manual.cpp b/layers/chassis/dispatch_object_manual.cpp index 78ba22fd33e..49db2a50a2f 100644 --- a/layers/chassis/dispatch_object_manual.cpp +++ b/layers/chassis/dispatch_object_manual.cpp @@ -2615,48 +2615,35 @@ VkResult DispatchDevice::CreateIndirectExecutionSetEXT(VkDevice device, const Vk if (!wrap_handles) return device_dispatch_table.CreateIndirectExecutionSetEXT(device, pCreateInfo, pAllocator, pIndirectExecutionSet); - // When using a union of pointer we still need to unwrap the handles, but since it is a pointer, we can just use the pointer - // from the incoming parameter instead of using safe structs as it is less complex doing it here + // The safe struct deep copies the |info| union (based on |type|), so the copy can be unwrapped in place vku::safe_VkIndirectExecutionSetCreateInfoEXT local_pCreateInfo; local_pCreateInfo.initialize(pCreateInfo); - // need in local scope to call down whatever we use - vku::safe_VkIndirectExecutionSetPipelineInfoEXT pipeline_info; - vku::safe_VkIndirectExecutionSetShaderInfoEXT shader_info; - - if (pCreateInfo) { - local_pCreateInfo.initialize(pCreateInfo); - switch (local_pCreateInfo.type) { - case VK_INDIRECT_EXECUTION_SET_INFO_TYPE_PIPELINES_EXT: - if (pCreateInfo->info.pPipelineInfo) { - pipeline_info.initialize(pCreateInfo->info.pPipelineInfo); - pipeline_info.initialPipeline = Unwrap(pCreateInfo->info.pPipelineInfo->initialPipeline); - local_pCreateInfo.info.pPipelineInfo = pipeline_info.ptr(); - } - break; - case VK_INDIRECT_EXECUTION_SET_INFO_TYPE_SHADER_OBJECTS_EXT: - if (local_pCreateInfo.info.pShaderInfo) { - shader_info.initialize(pCreateInfo->info.pShaderInfo); - - for (uint32_t index0 = 0; index0 < local_pCreateInfo.info.pShaderInfo->shaderCount; ++index0) { - if (local_pCreateInfo.info.pShaderInfo->pSetLayoutInfos) { - const auto& set_layout = local_pCreateInfo.info.pShaderInfo->pSetLayoutInfos[index0]; - if (set_layout.pSetLayouts) { - for (uint32_t index1 = 0; index1 < set_layout.setLayoutCount; ++index1) { - shader_info.pSetLayoutInfos[index0].pSetLayouts[index1] = - Unwrap(set_layout.pSetLayouts[index1]); - } - } + switch (local_pCreateInfo.type) { + case VK_INDIRECT_EXECUTION_SET_INFO_TYPE_PIPELINES_EXT: + if (local_pCreateInfo.info.pPipelineInfo) { + auto* pipeline_info = reinterpret_cast( + const_cast(local_pCreateInfo.info.pPipelineInfo)); + pipeline_info->initialPipeline = Unwrap(pipeline_info->initialPipeline); + } + break; + case VK_INDIRECT_EXECUTION_SET_INFO_TYPE_SHADER_OBJECTS_EXT: + if (local_pCreateInfo.info.pShaderInfo) { + auto* shader_info = reinterpret_cast( + const_cast(local_pCreateInfo.info.pShaderInfo)); + for (uint32_t index0 = 0; index0 < shader_info->shaderCount; ++index0) { + if (shader_info->pSetLayoutInfos) { + const auto& set_layout = shader_info->pSetLayoutInfos[index0]; + for (uint32_t index1 = 0; set_layout.pSetLayouts && index1 < set_layout.setLayoutCount; ++index1) { + set_layout.pSetLayouts[index1] = Unwrap(set_layout.pSetLayouts[index1]); } - shader_info.pInitialShaders[index0] = Unwrap(local_pCreateInfo.info.pShaderInfo->pInitialShaders[index0]); } - - local_pCreateInfo.info.pShaderInfo = shader_info.ptr(); + shader_info->pInitialShaders[index0] = Unwrap(shader_info->pInitialShaders[index0]); } - break; - default: - break; - } + } + break; + default: + break; } VkResult result = device_dispatch_table.CreateIndirectExecutionSetEXT( diff --git a/layers/gpu_dump/gpu_dump_device_generated_commands.cpp b/layers/gpu_dump/gpu_dump_device_generated_commands.cpp index 5518ca268c8..e1b124277ca 100644 --- a/layers/gpu_dump/gpu_dump_device_generated_commands.cpp +++ b/layers/gpu_dump/gpu_dump_device_generated_commands.cpp @@ -26,68 +26,77 @@ #include "state_tracker/buffer_state.h" #include "state_tracker/cmd_buffer_state.h" #include "state_tracker/device_generated_commands_state.h" -#include "state_tracker/last_bound_state.h" +#include "utils/device_generated_commands_utils.h" namespace gpudump { void CommandBufferSubState::DumpDeviceGeneratedCommands(const VkGeneratedCommandsInfoEXT& info, VkPipelineBindPoint bind_point, const Location& loc) const { + const auto indirect_commands_layout = dev_data.Get(info.indirectCommandsLayout); + if (!indirect_commands_layout) { + return; // Invalid handle, will be caught by object lifetime validation + } + const auto indirect_execution_set = dev_data.Get(info.indirectExecutionSet); + std::ostringstream ss; - ss << "[Dump Device Generated Commands]\n"; + ss << "[Dump Device Generated Commands] (" << dev_data.FormatHandle(base.Handle()) << ", " + << dev_data.FormatHandle(indirect_commands_layout->Handle()); + if (indirect_execution_set) { + ss << ", " << dev_data.FormatHandle(indirect_execution_set->Handle()); + } + ss << ")\n"; bool found_warning = false; - const LastBound& last_bound = base.lastBound[ConvertToVvlBindPoint(bind_point)]; - const bool has_pipeline = last_bound.pipeline_state != nullptr; - ss << "maxDrawCount = " << info.maxDrawCount << ", maxSequenceCount = " << info.maxSequenceCount << "\n"; + ss << "- shaderStages = " << string_VkShaderStageFlags(info.shaderStages) << " (" << string_VkPipelineBindPoint(bind_point) + << ")\n"; + ss << "- maxSequenceCount = " << info.maxSequenceCount << ", maxDrawCount = " << info.maxDrawCount << "\n"; if (info.sequenceCountAddress != 0) { vvl::range sequence_range{info.sequenceCountAddress, info.sequenceCountAddress + sizeof(uint32_t)}; - ss << "Sequence count found at " << vvl::string_range_hex(sequence_range) << "\n"; - auto buffer_states = dev_data.GetBuffersByAddress(info.sequenceCountAddress); - for (auto& buffer_state : buffer_states) { - ss << " - " << buffer_state->Describe(dev_data) << "\n"; - } - if (buffer_states.empty()) { - ss << " - [WARNING] No VkBuffer found at " << Hex(info.sequenceCountAddress) << "\n"; - found_warning = true; - } + ss << "- sequenceCountAddress at " << vvl::string_range_hex(sequence_range) << "\n"; + found_warning |= dev_data.ListBuffers(ss, info.sequenceCountAddress, 1); + } else { + ss << "- sequenceCountAddress = 0 (maxSequenceCount is used as the sequence count)\n"; + } + + { + vvl::range indirect_range{info.indirectAddress, info.indirectAddress + info.indirectAddressSize}; + ss << "- indirectAddress at " << vvl::string_range_hex(indirect_range) + << " (indirectAddressSize = " << info.indirectAddressSize << ")\n"; + found_warning |= dev_data.ListBuffers(ss, info.indirectAddress, 1); } if (info.preprocessAddress != 0) { vvl::range preprocess_range{info.preprocessAddress, info.preprocessAddress + info.preprocessSize}; - ss << "Preprocess at " << vvl::string_range_hex(preprocess_range) << "\n"; - auto buffer_states = dev_data.GetBuffersByAddress(info.preprocessAddress); - for (auto& buffer_state : buffer_states) { - ss << " - " << buffer_state->Describe(dev_data) << "\n"; - } - if (buffer_states.empty()) { - ss << " - [WARNING] No VkBuffer found at " << Hex(info.preprocessAddress) << "\n"; - found_warning = true; - } + ss << "- preprocessAddress at " << vvl::string_range_hex(preprocess_range) << " (preprocessSize = " << info.preprocessSize + << ")\n"; + found_warning |= dev_data.ListBuffers(ss, info.preprocessAddress, 1); } - { - vvl::range indirect_range{info.indirectAddress, info.indirectAddress + info.indirectAddressSize}; - ss << "Indirect buffer at " << vvl::string_range_hex(indirect_range) << "\n"; - auto buffer_states = dev_data.GetBuffersByAddress(info.indirectAddress); - for (auto& buffer_state : buffer_states) { - ss << " - " << buffer_state->Describe(dev_data) << "\n"; - } - if (buffer_states.empty()) { - ss << " - [WARNING] No VkBuffer found at " << Hex(info.indirectAddress) << "\n"; - found_warning = true; + if (indirect_execution_set) { + ss << "- " << dev_data.FormatHandle(indirect_execution_set->Handle()) << " contains "; + if (indirect_execution_set->is_pipeline) { + ss << "pipelines (maxPipelineCount = " << indirect_execution_set->max_pipeline_count << ")\n"; + } else { + ss << "shader objects (maxShaderCount = " << indirect_execution_set->max_shader_count << ")\n"; } } - const auto indirect_commands_layout = dev_data.Get(info.indirectCommandsLayout); - ss << "Tokens:\n"; - for (uint32_t i = 0; i < indirect_commands_layout->create_info.tokenCount; i++) { - const VkIndirectCommandsLayoutTokenEXT& token = indirect_commands_layout->create_info.pTokens[i]; - ss << " - Token [" << i << "] "; + const VkIndirectCommandsLayoutCreateInfoEXT& layout_ci = indirect_commands_layout->create_info; + ss << "- " << dev_data.FormatHandle(indirect_commands_layout->Handle()) << " indirectStride = " << layout_ci.indirectStride; + if (layout_ci.flags != 0) { + ss << ", flags = " << string_VkIndirectCommandsLayoutUsageFlagsEXT(layout_ci.flags); + } + ss << "\n"; + for (uint32_t i = 0; i < layout_ci.tokenCount; i++) { + const VkIndirectCommandsLayoutTokenEXT& token = layout_ci.pTokens[i]; + ss << " - Token [" << i << "] "; switch (token.type) { case VK_INDIRECT_COMMANDS_TOKEN_TYPE_EXECUTION_SET_EXT: - ss << "[EXECUTION_SET] " << (has_pipeline ? "pipeline" : "shader object") << ", stage " - << string_VkShaderStageFlags(token.data.pExecutionSet->shaderStages); + ss << "[EXECUTION_SET] " + << (token.data.pExecutionSet->type == VK_INDIRECT_EXECUTION_SET_INFO_TYPE_PIPELINES_EXT ? "pipeline" + : "shader object") + << ", stage " << string_VkShaderStageFlags(token.data.pExecutionSet->shaderStages); break; case VK_INDIRECT_COMMANDS_TOKEN_TYPE_PUSH_CONSTANT_EXT: ss << "[PUSH_CONSTANT] " << string_VkPushConstantRange(token.data.pPushConstant->updateRange); @@ -96,10 +105,12 @@ void CommandBufferSubState::DumpDeviceGeneratedCommands(const VkGeneratedCommand ss << "[SEQUENCE_INDEX] " << string_VkPushConstantRange(token.data.pPushConstant->updateRange); break; case VK_INDIRECT_COMMANDS_TOKEN_TYPE_INDEX_BUFFER_EXT: - ss << "[INDEX_BUFFER] mode = " << string_VkIndirectCommandsInputModeFlagBitsEXT(token.data.pIndexBuffer->mode); + ss << "[INDEX_BUFFER] mode = " << string_VkIndirectCommandsInputModeFlagBitsEXT(token.data.pIndexBuffer->mode) + << ", VkBindIndexBufferIndirectCommandEXT"; break; case VK_INDIRECT_COMMANDS_TOKEN_TYPE_VERTEX_BUFFER_EXT: - ss << "[VERTEX_BUFFER] vertexBindingUnit = " << token.data.pVertexBuffer->vertexBindingUnit; + ss << "[VERTEX_BUFFER] vertexBindingUnit = " << token.data.pVertexBuffer->vertexBindingUnit + << ", VkBindVertexBufferIndirectCommandEXT"; break; case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_INDEXED_EXT: ss << "[DRAW_INDEXED] VkDrawIndexedIndirectCommand"; @@ -140,7 +151,14 @@ void CommandBufferSubState::DumpDeviceGeneratedCommands(const VkGeneratedCommand case VK_INDIRECT_COMMANDS_TOKEN_TYPE_MAX_ENUM_EXT: break; } - ss << " (offset " << token.offset << ")\n"; + + const uint32_t data_size = vvl::IndirectCommandsTokenDataSize(token); + if (data_size == 0) { + // offset is ignored for these tokens + ss << " (nothing read from the indirect buffer, the sequence index is used)\n"; + } else { + ss << " (offset " << token.offset << ", size " << data_size << ")\n"; + } } if (dev_data.gpu_dump_settings.to_stdout) { diff --git a/scripts/known_good.json b/scripts/known_good.json index 116ff7cb0d4..3754cc33964 100644 --- a/scripts/known_good.json +++ b/scripts/known_good.json @@ -18,7 +18,7 @@ "sub_dir": "Vulkan-Utility-Libraries", "build_dir": "Vulkan-Utility-Libraries/build", "install_dir": "Vulkan-Utility-Libraries/build/install", - "commit": "v1.4.368", + "commit": "1b1e6773b3e00269a67d2d83d9268513d8cc9e1c", "deps": [ { "var_name": "VULKAN_HEADERS_INSTALL_DIR", diff --git a/tests/unit/gpu_dump.cpp b/tests/unit/gpu_dump.cpp index 0c640dd9c84..f839aebab1f 100644 --- a/tests/unit/gpu_dump.cpp +++ b/tests/unit/gpu_dump.cpp @@ -23,6 +23,7 @@ #include "utils/math_utils.h" #include "descriptor_heap_object.h" #include "ray_tracing_objects.h" +#include "shader_object_helper.h" static const VkLayerSettingEXT kAllDumpSettings[3] = { {OBJECT_LAYER_NAME, "gpu_dump_device_generated_commands", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &kVkTrue}, @@ -35,6 +36,7 @@ class NegativeGpuDump : public VkLayerTest { public: void InitDescriptorBuffer(VkLayerSettingsCreateInfoEXT* custom_setting = nullptr); void InitDescriptorHeap(VkLayerSettingsCreateInfoEXT* custom_setting = nullptr); + void InitDeviceGeneratedCommands(VkShaderStageFlags stages, VkLayerSettingsCreateInfoEXT* custom_setting = nullptr); VkPhysicalDeviceDescriptorHeapPropertiesEXT heap_props = vku::InitStructHelper(); VkPhysicalDeviceDescriptorBufferPropertiesEXT descriptor_buffer_props = vku::InitStructHelper(); }; @@ -63,6 +65,23 @@ void NegativeGpuDump::InitDescriptorHeap(VkLayerSettingsCreateInfoEXT* custom_se GetPhysicalDeviceProperties2(heap_props); } +void NegativeGpuDump::InitDeviceGeneratedCommands(VkShaderStageFlags stages, VkLayerSettingsCreateInfoEXT* custom_setting) { + SetTargetApiVersion(VK_API_VERSION_1_1); + AddRequiredExtensions(VK_EXT_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME); + AddRequiredExtensions(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME); + AddRequiredFeature(vkt::Feature::deviceGeneratedCommands); + AddRequiredFeature(vkt::Feature::bufferDeviceAddress); + RETURN_IF_SKIP(InitFramework(custom_setting ? custom_setting : &kAllDumpSettingCi)); + RETURN_IF_SKIP(InitState()); + + VkPhysicalDeviceDeviceGeneratedCommandsPropertiesEXT dgc_props = vku::InitStructHelper(); + GetPhysicalDeviceProperties2(dgc_props); + if ((dgc_props.supportedIndirectCommandsShaderStagesPipelineBinding & stages) != stages && + (dgc_props.supportedIndirectCommandsShaderStagesShaderBinding & stages) != stages) { + GTEST_SKIP() << "Shader stages are not supported by DGC."; + } +} + TEST_F(NegativeGpuDump, Descriptors) { RETURN_IF_SKIP(InitDescriptorBuffer()); @@ -3149,3 +3168,156 @@ TEST_F(NegativeGpuDump, DescriptorHeapIndirectIndexArrayAlias) { m_errorMonitor->VerifyFound(); m_command_buffer.End(); } + +TEST_F(NegativeGpuDump, DeviceGeneratedCommandsCompute) { + RETURN_IF_SKIP(InitDeviceGeneratedCommands(VK_SHADER_STAGE_COMPUTE_BIT)); + + vkt::PipelineLayout pipeline_layout(*m_device); + vkt::IndirectCommandsToken tokens; + tokens.ExecutionSetPipeline(VK_SHADER_STAGE_COMPUTE_BIT); + tokens.Action(VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_EXT); + vkt::IndirectCommandsLayout command_layout(*m_device, tokens, VK_SHADER_STAGE_COMPUTE_BIT, pipeline_layout); + const uint32_t stride = sizeof(uint32_t) + sizeof(VkDispatchIndirectCommand); + + VkPipelineCreateFlags2CreateInfo pipe_flags2 = vku::InitStructHelper(); + pipe_flags2.flags = VK_PIPELINE_CREATE_2_INDIRECT_BINDABLE_BIT_EXT; + CreateComputePipelineHelper pipe(*this, &pipe_flags2); + pipe.CreateComputePipeline(); + vkt::IndirectExecutionSet exe_set(*m_device, pipe, 1); + + vkt::Buffer indirect_buffer(*m_device, stride, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, vkt::device_address); + uint32_t* indirect_data = static_cast(indirect_buffer.Memory().Map()); + indirect_data[0] = 0; // pipeline index + const VkDispatchIndirectCommand dispatch = {2, 1, 1}; + memcpy(indirect_data + 1, &dispatch, sizeof(dispatch)); + + VkGeneratedCommandsInfoEXT generated_commands_info = vku::InitStructHelper(); + generated_commands_info.shaderStages = VK_SHADER_STAGE_COMPUTE_BIT; + generated_commands_info.indirectExecutionSet = exe_set; + generated_commands_info.indirectCommandsLayout = command_layout; + generated_commands_info.indirectAddressSize = stride; + generated_commands_info.indirectAddress = indirect_buffer.Address(); + generated_commands_info.maxSequenceCount = 1; + vkt::PreprocessBuffer preprocess_buffer(*m_device, generated_commands_info); + + m_command_buffer.Begin(); + vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); + m_errorMonitor->SetDesiredInfo("Token [1] [DISPATCH] VkDispatchIndirectCommand (offset 4, size 12)"); + vk::CmdExecuteGeneratedCommandsEXT(m_command_buffer, false, &generated_commands_info); + m_errorMonitor->VerifyFound(); + m_command_buffer.End(); +} + +TEST_F(NegativeGpuDump, DeviceGeneratedCommandsSequenceIndex) { + RETURN_IF_SKIP(InitDeviceGeneratedCommands(VK_SHADER_STAGE_COMPUTE_BIT)); + + const VkPushConstantRange pc_range = {VK_SHADER_STAGE_COMPUTE_BIT, 0, 4}; + vkt::PipelineLayout pipeline_layout(*m_device, {}, {pc_range}); + vkt::IndirectCommandsToken tokens; + tokens.SequenceIndex(pc_range); + tokens.Action(VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_EXT); + vkt::IndirectCommandsLayout command_layout(*m_device, tokens, VK_SHADER_STAGE_COMPUTE_BIT, pipeline_layout); + const uint32_t stride = sizeof(VkDispatchIndirectCommand); // the sequence index token reads nothing + + const char* cs_source = R"glsl( + #version 450 + layout(push_constant) uniform PushConstants { uint index; }; + shared uint sequence_index; + void main() { + sequence_index = index; + } + )glsl"; + CreateComputePipelineHelper pipe(*this); + pipe.cs_ = VkShaderObj(*m_device, cs_source, VK_SHADER_STAGE_COMPUTE_BIT); + pipe.cp_ci_.layout = pipeline_layout; + pipe.CreateComputePipeline(); + + vkt::Buffer indirect_buffer(*m_device, stride * 2, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, vkt::device_address); + VkDispatchIndirectCommand* indirect_data = static_cast(indirect_buffer.Memory().Map()); + indirect_data[0] = {1, 1, 1}; + indirect_data[1] = {1, 1, 1}; + + VkGeneratedCommandsPipelineInfoEXT pipeline_info = vku::InitStructHelper(); + pipeline_info.pipeline = pipe; + VkGeneratedCommandsInfoEXT generated_commands_info = vku::InitStructHelper(&pipeline_info); + generated_commands_info.shaderStages = VK_SHADER_STAGE_COMPUTE_BIT; + generated_commands_info.indirectCommandsLayout = command_layout; + generated_commands_info.indirectAddressSize = stride * 2; + generated_commands_info.indirectAddress = indirect_buffer.Address(); + generated_commands_info.maxSequenceCount = 2; + vkt::PreprocessBuffer preprocess_buffer(*m_device, generated_commands_info); + + m_command_buffer.Begin(); + vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipe); + m_errorMonitor->SetDesiredInfo( + "[SEQUENCE_INDEX] range [0, 4) for VK_SHADER_STAGE_COMPUTE_BIT (nothing read from the indirect buffer"); + vk::CmdExecuteGeneratedCommandsEXT(m_command_buffer, false, &generated_commands_info); + m_errorMonitor->VerifyFound(); + m_command_buffer.End(); +} + +TEST_F(NegativeGpuDump, DeviceGeneratedCommandsShaderObject) { + AddRequiredExtensions(VK_EXT_SHADER_OBJECT_EXTENSION_NAME); + AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); + AddRequiredFeature(vkt::Feature::shaderObject); + AddRequiredFeature(vkt::Feature::dynamicRendering); + RETURN_IF_SKIP(InitDeviceGeneratedCommands(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)); + InitRenderTarget(); + + vkt::PipelineLayout pipeline_layout(*m_device); + vkt::IndirectCommandsToken tokens; + tokens.ExecutionSetShaderObject(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT); + tokens.Action(VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_EXT); + vkt::IndirectCommandsLayout command_layout(*m_device, tokens, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, + pipeline_layout); + const uint32_t stride = 2 * sizeof(uint32_t) + sizeof(VkDrawIndirectCommand); + + const auto vert_spv = GLSLToSPV(VK_SHADER_STAGE_VERTEX_BIT, kVertexMinimalGlsl); + VkShaderCreateInfoEXT vert_create_info = + ShaderCreateInfoFlagEXT(vert_spv, VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_CREATE_INDIRECT_BINDABLE_BIT_EXT); + const vkt::ShaderEXT vert_shader(*m_device, vert_create_info); + const auto frag_spv = GLSLToSPV(VK_SHADER_STAGE_FRAGMENT_BIT, kFragmentMinimalGlsl); + VkShaderCreateInfoEXT frag_create_info = + ShaderCreateInfoFlagEXT(frag_spv, VK_SHADER_STAGE_FRAGMENT_BIT, VK_SHADER_CREATE_INDIRECT_BINDABLE_BIT_EXT); + const vkt::ShaderEXT frag_shader(*m_device, frag_create_info); + const VkShaderEXT shaders[] = {vert_shader, frag_shader}; + const VkShaderStageFlagBits stages[] = {VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_FRAGMENT_BIT}; + + VkIndirectExecutionSetShaderLayoutInfoEXT exe_set_layouts[2]; + exe_set_layouts[0] = vku::InitStructHelper(); + exe_set_layouts[1] = vku::InitStructHelper(); + VkIndirectExecutionSetShaderInfoEXT exe_set_shader_info = vku::InitStructHelper(); + exe_set_shader_info.shaderCount = 2; + exe_set_shader_info.pInitialShaders = shaders; + exe_set_shader_info.pSetLayoutInfos = exe_set_layouts; + exe_set_shader_info.maxShaderCount = 2; + vkt::IndirectExecutionSet exe_set(*m_device, exe_set_shader_info); + + vkt::Buffer indirect_buffer(*m_device, stride, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, vkt::device_address); + uint32_t* indirect_data = static_cast(indirect_buffer.Memory().Map()); + indirect_data[0] = 0; // vertex + indirect_data[1] = 1; // fragment + const VkDrawIndirectCommand draw = {3, 1, 0, 0}; + memcpy(indirect_data + 2, &draw, sizeof(draw)); + + VkGeneratedCommandsInfoEXT generated_commands_info = vku::InitStructHelper(); + generated_commands_info.shaderStages = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; + generated_commands_info.indirectExecutionSet = exe_set; + generated_commands_info.indirectCommandsLayout = command_layout; + generated_commands_info.indirectAddressSize = stride; + generated_commands_info.indirectAddress = indirect_buffer.Address(); + generated_commands_info.maxSequenceCount = 1; + generated_commands_info.maxDrawCount = 1; + vkt::PreprocessBuffer preprocess_buffer(*m_device, generated_commands_info); + + m_command_buffer.Begin(); + m_command_buffer.BeginRenderingColor(GetDynamicRenderTarget(), GetRenderTargetArea()); + vk::CmdBindShadersEXT(m_command_buffer, 2u, stages, shaders); + SetDefaultDynamicStatesAllEXT(m_command_buffer); + m_errorMonitor->SetDesiredInfo( + "[EXECUTION_SET] shader object, stage VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT (offset 0, size 8)"); + vk::CmdExecuteGeneratedCommandsEXT(m_command_buffer, false, &generated_commands_info); + m_errorMonitor->VerifyFound(); + m_command_buffer.EndRendering(); + m_command_buffer.End(); +}