新的 CreateColorAttachment/CreateDepthAttachment

This commit is contained in:
hyzboy 2019-07-02 21:39:24 +08:00
parent 395102da6f
commit 65805cd6cc
4 changed files with 132 additions and 44 deletions

View File

@ -175,8 +175,8 @@ public: //Command Buffer 相关
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_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 List<VkFormat> &depth_format,const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_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);
RenderPass * CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
const List<VkSubpassDescription> &subpass,

View File

@ -2,6 +2,7 @@
#include<hgl/graph/vulkan/VK.h>
#include<hgl/type/BaseString.h>
#include<hgl/type/Set.h>
VK_NAMESPACE_BEGIN
class PhysicalDevice
@ -15,6 +16,15 @@ class PhysicalDevice
List<VkLayerProperties> layer_properties;
List<VkExtensionProperties> extension_properties;
Set<VkFormat> optimal_color_format;
Set<VkFormat> optimal_depth_format;
Set<VkFormat> linear_color_format;
Set<VkFormat> linear_depth_format;
Set<VkFormat> buffer_color_format;
Set<VkFormat> buffer_depth_format;
void InitFormatSupport();
public:
PhysicalDevice(VkInstance,VkPhysicalDevice);
@ -71,9 +81,14 @@ public:
return fp;
}
bool IsOptimalColorFormat(const VkFormat format)const{return optimal_color_format.IsMember(format);}
bool IsOptimalDepthFormat(const VkFormat format)const{return optimal_depth_format.IsMember(format);}
bool IsLinearColorFormat(const VkFormat format)const{return linear_color_format.IsMember(format);}
bool IsLinearDepthFormat(const VkFormat format)const{return linear_depth_format.IsMember(format);}
bool IsBufferColorFormat(const VkFormat format)const{return buffer_color_format.IsMember(format);}
bool IsBufferDepthFormat(const VkFormat format)const{return buffer_depth_format.IsMember(format);}
VkFormat GetDepthFormat(bool lower_to_high=true)const;
VkFormat GetDepthStencilFormat(bool lower_to_high=true)const;
bool CheckDepthFormat(const VkFormat)const;
};//class PhysicalDevice
VK_NAMESPACE_END

View File

@ -64,9 +64,6 @@ 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)
{
if(!attr->physical_device->CheckDepthFormat(depth_format))
return(false);
uint atta_count=color_format.GetCount();
desc_list.SetCount(atta_count+1);
@ -106,6 +103,74 @@ bool Device::CreateAttachment(List<VkAttachmentReference> &ref_list,List<VkAttac
return(true);
}
bool Device::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();
for(uint i=0;i<color_format.GetCount();i++)
{
if(!attr->physical_device->IsOptimalColorFormat(*cf))
return(false);
++cf;
}
ref_list.SetCount(color_format.GetCount());
VkAttachmentReference *ref=ref_list.GetData();
desc_list.SetCount(color_format.GetCount());
VkAttachmentDescription *desc=desc_list.GetData();
for(uint i=0;i<color_format.GetCount();i++)
{
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->finalLayout = color_final_layout;
++desc;
ref->attachment = i;
ref->layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
++ref;
}
return(true);
}
bool Device::CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout)
{
if(!attr->physical_device->IsOptimalDepthFormat(depth_format))
return(false);
{
ref_list.SetCount(1);
VkAttachmentReference *ref=ref_list.GetData();
ref->attachment=0;
ref->layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
}
{
desc_list.SetCount(1);
VkAttachmentDescription *desc=desc_list.GetData();
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->finalLayout = depth_final_layout;
}
return(true);
}
RenderPass *Device::CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
const List<VkSubpassDescription> &subpass,
const List<VkSubpassDependency> &dependency,
@ -114,6 +179,20 @@ RenderPass *Device::CreateRenderPass( const List<VkAttachmentDescription> &des
const VkImageLayout color_final_layout,
const VkImageLayout depth_final_layout)
{
{
const VkFormat *cf=color_format.GetData();
for(uint i=0;i<color_format.GetCount();i++)
{
if(!attr->physical_device->IsOptimalColorFormat(*cf))
return(false);
++cf;
}
}
if(!attr->physical_device->IsOptimalDepthFormat(depth_format))
return(false);
VkRenderPassCreateInfo rp_info;
rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
@ -135,6 +214,12 @@ RenderPass *Device::CreateRenderPass( const List<VkAttachmentDescription> &des
RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout)
{
if(!attr->physical_device->IsOptimalColorFormat(color_format))
return(false);
if(!attr->physical_device->IsOptimalDepthFormat(depth_format))
return(false);
List<VkAttachmentReference> ref_list;
List<VkAttachmentDescription> desc_list;

View File

@ -56,6 +56,8 @@ PhysicalDevice::PhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
hgl_zero(driver_properties);
}
InitFormatSupport();
}
const uint32_t PhysicalDevice::GetExtensionSpecVersion(const UTF8String &name)const
@ -91,6 +93,27 @@ const bool PhysicalDevice::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFla
// No memory types matched, return failure
return false;
}
void PhysicalDevice::InitFormatSupport()
{
VkFormatProperties formatProps;
for(uint32 i=VK_FORMAT_BEGIN_RANGE;i<=VK_FORMAT_END_RANGE;i++)
{
hgl_zero(formatProps);
vkGetPhysicalDeviceFormatProperties(physical_device,(VkFormat)i,&formatProps);
if(formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT )optimal_color_format.Add((VkFormat)i);
if(formatProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT )linear_color_format.Add((VkFormat)i);
if(formatProps.bufferFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT )buffer_color_format.Add((VkFormat)i);
if(formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)optimal_depth_format.Add((VkFormat)i);
if(formatProps.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)linear_depth_format.Add((VkFormat)i);
if(formatProps.bufferFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)buffer_depth_format.Add((VkFormat)i);
}
}
VkFormat PhysicalDevice::GetDepthFormat(bool lower_to_high)const
{
constexpr VkFormat depthFormats[] =
@ -105,11 +128,7 @@ VkFormat PhysicalDevice::GetDepthFormat(bool lower_to_high)const
for (auto& format : depthFormats)
{
VkFormatProperties formatProps;
vkGetPhysicalDeviceFormatProperties(physical_device, format, &formatProps);
if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
if(IsOptimalDepthFormat(format))
{
if(lower_to_high)
return format;
@ -134,11 +153,7 @@ VkFormat PhysicalDevice::GetDepthStencilFormat(bool lower_to_high)const
for (auto& format : depthStencilFormats)
{
VkFormatProperties formatProps;
vkGetPhysicalDeviceFormatProperties(physical_device, format, &formatProps);
if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
if(IsOptimalDepthFormat(format))
{
if(lower_to_high)
return format;
@ -149,31 +164,4 @@ VkFormat PhysicalDevice::GetDepthStencilFormat(bool lower_to_high)const
return result;
}
bool PhysicalDevice::CheckDepthFormat(const VkFormat)const
{
constexpr VkFormat depthFormats[] =
{
VK_FORMAT_D16_UNORM,
VK_FORMAT_X8_D24_UNORM_PACK32,
VK_FORMAT_D32_SFLOAT,
VK_FORMAT_D16_UNORM_S8_UINT,
VK_FORMAT_D24_UNORM_S8_UINT,
VK_FORMAT_D32_SFLOAT_S8_UINT,
};
VkFormat result=VK_FORMAT_UNDEFINED;
for (auto& format : depthFormats)
{
VkFormatProperties formatProps;
vkGetPhysicalDeviceFormatProperties(physical_device, format, &formatProps);
if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
return(true);
}
return false;
}
VK_NAMESPACE_END