PhysicalDevice增加GetDepthFormat/GetDepthStencilFormat/CheckDepthFormat函数用于检测格式是否可用

This commit is contained in:
hyzboy 2019-06-19 16:54:41 +08:00
parent cb15487cbe
commit 223f767b01
2 changed files with 91 additions and 1 deletions

View File

@ -70,5 +70,10 @@ public:
return fp; return fp;
} }
VkFormat GetDepthFormat(bool lower_to_high=true)const;
VkFormat GetDepthStencilFormat(bool lower_to_high=true)const;
bool CheckDepthFormat(const VkFormat)const;
};//class PhysicalDevice };//class PhysicalDevice
VK_NAMESPACE_END VK_NAMESPACE_END

View File

@ -91,4 +91,89 @@ const bool PhysicalDevice::CheckMemoryType(uint32_t typeBits,VkFlags requirement
// No memory types matched, return failure // No memory types matched, return failure
return false; return false;
} }
VkFormat PhysicalDevice::GetDepthFormat(bool lower_to_high)const
{
constexpr VkFormat depthFormats[] =
{
VK_FORMAT_D16_UNORM,
VK_FORMAT_D24_UNORM_S8_UINT,
VK_FORMAT_D32_SFLOAT,
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)
{
if(lower_to_high)
return format;
else
result=format;
}
}
return result;
}
VkFormat PhysicalDevice::GetDepthStencilFormat(bool lower_to_high)const
{
constexpr VkFormat depthStencilFormats[] =
{
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 : depthStencilFormats)
{
VkFormatProperties formatProps;
vkGetPhysicalDeviceFormatProperties(physical_device, format, &formatProps);
if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
{
if(lower_to_high)
return format;
else
result=format;
}
}
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 VK_NAMESPACE_END