From 3292121e67ee2c238a1691289bb1916fc04eb378 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 25 Jan 2023 20:51:11 +1000 Subject: [PATCH] GS/SW: Make local a function parameter to SetupPrim .. and associated 32-bit removal. --- pcsx2/GS/Renderers/SW/GSDrawScanline.cpp | 4 ++-- pcsx2/GS/Renderers/SW/GSDrawScanline.h | 9 ++++++--- pcsx2/GS/Renderers/SW/GSRasterizer.cpp | 10 +++++----- .../Renderers/SW/GSSetupPrimCodeGenerator.all.cpp | 15 ++++----------- .../Renderers/SW/GSSetupPrimCodeGenerator.all.h | 13 +------------ 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/pcsx2/GS/Renderers/SW/GSDrawScanline.cpp b/pcsx2/GS/Renderers/SW/GSDrawScanline.cpp index 981646f4b4..9f58dc2d3e 100644 --- a/pcsx2/GS/Renderers/SW/GSDrawScanline.cpp +++ b/pcsx2/GS/Renderers/SW/GSDrawScanline.cpp @@ -1573,9 +1573,9 @@ void GSDrawScanline::CDrawScanline(int pixels, int left, int top, const GSVertex } #ifndef ENABLE_JIT_RASTERIZER -void GSDrawScanline::SetupPrim(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan) +void GSDrawScanline::SetupPrim(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan, GSScanlineLocalData& local) { - CSetupPrim(vertex, index, dscan, m_local, m_global); + CSetupPrim(vertex, index, dscan, local, *local.gd); } void GSDrawScanline::DrawScanline(int pixels, int left, int top, const GSVertexSW& scan) { diff --git a/pcsx2/GS/Renderers/SW/GSDrawScanline.h b/pcsx2/GS/Renderers/SW/GSDrawScanline.h index 6ab3417c63..f4a425b4c4 100644 --- a/pcsx2/GS/Renderers/SW/GSDrawScanline.h +++ b/pcsx2/GS/Renderers/SW/GSDrawScanline.h @@ -33,7 +33,7 @@ public: GSScanlineGlobalData global; }; - typedef void (*SetupPrimPtr)(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan); + typedef void (*SetupPrimPtr)(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan, GSScanlineLocalData& local); typedef void (*DrawScanlinePtr)(int pixels, int left, int top, const GSVertexSW& scan); protected: @@ -69,6 +69,9 @@ public: GSDrawScanline(); virtual ~GSDrawScanline() = default; + __forceinline GSScanlineGlobalData& GetGlobalData() { return m_global; } + __forceinline GSScanlineLocalData& GetLocalData() { return m_local; } + __forceinline bool HasEdge() const { return m_de != nullptr; } __forceinline bool IsSolidRect() const { return m_global.sel.IsSolidRect(); } @@ -85,13 +88,13 @@ public: #ifdef ENABLE_JIT_RASTERIZER - __forceinline void SetupPrim(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan) { m_sp(vertex, index, dscan); } + __forceinline void SetupPrim(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan, GSScanlineLocalData& local) { m_sp(vertex, index, dscan, local); } __forceinline void DrawScanline(int pixels, int left, int top, const GSVertexSW& scan) { m_ds(pixels, left, top, scan); } __forceinline void DrawEdge(int pixels, int left, int top, const GSVertexSW& scan) { m_de(pixels, left, top, scan); } #else - void SetupPrim(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan); + void SetupPrim(const GSVertexSW* vertex, const u32* index, const GSVertexSW& dscan, GSScanlineLocalData& local); void DrawScanline(int pixels, int left, int top, const GSVertexSW& scan); void DrawEdge(int pixels, int left, int top, const GSVertexSW& scan); diff --git a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp index 42c541745d..6cd2ceebdc 100644 --- a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp +++ b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp @@ -280,7 +280,7 @@ void GSRasterizer::DrawPoint(const GSVertexSW* vertex, int vertex_count, const u { if (IsOneOfMyScanlines(p.y)) { - m_ds->SetupPrim(vertex, index, GSVertexSW::zero()); + m_ds->SetupPrim(vertex, index, GSVertexSW::zero(), m_ds->GetLocalData()); DrawScanline(1, p.x, p.y, v); } @@ -301,7 +301,7 @@ void GSRasterizer::DrawPoint(const GSVertexSW* vertex, int vertex_count, const u { if (IsOneOfMyScanlines(p.y)) { - m_ds->SetupPrim(vertex, tmp_index, GSVertexSW::zero()); + m_ds->SetupPrim(vertex, tmp_index, GSVertexSW::zero(), m_ds->GetLocalData()); DrawScanline(1, p.x, p.y, v); } @@ -369,7 +369,7 @@ void GSRasterizer::DrawLine(const GSVertexSW* vertex, const u32* index) scan += dscan * (l - scan.p).xxxx(); - m_ds->SetupPrim(vertex, index, dscan); + m_ds->SetupPrim(vertex, index, dscan, m_ds->GetLocalData()); DrawScanline(pixels, left, p.y, scan); } @@ -864,7 +864,7 @@ void GSRasterizer::DrawSprite(const GSVertexSW* vertex, const u32* index) scan.t = (scan.t + dt * prestep).xyzw(scan.t); - m_ds->SetupPrim(vertex, index, dscan); + m_ds->SetupPrim(vertex, index, dscan, m_ds->GetLocalData()); while (1) { @@ -1093,7 +1093,7 @@ void GSRasterizer::Flush(const GSVertexSW* vertex, const u32* index, const GSVer if (count > 0) { - m_ds->SetupPrim(vertex, index, dscan); + m_ds->SetupPrim(vertex, index, dscan, m_ds->GetLocalData()); const GSVertexSW* RESTRICT e = m_edge.buff; const GSVertexSW* RESTRICT ee = e + count; diff --git a/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.cpp b/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.cpp index 0ea5b8e704..3fff4d2133 100644 --- a/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.cpp +++ b/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.cpp @@ -20,7 +20,7 @@ MULTI_ISA_UNSHARED_IMPL; using namespace Xbyak; -#define _rip_local(field) ((m_rip) ? ptr[rip + (char*)&m_local.field] : ptr[_m_local + OFFSETOF(GSScanlineLocalData, field)]) +#define _rip_local(field) (ptr[_m_local + OFFSETOF(GSScanlineLocalData, field)]) #define _64_m_local _64_t0 @@ -51,20 +51,19 @@ using namespace Xbyak; GSSetupPrimCodeGenerator2::GSSetupPrimCodeGenerator2(Xbyak::CodeGenerator* base, const ProcessorFeatures& cpu, void* param, u64 key) : _parent(base, cpu) , m_local(*(GSScanlineLocalData*)param) - , m_rip(false), many_regs(false) + , many_regs(false) // On x86 arg registers are very temporary but on x64 they aren't, so on x86 some registers overlap #ifdef _WIN32 , _64_vertex(rcx) , _index(rdx) , _dscan(r8) - , _64_t0(r9), t1(r10) + , _m_local(r9), t1(r10) #else , _64_vertex(rdi) , _index(rsi) , _dscan(rdx) - , _64_t0(rcx), t1(r8) + , _m_local(rcx), t1(r8) #endif - , _m_local(chooseLocal(&m_local, _64_m_local)) { m_sel.key = key; @@ -98,9 +97,6 @@ void GSSetupPrimCodeGenerator2::broadcastss(const XYm& reg, const Address& mem) void GSSetupPrimCodeGenerator2::Generate() { - // Technically we just need the delta < 2GB - m_rip = (size_t)&m_local < 0x80000000 && (size_t)getCurr() < 0x80000000; - bool needs_shift = ((m_en.z || m_en.f) && m_sel.prim != GS_SPRITE_CLASS) || m_en.t || (m_en.c && m_sel.iip); many_regs = isYmm && !m_sel.notest && needs_shift; @@ -116,9 +112,6 @@ void GSSetupPrimCodeGenerator2::Generate() } #endif - if (!m_rip) - mov(_64_m_local, (size_t)&m_local); - if (needs_shift) { diff --git a/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.h b/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.h index 97bd68634f..d89c5f23c6 100644 --- a/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.h +++ b/pcsx2/GS/Renderers/SW/GSSetupPrimCodeGenerator.all.h @@ -39,10 +39,6 @@ class GSSetupPrimCodeGenerator2 : public GSNewCodeGenerator using Xmm = Xbyak::Xmm; using Ymm = Xbyak::Ymm; - /// On x86-64 we reserve a bunch of GPRs for holding addresses of locals that would otherwise be hard to reach - /// On x86-32 the same values are just raw 32-bit addresses - using LocalAddr = Choose3264::type; - constexpr static bool isXmm = std::is_same::value; constexpr static bool isYmm = std::is_same::value; constexpr static int vecsize = isXmm ? 16 : 32; @@ -51,19 +47,12 @@ class GSSetupPrimCodeGenerator2 : public GSNewCodeGenerator GSScanlineSelector m_sel; GSScanlineLocalData& m_local; - bool m_rip; bool many_regs; struct {u32 z:1, f:1, t:1, c:1;} m_en; const XYm xym0{0}, xym1{1}, xym2{2}, xym3{3}, xym4{4}, xym5{5}, xym6{6}, xym7{7}, xym8{8}, xym9{9}, xym10{10}, xym11{11}, xym12{12}, xym13{13}, xym14{14}, xym15{15}; - const AddressReg _64_vertex, _index, _dscan, _64_t0, t1; - const LocalAddr _m_local; - /// Returns the first arg on 32-bit, second on 64-bit - static LocalAddr chooseLocal(const void* addr32, AddressReg reg64) - { - return choose3264((size_t)addr32, reg64); - } + const AddressReg _64_vertex, _index, _dscan, _m_local, t1; public: GSSetupPrimCodeGenerator2(Xbyak::CodeGenerator* base, const ProcessorFeatures& cpu, void* param, u64 key);