add CreatePipeline functions at RenderTarget,remove other they at other places.
This commit is contained in:
parent
341acc92e1
commit
d0fd9af309
@ -33,8 +33,8 @@ enum class GBufferAttachment
|
|||||||
ENUM_CLASS_RANGE(Color,Normal)
|
ENUM_CLASS_RANGE(Color,Normal)
|
||||||
};//
|
};//
|
||||||
|
|
||||||
constexpr VkFormat gbuffer_color_format[size_t(GBufferAttachment::RANGE_SIZE)]={UFMT_RGB565,UFMT_RG8};
|
constexpr VkFormat gbuffer_color_format[size_t(GBufferAttachment::RANGE_SIZE)]={UFMT_RGB565,FMT_RG8UN};
|
||||||
constexpr VkFormat gbuffer_depth_format=FMT_D32F;
|
constexpr VkFormat gbuffer_depth_format=FMT_D16UN;
|
||||||
|
|
||||||
struct alignas(16) PhongPointLight
|
struct alignas(16) PhongPointLight
|
||||||
{
|
{
|
||||||
@ -105,7 +105,7 @@ private:
|
|||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||||
|
|
||||||
return(true);
|
return(gbuffer_rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitSubpass(SubpassParam *sp,const OSString &material_filename)
|
bool InitSubpass(SubpassParam *sp,const OSString &material_filename)
|
||||||
@ -121,18 +121,18 @@ private:
|
|||||||
|
|
||||||
bool InitGBufferPipeline(SubpassParam *sp)
|
bool InitGBufferPipeline(SubpassParam *sp)
|
||||||
{
|
{
|
||||||
sp->pipeline_triangles =db->CreatePipeline(sp->material,gbuffer_rt,InlinePipeline::Solid3D,Prim::Triangles);
|
sp->pipeline_triangles =gbuffer_rt->CreatePipeline(sp->material,InlinePipeline::Solid3D,Prim::Triangles);
|
||||||
if(!sp->pipeline_triangles)
|
if(!sp->pipeline_triangles)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
sp->pipeline_fan =db->CreatePipeline(sp->material,gbuffer_rt,InlinePipeline::Solid3D,Prim::Fan);
|
sp->pipeline_fan =gbuffer_rt->CreatePipeline(sp->material,InlinePipeline::Solid3D,Prim::Fan);
|
||||||
|
|
||||||
return sp->pipeline_fan;
|
return sp->pipeline_fan;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitCompositionPipeline(SubpassParam *sp)
|
bool InitCompositionPipeline(SubpassParam *sp)
|
||||||
{
|
{
|
||||||
sp->pipeline_fan=db->CreatePipeline(sp->material,sc_render_target,InlinePipeline::Solid2D,Prim::Fan);
|
sp->pipeline_fan=sc_render_target->CreatePipeline(sp->material,InlinePipeline::Solid2D,Prim::Fan);
|
||||||
|
|
||||||
return sp->pipeline_fan;
|
return sp->pipeline_fan;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
os.material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
os.material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||||
if(!os.material_instance)return(false);
|
if(!os.material_instance)return(false);
|
||||||
|
|
||||||
os.pipeline=db->CreatePipeline(os.material_instance,os.render_taget,InlinePipeline::Solid2D,Prim::Fan);
|
os.pipeline=os.render_taget->CreatePipeline(os.material_instance,InlinePipeline::Solid2D,Prim::Fan);
|
||||||
if(!os.pipeline)return(false);
|
if(!os.pipeline)return(false);
|
||||||
|
|
||||||
if(!InitUBO(&os,os.render_taget->GetExtent()))
|
if(!InitUBO(&os,os.render_taget->GetExtent()))
|
||||||
|
@ -256,6 +256,9 @@ public:
|
|||||||
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),rl);
|
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ...ARGS>
|
||||||
|
Pipeline *CreatePipeline(ARGS...args){return sc_render_target->CreatePipeline(args...);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int AcquireNextImage()
|
int AcquireNextImage()
|
||||||
@ -291,38 +294,6 @@ public:
|
|||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public: //pipeline
|
|
||||||
|
|
||||||
Pipeline *CreatePipeline(Material *mtl,const InlinePipeline &ip,const Prim &prim=Prim::Triangles,const bool prim_restart=false)
|
|
||||||
{
|
|
||||||
return db->CreatePipeline(mtl,sc_render_target,ip,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *CreatePipeline(MaterialInstance *mi,const InlinePipeline &ip,const Prim &prim=Prim::Triangles,const bool prim_restart=false)
|
|
||||||
{
|
|
||||||
return db->CreatePipeline(mi,sc_render_target,ip,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *CreatePipeline(Material *mtl,PipelineData *pd,const Prim &prim=Prim::Triangles,const bool prim_restart=false)
|
|
||||||
{
|
|
||||||
return db->CreatePipeline(mtl,sc_render_target,pd,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *CreatePipeline(MaterialInstance *mi,PipelineData *pd,const Prim &prim=Prim::Triangles,const bool prim_restart=false)
|
|
||||||
{
|
|
||||||
return db->CreatePipeline(mi,sc_render_target,pd,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *CreatePipeline(Material *mtl,const OSString &pipeline_name,const Prim &prim=Prim::Triangles,const bool prim_restart=false)
|
|
||||||
{
|
|
||||||
return db->CreatePipeline(mtl,sc_render_target,pipeline_name,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *CreatePipeline(MaterialInstance *mi,const OSString &pipeline_name,const Prim &prim=Prim::Triangles,const bool prim_restart=false)
|
|
||||||
{
|
|
||||||
return db->CreatePipeline(mi,sc_render_target,pipeline_name,prim,prim_restart);
|
|
||||||
}
|
|
||||||
};//class VulkanApplicationFramework
|
};//class VulkanApplicationFramework
|
||||||
|
|
||||||
class CameraAppFramework:public VulkanApplicationFramework
|
class CameraAppFramework:public VulkanApplicationFramework
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
using MaterialID =int;
|
using MaterialID =int;
|
||||||
using MaterialInstanceID =int;
|
using MaterialInstanceID =int;
|
||||||
using PipelineID =int;
|
|
||||||
using BufferID =int;
|
using BufferID =int;
|
||||||
using DescriptorSetsID =int;
|
using DescriptorSetsID =int;
|
||||||
using RenderableID =int;
|
using RenderableID =int;
|
||||||
@ -39,7 +38,6 @@ class RenderResource
|
|||||||
|
|
||||||
IDResManage<MaterialID, Material> rm_material; ///<材质合集
|
IDResManage<MaterialID, Material> rm_material; ///<材质合集
|
||||||
IDResManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
IDResManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
||||||
IDResManage<PipelineID, Pipeline> rm_pipeline; ///<管线合集
|
|
||||||
IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
|
IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
|
||||||
IDResManage<RenderableID, Renderable> rm_renderables; ///<可渲染对象合集
|
IDResManage<RenderableID, Renderable> rm_renderables; ///<可渲染对象合集
|
||||||
IDResManage<BufferID, GPUBuffer> rm_buffers; ///<顶点缓冲区合集
|
IDResManage<BufferID, GPUBuffer> rm_buffers; ///<顶点缓冲区合集
|
||||||
@ -56,7 +54,6 @@ public: //Add
|
|||||||
|
|
||||||
MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
|
MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
|
||||||
MaterialInstanceID Add(MaterialInstance * mi ){return rm_material_instance.Add(mi);}
|
MaterialInstanceID Add(MaterialInstance * mi ){return rm_material_instance.Add(mi);}
|
||||||
PipelineID Add(Pipeline * p ){return rm_pipeline.Add(p);}
|
|
||||||
DescriptorSetsID Add(DescriptorSets * ds ){return rm_desc_sets.Add(ds);}
|
DescriptorSetsID Add(DescriptorSets * ds ){return rm_desc_sets.Add(ds);}
|
||||||
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
||||||
BufferID Add(GPUBuffer * buf ){return rm_buffers.Add(buf);}
|
BufferID Add(GPUBuffer * buf ){return rm_buffers.Add(buf);}
|
||||||
@ -99,13 +96,6 @@ public: //Material
|
|||||||
MaterialInstance * CreateMaterialInstance(Material *);
|
MaterialInstance * CreateMaterialInstance(Material *);
|
||||||
MaterialInstance * CreateMaterialInstance(const OSString &);
|
MaterialInstance * CreateMaterialInstance(const OSString &);
|
||||||
|
|
||||||
Pipeline * CreatePipeline(Material *, RenderTarget *,const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
|
||||||
Pipeline * CreatePipeline(MaterialInstance *, RenderTarget *,const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
|
||||||
Pipeline * CreatePipeline(Material *, RenderTarget *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
|
||||||
Pipeline * CreatePipeline(MaterialInstance *, RenderTarget *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
|
||||||
Pipeline * CreatePipeline(Material *, RenderTarget *,const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
|
||||||
Pipeline * CreatePipeline(MaterialInstance *, RenderTarget *,const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
|
||||||
|
|
||||||
Renderable * CreateRenderable(const uint32_t vertex_count=0);
|
Renderable * CreateRenderable(const uint32_t vertex_count=0);
|
||||||
TextRenderable * CreateTextRenderable(Material *);
|
TextRenderable * CreateTextRenderable(Material *);
|
||||||
|
|
||||||
@ -121,7 +111,6 @@ public: //Get
|
|||||||
|
|
||||||
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
||||||
MaterialInstance * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
|
MaterialInstance * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
|
||||||
Pipeline * GetPipeline (const PipelineID &id){return rm_pipeline.Get(id);}
|
|
||||||
DescriptorSets * GetDescSets (const DescriptorSetsID &id){return rm_desc_sets.Get(id);}
|
DescriptorSets * GetDescSets (const DescriptorSetsID &id){return rm_desc_sets.Get(id);}
|
||||||
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||||
GPUBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
GPUBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include<hgl/graph/VKFramebuffer.h>
|
#include<hgl/graph/VKFramebuffer.h>
|
||||||
#include<hgl/graph/VKSwapchain.h>
|
#include<hgl/graph/VKSwapchain.h>
|
||||||
#include<hgl/graph/VKQueue.h>
|
#include<hgl/graph/VKQueue.h>
|
||||||
|
#include<hgl/graph/VKPipeline.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
/**
|
/**
|
||||||
* 渲染目标
|
* 渲染目标
|
||||||
@ -28,6 +29,10 @@ protected:
|
|||||||
Texture2D **color_textures;
|
Texture2D **color_textures;
|
||||||
Texture2D *depth_texture;
|
Texture2D *depth_texture;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
ObjectList<Pipeline> pipeline_list;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
friend class GPUDevice;
|
friend class GPUDevice;
|
||||||
@ -47,6 +52,15 @@ public:
|
|||||||
virtual Texture2D * GetColorTexture (const int index=0){return color_textures[index];}
|
virtual Texture2D * GetColorTexture (const int index=0){return color_textures[index];}
|
||||||
virtual Texture2D * GetDepthTexture (){return depth_texture;}
|
virtual Texture2D * GetDepthTexture (){return depth_texture;}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
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:
|
public:
|
||||||
|
|
||||||
GPUSemaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
GPUSemaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
||||||
|
@ -85,6 +85,8 @@ SET(VK_RENDER_PASS_SOURCE ${VK_INCLUDE_PATH}/VKFramebuffer.h
|
|||||||
VKPipeline.cpp
|
VKPipeline.cpp
|
||||||
VKRenderPass.cpp
|
VKRenderPass.cpp
|
||||||
VKRenderTarget.cpp
|
VKRenderTarget.cpp
|
||||||
|
VKRenderTargetPipeline.cpp
|
||||||
|
VKSwapchainRenderTarget.cpp
|
||||||
VKSwapchain.cpp
|
VKSwapchain.cpp
|
||||||
VKCommandBuffer.cpp)
|
VKCommandBuffer.cpp)
|
||||||
|
|
||||||
|
@ -71,56 +71,6 @@ MaterialInstance *RenderResource::CreateMaterialInstance(const OSString &mtl_fil
|
|||||||
return CreateMaterialInstance(mtl);
|
return CreateMaterialInstance(mtl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline *RenderResource::CreatePipeline(Material *mtl,RenderTarget *rt,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
|
||||||
PipelineData *pd=GetPipelineData(ip);
|
|
||||||
|
|
||||||
pd->Set(prim,prim_restart);
|
|
||||||
|
|
||||||
Pipeline *p=device->CreatePipeline(pd,mtl,rt);
|
|
||||||
|
|
||||||
if(p)
|
|
||||||
Add(p);
|
|
||||||
|
|
||||||
return(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderResource::CreatePipeline(MaterialInstance *mi,RenderTarget *rt,const InlinePipeline &ip,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
|
||||||
return CreatePipeline(mi->GetMaterial(),rt,ip,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderResource::CreatePipeline(Material *mtl,RenderTarget *rt,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
|
||||||
pd->Set(prim,prim_restart);
|
|
||||||
|
|
||||||
Pipeline *p=device->CreatePipeline(pd,mtl,rt);
|
|
||||||
|
|
||||||
if(p)
|
|
||||||
Add(p);
|
|
||||||
|
|
||||||
return(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderResource::CreatePipeline(MaterialInstance *mi,RenderTarget *rt,PipelineData *pd,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
|
||||||
return CreatePipeline(mi->GetMaterial(),rt,pd,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderResource::CreatePipeline(Material *mtl,RenderTarget *rt,const OSString &pipeline_filename,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
|
||||||
PipelineData *pd=GetPipelineData(pipeline_filename);
|
|
||||||
|
|
||||||
if(!pd)return(nullptr);
|
|
||||||
|
|
||||||
return CreatePipeline(mtl,rt,pd,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pipeline *RenderResource::CreatePipeline(MaterialInstance *mi,RenderTarget *rt,const OSString &filename,const Prim &prim,const bool prim_restart)
|
|
||||||
{
|
|
||||||
return CreatePipeline(mi->GetMaterial(),rt,filename,prim,prim_restart);
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderable *RenderResource::CreateRenderable(const uint32_t vertex_count)
|
Renderable *RenderResource::CreateRenderable(const uint32_t vertex_count)
|
||||||
{
|
{
|
||||||
if(!vertex_count)return(nullptr);
|
if(!vertex_count)return(nullptr);
|
||||||
|
@ -54,6 +54,7 @@ RenderTarget::RenderTarget(GPUDevice *dev,RenderPass *_rp,Framebuffer *_fb,GPUCm
|
|||||||
|
|
||||||
RenderTarget::~RenderTarget()
|
RenderTarget::~RenderTarget()
|
||||||
{
|
{
|
||||||
|
pipeline_list.Clear();
|
||||||
SAFE_CLEAR(depth_texture);
|
SAFE_CLEAR(depth_texture);
|
||||||
SAFE_CLEAR_OBJECT_ARRAY(color_textures,color_count);
|
SAFE_CLEAR_OBJECT_ARRAY(color_textures,color_count);
|
||||||
|
|
||||||
@ -67,89 +68,4 @@ bool RenderTarget::Submit(GPUSemaphore *present_complete_semaphore)
|
|||||||
{
|
{
|
||||||
return this->GPUQueue::Submit(*command_buffer,present_complete_semaphore,render_complete_semaphore);
|
return this->GPUQueue::Submit(*command_buffer,present_complete_semaphore,render_complete_semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapchainRenderTarget::SwapchainRenderTarget(GPUDevice *dev,Swapchain *sc):RenderTarget(dev,nullptr,nullptr,sc->GetImageCount())
|
|
||||||
{
|
|
||||||
swapchain=sc;
|
|
||||||
vk_swapchain=swapchain->GetSwapchain();
|
|
||||||
|
|
||||||
present_info.waitSemaphoreCount = 0;
|
|
||||||
present_info.pWaitSemaphores = nullptr;
|
|
||||||
present_info.swapchainCount = 1;
|
|
||||||
present_info.pResults = nullptr;
|
|
||||||
present_info.pSwapchains = &vk_swapchain;
|
|
||||||
|
|
||||||
Texture2D **sc_color=swapchain->GetColorTextures();
|
|
||||||
Texture2D *sc_depth=swapchain->GetDepthTexture();
|
|
||||||
|
|
||||||
this->render_pass=device->CreateRenderPass((*sc_color)->GetFormat(),sc_depth->GetFormat(),VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
|
||||||
|
|
||||||
swap_chain_count=swapchain->GetImageCount();
|
|
||||||
|
|
||||||
extent=swapchain->GetExtent();
|
|
||||||
|
|
||||||
render_frame=new Framebuffer *[swap_chain_count];
|
|
||||||
|
|
||||||
for(uint i=0;i<swap_chain_count;i++)
|
|
||||||
{
|
|
||||||
render_frame[i]=device->CreateFramebuffer(this->render_pass,(*sc_color)->GetImageView(),sc_depth->GetImageView());
|
|
||||||
++sc_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
current_frame=0;
|
|
||||||
|
|
||||||
present_complete_semaphore=dev->CreateSemaphore();
|
|
||||||
}
|
|
||||||
|
|
||||||
SwapchainRenderTarget::~SwapchainRenderTarget()
|
|
||||||
{
|
|
||||||
SAFE_CLEAR_OBJECT_ARRAY(render_frame,swap_chain_count);
|
|
||||||
|
|
||||||
delete present_complete_semaphore;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SwapchainRenderTarget::AcquireNextImage()
|
|
||||||
{
|
|
||||||
if(vkAcquireNextImageKHR(device->GetDevice(),vk_swapchain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
|
||||||
return current_frame;
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SwapchainRenderTarget::PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t count)
|
|
||||||
{
|
|
||||||
present_info.waitSemaphoreCount =count;
|
|
||||||
present_info.pWaitSemaphores =wait_semaphores;
|
|
||||||
present_info.pImageIndices =¤t_frame;
|
|
||||||
|
|
||||||
VkResult result=vkQueuePresentKHR(queue,&present_info);
|
|
||||||
|
|
||||||
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
|
||||||
{
|
|
||||||
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
|
||||||
// Swap chain is no longer compatible with the surface and needs to be recreated
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SwapchainRenderTarget::PresentBackbuffer()
|
|
||||||
{
|
|
||||||
VkSemaphore sem=*render_complete_semaphore;
|
|
||||||
|
|
||||||
return this->PresentBackbuffer(&sem,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb)
|
|
||||||
{
|
|
||||||
return GPUQueue::Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb,GPUSemaphore *pce)
|
|
||||||
{
|
|
||||||
return GPUQueue::Submit(cb,pce,render_complete_semaphore);
|
|
||||||
}
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
61
src/RenderDevice/VKRenderTargetPipeline.cpp
Normal file
61
src/RenderDevice/VKRenderTargetPipeline.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#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
|
90
src/RenderDevice/VKSwapchainRenderTarget.cpp
Normal file
90
src/RenderDevice/VKSwapchainRenderTarget.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
|
#include<hgl/graph/VKDevice.h>
|
||||||
|
#include<hgl/graph/VKSemaphore.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
SwapchainRenderTarget::SwapchainRenderTarget(GPUDevice *dev,Swapchain *sc):RenderTarget(dev,nullptr,nullptr,sc->GetImageCount())
|
||||||
|
{
|
||||||
|
swapchain=sc;
|
||||||
|
vk_swapchain=swapchain->GetSwapchain();
|
||||||
|
|
||||||
|
present_info.waitSemaphoreCount = 0;
|
||||||
|
present_info.pWaitSemaphores = nullptr;
|
||||||
|
present_info.swapchainCount = 1;
|
||||||
|
present_info.pResults = nullptr;
|
||||||
|
present_info.pSwapchains = &vk_swapchain;
|
||||||
|
|
||||||
|
Texture2D **sc_color=swapchain->GetColorTextures();
|
||||||
|
Texture2D *sc_depth=swapchain->GetDepthTexture();
|
||||||
|
|
||||||
|
this->render_pass=device->CreateRenderPass((*sc_color)->GetFormat(),sc_depth->GetFormat(),VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||||
|
|
||||||
|
swap_chain_count=swapchain->GetImageCount();
|
||||||
|
|
||||||
|
extent=swapchain->GetExtent();
|
||||||
|
|
||||||
|
render_frame=new Framebuffer *[swap_chain_count];
|
||||||
|
|
||||||
|
for(uint i=0;i<swap_chain_count;i++)
|
||||||
|
{
|
||||||
|
render_frame[i]=device->CreateFramebuffer(this->render_pass,(*sc_color)->GetImageView(),sc_depth->GetImageView());
|
||||||
|
++sc_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_frame=0;
|
||||||
|
|
||||||
|
present_complete_semaphore=dev->CreateSemaphore();
|
||||||
|
}
|
||||||
|
|
||||||
|
SwapchainRenderTarget::~SwapchainRenderTarget()
|
||||||
|
{
|
||||||
|
SAFE_CLEAR_OBJECT_ARRAY(render_frame,swap_chain_count);
|
||||||
|
|
||||||
|
delete present_complete_semaphore;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SwapchainRenderTarget::AcquireNextImage()
|
||||||
|
{
|
||||||
|
if(vkAcquireNextImageKHR(device->GetDevice(),vk_swapchain,UINT64_MAX,*(this->present_complete_semaphore),VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||||
|
return current_frame;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwapchainRenderTarget::PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t count)
|
||||||
|
{
|
||||||
|
present_info.waitSemaphoreCount =count;
|
||||||
|
present_info.pWaitSemaphores =wait_semaphores;
|
||||||
|
present_info.pImageIndices =¤t_frame;
|
||||||
|
|
||||||
|
VkResult result=vkQueuePresentKHR(queue,&present_info);
|
||||||
|
|
||||||
|
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
||||||
|
{
|
||||||
|
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||||
|
// Swap chain is no longer compatible with the surface and needs to be recreated
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwapchainRenderTarget::PresentBackbuffer()
|
||||||
|
{
|
||||||
|
VkSemaphore sem=*render_complete_semaphore;
|
||||||
|
|
||||||
|
return this->PresentBackbuffer(&sem,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb)
|
||||||
|
{
|
||||||
|
return GPUQueue::Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwapchainRenderTarget::Submit(VkCommandBuffer cb,GPUSemaphore *pce)
|
||||||
|
{
|
||||||
|
return GPUQueue::Submit(cb,pce,render_complete_semaphore);
|
||||||
|
}
|
||||||
|
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user