diff --git a/Source/Core/VideoBackends/D3D/DXTexture.cpp b/Source/Core/VideoBackends/D3D/DXTexture.cpp index 4f0dec113f..127a922146 100644 --- a/Source/Core/VideoBackends/D3D/DXTexture.cpp +++ b/Source/Core/VideoBackends/D3D/DXTexture.cpp @@ -49,6 +49,8 @@ DXGI_FORMAT GetDXGIFormatForHostFormat(AbstractTextureFormat format) return DXGI_FORMAT_R32_FLOAT; case AbstractTextureFormat::D16: return DXGI_FORMAT_R16_TYPELESS; + case AbstractTextureFormat::D24_S8: + return DXGI_FORMAT_R24G8_TYPELESS; case AbstractTextureFormat::D32F: return DXGI_FORMAT_R32_TYPELESS; case AbstractTextureFormat::D32F_S8: @@ -64,6 +66,8 @@ DXGI_FORMAT GetSRVFormatForHostFormat(AbstractTextureFormat format) { case AbstractTextureFormat::D16: return DXGI_FORMAT_R16_UNORM; + case AbstractTextureFormat::D24_S8: + return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; case AbstractTextureFormat::D32F: return DXGI_FORMAT_R32_FLOAT; case AbstractTextureFormat::D32F_S8: @@ -78,6 +82,8 @@ DXGI_FORMAT GetDSVFormatForHostFormat(AbstractTextureFormat format) { case AbstractTextureFormat::D16: return DXGI_FORMAT_D16_UNORM; + case AbstractTextureFormat::D24_S8: + return DXGI_FORMAT_D24_UNORM_S8_UINT; case AbstractTextureFormat::D32F: return DXGI_FORMAT_D32_FLOAT; case AbstractTextureFormat::D32F_S8: diff --git a/Source/Core/VideoBackends/OGL/OGLTexture.cpp b/Source/Core/VideoBackends/OGL/OGLTexture.cpp index 4ce9aa398c..5399a11d04 100644 --- a/Source/Core/VideoBackends/OGL/OGLTexture.cpp +++ b/Source/Core/VideoBackends/OGL/OGLTexture.cpp @@ -41,6 +41,8 @@ GLenum GetGLInternalFormatForTextureFormat(AbstractTextureFormat format, bool st return GL_R32F; case AbstractTextureFormat::D16: return GL_DEPTH_COMPONENT16; + case AbstractTextureFormat::D24_S8: + return GL_DEPTH24_STENCIL8; case AbstractTextureFormat::D32F: return GL_DEPTH_COMPONENT32F; case AbstractTextureFormat::D32F_S8: @@ -65,6 +67,7 @@ GLenum GetGLFormatForTextureFormat(AbstractTextureFormat format) case AbstractTextureFormat::D16: case AbstractTextureFormat::D32F: return GL_DEPTH_COMPONENT; + case AbstractTextureFormat::D24_S8: case AbstractTextureFormat::D32F_S8: return GL_DEPTH_STENCIL; // Compressed texture formats don't use this parameter. @@ -86,6 +89,8 @@ GLenum GetGLTypeForTextureFormat(AbstractTextureFormat format) return GL_FLOAT; case AbstractTextureFormat::D16: return GL_UNSIGNED_SHORT; + case AbstractTextureFormat::D24_S8: + return GL_UNSIGNED_INT_24_8; case AbstractTextureFormat::D32F: return GL_FLOAT; case AbstractTextureFormat::D32F_S8: diff --git a/Source/Core/VideoBackends/Vulkan/Texture2D.cpp b/Source/Core/VideoBackends/Vulkan/Texture2D.cpp index 39eb9bfcd8..96bfba6538 100644 --- a/Source/Core/VideoBackends/Vulkan/Texture2D.cpp +++ b/Source/Core/VideoBackends/Vulkan/Texture2D.cpp @@ -169,9 +169,8 @@ void Texture2D::TransitionToLayout(VkCommandBuffer command_buffer, VkImageLayout VK_QUEUE_FAMILY_IGNORED, // uint32_t srcQueueFamilyIndex VK_QUEUE_FAMILY_IGNORED, // uint32_t dstQueueFamilyIndex m_image, // VkImage image - {static_cast(Util::IsDepthFormat(m_format) ? VK_IMAGE_ASPECT_DEPTH_BIT : - VK_IMAGE_ASPECT_COLOR_BIT), - 0, m_levels, 0, m_layers} // VkImageSubresourceRange subresourceRange + {Util::GetImageAspectForFormat(m_format), 0, m_levels, 0, + m_layers} // VkImageSubresourceRange subresourceRange }; // srcStageMask -> Stages that must complete before the barrier @@ -316,9 +315,8 @@ void Texture2D::TransitionToLayout(VkCommandBuffer command_buffer, ComputeImageL VK_QUEUE_FAMILY_IGNORED, // uint32_t srcQueueFamilyIndex VK_QUEUE_FAMILY_IGNORED, // uint32_t dstQueueFamilyIndex m_image, // VkImage image - {static_cast(Util::IsDepthFormat(m_format) ? VK_IMAGE_ASPECT_DEPTH_BIT : - VK_IMAGE_ASPECT_COLOR_BIT), - 0, m_levels, 0, m_layers} // VkImageSubresourceRange subresourceRange + {Util::GetImageAspectForFormat(m_format), 0, m_levels, 0, + m_layers} // VkImageSubresourceRange subresourceRange }; VkPipelineStageFlags srcStageMask, dstStageMask; diff --git a/Source/Core/VideoBackends/Vulkan/Util.cpp b/Source/Core/VideoBackends/Vulkan/Util.cpp index 9e9060c5a3..4ffa5c0146 100644 --- a/Source/Core/VideoBackends/Vulkan/Util.cpp +++ b/Source/Core/VideoBackends/Vulkan/Util.cpp @@ -118,6 +118,9 @@ VkFormat GetVkFormatForHostTextureFormat(AbstractTextureFormat format) case AbstractTextureFormat::D16: return VK_FORMAT_D16_UNORM; + case AbstractTextureFormat::D24_S8: + return VK_FORMAT_D24_UNORM_S8_UINT; + case AbstractTextureFormat::R32F: return VK_FORMAT_R32_SFLOAT; @@ -133,6 +136,24 @@ VkFormat GetVkFormatForHostTextureFormat(AbstractTextureFormat format) } } +VkImageAspectFlags GetImageAspectForFormat(VkFormat format) +{ + switch (format) + { + case VK_FORMAT_D16_UNORM_S8_UINT: + case VK_FORMAT_D24_UNORM_S8_UINT: + case VK_FORMAT_D32_SFLOAT_S8_UINT: + return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + + case VK_FORMAT_D16_UNORM: + case VK_FORMAT_D32_SFLOAT: + return VK_IMAGE_ASPECT_DEPTH_BIT; + + default: + return VK_IMAGE_ASPECT_COLOR_BIT; + } +} + u32 GetTexelSize(VkFormat format) { // Only contains pixel formats we use. diff --git a/Source/Core/VideoBackends/Vulkan/Util.h b/Source/Core/VideoBackends/Vulkan/Util.h index 56d8d58ff0..ced63ef06b 100644 --- a/Source/Core/VideoBackends/Vulkan/Util.h +++ b/Source/Core/VideoBackends/Vulkan/Util.h @@ -29,6 +29,7 @@ bool IsDepthFormat(VkFormat format); bool IsCompressedFormat(VkFormat format); VkFormat GetLinearFormat(VkFormat format); VkFormat GetVkFormatForHostTextureFormat(AbstractTextureFormat format); +VkImageAspectFlags GetImageAspectForFormat(VkFormat format); u32 GetTexelSize(VkFormat format); u32 GetBlockSize(VkFormat format); diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp index cee60012a8..b3c111d5a2 100644 --- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp @@ -94,8 +94,8 @@ std::unique_ptr VKTexture::Create(const TextureConfig& tex_config) { // Clear render targets before use to prevent reading uninitialized memory. VkClearDepthStencilValue clear_value = {0.0f, 0}; - VkImageSubresourceRange clear_range = {VK_IMAGE_ASPECT_DEPTH_BIT, 0, tex_config.levels, 0, - tex_config.layers}; + VkImageSubresourceRange clear_range = {Util::GetImageAspectForFormat(vk_format), 0, + tex_config.levels, 0, tex_config.layers}; texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentInitCommandBuffer(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); vkCmdClearDepthStencilImage(g_command_buffer_mgr->GetCurrentInitCommandBuffer(), diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp index b01fbce085..6190f0e51b 100644 --- a/Source/Core/VideoCommon/AbstractTexture.cpp +++ b/Source/Core/VideoCommon/AbstractTexture.cpp @@ -69,6 +69,7 @@ bool AbstractTexture::IsDepthFormat(AbstractTextureFormat format) switch (format) { case AbstractTextureFormat::D16: + case AbstractTextureFormat::D24_S8: case AbstractTextureFormat::D32F: case AbstractTextureFormat::D32F_S8: return true; @@ -80,7 +81,7 @@ bool AbstractTexture::IsDepthFormat(AbstractTextureFormat format) bool AbstractTexture::IsStencilFormat(AbstractTextureFormat format) { - return format == AbstractTextureFormat::D32F_S8; + return format == AbstractTextureFormat::D24_S8 || format == AbstractTextureFormat::D32F_S8; } size_t AbstractTexture::CalculateStrideForFormat(AbstractTextureFormat format, u32 row_length) @@ -100,6 +101,7 @@ size_t AbstractTexture::CalculateStrideForFormat(AbstractTextureFormat format, u case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::R32F: case AbstractTextureFormat::D32F: + case AbstractTextureFormat::D24_S8: return static_cast(row_length) * 4; case AbstractTextureFormat::D32F_S8: return static_cast(row_length) * 8; @@ -124,6 +126,7 @@ size_t AbstractTexture::GetTexelSizeForFormat(AbstractTextureFormat format) return 2; case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::BGRA8: + case AbstractTextureFormat::D24_S8: case AbstractTextureFormat::R32F: case AbstractTextureFormat::D32F: return 4; diff --git a/Source/Core/VideoCommon/TextureConfig.h b/Source/Core/VideoCommon/TextureConfig.h index 1aa27cca4c..a2358ff3b0 100644 --- a/Source/Core/VideoCommon/TextureConfig.h +++ b/Source/Core/VideoCommon/TextureConfig.h @@ -20,6 +20,7 @@ enum class AbstractTextureFormat : u32 BPTC, R16, D16, + D24_S8, R32F, D32F, D32F_S8,