to improve create program, that are RenderPass and Framebuffer

This commit is contained in:
hyzboy 2020-10-15 22:13:15 +08:00
parent c960731c28
commit 1e0676c6c7
21 changed files with 348 additions and 183 deletions

View File

@ -1,6 +1,3 @@
// 0.triangle
// 该范例主要演示直接绘制一个渐变色的三角形
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>

View File

@ -42,17 +42,11 @@ CreateProject(13.DrawTile DrawTile.cpp)
CreateProject(14.DrawText DrawText.cpp)
IF(SUPPORT_QT_VULKAN)
include(QtCommon)
CreateQtProject(14.VulkanQT VulkanQtApp.cpp
QtVulkanWindow.cpp
QtVulkanWindow.h
QtVulkanMainWindow.h
QtVulkanMainWindow.cpp)
ENDIF(SUPPORT_QT_VULKAN)
CreateProject(15.OffscreenRender OffscreenRender.cpp)
#CreateProject(12.PBRBasic PBRBasic.cpp)
#CreateProject(12.Deferred Deferred.cpp)
#CreateProject(13.DeferredModel DeferredModel.cpp)
CreateProject(16.DeferredModel DeferredModel.cpp)
#CreateProject(14.AutoMaterial auto_material.cpp)

View File

@ -4,8 +4,8 @@
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/SceneDB.h>
#include<hgl/graph/RenderableInstance.h>
#include<hgl/graph/vulkan/VKDatabase.h>
#include<hgl/graph/vulkan/VKRenderableInstance.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/vulkan/VKTexture.h>
#include<hgl/graph/vulkan/VKImageView.h>
@ -70,7 +70,7 @@ private:
struct
{
List<VkAttachmentDescription> desc_list;
List<VkAttachmentReference> color_ref_list;
VkAttachmentReference *color_ref_list;
VkAttachmentReference depth_ref;
}attachment;
@ -187,23 +187,21 @@ private:
gbuffer.image_view_list.Add(gbuffer.texture_list[i]->GetImageView());
}
device->CreateColorAttachmentReference(gbuffer.attachment.color_ref_list,0,3);
device->CreateDepthAttachmentReference(&gbuffer.attachment.depth_ref,3);
gbuffer.attachment.color_ref_list=new VkAttachmentReference[3];
if(!device->CreateAttachment( gbuffer.attachment.desc_list,
vulkan::CreateColorAttachmentReference(gbuffer.attachment.color_ref_list,3);
vulkan::CreateDepthAttachmentReference(&gbuffer.attachment.depth_ref);
if(!vulkan::CreateAttachment( gbuffer.attachment.desc_list,
gbuffer.gbuffer_format_list,
gbuffer.depth->GetFormat()))
return(false);
VkSubpassDescription desc;
device->CreateSubpassDescription(desc,
gbuffer.attachment.color_ref_list,
&gbuffer.attachment.depth_ref);
vulkan::SubpassDescription desc(gbuffer.attachment.color_ref_list,3,&gbuffer.attachment.depth_ref);
gbuffer.subpass.desc.Add(desc);
device->CreateSubpassDependency(gbuffer.subpass.dependency,2); //为啥要2个还不清楚
vulkan::CreateSubpassDependency(gbuffer.subpass.dependency,2); //为啥要2个还不清楚
gbuffer.renderpass=device->CreateRenderPass(gbuffer.attachment.desc_list,
gbuffer.subpass.desc,
@ -214,7 +212,7 @@ private:
if(!gbuffer.renderpass)
return(false);
gbuffer.framebuffer=vulkan::CreateFramebuffer(device,gbuffer.renderpass,gbuffer.image_view_list,gbuffer.depth->GetImageView());
gbuffer.framebuffer=vulkan::CreateFramebuffer(device->GetDevice(),gbuffer.renderpass,gbuffer.image_view_list,gbuffer.depth->GetImageView());
if(!gbuffer.framebuffer)
return(false);
@ -226,15 +224,12 @@ private:
bool InitSubpass(SubpassParam *sp,const OSString &vs,const OSString &fs)
{
sp->material=shader_manage->CreateMaterial(vs,fs);
sp->material=db->CreateMaterial(vs,fs);
if(!sp->material)
return(false);
sp->material_instance=sp->material->CreateInstance();
db->Add(sp->material);
db->Add(sp->material_instance);
sp->material_instance=db->CreateMaterialInstance(sp->material);
return(true);
}

View File

@ -0,0 +1,48 @@
#include<hgl/graph/vulkan/VKRenderTarget.h>
#include"VulkanAppFramework.h"
using namespace hgl;
using namespace hgl::graph;
constexpr uint OFFSCREEN_SIZE =512;
constexpr uint SCREEN_WIDTH =1024;
constexpr uint SCREEN_HEIGHT =(SCREEN_WIDTH/16)*9;
class OffscreenRender:public VulkanApplicationFramework
{
vulkan::RenderTarget *os_rt;
public:
~OffscreenRender()
{
}
bool InitOffscreenRT()
{
os_rt=vulkan::CreateColorFramebuffer(
}
bool Init()
{
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitOffscreenRT())
return(false);
return(true);
}
};//class OffscreenRender:public VulkanApplicationFramework
int main(int,char **)
{
OffscreenRender app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}

View File

@ -55,7 +55,7 @@ public:
DeviceAttribute * GetDeviceAttribute () {return attr;}
VkSurfaceKHR GetSurface () {return attr->surface;}
VkDevice GetDevice () {return attr->device;}
VkDevice GetDevice ()const {return attr->device;}
const PhysicalDevice * GetPhysicalDevice ()const {return attr->physical_device;}
VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;}
@ -122,9 +122,9 @@ public: //Image
public: //Texture
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal);
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal)const;
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal){return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
Texture2D *CreateTexture2D(TextureData *);
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
@ -242,37 +242,18 @@ public: //Command Buffer 相关
CommandBuffer * CreateCommandBuffer(const VkExtent2D &extent,const uint32_t atta_count);
void CreateAttachmentReference(VkAttachmentReference *ref_list,uint start,uint count,VkImageLayout layout)const;
void CreateColorAttachmentReference(List<VkAttachmentReference> &ref_list, uint start,uint count )const{ref_list.SetCount(count); CreateAttachmentReference(ref_list.GetData(), start,count,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);}
void CreateDepthAttachmentReference( VkAttachmentReference *depth_ref, uint index )const{ CreateAttachmentReference(depth_ref, index,1 ,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);}
void CreateInputAttachment( List<VkAttachmentReference> &ref_list, uint start,uint count )const{ref_list.SetCount(count); CreateAttachmentReference(ref_list.GetData(), start,count,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);}
bool CreateAttachment( List<VkAttachmentDescription> &color_output_desc_list,
const List<VkFormat> &color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
bool CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)const;
bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
void CreateSubpassDependency(VkSubpassDependency *);
void CreateSubpassDependency(List<VkSubpassDependency> &dependency,const uint32_t count)const;
void CreateSubpassDescription(VkSubpassDescription &,const List<VkAttachmentReference> &color_ref_list,VkAttachmentReference *depth_ref=nullptr)const;
RenderPass * CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
const List<VkSubpassDescription> &subpass,
const List<VkSubpassDependency> &dependency,
const List<VkFormat> &color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
RenderPass * CreateRenderPass( const VkFormat color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Fence * CreateFence(bool);
vulkan::Semaphore * CreateSem();
@ -283,9 +264,17 @@ public:
RenderTarget *CreateRenderTarget(Framebuffer *);
RenderTarget *CreateRenderTarget(const uint,const uint,const List<VkFormat> &);
RenderTarget *CreateRenderTarget(const uint,const uint,const VkFormat);
RenderTarget *CreateRenderTarget(const uint,const uint,const VkFormat,const VkFormat);
RenderTarget *CreateRenderTarget( const uint,const uint,const List<VkFormat> &,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
RenderTarget *CreateRenderTarget( const uint,const uint,const VkFormat,const VkImageLayout final_layout);
RenderTarget *CreateRenderTarget( const uint,const uint,
const VkFormat color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Pipeline *CreatePipeline(PipelineData *,const Material *,const RenderTarget *);
@ -294,6 +283,25 @@ public:
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class Device
void CreateSubpassDependency(VkSubpassDependency *);
void CreateSubpassDependency(List<VkSubpassDependency> &dependency,const uint32_t count);
void CreateAttachmentReference(VkAttachmentReference *ref_list,uint count,VkImageLayout layout);
inline void CreateColorAttachmentReference(VkAttachmentReference *ref_list,uint count ){CreateAttachmentReference(ref_list, count,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);}
inline void CreateDepthAttachmentReference(VkAttachmentReference *depth_ref) {CreateAttachmentReference(depth_ref, 1 ,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);}
inline void CreateInputAttachmentReference(VkAttachmentReference *ref_list,uint count ){CreateAttachmentReference(ref_list, count,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);}
bool CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
bool CreateAttachment( List<VkAttachmentDescription> &color_output_desc_list,
const List<VkFormat> &color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Device *CreateRenderDevice(Instance *inst,Window *win,const PhysicalDevice *physical_device=nullptr);
VK_NAMESPACE_END
#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE

View File

@ -13,25 +13,14 @@ class Framebuffer
uint32_t color_count;
bool has_depth;
ObjectList<Texture2D> color_texture;
Texture2D *depth_texture;
private:
friend Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
friend Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
Framebuffer(VkDevice dev,VkFramebuffer fb,VkFramebufferCreateInfo *fb_create_info,bool depth)
{
device=dev;
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;
}
Framebuffer(VkDevice dev,VkFramebuffer fb,VkFramebufferCreateInfo *fb_create_info,bool depth);
public:
@ -45,11 +34,13 @@ public:
const uint32_t GetAttachmentCount ()const{return fb_info->attachmentCount;} ///<获取渲染目标成分数量
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
Texture2D * GetColorTexture (const int index=0){return color_texture[index];}
Texture2D * GetDepthTexture (){return depth_texture;}
};//class Framebuffer
Framebuffer *CreateFramebuffer(Device *,RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFramebuffer(Device *,RenderPass *,List<ImageView *> &image_view_list);
Framebuffer *CreateColorFramebuffer(Device *,RenderPass *,ImageView *color,ImageView *depth=nullptr);
Framebuffer *CreateDepthFramebuffer(Device *,RenderPass *,ImageView *depth);
Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,ImageView *);
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE

View File

@ -44,6 +44,12 @@ public:
const uint GetColorCount()const{return color_formats.GetCount();}
const List<VkFormat> & GetColorFormat()const{return color_formats;}
const VkFormat GetColorFormat(int index)const
{
if(index<0||index>=color_formats.GetCount())return VK_FORMAT_UNDEFINED;
return color_formats.GetData()[index];
}
const VkFormat GetDepthFormat()const{return depth_format;}
};//class RenderPass
VK_NAMESPACE_END

View File

@ -50,7 +50,7 @@ protected:
public:
virtual ~RenderTarget()=default;
virtual ~RenderTarget();
const VkExtent2D & GetExtent ()const {return extent;}
CommandBuffer * GetCommandBuffer() {return command_buffer;}

31
inc/hgl/gui/Form.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef HGL_GUI_FORM_INCLUDE
#define HGL_GUI_FORM_INCLUDE
#include<hgl/graph/vulkan/VKPipeline.h>
namespace hgl
{
namespace gui
{
using namespace hgl::graph;
/**
* GUI控件的基本装置
*/
class Form
{
protected: //每个窗体独立一个FBO存在所以每个窗体会有自己的RenderTarget与pipeline
vulkan::Buffer *ui_matrix;
struct
{
vulkan::Pipeline *solid;
vulkan::Pipeline *mask;
vulkan::Pipeline *alpha;
}pipeline;
public:
};//class Form
}//namespace gui
}//namespace hgl
#endif//HGL_GUI_FORM_INCLUDE

View File

@ -1,6 +1,7 @@
file(GLOB GUI_HEADER ${ROOT_INCLUDE_PATH}/hgl/gui/*.*)
set(GUI_SOURCE Widget.cpp
Form.cpp
Panel.cpp
ThemeEngine.cpp
DefaultThemeEngine.h

View File

@ -6,7 +6,19 @@ namespace hgl
{
ThemeEngine *CreateDefaultThemeEngine()
{
return(new DefaultThemeEngine);
}
bool DefaultThemeEngine::Init()
{
}
void DefaultThemeEngine::Clear()
{
}
void DefaultThemeEngine::DrawFrame(const Widget *w)
{
}
}//namespace gui
}//namespace hgl

View File

@ -1,23 +1,32 @@
#pragma once
#include<hgl/gui/ThemeEngine.h>
#include<hgl/graph/vulkan/VKMaterialInstance.h>
namespace hgl
{
namespace gui
{
using namespace hgl::graph;
/**
* GUI主题引擎
*/
class DefaultThemeEngine:public ThemeEngine
{
struct
{
vulkan::Material * m;
vulkan::MaterialInstance * mi;
}panel;
public:
bool Init() override;
void Clear() override;
void DrawFrame(const RectScope2f &) override;
void DrawFrame(const Widget *) override;
};//class DefaultThemeEngine:public ThemeEngine
}//namespace gui
}//namespace hgl

0
src/GUI/Form.cpp Normal file
View File

View File

@ -26,7 +26,8 @@ SET(VK_DEVICE_SOURCE ${RD_INCLUDE_PATH}/VKDevice.h
VKDeviceImage.cpp
VKDeviceTexture.cpp
VKDeviceSwapchain.cpp
VKDeviceRenderPass.cpp)
VKDeviceRenderPass.cpp
VKDeviceRenderTarget.cpp)
SET(VK_PHYSICAL_DEVICE_SOURCE ${RD_INCLUDE_PATH}/VKPhysicalDevice.h
VKPhysicalDevice.cpp

View File

@ -103,16 +103,4 @@ vulkan::Semaphore *Device::CreateSem()
return(new vulkan::Semaphore(attr->device,sem));
}
RenderTarget *Device::CreateRenderTarget(Framebuffer *fb)
{
return(new RenderTarget(this,fb));
}
Pipeline *CreatePipeline(VkDevice device,VkPipelineCache pipeline_cache,PipelineData *data,const Material *material,const RenderTarget *rt);
Pipeline *Device::CreatePipeline(PipelineData *pd,const Material *mtl,const RenderTarget *rt)
{
return VK_NAMESPACE::CreatePipeline(attr->device,attr->pipeline_cache,pd,mtl,rt);
}
VK_NAMESPACE_END

View File

@ -3,7 +3,7 @@
#include<hgl/graph/vulkan/VKRenderPass.h>
VK_NAMESPACE_BEGIN
void Device::CreateSubpassDependency(VkSubpassDependency *dependency)
void CreateSubpassDependency(VkSubpassDependency *dependency)
{
dependency->srcSubpass = VK_SUBPASS_EXTERNAL;
dependency->dstSubpass = 0;
@ -14,7 +14,7 @@ void Device::CreateSubpassDependency(VkSubpassDependency *dependency)
dependency->dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
}
void Device::CreateSubpassDependency(List<VkSubpassDependency> &subpass_dependency_list,const uint32_t count) const
void CreateSubpassDependency(List<VkSubpassDependency> &subpass_dependency_list,const uint32_t count)
{
if(count<=0)return;
@ -67,11 +67,11 @@ void Device::CreateSubpassDependency(List<VkSubpassDependency> &subpass_dependen
}
}
void Device::CreateAttachmentReference(VkAttachmentReference *ref_list,uint start,uint count,VkImageLayout layout) const
void CreateAttachmentReference(VkAttachmentReference *ref_list,uint count,VkImageLayout layout)
{
VkAttachmentReference *ref=ref_list;
for(uint i=start;i<start+count;i++)
for(uint i=0;i<count;i++)
{
ref->attachment =i;
ref->layout =layout;
@ -80,7 +80,7 @@ void Device::CreateAttachmentReference(VkAttachmentReference *ref_list,uint star
}
}
bool Device::CreateAttachment(List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout) const
bool CreateAttachment(List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout)
{
const uint color_count=color_format.GetCount();
@ -118,17 +118,17 @@ bool Device::CreateAttachment(List<VkAttachmentDescription> &desc_list,const Lis
return(true);
}
bool Device::CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkImageLayout color_final_layout) const
bool CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkImageLayout color_final_layout)
{
const VkFormat *cf=color_format.GetData();
//const VkFormat *cf=color_format_list.GetData();
for(int i=0;i<color_format.GetCount();i++)
{
if(!attr->physical_device->IsColorAttachmentOptimal(*cf))
return(false);
//for(int i=0;i<color_format_list.GetCount();i++)
//{
// if(!attr->physical_device->IsColorAttachmentOptimal(*cf))
// return(false);
++cf;
}
// ++cf;
//}
ref_list.SetCount(color_format.GetCount());
VkAttachmentReference *ref=ref_list.GetData();
@ -156,10 +156,10 @@ bool Device::CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<V
return(true);
}
bool Device::CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout) const
bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout)
{
if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format))
return(false);
//if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format))
// return(false);
{
ref_list.SetCount(1);
@ -186,42 +186,19 @@ bool Device::CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<V
return(true);
}
void Device::CreateSubpassDescription(VkSubpassDescription &sd,const List<VkAttachmentReference> &color_ref_list,VkAttachmentReference *depth_ref) const
{
sd.flags =0;
sd.pipelineBindPoint =VK_PIPELINE_BIND_POINT_GRAPHICS;
sd.inputAttachmentCount =0;
sd.pInputAttachments =nullptr;
sd.pColorAttachments =color_ref_list.GetData();
sd.colorAttachmentCount =color_ref_list.GetCount();
sd.pDepthStencilAttachment =depth_ref;
sd.pResolveAttachments =nullptr;
sd.preserveAttachmentCount =0;
sd.pPreserveAttachments =nullptr;
}
RenderPass *Device::CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
const List<VkSubpassDescription> &subpass,
const List<VkSubpassDependency> &dependency,
const List<VkFormat> &color_format,
const List<VkFormat> &color_format_list,
const VkFormat depth_format,
const VkImageLayout color_final_layout,
const VkImageLayout depth_final_layout) const
const VkImageLayout depth_final_layout)
{
for(const VkFormat cf:color_format_list)
{
const VkFormat *cf=color_format.GetData();
for(int i=0;i<color_format.GetCount();i++)
{
if(!attr->physical_device->IsColorAttachmentOptimal(*cf)
&&!attr->physical_device->IsColorAttachmentLinear(*cf))
if(!attr->physical_device->IsColorAttachmentOptimal(cf)
&&!attr->physical_device->IsColorAttachmentLinear(cf))
return(nullptr);
++cf;
}
}
if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format)
@ -244,10 +221,10 @@ RenderPass *Device::CreateRenderPass( const List<VkAttachmentDescription> &des
if(vkCreateRenderPass(attr->device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
return(nullptr);
return(new RenderPass(attr->device,render_pass,color_format,depth_format));
return(new RenderPass(attr->device,render_pass,color_format_list,depth_format));
}
RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout) const
RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout)
{
if(!attr->physical_device->IsColorAttachmentOptimal(color_format))
return(nullptr);
@ -255,7 +232,7 @@ RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format
if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format))
return(nullptr);
List<VkAttachmentReference> color_ref;
VkAttachmentReference color_ref;
VkAttachmentReference depth_ref;
List<VkAttachmentDescription> desc_list;
@ -263,27 +240,14 @@ RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format
color_format_list.Add(color_format);
CreateColorAttachmentReference(color_ref,0,1);
CreateDepthAttachmentReference(&depth_ref,1);
CreateColorAttachmentReference(&color_ref,1);
CreateDepthAttachmentReference(&depth_ref);
CreateAttachment(desc_list,color_format_list,depth_format,color_final_layout,depth_final_layout);
List<VkSubpassDescription> subpass_desc_list;
VkSubpassDescription subpass;
subpass.flags = 0;
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.inputAttachmentCount = 0;
subpass.pInputAttachments = nullptr;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = color_ref.GetData();
subpass.pResolveAttachments = nullptr;
subpass.pDepthStencilAttachment = &depth_ref;
subpass.preserveAttachmentCount = 0;
subpass.pPreserveAttachments = nullptr;
subpass_desc_list.Add(subpass);
subpass_desc_list.Add(SubpassDescription(&color_ref,&depth_ref));
List<VkSubpassDependency> subpass_dependency_list;

