From 0b7d7159884a64597689e7cf0a1e73af02277db9 Mon Sep 17 00:00:00 2001 From: THISISAGOODNAME Date: Sat, 29 Oct 2022 21:59:20 +0800 Subject: [PATCH 1/3] VK_NV_mesh_shader -> VK_EXT_mesh_shader --- src/Core/CommandList/CommandList.h | 2 ++ src/Core/CommandList/DXCommandList.cpp | 5 +++++ src/Core/CommandList/DXCommandList.h | 1 + src/Core/CommandList/VKCommandList.cpp | 9 ++++++++- src/Core/CommandList/VKCommandList.h | 1 + src/Core/Device/VKDevice.cpp | 4 ++-- src/Core/HLSLCompiler/Compiler.cpp | 4 ++-- src/Core/Pipeline/VKComputePipeline.cpp | 2 +- src/Core/Pipeline/VKGraphicsPipeline.cpp | 2 +- src/Core/Pipeline/VKRayTracingPipeline.cpp | 2 +- 10 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Core/CommandList/CommandList.h b/src/Core/CommandList/CommandList.h index d7cf2822..f6fddd79 100644 --- a/src/Core/CommandList/CommandList.h +++ b/src/Core/CommandList/CommandList.h @@ -43,7 +43,9 @@ class CommandList : public QueryInterface uint32_t stride) = 0; virtual void Dispatch(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) = 0; virtual void DispatchIndirect(const std::shared_ptr& argument_buffer, uint64_t argument_buffer_offset) = 0; + [[deprecated("Use DispatchMesh(x, y, z) instead.")]] virtual void DispatchMesh(uint32_t thread_group_count_x) = 0; + virtual void DispatchMesh(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) = 0; virtual void DispatchRays(const RayTracingShaderTables& shader_tables, uint32_t width, uint32_t height, uint32_t depth) = 0; virtual void ResourceBarrier(const std::vector& barriers) = 0; virtual void UAVResourceBarrier(const std::shared_ptr& resource) = 0; diff --git a/src/Core/CommandList/DXCommandList.cpp b/src/Core/CommandList/DXCommandList.cpp index ca1e79ab..9eae342e 100644 --- a/src/Core/CommandList/DXCommandList.cpp +++ b/src/Core/CommandList/DXCommandList.cpp @@ -384,6 +384,11 @@ void DXCommandList::DispatchMesh(uint32_t thread_group_count_x) m_command_list6->DispatchMesh(thread_group_count_x, 1, 1); } +void DXCommandList::DispatchMesh(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) +{ + m_command_list6->DispatchMesh(thread_group_count_x, thread_group_count_y, thread_group_count_z); +} + static D3D12_GPU_VIRTUAL_ADDRESS GetVirtualAddress(const RayTracingShaderTable& table) { if (!table.resource) diff --git a/src/Core/CommandList/DXCommandList.h b/src/Core/CommandList/DXCommandList.h index 9b5abf41..6b36b3bc 100644 --- a/src/Core/CommandList/DXCommandList.h +++ b/src/Core/CommandList/DXCommandList.h @@ -42,6 +42,7 @@ class DXCommandList : public CommandList void Dispatch(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) override; void DispatchIndirect(const std::shared_ptr& argument_buffer, uint64_t argument_buffer_offset) override; void DispatchMesh(uint32_t thread_group_count_x) override; + void DispatchMesh(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) override; void DispatchRays(const RayTracingShaderTables& shader_tables, uint32_t width, uint32_t height, uint32_t depth) override; void ResourceBarrier(const std::vector& barriers) override; void UAVResourceBarrier(const std::shared_ptr& resource) override; diff --git a/src/Core/CommandList/VKCommandList.cpp b/src/Core/CommandList/VKCommandList.cpp index 2a488fb8..00120a9c 100644 --- a/src/Core/CommandList/VKCommandList.cpp +++ b/src/Core/CommandList/VKCommandList.cpp @@ -239,7 +239,14 @@ void VKCommandList::DispatchIndirect(const std::shared_ptr& argument_b void VKCommandList::DispatchMesh(uint32_t thread_group_count_x) { #ifndef USE_STATIC_MOLTENVK - m_command_list->drawMeshTasksNV(thread_group_count_x, 0); + m_command_list->drawMeshTasksEXT(thread_group_count_x, 1, 1); +#endif +} + +void VKCommandList::DispatchMesh(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) +{ +#ifndef USE_STATIC_MOLTENVK + m_command_list->drawMeshTasksEXT(thread_group_count_x, thread_group_count_y, thread_group_count_z); #endif } diff --git a/src/Core/CommandList/VKCommandList.h b/src/Core/CommandList/VKCommandList.h index 9b4fac26..9bc92937 100644 --- a/src/Core/CommandList/VKCommandList.h +++ b/src/Core/CommandList/VKCommandList.h @@ -38,6 +38,7 @@ class VKCommandList : public CommandList void Dispatch(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) override; void DispatchIndirect(const std::shared_ptr& argument_buffer, uint64_t argument_buffer_offset) override; void DispatchMesh(uint32_t thread_group_count_x) override; + void DispatchMesh(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) override; void DispatchRays(const RayTracingShaderTables& shader_tables, uint32_t width, uint32_t height, uint32_t depth) override; void ResourceBarrier(const std::vector& barriers) override; void UAVResourceBarrier(const std::shared_ptr& resource) override; diff --git a/src/Core/Device/VKDevice.cpp b/src/Core/Device/VKDevice.cpp index ed52d50f..4b3e729a 100644 --- a/src/Core/Device/VKDevice.cpp +++ b/src/Core/Device/VKDevice.cpp @@ -113,7 +113,7 @@ VKDevice::VKDevice(VKAdapter& adapter) VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME, - VK_NV_MESH_SHADER_EXTENSION_NAME, + VK_EXT_MESH_SHADER_EXTENSION_NAME, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME, }; @@ -127,7 +127,7 @@ VKDevice::VKDevice(VKAdapter& adapter) m_is_variable_rate_shading_supported = true; if (std::string(extension.extensionName.data()) == VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME) m_is_dxr_supported = true; - if (std::string(extension.extensionName.data()) == VK_NV_MESH_SHADER_EXTENSION_NAME) + if (std::string(extension.extensionName.data()) == VK_EXT_MESH_SHADER_EXTENSION_NAME) m_is_mesh_shading_supported = true; if (std::string(extension.extensionName.data()) == VK_KHR_RAY_QUERY_EXTENSION_NAME) m_is_ray_query_supported = true; diff --git a/src/Core/HLSLCompiler/Compiler.cpp b/src/Core/HLSLCompiler/Compiler.cpp index 4c203ede..beb3a5af 100644 --- a/src/Core/HLSLCompiler/Compiler.cpp +++ b/src/Core/HLSLCompiler/Compiler.cpp @@ -100,9 +100,9 @@ std::vector Compile(const ShaderDesc& shader, ShaderBlobType blob_type) if (blob_type == ShaderBlobType::kSPIRV) { arguments.emplace_back(L"-spirv"); - arguments.emplace_back(L"-fspv-target-env=vulkan1.2"); + arguments.emplace_back(L"-fspv-target-env=vulkan1.3"); arguments.emplace_back(L"-fspv-extension=KHR"); - arguments.emplace_back(L"-fspv-extension=SPV_NV_mesh_shader"); + arguments.emplace_back(L"-fspv-extension=SPV_EXT_mesh_shader"); arguments.emplace_back(L"-fspv-extension=SPV_EXT_descriptor_indexing"); arguments.emplace_back(L"-fspv-extension=SPV_EXT_shader_viewport_index_layer"); arguments.emplace_back(L"-fspv-extension=SPV_GOOGLE_hlsl_functionality1"); diff --git a/src/Core/Pipeline/VKComputePipeline.cpp b/src/Core/Pipeline/VKComputePipeline.cpp index 4d2b46ae..319a2c0c 100644 --- a/src/Core/Pipeline/VKComputePipeline.cpp +++ b/src/Core/Pipeline/VKComputePipeline.cpp @@ -13,7 +13,7 @@ VKComputePipeline::VKComputePipeline(VKDevice& device, const ComputePipelineDesc assert(m_shader_stage_create_info.size() == 1); pipeline_info.stage = m_shader_stage_create_info.front(); pipeline_info.layout = m_pipeline_layout; - m_pipeline = m_device.GetDevice().createComputePipelineUnique({}, pipeline_info); + auto [result, m_pipeline] = m_device.GetDevice().createComputePipelineUnique({}, pipeline_info); } PipelineType VKComputePipeline::GetPipelineType() const diff --git a/src/Core/Pipeline/VKGraphicsPipeline.cpp b/src/Core/Pipeline/VKGraphicsPipeline.cpp index 28612966..0d2c52f1 100644 --- a/src/Core/Pipeline/VKGraphicsPipeline.cpp +++ b/src/Core/Pipeline/VKGraphicsPipeline.cpp @@ -205,7 +205,7 @@ VKGraphicsPipeline::VKGraphicsPipeline(VKDevice& device, const GraphicsPipelineD pipeline_info.renderPass = GetRenderPass(); pipeline_info.pDynamicState = &pipelineDynamicStateCreateInfo; - m_pipeline = m_device.GetDevice().createGraphicsPipelineUnique({}, pipeline_info); + auto [result, m_pipeline] = m_device.GetDevice().createGraphicsPipelineUnique({}, pipeline_info); } PipelineType VKGraphicsPipeline::GetPipelineType() const diff --git a/src/Core/Pipeline/VKRayTracingPipeline.cpp b/src/Core/Pipeline/VKRayTracingPipeline.cpp index 1327b4cc..e91ef54f 100644 --- a/src/Core/Pipeline/VKRayTracingPipeline.cpp +++ b/src/Core/Pipeline/VKRayTracingPipeline.cpp @@ -58,7 +58,7 @@ VKRayTracingPipeline::VKRayTracingPipeline(VKDevice& device, const RayTracingPip ray_pipeline_info.layout = m_pipeline_layout; #ifndef USE_STATIC_MOLTENVK - m_pipeline = m_device.GetDevice().createRayTracingPipelineKHRUnique({}, {}, ray_pipeline_info); + auto [result, m_pipeline] = m_device.GetDevice().createRayTracingPipelineKHRUnique({}, {}, ray_pipeline_info); #endif } From e33ac7908788df3adca75ae99273db6948a8ef09 Mon Sep 17 00:00:00 2001 From: THISISAGOODNAME Date: Sat, 29 Oct 2022 22:21:30 +0800 Subject: [PATCH 2/3] update Vulkan-Headers --- 3rdparty/Vulkan-Headers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/Vulkan-Headers b/3rdparty/Vulkan-Headers index aa18f182..e12a8f8c 160000 --- a/3rdparty/Vulkan-Headers +++ b/3rdparty/Vulkan-Headers @@ -1 +1 @@ -Subproject commit aa18f182ebba65438b1cfdbd571f020bb2e34d04 +Subproject commit e12a8f8cde4047fb40c34bc1bf624e24c0d0c76e From 255a1e11d60fac86c22aae82dfeabc381757f053 Mon Sep 17 00:00:00 2001 From: THISISAGOODNAME Date: Sun, 30 Oct 2022 09:29:35 +0800 Subject: [PATCH 3/3] Fixing 1. DispatchMesh(x,y,z) missing in MTCommandList 2. m_pipeline not setting in VKXXXpipeline --- src/Core/CommandList/MTCommandList.h | 1 + src/Core/CommandList/MTCommandList.mm | 5 +++++ src/Core/Pipeline/VKComputePipeline.cpp | 6 +++++- src/Core/Pipeline/VKGraphicsPipeline.cpp | 6 +++++- src/Core/Pipeline/VKRayTracingPipeline.cpp | 6 +++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Core/CommandList/MTCommandList.h b/src/Core/CommandList/MTCommandList.h index ad3ce980..c40e3860 100644 --- a/src/Core/CommandList/MTCommandList.h +++ b/src/Core/CommandList/MTCommandList.h @@ -42,6 +42,7 @@ class MTCommandList : public CommandList void Dispatch(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) override; void DispatchIndirect(const std::shared_ptr& argument_buffer, uint64_t argument_buffer_offset) override; void DispatchMesh(uint32_t thread_group_count_x) override; + void DispatchMesh(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) override; void DispatchRays(const RayTracingShaderTables& shader_tables, uint32_t width, uint32_t height, uint32_t depth) override; void ResourceBarrier(const std::vector& barriers) override; void UAVResourceBarrier(const std::shared_ptr& resource) override; diff --git a/src/Core/CommandList/MTCommandList.mm b/src/Core/CommandList/MTCommandList.mm index c913a3ed..5b062364 100644 --- a/src/Core/CommandList/MTCommandList.mm +++ b/src/Core/CommandList/MTCommandList.mm @@ -369,6 +369,11 @@ static MTLCullMode ConvertCullMode(CullMode cull_mode) assert(false); } +void MTCommandList::DispatchMesh(uint32_t thread_group_count_x, uint32_t thread_group_count_y, uint32_t thread_group_count_z) +{ + assert(false); +} + void MTCommandList::DispatchRays(const RayTracingShaderTables& shader_tables, uint32_t width, uint32_t height, uint32_t depth) { assert(false); diff --git a/src/Core/Pipeline/VKComputePipeline.cpp b/src/Core/Pipeline/VKComputePipeline.cpp index 319a2c0c..11c2af84 100644 --- a/src/Core/Pipeline/VKComputePipeline.cpp +++ b/src/Core/Pipeline/VKComputePipeline.cpp @@ -13,7 +13,11 @@ VKComputePipeline::VKComputePipeline(VKDevice& device, const ComputePipelineDesc assert(m_shader_stage_create_info.size() == 1); pipeline_info.stage = m_shader_stage_create_info.front(); pipeline_info.layout = m_pipeline_layout; - auto [result, m_pipeline] = m_device.GetDevice().createComputePipelineUnique({}, pipeline_info); + auto resultValue = m_device.GetDevice().createComputePipelineUnique({}, pipeline_info); + if (resultValue.result == vk::Result::eSuccess) + m_pipeline = std::move(resultValue.value); + else + assert(false); } PipelineType VKComputePipeline::GetPipelineType() const diff --git a/src/Core/Pipeline/VKGraphicsPipeline.cpp b/src/Core/Pipeline/VKGraphicsPipeline.cpp index 0d2c52f1..a626142f 100644 --- a/src/Core/Pipeline/VKGraphicsPipeline.cpp +++ b/src/Core/Pipeline/VKGraphicsPipeline.cpp @@ -205,7 +205,11 @@ VKGraphicsPipeline::VKGraphicsPipeline(VKDevice& device, const GraphicsPipelineD pipeline_info.renderPass = GetRenderPass(); pipeline_info.pDynamicState = &pipelineDynamicStateCreateInfo; - auto [result, m_pipeline] = m_device.GetDevice().createGraphicsPipelineUnique({}, pipeline_info); + auto resultValue = m_device.GetDevice().createGraphicsPipelineUnique({}, pipeline_info); + if (resultValue.result == vk::Result::eSuccess) + m_pipeline = std::move(resultValue.value); + else + assert(false); } PipelineType VKGraphicsPipeline::GetPipelineType() const diff --git a/src/Core/Pipeline/VKRayTracingPipeline.cpp b/src/Core/Pipeline/VKRayTracingPipeline.cpp index e91ef54f..15f0d74a 100644 --- a/src/Core/Pipeline/VKRayTracingPipeline.cpp +++ b/src/Core/Pipeline/VKRayTracingPipeline.cpp @@ -58,7 +58,11 @@ VKRayTracingPipeline::VKRayTracingPipeline(VKDevice& device, const RayTracingPip ray_pipeline_info.layout = m_pipeline_layout; #ifndef USE_STATIC_MOLTENVK - auto [result, m_pipeline] = m_device.GetDevice().createRayTracingPipelineKHRUnique({}, {}, ray_pipeline_info); + auto resultValue = m_device.GetDevice().createRayTracingPipelineKHRUnique({}, {}, ray_pipeline_info); + if (resultValue.result == vk::Result::eSuccess) + m_pipeline = std::move(resultValue.value); + else + assert(false); #endif }