2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2020-10-15 22:13:15 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2020-10-21 12:39:22 +08:00
|
|
|
|
RenderTarget *GPUDevice::CreateRenderTarget(Framebuffer *fb,const uint32_t fence_count)
|
2020-10-15 22:13:15 +08:00
|
|
|
|
{
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUCmdBuffer *cb=CreateCommandBuffer(fb->GetExtent(),fb->GetAttachmentCount());
|
2020-10-15 22:13:15 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
return(new RenderTarget(this,fb,cb,fence_count));
|
2020-10-15 22:13:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 18:57:02 +08:00
|
|
|
|
RenderTarget *GPUDevice::CreateRenderTarget(const uint w,const uint h,
|
2020-10-16 19:44:00 +08:00
|
|
|
|
const List<VkFormat> &color_format_list,
|
2020-10-15 22:13:15 +08:00
|
|
|
|
const VkFormat depth_format,
|
|
|
|
|
const VkImageLayout color_layout,
|
2020-10-17 14:20:49 +08:00
|
|
|
|
const VkImageLayout depth_layout,
|
|
|
|
|
const uint32_t fence_count)
|
2020-10-15 22:13:15 +08:00
|
|
|
|
{
|
|
|
|
|
if(w<=0||h<=0)return(nullptr);
|
2020-10-16 19:26:28 +08:00
|
|
|
|
|
2020-10-16 19:44:00 +08:00
|
|
|
|
RenderPass *rp=CreateRenderPass(color_format_list,depth_format,color_layout,depth_layout); //Renderpass内部会验证格式,所以不需要自己处理
|
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
if(!rp)return(nullptr);
|
|
|
|
|
|
|
|
|
|
const uint32_t color_count=color_format_list.GetCount();
|
|
|
|
|
|
2020-10-24 19:11:03 +08:00
|
|
|
|
const VkExtent3D extent={w,h,1};
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
for(const VkFormat &fmt:color_format_list)
|
|
|
|
|
{
|
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)
|
|
|
|
|
{
|
|
|
|
|
delete rp;
|
|
|
|
|
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
|
|
|
|
|
2020-10-24 19:11:03 +08:00
|
|
|
|
Texture2D *depth_texture=(depth_format!=FMT_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
|
|
|
|
{
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUCmdBuffer *cb=CreateCommandBuffer(fb->GetExtent(),fb->GetAttachmentCount());
|
2020-10-17 14:20:49 +08:00
|
|
|
|
|
|
|
|
|
if(cb)
|
|
|
|
|
{
|
2020-10-18 18:01:55 +08:00
|
|
|
|
RenderTarget *rt=new RenderTarget(this,rp,fb,cb,color_texture_list,color_count,depth_texture,fence_count);
|
2020-10-17 14:20:49 +08:00
|
|
|
|
|
2020-10-17 16:26:53 +08:00
|
|
|
|
color_texture_list.DiscardObject();
|
|
|
|
|
return rt;
|
2020-10-17 14:20:49 +08:00
|
|
|
|
}
|
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);
|
|
|
|
|
delete rp;
|
|
|
|
|
return nullptr;
|
2020-10-15 22:13:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 18:57:02 +08:00
|
|
|
|
RenderTarget *GPUDevice::CreateRenderTarget(const uint w,const uint h,
|
2020-10-16 19:44:00 +08:00
|
|
|
|
const VkFormat color_format,
|
|
|
|
|
const VkFormat depth_format,
|
|
|
|
|
const VkImageLayout color_layout,
|
2020-10-17 14:20:49 +08:00
|
|
|
|
const VkImageLayout depth_layout,
|
|
|
|
|
const uint32_t fence_count)
|
2020-10-16 19:44:00 +08:00
|
|
|
|
{
|
|
|
|
|
if(w<=0||h<=0)return(nullptr);
|
|
|
|
|
|
|
|
|
|
List<VkFormat> color_format_list;
|
|
|
|
|
|
|
|
|
|
color_format_list.Add(color_format);
|
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
return CreateRenderTarget(w,h,color_format_list,depth_format,color_layout,depth_layout,fence_count);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
RenderTarget *GPUDevice::CreateRenderTarget(const uint w,const uint h,const VkFormat format,const VkImageLayout final_layout,const uint32_t fence_count)
|
2020-10-17 14:20:49 +08:00
|
|
|
|
{
|
|
|
|
|
if(w<=0||h<=0)return(nullptr);
|
|
|
|
|
|
|
|
|
|
if(format==FMT_UNDEFINED)return(nullptr);
|
|
|
|
|
|
|
|
|
|
List<VkFormat> color_format_list;
|
|
|
|
|
|
|
|
|
|
if(IsDepthFormat(format))
|
|
|
|
|
{
|
|
|
|
|
return CreateRenderTarget(w,h,color_format_list,format,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,final_layout,fence_count);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
color_format_list.Add(format);
|
|
|
|
|
|
|
|
|
|
return CreateRenderTarget(w,h,color_format_list,FMT_UNDEFINED,final_layout,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,fence_count);
|
|
|
|
|
}
|
2020-10-16 19:44:00 +08:00
|
|
|
|
}
|
2020-10-15 22:13:15 +08:00
|
|
|
|
VK_NAMESPACE_END
|