View File

@ -0,0 +1,92 @@
#include<hgl/graph/vulkan/VKDevice.h>
VK_NAMESPACE_BEGIN
RenderTarget *Device::CreateRenderTarget(Framebuffer *fb)
{
CommandBuffer *cb=CreateCommandBuffer(fb->GetExtent(),fb->GetAttachmentCount());
return(new RenderTarget(this,fb,cb));
}
RenderTarget *Device::CreateRenderTarget( const uint w,const uint h,
const VkFormat color_format,
const VkFormat depth_format,
const VkImageLayout color_layout,
const VkImageLayout depth_layout)
{
if(w<=0||h<=0)return(nullptr);
if(IsDepthStencilFormat(color_format))return(nullptr);
if(!IsDepthFormat(depth_format))return(nullptr);
if(!CheckTextureFormatSupport(color_format))return(nullptr);
if(!CheckTextureFormatSupport(depth_format))return(nullptr);
Texture2D *color_texture=CreateAttachmentTextureColor(color_format,w,h);
Texture2D *depth_texture=CreateAttachmentTextureDepth(depth_format,w,h);
RenderPass *rp=CreateRenderPass(color_format,depth_format,color_layout,depth_layout);
Framebuffer *fb=CreateFramebuffer(GetDevice(),rp,color_texture->GetImageView(),depth_texture->GetImageView());
return(CreateRenderTarget(fb));
}
//RenderTarget *Device::CreateRenderTarget(const uint w,const uint h,const List<VkFormat> &fmt_list)
//{
// if(w<=0||h<=0||fmt_list.GetCount()<=0)return(nullptr);
//
// uint color_count=0;
// uint depth_count=0; //只能有一个
// uint stencil_count=0;
//
// for(VkFormat fmt:fmt_list)
// {
// if(IsDepthFormat(fmt))++depth_count;
// else
// if(IsStencilFormat(fmt))++stencil_count;
// else
// ++color_count;
//
// if(CheckTextureFormatSupport(fmt))
// return(nullptr);
// }
//
// if(depth_count>1)return(nullptr);
// if(stencil_count>1)return(nullptr);
//
// List<VkFormat> color_format_list;
// VkFormat depth_format;
// List<VkAttachmentDescription> desc_list;
// List<VkAttachmentReference> color_ref_list;
// VkAttachmentReference depth_ref;
// List<vulkan::ImageView *> image_view_list;
//
// for(VkFormat fmt:fmt_list)
// {
// Texture2D *tex=nullptr;
//
// if(IsDepthFormat(fmt))
// {
// tex=CreateAttachmentTextureDepth(fmt,w,h);
//
// depth_format=fmt;
// }
// else
// {
// tex=CreateAttachmentTextureColor(fmt,w,h);
//
// image_view_list.Add(tex->GetImageView());
// color_format_list.Add(fmt);
// }
// }
//
// if(depth_count>0)CreateDepthAttachmentReference(&depth_ref,color_count);
// if(color_count>0)CreateColorAttachmentReference(color_ref_list,0,color_count);
//
// CreateAttachment(desc_list,color_format_list,depth_format,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
//
// VkSubpassDescription sd;
//
// CreateSubpassDescription(sd,color_ref_list,&depth_ref);
//}
VK_NAMESPACE_END

