From 96a7554053a173ade3d85f8599eaff910f91c4b5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 27 Nov 2021 17:12:48 -0800 Subject: [PATCH] sofjit: Move common types to reg cache header. This makes it easier to use vectors elsewhere. --- GPU/Software/DrawPixel.cpp | 8 ++++- GPU/Software/DrawPixel.h | 39 ++---------------------- GPU/Software/Rasterizer.cpp | 6 ++-- GPU/Software/RasterizerRectangle.cpp | 4 +-- GPU/Software/RasterizerRegCache.h | 44 ++++++++++++++++++++++++++++ GPU/Software/Sampler.h | 24 ++------------- 6 files changed, 60 insertions(+), 65 deletions(-) diff --git a/GPU/Software/DrawPixel.cpp b/GPU/Software/DrawPixel.cpp index 4cd9fc9c4a..f49ff94209 100644 --- a/GPU/Software/DrawPixel.cpp +++ b/GPU/Software/DrawPixel.cpp @@ -378,8 +378,14 @@ static inline u32 ApplyLogicOp(GELogicOp op, u32 old_color, u32 new_color) { } template -void SOFTPIXEL_CALL DrawSinglePixel(int x, int y, int z, int fog, SOFTPIXEL_VEC4I color_in, const PixelFuncID &pixelID) { +void SOFTRAST_CALL DrawSinglePixel(int x, int y, int z, int fog, Vec4IntArg color_in, const PixelFuncID &pixelID) { +#if PPSSPP_ARCH(ARM64) + Vec4 prim_color; + vst1q_s32(prim_color.AsArray(), color_in); + prim_color = prim_color.Clamp(0, 255); +#else Vec4 prim_color = Vec4(color_in).Clamp(0, 255); +#endif // Depth range test - applied in clear mode, if not through mode. if (pixelID.applyDepthRange) if (z < gstate.getDepthRangeMin() || z > gstate.getDepthRangeMax()) diff --git a/GPU/Software/DrawPixel.h b/GPU/Software/DrawPixel.h index 2e0b3cd9d4..f3e803c9f1 100644 --- a/GPU/Software/DrawPixel.h +++ b/GPU/Software/DrawPixel.h @@ -22,38 +22,13 @@ #include #include #include -#if PPSSPP_ARCH(ARM) -#include "Common/ArmEmitter.h" -#elif PPSSPP_ARCH(ARM64) -#include "Common/Arm64Emitter.h" -#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) -#include "Common/x64Emitter.h" -#elif PPSSPP_ARCH(MIPS) -#include "Common/MipsEmitter.h" -#else -#include "Common/FakeEmitter.h" -#endif #include "GPU/Math3D.h" #include "GPU/Software/FuncId.h" #include "GPU/Software/RasterizerRegCache.h" namespace Rasterizer { -#if PPSSPP_ARCH(AMD64) && PPSSPP_PLATFORM(WINDOWS) && (defined(_MSC_VER) || defined(__clang__)) -#define SOFTPIXEL_CALL __vectorcall -#define SOFTPIXEL_VEC4I __m128i -#define SOFTPIXEL_TO_VEC4I(x) (x).ivec -#elif PPSSPP_ARCH(AMD64) -#define SOFTPIXEL_CALL -#define SOFTPIXEL_VEC4I __m128i -#define SOFTPIXEL_TO_VEC4I(x) (x).ivec -#else -#define SOFTPIXEL_CALL -#define SOFTPIXEL_VEC4I const Math3D::Vec4 & -#define SOFTPIXEL_TO_VEC4I(x) (x) -#endif - -typedef void (SOFTPIXEL_CALL *SingleFunc)(int x, int y, int z, int fog, SOFTPIXEL_VEC4I color_in, const PixelFuncID &pixelID); +typedef void (SOFTRAST_CALL *SingleFunc)(int x, int y, int z, int fog, Vec4IntArg color_in, const PixelFuncID &pixelID); SingleFunc GetSingleFunc(const PixelFuncID &id); void Init(); @@ -68,17 +43,7 @@ struct PixelBlendState { }; void ComputePixelBlendState(PixelBlendState &state, const PixelFuncID &id); -#if PPSSPP_ARCH(ARM) -class PixelJitCache : public ArmGen::ARMXCodeBlock { -#elif PPSSPP_ARCH(ARM64) -class PixelJitCache : public Arm64Gen::ARM64CodeBlock { -#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) -class PixelJitCache : public Gen::XCodeBlock { -#elif PPSSPP_ARCH(MIPS) -class PixelJitCache : public MIPSGen::MIPSCodeBlock { -#else -class PixelJitCache : public FakeGen::FakeXCodeBlock { -#endif +class PixelJitCache : public Rasterizer::CodeBlock { public: PixelJitCache(); diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index d298c1d0c0..ebb9709fd8 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -906,7 +906,7 @@ void DrawTriangleSlice( subp.x = p.x + (i & 1); subp.y = p.y + (i / 2); - drawPixel(subp.x, subp.y, z[i], fog[i], SOFTPIXEL_TO_VEC4I(prim_color[i]), pixelID); + drawPixel(subp.x, subp.y, z[i], fog[i], ToVec4IntArg(prim_color[i]), pixelID); } } } @@ -1054,7 +1054,7 @@ void DrawPoint(const VertexData &v0) fog = ClampFogDepth(v0.fogdepth); } - drawPixel(p.x, p.y, z, fog, SOFTPIXEL_TO_VEC4I(prim_color), pixelID); + drawPixel(p.x, p.y, z, fog, ToVec4IntArg(prim_color), pixelID); } void ClearRectangle(const VertexData &v0, const VertexData &v1) @@ -1344,7 +1344,7 @@ void DrawLine(const VertexData &v0, const VertexData &v1) ScreenCoords pprime = ScreenCoords((int)x, (int)y, (int)z); DrawingCoords p = TransformUnit::ScreenToDrawing(pprime); - drawPixel(p.x, p.y, z, fog, SOFTPIXEL_TO_VEC4I(prim_color), pixelID); + drawPixel(p.x, p.y, z, fog, ToVec4IntArg(prim_color), pixelID); } x += xinc; diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index d2089f64bc..657ff93aab 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -193,7 +193,7 @@ void DrawSprite(const VertexData& v0, const VertexData& v1) { Vec4 prim_color = v1.color0; Vec4 tex_color = Vec4::FromRGBA(nearestFunc(s, t, texptr, texbufw, 0)); prim_color = GetTextureFunctionOutput(prim_color, tex_color); - drawPixel(x, y, z, 255, SOFTPIXEL_TO_VEC4I(prim_color), pixelID); + drawPixel(x, y, z, 255, ToVec4IntArg(prim_color), pixelID); s += ds; } t += dt; @@ -237,7 +237,7 @@ void DrawSprite(const VertexData& v0, const VertexData& v1) { for (int y = y1; y < y2; y++) { for (int x = pos0.x; x < pos1.x; x++) { Vec4 prim_color = v1.color0; - drawPixel(x, y, z, fog, SOFTPIXEL_TO_VEC4I(prim_color), pixelID); + drawPixel(x, y, z, fog, ToVec4IntArg(prim_color), pixelID); } } }, pos0.y, pos1.y, MIN_LINES_PER_THREAD); diff --git a/GPU/Software/RasterizerRegCache.h b/GPU/Software/RasterizerRegCache.h index 8efe81925a..a07440a484 100644 --- a/GPU/Software/RasterizerRegCache.h +++ b/GPU/Software/RasterizerRegCache.h @@ -21,6 +21,18 @@ #include #include + +#if defined(_M_SSE) +#include +#endif +#if PPSSPP_ARCH(ARM_NEON) && PPSSPP_ARCH(ARM64) +#if defined(_MSC_VER) && PPSSPP_ARCH(ARM64) +#include +#else +#include +#endif +#endif + #if PPSSPP_ARCH(ARM) #include "Common/ArmEmitter.h" #elif PPSSPP_ARCH(ARM64) @@ -32,9 +44,41 @@ #else #include "Common/FakeEmitter.h" #endif +#include "GPU/Math3D.h" namespace Rasterizer { +// While not part of the reg cache proper, this is the type it is built for. +#if PPSSPP_ARCH(ARM) +typedef ArmGen::ARMXCodeBlock CodeBlock; +#elif PPSSPP_ARCH(ARM64) +typedef Arm64Gen::ARM64CodeBlock CodeBlock; +#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) +typedef Gen::XCodeBlock CodeBlock; +#elif PPSSPP_ARCH(MIPS) +typedef MIPSGen::MIPSCodeBlock CodeBlock; +#else +typedef FakeGen::FakeXCodeBlock CodeBlock; +#endif + +// We also have the types of things that end up in regs. +#if PPSSPP_ARCH(ARM64) +typedef int32x4_t Vec4IntArg; +static inline Vec4IntArg ToVec4IntArg(const Math3D::Vec4 &a) { return vld1q_s32(a.AsArray()); } +#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) +typedef __m128i Vec4IntArg; +static inline Vec4IntArg ToVec4IntArg(const Math3D::Vec4 &a) { return a.ivec; } +#else +typedef const Math3D::Vec4 &Vec4IntArg; +static inline Vec4IntArg ToVec4IntArg(const Math3D::Vec4 &a) { return a; } +#endif + +#if PPSSPP_ARCH(AMD64) && PPSSPP_PLATFORM(WINDOWS) && (defined(_MSC_VER) || defined(__clang__) || defined(__INTEL_COMPILER)) +#define SOFTRAST_CALL __vectorcall +#else +#define SOFTRAST_CALL +#endif + struct RegCache { enum Purpose { FLAG_GEN = 0x0100, diff --git a/GPU/Software/Sampler.h b/GPU/Software/Sampler.h index 025b798252..a14c3e5520 100644 --- a/GPU/Software/Sampler.h +++ b/GPU/Software/Sampler.h @@ -20,19 +20,9 @@ #include "ppsspp_config.h" #include -#if PPSSPP_ARCH(ARM) -#include "Common/ArmEmitter.h" -#elif PPSSPP_ARCH(ARM64) -#include "Common/Arm64Emitter.h" -#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) -#include "Common/x64Emitter.h" -#elif PPSSPP_ARCH(MIPS) -#include "Common/MipsEmitter.h" -#else -#include "Common/FakeEmitter.h" -#endif #include "GPU/Math3D.h" #include "GPU/Software/FuncId.h" +#include "GPU/Software/RasterizerRegCache.h" namespace Sampler { @@ -58,17 +48,7 @@ void Shutdown(); bool DescribeCodePtr(const u8 *ptr, std::string &name); -#if PPSSPP_ARCH(ARM) -class SamplerJitCache : public ArmGen::ARMXCodeBlock { -#elif PPSSPP_ARCH(ARM64) -class SamplerJitCache : public Arm64Gen::ARM64CodeBlock { -#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) -class SamplerJitCache : public Gen::XCodeBlock { -#elif PPSSPP_ARCH(MIPS) -class SamplerJitCache : public MIPSGen::MIPSCodeBlock { -#else -class SamplerJitCache : public FakeGen::FakeXCodeBlock { -#endif +class SamplerJitCache : public Rasterizer::CodeBlock { public: SamplerJitCache();