upgrade the PipelineCreater, it don't need use RenderTarge when construct.

This commit is contained in:
hyzboy 2020-09-18 11:45:52 +08:00
parent e7ed72d6e2
commit 5df8466cc8
3 changed files with 18 additions and 27 deletions

View File

@ -87,12 +87,12 @@ private:
bool InitPipeline() bool InitPipeline()
{ {
AutoDelete<vulkan::PipelineCreater> AutoDelete<vulkan::PipelineCreater>
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target); pipeline_creater=new vulkan::PipelineCreater(device,material);
pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthTest(true);
pipeline_creater->SetDepthWrite(true); pipeline_creater->SetDepthWrite(true);
pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE);
pipeline_creater->Set(Prim::Triangles); pipeline_creater->Set(Prim::Triangles);
pipeline_solid=pipeline_creater->Create(); pipeline_solid=pipeline_creater->Create(sc_render_target);
if(!pipeline_solid) if(!pipeline_solid)
return(false); return(false);

View File

@ -40,7 +40,6 @@ constexpr size_t VK_DYNAMIC_STATE_RANGE_SIZE=VK_DYNAMIC_STATE_END_RANGE-VK_DYNAM
class PipelineCreater class PipelineCreater
{ {
VkDevice device; VkDevice device;
VkExtent2D extent;
VkPipelineCache cache; VkPipelineCache cache;
VkGraphicsPipelineCreateInfo pipelineInfo; VkGraphicsPipelineCreateInfo pipelineInfo;
@ -55,7 +54,7 @@ class PipelineCreater
VkRect2D scissor; VkRect2D scissor;
VkPipelineViewportStateCreateInfo viewportState; VkPipelineViewportStateCreateInfo viewportState;
void InitViewportState(); void InitViewportState(const VkExtent2D &);
VkPipelineRasterizationStateCreateInfo rasterizer; VkPipelineRasterizationStateCreateInfo rasterizer;
@ -77,8 +76,8 @@ class PipelineCreater
public: public:
PipelineCreater(Device *dev,const Material *,const RenderTarget *); PipelineCreater(Device *dev,const Material *,const uint32_t color_attachment_count=1);
PipelineCreater(Device *dev,const Material *,const RenderTarget *,uchar *data,uint size); PipelineCreater(Device *dev,const Material *,uchar *data,uint size);
~PipelineCreater()=default; ~PipelineCreater()=default;
bool Set(const Prim prim,bool=false); bool Set(const Prim prim,bool=false);
@ -193,7 +192,7 @@ public:
bool SaveToStream(io::DataOutputStream *dos); bool SaveToStream(io::DataOutputStream *dos);
bool LoadFromMemory(uchar *,uint); bool LoadFromMemory(uchar *,uint);
Pipeline *Create(); Pipeline *Create(const RenderTarget *);
};//class PipelineCreater };//class PipelineCreater
VK_NAMESPACE_END VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_PIPELINE_INCLUDE #endif//HGL_GRAPH_VULKAN_PIPELINE_INCLUDE

View File

@ -27,7 +27,7 @@ void PipelineCreater::InitVertexInputState(const Material *material)
} }
} }
void PipelineCreater::InitViewportState() void PipelineCreater::InitViewportState(const VkExtent2D &extent)
{ {
viewport.x = 0.0f; viewport.x = 0.0f;
viewport.y = 0.0f; viewport.y = 0.0f;
@ -70,10 +70,9 @@ void PipelineCreater::InitDynamicState()
//为什么一定要把ext放在这里因为如果不放在这里总是会让人遗忘它的重要性 //为什么一定要把ext放在这里因为如果不放在这里总是会让人遗忘它的重要性
PipelineCreater::PipelineCreater(Device *dev,const Material *material,const RenderTarget *rt) PipelineCreater::PipelineCreater(Device *dev,const Material *material,const uint32_t color_attachment_count)
{ {
device=dev->GetDevice(); device=dev->GetDevice();
extent=rt->GetExtent();
cache=dev->GetPipelineCache(); cache=dev->GetPipelineCache();
//未来这里需要增加是否有vs/fs的检测 //未来这里需要增加是否有vs/fs的检测
@ -89,8 +88,6 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,const Rend
pipelineInfo.pTessellationState=&tessellation; pipelineInfo.pTessellationState=&tessellation;
InitViewportState();
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rasterizer.pNext = nullptr; rasterizer.pNext = nullptr;
rasterizer.flags = 0; rasterizer.flags = 0;
@ -151,7 +148,7 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,const Rend
cba.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; cba.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
cba.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; cba.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendAttachments.Add(cba,rt->GetColorCount()); //这个需要和subpass中的color attachment数量相等所以添加多份 colorBlendAttachments.Add(cba,color_attachment_count); //这个需要和subpass中的color attachment数量相等所以添加多份
alpha_blend=false; alpha_blend=false;
@ -172,10 +169,6 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,const Rend
InitDynamicState(); InitDynamicState();
pipelineInfo.layout = material->GetPipelineLayout(); pipelineInfo.layout = material->GetPipelineLayout();
{
pipelineInfo.renderPass = rt->GetRenderPass();
pipelineInfo.subpass = 0; //subpass由于还不知道有什么用所以暂时写0待知道功用后需改进
}
{ {
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
@ -183,21 +176,17 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,const Rend
} }
} }
PipelineCreater::PipelineCreater(Device *dev,const Material *material,const RenderTarget *rt,uchar *data,uint size) PipelineCreater::PipelineCreater(Device *dev,const Material *material,uchar *data,uint size)
{ {
LoadFromMemory(data,size); LoadFromMemory(data,size);
device=dev->GetDevice(); device=dev->GetDevice();
extent=rt->GetExtent();
cache=dev->GetPipelineCache(); cache=dev->GetPipelineCache();
InitVertexInputState(material); InitVertexInputState(material);
pipelineInfo.pInputAssemblyState=&inputAssembly; pipelineInfo.pInputAssemblyState=&inputAssembly;
pipelineInfo.pTessellationState =&tessellation; pipelineInfo.pTessellationState =&tessellation;
InitViewportState();
pipelineInfo.pRasterizationState=&rasterizer; pipelineInfo.pRasterizationState=&rasterizer;
pipelineInfo.pMultisampleState =&multisampling; pipelineInfo.pMultisampleState =&multisampling;
pipelineInfo.pDepthStencilState =&depthStencilState; pipelineInfo.pDepthStencilState =&depthStencilState;
@ -206,10 +195,6 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,const Rend
InitDynamicState(); InitDynamicState();
pipelineInfo.layout = material->GetPipelineLayout(); pipelineInfo.layout = material->GetPipelineLayout();
{
pipelineInfo.renderPass = rt->GetRenderPass();
pipelineInfo.subpass = 0; //subpass由于还不知道有什么用所以暂时写0待知道功用后需改进
}
{ {
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
@ -232,10 +217,17 @@ bool PipelineCreater::Set(const Prim topology,bool restart)
return(true); return(true);
} }
Pipeline *PipelineCreater::Create() Pipeline *PipelineCreater::Create(const RenderTarget *rt)
{ {
VkPipeline graphicsPipeline; VkPipeline graphicsPipeline;
InitViewportState(rt->GetExtent());
{
pipelineInfo.renderPass = rt->GetRenderPass();
pipelineInfo.subpass = 0; //subpass由于还不知道有什么用所以暂时写0待知道功用后需改进
}
if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS)
return(nullptr); return(nullptr);