From 66c26e39fe1e3122d2a891de04af4ea0089e29c6 Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Mon, 24 Nov 2025 00:07:04 -0400 Subject: [PATCH] [maxwell] Logging for HDR wrong convertions into depth formats --- .../texture_cache/format_lookup_table.cpp | 13 +++-- src/video_core/texture_cache/image_info.cpp | 54 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/video_core/texture_cache/format_lookup_table.cpp b/src/video_core/texture_cache/format_lookup_table.cpp index 8c774f512c..86d8a5a98a 100644 --- a/src/video_core/texture_cache/format_lookup_table.cpp +++ b/src/video_core/texture_cache/format_lookup_table.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -245,9 +248,13 @@ PixelFormat PixelFormatFromTextureInfo(TextureFormat format, ComponentType red, case Hash(TextureFormat::ASTC_2D_6X5, UNORM, SRGB): return PixelFormat::ASTC_2D_6X5_SRGB; } - UNIMPLEMENTED_MSG("texture format={} srgb={} components={{{} {} {} {}}}", - static_cast(format), is_srgb, static_cast(red), - static_cast(green), static_cast(blue), static_cast(alpha)); + const u32 hash_value = Hash(format, red, green, blue, alpha, is_srgb); + LOG_ERROR(Render_Vulkan, + "Unmapped texture format: format=0x{:02X} ({}) srgb={} " + "components={{r={} g={} b={} a={}}} hash=0x{:08X}", + static_cast(format), static_cast(format), is_srgb, + static_cast(red), static_cast(green), + static_cast(blue), static_cast(alpha), hash_value); return PixelFormat::A8B8G8R8_UNORM; } diff --git a/src/video_core/texture_cache/image_info.cpp b/src/video_core/texture_cache/image_info.cpp index ef02972209..bfa306fd19 100644 --- a/src/video_core/texture_cache/image_info.cpp +++ b/src/video_core/texture_cache/image_info.cpp @@ -31,8 +31,62 @@ constexpr u32 DownscaleHeightThreshold = 512; ImageInfo::ImageInfo(const TICEntry& config) noexcept { forced_flushed = config.IsPitchLinear() && !Settings::values.use_reactive_flushing.GetValue(); dma_downloaded = forced_flushed; + + // Validate component types match format expectations + const auto tex_format = config.format; + const bool is_depth_stencil = + tex_format == Tegra::Texture::TextureFormat::Z24S8 || + tex_format == Tegra::Texture::TextureFormat::S8Z24 || + tex_format == Tegra::Texture::TextureFormat::Z32 || + tex_format == Tegra::Texture::TextureFormat::Z16 || + tex_format == Tegra::Texture::TextureFormat::X8Z24 || + tex_format == Tegra::Texture::TextureFormat::Z32_X24S8; + + const bool is_hdr_float = + tex_format == Tegra::Texture::TextureFormat::B10G11R11 || + tex_format == Tegra::Texture::TextureFormat::E5B9G9R9; + + // Sanity check: HDR formats should use FLOAT components, depth should use UNORM/UINT + if (is_hdr_float && config.r_type != Tegra::Texture::ComponentType::FLOAT) { + LOG_WARNING(Render_Vulkan, + "HDR format 0x{:02X} has non-FLOAT components (r={} g={} b={} a={}), " + "possible register corruption", + static_cast(tex_format), + static_cast(config.r_type), static_cast(config.g_type), + static_cast(config.b_type), static_cast(config.a_type)); + } + format = PixelFormatFromTextureInfo(config.format, config.r_type, config.g_type, config.b_type, config.a_type, config.srgb_conversion); + + // Validate final format makes sense + const bool detected_as_depth = + format == PixelFormat::D32_FLOAT || format == PixelFormat::D16_UNORM || + format == PixelFormat::X8_D24_UNORM || format == PixelFormat::S8_UINT || + format == PixelFormat::S8_UINT_D24_UNORM || format == PixelFormat::D24_UNORM_S8_UINT || + format == PixelFormat::D32_FLOAT_S8_UINT; + + if (is_hdr_float && detected_as_depth) { + LOG_ERROR(Render_Vulkan, + "Format mismatch: HDR format 0x{:02X} mapped to depth/stencil {}. " + "TIC components: r={} g={} b={} a={} srgb={}", + static_cast(tex_format), format, + static_cast(config.r_type), static_cast(config.g_type), + static_cast(config.b_type), static_cast(config.a_type), + config.srgb_conversion); + } + + if (is_depth_stencil && !detected_as_depth && + format != PixelFormat::A8B8G8R8_UNORM) { // Allow fallback + LOG_ERROR(Render_Vulkan, + "Format mismatch: Depth/stencil format 0x{:02X} mapped to color {}. " + "TIC components: r={} g={} b={} a={} srgb={}", + static_cast(tex_format), format, + static_cast(config.r_type), static_cast(config.g_type), + static_cast(config.b_type), static_cast(config.a_type), + config.srgb_conversion); + } + num_samples = NumSamples(config.msaa_mode); resources.levels = config.max_mip_level + 1; if (config.IsPitchLinear()) {