diff --git a/pcsx2/GS/GSLocalMemory.cpp b/pcsx2/GS/GSLocalMemory.cpp index 1def2c2eaf..31e28dd1d5 100644 --- a/pcsx2/GS/GSLocalMemory.cpp +++ b/pcsx2/GS/GSLocalMemory.cpp @@ -211,8 +211,7 @@ GSLocalMemory::GSLocalMemory() for (size_t i = 0; i < countof(m_psm); i++) { - m_psm[i].pa = &GSLocalMemory::PixelAddress32; - m_psm[i].bn = &GSLocalMemory::BlockNumber32; + m_psm[i].info = GSLocalMemory::swizzle32; m_psm[i].rp = &GSLocalMemory::ReadPixel32; m_psm[i].rpa = &GSLocalMemory::ReadPixel32; m_psm[i].wp = &GSLocalMemory::WritePixel32; @@ -237,25 +236,15 @@ GSLocalMemory::GSLocalMemory() m_psm[i].depth = 0; } - m_psm[PSM_PSGPU24].pa = &GSLocalMemory::PixelAddress16; - m_psm[PSM_PSMCT16].pa = &GSLocalMemory::PixelAddress16; - m_psm[PSM_PSMCT16S].pa = &GSLocalMemory::PixelAddress16S; - m_psm[PSM_PSMT8].pa = &GSLocalMemory::PixelAddress8; - m_psm[PSM_PSMT4].pa = &GSLocalMemory::PixelAddress4; - m_psm[PSM_PSMZ32].pa = &GSLocalMemory::PixelAddress32Z; - m_psm[PSM_PSMZ24].pa = &GSLocalMemory::PixelAddress32Z; - m_psm[PSM_PSMZ16].pa = &GSLocalMemory::PixelAddress16Z; - m_psm[PSM_PSMZ16S].pa = &GSLocalMemory::PixelAddress16SZ; - - m_psm[PSM_PSGPU24].bn = &GSLocalMemory::BlockNumber16; - m_psm[PSM_PSMCT16].bn = &GSLocalMemory::BlockNumber16; - m_psm[PSM_PSMCT16S].bn = &GSLocalMemory::BlockNumber16S; - m_psm[PSM_PSMT8].bn = &GSLocalMemory::BlockNumber8; - m_psm[PSM_PSMT4].bn = &GSLocalMemory::BlockNumber4; - m_psm[PSM_PSMZ32].bn = &GSLocalMemory::BlockNumber32Z; - m_psm[PSM_PSMZ24].bn = &GSLocalMemory::BlockNumber32Z; - m_psm[PSM_PSMZ16].bn = &GSLocalMemory::BlockNumber16Z; - m_psm[PSM_PSMZ16S].bn = &GSLocalMemory::BlockNumber16SZ; + m_psm[PSM_PSGPU24].info = GSLocalMemory::swizzle16; + m_psm[PSM_PSMCT16].info = GSLocalMemory::swizzle16; + m_psm[PSM_PSMCT16S].info = GSLocalMemory::swizzle16S; + m_psm[PSM_PSMT8].info = GSLocalMemory::swizzle8; + m_psm[PSM_PSMT4].info = GSLocalMemory::swizzle4; + m_psm[PSM_PSMZ32].info = GSLocalMemory::swizzle32Z; + m_psm[PSM_PSMZ24].info = GSLocalMemory::swizzle32Z; + m_psm[PSM_PSMZ16].info = GSLocalMemory::swizzle16Z; + m_psm[PSM_PSMZ16S].info = GSLocalMemory::swizzle16SZ; m_psm[PSM_PSMCT24].rp = &GSLocalMemory::ReadPixel24; m_psm[PSM_PSMCT16].rp = &GSLocalMemory::ReadPixel16; @@ -549,16 +538,13 @@ GSPixelOffset* GSLocalMemory::GetPixelOffset(const GIFRegFRAME& FRAME, const GIF off->zpsm = zpsm; off->bw = bw; - pixelAddress fpa = m_psm[fpsm].pa; - pixelAddress zpa = m_psm[zpsm].pa; - int fs = m_psm[fpsm].bpp >> 5; int zs = m_psm[zpsm].bpp >> 5; for (int i = 0; i < 2048; i++) { - off->row[i].x = (int)fpa(0, i, fbp, bw) << fs; - off->row[i].y = (int)zpa(0, i, zbp, bw) << zs; + off->row[i].x = (int)m_psm[fpsm].info.pa(0, i, fbp, bw) << fs; + off->row[i].y = (int)m_psm[zpsm].info.pa(0, i, zbp, bw) << zs; } for (int i = 0; i < 2048; i++) @@ -605,16 +591,13 @@ GSPixelOffset4* GSLocalMemory::GetPixelOffset4(const GIFRegFRAME& FRAME, const G off->zpsm = zpsm; off->bw = bw; - pixelAddress fpa = m_psm[fpsm].pa; - pixelAddress zpa = m_psm[zpsm].pa; - int fs = m_psm[fpsm].bpp >> 5; int zs = m_psm[zpsm].bpp >> 5; for (int i = 0; i < 2048; i++) { - off->row[i].x = (int)fpa(0, i, fbp, bw) << fs; - off->row[i].y = (int)zpa(0, i, zbp, bw) << zs; + off->row[i].x = (int)m_psm[fpsm].info.pa(0, i, fbp, bw) << fs; + off->row[i].y = (int)m_psm[zpsm].info.pa(0, i, zbp, bw) << zs; } for (int i = 0; i < 512; i++) @@ -1276,7 +1259,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x++, pd++) @@ -1300,7 +1283,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x++, pb += 3) @@ -1326,7 +1309,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x++, pw++) @@ -1347,7 +1330,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x++, pb++) @@ -1368,7 +1351,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x += 2, pb++) @@ -1390,7 +1373,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x++, pb++) @@ -1411,7 +1394,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x += 2, pb++) @@ -1433,7 +1416,7 @@ void GSLocalMemory::WriteImageX(int& tx, int& ty, const uint8* src, int len, GIF while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x += 2, pb++) @@ -1490,7 +1473,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { int* RESTRICT offset = psm->rowOffset[y & 7]; - uint32* RESTRICT ps = &m_vm32[psm->pa(0, y, bp, bw)]; + uint32* RESTRICT ps = &m_vm32[psm->info.pa(0, y, bp, bw)]; for (; len > 0 && x < ex && (x & 7); len--, x++, pd++) { @@ -1532,7 +1515,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { int* RESTRICT offset = psm->rowOffset[y & 7]; - uint32* RESTRICT ps = &m_vm32[psm->pa(0, y, bp, bw)]; + uint32* RESTRICT ps = &m_vm32[psm->info.pa(0, y, bp, bw)]; for (; len > 0 && x < ex; len--, x++, pb += 3) { @@ -1562,7 +1545,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { int* RESTRICT offset = psm->rowOffset[y & 7]; - uint16* RESTRICT ps = &m_vm16[psm->pa(0, y, bp, bw)]; + uint16* RESTRICT ps = &m_vm16[psm->info.pa(0, y, bp, bw)]; for (int ex4 = ex - 4; len >= 4 && x <= ex4; len -= 4, x += 4, pw += 4) { @@ -1591,7 +1574,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { int* RESTRICT offset = psm->rowOffset[y & 7]; - uint8* RESTRICT ps = &m_vm8[psm->pa(0, y, bp, bw)]; + uint8* RESTRICT ps = &m_vm8[psm->info.pa(0, y, bp, bw)]; for (int ex4 = ex - 4; len >= 4 && x <= ex4; len -= 4, x += 4, pb += 4) { @@ -1619,7 +1602,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { - uint32 addr = psm->pa(0, y, bp, bw); + uint32 addr = psm->info.pa(0, y, bp, bw); int* RESTRICT offset = psm->rowOffset[y & 7]; for (; len > 0 && x < ex; len--, x += 2, pb++) @@ -1641,7 +1624,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { int* RESTRICT offset = psm->rowOffset[y & 7]; - uint32* RESTRICT ps = &m_vm32[psm->pa(0, y, bp, bw)]; + uint32* RESTRICT ps = &m_vm32[psm->info.pa(0, y, bp, bw)]; for (int ex4 = ex - 4; len >= 4 && x <= ex4; len -= 4, x += 4, pb += 4) { @@ -1670,7 +1653,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { int* offset = psm->rowOffset[y & 7]; - uint32* RESTRICT ps = &m_vm32[psm->pa(0, y, bp, bw)]; + uint32* RESTRICT ps = &m_vm32[psm->info.pa(0, y, bp, bw)]; for (; len > 0 && x < ex; len--, x += 2, pb++) { @@ -1694,7 +1677,7 @@ void GSLocalMemory::ReadImageX(int& tx, int& ty, uint8* dst, int len, GIFRegBITB while (len > 0) { int* RESTRICT offset = psm->rowOffset[y & 7]; - uint32* RESTRICT ps = &m_vm32[psm->pa(0, y, bp, bw)]; + uint32* RESTRICT ps = &m_vm32[psm->info.pa(0, y, bp, bw)]; for (; len > 0 && x < ex; len--, x += 2, pb++) { @@ -2122,20 +2105,16 @@ GSOffset::GSOffset(uint32 _bp, uint32 _bw, uint32 _psm) { hash = _bp | (_bw << 14) | (_psm << 20); - GSLocalMemory::pixelAddress bn = GSLocalMemory::m_psm[_psm].bn; - for (int i = 0; i < 256; i++) { - block.row[i] = (short)bn(0, i << 3, _bp, _bw); + block.row[i] = (short)GSLocalMemory::m_psm[_psm].info.bn(0, i << 3, _bp, _bw); } block.col = GSLocalMemory::m_psm[_psm].blockOffset; - GSLocalMemory::pixelAddress pa = GSLocalMemory::m_psm[_psm].pa; - for (int i = 0; i < 4096; i++) { - pixel.row[i] = (int)pa(0, i & 0x7ff, _bp, _bw); + pixel.row[i] = (int)GSLocalMemory::m_psm[_psm].info.pa(0, i & 0x7ff, _bp, _bw); } for (int i = 0; i < 8; i++) diff --git a/pcsx2/GS/GSLocalMemory.h b/pcsx2/GS/GSLocalMemory.h index 00929505db..481cc6dc99 100644 --- a/pcsx2/GS/GSLocalMemory.h +++ b/pcsx2/GS/GSLocalMemory.h @@ -144,7 +144,7 @@ public: struct alignas(128) psm_t { - pixelAddress pa, bn; + GSSwizzleInfo info; readPixel rp; readPixelAddr rpa; writePixel wp; diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index 8922a60470..945ee0e906 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -276,7 +276,7 @@ GSTextureCache::Source* GSTextureCache::LookupSource(const GIFRegTEX0& TEX0, con uint32 bw = TEX0.TBW; int tw = 1 << TEX0.TW; int th = 1 << TEX0.TH; - uint32 bp_end = psm_s.bn(tw - 1, th - 1, bp, bw); // Valid only for color formats + uint32 bp_end = psm_s.info.bn(tw - 1, th - 1, bp, bw); // Valid only for color formats // Arc the Lad finds the wrong surface here when looking for a depth stencil. // Since we're currently not caching depth stencils (check ToDo in CreateSource) we should not look for it here. @@ -376,7 +376,7 @@ GSTextureCache::Source* GSTextureCache::LookupSource(const GIFRegTEX0& TEX0, con { if (candidate_x_offset == 0 && candidate_y_offset == 0) continue; - uint32 candidate_bp = psm_s.bn(candidate_x_offset, candidate_y_offset, t->m_TEX0.TBP0, bw); + uint32 candidate_bp = psm_s.info.bn(candidate_x_offset, candidate_y_offset, t->m_TEX0.TBP0, bw); if (bp == candidate_bp && bp_end <= t->m_end_block) { // SWEEP HIT: offset found @@ -847,7 +847,7 @@ void GSTextureCache::InvalidateVideoMem(GSOffset* off, const GSVector4i& rect, b // we are screwed. if (m_renderer->m_game.title == CRC::HauntingGround) { - uint32 end_block = GSLocalMemory::m_psm[psm].bn(rect.z - 1, rect.w - 1, bp, bw); // Valid only for color formats + uint32 end_block = GSLocalMemory::m_psm[psm].info.bn(rect.z - 1, rect.w - 1, bp, bw); // Valid only for color formats auto type = RenderTarget; for (auto t : m_dst[type]) @@ -1724,14 +1724,14 @@ void GSTextureCache::Surface::UpdateAge() bool GSTextureCache::Surface::Inside(uint32 bp, uint32 bw, uint32 psm, const GSVector4i& rect) { // Valid only for color formats. - uint32 const end_block = GSLocalMemory::m_psm[psm].bn(rect.z - 1, rect.w - 1, bp, bw); + uint32 const end_block = GSLocalMemory::m_psm[psm].info.bn(rect.z - 1, rect.w - 1, bp, bw); return bp >= m_TEX0.TBP0 && end_block <= m_end_block; } bool GSTextureCache::Surface::Overlaps(uint32 bp, uint32 bw, uint32 psm, const GSVector4i& rect) { // Valid only for color formats. - uint32 const end_block = GSLocalMemory::m_psm[psm].bn(rect.z - 1, rect.w - 1, bp, bw); + uint32 const end_block = GSLocalMemory::m_psm[psm].info.bn(rect.z - 1, rect.w - 1, bp, bw); return (m_TEX0.TBP0 <= bp && bp <= m_end_block) || (m_TEX0.TBP0 <= end_block && end_block <= m_end_block); } @@ -2123,7 +2123,7 @@ void GSTextureCache::Target::UpdateValidity(const GSVector4i& rect) m_valid = m_valid.runion(rect); // Block of the bottom right texel of the validity rectangle, last valid block of the texture - m_end_block = GSLocalMemory::m_psm[m_TEX0.PSM].bn(m_valid.z - 1, m_valid.w - 1, m_TEX0.TBP0, m_TEX0.TBW); // Valid only for color formats + m_end_block = GSLocalMemory::m_psm[m_TEX0.PSM].info.bn(m_valid.z - 1, m_valid.w - 1, m_TEX0.TBP0, m_TEX0.TBW); // Valid only for color formats // GL_CACHE("UpdateValidity (0x%x->0x%x) from R:%d,%d Valid: %d,%d", m_TEX0.TBP0, m_end_block, rect.z, rect.w, m_valid.z, m_valid.w); }