moved CreatePipeline functions to RenderPass class.
This commit is contained in:
parent
fa47bc552c
commit
2753f95999
@ -1 +1 @@
|
||||
Subproject commit ea88b9fa13b816293530be9232f9ce5a529944ae
|
||||
Subproject commit cbc6cda17afa4985025f588e7801654d9a8d4d1b
|
@ -44,7 +44,7 @@ private:
|
||||
bool RecreatePipeline()
|
||||
{
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ protected:
|
||||
protected:
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
SwapchainRenderTarget * sc_render_target =nullptr;
|
||||
|
||||
protected:
|
||||
@ -118,6 +119,8 @@ public:
|
||||
if(!device)
|
||||
return(false);
|
||||
|
||||
device_render_pass=device->GetRenderPass();
|
||||
|
||||
db=new RenderResource(device);
|
||||
|
||||
InitCommandBuffer();
|
||||
@ -258,7 +261,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename ...ARGS>
|
||||
Pipeline *CreatePipeline(ARGS...args){return sc_render_target->CreatePipeline(args...);}
|
||||
Pipeline *CreatePipeline(ARGS...args){return device_render_pass->CreatePipeline(args...);}
|
||||
|
||||
public:
|
||||
|
||||
|
@ -240,11 +240,6 @@ public:
|
||||
|
||||
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRenderTarget( const FramebufferInfo *fbi,const uint32_t fence_count=1);
|
||||
|
||||
public:
|
||||
|
||||
Pipeline *CreatePipeline( PipelineData *, const Material *,const RenderTarget *);
|
||||
Pipeline *CreatePipeline(const InlinePipeline &,const Material *,const RenderTarget *);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -11,6 +11,7 @@ using RenderPassHASHCode=util::HashCodeSHA1LE;
|
||||
class DeviceRenderPassManage
|
||||
{
|
||||
VkDevice device;
|
||||
VkPipelineCache pipeline_cache;
|
||||
|
||||
util::Hash *hash;
|
||||
|
||||
@ -20,7 +21,7 @@ private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
DeviceRenderPassManage(VkDevice);
|
||||
DeviceRenderPassManage(VkDevice,VkPipelineCache);
|
||||
~DeviceRenderPassManage();
|
||||
|
||||
private:
|
||||
|
@ -17,7 +17,7 @@ class Pipeline
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
friend class RenderPass;
|
||||
|
||||
Pipeline(VkDevice dev,VkPipeline p,PipelineData *pd)
|
||||
{
|
||||
@ -35,8 +35,6 @@ public:
|
||||
|
||||
operator VkPipeline(){return pipeline;}
|
||||
|
||||
const PipelineData *GetData()const{return data;}
|
||||
|
||||
const bool IsAlphaTest()const{return data->alpha_test>0;}
|
||||
const bool IsAlphaBlend()const{return data->alpha_blend;}
|
||||
};//class GraphicsPipeline
|
||||
|
@ -2,6 +2,8 @@
|
||||
#define HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/type/List.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* RenderPass功能封装<br>
|
||||
@ -11,36 +13,35 @@ VK_NAMESPACE_BEGIN
|
||||
class RenderPass
|
||||
{
|
||||
VkDevice device;
|
||||
VkPipelineCache pipeline_cache;
|
||||
VkRenderPass render_pass;
|
||||
|
||||
List<VkFormat> color_formats;
|
||||
VkFormat depth_format;
|
||||
|
||||
protected:
|
||||
|
||||
ObjectList<Pipeline> pipeline_list;
|
||||
|
||||
private:
|
||||
|
||||
friend class DeviceRenderPassManage;
|
||||
|
||||
RenderPass(VkDevice d,VkRenderPass rp,const List<VkFormat> &cf,VkFormat df)
|
||||
RenderPass(VkDevice d,VkPipelineCache pc,VkRenderPass rp,const List<VkFormat> &cf,VkFormat df)
|
||||
{
|
||||
device=d;
|
||||
pipeline_cache=pc;
|
||||
render_pass=rp;
|
||||
color_formats=cf;
|
||||
depth_format=df;
|
||||
}
|
||||
|
||||
RenderPass(VkDevice d,VkRenderPass rp,VkFormat cf,VkFormat df)
|
||||
{
|
||||
device=d;
|
||||
render_pass=rp;
|
||||
color_formats.Add(cf);
|
||||
depth_format=df;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual ~RenderPass();
|
||||
|
||||
operator VkRenderPass(){return render_pass;}
|
||||
VkRenderPass GetVkRenderPass(){return render_pass;}
|
||||
VkPipelineCache GetPipelineCache(){return pipeline_cache;}
|
||||
|
||||
const uint GetColorCount()const{return color_formats.GetCount();}
|
||||
const List<VkFormat> & GetColorFormat()const{return color_formats;}
|
||||
@ -51,6 +52,20 @@ public:
|
||||
return color_formats.GetData()[index];
|
||||
}
|
||||
const VkFormat GetDepthFormat()const{return depth_format;}
|
||||
|
||||
public:
|
||||
|
||||
Pipeline *CreatePipeline(const Material *, PipelineData *);
|
||||
Pipeline *CreatePipeline(const Material *,const InlinePipeline &);
|
||||
|
||||
public:
|
||||
|
||||
Pipeline *CreatePipeline(Material *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *, PipelineData *, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, PipelineData *, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *, const OSString &, const Prim &prim,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim,const bool prim_restart=false);
|
||||
};//class RenderPass
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
|
@ -28,10 +28,6 @@ protected:
|
||||
Texture2D **color_textures;
|
||||
Texture2D *depth_texture;
|
||||
|
||||
protected:
|
||||
|
||||
ObjectList<Pipeline> pipeline_list;
|
||||
|
||||
protected:
|
||||
|
||||
friend class GPUDevice;
|
||||
@ -45,22 +41,13 @@ public:
|
||||
|
||||
const VkExtent2D & GetExtent ()const {return extent;}
|
||||
virtual RenderPass * GetRenderPass () {return render_pass;}
|
||||
virtual const VkRenderPass GetVkRenderPass ()const {return *render_pass;}
|
||||
virtual const VkRenderPass GetVkRenderPass ()const {return render_pass->GetVkRenderPass();}
|
||||
virtual const uint32_t GetColorCount ()const {return fbo->GetColorCount();}
|
||||
virtual Framebuffer * GetFramebuffer () {return fbo;}
|
||||
|
||||
virtual Texture2D * GetColorTexture (const int index=0){return color_textures[index];}
|
||||
virtual Texture2D * GetDepthTexture (){return depth_texture;}
|
||||
|
||||
public: //pipeline
|
||||
|
||||
Pipeline *CreatePipeline(Material *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(Material *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||
Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
||||
|
||||
public: // command buffer
|
||||
|
||||
GPUSemaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
||||
|
@ -119,7 +119,6 @@ SET(VK_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
|
||||
Vulkan/VKDeviceImage.cpp
|
||||
Vulkan/VKDeviceTexture.cpp
|
||||
Vulkan/VKDeviceMaterial.cpp
|
||||
Vulkan/VKDevicePipeline.cpp
|
||||
Vulkan/VKDeviceFramebuffer.cpp
|
||||
Vulkan/VKDeviceSwapchain.cpp
|
||||
Vulkan/VKDeviceRenderPass.cpp
|
||||
@ -183,7 +182,6 @@ SET(VK_RENDER_PASS_SOURCE ${SG_INCLUDE_PATH}/VKFramebuffer.h
|
||||
Vulkan/VKPipelineCache.cpp
|
||||
Vulkan/VKRenderPass.cpp
|
||||
Vulkan/VKRenderTarget.cpp
|
||||
Vulkan/VKRenderTargetPipeline.cpp
|
||||
Vulkan/VKSwapchainRenderTarget.cpp
|
||||
Vulkan/VKSwapchain.cpp
|
||||
)
|
||||
|
@ -72,7 +72,7 @@ bool RenderCmdBuffer::BindFramebuffer(RenderPass *rp,Framebuffer *fb)
|
||||
render_area.offset.y=0;
|
||||
render_area.extent=fb->GetExtent();
|
||||
|
||||
rp_begin.renderPass = *rp;
|
||||
rp_begin.renderPass = rp->GetVkRenderPass();
|
||||
rp_begin.framebuffer = *fb;
|
||||
rp_begin.renderArea = render_area;
|
||||
rp_begin.clearValueCount = cv_count;
|
||||
|
@ -5,7 +5,7 @@ VkFramebuffer CreateVulkanFramebuffer(VkDevice device,RenderPass *rp,const VkExt
|
||||
{
|
||||
FramebufferCreateInfo fb_info;
|
||||
|
||||
fb_info.renderPass = *rp;
|
||||
fb_info.renderPass = rp->GetVkRenderPass();
|
||||
fb_info.attachmentCount = attachmentCount;
|
||||
fb_info.pAttachments = attachments;
|
||||
fb_info.width = extent.width;
|
||||
@ -75,7 +75,7 @@ Framebuffer *GPUDevice::CreateFramebuffer(RenderPass *rp,ImageView **color_list,
|
||||
if(!fbo)
|
||||
return(nullptr);
|
||||
|
||||
return(new Framebuffer(GetDevice(),fbo,extent,*rp,color_count,depth));
|
||||
return(new Framebuffer(GetDevice(),fbo,extent,rp->GetVkRenderPass(),color_count,depth));
|
||||
}
|
||||
//
|
||||
//Framebuffer *GPUDevice::CreateFramebuffer(RenderPass *rp,List<ImageView *> &color,ImageView *depth)
|
||||
|
@ -1,48 +0,0 @@
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKFramebuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Pipeline *GPUDevice::CreatePipeline(PipelineData *data,const Material *material,const RenderTarget *rt)
|
||||
{
|
||||
VkPipeline graphicsPipeline;
|
||||
|
||||
data->InitVertexInputState( material->GetStageCount(),
|
||||
material->GetStages(),
|
||||
material->GetVertexAttrCount(),
|
||||
material->GetVertexBindingList(),
|
||||
material->GetVertexAttributeList());
|
||||
|
||||
data->InitViewportState(rt->GetExtent());
|
||||
|
||||
data->SetColorAttachments(rt->GetColorCount());
|
||||
|
||||
data->pipeline_info.layout = material->GetPipelineLayout();
|
||||
|
||||
{
|
||||
data->pipeline_info.renderPass = rt->GetVkRenderPass();
|
||||
data->pipeline_info.subpass = 0; //subpass由于还不知道有什么用,所以暂时写0,待知道功用后,需改进
|
||||
}
|
||||
|
||||
if (vkCreateGraphicsPipelines( attr->device,
|
||||
attr->pipeline_cache,
|
||||
1,&data->pipeline_info,
|
||||
nullptr,
|
||||
&graphicsPipeline) != VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new Pipeline(attr->device,graphicsPipeline,data));
|
||||
}
|
||||
|
||||
Pipeline *GPUDevice::CreatePipeline(const InlinePipeline &ip,const Material *mtl,const RenderTarget *rt)
|
||||
{
|
||||
PipelineData *pd=GetPipelineData(ip);
|
||||
|
||||
if(!pd)return(nullptr);
|
||||
|
||||
return this->CreatePipeline(pd,mtl,rt);
|
||||
}
|
||||
VK_NAMESPACE_END
|
@ -6,7 +6,7 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
void GPUDevice::InitRenderPassManage()
|
||||
{
|
||||
render_pass_manage=new DeviceRenderPassManage(attr->device);
|
||||
render_pass_manage=new DeviceRenderPassManage(attr->device,attr->pipeline_cache);
|
||||
|
||||
SwapchainRenderbufferInfo rbi(attr->format,attr->physical_device->GetDepthFormat());
|
||||
|
||||
|
@ -210,9 +210,10 @@ bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachm
|
||||
return(true);
|
||||
}
|
||||
|
||||
DeviceRenderPassManage::DeviceRenderPassManage(VkDevice dev)
|
||||
DeviceRenderPassManage::DeviceRenderPassManage(VkDevice dev,VkPipelineCache pc)
|
||||
{
|
||||
device=dev;
|
||||
pipeline_cache=pc;
|
||||
|
||||
hash=util::CreateSHA1LEHash();
|
||||
}
|
||||
@ -298,7 +299,7 @@ RenderPass *DeviceRenderPassManage::CreateRenderPass( const List<VkAttachmentD
|
||||
if(vkCreateRenderPass(device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new RenderPass(device,render_pass,rbi->GetColorFormatList(),depth_format));
|
||||
return(new RenderPass(device,pipeline_cache,render_pass,rbi->GetColorFormatList(),depth_format));
|
||||
}
|
||||
|
||||
RenderPass *DeviceRenderPassManage::AcquireRenderPass(const RenderbufferInfo *rbi)
|
||||
|
@ -1,8 +1,106 @@
|
||||
#include<hgl/graph/VKRenderPass.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKPipelineData.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderPass::~RenderPass()
|
||||
{
|
||||
pipeline_list.Clear();
|
||||
|
||||
vkDestroyRenderPass(device,render_pass,nullptr);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(const Material *material,PipelineData *data)
|
||||
{
|
||||
VkPipeline graphicsPipeline;
|
||||
|
||||
data->InitVertexInputState( material->GetStageCount(),
|
||||
material->GetStages(),
|
||||
material->GetVertexAttrCount(),
|
||||
material->GetVertexBindingList(),
|
||||
material->GetVertexAttributeList());
|
||||
|
||||
data->SetColorAttachments(color_formats.GetCount());
|
||||
|
||||
data->pipeline_info.layout = material->GetPipelineLayout();
|
||||
|
||||
{
|
||||
data->pipeline_info.renderPass = render_pass;
|
||||
data->pipeline_info.subpass = 0; //subpass由于还不知道有什么用,所以暂时写0,待知道功用后,需改进
|
||||
}
|
||||
|
||||
if (vkCreateGraphicsPipelines( device,
|
||||
pipeline_cache,
|
||||
1,&data->pipeline_info,
|
||||
nullptr,
|
||||
&graphicsPipeline) != VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new Pipeline(device,graphicsPipeline,data));
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(const Material *mtl,const InlinePipeline &ip)
|
||||
{
|
||||
PipelineData *pd=GetPipelineData(ip);
|
||||
|
||||
if(!pd)return(nullptr);
|
||||
|
||||
return CreatePipeline(mtl,pd);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
if(!mtl)return(nullptr);
|
||||
|
||||
PipelineData *pd=GetPipelineData(ip);
|
||||
|
||||
pd->Set(prim,prim_restart);
|
||||
|
||||
Pipeline *p=CreatePipeline(mtl,pd);
|
||||
|
||||
if(p)
|
||||
pipeline_list.Add(p);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
if(!mi)return(nullptr);
|
||||
|
||||
return CreatePipeline(mi->GetMaterial(),ip,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
pd->Set(prim,prim_restart);
|
||||
|
||||
Pipeline *p=CreatePipeline(mtl,pd);
|
||||
|
||||
if(p)
|
||||
pipeline_list.Add(p);
|
||||
|
||||
return(p);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
return CreatePipeline(mi->GetMaterial(),pd,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(Material *mtl,const OSString &pipeline_filename,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
PipelineData *pd=GetPipelineData(pipeline_filename);
|
||||
|
||||
if(!pd)return(nullptr);
|
||||
|
||||
return CreatePipeline(mtl,pd,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderPass::CreatePipeline(MaterialInstance *mi,const OSString &filename,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
return CreatePipeline(mi->GetMaterial(),filename,prim,prim_restart);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -53,7 +53,6 @@ RenderTarget::RenderTarget(GPUDevice *dev,RenderPass *_rp,Framebuffer *_fb,Textu
|
||||
|
||||
RenderTarget::~RenderTarget()
|
||||
{
|
||||
pipeline_list.Clear();
|
||||
SAFE_CLEAR(depth_texture);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(color_textures,color_count);
|
||||
|
||||
|
@ -1,61 +0,0 @@
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKPipelineData.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Pipeline *RenderTarget::CreatePipeline(Material *mtl,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
if(!mtl)return(nullptr);
|
||||
|
||||
PipelineData *pd=GetPipelineData(ip);
|
||||
|
||||
pd->Set(prim,prim_restart);
|
||||
|
||||
Pipeline *p=device->CreatePipeline(pd,mtl,this);
|
||||
|
||||
if(p)
|
||||
pipeline_list.Add(p);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Pipeline *RenderTarget::CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
if(!mi)return(nullptr);
|
||||
|
||||
return CreatePipeline(mi->GetMaterial(),ip,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderTarget::CreatePipeline(Material *mtl,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
pd->Set(prim,prim_restart);
|
||||
|
||||
Pipeline *p=device->CreatePipeline(pd,mtl,this);
|
||||
|
||||
if(p)
|
||||
pipeline_list.Add(p);
|
||||
|
||||
return(p);
|
||||
}
|
||||
|
||||
Pipeline *RenderTarget::CreatePipeline(MaterialInstance *mi,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
return CreatePipeline(mi->GetMaterial(),pd,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderTarget::CreatePipeline(Material *mtl,const OSString &pipeline_filename,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
PipelineData *pd=GetPipelineData(pipeline_filename);
|
||||
|
||||
if(!pd)return(nullptr);
|
||||
|
||||
return CreatePipeline(mtl,pd,prim,prim_restart);
|
||||
}
|
||||
|
||||
Pipeline *RenderTarget::CreatePipeline(MaterialInstance *mi,const OSString &filename,const Prim &prim,const bool prim_restart)
|
||||
{
|
||||
return CreatePipeline(mi->GetMaterial(),filename,prim,prim_restart);
|
||||
}
|
||||
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user