From 29b7e33c1466a07db07e796ce9492ee384d4da2c Mon Sep 17 00:00:00 2001 From: Jonathan Hamilton Date: Wed, 16 May 2018 17:12:56 -0700 Subject: Make arbitrary mipmap detection a config option Under GFX::Enhancements::ArbitraryMipmapDetection - default enabled --- Source/Core/VideoCommon/TextureCacheBase.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index bf9dc98b9d..00d65c953d 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -500,6 +500,9 @@ public: if (levels.size() < 2) return false; + if (!g_ActiveConfig.bArbitraryMipmapDetection) + return false; + // This is the average per-pixel, per-channel difference in percent between what we // expect a normal blurred mipmap to look like and what we actually received // 4.5% was chosen because it's just below the lowest clearly-arbitrary texture -- cgit v1.2.3 From 8be5cdfcad046f084441e71ee8204dfb40a18d2d Mon Sep 17 00:00:00 2001 From: Jonathan Hamilton Date: Wed, 16 May 2018 17:45:10 -0700 Subject: Make the arbitrary mipmap detection threshold configureable This is likely a "superuser" option at best, but I want to be able to play with it without rebuilding if I want to tweak the heuristics --- Source/Core/VideoCommon/TextureCacheBase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 00d65c953d..370bdd836b 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -507,7 +507,7 @@ public: // expect a normal blurred mipmap to look like and what we actually received // 4.5% was chosen because it's just below the lowest clearly-arbitrary texture // I found in my tests, the background clouds in Mario Galaxy's Observatory lobby. - constexpr auto THRESHOLD_PERCENT = 4.5f; + const auto threshold = g_ActiveConfig.fArbitraryMipmapDetectionThreshold; auto* src = downsample_buffer; auto* dst = downsample_buffer + levels[1].shape.row_length * levels[1].shape.height * 4; @@ -533,7 +533,7 @@ public: } auto all_levels = total_diff / (levels.size() - 1); - return all_levels > THRESHOLD_PERCENT; + return all_levels > threshold; } private: -- cgit v1.2.3 From 61a81795e5afe551f5622f146ca52d5331069742 Mon Sep 17 00:00:00 2001 From: Jonathan Hamilton Date: Wed, 16 May 2018 17:50:39 -0700 Subject: Change the arbitrary mipmap detection to use the square of the error Hopefully this better matches the user's view of a texture - as large changes in colour should be weighted higher than lots of very small changes Note: This likely invalidates the current heuristic threshold default --- Source/Core/VideoCommon/TextureCacheBase.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 370bdd836b..1b385dcbfe 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -608,10 +608,13 @@ private: const auto* row2 = ptr2; for (u32 j = 0; j < shape.width; ++j, row1 += 4, row2 += 4) { - average_diff += std::abs(static_cast(row1[0]) - static_cast(row2[0])); - average_diff += std::abs(static_cast(row1[1]) - static_cast(row2[1])); - average_diff += std::abs(static_cast(row1[2]) - static_cast(row2[2])); - average_diff += std::abs(static_cast(row1[3]) - static_cast(row2[3])); + for (int channel = 0; channel < 4; channel++) + { + const float diff = + std::abs(static_cast(row1[channel]) - static_cast(row2[channel])); + const float diff_squared = diff * diff; + average_diff += diff_squared; + } } ptr1 += shape.row_length; ptr2 += shape.row_length; -- cgit v1.2.3 From b30d56ccc0a03c41c758afcd47f5d19fa34b0a98 Mon Sep 17 00:00:00 2001 From: Jonathan Hamilton Date: Thu, 17 May 2018 09:39:39 -0700 Subject: Texture AverageDiff: Do more in int space and avoid excessive float conversion Multiplying 2x 8bit values is guaranteed to fit in 16bits, 4 channels then in 18bits, which means an 'int' shouild be sufficient to avoid overflows --- Source/Core/VideoCommon/TextureCacheBase.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 1b385dcbfe..c84bb6ec38 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -608,13 +608,14 @@ private: const auto* row2 = ptr2; for (u32 j = 0; j < shape.width; ++j, row1 += 4, row2 += 4) { + int pixel_diff = 0; for (int channel = 0; channel < 4; channel++) { - const float diff = - std::abs(static_cast(row1[channel]) - static_cast(row2[channel])); - const float diff_squared = diff * diff; - average_diff += diff_squared; + const int diff = static_cast(row1[channel]) - static_cast(row2[channel]); + const int diff_squared = diff * diff; + pixel_diff += diff_squared; } + average_diff += pixel_diff; } ptr1 += shape.row_length; ptr2 += shape.row_length; -- cgit v1.2.3