From 1e8eb7d6bf5205c9b7c1a868942197702068ea3d Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 5 Jul 2019 17:00:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=80=E6=9C=89PipelineCreater=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=94=B9=E7=94=A8=E6=99=BA=E8=83=BD=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/Atomsphere.cpp | 5 +-- example/Vulkan/Deferred.cpp | 19 ++++------ example/Vulkan/Geometry2D.cpp | 23 +++++------ example/Vulkan/Geometry3D.cpp | 26 ++++++------- example/Vulkan/InlineGeometryScene.cpp | 26 +++++++------ example/Vulkan/LoadModel.cpp | 38 +++++++++---------- example/Vulkan/SceneTree.cpp | 30 +++++++-------- example/Vulkan/indices_rect.cpp | 5 +-- example/Vulkan/main.cpp | 9 ++--- example/Vulkan/texture_rect.cpp | 7 +--- src/RenderDevice/Vulkan/VKCommandBuffer.cpp | 26 ++++++------- .../Vulkan/VKShaderModuleManage.cpp | 22 +++++------ src/RenderDevice/Vulkan/VKShaderParse.h | 2 +- 13 files changed, 108 insertions(+), 130 deletions(-) diff --git a/example/Vulkan/Atomsphere.cpp b/example/Vulkan/Atomsphere.cpp index c2de3f9b..43f504ea 100644 --- a/example/Vulkan/Atomsphere.cpp +++ b/example/Vulkan/Atomsphere.cpp @@ -87,7 +87,8 @@ private: bool InitPipeline() { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthWrite(true); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); @@ -98,8 +99,6 @@ private: return(false); db->Add(pipeline_solid); - - delete pipeline_creater; return(true); } diff --git a/example/Vulkan/Deferred.cpp b/example/Vulkan/Deferred.cpp index f12ce231..edf4ec12 100644 --- a/example/Vulkan/Deferred.cpp +++ b/example/Vulkan/Deferred.cpp @@ -49,7 +49,7 @@ private: Texture2DPointer texture_list[4]; }; - List color_format_list; + List gbuffer_format_list; List image_view_list; struct @@ -91,13 +91,13 @@ private: for(uint i=0;i<3;i++) { - gbuffer.color_format_list.Add(gbuffer.texture_list[i]->GetFormat()); + gbuffer.gbuffer_format_list.Add(gbuffer.texture_list[i]->GetFormat()); gbuffer.image_view_list.Add(gbuffer.texture_list[i]->GetImageView()); } if(!device->CreateAttachment( gbuffer.attachment.ref_list, gbuffer.attachment.desc_list, - gbuffer.color_format_list, + gbuffer.gbuffer_format_list, gbuffer.depth->GetFormat())) return(false); @@ -112,7 +112,7 @@ private: gbuffer.renderpass=device->CreateRenderPass(gbuffer.attachment.desc_list, gbuffer.subpass.desc, gbuffer.subpass.dependency, - gbuffer.color_format_list, + gbuffer.gbuffer_format_list, gbuffer.depth->GetFormat()); if(!gbuffer.renderpass) @@ -131,7 +131,7 @@ private: sp->material=shader_manage->CreateMaterial(vs,fs); if(!sp->material) - return(false); + return(false); sp->desc_sets=sp->material->CreateDescriptorSets(); @@ -142,25 +142,24 @@ private: bool InitGBufferPipeline(SubpassParam *sp) { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,sp->material,gbuffer.renderpass,device->GetExtent()); + SharedPtr pipeline_creater=new vulkan::PipelineCreater(device,sp->material,gbuffer.renderpass,device->GetExtent()); pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthWrite(true); pipeline_creater->SetCullMode(VK_CULL_MODE_BACK_BIT); pipeline_creater->Set(PRIM_TRIANGLES); + sp->pipeline=pipeline_creater->Create(); if(!sp->pipeline) return(false); db->Add(sp->pipeline); - - delete pipeline_creater; return(true); } bool InitCompositionPipeline(SubpassParam *sp) { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,sp->material,device->GetMainRenderPass(),device->GetExtent()); + SharedPtr pipeline_creater=new vulkan::PipelineCreater(device,sp->material,device->GetMainRenderPass(),device->GetExtent()); pipeline_creater->SetDepthTest(false); pipeline_creater->SetDepthWrite(false); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); @@ -171,8 +170,6 @@ private: return(false); db->Add(sp->pipeline); - - delete pipeline_creater; return(true); } diff --git a/example/Vulkan/Geometry2D.cpp b/example/Vulkan/Geometry2D.cpp index 448a0e43..3c0d7dad 100644 --- a/example/Vulkan/Geometry2D.cpp +++ b/example/Vulkan/Geometry2D.cpp @@ -114,21 +114,18 @@ private: bool InitPipeline() { - constexpr os_char PIPELINE_FILENAME[]=OS_TEXT("2DSolid.pipeline"); + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + pipeline_creater->SetDepthTest(false); + pipeline_creater->SetDepthWrite(false); + pipeline_creater->CloseCullFace(); + pipeline_creater->Set(PRIM_TRIANGLE_FAN); - { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(false); - pipeline_creater->SetDepthWrite(false); - pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_TRIANGLE_FAN); + pipeline=pipeline_creater->Create(); + if(!pipeline)return(false); - pipeline=pipeline_creater->Create(); - db->Add(pipeline); - delete pipeline_creater; - } - - return pipeline; + db->Add(pipeline); + return(true); } bool InitScene() diff --git a/example/Vulkan/Geometry3D.cpp b/example/Vulkan/Geometry3D.cpp index 7588116c..e6ea5930 100644 --- a/example/Vulkan/Geometry3D.cpp +++ b/example/Vulkan/Geometry3D.cpp @@ -84,23 +84,19 @@ private: bool InitPipeline() { - { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(true); - pipeline_creater->SetDepthWrite(true); - pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_LINES); + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + pipeline_creater->SetDepthTest(true); + pipeline_creater->SetDepthWrite(true); + pipeline_creater->CloseCullFace(); + pipeline_creater->Set(PRIM_LINES); - pipeline_line=pipeline_creater->Create(); - if(!pipeline_line) - return(false); + pipeline_line=pipeline_creater->Create(); + if(!pipeline_line) + return(false); - db->Add(pipeline_line); - - delete pipeline_creater; - } - - return pipeline_line; + db->Add(pipeline_line); + return(true); } bool InitScene() diff --git a/example/Vulkan/InlineGeometryScene.cpp b/example/Vulkan/InlineGeometryScene.cpp index 8111ade8..5826d3b8 100644 --- a/example/Vulkan/InlineGeometryScene.cpp +++ b/example/Vulkan/InlineGeometryScene.cpp @@ -137,31 +137,35 @@ private: bool InitPipeline() { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthWrite(true); pipeline_creater->Set(PRIM_LINES); pipeline_line=pipeline_creater->Create(); + + if(!pipeline_line) + return(false); + db->Add(pipeline_line); pipeline_creater->Set(PRIM_TRIANGLES); pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE); pipeline_solid=pipeline_creater->Create(); - db->Add(pipeline_solid); - - pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); - pipeline_twoside=pipeline_creater->Create(); - db->Add(pipeline_twoside); - - delete pipeline_creater; - - if(!pipeline_line) - return(false); if(!pipeline_solid) return(false); + db->Add(pipeline_solid); + + pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); + pipeline_twoside=pipeline_creater->Create(); + + if(!pipeline_twoside) + return(false); + + db->Add(pipeline_twoside); return(true); } diff --git a/example/Vulkan/LoadModel.cpp b/example/Vulkan/LoadModel.cpp index 0e650c1e..5fe2cf17 100644 --- a/example/Vulkan/LoadModel.cpp +++ b/example/Vulkan/LoadModel.cpp @@ -162,33 +162,31 @@ private: bool InitPipeline() { - constexpr os_char PIPELINE_FILENAME[]=OS_TEXT("2DSolid.pipeline"); + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + pipeline_creater->SetDepthTest(false); + pipeline_creater->SetDepthWrite(false); + pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE); + pipeline_creater->CloseCullFace(); + pipeline_creater->Set(PRIM_TRIANGLES); - { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(false); - pipeline_creater->SetDepthWrite(false); - pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE); - pipeline_creater->CloseCullFace(); - pipeline_creater->Set(PRIM_TRIANGLES); + pipeline_wireframe=pipeline_creater->Create(); - pipeline_wireframe=pipeline_creater->Create(); + if(!pipeline_wireframe) + return(false); - if(pipeline_wireframe) - db->Add(pipeline_wireframe); + db->Add(pipeline_wireframe); - pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_FILL); - pipeline_creater->Set(PRIM_LINES); + pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_FILL); + pipeline_creater->Set(PRIM_LINES); - pipeline_lines=pipeline_creater->Create(); + pipeline_lines=pipeline_creater->Create(); - if(pipeline_lines) - db->Add(pipeline_lines); + if(!pipeline_lines) + return(false); - delete pipeline_creater; - } - - return pipeline_wireframe; + db->Add(pipeline_lines); + return(true); } void CreateSceneNode(SceneNode *scene_node,ModelSceneNode *model_node) diff --git a/example/Vulkan/SceneTree.cpp b/example/Vulkan/SceneTree.cpp index 57d91c95..c504f7a2 100644 --- a/example/Vulkan/SceneTree.cpp +++ b/example/Vulkan/SceneTree.cpp @@ -73,25 +73,21 @@ private: } bool InitPipeline() - { - { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(true); - pipeline_creater->SetDepthWrite(true); - pipeline_creater->CloseCullFace(); - pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE); - pipeline_creater->Set(PRIM_TRIANGLES); + { + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + pipeline_creater->SetDepthTest(true); + pipeline_creater->SetDepthWrite(true); + pipeline_creater->CloseCullFace(); + pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE); + pipeline_creater->Set(PRIM_TRIANGLES); - pipeline_line=pipeline_creater->Create(); - if(!pipeline_line) - return(false); + pipeline_line=pipeline_creater->Create(); + if(!pipeline_line) + return(false); - db->Add(pipeline_line); - - delete pipeline_creater; - } - - return pipeline_line; + db->Add(pipeline_line); + return(true); } bool InitScene() diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index 86092956..df04b67a 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -103,7 +103,7 @@ private: bool InitPipeline() { - vulkan::PipelineCreater * + SharedPtr pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); pipeline_creater->SetDepthTest(false); pipeline_creater->SetDepthWrite(false); @@ -112,9 +112,6 @@ private: pipeline=pipeline_creater->Create(); - delete pipeline_creater; - pipeline_creater=nullptr; - return pipeline; } diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index dbed2526..188f547f 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -107,26 +107,23 @@ private: constexpr os_char PIPELINE_FILENAME[]=OS_TEXT("2DSolid.pipeline"); { - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); pipeline_creater->SetDepthTest(false); pipeline_creater->SetDepthWrite(false); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLES); SaveToFile(PIPELINE_FILENAME,pipeline_creater); - - delete pipeline_creater; } { void *data; uint size=filesystem::LoadFileToMemory(PIPELINE_FILENAME,(void **)&data); - vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent(),(uchar *)data,size); + SharedPtr pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent(),(uchar *)data,size); pipeline=pipeline_creater->Create(); - - delete pipeline_creater; } return pipeline; diff --git a/example/Vulkan/texture_rect.cpp b/example/Vulkan/texture_rect.cpp index 7d2efd3a..3e9ad671 100644 --- a/example/Vulkan/texture_rect.cpp +++ b/example/Vulkan/texture_rect.cpp @@ -148,8 +148,8 @@ private: bool InitPipeline() { - vulkan::PipelineCreater * - pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); + SharedPtr + pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); pipeline_creater->SetDepthTest(false); pipeline_creater->SetDepthWrite(false); pipeline_creater->CloseCullFace(); @@ -157,9 +157,6 @@ private: pipeline=pipeline_creater->Create(); - delete pipeline_creater; - pipeline_creater=nullptr; - return pipeline; } diff --git a/src/RenderDevice/Vulkan/VKCommandBuffer.cpp b/src/RenderDevice/Vulkan/VKCommandBuffer.cpp index 23e88606..fa7441a4 100644 --- a/src/RenderDevice/Vulkan/VKCommandBuffer.cpp +++ b/src/RenderDevice/Vulkan/VKCommandBuffer.cpp @@ -52,22 +52,22 @@ bool CommandBuffer::BeginRenderPass(RenderPass *rp,Framebuffer *fb) { VkRenderPassBeginInfo rp_begin; - rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - rp_begin.pNext = nullptr; - rp_begin.renderPass = *rp; - rp_begin.framebuffer = *fb; - rp_begin.renderArea = render_area; - rp_begin.clearValueCount = 2; - rp_begin.pClearValues = clear_values; + rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + rp_begin.pNext = nullptr; + rp_begin.renderPass = *rp; + rp_begin.framebuffer = *fb; + rp_begin.renderArea = render_area; + rp_begin.clearValueCount = 2; + rp_begin.pClearValues = clear_values; vkCmdBeginRenderPass(cmd_buf, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); - viewport.x=0; - viewport.y=0; - viewport.minDepth=0.0f; - viewport.maxDepth=1.0f; - viewport.width=render_area.extent.width; - viewport.height=render_area.extent.height; + viewport.x = 0; + viewport.y = 0; + viewport.minDepth = 0.0f; + viewport.maxDepth = 1.0f; + viewport.width = render_area.extent.width; + viewport.height = render_area.extent.height; vkCmdSetViewport(cmd_buf,0,1,&viewport); vkCmdSetScissor(cmd_buf,0,1,&render_area); diff --git a/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp b/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp index 3db88eda..ee1ca8b9 100644 --- a/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp +++ b/src/RenderDevice/Vulkan/VKShaderModuleManage.cpp @@ -31,19 +31,19 @@ const ShaderModule *ShaderModuleManage::CreateShader(const VkShaderStageFlagBits return(nullptr); VkPipelineShaderStageCreateInfo *shader_stage=new VkPipelineShaderStageCreateInfo; - shader_stage->sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - shader_stage->pNext=nullptr; - shader_stage->pSpecializationInfo=nullptr; - shader_stage->flags=0; - shader_stage->stage=shader_stage_bit; - shader_stage->pName="main"; + shader_stage->sType =VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stage->pNext =nullptr; + shader_stage->pSpecializationInfo =nullptr; + shader_stage->flags =0; + shader_stage->stage =shader_stage_bit; + shader_stage->pName ="main"; VkShaderModuleCreateInfo moduleCreateInfo; - moduleCreateInfo.sType=VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - moduleCreateInfo.pNext=nullptr; - moduleCreateInfo.flags=0; - moduleCreateInfo.codeSize=spv_size; - moduleCreateInfo.pCode=(const uint32_t *)spv_data; + moduleCreateInfo.sType =VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + moduleCreateInfo.pNext =nullptr; + moduleCreateInfo.flags =0; + moduleCreateInfo.codeSize =spv_size; + moduleCreateInfo.pCode =(const uint32_t *)spv_data; if(vkCreateShaderModule(*device,&moduleCreateInfo,nullptr,&(shader_stage->module))!=VK_SUCCESS) return(nullptr); diff --git a/src/RenderDevice/Vulkan/VKShaderParse.h b/src/RenderDevice/Vulkan/VKShaderParse.h index 2c78363f..f997abe5 100644 --- a/src/RenderDevice/Vulkan/VKShaderParse.h +++ b/src/RenderDevice/Vulkan/VKShaderParse.h @@ -32,8 +32,8 @@ public: SHADER_PARSE_GET_RESOURCE(StageInputs, stage_inputs) SHADER_PARSE_GET_RESOURCE(StageOutputs, stage_outputs) SHADER_PARSE_GET_RESOURCE(Sampler, sampled_images) + SHADER_PARSE_GET_RESOURCE(Subpass, subpass_inputs) - //SmallVector subpass_inputs; //SmallVector storage_images; //SmallVector atomic_counters; //SmallVector acceleration_structures;