From 43ce892284a7c7f4294691a831602ae0150443aa Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Wed, 15 Sep 2021 01:41:42 +0000 Subject: [PATCH] Remove descriptor in RenderPipeline::Initialize This patch removes the parameter "descriptor" from the function RenderPipeline::Initialize() on D3D12, Metal and Vulkan backends as a preparation of creating render pipeline asynchronously. BUG=dawn:529 Change-Id: I6bdd74ad0af6a1924fac3703908cd5f66b75994b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64163 Reviewed-by: Austin Eng Commit-Queue: Jiawei Shao --- src/dawn_native/d3d12/RenderPipelineD3D12.cpp | 15 +++++++++------ src/dawn_native/d3d12/RenderPipelineD3D12.h | 2 +- src/dawn_native/metal/RenderPipelineMTL.h | 2 +- src/dawn_native/metal/RenderPipelineMTL.mm | 14 ++++++++------ src/dawn_native/vulkan/RenderPipelineVk.cpp | 18 ++++++++++-------- src/dawn_native/vulkan/RenderPipelineVk.h | 2 +- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp index 0978bd8222..12aa05b93f 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp @@ -319,11 +319,11 @@ namespace dawn_native { namespace d3d12 { Device* device, const RenderPipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize(descriptor)); + DAWN_TRY(pipeline->Initialize()); return pipeline; } - MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { + MaybeError RenderPipeline::Initialize() { Device* device = ToBackend(GetDevice()); uint32_t compileFlags = 0; @@ -340,13 +340,16 @@ namespace dawn_native { namespace d3d12 { D3D12_GRAPHICS_PIPELINE_STATE_DESC descriptorD3D12 = {}; + const ProgrammableStage& vertexStage = GetStage(SingleShaderStage::Vertex); + const ProgrammableStage& fragmentStage = GetStage(SingleShaderStage::Fragment); + PerStage entryPoints; - entryPoints[SingleShaderStage::Vertex] = descriptor->vertex.entryPoint; - entryPoints[SingleShaderStage::Fragment] = descriptor->fragment->entryPoint; + entryPoints[SingleShaderStage::Vertex] = vertexStage.entryPoint.c_str(); + entryPoints[SingleShaderStage::Fragment] = fragmentStage.entryPoint.c_str(); PerStage modules; - modules[SingleShaderStage::Vertex] = ToBackend(descriptor->vertex.module); - modules[SingleShaderStage::Fragment] = ToBackend(descriptor->fragment->module); + modules[SingleShaderStage::Vertex] = ToBackend(vertexStage.module.Get()); + modules[SingleShaderStage::Fragment] = ToBackend(fragmentStage.module.Get()); PerStage shaders; shaders[SingleShaderStage::Vertex] = &descriptorD3D12.VS; diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.h b/src/dawn_native/d3d12/RenderPipelineD3D12.h index 67222f4320..ed71da92a9 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.h +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.h @@ -42,7 +42,7 @@ namespace dawn_native { namespace d3d12 { private: ~RenderPipeline() override; using RenderPipelineBase::RenderPipelineBase; - MaybeError Initialize(const RenderPipelineDescriptor* descriptor); + MaybeError Initialize(); D3D12_INPUT_LAYOUT_DESC ComputeInputLayout( std::array* inputElementDescriptors); diff --git a/src/dawn_native/metal/RenderPipelineMTL.h b/src/dawn_native/metal/RenderPipelineMTL.h index 43eebec365..07a2d77292 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.h +++ b/src/dawn_native/metal/RenderPipelineMTL.h @@ -47,7 +47,7 @@ namespace dawn_native { namespace metal { private: using RenderPipelineBase::RenderPipelineBase; - MaybeError Initialize(const RenderPipelineDescriptor* descriptor); + MaybeError Initialize(); MTLVertexDescriptor* MakeVertexDesc(); diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm index 17706d7698..a38a23a755 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.mm +++ b/src/dawn_native/metal/RenderPipelineMTL.mm @@ -314,11 +314,11 @@ namespace dawn_native { namespace metal { Device* device, const RenderPipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize(descriptor)); + DAWN_TRY(pipeline->Initialize()); return pipeline; } - MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { + MaybeError RenderPipeline::Initialize() { mMtlPrimitiveTopology = MTLPrimitiveTopology(GetPrimitiveTopology()); mMtlFrontFace = MTLFrontFace(GetFrontFace()); mMtlCullMode = ToMTLCullMode(GetCullMode()); @@ -338,8 +338,9 @@ namespace dawn_native { namespace metal { } descriptorMTL.vertexDescriptor = vertexDesc.Get(); - ShaderModule* vertexModule = ToBackend(descriptor->vertex.module); - const char* vertexEntryPoint = descriptor->vertex.entryPoint; + const ProgrammableStage& vertexStage = GetStage(SingleShaderStage::Vertex); + ShaderModule* vertexModule = ToBackend(vertexStage.module.Get()); + const char* vertexEntryPoint = vertexStage.entryPoint.c_str(); ShaderModule::MetalFunctionData vertexData; DAWN_TRY(vertexModule->CreateFunction(vertexEntryPoint, SingleShaderStage::Vertex, ToBackend(GetLayout()), &vertexData, 0xFFFFFFFF, @@ -350,8 +351,9 @@ namespace dawn_native { namespace metal { mStagesRequiringStorageBufferLength |= wgpu::ShaderStage::Vertex; } - ShaderModule* fragmentModule = ToBackend(descriptor->fragment->module); - const char* fragmentEntryPoint = descriptor->fragment->entryPoint; + const ProgrammableStage& fragmentStage = GetStage(SingleShaderStage::Fragment); + ShaderModule* fragmentModule = ToBackend(fragmentStage.module.Get()); + const char* fragmentEntryPoint = fragmentStage.entryPoint.c_str(); ShaderModule::MetalFunctionData fragmentData; DAWN_TRY(fragmentModule->CreateFunction(fragmentEntryPoint, SingleShaderStage::Fragment, ToBackend(GetLayout()), &fragmentData, diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp index 22bfe8248a..5fb426633e 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.cpp +++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp @@ -323,38 +323,40 @@ namespace dawn_native { namespace vulkan { Device* device, const RenderPipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize(descriptor)); + DAWN_TRY(pipeline->Initialize()); return pipeline; } - MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { + MaybeError RenderPipeline::Initialize() { Device* device = ToBackend(GetDevice()); VkPipelineShaderStageCreateInfo shaderStages[2]; { // Generate a new VkShaderModule with BindingRemapper tint transform for each // pipeline + const ProgrammableStage& vertexStage = GetStage(SingleShaderStage::Vertex); DAWN_TRY_ASSIGN(shaderStages[0].module, - ToBackend(descriptor->vertex.module) - ->GetTransformedModuleHandle(descriptor->vertex.entryPoint, + ToBackend(vertexStage.module.Get()) + ->GetTransformedModuleHandle(vertexStage.entryPoint.c_str(), ToBackend(GetLayout()))); + const ProgrammableStage& fragmentStage = GetStage(SingleShaderStage::Fragment); DAWN_TRY_ASSIGN(shaderStages[1].module, - ToBackend(descriptor->fragment->module) - ->GetTransformedModuleHandle(descriptor->fragment->entryPoint, + ToBackend(fragmentStage.module.Get()) + ->GetTransformedModuleHandle(fragmentStage.entryPoint.c_str(), ToBackend(GetLayout()))); shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStages[0].pNext = nullptr; shaderStages[0].flags = 0; shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; shaderStages[0].pSpecializationInfo = nullptr; - shaderStages[0].pName = descriptor->vertex.entryPoint; + shaderStages[0].pName = vertexStage.entryPoint.c_str(); shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStages[1].pNext = nullptr; shaderStages[1].flags = 0; shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; shaderStages[1].pSpecializationInfo = nullptr; - shaderStages[1].pName = descriptor->fragment->entryPoint; + shaderStages[1].pName = fragmentStage.entryPoint.c_str(); } PipelineVertexInputStateCreateInfoTemporaryAllocations tempAllocations; diff --git a/src/dawn_native/vulkan/RenderPipelineVk.h b/src/dawn_native/vulkan/RenderPipelineVk.h index 9339bb63da..fe653c80d4 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.h +++ b/src/dawn_native/vulkan/RenderPipelineVk.h @@ -38,7 +38,7 @@ namespace dawn_native { namespace vulkan { private: ~RenderPipeline() override; using RenderPipelineBase::RenderPipelineBase; - MaybeError Initialize(const RenderPipelineDescriptor* descriptor); + MaybeError Initialize(); struct PipelineVertexInputStateCreateInfoTemporaryAllocations { std::array bindings;