GS: Get rid of redundant pointers to VM

This commit is contained in:
Connor McLaughlin 2022-05-27 21:11:57 +10:00 committed by refractionpcsx2
parent f8fbfee49d
commit 5963efcec8
5 changed files with 47 additions and 49 deletions

View File

@ -204,7 +204,7 @@ template <int n>
void GSClut::WriteCLUT32_CSM2(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT)
{
GSOffset off = GSOffset::fromKnownPSM(TEX0.CBP, TEXCLUT.CBW, PSM_PSMCT32);
auto pa = off.paMulti(m_mem->m_vm32, TEXCLUT.COU << 4, TEXCLUT.COV);
auto pa = off.paMulti(m_mem->vm32(), TEXCLUT.COU << 4, TEXCLUT.COV);
u16* RESTRICT clut = m_clut + ((TEX0.CSA & 15) << 4);
@ -221,7 +221,7 @@ template <int n>
void GSClut::WriteCLUT16_CSM2(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT)
{
GSOffset off = GSOffset::fromKnownPSM(TEX0.CBP, TEXCLUT.CBW, PSM_PSMCT16);
auto pa = off.paMulti(m_mem->m_vm16, TEXCLUT.COU << 4, TEXCLUT.COV);
auto pa = off.paMulti(m_mem->vm16(), TEXCLUT.COU << 4, TEXCLUT.COV);
u16* RESTRICT clut = m_clut + (TEX0.CSA << 4);
@ -235,7 +235,7 @@ template <int n>
void GSClut::WriteCLUT16S_CSM2(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT)
{
GSOffset off = GSOffset::fromKnownPSM(TEX0.CBP, TEXCLUT.CBW, PSM_PSMCT16S);
auto pa = off.paMulti(m_mem->m_vm16, TEXCLUT.COU << 4, TEXCLUT.COV);
auto pa = off.paMulti(m_mem->vm16(), TEXCLUT.COU << 4, TEXCLUT.COV);
u16* RESTRICT clut = m_clut + (TEX0.CSA << 4);

View File

@ -79,9 +79,6 @@ GSLocalMemory::GSLocalMemory()
m_use_fifo_alloc = false;
}
m_vm16 = (u16*)m_vm8;
m_vm32 = (u32*)m_vm8;
memset(m_vm8, 0, m_vmsize);
for (psm_t& psm : m_psm)
@ -1190,7 +1187,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const u8* src, int len, GIFReg
{
case PSM_PSMCT32:
case PSM_PSMZ32:
readWriteHelper(m_vm32, tx, ty, len / 4, 1, sx, w, off.assertSizesMatch(swizzle32), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len / 4, 1, sx, w, off.assertSizesMatch(swizzle32), [&](auto& pa, int x)
{
*pa.value(x) = *pd;
pd++;
@ -1199,7 +1196,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const u8* src, int len, GIFReg
case PSM_PSMCT24:
case PSM_PSMZ24:
readWriteHelper(m_vm32, tx, ty, len / 3, 1, sx, w, off.assertSizesMatch(swizzle32), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len / 3, 1, sx, w, off.assertSizesMatch(swizzle32), [&](auto& pa, int x)
{
WritePixel24(pa.value(x), *(u32*)pb);
pb += 3;
@ -1210,7 +1207,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const u8* src, int len, GIFReg
case PSM_PSMCT16S:
case PSM_PSMZ16:
case PSM_PSMZ16S:
readWriteHelper(m_vm16, tx, ty, len / 2, 1, sx, w, off.assertSizesMatch(swizzle16), [&](auto& pa, int x)
readWriteHelper(vm16(), tx, ty, len / 2, 1, sx, w, off.assertSizesMatch(swizzle16), [&](auto& pa, int x)
{
*pa.value(x) = *pw;
pw++;
@ -1235,7 +1232,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const u8* src, int len, GIFReg
break;
case PSM_PSMT8H:
readWriteHelper(m_vm32, tx, ty, len, 1, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT8H), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len, 1, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT8H), [&](auto& pa, int x)
{
WritePixel8H(pa.value(x), *pb);
pb++;
@ -1243,7 +1240,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const u8* src, int len, GIFReg
break;
case PSM_PSMT4HL:
readWriteHelper(m_vm32, tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HL), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HL), [&](auto& pa, int x)
{
WritePixel4HL(pa.value(x), *pb & 0xf);
WritePixel4HL(pa.value(x + 1), *pb >> 4);
@ -1252,7 +1249,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const u8* src, int len, GIFReg
break;
case PSM_PSMT4HH:
readWriteHelper(m_vm32, tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HH), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HH), [&](auto& pa, int x)
{
WritePixel4HH(pa.value(x), *pb & 0xf);
WritePixel4HH(pa.value(x + 1), *pb >> 4);
@ -1296,7 +1293,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, u8* dst, int len, GIFRegBITBLTB
len /= 4;
GSOffset::PAPtrHelper pa = off.assertSizesMatch(swizzle32).paMulti(m_vm32, 0, y);
GSOffset::PAPtrHelper pa = off.assertSizesMatch(swizzle32).paMulti(vm32(), 0, y);
while (len > 0)
{
@ -1327,7 +1324,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, u8* dst, int len, GIFRegBITBLTB
{
y++;
x = sx;
pa = off.assertSizesMatch(swizzle32).paMulti(m_vm32, 0, y);
pa = off.assertSizesMatch(swizzle32).paMulti(vm32(), 0, y);
}
}
@ -1338,7 +1335,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, u8* dst, int len, GIFRegBITBLTB
case PSM_PSMCT24:
case PSM_PSMZ24:
readWriteHelper(m_vm32, tx, ty, len / 3, 1, sx, w, off.assertSizesMatch(swizzle32), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len / 3, 1, sx, w, off.assertSizesMatch(swizzle32), [&](auto& pa, int x)
{
u32 c = *pa.value(x);
pb[0] = (u8)(c);
@ -1352,7 +1349,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, u8* dst, int len, GIFRegBITBLTB
case PSM_PSMCT16S:
case PSM_PSMZ16:
case PSM_PSMZ16S:
readWriteHelper(m_vm16, tx, ty, len / 2, 1, sx, w, off.assertSizesMatch(swizzle16), [&](auto& pa, int x)
readWriteHelper(vm16(), tx, ty, len / 2, 1, sx, w, off.assertSizesMatch(swizzle16), [&](auto& pa, int x)
{
*pw = *pa.value(x);
pw++;
@ -1377,7 +1374,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, u8* dst, int len, GIFRegBITBLTB
break;
case PSM_PSMT8H:
readWriteHelper(m_vm32, tx, ty, len, 1, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT8H), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len, 1, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT8H), [&](auto& pa, int x)
{
*pb = (u8)(*pa.value(x) >> 24);
pb++;
@ -1385,7 +1382,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, u8* dst, int len, GIFRegBITBLTB
break;
case PSM_PSMT4HL:
readWriteHelper(m_vm32, tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HL), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HL), [&](auto& pa, int x)
{
u32 c0 = *pa.value(x) >> 24 & 0x0f;
u32 c1 = *pa.value(x + 1) >> 20 & 0xf0;
@ -1395,7 +1392,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, u8* dst, int len, GIFRegBITBLTB
break;
case PSM_PSMT4HH:
readWriteHelper(m_vm32, tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HH), [&](auto& pa, int x)
readWriteHelper(vm32(), tx, ty, len * 2, 2, sx, w, GSOffset::fromKnownPSM(bp, bw, PSM_PSMT4HH), [&](auto& pa, int x)
{
u32 c0 = *pa.value(x) >> 28 & 0x0f;
u32 c1 = *pa.value(x + 1) >> 24 & 0xf0;

View File

@ -476,8 +476,6 @@ public:
static const int m_vmsize = 1024 * 1024 * 4;
u8* m_vm8;
u16* m_vm16;
u32* m_vm32;
GSClut m_clut;
@ -522,6 +520,9 @@ public:
GSLocalMemory();
virtual ~GSLocalMemory();
__forceinline u16* vm16() const { return reinterpret_cast<u16*>(m_vm8); }
__forceinline u32* vm32() const { return reinterpret_cast<u32*>(m_vm8); }
GSOffset GetOffset(u32 bp, u32 bw, u32 psm) const
{
return GSOffset(m_psm[psm].info, bp, bw, psm);
@ -669,17 +670,17 @@ public:
__forceinline u32 ReadPixel32(u32 addr) const
{
return m_vm32[addr];
return vm32()[addr];
}
__forceinline u32 ReadPixel24(u32 addr) const
{
return m_vm32[addr] & 0x00ffffff;
return vm32()[addr] & 0x00ffffff;
}
__forceinline u32 ReadPixel16(u32 addr) const
{
return (u32)m_vm16[addr];
return (u32)vm16()[addr];
}
__forceinline u32 ReadPixel8(u32 addr) const
@ -694,27 +695,27 @@ public:
__forceinline u32 ReadPixel8H(u32 addr) const
{
return m_vm32[addr] >> 24;
return vm32()[addr] >> 24;
}
__forceinline u32 ReadPixel4HL(u32 addr) const
{
return (m_vm32[addr] >> 24) & 0x0f;
return (vm32()[addr] >> 24) & 0x0f;
}
__forceinline u32 ReadPixel4HH(u32 addr) const
{
return (m_vm32[addr] >> 28) & 0x0f;
return (vm32()[addr] >> 28) & 0x0f;
}
__forceinline u32 ReadFrame24(u32 addr) const
{
return 0x80000000 | (m_vm32[addr] & 0xffffff);
return 0x80000000 | (vm32()[addr] & 0xffffff);
}
__forceinline u32 ReadFrame16(u32 addr) const
{
u32 c = (u32)m_vm16[addr];
u32 c = (u32)vm16()[addr];
return ((c & 0x8000) << 16) | ((c & 0x7c00) << 9) | ((c & 0x03e0) << 6) | ((c & 0x001f) << 3);
}
@ -816,7 +817,7 @@ public:
__forceinline void WritePixel32(u32 addr, u32 c)
{
m_vm32[addr] = c;
vm32()[addr] = c;
}
__forceinline static void WritePixel24(u32* addr, u32 c)
@ -826,12 +827,12 @@ public:
__forceinline void WritePixel24(u32 addr, u32 c)
{
WritePixel24(m_vm32 + addr, c);
WritePixel24(vm32() + addr, c);
}
__forceinline void WritePixel16(u32 addr, u32 c)
{
m_vm16[addr] = (u16)c;
vm16()[addr] = (u16)c;
}
__forceinline void WritePixel8(u32 addr, u32 c)
@ -854,7 +855,7 @@ public:
__forceinline void WritePixel8H(u32 addr, u32 c)
{
WritePixel8H(m_vm32 + addr, c);
WritePixel8H(vm32() + addr, c);
}
__forceinline static void WritePixel4HL(u32* addr, u32 c)
@ -864,7 +865,7 @@ public:
__forceinline void WritePixel4HL(u32 addr, u32 c)
{
WritePixel4HL(m_vm32 + addr, c);
WritePixel4HL(vm32() + addr, c);
}
__forceinline static void WritePixel4HH(u32* addr, u32 c)
@ -874,7 +875,7 @@ public:
__forceinline void WritePixel4HH(u32 addr, u32 c)
{
WritePixel4HH(m_vm32 + addr, c);
WritePixel4HH(vm32() + addr, c);
}
__forceinline void WriteFrame16(u32 addr, u32 c)
@ -972,12 +973,12 @@ public:
void WritePixel32(u8* RESTRICT src, u32 pitch, const GSOffset& off, const GSVector4i& r)
{
off.loopPixels(r, m_vm32, (u32*)src, pitch, [&](u32* dst, u32* src) { *dst = *src; });
off.loopPixels(r, vm32(), (u32*)src, pitch, [&](u32* dst, u32* src) { *dst = *src; });
}
void WritePixel24(u8* RESTRICT src, u32 pitch, const GSOffset& off, const GSVector4i& r)
{
off.loopPixels(r, m_vm32, (u32*)src, pitch,
off.loopPixels(r, vm32(), (u32*)src, pitch,
[&](u32* dst, u32* src)
{
*dst = (*dst & 0xff000000) | (*src & 0x00ffffff);
@ -986,12 +987,12 @@ public:
void WritePixel16(u8* RESTRICT src, u32 pitch, const GSOffset& off, const GSVector4i& r)
{
off.loopPixels(r, m_vm16, (u16*)src, pitch, [&](u16* dst, u16* src) { *dst = *src; });
off.loopPixels(r, vm16(), (u16*)src, pitch, [&](u16* dst, u16* src) { *dst = *src; });
}
void WriteFrame16(u8* RESTRICT src, u32 pitch, const GSOffset& off, const GSVector4i& r)
{
off.loopPixels(r, m_vm16, (u32*)src, pitch,
off.loopPixels(r, vm16(), (u32*)src, pitch,
[&](u16* dst, u32* src)
{
u32 rb = *src & 0x00f800f8;
@ -1003,17 +1004,17 @@ public:
__forceinline u32 ReadTexel32(u32 addr, const GIFRegTEXA& TEXA) const
{
return m_vm32[addr];
return vm32()[addr];
}
__forceinline u32 ReadTexel24(u32 addr, const GIFRegTEXA& TEXA) const
{
return Expand24To32(m_vm32[addr], TEXA);
return Expand24To32(vm32()[addr], TEXA);
}
__forceinline u32 ReadTexel16(u32 addr, const GIFRegTEXA& TEXA) const
{
return Expand16To32(m_vm16[addr], TEXA);
return Expand16To32(vm16()[addr], TEXA);
}
__forceinline u32 ReadTexel8(u32 addr, const GIFRegTEXA& TEXA) const

View File

@ -2016,21 +2016,21 @@ void GSState::Move()
{
if (spsm.trbpp == 32)
{
copyFast(m_mem.m_vm32, dpo.assertSizesMatch(GSLocalMemory::swizzle32), spo.assertSizesMatch(GSLocalMemory::swizzle32), [](u32* d, u32* s)
copyFast(m_mem.vm32(), dpo.assertSizesMatch(GSLocalMemory::swizzle32), spo.assertSizesMatch(GSLocalMemory::swizzle32), [](u32* d, u32* s)
{
*d = *s;
});
}
else if (spsm.trbpp == 24)
{
copyFast(m_mem.m_vm32, dpo.assertSizesMatch(GSLocalMemory::swizzle32), spo.assertSizesMatch(GSLocalMemory::swizzle32), [](u32* d, u32* s)
copyFast(m_mem.vm32(), dpo.assertSizesMatch(GSLocalMemory::swizzle32), spo.assertSizesMatch(GSLocalMemory::swizzle32), [](u32* d, u32* s)
{
*d = (*d & 0xff000000) | (*s & 0x00ffffff);
});
}
else // if(spsm.trbpp == 16)
{
copyFast(m_mem.m_vm16, dpo.assertSizesMatch(GSLocalMemory::swizzle16), spo.assertSizesMatch(GSLocalMemory::swizzle16), [](u16* d, u16* s)
copyFast(m_mem.vm16(), dpo.assertSizesMatch(GSLocalMemory::swizzle16), spo.assertSizesMatch(GSLocalMemory::swizzle16), [](u16* d, u16* s)
{
*d = *s;
});

View File

@ -943,8 +943,8 @@ void GSRendererHW::SwSpriteRender()
for (int y = 0; y < h; y++, ++sy, ++dy)
{
const auto& spa = spo.paMulti(m_mem.m_vm32, sx, sy);
const auto& dpa = dpo.paMulti(m_mem.m_vm32, dx, dy);
const auto& spa = spo.paMulti(m_mem.vm32(), sx, sy);
const auto& dpa = dpo.paMulti(m_mem.vm32(), dx, dy);
ASSERT(w % 2 == 0);
@ -3831,7 +3831,7 @@ void GSRendererHW::OI_GsMemClear()
// Based on WritePixel32
for (int y = r.top; y < r.bottom; y++)
{
auto pa = off.assertSizesMatch(GSLocalMemory::swizzle32).paMulti(m_mem.m_vm32, 0, y);
auto pa = off.assertSizesMatch(GSLocalMemory::swizzle32).paMulti(m_mem.vm32(), 0, y);
for (int x = r.left; x < r.right; x++)
{
@ -3844,7 +3844,7 @@ void GSRendererHW::OI_GsMemClear()
// Based on WritePixel24
for (int y = r.top; y < r.bottom; y++)
{
auto pa = off.assertSizesMatch(GSLocalMemory::swizzle32).paMulti(m_mem.m_vm32, 0, y);
auto pa = off.assertSizesMatch(GSLocalMemory::swizzle32).paMulti(m_mem.vm32(), 0, y);
for (int x = r.left; x < r.right; x++)
{