Skip to content

Commit

Permalink
samplerjit: Refactor nearest using reg cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Dec 4, 2021
1 parent 676ed6c commit d7c25b3
Show file tree
Hide file tree
Showing 4 changed files with 534 additions and 246 deletions.
22 changes: 22 additions & 0 deletions GPU/Software/RasterizerRegCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ void RegCache::GrabReg(Reg r, Purpose p, bool &needsSwap, Reg swapReg, Purpose s
_assert_msg_(false, "softjit GrabReg() reg that isn't there");
}

bool RegCache::ChangeReg(Reg r, Purpose p) {
for (auto &reg : regs) {
if (reg.reg != r)
continue;
if ((reg.purpose & FLAG_GEN) != (p & FLAG_GEN))
continue;

if (reg.purpose == p)
return true;
_assert_msg_(!Has(p), "softjit ChangeReg() duplicate purpose (%04X)", p);

if (reg.locked != 0 || reg.forceRetained)
return false;

reg.purpose = p;
return true;
}

_assert_msg_(false, "softjit ChangeReg() reg that isn't there");
return false;
}

RegCache::RegStatus *RegCache::FindReg(Reg r, Purpose p) {
for (auto &reg : regs) {
if (reg.reg == r && reg.purpose == p) {
Expand Down
13 changes: 13 additions & 0 deletions GPU/Software/RasterizerRegCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,23 @@ struct RegCache {
GEN_STENCIL = 0x0103,
GEN_COLOR_OFF = 0x0104,
GEN_DEPTH_OFF = 0x0105,
GEN_RESULT = 0x0106,
GEN_SHIFTVAL = 0x0107,

GEN_ARG_X = 0x0180,
GEN_ARG_Y = 0x0181,
GEN_ARG_Z = 0x0182,
GEN_ARG_FOG = 0x0183,
GEN_ARG_ID = 0x0184,
GEN_ARG_U = 0x0185,
GEN_ARG_V = 0x0186,
GEN_ARG_TEXPTR = 0x0187,
GEN_ARG_BUFW = 0x0188,
GEN_ARG_LEVEL = 0x0189,
GEN_ARG_U_PTR = 0x018A,
GEN_ARG_V_PTR = 0x018B,
GEN_ARG_FRAC_U = 0x018C,
GEN_ARG_FRAC_V = 0x018D,
VEC_ARG_COLOR = 0x0080,
VEC_ARG_MASK = 0x0081,

Expand Down Expand Up @@ -170,6 +181,8 @@ struct RegCache {

// 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);
// For setting the purpose of a specific reg. Returns false if it is locked.
bool ChangeReg(Reg r, Purpose p);

private:
RegStatus *FindReg(Reg r, Purpose p);
Expand Down
1 change: 1 addition & 0 deletions GPU/Software/Sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SamplerJitCache : public Rasterizer::CodeBlock {

std::unordered_map<SamplerID, NearestFunc> cache_;
std::unordered_map<SamplerID, const u8 *> addresses_;
Rasterizer::RegCache regCache_;
};

};
Loading

0 comments on commit d7c25b3

Please sign in to comment.