Support image depth/stencil format D32S8 when D24S8 not available (e.g. Vulkan on AMD GPUs)

This commit is contained in:
Stephen Saunders 2022-11-10 14:50:09 -05:00
parent 80c56e573d
commit f6e5571d39
3 changed files with 25 additions and 3 deletions

View file

@ -286,7 +286,15 @@ void idImage::AllocImage()
break;
case FMT_DEPTH_STENCIL:
format = nvrhi::Format::D24S8;
// SRS - Check if D24S8 is supported, otherwise fall back to D32S8
if( deviceManager->deviceParms.enableImageFormatD24S8 )
{
format = nvrhi::Format::D24S8;
}
else
{
format = nvrhi::Format::D32S8;
}
break;
case FMT_SHADOW_ARRAY:

View file

@ -96,6 +96,9 @@ struct DeviceCreationParameters
std::vector<std::string> optionalVulkanLayers;
std::vector<size_t> ignoredVulkanValidationMessageLocations;
#endif
// SRS - Used by idImage::AllocImage() to determine if format D24S8 is supported by device (default = true)
bool enableImageFormatD24S8 = true;
};
struct DefaultMessageCallback : public nvrhi::IMessageCallback
@ -131,6 +134,7 @@ public:
protected:
friend class idRenderBackend;
friend class idImage;
void* windowInstance;
void* windowHandle;
@ -216,4 +220,4 @@ private:
std::string m_WindowTitle;
};
#endif
#endif

View file

@ -862,7 +862,17 @@ bool DeviceManager_VK::createDevice()
m_VulkanDevice.getQueue( m_PresentQueueFamily, 0, &m_PresentQueue );
VULKAN_HPP_DEFAULT_DISPATCHER.init( m_VulkanDevice );
// SRS - Determine if preferred image depth/stencil format D24S8 is supported (issue with Vulkan on AMD GPUs)
vk::ImageFormatProperties imageFormatProperties;
const vk::Result ret = m_VulkanPhysicalDevice.getImageFormatProperties( vk::Format( VK_FORMAT_D24_UNORM_S8_UINT ),
vk::ImageType( VK_IMAGE_TYPE_2D ),
vk::ImageTiling( VK_IMAGE_TILING_OPTIMAL ),
vk::ImageUsageFlags( VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ),
vk::ImageCreateFlags( 0 ),
&imageFormatProperties );
deviceParms.enableImageFormatD24S8 = ( ret == vk::Result::eSuccess );
// stash the renderer string
auto prop = m_VulkanPhysicalDevice.getProperties();
m_RendererString = std::string( prop.deviceName.data() );