View File

@ -21,7 +21,7 @@ namespace
}
}//namespace
bool Device::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling)
bool Device::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const
{
const VkFormatProperties fp=attr->physical_device->GetFormatProperties(format);

View File

@ -2,15 +2,38 @@
#include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKImageView.h>
#include<hgl/graph/vulkan/VKRenderPass.h>
#include<hgl/graph/vulkan/VKTexture.h>
#include<hgl/type/Smart.h>
VK_NAMESPACE_BEGIN
Framebuffer::Framebuffer(VkDevice dev,VkFramebuffer fb,VkFramebufferCreateInfo *fb_create_info,bool depth)
{
device=dev;
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;
depth_texture=nullptr;
}
Framebuffer::~Framebuffer()
{
SAFE_CLEAR(depth_texture);
color_texture.Clear();
vkDestroyFramebuffer(device,frame_buffer,nullptr);
}
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
{
uint att_count=color_count;
@ -60,13 +83,13 @@ Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list
VkFramebuffer fb;
if(vkCreateFramebuffer(dev->GetDevice(),fb_info,nullptr,&fb)!=VK_SUCCESS)
if(vkCreateFramebuffer(dev,fb_info,nullptr,&fb)!=VK_SUCCESS)
return(nullptr);
return(new Framebuffer(dev->GetDevice(),fb,fb_info,depth));
return(new Framebuffer(dev,fb,fb_info,depth));
}
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> &color,ImageView *depth)
Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,List<ImageView *> &color,ImageView *depth)
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
@ -78,19 +101,7 @@ Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> &col
return CreateFramebuffer(dev,rp,color.GetData(),color.GetCount(),depth);
}
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> &image_view_list)
{
const int count=image_view_list.GetCount();
ImageView *last_iv=*(image_view_list.GetData()+count-1);
if(last_iv->GetAspectFlags()&VK_IMAGE_ASPECT_DEPTH_BIT)
return CreateFramebuffer(dev,rp,image_view_list.GetData(),count-1,last_iv);
else
return CreateFramebuffer(dev,rp,image_view_list.GetData(),count,nullptr);
}
Framebuffer *CreateColorFramebuffer(Device *dev,RenderPass *rp,ImageView *color,ImageView *depth)
Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView *color,ImageView *depth)
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
@ -99,12 +110,18 @@ Framebuffer *CreateColorFramebuffer(Device *dev,RenderPass *rp,ImageView *color,
return CreateFramebuffer(dev,rp,&color,1,depth);
}
Framebuffer *CreateDepthFramebuffer(Device *dev,RenderPass *rp,ImageView *depth)
Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView *iv)
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
if(!depth)return(nullptr);
if(!iv)return(nullptr);
return CreateFramebuffer(dev,rp,nullptr,0,depth);
if(iv->hasColor())
return CreateFramebuffer(dev,rp,&iv,1,nullptr);
else
if(iv->hasDepth())
return CreateFramebuffer(dev,rp,nullptr,0,iv);
else
return nullptr;
}
VK_NAMESPACE_END

