RenderTarget初步制作并测试成功
This commit is contained in:
parent
ec106446b2
commit
32db6678cc
@ -88,7 +88,7 @@ private:
|
|||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
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);
|
||||||
|
@ -251,7 +251,7 @@ private:
|
|||||||
|
|
||||||
bool InitCompositionPipeline(SubpassParam *sp)
|
bool InitCompositionPipeline(SubpassParam *sp)
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,sp->material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,sp->material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->SetDepthTest(false);
|
pipeline_creater->SetDepthTest(false);
|
||||||
pipeline_creater->SetDepthWrite(false);
|
pipeline_creater->SetDepthWrite(false);
|
||||||
pipeline_creater->SetCullMode(VK_CULL_MODE_NONE);
|
pipeline_creater->SetCullMode(VK_CULL_MODE_NONE);
|
||||||
@ -408,7 +408,7 @@ private:
|
|||||||
gbuffer_cmd->EndRenderPass();
|
gbuffer_cmd->EndRenderPass();
|
||||||
gbuffer_cmd->End();
|
gbuffer_cmd->End();
|
||||||
|
|
||||||
device->SubmitDraw(*gbuffer_cmd);
|
device->Submit(*gbuffer_cmd);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ private:
|
|||||||
|
|
||||||
bool InitUBO()
|
bool InitUBO()
|
||||||
{
|
{
|
||||||
const VkExtent2D extent=swapchain->GetExtent();
|
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||||
|
|
||||||
world.mvp=ortho(extent.width,extent.height);
|
world.mvp=ortho(extent.width,extent.height);
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ private:
|
|||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->CloseCullFace();
|
pipeline_creater->CloseCullFace();
|
||||||
pipeline_creater->Set(PRIM_TRIANGLE_FAN);
|
pipeline_creater->Set(PRIM_TRIANGLE_FAN);
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ private:
|
|||||||
bool InitPipeline(MDP *mdp,const VkPrimitiveTopology primitive)
|
bool InitPipeline(MDP *mdp,const VkPrimitiveTopology primitive)
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,mdp->material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,mdp->material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->CloseCullFace();
|
pipeline_creater->CloseCullFace();
|
||||||
pipeline_creater->Set(primitive);
|
pipeline_creater->Set(primitive);
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
constexpr uint32_t SCREEN_WIDTH=128;
|
||||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
constexpr uint32_t SCREEN_HEIGHT=128;
|
||||||
|
|
||||||
class TestApp:public CameraAppFramework
|
class TestApp:public CameraAppFramework
|
||||||
{
|
{
|
||||||
@ -137,7 +137,7 @@ private:
|
|||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->Set(PRIM_LINES);
|
pipeline_creater->Set(PRIM_LINES);
|
||||||
|
|
||||||
pipeline_line=pipeline_creater->Create();
|
pipeline_line=pipeline_creater->Create();
|
||||||
|
@ -163,7 +163,7 @@ private:
|
|||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->SetDepthTest(false);
|
pipeline_creater->SetDepthTest(false);
|
||||||
pipeline_creater->SetDepthWrite(false);
|
pipeline_creater->SetDepthWrite(false);
|
||||||
pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE);
|
pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE);
|
||||||
|
@ -75,7 +75,7 @@ private:
|
|||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->SetDepthTest(true);
|
pipeline_creater->SetDepthTest(true);
|
||||||
pipeline_creater->SetDepthWrite(true);
|
pipeline_creater->SetDepthWrite(true);
|
||||||
pipeline_creater->CloseCullFace();
|
pipeline_creater->CloseCullFace();
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include<hgl/graph/vulkan/VKFormat.h>
|
#include<hgl/graph/vulkan/VKFormat.h>
|
||||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||||
#include<hgl/graph/vulkan/VKMaterial.h>
|
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||||
|
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
||||||
#include<hgl/graph/SceneDB.h>
|
#include<hgl/graph/SceneDB.h>
|
||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
|
|
||||||
@ -50,19 +51,19 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
vulkan::Device * device =nullptr;
|
vulkan::Device * device =nullptr;
|
||||||
vulkan::Swapchain * swapchain =nullptr;
|
vulkan::SwapchainRenderTarget * sc_render_target =nullptr;
|
||||||
|
|
||||||
vulkan::Semaphore * present_complete_semaphore =nullptr,
|
vulkan::Semaphore * present_complete_semaphore =nullptr,
|
||||||
* render_complete_semaphore =nullptr;
|
* render_complete_semaphore =nullptr;
|
||||||
|
|
||||||
vulkan::ShaderModuleManage *shader_manage =nullptr;
|
vulkan::ShaderModuleManage * shader_manage =nullptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
uint32_t swap_chain_count=0;
|
uint32_t swap_chain_count=0;
|
||||||
|
|
||||||
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
vulkan::CommandBuffer ** cmd_buf =nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ public:
|
|||||||
if(!device)
|
if(!device)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
swapchain=device->GetSwapchain();
|
sc_render_target=device->GetSwapchainRT();
|
||||||
present_complete_semaphore =device->CreateSem();
|
present_complete_semaphore =device->CreateSem();
|
||||||
render_complete_semaphore =device->CreateSem();
|
render_complete_semaphore =device->CreateSem();
|
||||||
|
|
||||||
@ -147,10 +148,9 @@ public:
|
|||||||
if(cmd_buf)
|
if(cmd_buf)
|
||||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||||
|
|
||||||
|
swap_chain_count=sc_render_target->GetImageCount();
|
||||||
swap_chain_count=swapchain->GetImageCount();
|
|
||||||
{
|
{
|
||||||
const VkExtent2D extent=swapchain->GetExtent();
|
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||||
|
|
||||||
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ public:
|
|||||||
vulkan::CommandBuffer *cb=cmd_buf[index];
|
vulkan::CommandBuffer *cb=cmd_buf[index];
|
||||||
|
|
||||||
cb->Begin();
|
cb->Begin();
|
||||||
cb->BeginRenderPass(swapchain->GetMainRenderPass(),swapchain->GetFramebuffer(index));
|
cb->BeginRenderPass(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
||||||
cb->Bind(p);
|
cb->Bind(p);
|
||||||
cb->Bind(ds);
|
cb->Bind(ds);
|
||||||
cb->Bind(r);
|
cb->Bind(r);
|
||||||
@ -191,7 +191,7 @@ public:
|
|||||||
|
|
||||||
void BuildCurrentCommandBuffer(vulkan::Pipeline *p,vulkan::DescriptorSets *ds,vulkan::Renderable *r)
|
void BuildCurrentCommandBuffer(vulkan::Pipeline *p,vulkan::DescriptorSets *ds,vulkan::Renderable *r)
|
||||||
{
|
{
|
||||||
BuildCommandBuffer(swapchain->GetCurrentFrameIndices(),p,ds,r);
|
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),p,ds,r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildCommandBuffer(uint32_t index,RenderList *rl)
|
void BuildCommandBuffer(uint32_t index,RenderList *rl)
|
||||||
@ -201,7 +201,7 @@ public:
|
|||||||
vulkan::CommandBuffer *cb=cmd_buf[index];
|
vulkan::CommandBuffer *cb=cmd_buf[index];
|
||||||
|
|
||||||
cb->Begin();
|
cb->Begin();
|
||||||
cb->BeginRenderPass(swapchain->GetMainRenderPass(),swapchain->GetFramebuffer(index));
|
cb->BeginRenderPass(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
||||||
rl->Render(cb);
|
rl->Render(cb);
|
||||||
cb->EndRenderPass();
|
cb->EndRenderPass();
|
||||||
cb->End();
|
cb->End();
|
||||||
@ -215,16 +215,16 @@ public:
|
|||||||
|
|
||||||
void BuildCurrentCommandBuffer(RenderList *rl)
|
void BuildCurrentCommandBuffer(RenderList *rl)
|
||||||
{
|
{
|
||||||
BuildCommandBuffer(swapchain->GetCurrentFrameIndices(),rl);
|
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int AcquireNextImage()
|
int AcquireNextImage()
|
||||||
{
|
{
|
||||||
if(swapchain->Wait())
|
if(sc_render_target->Wait())
|
||||||
{
|
{
|
||||||
int cur=swapchain->AcquireNextImage(present_complete_semaphore);
|
int cur=sc_render_target->AcquireNextImage(present_complete_semaphore);
|
||||||
|
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
@ -236,8 +236,8 @@ public:
|
|||||||
{
|
{
|
||||||
VkCommandBuffer cb=*cmd_buf[index];
|
VkCommandBuffer cb=*cmd_buf[index];
|
||||||
|
|
||||||
swapchain->SubmitDraw(cb,present_complete_semaphore,render_complete_semaphore);
|
sc_render_target->Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
||||||
swapchain->PresentBackbuffer(render_complete_semaphore);
|
sc_render_target->PresentBackbuffer(render_complete_semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Draw()
|
virtual void Draw()
|
||||||
|
@ -76,7 +76,7 @@ private:
|
|||||||
|
|
||||||
bool InitUBO()
|
bool InitUBO()
|
||||||
{
|
{
|
||||||
const VkExtent2D extent=swapchain->GetExtent();
|
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||||
|
|
||||||
world.mvp=ortho(extent.width,extent.height);
|
world.mvp=ortho(extent.width,extent.height);
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ private:
|
|||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->CloseCullFace();
|
pipeline_creater->CloseCullFace();
|
||||||
pipeline_creater->Set(PRIM_TRIANGLES);
|
pipeline_creater->Set(PRIM_TRIANGLES);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ private:
|
|||||||
|
|
||||||
bool InitUBO()
|
bool InitUBO()
|
||||||
{
|
{
|
||||||
const VkExtent2D extent=swapchain->GetExtent();
|
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||||
|
|
||||||
world.mvp=ortho(extent.width,extent.height);
|
world.mvp=ortho(extent.width,extent.height);
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ private:
|
|||||||
|
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->CloseCullFace();
|
pipeline_creater->CloseCullFace();
|
||||||
pipeline_creater->Set(PRIM_TRIANGLES);
|
pipeline_creater->Set(PRIM_TRIANGLES);
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ private:
|
|||||||
void *data;
|
void *data;
|
||||||
uint size=filesystem::LoadFileToMemory(PIPELINE_FILENAME,(void **)&data);
|
uint size=filesystem::LoadFileToMemory(PIPELINE_FILENAME,(void **)&data);
|
||||||
|
|
||||||
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent(),(uchar *)data,size);
|
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent(),(uchar *)data,size);
|
||||||
|
|
||||||
pipeline=pipeline_creater->Create();
|
pipeline=pipeline_creater->Create();
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ private:
|
|||||||
|
|
||||||
bool InitUBO()
|
bool InitUBO()
|
||||||
{
|
{
|
||||||
const VkExtent2D extent=swapchain->GetExtent();
|
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||||
|
|
||||||
world.mvp=ortho(extent.width,extent.height);
|
world.mvp=ortho(extent.width,extent.height);
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ private:
|
|||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
AutoDelete<vulkan::PipelineCreater>
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,swapchain->GetMainRenderPass(),swapchain->GetExtent());
|
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target->GetRenderPass(),sc_render_target->GetExtent());
|
||||||
pipeline_creater->CloseCullFace();
|
pipeline_creater->CloseCullFace();
|
||||||
pipeline_creater->Set(PRIM_TRIANGLES);
|
pipeline_creater->Set(PRIM_TRIANGLES);
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@ class Device;
|
|||||||
struct DeviceAttribute;
|
struct DeviceAttribute;
|
||||||
class ImageView;
|
class ImageView;
|
||||||
class Framebuffer;
|
class Framebuffer;
|
||||||
|
class Swapchain;
|
||||||
|
class RenderTarget;
|
||||||
|
class SwapchainRenderTarget;
|
||||||
|
|
||||||
class Texture;
|
class Texture;
|
||||||
class Texture1D;
|
class Texture1D;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include<hgl/graph/vulkan/VK.h>
|
#include<hgl/graph/vulkan/VK.h>
|
||||||
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
|
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
|
||||||
#include<hgl/graph/vulkan/VKSwapchain.h>
|
#include<hgl/graph/vulkan/VKSwapchain.h>
|
||||||
|
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
||||||
#include<hgl/graph/VertexBufferCreater.h>
|
#include<hgl/graph/VertexBufferCreater.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -21,6 +22,7 @@ class Device
|
|||||||
CommandBuffer *texture_cmd_buf;
|
CommandBuffer *texture_cmd_buf;
|
||||||
|
|
||||||
Swapchain *swapchain;
|
Swapchain *swapchain;
|
||||||
|
SwapchainRenderTarget *swapchainRT;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -47,6 +49,8 @@ public:
|
|||||||
|
|
||||||
Swapchain * GetSwapchain () {return swapchain;}
|
Swapchain * GetSwapchain () {return swapchain;}
|
||||||
|
|
||||||
|
SwapchainRenderTarget * GetSwapchainRT () {return swapchainRT;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool Resize (const VkExtent2D &);
|
bool Resize (const VkExtent2D &);
|
||||||
@ -180,6 +184,8 @@ public: //Command Buffer 相关
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
|
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
|
||||||
|
|
||||||
|
RenderTarget *CreateRenderTarget(Framebuffer *);
|
||||||
};//class Device
|
};//class Device
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
||||||
|
@ -3,27 +3,48 @@
|
|||||||
|
|
||||||
#include<hgl/graph/vulkan/VK.h>
|
#include<hgl/graph/vulkan/VK.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
class Framebuffer
|
class Framebuffer
|
||||||
{
|
{
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
VkFramebuffer frame_buffer;
|
VkFramebuffer frame_buffer;
|
||||||
|
VkFramebufferCreateInfo *fb_info;
|
||||||
|
|
||||||
|
VkExtent2D extent;
|
||||||
|
uint32_t color_count;
|
||||||
|
bool has_depth;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
|
friend Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
|
||||||
|
|
||||||
Framebuffer(VkDevice dev,VkFramebuffer fb)
|
Framebuffer(VkDevice dev,VkFramebuffer fb,VkFramebufferCreateInfo *fb_create_info,bool depth)
|
||||||
{
|
{
|
||||||
device=dev;
|
device=dev;
|
||||||
frame_buffer=fb;
|
frame_buffer=fb;
|
||||||
|
fb_info=fb_create_info;
|
||||||
|
|
||||||
|
extent.width=fb_info->width;
|
||||||
|
extent.height=fb_info->height;
|
||||||
|
|
||||||
|
has_depth=depth;
|
||||||
|
if(has_depth)
|
||||||
|
color_count=fb_info->attachmentCount-1;
|
||||||
|
else
|
||||||
|
color_count=fb_info->attachmentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
~Framebuffer();
|
~Framebuffer();
|
||||||
|
|
||||||
operator VkFramebuffer(){return frame_buffer;}
|
VkFramebuffer GetFramebuffer (){return frame_buffer;}
|
||||||
|
VkRenderPass GetRenderPass (){return fb_info->renderPass;}
|
||||||
|
|
||||||
|
const VkExtent2D & GetExtent ()const{return extent;}
|
||||||
|
|
||||||
|
const uint32_t GetAttachmentCount ()const{return fb_info->attachmentCount;} ///<获取渲染目标成分数量
|
||||||
|
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
|
||||||
|
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
|
||||||
};//class Framebuffer
|
};//class Framebuffer
|
||||||
|
|
||||||
Framebuffer *CreateFramebuffer(Device *,RenderPass *,List<ImageView *> &color,ImageView *depth);
|
Framebuffer *CreateFramebuffer(Device *,RenderPass *,List<ImageView *> &color,ImageView *depth);
|
||||||
|
@ -4,42 +4,93 @@
|
|||||||
#include<hgl/graph/vulkan/VK.h>
|
#include<hgl/graph/vulkan/VK.h>
|
||||||
#include<hgl/graph/vulkan/VKRenderPass.h>
|
#include<hgl/graph/vulkan/VKRenderPass.h>
|
||||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||||
|
#include<hgl/graph/vulkan/VKSwapchain.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class RenderTarget
|
class SubmitQueue
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
Device *device;
|
Device *device;
|
||||||
|
VkQueue queue;
|
||||||
|
|
||||||
|
uint32_t current_fence;
|
||||||
|
ObjectList<Fence> fence_list;
|
||||||
|
|
||||||
RenderPass *rp;
|
VkSubmitInfo submit_info;
|
||||||
Framebuffer *fb;
|
|
||||||
|
|
||||||
VkExtent2D extent;
|
|
||||||
|
|
||||||
List<ImageView *> colors;
|
|
||||||
ImageView *depth;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
friend class Device;
|
|
||||||
|
|
||||||
RenderTarget(Device *dev,RenderPass *_rp,Framebuffer *_fb)
|
|
||||||
{
|
|
||||||
device=dev;
|
|
||||||
rp=_rp;
|
|
||||||
fb=_fb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~RenderTarget()
|
SubmitQueue(Device *dev,VkQueue q,const uint32_t fence_count=1);
|
||||||
{
|
virtual ~SubmitQueue();
|
||||||
if(fb)
|
|
||||||
delete fb;
|
bool Wait(const bool wait_wall=true,const uint64 time_out=HGL_NANO_SEC_PER_SEC);
|
||||||
}
|
bool Submit(VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem);
|
||||||
|
};//class SumbitQueue
|
||||||
|
|
||||||
const VkExtent2D & GetExtent ()const{return extent;} ///<取得画面尺寸
|
/**
|
||||||
|
* 渲染目标
|
||||||
|
*/
|
||||||
|
class RenderTarget:public SubmitQueue
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
const uint GetColorCount ()const{colors.GetCount();} ///<取得颜色成份数量
|
Framebuffer *fb;
|
||||||
const bool IsExistDepth ()const{return depth;} ///<是否存在深度成份
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
friend class Device;
|
||||||
|
|
||||||
|
RenderTarget(Device *dev,Framebuffer *_fb,const uint32_t fence_count=1);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~RenderTarget()=default;
|
||||||
|
|
||||||
};//class RenderTarget
|
};//class RenderTarget
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 交换链专用渲染目标
|
||||||
|
*/
|
||||||
|
class SwapchainRenderTarget:public RenderTarget
|
||||||
|
{
|
||||||
|
Swapchain *swapchain;
|
||||||
|
VkSwapchainKHR vk_swapchain;
|
||||||
|
VkPresentInfoKHR present_info;
|
||||||
|
|
||||||
|
RenderPass *main_rp=nullptr;
|
||||||
|
|
||||||
|
uint32_t swap_chain_count;
|
||||||
|
VkExtent2D extent;
|
||||||
|
|
||||||
|
uint32_t current_frame;
|
||||||
|
ObjectList<Framebuffer> render_frame;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
SwapchainRenderTarget(Device *dev,Swapchain *sc);
|
||||||
|
~SwapchainRenderTarget();
|
||||||
|
|
||||||
|
const uint32_t GetImageCount()const{return swap_chain_count;}
|
||||||
|
const VkExtent2D & GetExtent()const{return extent;}
|
||||||
|
|
||||||
|
RenderPass * GetRenderPass(){return main_rp;}
|
||||||
|
Framebuffer * GetFramebuffer(const uint32_t index){return render_frame[index];}
|
||||||
|
|
||||||
|
const uint32_t GetCurrentFrameIndices()const{return current_frame;}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求下一帧画面的索引
|
||||||
|
* @param present_complete_semaphore 推送完成信号
|
||||||
|
*/
|
||||||
|
int AcquireNextImage(vulkan::Semaphore *present_complete_semaphore);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送后台画面到前台
|
||||||
|
* @param render_complete_semaphore 渲染完成信号
|
||||||
|
*/
|
||||||
|
bool PresentBackbuffer(vulkan::Semaphore *render_complete_semaphore);
|
||||||
|
};//class SwapchainRenderTarget:public RenderTarget
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
||||||
|
@ -16,28 +16,33 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
VkPipelineStageFlags pipe_stage_flags;
|
// VkPipelineStageFlags pipe_stage_flags;
|
||||||
|
|
||||||
uint32_t current_frame;
|
//uint32_t current_frame;
|
||||||
ObjectList<Framebuffer> render_frame;
|
//ObjectList<Framebuffer> render_frame;
|
||||||
|
|
||||||
uint32_t current_fence;
|
//uint32_t current_fence;
|
||||||
ObjectList<Fence> fence_list;
|
//ObjectList<Fence> fence_list;
|
||||||
|
|
||||||
RenderPass *main_rp =nullptr;
|
//RenderPass *main_rp =nullptr;
|
||||||
|
|
||||||
VkSubmitInfo submit_info;
|
//VkSubmitInfo submit_info;
|
||||||
VkPresentInfoKHR present_info;
|
//VkPresentInfoKHR present_info;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
VkSwapchainKHR GetSwapchain () {return sc_attr->swap_chain;}
|
||||||
const VkExtent2D & GetExtent ()const {return sc_attr->extent;}
|
const VkExtent2D & GetExtent ()const {return sc_attr->extent;}
|
||||||
const uint32_t GetImageCount ()const {return sc_attr->sc_color.GetCount();}
|
const uint32_t GetImageCount ()const {return sc_attr->sc_color.GetCount();}
|
||||||
|
|
||||||
RenderPass * GetMainRenderPass () {return main_rp;}
|
Texture2D ** GetColorTextures () {return sc_attr->sc_color.GetData();}
|
||||||
Framebuffer * GetFramebuffer (int index) {return render_frame[index];}
|
Texture2D * GetColorTexture (int index) {return sc_attr->sc_color[index];}
|
||||||
const uint32_t GetCurrentFrameIndices () {return current_frame;}
|
Texture2D * GetDepthTexture () {return sc_attr->sc_depth;}
|
||||||
Framebuffer * GetCurrentFramebuffer () {return render_frame[current_frame];}
|
|
||||||
|
// RenderPass * GetMainRenderPass () {return main_rp;}
|
||||||
|
// Framebuffer * GetFramebuffer (int index) {return render_frame[index];}
|
||||||
|
//const uint32_t GetCurrentFrameIndices () {return current_frame;}
|
||||||
|
// Framebuffer * GetCurrentFramebuffer () {return render_frame[current_frame];}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -45,36 +50,36 @@ public:
|
|||||||
|
|
||||||
virtual ~Swapchain();
|
virtual ~Swapchain();
|
||||||
|
|
||||||
bool Wait (bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1); ///<等待队列完成
|
//bool Wait (bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1); ///<等待队列完成
|
||||||
|
|
||||||
/**
|
///**
|
||||||
* 请求获得下一帧的索引,并将确认信息发送到指定信号
|
// * 请求获得下一帧的索引,并将确认信息发送到指定信号
|
||||||
* @param complete_semaphore 完成后请发送至此信号
|
// * @param complete_semaphore 完成后请发送至此信号
|
||||||
* @return 下一帧的索引
|
// * @return 下一帧的索引
|
||||||
* @return <0 错误
|
// * @return <0 错误
|
||||||
*/
|
// */
|
||||||
int AcquireNextImage (vulkan::Semaphore *complete_semaphore); ///<请求获得下一帧的索引
|
//int AcquireNextImage (vulkan::Semaphore *complete_semaphore); ///<请求获得下一帧的索引
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 提交一个绘制指令
|
// * 提交一个绘制指令
|
||||||
* @param cmd_list 绘制指令
|
// * @param cmd_list 绘制指令
|
||||||
* @param wait_sem 指令开始前要等待的确认的信号
|
// * @param wait_sem 指令开始前要等待的确认的信号
|
||||||
* @param complete_semaphore 绘制完成后发送的信号
|
// * @param complete_semaphore 绘制完成后发送的信号
|
||||||
*/
|
// */
|
||||||
bool SubmitDraw (VkCommandBuffer &cmd_list,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_semaphore); ///<提交绘制指令
|
//bool SubmitDraw (VkCommandBuffer &cmd_list,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_semaphore); ///<提交绘制指令
|
||||||
|
|
||||||
/**
|
///**
|
||||||
* 提交一批绘制指令
|
// * 提交一批绘制指令
|
||||||
* @param cmd_list 绘制指令
|
// * @param cmd_list 绘制指令
|
||||||
* @param wait_sems 指令开始前要等待的确认的信号
|
// * @param wait_sems 指令开始前要等待的确认的信号
|
||||||
* @param complete_semaphores 绘制完成后发送的信号
|
// * @param complete_semaphores 绘制完成后发送的信号
|
||||||
*/
|
// */
|
||||||
bool SubmitDraw (List<VkCommandBuffer> &cmd_list,List<VkSemaphore> &wait_sems,List<VkSemaphore> &complete_semaphores); ///<提交绘制指令
|
//bool SubmitDraw (List<VkCommandBuffer> &cmd_list,List<VkSemaphore> &wait_sems,List<VkSemaphore> &complete_semaphores); ///<提交绘制指令
|
||||||
|
|
||||||
/**
|
///**
|
||||||
* @param render_complete_semaphore 渲染完成信号
|
// * @param render_complete_semaphore 渲染完成信号
|
||||||
*/
|
// */
|
||||||
bool PresentBackbuffer (vulkan::Semaphore *render_complete_semaphore); ///<等待绘制队列完成,并将后台缓冲区呈现到前台
|
//bool PresentBackbuffer (vulkan::Semaphore *render_complete_semaphore); ///<等待绘制队列完成,并将后台缓冲区呈现到前台
|
||||||
};//class Swapchain
|
};//class Swapchain
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKPrimivate.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKPrimivate.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderable.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderable.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderPass.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderPass.h
|
||||||
# ${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderTarget.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderTarget.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKSemaphore.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKSemaphore.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderResource.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderResource.h
|
||||||
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderModule.h
|
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderModule.h
|
||||||
@ -46,7 +46,7 @@ SET(RENDER_DEVICE_VULKAN_SOURCE VKFormat.cpp
|
|||||||
VKDescriptorSetLayoutCreater.cpp
|
VKDescriptorSetLayoutCreater.cpp
|
||||||
VKDescriptorSetLayoutCreater.h
|
VKDescriptorSetLayoutCreater.h
|
||||||
VKRenderPass.cpp
|
VKRenderPass.cpp
|
||||||
# VKRenderTarget.cpp
|
VKRenderTarget.cpp
|
||||||
VKShaderParse.h
|
VKShaderParse.h
|
||||||
VKShaderModule.cpp
|
VKShaderModule.cpp
|
||||||
VKShaderModuleManage.cpp
|
VKShaderModuleManage.cpp
|
||||||
|
@ -64,7 +64,7 @@ bool CommandBuffer::BeginRenderPass(RenderPass *rp,Framebuffer *fb)
|
|||||||
rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
rp_begin.pNext = nullptr;
|
rp_begin.pNext = nullptr;
|
||||||
rp_begin.renderPass = *rp;
|
rp_begin.renderPass = *rp;
|
||||||
rp_begin.framebuffer = *fb;
|
rp_begin.framebuffer = fb->GetFramebuffer();
|
||||||
rp_begin.renderArea = render_area;
|
rp_begin.renderArea = render_area;
|
||||||
rp_begin.clearValueCount = cv_count;
|
rp_begin.clearValueCount = cv_count;
|
||||||
rp_begin.pClearValues = clear_values;
|
rp_begin.pClearValues = clear_values;
|
||||||
|
@ -24,11 +24,13 @@ Device::Device(DeviceAttribute *da)
|
|||||||
texture_cmd_buf=nullptr;
|
texture_cmd_buf=nullptr;
|
||||||
|
|
||||||
swapchain=nullptr;
|
swapchain=nullptr;
|
||||||
|
swapchainRT=nullptr;
|
||||||
Resize(attr->surface_caps.currentExtent);
|
Resize(attr->surface_caps.currentExtent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device()
|
Device::~Device()
|
||||||
{
|
{
|
||||||
|
SAFE_CLEAR(swapchainRT);
|
||||||
SAFE_CLEAR(swapchain);
|
SAFE_CLEAR(swapchain);
|
||||||
|
|
||||||
delete texture_cmd_buf;
|
delete texture_cmd_buf;
|
||||||
@ -39,8 +41,8 @@ Device::~Device()
|
|||||||
|
|
||||||
bool Device::Resize(const VkExtent2D &extent)
|
bool Device::Resize(const VkExtent2D &extent)
|
||||||
{
|
{
|
||||||
if(swapchain)
|
SAFE_CLEAR(swapchainRT);
|
||||||
delete swapchain;
|
SAFE_CLEAR(swapchain);
|
||||||
|
|
||||||
swapchain=CreateSwapchain(this,extent);
|
swapchain=CreateSwapchain(this,extent);
|
||||||
|
|
||||||
@ -48,6 +50,8 @@ bool Device::Resize(const VkExtent2D &extent)
|
|||||||
|
|
||||||
texture_cmd_buf=CreateCommandBuffer(swapchain->GetExtent(),0);
|
texture_cmd_buf=CreateCommandBuffer(swapchain->GetExtent(),0);
|
||||||
|
|
||||||
|
swapchainRT=new SwapchainRenderTarget(this,swapchain);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,4 +114,9 @@ ShaderModuleManage *Device::CreateShaderModuleManage()
|
|||||||
{
|
{
|
||||||
return(new ShaderModuleManage(this));
|
return(new ShaderModuleManage(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RenderTarget *Device::CreateRenderTarget(Framebuffer *fb)
|
||||||
|
{
|
||||||
|
return(new RenderTarget(this,fb));
|
||||||
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -16,7 +16,7 @@ Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list
|
|||||||
|
|
||||||
if(depth)++att_count;
|
if(depth)++att_count;
|
||||||
|
|
||||||
SharedArray<VkImageView> attachments=new VkImageView[att_count];
|
VkImageView *attachments=new VkImageView[att_count];
|
||||||
|
|
||||||
if(color_count)
|
if(color_count)
|
||||||
{
|
{
|
||||||
@ -39,30 +39,33 @@ Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list
|
|||||||
if(depth)
|
if(depth)
|
||||||
{
|
{
|
||||||
if(rp->GetDepthFormat()!=depth->GetFormat())
|
if(rp->GetDepthFormat()!=depth->GetFormat())
|
||||||
|
{
|
||||||
|
delete[] attachments;
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
attachments[color_count]=*depth;
|
attachments[color_count]=*depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VkExtent3D extent=depth->GetExtent();
|
const VkExtent3D extent=depth->GetExtent();
|
||||||
|
|
||||||
VkFramebufferCreateInfo fb_info;
|
VkFramebufferCreateInfo *fb_info=new VkFramebufferCreateInfo;
|
||||||
fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
fb_info->sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||||
fb_info.pNext = nullptr;
|
fb_info->pNext = nullptr;
|
||||||
fb_info.flags = 0;
|
fb_info->flags = 0;
|
||||||
fb_info.renderPass = *rp;
|
fb_info->renderPass = *rp;
|
||||||
fb_info.attachmentCount = att_count;
|
fb_info->attachmentCount = att_count;
|
||||||
fb_info.pAttachments = attachments;
|
fb_info->pAttachments = attachments;
|
||||||
fb_info.width = extent.width;
|
fb_info->width = extent.width;
|
||||||
fb_info.height = extent.height;
|
fb_info->height = extent.height;
|
||||||
fb_info.layers = 1;
|
fb_info->layers = 1;
|
||||||
|
|
||||||
VkFramebuffer fb;
|
VkFramebuffer fb;
|
||||||
|
|
||||||
if(vkCreateFramebuffer(dev->GetDevice(), &fb_info, nullptr, &fb)!=VK_SUCCESS)
|
if(vkCreateFramebuffer(dev->GetDevice(),fb_info,nullptr,&fb)!=VK_SUCCESS)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new Framebuffer(dev->GetDevice(),fb));
|
return(new Framebuffer(dev->GetDevice(),fb,fb_info,depth));
|
||||||
}
|
}
|
||||||
|
|
||||||
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> &color,ImageView *depth)
|
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> &color,ImageView *depth)
|
||||||
|
@ -1,9 +1,150 @@
|
|||||||
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
||||||
|
#include<hgl/graph/vulkan/VKDevice.h>
|
||||||
|
#include<hgl/graph/vulkan/VKSwapchain.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
RenderTarget::~RenderTarget()
|
namespace
|
||||||
{
|
{
|
||||||
if(fb)
|
const VkPipelineStageFlags pipe_stage_flags=VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
delete fb;
|
}//namespace
|
||||||
|
|
||||||
|
SubmitQueue::SubmitQueue(Device *dev,VkQueue q,const uint32_t fence_count)
|
||||||
|
{
|
||||||
|
device=dev;
|
||||||
|
queue=q;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<fence_count;i++)
|
||||||
|
fence_list.Add(device->CreateFence(true));
|
||||||
|
|
||||||
|
current_fence=0;
|
||||||
|
|
||||||
|
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
submit_info.pNext = nullptr;
|
||||||
|
//submit_info.waitSemaphoreCount = 1;
|
||||||
|
//submit_info.pWaitSemaphores = *present_complete_semaphore;
|
||||||
|
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
||||||
|
//submit_info.signalSemaphoreCount = 1;
|
||||||
|
//submit_info.pSignalSemaphores = *render_complete_semaphore;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubmitQueue::~SubmitQueue()
|
||||||
|
{
|
||||||
|
fence_list.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SubmitQueue::Wait(const bool wait_all,uint64_t time_out)
|
||||||
|
{
|
||||||
|
VkFence fence=*fence_list[current_fence];
|
||||||
|
|
||||||
|
VkResult result;
|
||||||
|
|
||||||
|
result=vkWaitForFences(device->GetDevice(),1,&fence,wait_all,time_out);
|
||||||
|
result=vkResetFences(device->GetDevice(),1,&fence);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SubmitQueue::Submit(VkCommandBuffer &cmd_buf,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
||||||
|
{
|
||||||
|
VkSemaphore ws=*wait_sem;
|
||||||
|
VkSemaphore cs=*complete_sem;
|
||||||
|
|
||||||
|
submit_info.waitSemaphoreCount =1;
|
||||||
|
submit_info.pWaitSemaphores =&ws;
|
||||||
|
submit_info.commandBufferCount =1;
|
||||||
|
submit_info.pCommandBuffers =&cmd_buf;
|
||||||
|
submit_info.signalSemaphoreCount=1;
|
||||||
|
submit_info.pSignalSemaphores =&cs;
|
||||||
|
|
||||||
|
VkFence fence=*fence_list[current_fence];
|
||||||
|
|
||||||
|
VkResult result=vkQueueSubmit(queue,1,&submit_info,fence);
|
||||||
|
|
||||||
|
if(++current_fence==fence_list.GetCount())
|
||||||
|
current_fence=0;
|
||||||
|
|
||||||
|
//不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
||||||
|
|
||||||
|
return(result==VK_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderTarget::RenderTarget(Device *dev,Framebuffer *_fb,const uint32_t fence_count):SubmitQueue(dev,dev->GetGraphicsQueue(),fence_count)
|
||||||
|
{
|
||||||
|
fb=_fb;
|
||||||
|
}
|
||||||
|
|
||||||
|
SwapchainRenderTarget::SwapchainRenderTarget(Device *dev,Swapchain *sc):RenderTarget(dev,nullptr,sc->GetImageCount())
|
||||||
|
{
|
||||||
|
swapchain=sc;
|
||||||
|
vk_swapchain=swapchain->GetSwapchain();
|
||||||
|
|
||||||
|
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||||
|
present_info.pNext = nullptr;
|
||||||
|
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();
|
||||||
|
|
||||||
|
main_rp=device->CreateRenderPass((*sc_color)->GetFormat(),sc_depth->GetFormat());
|
||||||
|
|
||||||
|
swap_chain_count=swapchain->GetImageCount();
|
||||||
|
|
||||||
|
extent=swapchain->GetExtent();
|
||||||
|
|
||||||
|
for(uint i=0;i<swap_chain_count;i++)
|
||||||
|
{
|
||||||
|
render_frame.Add(vulkan::CreateFramebuffer(device,main_rp,(*sc_color)->GetImageView(),sc_depth->GetImageView()));
|
||||||
|
++sc_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_frame=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SwapchainRenderTarget::~SwapchainRenderTarget()
|
||||||
|
{
|
||||||
|
render_frame.Clear();
|
||||||
|
|
||||||
|
delete main_rp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SwapchainRenderTarget::AcquireNextImage(vulkan::Semaphore *present_complete_semaphore)
|
||||||
|
{
|
||||||
|
VkSemaphore sem=*present_complete_semaphore;
|
||||||
|
|
||||||
|
if(vkAcquireNextImageKHR(device->GetDevice(),vk_swapchain,UINT64_MAX,sem,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||||
|
return current_frame;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwapchainRenderTarget::PresentBackbuffer(vulkan::Semaphore *render_complete_semaphore)
|
||||||
|
{
|
||||||
|
VkSemaphore sem=*render_complete_semaphore;
|
||||||
|
|
||||||
|
present_info.waitSemaphoreCount=1;
|
||||||
|
present_info.pWaitSemaphores=&sem;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result=vkQueueWaitIdle(queue);
|
||||||
|
|
||||||
|
if(result!=VK_SUCCESS)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -8,140 +8,140 @@ Swapchain::Swapchain(Device *dev,SwapchainAttribute *sa)
|
|||||||
device=dev;
|
device=dev;
|
||||||
sc_attr=sa;
|
sc_attr=sa;
|
||||||
|
|
||||||
pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
//pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
//
|
||||||
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
//submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submit_info.pNext = nullptr;
|
//submit_info.pNext = nullptr;
|
||||||
//submit_info.waitSemaphoreCount = 1;
|
////submit_info.waitSemaphoreCount = 1;
|
||||||
//submit_info.pWaitSemaphores = *present_complete_semaphore;
|
////submit_info.pWaitSemaphores = *present_complete_semaphore;
|
||||||
submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
//submit_info.pWaitDstStageMask = &pipe_stage_flags;
|
||||||
//submit_info.signalSemaphoreCount = 1;
|
////submit_info.signalSemaphoreCount = 1;
|
||||||
//submit_info.pSignalSemaphores = *render_complete_semaphore;
|
////submit_info.pSignalSemaphores = *render_complete_semaphore;
|
||||||
|
//
|
||||||
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
//present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||||
present_info.pNext = nullptr;
|
//present_info.pNext = nullptr;
|
||||||
present_info.waitSemaphoreCount = 1;
|
//present_info.waitSemaphoreCount = 1;
|
||||||
//present_info.pWaitSemaphores = *render_complete_semaphore;
|
////present_info.pWaitSemaphores = *render_complete_semaphore;
|
||||||
present_info.swapchainCount = 1;
|
//present_info.swapchainCount = 1;
|
||||||
present_info.pResults = nullptr;
|
//present_info.pResults = nullptr;
|
||||||
|
//
|
||||||
present_info.pSwapchains=&(sc_attr->swap_chain);
|
//present_info.pSwapchains=&(sc_attr->swap_chain);
|
||||||
|
|
||||||
main_rp=device->CreateRenderPass(sc_attr->sc_color[0]->GetFormat(),sc_attr->sc_depth->GetFormat());
|
//main_rp=device->CreateRenderPass(sc_attr->sc_color[0]->GetFormat(),sc_attr->sc_depth->GetFormat());
|
||||||
|
|
||||||
for(uint i=0;i<sc_attr->swap_chain_count;i++)
|
//for(uint i=0;i<sc_attr->swap_chain_count;i++)
|
||||||
{
|
//{
|
||||||
render_frame.Add(vulkan::CreateFramebuffer(device,main_rp,sc_attr->sc_color[i]->GetImageView(),sc_attr->sc_depth->GetImageView()));
|
// render_frame.Add(vulkan::CreateFramebuffer(device,main_rp,sc_attr->sc_color[i]->GetImageView(),sc_attr->sc_depth->GetImageView()));
|
||||||
fence_list.Add(device->CreateFence(true));
|
// fence_list.Add(device->CreateFence(true));
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
current_frame=0;
|
//current_frame=0;
|
||||||
current_fence=0;
|
//current_fence=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Swapchain::~Swapchain()
|
Swapchain::~Swapchain()
|
||||||
{
|
{
|
||||||
fence_list.Clear();
|
//fence_list.Clear();
|
||||||
render_frame.Clear();
|
//render_frame.Clear();
|
||||||
|
|
||||||
delete main_rp;
|
//delete main_rp;
|
||||||
|
|
||||||
SAFE_CLEAR(sc_attr);
|
SAFE_CLEAR(sc_attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Swapchain::Wait(bool wait_all,uint64_t time_out)
|
//bool Swapchain::Wait(bool wait_all,uint64_t time_out)
|
||||||
{
|
//{
|
||||||
VkFence fence=*fence_list[current_fence];
|
// VkFence fence=*fence_list[current_fence];
|
||||||
|
//
|
||||||
VkResult result;
|
// VkResult result;
|
||||||
|
//
|
||||||
result=vkWaitForFences(device->GetDevice(),1,&fence,wait_all,time_out);
|
// result=vkWaitForFences(device->GetDevice(),1,&fence,wait_all,time_out);
|
||||||
result=vkResetFences(device->GetDevice(),1,&fence);
|
// result=vkResetFences(device->GetDevice(),1,&fence);
|
||||||
|
//
|
||||||
return(true);
|
// return(true);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
int Swapchain::AcquireNextImage(vulkan::Semaphore *present_complete_semaphore)
|
//int Swapchain::AcquireNextImage(vulkan::Semaphore *present_complete_semaphore)
|
||||||
{
|
//{
|
||||||
VkSemaphore sem=*present_complete_semaphore;
|
// VkSemaphore sem=*present_complete_semaphore;
|
||||||
|
//
|
||||||
if(vkAcquireNextImageKHR(device->GetDevice(),sc_attr->swap_chain,UINT64_MAX,sem,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
// if(vkAcquireNextImageKHR(device->GetDevice(),sc_attr->swap_chain,UINT64_MAX,sem,VK_NULL_HANDLE,¤t_frame)==VK_SUCCESS)
|
||||||
return current_frame;
|
// return current_frame;
|
||||||
|
//
|
||||||
return -1;
|
// return -1;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
bool Swapchain::SubmitDraw(VkCommandBuffer &cmd_list,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
//bool Swapchain::SubmitDraw(VkCommandBuffer &cmd_list,vulkan::Semaphore *wait_sem,vulkan::Semaphore *complete_sem)
|
||||||
{
|
//{
|
||||||
VkSemaphore ws=*wait_sem;
|
// VkSemaphore ws=*wait_sem;
|
||||||
VkSemaphore cs=*complete_sem;
|
// VkSemaphore cs=*complete_sem;
|
||||||
|
//
|
||||||
submit_info.waitSemaphoreCount =1;
|
// submit_info.waitSemaphoreCount =1;
|
||||||
submit_info.pWaitSemaphores =&ws;
|
// submit_info.pWaitSemaphores =&ws;
|
||||||
submit_info.commandBufferCount =1;
|
// submit_info.commandBufferCount =1;
|
||||||
submit_info.pCommandBuffers =&cmd_list;
|
// submit_info.pCommandBuffers =&cmd_list;
|
||||||
submit_info.signalSemaphoreCount=1;
|
// submit_info.signalSemaphoreCount=1;
|
||||||
submit_info.pSignalSemaphores =&cs;
|
// submit_info.pSignalSemaphores =&cs;
|
||||||
|
//
|
||||||
VkFence fence=*fence_list[current_fence];
|
// VkFence fence=*fence_list[current_fence];
|
||||||
|
//
|
||||||
VkResult result=vkQueueSubmit(sc_attr->graphics_queue,1,&submit_info,fence);
|
// VkResult result=vkQueueSubmit(sc_attr->graphics_queue,1,&submit_info,fence);
|
||||||
|
//
|
||||||
if(++current_fence==sc_attr->swap_chain_count)
|
// if(++current_fence==sc_attr->swap_chain_count)
|
||||||
current_fence=0;
|
// current_fence=0;
|
||||||
|
//
|
||||||
//不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
// //不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
||||||
|
//
|
||||||
return(result==VK_SUCCESS);
|
// return(result==VK_SUCCESS);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
bool Swapchain::SubmitDraw(List<VkCommandBuffer> &cmd_lists,List<VkSemaphore> &wait_sems,List<VkSemaphore> &complete_sems)
|
//bool Swapchain::SubmitDraw(List<VkCommandBuffer> &cmd_lists,List<VkSemaphore> &wait_sems,List<VkSemaphore> &complete_sems)
|
||||||
{
|
//{
|
||||||
if(cmd_lists.GetCount()<=0)
|
// if(cmd_lists.GetCount()<=0)
|
||||||
return(false);
|
// return(false);
|
||||||
|
//
|
||||||
submit_info.waitSemaphoreCount =wait_sems.GetCount();
|
// submit_info.waitSemaphoreCount =wait_sems.GetCount();
|
||||||
submit_info.pWaitSemaphores =wait_sems.GetData();
|
// submit_info.pWaitSemaphores =wait_sems.GetData();
|
||||||
submit_info.commandBufferCount =cmd_lists.GetCount();
|
// submit_info.commandBufferCount =cmd_lists.GetCount();
|
||||||
submit_info.pCommandBuffers =cmd_lists.GetData();
|
// submit_info.pCommandBuffers =cmd_lists.GetData();
|
||||||
submit_info.signalSemaphoreCount=complete_sems.GetCount();
|
// submit_info.signalSemaphoreCount=complete_sems.GetCount();
|
||||||
submit_info.pSignalSemaphores =complete_sems.GetData();
|
// submit_info.pSignalSemaphores =complete_sems.GetData();
|
||||||
|
//
|
||||||
VkFence fence=*fence_list[current_fence];
|
// VkFence fence=*fence_list[current_fence];
|
||||||
|
//
|
||||||
VkResult result=vkQueueSubmit(sc_attr->graphics_queue,1,&submit_info,fence);
|
// VkResult result=vkQueueSubmit(sc_attr->graphics_queue,1,&submit_info,fence);
|
||||||
|
//
|
||||||
if(++current_fence==sc_attr->swap_chain_count)
|
// if(++current_fence==sc_attr->swap_chain_count)
|
||||||
current_fence=0;
|
// current_fence=0;
|
||||||
|
//
|
||||||
//不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
// //不在这里立即等待fence完成,是因为有可能queue submit需要久一点工作时间,我们这个时间可以去干别的。等在AcquireNextImage时再去等待fence,而且是另一帧的fence。这样有利于异步处理
|
||||||
|
//
|
||||||
return(result==VK_SUCCESS);
|
// return(result==VK_SUCCESS);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
bool Swapchain::PresentBackbuffer(vulkan::Semaphore *render_complete_semaphore)
|
//bool Swapchain::PresentBackbuffer(vulkan::Semaphore *render_complete_semaphore)
|
||||||
{
|
//{
|
||||||
VkSemaphore sem=*render_complete_semaphore;
|
// VkSemaphore sem=*render_complete_semaphore;
|
||||||
|
//
|
||||||
present_info.pWaitSemaphores=&sem;
|
// present_info.pWaitSemaphores=&sem;
|
||||||
present_info.pImageIndices=¤t_frame;
|
// present_info.pImageIndices=¤t_frame;
|
||||||
|
//
|
||||||
VkResult result=vkQueuePresentKHR(sc_attr->graphics_queue,&present_info);
|
// VkResult result=vkQueuePresentKHR(sc_attr->graphics_queue,&present_info);
|
||||||
|
//
|
||||||
if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
// if (!((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)))
|
||||||
{
|
// {
|
||||||
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
// if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||||
// Swap chain is no longer compatible with the surface and needs to be recreated
|
// // Swap chain is no longer compatible with the surface and needs to be recreated
|
||||||
|
//
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
result=vkQueueWaitIdle(sc_attr->graphics_queue);
|
// result=vkQueueWaitIdle(sc_attr->graphics_queue);
|
||||||
|
//
|
||||||
if(result!=VK_SUCCESS)
|
// if(result!=VK_SUCCESS)
|
||||||
return(false);
|
// return(false);
|
||||||
|
//
|
||||||
return(true);
|
// return(true);
|
||||||
}
|
//}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user