PhysicalDevice增加GetDepthFormat/GetDepthStencilFormat/CheckDepthFormat函数用于检测格式是否可用
This commit is contained in:
parent
cb15487cbe
commit
223f767b01
@ -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
|
@ -35,7 +35,7 @@ PhysicalDevice::PhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
|||||||
|
|
||||||
if(GetExtensionSpecVersion(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
|
if(GetExtensionSpecVersion(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
|
||||||
GetPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2KHR");
|
GetPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2KHR");
|
||||||
|
|
||||||
if(!GetPhysicalDeviceProperties2)
|
if(!GetPhysicalDeviceProperties2)
|
||||||
if(GetExtensionSpecVersion(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME))
|
if(GetExtensionSpecVersion(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME))
|
||||||
GetPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2");
|
GetPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2");
|
||||||
@ -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
|
Loading…
x
Reference in New Issue
Block a user