summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/TextureCacheBase.cpp
diff options
context:
space:
mode:
authorJonathan Hamilton <jtrhamilton@gmail.com>2018-05-17 09:39:39 -0700
committerJonathan Hamilton <jtrhamilton@gmail.com>2018-05-17 09:39:39 -0700
commitb30d56ccc0a03c41c758afcd47f5d19fa34b0a98 (patch)
tree97c14ec8dcea53d3b9a2acf9272678b22d15d67b /Source/Core/VideoCommon/TextureCacheBase.cpp
parent61a81795e5afe551f5622f146ca52d5331069742 (diff)
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
Diffstat (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp')
-rw-r--r--Source/Core/VideoCommon/TextureCacheBase.cpp9
1 files changed, 5 insertions, 4 deletions
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<float>(row1[channel]) - static_cast<float>(row2[channel]));
- const float diff_squared = diff * diff;
- average_diff += diff_squared;
+ const int diff = static_cast<int>(row1[channel]) - static_cast<int>(row2[channel]);
+ const int diff_squared = diff * diff;
+ pixel_diff += diff_squared;
}
+ average_diff += pixel_diff;
}
ptr1 += shape.row_length;
ptr2 += shape.row_length;