GS: improve GSDirtyRect psm conv., add bw field.

This commit is contained in:
iMineLink 2020-12-23 13:13:05 +01:00 committed by refractionpcsx2
parent be0932f538
commit 44d0966892
3 changed files with 37 additions and 35 deletions

View File

@ -16,47 +16,46 @@
#include "PrecompiledHeader.h"
#include "GSDirtyRect.h"
GSDirtyRect::GSDirtyRect()
: psm(PSM_PSMCT32)
GSDirtyRect::GSDirtyRect() :
r(GSVector4i::zero()),
psm(PSM_PSMCT32),
bw(1)
{
left = top = right = bottom = 0;
}
GSDirtyRect::GSDirtyRect(const GSVector4i& r, u32 psm)
: psm(psm)
GSDirtyRect::GSDirtyRect(const GSVector4i& r, const u32 psm, const u32 bw) :
r(r),
psm(psm),
bw(bw)
{
left = r.left;
top = r.top;
right = r.right;
bottom = r.bottom;
}
const GSVector4i GSDirtyRect::GetDirtyRect(const GIFRegTEX0& TEX0) const
{
GSVector4i r;
GSVector4i _r;
const GSVector2i src = GSLocalMemory::m_psm[psm].bs;
const GSVector2i& src = GSLocalMemory::m_psm[psm].bs;
if (psm != TEX0.PSM)
{
const GSVector2i dst = GSLocalMemory::m_psm[TEX0.PSM].bs;
r.left = left * dst.x / src.x;
r.top = top * dst.y / src.y;
r.right = right * dst.x / src.x;
r.bottom = bottom * dst.y / src.y;
const GSVector2i& dst = GSLocalMemory::m_psm[TEX0.PSM].bs;
_r.left = (r.left * dst.x) / src.x;
_r.top = (r.top * dst.y) / src.y;
_r.right = (r.right * dst.x) / src.x;
_r.bottom = (r.bottom * dst.y) / src.y;
_r = _r.ralign<Align_Outside>(src);
}
else
{
r = GSVector4i(left, top, right, bottom).ralign<Align_Outside>(src);
_r = r.ralign<Align_Outside>(src);
}
return r;
return _r;
}
//
const GSVector4i GSDirtyRectList::GetDirtyRectAndClear(const GIFRegTEX0& TEX0, const GSVector2i& size)
const GSVector4i GSDirtyRectList::GetDirtyRect(const GIFRegTEX0& TEX0, const GSVector2i& size) const
{
if (!empty())
{
@ -67,8 +66,6 @@ const GSVector4i GSDirtyRectList::GetDirtyRectAndClear(const GIFRegTEX0& TEX0, c
r = r.runion(dirty_rect.GetDirtyRect(TEX0));
}
clear();
const GSVector2i bs = GSLocalMemory::m_psm[TEX0.PSM].bs;
return r.ralign<Align_Outside>(bs).rintersect(GSVector4i(0, 0, size.x, size.y));
@ -76,3 +73,10 @@ const GSVector4i GSDirtyRectList::GetDirtyRectAndClear(const GIFRegTEX0& TEX0, c
return GSVector4i::zero();
}
const GSVector4i GSDirtyRectList::GetDirtyRectAndClear(const GIFRegTEX0& TEX0, const GSVector2i& size)
{
const GSVector4i r = GetDirtyRect(TEX0, size);
clear();
return r;
}

View File

@ -19,16 +19,13 @@
class GSDirtyRect
{
int left;
int top;
int right;
int bottom;
u32 psm;
public:
const GSVector4i r;
const u32 psm;
const u32 bw;
GSDirtyRect();
GSDirtyRect(const GSVector4i& r, u32 psm);
GSDirtyRect(const GSVector4i& r, const u32 psm, const u32 bw);
const GSVector4i GetDirtyRect(const GIFRegTEX0& TEX0) const;
};
@ -36,5 +33,6 @@ class GSDirtyRectList : public std::vector<GSDirtyRect>
{
public:
GSDirtyRectList() {}
const GSVector4i GetDirtyRect(const GIFRegTEX0& TEX0, const GSVector2i& size) const;
const GSVector4i GetDirtyRectAndClear(const GIFRegTEX0& TEX0, const GSVector2i& size);
};

View File

@ -561,7 +561,7 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int
// h is likely smaller than w (true most of the time). Reduce the upload size (speed)
max_h = std::min<int>(max_h, TEX0.TBW * 64);
dst->m_dirty.push_back(GSDirtyRect(GSVector4i(0, 0, TEX0.TBW * 64, max_h), TEX0.PSM));
dst->m_dirty.push_back(GSDirtyRect(GSVector4i(0, 0, TEX0.TBW * 64, max_h), TEX0.PSM, TEX0.TBW));
dst->Update();
}
}
@ -672,7 +672,7 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int
// Code is more or less an equivalent of the SW renderer
//
// Option is hidden and not enabled by default to avoid any regression
dst->m_dirty.push_back(GSDirtyRect(GSVector4i(0, 0, TEX0.TBW * 64, real_h), TEX0.PSM));
dst->m_dirty.push_back(GSDirtyRect(GSVector4i(0, 0, TEX0.TBW * 64, real_h), TEX0.PSM, TEX0.TBW));
dst->Update();
}
}
@ -877,8 +877,8 @@ void GSTextureCache::InvalidateVideoMem(const GSOffset& off, const GSVector4i& r
GL_CACHE("TC: Dirty Target(%s) %d (0x%x) r(%d,%d,%d,%d)", to_string(type),
t->m_texture ? t->m_texture->GetID() : 0,
t->m_TEX0.TBP0, r.x, r.y, r.z, r.w);
t->m_dirty.push_back(GSDirtyRect(r, psm));
t->m_TEX0.TBW = bw;
t->m_dirty.push_back(GSDirtyRect(r, psm, bw));
}
else
{
@ -917,8 +917,8 @@ void GSTextureCache::InvalidateVideoMem(const GSOffset& off, const GSVector4i& r
t->m_texture ? t->m_texture->GetID() : 0,
t->m_TEX0.TBP0);
// TODO: do not add this rect above too
t->m_dirty.push_back(GSDirtyRect(GSVector4i(r.left, r.top - y, r.right, r.bottom - y), psm));
t->m_TEX0.TBW = bw;
t->m_dirty.push_back(GSDirtyRect(GSVector4i(r.left, r.top - y, r.right, r.bottom - y), psm, bw));
continue;
}
}
@ -945,8 +945,8 @@ void GSTextureCache::InvalidateVideoMem(const GSOffset& off, const GSVector4i& r
t->m_TEX0.TBP0, t->m_end_block,
r.left, r.top + y, r.right, r.bottom + y, bw);
t->m_dirty.push_back(GSDirtyRect(GSVector4i(r.left, r.top + y, r.right, r.bottom + y), psm));
t->m_TEX0.TBW = bw;
t->m_dirty.push_back(GSDirtyRect(GSVector4i(r.left, r.top + y, r.right, r.bottom + y), psm, bw));
continue;
}
}