新的颜色格式属性记录

This commit is contained in:
hyzboy 2019-07-02 21:52:27 +08:00
parent 65805cd6cc
commit 9b961ffe08
3 changed files with 23 additions and 32 deletions

View File

@ -16,12 +16,7 @@ class PhysicalDevice
List<VkLayerProperties> layer_properties; List<VkLayerProperties> layer_properties;
List<VkExtensionProperties> extension_properties; List<VkExtensionProperties> extension_properties;
Set<VkFormat> optimal_color_format; VkFormatProperties format_properties[VK_FORMAT_RANGE_SIZE];
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(); void InitFormatSupport();
@ -80,13 +75,17 @@ public:
return fp; return fp;
} }
bool IsOptimalTilingFeatures(const VkFormat format,const VkFormatFeatureFlags flag)const
{
if(format<VK_FORMAT_BEGIN_RANGE||format>VK_FORMAT_END_RANGE)
return(false);
return(format_properties[format].optimalTilingFeatures&flag);
}
bool IsOptimalColorFormat(const VkFormat format)const{return optimal_color_format.IsMember(format);} bool IsColorAttachmentOptimal(const VkFormat format)const{return IsOptimalTilingFeatures(format,VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);}
bool IsOptimalDepthFormat(const VkFormat format)const{return optimal_depth_format.IsMember(format);} bool IsDepthAttachmentOptimal(const VkFormat format)const{return IsOptimalTilingFeatures(format,VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);}
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 GetDepthFormat(bool lower_to_high=true)const;
VkFormat GetDepthStencilFormat(bool lower_to_high=true)const; VkFormat GetDepthStencilFormat(bool lower_to_high=true)const;

View File

@ -109,7 +109,7 @@ bool Device::CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<V
for(uint i=0;i<color_format.GetCount();i++) for(uint i=0;i<color_format.GetCount();i++)
{ {
if(!attr->physical_device->IsOptimalColorFormat(*cf)) if(!attr->physical_device->IsColorAttachmentOptimal(*cf))
return(false); return(false);
++cf; ++cf;
@ -143,7 +143,7 @@ bool Device::CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<V
bool Device::CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout) 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)) if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format))
return(false); return(false);
{ {
@ -184,14 +184,14 @@ RenderPass *Device::CreateRenderPass( const List<VkAttachmentDescription> &des
for(uint i=0;i<color_format.GetCount();i++) for(uint i=0;i<color_format.GetCount();i++)
{ {
if(!attr->physical_device->IsOptimalColorFormat(*cf)) if(!attr->physical_device->IsColorAttachmentOptimal(*cf))
return(false); return(false);
++cf; ++cf;
} }
} }
if(!attr->physical_device->IsOptimalDepthFormat(depth_format)) if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format))
return(false); return(false);
VkRenderPassCreateInfo rp_info; VkRenderPassCreateInfo rp_info;
@ -214,10 +214,10 @@ RenderPass *Device::CreateRenderPass( const List<VkAttachmentDescription> &des
RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout) RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout)
{ {
if(!attr->physical_device->IsOptimalColorFormat(color_format)) if(!attr->physical_device->IsColorAttachmentOptimal(color_format))
return(false); return(false);
if(!attr->physical_device->IsOptimalDepthFormat(depth_format)) if(!attr->physical_device->IsDepthAttachmentOptimal(depth_format))
return(false); return(false);
List<VkAttachmentReference> ref_list; List<VkAttachmentReference> ref_list;

View File

@ -96,21 +96,13 @@ const bool PhysicalDevice::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFla
void PhysicalDevice::InitFormatSupport() void PhysicalDevice::InitFormatSupport()
{ {
VkFormatProperties formatProps; VkFormatProperties *fp=format_properties;
for(uint32 i=VK_FORMAT_BEGIN_RANGE;i<=VK_FORMAT_END_RANGE;i++) for(uint32 i=VK_FORMAT_BEGIN_RANGE;i<=VK_FORMAT_END_RANGE;i++)
{ {
hgl_zero(formatProps); vkGetPhysicalDeviceFormatProperties(physical_device,(VkFormat)i,fp);
vkGetPhysicalDeviceFormatProperties(physical_device,(VkFormat)i,&formatProps); ++fp;
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);
} }
} }
@ -128,7 +120,7 @@ VkFormat PhysicalDevice::GetDepthFormat(bool lower_to_high)const
for (auto& format : depthFormats) for (auto& format : depthFormats)
{ {
if(IsOptimalDepthFormat(format)) if(IsDepthAttachmentOptimal(format))
{ {
if(lower_to_high) if(lower_to_high)
return format; return format;
@ -153,7 +145,7 @@ VkFormat PhysicalDevice::GetDepthStencilFormat(bool lower_to_high)const
for (auto& format : depthStencilFormats) for (auto& format : depthStencilFormats)
{ {
if(IsOptimalDepthFormat(format)) if(IsDepthAttachmentOptimal(format))
{ {
if(lower_to_high) if(lower_to_high)
return format; return format;