2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:09:55 +02:00
|
|
|
// Refer to the license.txt file included.
|
2009-03-07 09:35:01 +01:00
|
|
|
|
2016-01-17 22:54:31 +01:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
2017-03-03 20:43:52 +01:00
|
|
|
#include "Common/Swap.h"
|
|
|
|
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "Core/HW/Memmap.h"
|
2017-03-03 20:43:52 +01:00
|
|
|
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
2014-09-03 22:39:26 +02:00
|
|
|
#include "VideoCommon/DataReader.h"
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
#include "VideoCommon/Fifo.h"
|
2014-12-14 21:23:13 +01:00
|
|
|
#include "VideoCommon/GeometryShaderManager.h"
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
|
|
|
#include "VideoCommon/VertexManagerBase.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
|
|
|
#include "VideoCommon/XFMemory.h"
|
2009-03-07 09:35:01 +01:00
|
|
|
|
2014-07-08 14:29:26 +02:00
|
|
|
static void XFMemWritten(u32 transferSize, u32 baseAddress)
|
2011-02-05 19:25:34 +01:00
|
|
|
{
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2011-02-05 19:25:34 +01:00
|
|
|
VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
|
|
|
|
}
|
|
|
|
|
2014-11-27 23:53:11 +01:00
|
|
|
static void XFRegWritten(int transferSize, u32 baseAddress, DataReader src)
|
2009-03-07 09:35:01 +01:00
|
|
|
{
|
2011-02-05 19:25:34 +01:00
|
|
|
u32 address = baseAddress;
|
|
|
|
u32 dataIndex = 0;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
while (transferSize > 0 && address < 0x1058)
|
|
|
|
{
|
2014-11-27 23:53:11 +01:00
|
|
|
u32 newValue = src.Peek<u32>(dataIndex * sizeof(u32));
|
2011-02-05 19:25:34 +01:00
|
|
|
u32 nextAddress = address + 1;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
switch (address)
|
|
|
|
{
|
|
|
|
case XFMEM_ERROR:
|
|
|
|
case XFMEM_DIAG:
|
|
|
|
case XFMEM_STATE0: // internal state 0
|
|
|
|
case XFMEM_STATE1: // internal state 1
|
|
|
|
case XFMEM_CLOCK:
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETGPMETRIC:
|
|
|
|
nextAddress = 0x1007;
|
2013-03-20 02:51:12 +01:00
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_CLIPDISABLE:
|
2011-02-05 19:25:34 +01:00
|
|
|
// if (data & 1) {} // disable clipping detection
|
|
|
|
// if (data & 2) {} // disable trivial rejection
|
|
|
|
// if (data & 4) {} // disable cpoly clipping acceleration
|
2013-03-20 02:51:12 +01:00
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_VTXSPECS: //__GXXfVtxSpecs, wrote 0004
|
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_SETNUMCHAN:
|
2014-04-27 20:59:04 +02:00
|
|
|
if (xfmem.numChan.numColorChans != (newValue & 3))
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2017-07-20 07:25:27 +02:00
|
|
|
VertexShaderManager::SetLightingConfigChanged();
|
2013-03-20 02:51:12 +01:00
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETCHAN1_AMBCOLOR:
|
2009-11-19 03:28:41 +01:00
|
|
|
{
|
2011-02-05 19:25:34 +01:00
|
|
|
u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR;
|
2014-04-27 20:59:04 +02:00
|
|
|
if (xfmem.ambColor[chan] != newValue)
|
2009-07-26 11:52:35 +02:00
|
|
|
{
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2015-08-17 03:07:10 +02:00
|
|
|
VertexShaderManager::SetMaterialColorChanged(chan);
|
2013-03-20 02:51:12 +01:00
|
|
|
}
|
2011-02-05 19:25:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_SETCHAN0_MATCOLOR: // Channel Material Color
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETCHAN1_MATCOLOR:
|
|
|
|
{
|
|
|
|
u8 chan = address - XFMEM_SETCHAN0_MATCOLOR;
|
2014-04-27 20:59:04 +02:00
|
|
|
if (xfmem.matColor[chan] != newValue)
|
2009-07-26 11:52:35 +02:00
|
|
|
{
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2015-08-17 03:07:10 +02:00
|
|
|
VertexShaderManager::SetMaterialColorChanged(chan + 2);
|
2009-07-26 11:52:35 +02:00
|
|
|
}
|
2011-02-05 19:25:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_SETCHAN0_COLOR: // Channel Color
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETCHAN1_COLOR:
|
|
|
|
case XFMEM_SETCHAN0_ALPHA: // Channel Alpha
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_SETCHAN1_ALPHA:
|
2014-04-27 20:59:04 +02:00
|
|
|
if (((u32*)&xfmem)[address] != (newValue & 0x7fff))
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2017-07-20 07:25:27 +02:00
|
|
|
VertexShaderManager::SetLightingConfigChanged();
|
2011-02-05 19:25:34 +01:00
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_DUALTEX:
|
2014-04-27 20:59:04 +02:00
|
|
|
if (xfmem.dualTexTrans.enabled != (newValue & 1))
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2017-07-20 07:25:27 +02:00
|
|
|
VertexShaderManager::SetTexMatrixInfoChanged(-1);
|
2013-03-20 02:51:12 +01:00
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_SETMATRIXINDA:
|
2011-02-05 19:25:34 +01:00
|
|
|
VertexShaderManager::SetTexMatrixChangedA(newValue);
|
2013-03-20 02:51:12 +01:00
|
|
|
break;
|
|
|
|
case XFMEM_SETMATRIXINDB:
|
|
|
|
VertexShaderManager::SetTexMatrixChangedB(newValue);
|
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETVIEWPORT:
|
|
|
|
case XFMEM_SETVIEWPORT + 1:
|
|
|
|
case XFMEM_SETVIEWPORT + 2:
|
|
|
|
case XFMEM_SETVIEWPORT + 3:
|
|
|
|
case XFMEM_SETVIEWPORT + 4:
|
|
|
|
case XFMEM_SETVIEWPORT + 5:
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2012-11-19 21:09:31 +01:00
|
|
|
VertexShaderManager::SetViewportChanged();
|
|
|
|
PixelShaderManager::SetViewportChanged();
|
2014-12-14 21:23:13 +01:00
|
|
|
GeometryShaderManager::SetViewportChanged();
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2012-11-19 21:09:31 +01:00
|
|
|
nextAddress = XFMEM_SETVIEWPORT + 6;
|
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETPROJECTION:
|
|
|
|
case XFMEM_SETPROJECTION + 1:
|
|
|
|
case XFMEM_SETPROJECTION + 2:
|
|
|
|
case XFMEM_SETPROJECTION + 3:
|
|
|
|
case XFMEM_SETPROJECTION + 4:
|
|
|
|
case XFMEM_SETPROJECTION + 5:
|
|
|
|
case XFMEM_SETPROJECTION + 6:
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2012-11-19 21:09:31 +01:00
|
|
|
VertexShaderManager::SetProjectionChanged();
|
2014-12-14 21:23:13 +01:00
|
|
|
GeometryShaderManager::SetProjectionChanged();
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2012-11-19 21:09:31 +01:00
|
|
|
nextAddress = XFMEM_SETPROJECTION + 7;
|
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
|
2014-04-27 20:59:04 +02:00
|
|
|
if (xfmem.numTexGen.numTexGens != (newValue & 15))
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2013-03-20 02:51:12 +01:00
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETTEXMTXINFO:
|
|
|
|
case XFMEM_SETTEXMTXINFO + 1:
|
|
|
|
case XFMEM_SETTEXMTXINFO + 2:
|
|
|
|
case XFMEM_SETTEXMTXINFO + 3:
|
|
|
|
case XFMEM_SETTEXMTXINFO + 4:
|
|
|
|
case XFMEM_SETTEXMTXINFO + 5:
|
|
|
|
case XFMEM_SETTEXMTXINFO + 6:
|
|
|
|
case XFMEM_SETTEXMTXINFO + 7:
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2017-07-20 07:25:27 +02:00
|
|
|
VertexShaderManager::SetTexMatrixInfoChanged(address - XFMEM_SETTEXMTXINFO);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2012-11-19 21:09:31 +01:00
|
|
|
nextAddress = XFMEM_SETTEXMTXINFO + 8;
|
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
case XFMEM_SETPOSMTXINFO:
|
|
|
|
case XFMEM_SETPOSMTXINFO + 1:
|
|
|
|
case XFMEM_SETPOSMTXINFO + 2:
|
|
|
|
case XFMEM_SETPOSMTXINFO + 3:
|
|
|
|
case XFMEM_SETPOSMTXINFO + 4:
|
|
|
|
case XFMEM_SETPOSMTXINFO + 5:
|
|
|
|
case XFMEM_SETPOSMTXINFO + 6:
|
|
|
|
case XFMEM_SETPOSMTXINFO + 7:
|
2016-08-22 05:02:37 +02:00
|
|
|
g_vertex_manager->Flush();
|
2017-07-20 07:25:27 +02:00
|
|
|
VertexShaderManager::SetTexMatrixInfoChanged(address - XFMEM_SETPOSMTXINFO);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2012-11-19 21:09:31 +01:00
|
|
|
nextAddress = XFMEM_SETPOSMTXINFO + 8;
|
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
// --------------
|
|
|
|
// Unknown Regs
|
|
|
|
// --------------
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
// Maybe these are for Normals?
|
2014-04-27 20:59:04 +02:00
|
|
|
case 0x1048: // xfmem.texcoords[0].nrmmtxinfo.hex = data; break; ??
|
2013-03-20 02:51:12 +01:00
|
|
|
case 0x1049:
|
|
|
|
case 0x104a:
|
|
|
|
case 0x104b:
|
|
|
|
case 0x104c:
|
|
|
|
case 0x104d:
|
|
|
|
case 0x104e:
|
|
|
|
case 0x104f:
|
2013-08-21 00:19:50 +02:00
|
|
|
DEBUG_LOG(VIDEO, "Possible Normal Mtx XF reg?: %x=%x", address, newValue);
|
2011-02-05 19:25:34 +01:00
|
|
|
break;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
case 0x1013:
|
2013-03-20 02:51:12 +01:00
|
|
|
case 0x1014:
|
|
|
|
case 0x1015:
|
|
|
|
case 0x1016:
|
|
|
|
case 0x1017:
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
default:
|
2015-11-08 02:17:12 +01:00
|
|
|
if (newValue != 0) // Ignore writes of zero.
|
|
|
|
WARN_LOG(VIDEO, "Unknown XF Reg: %x=%x", address, newValue);
|
2013-03-20 02:51:12 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
int transferred = nextAddress - address;
|
|
|
|
address = nextAddress;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
transferSize -= transferred;
|
|
|
|
dataIndex += transferred;
|
2013-03-20 02:51:12 +01:00
|
|
|
}
|
2011-02-05 19:25:34 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 23:53:11 +01:00
|
|
|
void LoadXFReg(u32 transferSize, u32 baseAddress, DataReader src)
|
2011-02-05 19:25:34 +01:00
|
|
|
{
|
2013-03-20 02:51:12 +01:00
|
|
|
// do not allow writes past registers
|
|
|
|
if (baseAddress + transferSize > 0x1058)
|
|
|
|
{
|
2016-09-25 01:06:47 +02:00
|
|
|
WARN_LOG(VIDEO, "XF load exceeds address space: %x %d bytes", baseAddress, transferSize);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-03-20 02:51:12 +01:00
|
|
|
if (baseAddress >= 0x1058)
|
|
|
|
transferSize = 0;
|
|
|
|
else
|
|
|
|
transferSize = 0x1058 - baseAddress;
|
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
// write to XF mem
|
|
|
|
if (baseAddress < 0x1000 && transferSize > 0)
|
|
|
|
{
|
|
|
|
u32 end = baseAddress + transferSize;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
u32 xfMemBase = baseAddress;
|
|
|
|
u32 xfMemTransferSize = transferSize;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
if (end >= 0x1000)
|
|
|
|
{
|
|
|
|
xfMemTransferSize = 0x1000 - baseAddress;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
baseAddress = 0x1000;
|
|
|
|
transferSize = end - 0x1000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
transferSize = 0;
|
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2012-11-19 21:09:31 +01:00
|
|
|
XFMemWritten(xfMemTransferSize, xfMemBase);
|
2014-09-03 22:39:26 +02:00
|
|
|
for (u32 i = 0; i < xfMemTransferSize; i++)
|
|
|
|
{
|
2014-11-27 23:53:11 +01:00
|
|
|
((u32*)&xfmem)[xfMemBase + i] = src.Read<u32>();
|
2014-09-03 22:39:26 +02:00
|
|
|
}
|
2011-02-05 19:25:34 +01:00
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-02-05 19:25:34 +01:00
|
|
|
// write to XF regs
|
2013-03-20 02:51:12 +01:00
|
|
|
if (transferSize > 0)
|
2013-10-29 06:23:17 +01:00
|
|
|
{
|
2014-11-27 23:53:11 +01:00
|
|
|
XFRegWritten(transferSize, baseAddress, src);
|
2014-09-03 22:39:26 +02:00
|
|
|
for (u32 i = 0; i < transferSize; i++)
|
|
|
|
{
|
2014-11-27 23:53:11 +01:00
|
|
|
((u32*)&xfmem)[baseAddress + i] = src.Read<u32>();
|
2014-09-03 22:39:26 +02:00
|
|
|
}
|
2013-03-20 02:51:12 +01:00
|
|
|
}
|
2009-03-07 09:35:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO - verify that it is correct. Seems to work, though.
|
2011-05-25 20:14:29 +02:00
|
|
|
void LoadIndexedXF(u32 val, int refarray)
|
2009-03-07 09:35:01 +01:00
|
|
|
{
|
2012-05-19 10:54:40 +02:00
|
|
|
int index = val >> 16;
|
|
|
|
int address = val & 0xFFF; // check mask
|
|
|
|
int size = ((val >> 12) & 0xF) + 1;
|
|
|
|
// load stuff from array to address in xf mem
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2014-04-27 20:59:04 +02:00
|
|
|
u32* currData = (u32*)(&xfmem) + address;
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
u32* newData;
|
2016-01-24 05:31:13 +01:00
|
|
|
if (Fifo::UseDeterministicGPUThread())
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
{
|
2016-01-12 22:44:58 +01:00
|
|
|
newData = (u32*)Fifo::PopFifoAuxBuffer(size * sizeof(u32));
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newData = (u32*)Memory::GetPointer(g_main_cp_state.array_bases[refarray] +
|
|
|
|
g_main_cp_state.array_strides[refarray] * index);
|
|
|
|
}
|
2012-05-20 22:16:21 +02:00
|
|
|
bool changed = false;
|
|
|
|
for (int i = 0; i < size; ++i)
|
2012-05-19 10:54:40 +02:00
|
|
|
{
|
2012-05-20 22:16:21 +02:00
|
|
|
if (currData[i] != Common::swap32(newData[i]))
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
XFMemWritten(size, address);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < size; ++i)
|
|
|
|
currData[i] = Common::swap32(newData[i]);
|
2012-05-19 10:54:40 +02:00
|
|
|
}
|
2009-03-07 09:35:01 +01:00
|
|
|
}
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
|
|
|
|
void PreprocessIndexedXF(u32 val, int refarray)
|
|
|
|
{
|
2017-03-27 05:09:28 +02:00
|
|
|
const u32 index = val >> 16;
|
|
|
|
const u32 size = ((val >> 12) & 0xF) + 1;
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
|
2017-03-27 05:09:28 +02:00
|
|
|
const u8* new_data = Memory::GetPointer(g_preprocess_cp_state.array_bases[refarray] +
|
|
|
|
g_preprocess_cp_state.array_strides[refarray] * index);
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
|
2017-03-27 02:38:19 +02:00
|
|
|
const size_t buf_size = size * sizeof(u32);
|
2016-01-12 22:44:58 +01:00
|
|
|
Fifo::PushFifoAuxBuffer(new_data, buf_size);
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 04:56:19 +02:00
|
|
|
}
|