删除PipelineLayout类,数据并入Pipeline类
This commit is contained in:
parent
20f2aa7277
commit
9d8da06a3e
@ -19,7 +19,6 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
|
||||
VKDeviceBuffer.cpp
|
||||
VKBuffer.cpp
|
||||
VKDescriptorSets.cpp
|
||||
VKPipelineLayout.cpp
|
||||
VKRenderPass.cpp
|
||||
VKShaderModule.cpp
|
||||
VKShaderModuleManage.cpp
|
||||
@ -45,7 +44,6 @@ SET(VULKAN_TEST_HEADER_FILES AssetsManage.h
|
||||
VKDevice.h
|
||||
VKBuffer.h
|
||||
VKDescriptorSets.h
|
||||
VKPipelineLayout.h
|
||||
VKRenderPass.h
|
||||
VKShaderModule.h
|
||||
VKShaderModuleManage.h
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include"VKRenderPass.h"
|
||||
#include"VKFramebuffer.h"
|
||||
#include"VKPipeline.h"
|
||||
#include"VKPipelineLayout.h"
|
||||
#include"VKBuffer.h"
|
||||
#include"VKRenderable.h"
|
||||
#include"VKDescriptorSets.h"
|
||||
@ -72,15 +71,10 @@ bool CommandBuffer::Bind(Pipeline *p)
|
||||
{
|
||||
if(!p)return(false);
|
||||
|
||||
vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, *p);
|
||||
return(true);
|
||||
}
|
||||
if(p->GetDescriptorSetCount()>0)
|
||||
vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, p->GetLayout(), 0, p->GetDescriptorSetCount(),p->GetDescriptorSets(), 0, nullptr);
|
||||
|
||||
bool CommandBuffer::Bind(PipelineLayout *pl)
|
||||
{
|
||||
if(!pl)return(false);
|
||||
if(pl->GetDescriptorSetCount()>0)
|
||||
vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pl, 0, pl->GetDescriptorSetCount(),pl->GetDescriptorSets(), 0, nullptr);
|
||||
vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS,*p);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
@ -96,19 +96,40 @@ MaterialInstance *Material::CreateInstance()const
|
||||
|
||||
DescriptorSetLayout *dsl=dsl_creater->Create();
|
||||
|
||||
return(new MaterialInstance(this,vertex_sm,vab,dsl));
|
||||
const uint32_t layout_count=dsl->GetCount();
|
||||
const VkDescriptorSetLayout *layouts=(layout_count>0?dsl->GetLayouts():nullptr);
|
||||
|
||||
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = {};
|
||||
pPipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||
pPipelineLayoutCreateInfo.pNext = nullptr;
|
||||
pPipelineLayoutCreateInfo.pushConstantRangeCount = 0;
|
||||
pPipelineLayoutCreateInfo.pPushConstantRanges = nullptr;
|
||||
pPipelineLayoutCreateInfo.setLayoutCount = layout_count;
|
||||
pPipelineLayoutCreateInfo.pSetLayouts = layouts;
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
if(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, nullptr, &pipeline_layout)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new MaterialInstance(device,this,vertex_sm,vab,dsl,pipeline_layout));
|
||||
}
|
||||
|
||||
MaterialInstance::MaterialInstance(const Material *m,const VertexShaderModule *vsm,VertexAttributeBinding *v,DescriptorSetLayout *d)
|
||||
MaterialInstance::MaterialInstance(VkDevice dev,const Material *m,const VertexShaderModule *vsm,VertexAttributeBinding *v,DescriptorSetLayout *d,VkPipelineLayout pl)
|
||||
{
|
||||
device=dev;
|
||||
mat=m;
|
||||
vertex_sm=vsm;
|
||||
vab=v;
|
||||
desc_set_layout=d;
|
||||
pipeline_layout=pl;
|
||||
}
|
||||
|
||||
MaterialInstance::~MaterialInstance()
|
||||
{
|
||||
if(pipeline_layout)
|
||||
vkDestroyPipelineLayout(device,pipeline_layout,nullptr);
|
||||
|
||||
delete desc_set_layout;
|
||||
delete vab;
|
||||
}
|
||||
@ -123,6 +144,11 @@ void MaterialInstance::Write(VkPipelineVertexInputStateCreateInfo &vis)const
|
||||
return vab->Write(vis);
|
||||
}
|
||||
|
||||
const List<VkDescriptorSet> *MaterialInstance::GetDescriptorSets()const
|
||||
{
|
||||
return &(desc_set_layout->GetSets());
|
||||
}
|
||||
|
||||
Renderable *MaterialInstance::CreateRenderable()
|
||||
{
|
||||
return(new Renderable(vertex_sm));
|
||||
|
@ -14,6 +14,7 @@ class MaterialInstance;
|
||||
class VertexAttributeBinding;
|
||||
class VertexBuffer;
|
||||
class Renderable;
|
||||
class PipelineLayout;
|
||||
|
||||
using ShaderModuleMap=hgl::Map<VkShaderStageFlagBits,const ShaderModule *>;
|
||||
|
||||
@ -50,14 +51,17 @@ public:
|
||||
*/
|
||||
class MaterialInstance
|
||||
{
|
||||
VkDevice device;
|
||||
const Material *mat; ///<这里的是对material的完全引用,不做任何修改
|
||||
const VertexShaderModule *vertex_sm;
|
||||
VertexAttributeBinding *vab;
|
||||
DescriptorSetLayout *desc_set_layout;
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
public:
|
||||
|
||||
MaterialInstance(const Material *m,const VertexShaderModule *,VertexAttributeBinding *v,DescriptorSetLayout *d);
|
||||
MaterialInstance(VkDevice dev,const Material *m,const VertexShaderModule *,VertexAttributeBinding *v,DescriptorSetLayout *d,VkPipelineLayout pl);
|
||||
~MaterialInstance();
|
||||
|
||||
bool UpdateUBO(const uint32_t binding,const VkDescriptorBufferInfo *buf_info);
|
||||
@ -68,15 +72,14 @@ public:
|
||||
|
||||
return UpdateUBO(mat->GetUBOBinding(name),buf_info);
|
||||
}
|
||||
|
||||
const VertexShaderModule * GetVertexShader ()const{return vertex_sm;}
|
||||
|
||||
|
||||
const uint32_t GetStageCount ()const{return mat->GetStageCount();}
|
||||
const VkPipelineShaderStageCreateInfo * GetStages ()const{return mat->GetStages();}
|
||||
|
||||
void Write(VkPipelineVertexInputStateCreateInfo &vis)const;
|
||||
|
||||
DescriptorSetLayout * GetDSL(){return desc_set_layout;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
|
||||
const List<VkDescriptorSet> * GetDescriptorSets ()const;
|
||||
|
||||
Renderable *CreateRenderable();
|
||||
};//class MaterialInstance
|
||||
|
@ -9,14 +9,21 @@ Pipeline::~Pipeline()
|
||||
vkDestroyPipeline(device,pipeline,nullptr);
|
||||
}
|
||||
|
||||
PipelineCreater::PipelineCreater(Device *dev,RenderPass *rp)
|
||||
PipelineCreater::PipelineCreater(Device *dev,const MaterialInstance *mi,RenderPass *rp)
|
||||
{
|
||||
device=dev->GetDevice();
|
||||
extent=dev->GetExtent();
|
||||
cache=dev->GetPipelineCache();
|
||||
|
||||
material=mi;
|
||||
|
||||
//未来这里需要增加是否有vs/fs的检测
|
||||
|
||||
hgl_zero(pipelineInfo);
|
||||
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
pipelineInfo.layout = material->GetPipelineLayout();
|
||||
pipelineInfo.stageCount=material->GetStageCount();
|
||||
pipelineInfo.pStages=material->GetStages();
|
||||
|
||||
{
|
||||
if(!rp)
|
||||
@ -31,11 +38,7 @@ PipelineCreater::PipelineCreater(Device *dev,RenderPass *rp)
|
||||
vis_create_info.pNext = nullptr;
|
||||
vis_create_info.flags = 0;
|
||||
|
||||
vis_create_info.vertexBindingDescriptionCount = 0;
|
||||
vis_create_info.pVertexBindingDescriptions = nullptr;
|
||||
|
||||
vis_create_info.vertexAttributeDescriptionCount = 0;
|
||||
vis_create_info.pVertexAttributeDescriptions = nullptr;
|
||||
material->Write(vis_create_info);
|
||||
|
||||
pipelineInfo.pVertexInputState=&vis_create_info;
|
||||
}
|
||||
@ -147,20 +150,6 @@ PipelineCreater::PipelineCreater(Device *dev,RenderPass *rp)
|
||||
pipelineInfo.basePipelineIndex = 0;
|
||||
}
|
||||
|
||||
bool PipelineCreater::Set(const MaterialInstance *mi)
|
||||
{
|
||||
if(!mi)return(false);
|
||||
|
||||
//未来这里需要增加是否有vs/fs的检测
|
||||
|
||||
pipelineInfo.stageCount=mi->GetStageCount();
|
||||
pipelineInfo.pStages=mi->GetStages();
|
||||
|
||||
mi->Write(vis_create_info);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool PipelineCreater::Set(const VkPrimitiveTopology topology,bool restart)
|
||||
{
|
||||
if(topology<VK_PRIMITIVE_TOPOLOGY_BEGIN_RANGE||topology>VK_PRIMITIVE_TOPOLOGY_END_RANGE)
|
||||
@ -176,14 +165,6 @@ bool PipelineCreater::Set(const VkPrimitiveTopology topology,bool restart)
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool PipelineCreater::Set(VkPipelineLayout pl)
|
||||
{
|
||||
if(!pl)return(false);
|
||||
|
||||
pipelineInfo.layout = pl;
|
||||
return(true);
|
||||
}
|
||||
|
||||
Pipeline *PipelineCreater::Create()
|
||||
{
|
||||
VkPipeline graphicsPipeline;
|
||||
@ -191,6 +172,8 @@ Pipeline *PipelineCreater::Create()
|
||||
if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new Pipeline(device,graphicsPipeline));
|
||||
return(new Pipeline(device,graphicsPipeline,
|
||||
material->GetPipelineLayout(),
|
||||
material->GetDescriptorSets()));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -13,13 +13,21 @@ class Pipeline
|
||||
{
|
||||
VkDevice device;
|
||||
VkPipeline pipeline;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
const List<VkDescriptorSet> *desc_sets;
|
||||
|
||||
public:
|
||||
|
||||
Pipeline(VkDevice dev,VkPipeline p){device=dev;pipeline=p;}
|
||||
Pipeline(VkDevice dev,VkPipeline p,VkPipelineLayout pl,const List<VkDescriptorSet> *ds){device=dev;pipeline=p;pipeline_layout=pl;desc_sets=ds;}
|
||||
virtual ~Pipeline();
|
||||
|
||||
operator VkPipeline(){return pipeline;}
|
||||
|
||||
VkPipelineLayout GetLayout(){return pipeline_layout;}
|
||||
|
||||
const uint32_t GetDescriptorSetCount()const{return desc_sets->GetCount();}
|
||||
const VkDescriptorSet * GetDescriptorSets()const{return desc_sets->GetData();}
|
||||
};//class GraphicsPipeline
|
||||
|
||||
class Shader;
|
||||
@ -52,17 +60,14 @@ class PipelineCreater
|
||||
|
||||
private:
|
||||
|
||||
const Shader * shader =nullptr;
|
||||
const VertexInput * vertex_input=nullptr;
|
||||
const MaterialInstance *material=nullptr;
|
||||
|
||||
public:
|
||||
|
||||
PipelineCreater(Device *dev,RenderPass *rp=nullptr);
|
||||
PipelineCreater(Device *dev,const MaterialInstance *,RenderPass *rp=nullptr);
|
||||
~PipelineCreater()=default;
|
||||
|
||||
bool Set(const MaterialInstance *);
|
||||
bool Set(const VkPrimitiveTopology,bool=false);
|
||||
bool Set(VkPipelineLayout pl);
|
||||
|
||||
void SetViewport( float x,float y,float w,float h){viewport.x=x;viewport.y=y;viewport.width=w;viewport.height=h;}
|
||||
void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;}
|
||||
|
@ -1,31 +0,0 @@
|
||||
#include"VKPipelineLayout.h"
|
||||
#include"VKDescriptorSets.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
PipelineLayout::~PipelineLayout()
|
||||
{
|
||||
if(layout)
|
||||
vkDestroyPipelineLayout(device,layout,nullptr);
|
||||
}
|
||||
|
||||
PipelineLayout *CreatePipelineLayout(VkDevice dev,const DescriptorSetLayout *dsl)
|
||||
{
|
||||
const uint32_t layout_count=(dsl?dsl->GetCount():0);
|
||||
const VkDescriptorSetLayout *layouts=(layout_count>0?dsl->GetLayouts():nullptr);
|
||||
|
||||
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = {};
|
||||
pPipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||
pPipelineLayoutCreateInfo.pNext = nullptr;
|
||||
pPipelineLayoutCreateInfo.pushConstantRangeCount = 0;
|
||||
pPipelineLayoutCreateInfo.pPushConstantRanges = nullptr;
|
||||
pPipelineLayoutCreateInfo.setLayoutCount = layout_count;
|
||||
pPipelineLayoutCreateInfo.pSetLayouts = layouts;
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
if(vkCreatePipelineLayout(dev, &pPipelineLayoutCreateInfo, nullptr, &pipeline_layout)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new PipelineLayout(dev,pipeline_layout,dsl->GetSets()));
|
||||
}
|
||||
VK_NAMESPACE_END
|
@ -1,32 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include"VKDescriptorSets.h"
|
||||
VK_NAMESPACE_BEGIN
|
||||
class PipelineLayout
|
||||
{
|
||||
VkDevice device;
|
||||
VkPipelineLayout layout;
|
||||
|
||||
List<VkDescriptorSet> desc_sets;
|
||||
|
||||
private:
|
||||
|
||||
friend PipelineLayout *CreatePipelineLayout(VkDevice dev,const DescriptorSetLayout *dsl);
|
||||
|
||||
PipelineLayout(VkDevice dev,VkPipelineLayout pl,const List<VkDescriptorSet> &ds){device=dev;layout=pl;desc_sets=ds;}
|
||||
|
||||
public:
|
||||
|
||||
~PipelineLayout();
|
||||
|
||||
operator VkPipelineLayout (){return layout;}
|
||||
|
||||
const uint32_t GetDescriptorSetCount ()const{return desc_sets.GetCount();}
|
||||
const VkDescriptorSet * GetDescriptorSets ()const{return desc_sets.GetData();}
|
||||
};//class PipelineLayout
|
||||
|
||||
PipelineLayout *CreatePipelineLayout(VkDevice dev,const DescriptorSetLayout *dsl);
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
|
@ -70,8 +70,6 @@ bool VertexAttributeBinding::SetOffset(const uint index,const uint32_t offset)
|
||||
|
||||
void VertexAttributeBinding::Write(VkPipelineVertexInputStateCreateInfo &vis_create_info) const
|
||||
{
|
||||
vis_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
|
||||
const uint32_t count=vsm->GetAttrCount();
|
||||
|
||||
vis_create_info.vertexBindingDescriptionCount = count;
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include"VKRenderable.h"
|
||||
#include"VKDescriptorSets.h"
|
||||
#include"VKRenderPass.h"
|
||||
#include"VKPipelineLayout.h"
|
||||
#include"VKPipeline.h"
|
||||
#include"VKCommandBuffer.h"
|
||||
#include"VKFormat.h"
|
||||
@ -131,24 +130,16 @@ int main(int,char **)
|
||||
|
||||
vulkan::MaterialInstance *mi=material->CreateInstance();
|
||||
vulkan::Renderable *render_obj=mi->CreateRenderable();
|
||||
|
||||
vulkan::Buffer *ubo=CreateUBO(device);
|
||||
|
||||
vulkan::PipelineCreater pc(device);
|
||||
|
||||
mi->UpdateUBO("world",*ubo);
|
||||
|
||||
CreateVertexBuffer(device,render_obj);
|
||||
|
||||
vulkan::PipelineLayout *pl=CreatePipelineLayout(*device,mi->GetDSL());
|
||||
vulkan::Buffer *ubo=CreateUBO(device);
|
||||
mi->UpdateUBO("world",*ubo);
|
||||
|
||||
vulkan::PipelineCreater pc(device,mi);
|
||||
pc.SetDepthTest(false);
|
||||
pc.SetDepthWrite(false);
|
||||
pc.CloseCullFace();
|
||||
|
||||
pc.Set(mi);
|
||||
pc.Set(PRIM_TRIANGLES);
|
||||
pc.Set(*pl);
|
||||
|
||||
vulkan::Pipeline *pipeline=pc.Create();
|
||||
|
||||
@ -161,7 +152,6 @@ int main(int,char **)
|
||||
|
||||
cmd_buf->Begin(device->GetRenderPass(),device->GetFramebuffer(0));
|
||||
cmd_buf->Bind(pipeline);
|
||||
cmd_buf->Bind(pl);
|
||||
cmd_buf->Bind(render_obj);
|
||||
cmd_buf->Draw(VERTEX_COUNT);
|
||||
cmd_buf->End();
|
||||
@ -177,7 +167,6 @@ int main(int,char **)
|
||||
|
||||
delete pipeline;
|
||||
|
||||
delete pl;
|
||||
delete ubo;
|
||||
delete mi;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user