GS: Fix ReadTexture on unaligned reads

No longer reads out of bounds
This commit is contained in:
TellowKrinkle 2022-04-27 00:47:56 -05:00 committed by refractionpcsx2
parent 59531f005e
commit 8e23d8d557
1 changed files with 13 additions and 9 deletions

View File

@ -1670,15 +1670,9 @@ void GSLocalMemory::ReadTexture(const GSOffset& off, const GSVector4i& r, u8* ds
}
else
{
for (int y = r.top; y < cr.top; y++, dst += dstpitch)
{
for (int x = r.left, i = 0; x < r.right; x++, i++)
{
((u32*)dst)[i] = (this->*rt)(x, y, TEX0, TEXA);
}
}
u8* crdst = dst;
for (int y = cr.bottom; y < r.bottom; y++, dst += dstpitch)
for (int y = r.top; y < cr.top; y++, dst += dstpitch)
{
for (int x = r.left, i = 0; x < r.right; x++, i++)
{
@ -1699,9 +1693,19 @@ void GSLocalMemory::ReadTexture(const GSOffset& off, const GSVector4i& r, u8* ds
}
}
for (int y = cr.bottom; y < r.bottom; y++, dst += dstpitch)
{
for (int x = r.left, i = 0; x < r.right; x++, i++)
{
((u32*)dst)[i] = (this->*rt)(x, y, TEX0, TEXA);
}
}
if (!cr.rempty())
{
(this->*rtx)(off, cr, dst + (cr.left - r.left) * sizeof(u32), dstpitch, TEXA);
crdst += dstpitch * (cr.top - r.top);
crdst += sizeof(u32) * (cr.left - r.left);
(this->*rtx)(off, cr, crdst, dstpitch, TEXA);
}
}
}