From 9b921c2e7c06d2c778f205d7c75e08bfc7cf42e0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 10 Oct 2015 16:16:48 -0400 Subject: [PATCH 1/5] Rasterizer: Get rid of a trivial pointer cast --- .../VideoBackends/Software/Rasterizer.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 440572e45a..d4977f7671 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "Common/CommonTypes.h" #include "VideoBackends/Software/BPMemLoader.h" @@ -15,22 +16,10 @@ #include "VideoBackends/Software/XFMemLoader.h" #include "VideoCommon/BoundingBox.h" - #define BLOCK_SIZE 2 #define CLAMP(x, a, b) (x>b)?b:(x> 19) - 2032; // integer part - s32 logFract = (*x & 0x007fffff) >> 19; // approximate fractional part - - return logInt + logFract; -} - namespace Rasterizer { static Slope ZSlope; @@ -83,6 +72,19 @@ void Init() ZSlope.f0 = 1.f; } +// Returns approximation of log2(f) in s28.4 +// results are close enough to use for LOD +static s32 FixedLog2(float f) +{ + u32 x; + std::memcpy(&x, &f, sizeof(u32)); + + s32 logInt = ((x & 0x7F800000) >> 19) - 2032; // integer part + s32 logFract = (x & 0x007fffff) >> 19; // approximate fractional part + + return logInt + logFract; +} + static inline int iround(float x) { int t = (int)x; From 2793785e0cc5dd5a4bd823e52266df796a065d1c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 10 Oct 2015 16:34:03 -0400 Subject: [PATCH 2/5] Rasterizer: Get rid of a clamp macro --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index d4977f7671..f8e746c598 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -18,8 +18,6 @@ #define BLOCK_SIZE 2 -#define CLAMP(x, a, b) (x>b)?b:(x 0 && (tm0.min_filter & 4)) || (lod <= 0 && tm0.mag_filter)); - // order of checks matters - // should be: - // if lod > max then max - // else if lod < min then min - lod = CLAMP(lod, (s32)tm1.min_lod, (s32)tm1.max_lod); + // NOTE: The order of comparisons for this clamp check matters. + if (lod > static_cast(tm1.max_lod)) + lod = static_cast(tm1.max_lod); + else if (lod < static_cast(tm1.min_lod)) + lod = static_cast(tm1.min_lod); + *lodp = lod; } From a0924b5e1b2263314a1be74c44052cdda7628e29 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 10 Oct 2015 16:35:46 -0400 Subject: [PATCH 3/5] Rasterizer: Convert BLOCK_SIZE into a constant variable --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index f8e746c598..0e392eef06 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -16,10 +16,10 @@ #include "VideoBackends/Software/XFMemLoader.h" #include "VideoCommon/BoundingBox.h" -#define BLOCK_SIZE 2 - namespace Rasterizer { +static constexpr int BLOCK_SIZE = 2; + static Slope ZSlope; static Slope WSlope; static Slope ColorSlopes[2][4]; From 0608ed513042d0c3670ff653d14c618ed4ce26c1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 10 Oct 2015 16:37:15 -0400 Subject: [PATCH 4/5] Rasterizer: Specify internal linkage on Draw It's not exposed in the header. --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 0e392eef06..9583456277 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -119,7 +119,7 @@ void SetTevReg(int reg, int comp, bool konst, s16 color) tev.SetRegColor(reg, comp, konst, color); } -inline void Draw(s32 x, s32 y, s32 xi, s32 yi) +static void Draw(s32 x, s32 y, s32 xi, s32 yi) { INCSTAT(swstats.thisFrame.rasterizedPixels); From 7762d68c4b93bf55061e2b8c1986c2f0f7b5e545 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 10 Oct 2015 16:43:31 -0400 Subject: [PATCH 5/5] Rasterizer: Mark some references as const --- Source/Core/VideoBackends/Software/Rasterizer.cpp | 10 +++++----- Source/Core/VideoCommon/BPMemory.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index 9583456277..79332b6cdb 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -210,13 +210,13 @@ static void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, fl static inline void CalculateLOD(s32* lodp, bool* linear, u32 texmap, u32 texcoord) { - FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1]; - u8 subTexmap = texmap & 3; + const FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1]; + const u8 subTexmap = texmap & 3; // LOD calculation requires data from the texture mode for bias, etc. // it does not seem to use the actual texture size - TexMode0& tm0 = texUnit.texMode0[subTexmap]; - TexMode1& tm1 = texUnit.texMode1[subTexmap]; + const TexMode0& tm0 = texUnit.texMode0[subTexmap]; + const TexMode1& tm1 = texUnit.texMode1[subTexmap]; float sDelta, tDelta; if (tm0.diag_lod) @@ -301,7 +301,7 @@ static void BuildBlock(s32 blockX, s32 blockY) for (unsigned int i = 0; i <= bpmem.genMode.numtevstages; i++) { int stageOdd = i&1; - TwoTevStageOrders &order = bpmem.tevorders[i >> 1]; + const TwoTevStageOrders& order = bpmem.tevorders[i >> 1]; if (order.getEnable(stageOdd)) { u32 texmap = order.getTexMap(stageOdd); diff --git a/Source/Core/VideoCommon/BPMemory.h b/Source/Core/VideoCommon/BPMemory.h index 14ac732edf..0dc2b44212 100644 --- a/Source/Core/VideoCommon/BPMemory.h +++ b/Source/Core/VideoCommon/BPMemory.h @@ -400,10 +400,10 @@ struct TevStageCombiner u32 rid : 8; }; u32 hex; - int getTexMap(int i){return i?texmap1:texmap0;} - int getTexCoord(int i){return i?texcoord1:texcoord0;} - int getEnable(int i){return i?enable1:enable0;} - int getColorChan(int i){return i?colorchan1:colorchan0;} + int getTexMap(int i) const { return i ? texmap1 : texmap0;} + int getTexCoord(int i) const { return i ? texcoord1 : texcoord0;} + int getEnable(int i) const { return i ? enable1 : enable0; } + int getColorChan(int i) const { return i ? colorchan1 : colorchan0; } }; union TEXSCALE