From 334a440af846f75f9c675e08d34e1c8821f8faec Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Thu, 20 Nov 2025 00:25:27 -0400 Subject: [PATCH] [vk, texture_cache] Refining vk format reinterpreation usage --- .../renderer_vulkan/vk_texture_cache.cpp | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 03603f1ee3..426c446b91 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -2123,31 +2123,37 @@ ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewI VkFormat view_format = format_info.format; // Format reinterpretation for games with incorrect format usage - // Some games declare render targets as R32_UINT but sample them - // as float textures. + // Only apply to sampled images (not render targets, not storage images) const auto reinterpretation_mode = Settings::values.format_reinterpretation.GetValue(); - if (reinterpretation_mode != Settings::FormatReinterpretation::Disabled) { - switch (reinterpretation_mode) { - case Settings::FormatReinterpretation::R32UintToR32Sfloat: - if (view_format == VK_FORMAT_R32_UINT) { - view_format = VK_FORMAT_R32_SFLOAT; - LOG_DEBUG(Render_Vulkan, "Reinterpreting R32_UINT -> R32_SFLOAT for texture view"); - } - break; - case Settings::FormatReinterpretation::R32SintToR32Uint: - if (view_format == VK_FORMAT_R32_SINT) { - view_format = VK_FORMAT_R32_UINT; - LOG_DEBUG(Render_Vulkan, "Reinterpreting R32_SINT -> R32_UINT for texture view"); - } - break; - case Settings::FormatReinterpretation::R32SfloatToR32Sint: - if (view_format == VK_FORMAT_R32_SFLOAT) { - view_format = VK_FORMAT_R32_SINT; - LOG_DEBUG(Render_Vulkan, "Reinterpreting R32_SFLOAT -> R32_SINT for texture view"); + if (reinterpretation_mode != Settings::FormatReinterpretation::Disabled && + !info.IsRenderTarget() && + (ImageUsageFlags(format_info, format) & VK_IMAGE_USAGE_SAMPLED_BIT)) { + + // Only reinterpret if NOT used as storage image (storage requires matching types) + const bool is_storage = (ImageUsageFlags(format_info, format) & VK_IMAGE_USAGE_STORAGE_BIT) != 0; + if (!is_storage) { + switch (reinterpretation_mode) { + case Settings::FormatReinterpretation::R32UintToR32Sfloat: + if (view_format == VK_FORMAT_R32_UINT) { + view_format = VK_FORMAT_R32_SFLOAT; + LOG_DEBUG(Render_Vulkan, "Reinterpreting R32_UINT -> R32_SFLOAT for sampled image"); + } + break; + case Settings::FormatReinterpretation::R32SintToR32Uint: + if (view_format == VK_FORMAT_R32_SINT) { + view_format = VK_FORMAT_R32_UINT; + LOG_DEBUG(Render_Vulkan, "Reinterpreting R32_SINT -> R32_UINT for sampled image"); + } + break; + case Settings::FormatReinterpretation::R32SfloatToR32Sint: + if (view_format == VK_FORMAT_R32_SFLOAT) { + view_format = VK_FORMAT_R32_SINT; + LOG_DEBUG(Render_Vulkan, "Reinterpreting R32_SFLOAT -> R32_SINT for sampled image"); + } + break; + default: + break; } - break; - default: - break; } }