View File

@ -39,4 +39,9 @@ Pipeline *CreatePipeline(VkDevice device,VkPipelineCache pipeline_cache,Pipeline
return(new Pipeline(device,graphicsPipeline,data));
}
Pipeline *Device::CreatePipeline(PipelineData *pd,const Material *mtl,const RenderTarget *rt)
{
return VK_NAMESPACE::CreatePipeline(attr->device,attr->pipeline_cache,pd,mtl,rt);
}
VK_NAMESPACE_END

View File

@ -2,6 +2,7 @@
#include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKSwapchain.h>
#include<hgl/graph/vulkan/VKSemaphore.h>
#include<hgl/graph/vulkan/VKCommandBuffer.h>
VK_NAMESPACE_BEGIN
namespace
@ -96,7 +97,12 @@ RenderTarget::RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,const
command_buffer=_cb;
}
SwapchainRenderTarget::SwapchainRenderTarget(Device *dev,Swapchain *sc):RenderTarget(dev,nullptr,sc->GetImageCount())
RenderTarget::~RenderTarget()
{
SAFE_CLEAR(command_buffer);
}
SwapchainRenderTarget::SwapchainRenderTarget(Device *dev,Swapchain *sc):RenderTarget(dev,nullptr,nullptr,sc->GetImageCount())
{
swapchain=sc;
vk_swapchain=swapchain->GetSwapchain();
@ -118,7 +124,7 @@ SwapchainRenderTarget::SwapchainRenderTarget(Device *dev,Swapchain *sc):RenderTa
for(uint i=0;i<swap_chain_count;i++)
{
render_frame.Add(vulkan::CreateColorFramebuffer(device,main_rp,(*sc_color)->GetImageView(),sc_depth->GetImageView()));
render_frame.Add(vulkan::CreateFramebuffer(device->GetDevice(),main_rp,(*sc_color)->GetImageView(),sc_depth->GetImageView()));
++sc_color;
}