summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorDr. Dystopia <jonis9898@hotmail.com>2026-07-31 23:16:34 +0200
committerDr. Dystopia <jonis9898@hotmail.com>2026-08-16 10:28:21 +0200
commiteb956a158c76a0b7ebf19423d31ac91a31dc394e (patch)
tree2ef18e6c3e558b3bb58c98404789df322e2a3afa /Source/Core/VideoCommon
parent54070da5851e12f2d1a4389daa528e4fb81327ce (diff)
Replace manual calculations with std::lerp and std::midpoint
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/PerformanceTracker.cpp2
-rw-r--r--Source/Core/VideoCommon/ShaderGenCommon.h3
-rw-r--r--Source/Core/VideoCommon/TextureDecoder_Common.cpp7
-rw-r--r--Source/Core/VideoCommon/TextureDecoder_Generic.cpp7
-rw-r--r--Source/Core/VideoCommon/TextureDecoder_x64.cpp8
5 files changed, 19 insertions, 8 deletions
diff --git a/Source/Core/VideoCommon/PerformanceTracker.cpp b/Source/Core/VideoCommon/PerformanceTracker.cpp
index 3d519865be..2ff6a7863b 100644
--- a/Source/Core/VideoCommon/PerformanceTracker.cpp
+++ b/Source/Core/VideoCommon/PerformanceTracker.cpp
@@ -94,7 +94,7 @@ void PerformanceTracker::HandleRawDt(DT diff)
// Sometimes euler averages can break when the average is inf/nan
const auto hz_avg = m_hz_avg.load();
if (std::isfinite(hz_avg))
- m_hz_avg = hz_avg + a * (hz - hz_avg);
+ m_hz_avg = std::lerp(hz_avg, hz, a);
else
m_hz_avg = hz;
diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h
index 7d2c80f086..3ec230b35f 100644
--- a/Source/Core/VideoCommon/ShaderGenCommon.h
+++ b/Source/Core/VideoCommon/ShaderGenCommon.h
@@ -6,6 +6,7 @@
#include <cstring>
#include <functional>
#include <iterator>
+#include <numeric>
#include <string>
#include <string_view>
#include <type_traits>
@@ -247,7 +248,7 @@ void WriteSwitch(ShaderCode& out, APIType ApiType, std::string_view variable,
}
else
{
- u32 mid = low + ((high - low) / 2);
+ u32 mid = std::midpoint(low, high);
out.Write("{:{}}if ({} < {}u) {{\n", "", cur_indent, variable, mid);
BuildTree(cur_indent + 2, low, mid);
out.Write("{:{}}}} else {{\n", "", cur_indent);
diff --git a/Source/Core/VideoCommon/TextureDecoder_Common.cpp b/Source/Core/VideoCommon/TextureDecoder_Common.cpp
index 3506514a54..a9e0cf91d8 100644
--- a/Source/Core/VideoCommon/TextureDecoder_Common.cpp
+++ b/Source/Core/VideoCommon/TextureDecoder_Common.cpp
@@ -4,6 +4,7 @@
#include <algorithm>
#include <array>
#include <cstddef>
+#include <numeric>
#include <span>
#include "Common/CommonTypes.h"
@@ -602,12 +603,14 @@ void TexDecoder_DecodeTexel(u8* dst, std::span<const u8> src, int s, int t, int
color = MakeRGBA(DXTBlend(red1, red2), DXTBlend(green1, green2), DXTBlend(blue1, blue2), 255);
break;
case 6:
- color = MakeRGBA((red1 + red2) / 2, (green1 + green2) / 2, (blue1 + blue2) / 2, 255);
+ color = MakeRGBA(std::midpoint(red1, red2), std::midpoint(green1, green2),
+ std::midpoint(blue1, blue2), 255);
break;
case 7:
// color[3] is the same as color[2] (average of both colors), but transparent.
// This differs from DXT1 where color[3] is transparent black.
- color = MakeRGBA((red1 + red2) / 2, (green1 + green2) / 2, (blue1 + blue2) / 2, 0);
+ color = MakeRGBA(std::midpoint(red1, red2), std::midpoint(green1, green2),
+ std::midpoint(blue1, blue2), 0);
break;
default:
color = 0;
diff --git a/Source/Core/VideoCommon/TextureDecoder_Generic.cpp b/Source/Core/VideoCommon/TextureDecoder_Generic.cpp
index 835ddb523e..04dd0456b2 100644
--- a/Source/Core/VideoCommon/TextureDecoder_Generic.cpp
+++ b/Source/Core/VideoCommon/TextureDecoder_Generic.cpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <cmath>
+#include <numeric>
#include "Common/CPUDetect.h"
#include "Common/CommonTypes.h"
@@ -151,8 +152,10 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch)
{
// color[3] is the same as color[2] (average of both colors), but transparent.
// This differs from DXT1 where color[3] is transparent black.
- colors[2] = MakeRGBA((red1 + red2) / 2, (green1 + green2) / 2, (blue1 + blue2) / 2, 255);
- colors[3] = MakeRGBA((red1 + red2) / 2, (green1 + green2) / 2, (blue1 + blue2) / 2, 0);
+ colors[2] = MakeRGBA(std::midpoint(red1, red2), std::midpoint(green1, green2),
+ std::midpoint(blue1, blue2), 255);
+ colors[3] = MakeRGBA(std::midpoint(red1, red2), std::midpoint(green1, green2),
+ std::midpoint(blue1, blue2), 0);
}
for (int y = 0; y < 4; y++)
diff --git a/Source/Core/VideoCommon/TextureDecoder_x64.cpp b/Source/Core/VideoCommon/TextureDecoder_x64.cpp
index 3918361561..a3bbcd8020 100644
--- a/Source/Core/VideoCommon/TextureDecoder_x64.cpp
+++ b/Source/Core/VideoCommon/TextureDecoder_x64.cpp
@@ -3,6 +3,8 @@
#include "VideoCommon/TextureDecoder.h"
+#include <numeric>
+
#ifdef CHECK
#include "Common/Assert.h"
#endif
@@ -188,8 +190,10 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch)
{
// color[3] is the same as color[2] (average of both colors), but transparent.
// This differs from DXT1 where color[3] is transparent black.
- colors[2] = MakeRGBA((red1 + red2) / 2, (green1 + green2) / 2, (blue1 + blue2) / 2, 255);
- colors[3] = MakeRGBA((red1 + red2) / 2, (green1 + green2) / 2, (blue1 + blue2) / 2, 0);
+ colors[2] = MakeRGBA(std::midpoint(red1 + red2), std::midpoint(green1, green2),
+ std::midpoint(blue1, blue2), 255);
+ colors[3] = MakeRGBA(std::midpoint(red1 + red2), std::midpoint(green1, green2),
+ std::midpoint(blue1, blue2), 0);
}
for (int y = 0; y < 4; y++)