From 7fa2d0ea42ffec01006d8b6cfaf9451ff607538f Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Sun, 20 Apr 2025 15:02:58 +0200 Subject: [PATCH] Skip PromoteFormatToDepth in the case of a dummy image Also add more debug info in case of a failure --- src/video_core/renderer_vulkan/liverpool_to_vk.h | 5 +++-- src/video_core/texture_cache/image_info.cpp | 12 +++++++++--- src/video_core/texture_cache/image_view.cpp | 10 ++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/video_core/renderer_vulkan/liverpool_to_vk.h b/src/video_core/renderer_vulkan/liverpool_to_vk.h index fca0a8378..942f7cfe8 100644 --- a/src/video_core/renderer_vulkan/liverpool_to_vk.h +++ b/src/video_core/renderer_vulkan/liverpool_to_vk.h @@ -100,13 +100,14 @@ static inline bool IsFormatStencilCompatible(vk::Format fmt) { } } -static inline vk::Format PromoteFormatToDepth(vk::Format fmt) { +static inline vk::Format PromoteFormatToDepth(vk::Format fmt, bool& valid) { if (fmt == vk::Format::eR32Sfloat || fmt == vk::Format::eR32Uint) { return vk::Format::eD32Sfloat; } else if (fmt == vk::Format::eR16Unorm) { return vk::Format::eD16Unorm; } - UNREACHABLE_MSG("Unexpected depth format {}", vk::to_string(fmt)); + valid = false; + return fmt; // move the unreachable one step up to be able to print more info } } // namespace Vulkan::LiverpoolToVK diff --git a/src/video_core/texture_cache/image_info.cpp b/src/video_core/texture_cache/image_info.cpp index 39322f449..53d61c51e 100644 --- a/src/video_core/texture_cache/image_info.cpp +++ b/src/video_core/texture_cache/image_info.cpp @@ -126,9 +126,15 @@ ImageInfo::ImageInfo(const AmdGpu::Liverpool::DepthBuffer& buffer, u32 num_slice ImageInfo::ImageInfo(const AmdGpu::Image& image, const Shader::ImageResource& desc) noexcept { tiling_mode = image.GetTilingMode(); pixel_format = LiverpoolToVK::SurfaceFormat(image.GetDataFmt(), image.GetNumberFmt()); - // Override format if image is forced to be a depth target - if (desc.is_depth) { - pixel_format = LiverpoolToVK::PromoteFormatToDepth(pixel_format); + // Override format if image is forced to be a depth target, except if the image is a dummy one + if (desc.is_depth && (image.width != 0 && image.height != 0)) { + bool valid = true; + pixel_format = Vulkan::LiverpoolToVK::PromoteFormatToDepth(pixel_format, valid); + ASSERT_MSG( + valid, + "PromoteFormatToDepth failed, info dump: format: {}, size: {}x{}, data_format: {}", + vk::to_string(pixel_format), image.width + 1, image.height + 1, + AmdGpu::NameOf(image.GetDataFmt())); } type = ConvertImageType(image.GetType()); props.is_tiled = image.IsTiled(); diff --git a/src/video_core/texture_cache/image_view.cpp b/src/video_core/texture_cache/image_view.cpp index 7befb5259..4d02f3bf6 100644 --- a/src/video_core/texture_cache/image_view.cpp +++ b/src/video_core/texture_cache/image_view.cpp @@ -37,8 +37,14 @@ ImageViewInfo::ImageViewInfo(const AmdGpu::Image& image, const Shader::ImageReso nfmt = AmdGpu::NumberFormat::Unorm; } format = Vulkan::LiverpoolToVK::SurfaceFormat(dfmt, nfmt); - if (desc.is_depth) { - format = Vulkan::LiverpoolToVK::PromoteFormatToDepth(format); + // Override format if image is forced to be a depth target, except if the image is a dummy one + if (desc.is_depth && (image.width != 0 && image.height != 0)) { + bool valid = true; + format = Vulkan::LiverpoolToVK::PromoteFormatToDepth(format, valid); + ASSERT_MSG( + valid, + "PromoteFormatToDepth failed, info dump: format: {}, size: {}x{}, data_format: {}", + vk::to_string(format), image.width, image.height, AmdGpu::NameOf(image.GetDataFmt())); } range.base.level = image.base_level;