From f6e5571d39371332213833dc3c8046426a11c485 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 10 Nov 2022 14:50:09 -0500 Subject: [PATCH] Support image depth/stencil format D32S8 when D24S8 not available (e.g. Vulkan on AMD GPUs) --- neo/renderer/NVRHI/Image_NVRHI.cpp | 10 +++++++++- neo/sys/DeviceManager.h | 6 +++++- neo/sys/DeviceManager_VK.cpp | 12 +++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/neo/renderer/NVRHI/Image_NVRHI.cpp b/neo/renderer/NVRHI/Image_NVRHI.cpp index 075de7ef..0c739692 100644 --- a/neo/renderer/NVRHI/Image_NVRHI.cpp +++ b/neo/renderer/NVRHI/Image_NVRHI.cpp @@ -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: diff --git a/neo/sys/DeviceManager.h b/neo/sys/DeviceManager.h index 09c48979..4a4be2ff 100644 --- a/neo/sys/DeviceManager.h +++ b/neo/sys/DeviceManager.h @@ -96,6 +96,9 @@ struct DeviceCreationParameters std::vector optionalVulkanLayers; std::vector 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 \ No newline at end of file +#endif diff --git a/neo/sys/DeviceManager_VK.cpp b/neo/sys/DeviceManager_VK.cpp index a6fec731..58249ff4 100644 --- a/neo/sys/DeviceManager_VK.cpp +++ b/neo/sys/DeviceManager_VK.cpp @@ -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() );