Split vulkan::Device::CreateAttachmentDescription to a new function.
This commit is contained in:
parent
9d92ebb8da
commit
b9249d960c
@ -70,7 +70,8 @@ private:
|
||||
struct
|
||||
{
|
||||
List<VkAttachmentDescription> desc_list;
|
||||
List<VkAttachmentReference> ref_list;
|
||||
List<VkAttachmentReference> color_ref_list;
|
||||
VkAttachmentReference depth_ref;
|
||||
}attachment;
|
||||
|
||||
struct
|
||||
@ -186,15 +187,19 @@ private:
|
||||
gbuffer.image_view_list.Add(gbuffer.texture_list[i]->GetImageView());
|
||||
}
|
||||
|
||||
if(!device->CreateAttachment( gbuffer.attachment.ref_list,
|
||||
gbuffer.attachment.desc_list,
|
||||
device->CreateColorAttachmentReference(gbuffer.attachment.color_ref_list,0,3);
|
||||
device->CreateDepthAttachmentReference(&gbuffer.attachment.depth_ref,3);
|
||||
|
||||
if(!device->CreateAttachment( gbuffer.attachment.desc_list,
|
||||
gbuffer.gbuffer_format_list,
|
||||
gbuffer.depth->GetFormat()))
|
||||
return(false);
|
||||
|
||||
VkSubpassDescription desc;
|
||||
|
||||
device->CreateSubpassDescription(desc,gbuffer.attachment.ref_list);
|
||||
device->CreateSubpassDescription(desc,
|
||||
gbuffer.attachment.color_ref_list,
|
||||
&gbuffer.attachment.depth_ref);
|
||||
|
||||
gbuffer.subpass.desc.Add(desc);
|
||||
|
||||
|
@ -176,8 +176,13 @@ public: //Command Buffer 相关
|
||||
|
||||
CommandBuffer * CreateCommandBuffer(const VkExtent2D &extent,const uint32_t atta_count);
|
||||
|
||||
bool CreateAttachment( List<VkAttachmentReference> &ref_list,
|
||||
List<VkAttachmentDescription> &desc_list,
|
||||
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,
|
||||
@ -186,8 +191,9 @@ public: //Command Buffer 相关
|
||||
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> &)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,
|
||||
|
9
res/shader/VertexNormal.frag
Normal file
9
res/shader/VertexNormal.frag
Normal file
@ -0,0 +1,9 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec4 FragmentNormal;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor=FragmentNormal;
|
||||
}
|
@ -3,6 +3,17 @@
|
||||
#include<hgl/graph/vulkan/VKRenderPass.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
void Device::CreateSubpassDependency(VkSubpassDependency *dependency)
|
||||
{
|
||||
dependency->srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||
dependency->dstSubpass = 0;
|
||||
dependency->srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
dependency->srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
dependency->dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||
dependency->dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
dependency->dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
}
|
||||
|
||||
void Device::CreateSubpassDependency(List<VkSubpassDependency> &subpass_dependency_list,const uint32_t count) const
|
||||
{
|
||||
if(count<=0)return;
|
||||
@ -56,45 +67,54 @@ void Device::CreateSubpassDependency(List<VkSubpassDependency> &subpass_dependen
|
||||
}
|
||||
}
|
||||
|
||||
bool Device::CreateAttachment(List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout) const
|
||||
void Device::CreateAttachmentReference(VkAttachmentReference *ref_list,uint start,uint count,VkImageLayout layout) const
|
||||
{
|
||||
uint atta_count=color_format.GetCount();
|
||||
VkAttachmentReference *ref=ref_list;
|
||||
|
||||
desc_list.SetCount(atta_count+1);
|
||||
for(uint i=start;i<start+count;i++)
|
||||
{
|
||||
ref->attachment =i;
|
||||
ref->layout =layout;
|
||||
|
||||
++ref;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
const uint color_count=color_format.GetCount();
|
||||
|
||||
desc_list.SetCount(color_count+1);
|
||||
VkAttachmentDescription *desc=desc_list.GetData();
|
||||
|
||||
ref_list.SetCount(atta_count+1);
|
||||
VkAttachmentReference *ref=ref_list.GetData();
|
||||
|
||||
for(uint i=0;i<atta_count+1;i++)
|
||||
for(uint i=0;i<color_count+1;i++)
|
||||
{
|
||||
desc[i].flags = 0;
|
||||
desc[i].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
desc[i].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; //LOAD_OP_CLEAR代表LOAD时清空内容
|
||||
desc[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE; //STORE_OP_STROE代表SOTRE时储存内容
|
||||
desc[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; //DONT CARE表示不在意
|
||||
desc[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
desc[i].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //代表不关心初始布局
|
||||
desc->flags = 0;
|
||||
desc->samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
desc->loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; //LOAD_OP_CLEAR代表LOAD时清空内容
|
||||
desc->storeOp = VK_ATTACHMENT_STORE_OP_STORE; //STORE_OP_STROE代表SOTRE时储存内容
|
||||
desc->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; //DONT CARE表示不在意
|
||||
desc->stencilStoreOp= VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
desc->initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //代表不关心初始布局
|
||||
|
||||
++desc;
|
||||
}
|
||||
|
||||
desc=desc_list.GetData();
|
||||
const VkFormat *cf=color_format.GetData();
|
||||
for(uint i=0;i<atta_count;i++)
|
||||
for(uint i=0;i<color_count;i++)
|
||||
{
|
||||
desc[i].finalLayout = color_final_layout;
|
||||
desc[i].format = *cf;
|
||||
++cf;
|
||||
desc->finalLayout = color_final_layout;
|
||||
desc->format = *cf;
|
||||
|
||||
ref[i].attachment = i;
|
||||
ref[i].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
++desc;
|
||||
++cf;
|
||||
}
|
||||
|
||||
desc[atta_count].finalLayout = depth_final_layout;
|
||||
desc[atta_count].format = depth_format;
|
||||
desc[atta_count].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; //深度缓冲区不用于显示也不用于下一帧,所以结束后不用保存
|
||||
desc->finalLayout = depth_final_layout;
|
||||
desc->format = depth_format;
|
||||
desc->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; //深度缓冲区不用于显示也不用于下一帧,所以结束后不用保存
|
||||
|
||||
ref[atta_count].attachment = atta_count;
|
||||
ref[atta_count].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -166,26 +186,18 @@ bool Device::CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<V
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Device::CreateSubpassDescription(VkSubpassDescription &sd,const List<VkAttachmentReference> &ref_list) const
|
||||
void Device::CreateSubpassDescription(VkSubpassDescription &sd,const List<VkAttachmentReference> &color_ref_list,VkAttachmentReference *depth_ref) const
|
||||
{
|
||||
const VkAttachmentReference *end_ref=ref_list.GetPointer(ref_list.GetCount()-1);
|
||||
|
||||
if(end_ref->layout==VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) //最后一个是深度
|
||||
{
|
||||
sd.colorAttachmentCount =ref_list.GetCount()-1;
|
||||
sd.pDepthStencilAttachment =end_ref;
|
||||
}
|
||||
else
|
||||
{
|
||||
sd.colorAttachmentCount =ref_list.GetCount();
|
||||
sd.pDepthStencilAttachment =nullptr;
|
||||
}
|
||||
|
||||
sd.flags =0;
|
||||
sd.pipelineBindPoint =VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
sd.inputAttachmentCount =0;
|
||||
sd.pInputAttachments =nullptr;
|
||||
sd.pColorAttachments =ref_list.GetData();
|
||||
|
||||
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;
|
||||
@ -243,14 +255,18 @@ RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format
|
||||
if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format))
|
||||
return(false);
|
||||
|
||||
List<VkAttachmentReference> ref_list;
|
||||
List<VkAttachmentReference> color_ref;
|
||||
VkAttachmentReference depth_ref;
|
||||
List<VkAttachmentDescription> desc_list;
|
||||
|
||||
List<VkFormat> color_format_list;
|
||||
|
||||
color_format_list.Add(color_format);
|
||||
|
||||
CreateAttachment(ref_list,desc_list,color_format_list,depth_format,color_final_layout,depth_final_layout);
|
||||
CreateColorAttachmentReference(color_ref,0,1);
|
||||
CreateDepthAttachmentReference(&depth_ref,1);
|
||||
|
||||
CreateAttachment(desc_list,color_format_list,depth_format,color_final_layout,depth_final_layout);
|
||||
|
||||
List<VkSubpassDescription> subpass_desc_list;
|
||||
|
||||
@ -261,9 +277,9 @@ RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format
|
||||
subpass.inputAttachmentCount = 0;
|
||||
subpass.pInputAttachments = nullptr;
|
||||
subpass.colorAttachmentCount = 1;
|
||||
subpass.pColorAttachments = ref_list.GetData();
|
||||
subpass.pColorAttachments = color_ref.GetData();
|
||||
subpass.pResolveAttachments = nullptr;
|
||||
subpass.pDepthStencilAttachment = ref_list.GetData()+1;
|
||||
subpass.pDepthStencilAttachment = &depth_ref;
|
||||
subpass.preserveAttachmentCount = 0;
|
||||
subpass.pPreserveAttachments = nullptr;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user