mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
softjit: Rename reg cache so it can be reused.
Intentionally just the name changes in this commit.
This commit is contained in:
parent
4703b6cb56
commit
3d5bced296
@ -1595,6 +1595,8 @@ set(GPU_SOURCES
|
||||
GPU/Software/Rasterizer.h
|
||||
GPU/Software/RasterizerRectangle.cpp
|
||||
GPU/Software/RasterizerRectangle.h
|
||||
GPU/Software/RasterizerRegCache.cpp
|
||||
GPU/Software/RasterizerRegCache.h
|
||||
GPU/Software/Sampler.cpp
|
||||
GPU/Software/Sampler.h
|
||||
GPU/Software/SoftGpu.cpp
|
||||
|
@ -458,6 +458,7 @@
|
||||
<ClInclude Include="Software\FuncId.h" />
|
||||
<ClInclude Include="Software\Rasterizer.h" />
|
||||
<ClInclude Include="Software\RasterizerRectangle.h" />
|
||||
<ClInclude Include="Software\RasterizerRegCache.h" />
|
||||
<ClInclude Include="Software\Sampler.h" />
|
||||
<ClInclude Include="Software\SoftGpu.h" />
|
||||
<ClInclude Include="Software\TransformUnit.h" />
|
||||
@ -636,6 +637,7 @@
|
||||
<ClCompile Include="Software\FuncId.cpp" />
|
||||
<ClCompile Include="Software\Rasterizer.cpp" />
|
||||
<ClCompile Include="Software\RasterizerRectangle.cpp" />
|
||||
<ClCompile Include="Software\RasterizerRegCache.cpp" />
|
||||
<ClCompile Include="Software\Sampler.cpp" />
|
||||
<ClCompile Include="Software\SamplerX86.cpp" />
|
||||
<ClCompile Include="Software\SoftGpu.cpp" />
|
||||
|
@ -270,6 +270,9 @@
|
||||
<ClInclude Include="Software\DrawPixel.h">
|
||||
<Filter>Software</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Software\RasterizerRegCache.h">
|
||||
<Filter>Software</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Math3D.cpp">
|
||||
@ -545,5 +548,8 @@
|
||||
<ClCompile Include="Software\DrawPixelX86.cpp">
|
||||
<Filter>Software</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Software\RasterizerRegCache.cpp">
|
||||
<Filter>Software</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -635,196 +635,4 @@ void ComputePixelBlendState(PixelBlendState &state, const PixelFuncID &id) {
|
||||
}
|
||||
}
|
||||
|
||||
void PixelRegCache::Reset(bool validate) {
|
||||
if (validate) {
|
||||
for (auto ® : regs) {
|
||||
_assert_msg_(reg.locked == 0, "softjit: Reset() with reg still locked (%04X)", reg.purpose);
|
||||
_assert_msg_(!reg.forceRetained, "softjit: Reset() with reg force retained (%04X)", reg.purpose);
|
||||
}
|
||||
}
|
||||
regs.clear();
|
||||
}
|
||||
|
||||
void PixelRegCache::Add(Reg r, Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.reg == r && (reg.purpose & FLAG_GEN) == (p & FLAG_GEN)) {
|
||||
_assert_msg_(false, "softjit Add() reg duplicate (%04X)", p);
|
||||
}
|
||||
}
|
||||
_assert_msg_(r != REG_INVALID_VALUE, "softjit Add() invalid reg (%04X)", p);
|
||||
|
||||
RegStatus newStatus;
|
||||
newStatus.reg = r;
|
||||
newStatus.purpose = p;
|
||||
regs.push_back(newStatus);
|
||||
}
|
||||
|
||||
void PixelRegCache::Change(Purpose history, Purpose destiny) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == history) {
|
||||
reg.purpose = destiny;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit Change() reg that isn't there (%04X)", history);
|
||||
}
|
||||
|
||||
void PixelRegCache::Release(Reg &r, Purpose p) {
|
||||
RegStatus *status = FindReg(r, p);
|
||||
_assert_msg_(status != nullptr, "softjit Release() reg that isn't there (%04X)", p);
|
||||
_assert_msg_(status->locked > 0, "softjit Release() reg that isn't locked (%04X)", p);
|
||||
_assert_msg_(!status->forceRetained, "softjit Release() reg that is force retained (%04X)", p);
|
||||
|
||||
status->locked--;
|
||||
if (status->locked == 0) {
|
||||
if ((status->purpose & FLAG_GEN) != 0)
|
||||
status->purpose = GEN_INVALID;
|
||||
else
|
||||
status->purpose = VEC_INVALID;
|
||||
}
|
||||
|
||||
r = REG_INVALID_VALUE;
|
||||
}
|
||||
|
||||
void PixelRegCache::Unlock(Reg &r, Purpose p) {
|
||||
RegStatus *status = FindReg(r, p);
|
||||
if (status) {
|
||||
_assert_msg_(status->locked > 0, "softjit Unlock() reg that isn't locked (%04X)", p);
|
||||
status->locked--;
|
||||
r = REG_INVALID_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit Unlock() reg that isn't there (%04X)", p);
|
||||
}
|
||||
|
||||
bool PixelRegCache::Has(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PixelRegCache::Reg PixelRegCache::Find(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
_assert_msg_(reg.locked <= 255, "softjit Find() reg has lots of locks (%04X)", p);
|
||||
reg.locked++;
|
||||
return reg.reg;
|
||||
}
|
||||
}
|
||||
_assert_msg_(false, "softjit Find() reg that isn't there (%04X)", p);
|
||||
return REG_INVALID_VALUE;
|
||||
}
|
||||
|
||||
PixelRegCache::Reg PixelRegCache::Alloc(Purpose p) {
|
||||
_assert_msg_(!Has(p), "softjit Alloc() reg duplicate (%04X)", p);
|
||||
RegStatus *best = nullptr;
|
||||
for (auto ® : regs) {
|
||||
if (reg.locked != 0 || reg.forceRetained)
|
||||
continue;
|
||||
// Needs to be the same type.
|
||||
if ((reg.purpose & FLAG_GEN) != (p & FLAG_GEN))
|
||||
continue;
|
||||
|
||||
if (best == nullptr)
|
||||
best = ®
|
||||
// Prefer a free/purposeless reg (includes INVALID.)
|
||||
if ((reg.purpose & FLAG_TEMP) != 0) {
|
||||
best = ®
|
||||
break;
|
||||
}
|
||||
// But also prefer a lower priority reg.
|
||||
if (reg.purpose < best->purpose)
|
||||
best = ®
|
||||
}
|
||||
|
||||
if (best) {
|
||||
best->locked = 1;
|
||||
best->purpose = p;
|
||||
return best->reg;
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit Alloc() reg with none free (%04X)", p);
|
||||
return REG_INVALID_VALUE;
|
||||
}
|
||||
|
||||
void PixelRegCache::ForceRetain(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
reg.forceRetained = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit ForceRetain() reg that isn't there (%04X)", p);
|
||||
}
|
||||
|
||||
void PixelRegCache::ForceRelease(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
_assert_msg_(reg.locked == 0, "softjit ForceRelease() while locked (%04X)", p);
|
||||
reg.forceRetained = false;
|
||||
if ((reg.purpose & FLAG_GEN) != 0)
|
||||
reg.purpose = GEN_INVALID;
|
||||
else
|
||||
reg.purpose = VEC_INVALID;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit ForceRelease() reg that isn't there (%04X)", p);
|
||||
}
|
||||
|
||||
void PixelRegCache::GrabReg(Reg r, Purpose p, bool &needsSwap, Reg swapReg, Purpose swapPurpose) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.reg != r)
|
||||
continue;
|
||||
if ((reg.purpose & FLAG_GEN) != (p & FLAG_GEN))
|
||||
continue;
|
||||
|
||||
// Easy version, it's free.
|
||||
if (reg.locked == 0 && !reg.forceRetained) {
|
||||
needsSwap = false;
|
||||
reg.purpose = p;
|
||||
reg.locked = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
// Okay, we need to swap. Find that reg.
|
||||
needsSwap = true;
|
||||
RegStatus *swap = FindReg(swapReg, swapPurpose);
|
||||
if (swap) {
|
||||
swap->purpose = reg.purpose;
|
||||
swap->forceRetained = reg.forceRetained;
|
||||
swap->locked = reg.locked;
|
||||
} else {
|
||||
_assert_msg_(!Has(swapPurpose), "softjit GrabReg() wrong purpose (%04X)", swapPurpose);
|
||||
RegStatus newStatus = reg;
|
||||
newStatus.reg = swapReg;
|
||||
regs.push_back(newStatus);
|
||||
}
|
||||
|
||||
reg.purpose = p;
|
||||
reg.locked = 1;
|
||||
reg.forceRetained = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit GrabReg() reg that isn't there");
|
||||
}
|
||||
|
||||
PixelRegCache::RegStatus *PixelRegCache::FindReg(Reg r, Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.reg == r && reg.purpose == p) {
|
||||
return ®
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -35,6 +35,7 @@
|
||||
#endif
|
||||
#include "GPU/Math3D.h"
|
||||
#include "GPU/Software/FuncId.h"
|
||||
#include "GPU/Software/RasterizerRegCache.h"
|
||||
|
||||
namespace Rasterizer {
|
||||
|
||||
@ -60,90 +61,6 @@ void Shutdown();
|
||||
|
||||
bool DescribeCodePtr(const u8 *ptr, std::string &name);
|
||||
|
||||
struct PixelRegCache {
|
||||
enum Purpose {
|
||||
FLAG_GEN = 0x0100,
|
||||
FLAG_TEMP = 0x1000,
|
||||
|
||||
VEC_ZERO = 0x0000,
|
||||
|
||||
GEN_SRC_ALPHA = 0x0100,
|
||||
GEN_GSTATE = 0x0101,
|
||||
GEN_CONST_BASE = 0x0102,
|
||||
GEN_STENCIL = 0x0103,
|
||||
GEN_COLOR_OFF = 0x0104,
|
||||
GEN_DEPTH_OFF = 0x0105,
|
||||
|
||||
GEN_ARG_X = 0x0180,
|
||||
GEN_ARG_Y = 0x0181,
|
||||
GEN_ARG_Z = 0x0182,
|
||||
GEN_ARG_FOG = 0x0183,
|
||||
VEC_ARG_COLOR = 0x0080,
|
||||
VEC_ARG_MASK = 0x0081,
|
||||
|
||||
VEC_TEMP0 = 0x1000,
|
||||
VEC_TEMP1 = 0x1001,
|
||||
VEC_TEMP2 = 0x1002,
|
||||
VEC_TEMP3 = 0x1003,
|
||||
VEC_TEMP4 = 0x1004,
|
||||
VEC_TEMP5 = 0x1005,
|
||||
|
||||
GEN_TEMP0 = 0x1100,
|
||||
GEN_TEMP1 = 0x1101,
|
||||
GEN_TEMP2 = 0x1102,
|
||||
GEN_TEMP3 = 0x1103,
|
||||
GEN_TEMP4 = 0x1104,
|
||||
GEN_TEMP5 = 0x1105,
|
||||
GEN_TEMP_HELPER = 0x1106,
|
||||
|
||||
VEC_INVALID = 0xFEFF,
|
||||
GEN_INVALID = 0xFFFF,
|
||||
};
|
||||
|
||||
#if PPSSPP_ARCH(ARM)
|
||||
typedef ArmGen::ARMReg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = ArmGen::INVALID_REG;
|
||||
#elif PPSSPP_ARCH(ARM64)
|
||||
typedef Arm64Gen::ARM64Reg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = Arm64Gen::INVALID_REG;
|
||||
#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
||||
typedef Gen::X64Reg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = Gen::INVALID_REG;
|
||||
#elif PPSSPP_ARCH(MIPS)
|
||||
typedef MIPSGen::MIPSReg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = MIPSGen::INVALID_REG;
|
||||
#else
|
||||
typedef int Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = -1;
|
||||
#endif
|
||||
|
||||
struct RegStatus {
|
||||
Reg reg;
|
||||
Purpose purpose;
|
||||
uint8_t locked = 0;
|
||||
bool forceRetained = false;
|
||||
};
|
||||
|
||||
void Reset(bool validate);
|
||||
void Add(Reg r, Purpose p);
|
||||
void Change(Purpose history, Purpose destiny);
|
||||
void Release(Reg &r, Purpose p);
|
||||
void Unlock(Reg &r, Purpose p);
|
||||
bool Has(Purpose p);
|
||||
Reg Find(Purpose p);
|
||||
Reg Alloc(Purpose p);
|
||||
void ForceRetain(Purpose p);
|
||||
void ForceRelease(Purpose p);
|
||||
|
||||
// For getting a specific reg. WARNING: May return a locked reg, so you have to check.
|
||||
void GrabReg(Reg r, Purpose p, bool &needsSwap, Reg swapReg, Purpose swapPurpose);
|
||||
|
||||
private:
|
||||
RegStatus *FindReg(Reg r, Purpose p);
|
||||
|
||||
std::vector<RegStatus> regs;
|
||||
};
|
||||
|
||||
struct PixelBlendState {
|
||||
bool usesFactors = false;
|
||||
bool usesDstAlpha = false;
|
||||
@ -179,41 +96,41 @@ private:
|
||||
Arm64Gen::ARM64FloatEmitter fp;
|
||||
#endif
|
||||
|
||||
PixelRegCache::Reg GetGState();
|
||||
PixelRegCache::Reg GetConstBase();
|
||||
PixelRegCache::Reg GetZeroVec();
|
||||
RegCache::Reg GetGState();
|
||||
RegCache::Reg GetConstBase();
|
||||
RegCache::Reg GetZeroVec();
|
||||
// Note: these may require a temporary reg.
|
||||
PixelRegCache::Reg GetColorOff(const PixelFuncID &id);
|
||||
PixelRegCache::Reg GetDepthOff(const PixelFuncID &id);
|
||||
PixelRegCache::Reg GetDestStencil(const PixelFuncID &id);
|
||||
RegCache::Reg GetColorOff(const PixelFuncID &id);
|
||||
RegCache::Reg GetDepthOff(const PixelFuncID &id);
|
||||
RegCache::Reg GetDestStencil(const PixelFuncID &id);
|
||||
|
||||
bool Jit_ApplyDepthRange(const PixelFuncID &id);
|
||||
bool Jit_AlphaTest(const PixelFuncID &id);
|
||||
bool Jit_ApplyFog(const PixelFuncID &id);
|
||||
bool Jit_ColorTest(const PixelFuncID &id);
|
||||
bool Jit_StencilAndDepthTest(const PixelFuncID &id);
|
||||
bool Jit_StencilTest(const PixelFuncID &id, PixelRegCache::Reg stencilReg, PixelRegCache::Reg maskedReg);
|
||||
bool Jit_DepthTestForStencil(const PixelFuncID &id, PixelRegCache::Reg stencilReg);
|
||||
bool Jit_ApplyStencilOp(const PixelFuncID &id, GEStencilOp op, PixelRegCache::Reg stencilReg);
|
||||
bool Jit_WriteStencilOnly(const PixelFuncID &id, PixelRegCache::Reg stencilReg);
|
||||
bool Jit_StencilTest(const PixelFuncID &id, RegCache::Reg stencilReg, RegCache::Reg maskedReg);
|
||||
bool Jit_DepthTestForStencil(const PixelFuncID &id, RegCache::Reg stencilReg);
|
||||
bool Jit_ApplyStencilOp(const PixelFuncID &id, GEStencilOp op, RegCache::Reg stencilReg);
|
||||
bool Jit_WriteStencilOnly(const PixelFuncID &id, RegCache::Reg stencilReg);
|
||||
bool Jit_DepthTest(const PixelFuncID &id);
|
||||
bool Jit_WriteDepth(const PixelFuncID &id);
|
||||
bool Jit_AlphaBlend(const PixelFuncID &id);
|
||||
bool Jit_BlendFactor(const PixelFuncID &id, PixelRegCache::Reg factorReg, PixelRegCache::Reg dstReg, GEBlendSrcFactor factor);
|
||||
bool Jit_DstBlendFactor(const PixelFuncID &id, PixelRegCache::Reg srcFactorReg, PixelRegCache::Reg dstFactorReg, PixelRegCache::Reg dstReg);
|
||||
bool Jit_BlendFactor(const PixelFuncID &id, RegCache::Reg factorReg, RegCache::Reg dstReg, GEBlendSrcFactor factor);
|
||||
bool Jit_DstBlendFactor(const PixelFuncID &id, RegCache::Reg srcFactorReg, RegCache::Reg dstFactorReg, RegCache::Reg dstReg);
|
||||
bool Jit_Dither(const PixelFuncID &id);
|
||||
bool Jit_WriteColor(const PixelFuncID &id);
|
||||
bool Jit_ApplyLogicOp(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg maskReg);
|
||||
bool Jit_ConvertTo565(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg);
|
||||
bool Jit_ConvertTo5551(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
||||
bool Jit_ConvertTo4444(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
||||
bool Jit_ConvertFrom565(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg);
|
||||
bool Jit_ConvertFrom5551(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
||||
bool Jit_ConvertFrom4444(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
||||
bool Jit_ApplyLogicOp(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg maskReg);
|
||||
bool Jit_ConvertTo565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);
|
||||
bool Jit_ConvertTo5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
||||
bool Jit_ConvertTo4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
||||
bool Jit_ConvertFrom565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);
|
||||
bool Jit_ConvertFrom5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
||||
bool Jit_ConvertFrom4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
||||
|
||||
std::unordered_map<PixelFuncID, SingleFunc> cache_;
|
||||
std::unordered_map<PixelFuncID, const u8 *> addresses_;
|
||||
PixelRegCache regCache_;
|
||||
RegCache regCache_;
|
||||
|
||||
#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
||||
void Discard();
|
||||
|
File diff suppressed because it is too large
Load Diff
214
GPU/Software/RasterizerRegCache.cpp
Normal file
214
GPU/Software/RasterizerRegCache.cpp
Normal file
@ -0,0 +1,214 @@
|
||||
// Copyright (c) 2021- PPSSPP Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0 or later versions.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "GPU/Software/RasterizerRegCache.h"
|
||||
|
||||
namespace Rasterizer {
|
||||
|
||||
void RegCache::Reset(bool validate) {
|
||||
if (validate) {
|
||||
for (auto ® : regs) {
|
||||
_assert_msg_(reg.locked == 0, "softjit: Reset() with reg still locked (%04X)", reg.purpose);
|
||||
_assert_msg_(!reg.forceRetained, "softjit: Reset() with reg force retained (%04X)", reg.purpose);
|
||||
}
|
||||
}
|
||||
regs.clear();
|
||||
}
|
||||
|
||||
void RegCache::Add(Reg r, Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.reg == r && (reg.purpose & FLAG_GEN) == (p & FLAG_GEN)) {
|
||||
_assert_msg_(false, "softjit Add() reg duplicate (%04X)", p);
|
||||
}
|
||||
}
|
||||
_assert_msg_(r != REG_INVALID_VALUE, "softjit Add() invalid reg (%04X)", p);
|
||||
|
||||
RegStatus newStatus;
|
||||
newStatus.reg = r;
|
||||
newStatus.purpose = p;
|
||||
regs.push_back(newStatus);
|
||||
}
|
||||
|
||||
void RegCache::Change(Purpose history, Purpose destiny) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == history) {
|
||||
reg.purpose = destiny;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit Change() reg that isn't there (%04X)", history);
|
||||
}
|
||||
|
||||
void RegCache::Release(Reg &r, Purpose p) {
|
||||
RegStatus *status = FindReg(r, p);
|
||||
_assert_msg_(status != nullptr, "softjit Release() reg that isn't there (%04X)", p);
|
||||
_assert_msg_(status->locked > 0, "softjit Release() reg that isn't locked (%04X)", p);
|
||||
_assert_msg_(!status->forceRetained, "softjit Release() reg that is force retained (%04X)", p);
|
||||
|
||||
status->locked--;
|
||||
if (status->locked == 0) {
|
||||
if ((status->purpose & FLAG_GEN) != 0)
|
||||
status->purpose = GEN_INVALID;
|
||||
else
|
||||
status->purpose = VEC_INVALID;
|
||||
}
|
||||
|
||||
r = REG_INVALID_VALUE;
|
||||
}
|
||||
|
||||
void RegCache::Unlock(Reg &r, Purpose p) {
|
||||
RegStatus *status = FindReg(r, p);
|
||||
if (status) {
|
||||
_assert_msg_(status->locked > 0, "softjit Unlock() reg that isn't locked (%04X)", p);
|
||||
status->locked--;
|
||||
r = REG_INVALID_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit Unlock() reg that isn't there (%04X)", p);
|
||||
}
|
||||
|
||||
bool RegCache::Has(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RegCache::Reg RegCache::Find(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
_assert_msg_(reg.locked <= 255, "softjit Find() reg has lots of locks (%04X)", p);
|
||||
reg.locked++;
|
||||
return reg.reg;
|
||||
}
|
||||
}
|
||||
_assert_msg_(false, "softjit Find() reg that isn't there (%04X)", p);
|
||||
return REG_INVALID_VALUE;
|
||||
}
|
||||
|
||||
RegCache::Reg RegCache::Alloc(Purpose p) {
|
||||
_assert_msg_(!Has(p), "softjit Alloc() reg duplicate (%04X)", p);
|
||||
RegStatus *best = nullptr;
|
||||
for (auto ® : regs) {
|
||||
if (reg.locked != 0 || reg.forceRetained)
|
||||
continue;
|
||||
// Needs to be the same type.
|
||||
if ((reg.purpose & FLAG_GEN) != (p & FLAG_GEN))
|
||||
continue;
|
||||
|
||||
if (best == nullptr)
|
||||
best = ®
|
||||
// Prefer a free/purposeless reg (includes INVALID.)
|
||||
if ((reg.purpose & FLAG_TEMP) != 0) {
|
||||
best = ®
|
||||
break;
|
||||
}
|
||||
// But also prefer a lower priority reg.
|
||||
if (reg.purpose < best->purpose)
|
||||
best = ®
|
||||
}
|
||||
|
||||
if (best) {
|
||||
best->locked = 1;
|
||||
best->purpose = p;
|
||||
return best->reg;
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit Alloc() reg with none free (%04X)", p);
|
||||
return REG_INVALID_VALUE;
|
||||
}
|
||||
|
||||
void RegCache::ForceRetain(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
reg.forceRetained = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit ForceRetain() reg that isn't there (%04X)", p);
|
||||
}
|
||||
|
||||
void RegCache::ForceRelease(Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.purpose == p) {
|
||||
_assert_msg_(reg.locked == 0, "softjit ForceRelease() while locked (%04X)", p);
|
||||
reg.forceRetained = false;
|
||||
if ((reg.purpose & FLAG_GEN) != 0)
|
||||
reg.purpose = GEN_INVALID;
|
||||
else
|
||||
reg.purpose = VEC_INVALID;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit ForceRelease() reg that isn't there (%04X)", p);
|
||||
}
|
||||
|
||||
void RegCache::GrabReg(Reg r, Purpose p, bool &needsSwap, Reg swapReg, Purpose swapPurpose) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.reg != r)
|
||||
continue;
|
||||
if ((reg.purpose & FLAG_GEN) != (p & FLAG_GEN))
|
||||
continue;
|
||||
|
||||
// Easy version, it's free.
|
||||
if (reg.locked == 0 && !reg.forceRetained) {
|
||||
needsSwap = false;
|
||||
reg.purpose = p;
|
||||
reg.locked = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
// Okay, we need to swap. Find that reg.
|
||||
needsSwap = true;
|
||||
RegStatus *swap = FindReg(swapReg, swapPurpose);
|
||||
if (swap) {
|
||||
swap->purpose = reg.purpose;
|
||||
swap->forceRetained = reg.forceRetained;
|
||||
swap->locked = reg.locked;
|
||||
} else {
|
||||
_assert_msg_(!Has(swapPurpose), "softjit GrabReg() wrong purpose (%04X)", swapPurpose);
|
||||
RegStatus newStatus = reg;
|
||||
newStatus.reg = swapReg;
|
||||
regs.push_back(newStatus);
|
||||
}
|
||||
|
||||
reg.purpose = p;
|
||||
reg.locked = 1;
|
||||
reg.forceRetained = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_assert_msg_(false, "softjit GrabReg() reg that isn't there");
|
||||
}
|
||||
|
||||
RegCache::RegStatus *RegCache::FindReg(Reg r, Purpose p) {
|
||||
for (auto ® : regs) {
|
||||
if (reg.reg == r && reg.purpose == p) {
|
||||
return ®
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
};
|
122
GPU/Software/RasterizerRegCache.h
Normal file
122
GPU/Software/RasterizerRegCache.h
Normal file
@ -0,0 +1,122 @@
|
||||
// Copyright (c) 2021- PPSSPP Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0 or later versions.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#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
|
||||
|
||||
namespace Rasterizer {
|
||||
|
||||
struct RegCache {
|
||||
enum Purpose {
|
||||
FLAG_GEN = 0x0100,
|
||||
FLAG_TEMP = 0x1000,
|
||||
|
||||
VEC_ZERO = 0x0000,
|
||||
|
||||
GEN_SRC_ALPHA = 0x0100,
|
||||
GEN_GSTATE = 0x0101,
|
||||
GEN_CONST_BASE = 0x0102,
|
||||
GEN_STENCIL = 0x0103,
|
||||
GEN_COLOR_OFF = 0x0104,
|
||||
GEN_DEPTH_OFF = 0x0105,
|
||||
|
||||
GEN_ARG_X = 0x0180,
|
||||
GEN_ARG_Y = 0x0181,
|
||||
GEN_ARG_Z = 0x0182,
|
||||
GEN_ARG_FOG = 0x0183,
|
||||
VEC_ARG_COLOR = 0x0080,
|
||||
VEC_ARG_MASK = 0x0081,
|
||||
|
||||
VEC_TEMP0 = 0x1000,
|
||||
VEC_TEMP1 = 0x1001,
|
||||
VEC_TEMP2 = 0x1002,
|
||||
VEC_TEMP3 = 0x1003,
|
||||
VEC_TEMP4 = 0x1004,
|
||||
VEC_TEMP5 = 0x1005,
|
||||
|
||||
GEN_TEMP0 = 0x1100,
|
||||
GEN_TEMP1 = 0x1101,
|
||||
GEN_TEMP2 = 0x1102,
|
||||
GEN_TEMP3 = 0x1103,
|
||||
GEN_TEMP4 = 0x1104,
|
||||
GEN_TEMP5 = 0x1105,
|
||||
GEN_TEMP_HELPER = 0x1106,
|
||||
|
||||
VEC_INVALID = 0xFEFF,
|
||||
GEN_INVALID = 0xFFFF,
|
||||
};
|
||||
|
||||
#if PPSSPP_ARCH(ARM)
|
||||
typedef ArmGen::ARMReg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = ArmGen::INVALID_REG;
|
||||
#elif PPSSPP_ARCH(ARM64)
|
||||
typedef Arm64Gen::ARM64Reg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = Arm64Gen::INVALID_REG;
|
||||
#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
||||
typedef Gen::X64Reg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = Gen::INVALID_REG;
|
||||
#elif PPSSPP_ARCH(MIPS)
|
||||
typedef MIPSGen::MIPSReg Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = MIPSGen::INVALID_REG;
|
||||
#else
|
||||
typedef int Reg;
|
||||
static constexpr Reg REG_INVALID_VALUE = -1;
|
||||
#endif
|
||||
|
||||
struct RegStatus {
|
||||
Reg reg;
|
||||
Purpose purpose;
|
||||
uint8_t locked = 0;
|
||||
bool forceRetained = false;
|
||||
};
|
||||
|
||||
void Reset(bool validate);
|
||||
void Add(Reg r, Purpose p);
|
||||
void Change(Purpose history, Purpose destiny);
|
||||
void Release(Reg &r, Purpose p);
|
||||
void Unlock(Reg &r, Purpose p);
|
||||
bool Has(Purpose p);
|
||||
Reg Find(Purpose p);
|
||||
Reg Alloc(Purpose p);
|
||||
void ForceRetain(Purpose p);
|
||||
void ForceRelease(Purpose p);
|
||||
|
||||
// For getting a specific reg. WARNING: May return a locked reg, so you have to check.
|
||||
void GrabReg(Reg r, Purpose p, bool &needsSwap, Reg swapReg, Purpose swapPurpose);
|
||||
|
||||
private:
|
||||
RegStatus *FindReg(Reg r, Purpose p);
|
||||
|
||||
std::vector<RegStatus> regs;
|
||||
};
|
||||
|
||||
};
|
@ -431,6 +431,7 @@
|
||||
<ClInclude Include="..\..\GPU\Software\Lighting.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Rasterizer.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\RasterizerRectangle.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\RasterizerRegCache.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\Sampler.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\SoftGpu.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\TransformUnit.h" />
|
||||
@ -491,6 +492,7 @@
|
||||
<ClCompile Include="..\..\GPU\Software\Lighting.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Rasterizer.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\RasterizerRectangle.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\RasterizerRegCache.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\Sampler.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\SoftGpu.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\TransformUnit.cpp" />
|
||||
|
@ -55,6 +55,7 @@
|
||||
<ClCompile Include="..\..\GPU\Software\TransformUnit.cpp" />
|
||||
<ClCompile Include="pch.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\RasterizerRectangle.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Software\RasterizerRegCache.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\FragmentShaderGenerator.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\VertexShaderGenerator.cpp" />
|
||||
<ClCompile Include="..\..\GPU\Common\ReinterpretFramebuffer.cpp" />
|
||||
@ -114,6 +115,7 @@
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\RasterizerRectangle.h" />
|
||||
<ClInclude Include="..\..\GPU\Software\RasterizerRegCache.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\FragmentShaderGenerator.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\VertexShaderGenerator.h" />
|
||||
<ClInclude Include="..\..\GPU\Common\ReinterpretFramebuffer.h" />
|
||||
|
@ -369,6 +369,7 @@ EXEC_AND_LIB_FILES := \
|
||||
$(SRC)/GPU/Software/Lighting.cpp \
|
||||
$(SRC)/GPU/Software/Rasterizer.cpp.arm \
|
||||
$(SRC)/GPU/Software/RasterizerRectangle.cpp.arm \
|
||||
$(SRC)/GPU/Software/RasterizerRegCache.cpp \
|
||||
$(SRC)/GPU/Software/Sampler.cpp \
|
||||
$(SRC)/GPU/Software/SoftGpu.cpp \
|
||||
$(SRC)/GPU/Software/TransformUnit.cpp \
|
||||
|
@ -356,6 +356,7 @@ SOURCES_CXX += \
|
||||
$(GPUDIR)/Software/Lighting.cpp \
|
||||
$(GPUDIR)/Software/Rasterizer.cpp \
|
||||
$(GPUDIR)/Software/RasterizerRectangle.cpp \
|
||||
$(GPUDIR)/Software/RasterizerRegCache.cpp \
|
||||
$(GPUDIR)/GLES/DepalettizeShaderGLES.cpp \
|
||||
$(GPUDIR)/GLES/DepthBufferGLES.cpp \
|
||||
$(GPUDIR)/GLES/DrawEngineGLES.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user