2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2020-10-15 22:13:15 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2021-09-22 15:32:20 +08:00
|
|
|
|
RenderTarget *GPUDevice::CreateRenderTarget(const FramebufferInfo *fbi,RenderPass *rp,const uint32_t fence_count)
|
2020-10-15 22:13:15 +08:00
|
|
|
|
{
|
2020-10-27 22:43:24 +08:00
|
|
|
|
if(!fbi)return(nullptr);
|
2020-10-17 14:20:49 +08:00
|
|
|
|
if(!rp)return(nullptr);
|
|
|
|
|
|
2020-10-27 22:43:24 +08:00
|
|
|
|
const uint32_t color_count=fbi->GetColorCount();
|
|
|
|
|
const VkExtent2D extent=fbi->GetExtent();
|
|
|
|
|
const VkFormat depth_format=fbi->GetDepthFormat();
|
2020-10-24 19:11:03 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
AutoDeleteObjectArray<Texture2D> color_texture_list(color_count);
|
2020-10-24 19:11:03 +08:00
|
|
|
|
AutoDeleteArray<ImageView *> color_iv_list(color_count); //iv只是从Texture2D中取出来的,无需一个个delete
|
2020-10-17 14:20:49 +08:00
|
|
|
|
|
|
|
|
|
Texture2D **tp=color_texture_list;
|
|
|
|
|
ImageView **iv=color_iv_list;
|
2020-10-16 19:44:00 +08:00
|
|
|
|
|
2020-10-27 22:43:24 +08:00
|
|
|
|
for(const VkFormat &fmt:fbi->GetColorFormatList())
|
2020-10-16 19:44:00 +08:00
|
|
|
|
{
|
2020-10-24 19:11:03 +08:00
|
|
|
|
Texture2D *color_texture=CreateTexture2D(new ColorAttachmentTextureCreateInfo(fmt,extent));
|
2020-10-16 19:44:00 +08:00
|
|
|
|
|
|
|
|
|
if(!color_texture)
|
|
|
|
|
return(nullptr);
|
2020-10-15 22:13:15 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
*tp++=color_texture;
|
|
|
|
|
*iv++=color_texture->GetImageView();
|
2020-10-16 19:44:00 +08:00
|
|
|
|
}
|
2020-10-15 22:13:15 +08:00
|
|
|
|
|
2021-06-24 19:25:43 +08:00
|
|
|
|
Texture2D *depth_texture=(depth_format!=PF_UNDEFINED)?CreateTexture2D(new DepthAttachmentTextureCreateInfo(depth_format,extent)):nullptr;
|
2020-10-15 22:13:15 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
Framebuffer *fb=CreateFramebuffer(rp,color_iv_list,color_count,depth_texture?depth_texture->GetImageView():nullptr);
|
2020-10-16 19:44:00 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
if(fb)
|
2020-10-16 19:44:00 +08:00
|
|
|
|
{
|
2021-12-15 19:57:35 +08:00
|
|
|
|
GPUQueue *q=CreateQueue(fence_count,false);
|
|
|
|
|
GPUSemaphore *render_complete_semaphore=CreateGPUSemaphore();
|
|
|
|
|
|
|
|
|
|
RenderTarget *rt=new RenderTarget(q,render_complete_semaphore,rp,fb,color_texture_list,color_count,depth_texture);
|
2020-10-17 14:20:49 +08:00
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
color_texture_list.DiscardObject();
|
|
|
|
|
return rt;
|
2020-10-16 19:44:00 +08:00
|
|
|
|
}
|
2020-10-15 22:13:15 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
SAFE_CLEAR(depth_texture);
|
|
|
|
|
return nullptr;
|
2020-10-15 22:13:15 +08:00
|
|
|
|
}
|
2021-09-22 15:32:20 +08:00
|
|
|
|
|
|
|
|
|
RenderTarget *GPUDevice::CreateRenderTarget(const FramebufferInfo *fbi,const uint32_t fence_count)
|
|
|
|
|
{
|
|
|
|
|
if(!fbi)return(nullptr);
|
|
|
|
|
|
2021-09-22 16:28:39 +08:00
|
|
|
|
RenderPass *rp=AcquireRenderPass(fbi);
|
2021-09-22 15:32:20 +08:00
|
|
|
|
|
|
|
|
|
if(!rp)return(nullptr);
|
|
|
|
|
|
|
|
|
|
return CreateRenderTarget(fbi,rp,fence_count);
|
|
|
|
|
}
|
2021-12-15 19:57:35 +08:00
|
|
|
|
|
2021-12-15 19:59:28 +08:00
|
|
|
|
SwapchainRenderTarget *GPUDevice::CreateSwapchainRenderTarget()
|
2021-12-15 19:57:35 +08:00
|
|
|
|
{
|
|
|
|
|
const uint32_t count=swapchain->GetImageCount();
|
|
|
|
|
|
|
|
|
|
GPUQueue *q=CreateQueue(count,false);
|
|
|
|
|
GPUSemaphore *render_complete_semaphore=CreateGPUSemaphore();
|
|
|
|
|
GPUSemaphore *present_complete_semaphore=CreateGPUSemaphore();
|
|
|
|
|
|
|
|
|
|
Texture2D **sc_color=swapchain->GetColorTextures();
|
|
|
|
|
Texture2D *sc_depth=swapchain->GetDepthTexture();
|
|
|
|
|
|
|
|
|
|
Framebuffer **render_frame=new Framebuffer *[count];
|
|
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<count;i++)
|
|
|
|
|
{
|
|
|
|
|
render_frame[i]=CreateFramebuffer(device_render_pass,(*sc_color)->GetImageView(),sc_depth->GetImageView());
|
|
|
|
|
++sc_color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SwapchainRenderTarget *srt=new SwapchainRenderTarget( attr->device,
|
|
|
|
|
swapchain,
|
|
|
|
|
q,
|
|
|
|
|
render_complete_semaphore,
|
|
|
|
|
present_complete_semaphore,
|
|
|
|
|
device_render_pass,
|
|
|
|
|
render_frame
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return srt;
|
|
|
|
|
}
|
2020-10-15 22:13:15 +08:00
|
|
|
|
VK_NAMESPACE_END
|