GS: Avoid modifying single QW downloads as they go to a register

Also avoid downloading more than requested
This commit is contained in:
refractionpcsx2 2023-04-06 21:43:54 +01:00
parent 631f75a79c
commit bbe22f95d1
2 changed files with 10 additions and 5 deletions

View File

@ -1008,11 +1008,11 @@ void GSLocalMemoryFunctions::ReadImageX(const GSLocalMemory& mem, int& tx, int&
{ {
const int length = len / 3; const int length = len / 3;
const int aligned_length = (len + 2) / 3; const int aligned_length = (len + 2) / 3;
if (length != aligned_length) if ((length * 3) != len)
{ {
offset = 3 - (len - (length * 3)); offset = (len - (length * 3));
} }
readWriteHelper(mem.vm32(), tx, ty, aligned_length, 1, sx, w, off.assertSizesMatch(GSLocalMemory::swizzle32), [&](auto& pa, int x) readWriteHelper(mem.vm32(), tx, ty, length, 1, sx, w, off.assertSizesMatch(GSLocalMemory::swizzle32), [&](auto& pa, int x)
{ {
u32 c = *pa.value(x); u32 c = *pa.value(x);
pb[0] = (u8)(c); pb[0] = (u8)(c);

View File

@ -1804,8 +1804,13 @@ void GSState::Read(u8* mem, int len)
if (!m_tr.Update(w, h, bpp, len)) if (!m_tr.Update(w, h, bpp, len))
return; return;
mem += m_tr.offset; // If it's 1 QW the destination is likely a register, so don't mess with this, else it can cause stack corruption.
len -= m_tr.offset; // TODO: Change the FIFO downloads to just read off the whole transfer from memory to a temp buffer so we can read it in byte level chunks.
if (len > 16)
{
mem -= m_tr.offset;
len += m_tr.offset;
}
m_mem.ReadImageX(m_tr.x, m_tr.y, m_tr.offset, mem, len, m_env.BITBLTBUF, m_env.TRXPOS, m_env.TRXREG); m_mem.ReadImageX(m_tr.x, m_tr.y, m_tr.offset, mem, len, m_env.BITBLTBUF, m_env.TRXPOS, m_env.TRXREG);
if (GSConfig.DumpGSData && GSConfig.SaveRT && s_n >= GSConfig.SaveN) if (GSConfig.DumpGSData && GSConfig.SaveRT && s_n >= GSConfig.SaveN)