From ddbe4960976c84e15b9f465e5a3c0d6d97696ac6 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 7 Jun 2021 00:29:52 +0300 Subject: [PATCH] rsx: Fix depth/color mismatch resolve in texture cache - Sometimes we need a depth texture but only a color texture is available. --- rpcs3/Emu/RSX/Common/texture_cache_helpers.h | 9 ++++++++- rpcs3/Emu/RSX/VK/VKTextureCache.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/texture_cache_helpers.h b/rpcs3/Emu/RSX/Common/texture_cache_helpers.h index 636fb989d4..f5511d5312 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_helpers.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_helpers.h @@ -529,12 +529,19 @@ namespace rsx if (const bool gcm_format_is_depth = is_gcm_depth_format(attr2.gcm_format); gcm_format_is_depth != is_depth) { - if (force_convert) + if (force_convert || gcm_format_is_depth) { + // If force_convert is set, we already know there is no simple workaround. Bitcast will be forced to resolve the issue. + // If the existing texture is a color texture but depth readout is requested, force bitcast + // Note that if only reading the depth value was needed from a depth surface, it would have been sampled as color due to Z comparison. is_depth = gcm_format_is_depth; + force_convert = true; } else { + // Existing texture is a depth texture, but RSX wants a color texture. + // Change the RSX request to a compatible depth texture to give same results in shader. + ensure(is_depth); attr2.gcm_format = get_compatible_depth_format(attr2.gcm_format); } diff --git a/rpcs3/Emu/RSX/VK/VKTextureCache.h b/rpcs3/Emu/RSX/VK/VKTextureCache.h index e38474c1c4..a3108cf6bd 100644 --- a/rpcs3/Emu/RSX/VK/VKTextureCache.h +++ b/rpcs3/Emu/RSX/VK/VKTextureCache.h @@ -1047,7 +1047,7 @@ namespace vk case CELL_GCM_TEXTURE_X16: case CELL_GCM_TEXTURE_DEPTH16: case CELL_GCM_TEXTURE_DEPTH16_FLOAT: - return (vk_format == VK_FORMAT_D16_UNORM); + return (vk_format == VK_FORMAT_D16_UNORM || vk_format == VK_FORMAT_D32_SFLOAT); } }