2014-08-24 17:13:46 -06:00
|
|
|
#include "Common/Event.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
|
2014-11-13 15:26:49 -07:00
|
|
|
#include "VideoCommon/BoundingBox.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/BPStructs.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
|
|
|
#include "VideoCommon/Fifo.h"
|
|
|
|
#include "VideoCommon/FramebufferManagerBase.h"
|
|
|
|
#include "VideoCommon/MainBase.h"
|
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
|
|
#include "VideoCommon/PixelEngine.h"
|
|
|
|
#include "VideoCommon/RenderBase.h"
|
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
#include "VideoCommon/VideoState.h"
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2011-02-13 19:18:03 -07:00
|
|
|
bool s_BackendInitialized = false;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-08-24 17:13:46 -06:00
|
|
|
Common::Flag s_swapRequested;
|
|
|
|
static Common::Flag s_FifoShuttingDown;
|
|
|
|
static Common::Flag s_efbAccessRequested;
|
|
|
|
static Common::Event s_efbAccessReadyEvent;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-08-24 17:13:46 -06:00
|
|
|
static Common::Flag s_perfQueryRequested;
|
|
|
|
static Common::Event s_perfQueryReadyEvent;
|
2013-02-16 16:50:40 -07:00
|
|
|
|
2014-11-13 15:26:49 -07:00
|
|
|
static Common::Flag s_BBoxRequested;
|
|
|
|
static Common::Event s_BBoxReadyEvent;
|
|
|
|
static int s_BBoxIndex;
|
|
|
|
static u16 s_BBoxResult;
|
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
static volatile struct
|
|
|
|
{
|
|
|
|
u32 xfbAddr;
|
|
|
|
u32 fbWidth;
|
2014-05-02 01:08:44 -06:00
|
|
|
u32 fbStride;
|
2010-11-17 19:21:26 -07:00
|
|
|
u32 fbHeight;
|
|
|
|
} s_beginFieldArgs;
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
EFBAccessType type;
|
|
|
|
u32 x;
|
|
|
|
u32 y;
|
|
|
|
u32 Data;
|
|
|
|
} s_accessEFBArgs;
|
|
|
|
|
|
|
|
static u32 s_AccessEFBResult = 0;
|
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::EmuStateChange(EMUSTATE_CHANGE newState)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
Big Fifo Commit Part2: Now the fifo is more stable than my first commit, so is time...
- ReImplementing Single Core Mode like Dual Core Mode Style.
- Stage 1: My goal is, we have the Fifo, CommandProccessor code the more clear, maintenible and documented possible. When I quit dolphin I want any developer can continue with the work only reading the code.
* Big Refactoring: A lot of functions was changed the names, and modularized.
Now the FifoLoop and CatchUpGPU does not exist, was replaced by RunGpu() and RunGpuLoop().
The general idea is modeling the code like the real HW. The fifo is only a buffer where the Write Gather Pipe write the commands and from the Graphic Processor read these.
* Big Clean UP a lot of obsolete code and comments was deleted, like DcFakeWachDog, "Fifo very soon hack", etc.
In the stage 2, I will refactoring more code doing emphasis in the division of CommandProcessor, Fifo, Gpu Emulation. Beside I will comment all functions and variables in the code (Don't worry I will ask for English help for this part ;) )
Please test a lot SC mode and DC mode :)
Thank you so much for testing always and the patience. I don't like broke your favorite game but... you must believe me this part is very sensible, I only try to contribute for have a better and stable dolphin emulator.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7185 8ced0084-cf51-0410-be5f-012b33b47a6e
2011-02-16 21:25:21 -07:00
|
|
|
EmulatorState((newState == EMUSTATE_CHANGE_PLAY) ? true : false);
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enter and exit the video loop
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::Video_EnterLoop()
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
Big Fifo Commit Part2: Now the fifo is more stable than my first commit, so is time...
- ReImplementing Single Core Mode like Dual Core Mode Style.
- Stage 1: My goal is, we have the Fifo, CommandProccessor code the more clear, maintenible and documented possible. When I quit dolphin I want any developer can continue with the work only reading the code.
* Big Refactoring: A lot of functions was changed the names, and modularized.
Now the FifoLoop and CatchUpGPU does not exist, was replaced by RunGpu() and RunGpuLoop().
The general idea is modeling the code like the real HW. The fifo is only a buffer where the Write Gather Pipe write the commands and from the Graphic Processor read these.
* Big Clean UP a lot of obsolete code and comments was deleted, like DcFakeWachDog, "Fifo very soon hack", etc.
In the stage 2, I will refactoring more code doing emphasis in the division of CommandProcessor, Fifo, Gpu Emulation. Beside I will comment all functions and variables in the code (Don't worry I will ask for English help for this part ;) )
Please test a lot SC mode and DC mode :)
Thank you so much for testing always and the patience. I don't like broke your favorite game but... you must believe me this part is very sensible, I only try to contribute for have a better and stable dolphin emulator.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7185 8ced0084-cf51-0410-be5f-012b33b47a6e
2011-02-16 21:25:21 -07:00
|
|
|
RunGpuLoop();
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::Video_ExitLoop()
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
Big Fifo Commit Part2: Now the fifo is more stable than my first commit, so is time...
- ReImplementing Single Core Mode like Dual Core Mode Style.
- Stage 1: My goal is, we have the Fifo, CommandProccessor code the more clear, maintenible and documented possible. When I quit dolphin I want any developer can continue with the work only reading the code.
* Big Refactoring: A lot of functions was changed the names, and modularized.
Now the FifoLoop and CatchUpGPU does not exist, was replaced by RunGpu() and RunGpuLoop().
The general idea is modeling the code like the real HW. The fifo is only a buffer where the Write Gather Pipe write the commands and from the Graphic Processor read these.
* Big Clean UP a lot of obsolete code and comments was deleted, like DcFakeWachDog, "Fifo very soon hack", etc.
In the stage 2, I will refactoring more code doing emphasis in the division of CommandProcessor, Fifo, Gpu Emulation. Beside I will comment all functions and variables in the code (Don't worry I will ask for English help for this part ;) )
Please test a lot SC mode and DC mode :)
Thank you so much for testing always and the patience. I don't like broke your favorite game but... you must believe me this part is very sensible, I only try to contribute for have a better and stable dolphin emulator.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7185 8ced0084-cf51-0410-be5f-012b33b47a6e
2011-02-16 21:25:21 -07:00
|
|
|
ExitGpuLoop();
|
2014-08-24 17:13:46 -06:00
|
|
|
s_FifoShuttingDown.Set();
|
|
|
|
s_efbAccessReadyEvent.Set();
|
|
|
|
s_perfQueryReadyEvent.Set();
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::Video_SetRendering(bool bEnabled)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
|
|
|
Fifo_SetRendering(bEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the graphics thread (from Fifo.cpp)
|
2014-07-08 06:29:26 -06:00
|
|
|
static void VideoFifo_CheckSwapRequest()
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2014-03-10 05:30:55 -06:00
|
|
|
if (g_ActiveConfig.bUseXFB)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2014-08-24 17:13:46 -06:00
|
|
|
if (s_swapRequested.IsSet())
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
|
|
|
EFBRectangle rc;
|
2014-05-02 01:08:44 -06:00
|
|
|
Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbStride, s_beginFieldArgs.fbHeight, rc);
|
2014-08-24 17:13:46 -06:00
|
|
|
s_swapRequested.Clear();
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the graphics thread (from Fifo.cpp)
|
|
|
|
void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
|
|
|
|
{
|
|
|
|
if (g_ActiveConfig.bUseXFB)
|
|
|
|
{
|
2014-08-24 17:13:46 -06:00
|
|
|
if (s_swapRequested.IsSet())
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
|
|
|
u32 aLower = xfbAddr;
|
|
|
|
u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight;
|
|
|
|
u32 bLower = s_beginFieldArgs.xfbAddr;
|
2014-05-02 01:08:44 -06:00
|
|
|
u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbStride * s_beginFieldArgs.fbHeight;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-09-20 12:54:59 -06:00
|
|
|
if (AddressRangesOverlap(aLower, aUpper, bLower, bUpper))
|
2010-11-17 19:21:26 -07:00
|
|
|
VideoFifo_CheckSwapRequest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2014-05-02 01:08:44 -06:00
|
|
|
void VideoBackendHardware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2011-02-13 19:18:03 -07:00
|
|
|
if (s_BackendInitialized && g_ActiveConfig.bUseXFB)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2011-01-30 18:28:32 -07:00
|
|
|
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
2010-11-17 19:21:26 -07:00
|
|
|
VideoFifo_CheckSwapRequest();
|
|
|
|
s_beginFieldArgs.xfbAddr = xfbAddr;
|
|
|
|
s_beginFieldArgs.fbWidth = fbWidth;
|
2014-05-02 01:08:44 -06:00
|
|
|
s_beginFieldArgs.fbStride = fbStride;
|
2010-11-17 19:21:26 -07:00
|
|
|
s_beginFieldArgs.fbHeight = fbHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::Video_EndField()
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2011-02-13 19:18:03 -07:00
|
|
|
if (s_BackendInitialized)
|
2010-11-17 19:21:26 -07: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-27 20:56:19 -06:00
|
|
|
SyncGPU(SYNC_GPU_SWAP);
|
2014-08-24 17:13:46 -06:00
|
|
|
s_swapRequested.Set();
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
void VideoBackendHardware::Video_AddMessage(const std::string& msg, u32 milliseconds)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2014-03-12 13:33:41 -06:00
|
|
|
OSD::AddMessage(msg, milliseconds);
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::Video_ClearMessages()
|
2011-02-01 21:40:27 -07:00
|
|
|
{
|
|
|
|
OSD::ClearMessages();
|
|
|
|
}
|
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
// Screenshot
|
2014-03-12 13:33:41 -06:00
|
|
|
bool VideoBackendHardware::Video_Screenshot(const std::string& filename)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2014-03-12 13:33:41 -06:00
|
|
|
Renderer::SetScreenshot(filename.c_str());
|
2011-01-30 18:28:32 -07:00
|
|
|
return true;
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoFifo_CheckEFBAccess()
|
|
|
|
{
|
2014-08-24 17:13:46 -06:00
|
|
|
if (s_efbAccessRequested.IsSet())
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
|
|
|
s_AccessEFBResult = g_renderer->AccessEFB(s_accessEFBArgs.type, s_accessEFBArgs.x, s_accessEFBArgs.y, s_accessEFBArgs.Data);
|
2014-08-24 17:13:46 -06:00
|
|
|
s_efbAccessRequested.Clear();
|
|
|
|
s_efbAccessReadyEvent.Set();
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2014-01-09 10:37:59 -07:00
|
|
|
if (s_BackendInitialized && g_ActiveConfig.bEFBAccessEnable)
|
2010-11-17 19:21:26 -07: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-27 20:56:19 -06:00
|
|
|
SyncGPU(SYNC_GPU_EFB_POKE);
|
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
s_accessEFBArgs.type = type;
|
|
|
|
s_accessEFBArgs.x = x;
|
|
|
|
s_accessEFBArgs.y = y;
|
|
|
|
s_accessEFBArgs.Data = InputData;
|
|
|
|
|
2014-08-24 17:13:46 -06:00
|
|
|
s_efbAccessRequested.Set();
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2014-08-24 17:13:46 -06:00
|
|
|
s_efbAccessReadyEvent.Reset();
|
|
|
|
if (s_FifoShuttingDown.IsSet())
|
|
|
|
return 0;
|
|
|
|
s_efbAccessRequested.Set();
|
|
|
|
s_efbAccessReadyEvent.Wait();
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
VideoFifo_CheckEFBAccess();
|
|
|
|
|
|
|
|
return s_AccessEFBResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-08 06:29:26 -06:00
|
|
|
static void VideoFifo_CheckPerfQueryRequest()
|
2013-02-16 16:50:40 -07:00
|
|
|
{
|
2014-08-24 17:13:46 -06:00
|
|
|
if (s_perfQueryRequested.IsSet())
|
2013-02-16 16:50:40 -07:00
|
|
|
{
|
|
|
|
g_perf_query->FlushResults();
|
2014-08-24 17:13:46 -06:00
|
|
|
s_perfQueryRequested.Clear();
|
|
|
|
s_perfQueryReadyEvent.Set();
|
2013-02-16 16:50:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
|
|
|
|
{
|
2014-03-10 05:30:55 -06:00
|
|
|
if (!g_perf_query->ShouldEmulate())
|
2014-01-09 10:37:59 -07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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-27 20:56:19 -06:00
|
|
|
SyncGPU(SYNC_GPU_PERFQUERY);
|
|
|
|
|
2013-03-01 15:02:11 -07:00
|
|
|
// TODO: Is this check sane?
|
2013-02-16 16:50:40 -07:00
|
|
|
if (!g_perf_query->IsFlushed())
|
|
|
|
{
|
|
|
|
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
|
|
|
{
|
2014-08-24 17:13:46 -06:00
|
|
|
s_perfQueryReadyEvent.Reset();
|
|
|
|
if (s_FifoShuttingDown.IsSet())
|
|
|
|
return 0;
|
|
|
|
s_perfQueryRequested.Set();
|
|
|
|
s_perfQueryReadyEvent.Wait();
|
2013-02-16 16:50:40 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_perf_query->FlushResults();
|
|
|
|
}
|
2013-03-01 15:02:11 -07:00
|
|
|
|
2013-02-16 16:50:40 -07:00
|
|
|
return g_perf_query->GetQueryResult(type);
|
|
|
|
}
|
2011-12-30 21:16:12 -07:00
|
|
|
|
2014-11-13 15:26:49 -07:00
|
|
|
u16 VideoBackendHardware::Video_GetBoundingBox(int index)
|
|
|
|
{
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsBBox)
|
|
|
|
return BoundingBox::coords[index];
|
|
|
|
|
|
|
|
SyncGPU(SYNC_GPU_BBOX);
|
|
|
|
|
|
|
|
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
|
|
|
{
|
|
|
|
s_BBoxReadyEvent.Reset();
|
|
|
|
if (s_FifoShuttingDown.IsSet())
|
|
|
|
return 0;
|
|
|
|
s_BBoxIndex = index;
|
|
|
|
s_BBoxRequested.Set();
|
|
|
|
s_BBoxReadyEvent.Wait();
|
|
|
|
return s_BBoxResult;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return g_renderer->BBoxRead(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void VideoFifo_CheckBBoxRequest()
|
|
|
|
{
|
|
|
|
if (s_BBoxRequested.IsSet())
|
|
|
|
{
|
|
|
|
s_BBoxResult = g_renderer->BBoxRead(s_BBoxIndex);
|
|
|
|
s_BBoxRequested.Clear();
|
|
|
|
s_BBoxReadyEvent.Set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-02 03:20:22 -07:00
|
|
|
void VideoBackendHardware::InitializeShared()
|
|
|
|
{
|
|
|
|
VideoCommon_Init();
|
|
|
|
|
2014-08-24 17:13:46 -06:00
|
|
|
s_swapRequested.Clear();
|
|
|
|
s_efbAccessRequested.Clear();
|
|
|
|
s_perfQueryRequested.Clear();
|
|
|
|
s_FifoShuttingDown.Clear();
|
2012-01-02 03:20:22 -07:00
|
|
|
memset((void*)&s_beginFieldArgs, 0, sizeof(s_beginFieldArgs));
|
|
|
|
memset(&s_accessEFBArgs, 0, sizeof(s_accessEFBArgs));
|
|
|
|
s_AccessEFBResult = 0;
|
2012-12-23 05:32:23 -07:00
|
|
|
m_invalid = false;
|
2012-01-02 03:20:22 -07:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:16:12 -07:00
|
|
|
// Run from the CPU thread
|
|
|
|
void VideoBackendHardware::DoState(PointerWrap& p)
|
2011-02-08 03:37:47 -07:00
|
|
|
{
|
2013-02-26 16:28:56 -07:00
|
|
|
bool software = false;
|
|
|
|
p.Do(software);
|
2013-04-24 07:21:54 -06:00
|
|
|
|
2013-02-26 16:28:56 -07:00
|
|
|
if (p.GetMode() == PointerWrap::MODE_READ && software == true)
|
2013-04-24 07:21:54 -06:00
|
|
|
{
|
2013-02-26 16:28:56 -07:00
|
|
|
// change mode to abort load of incompatible save state.
|
|
|
|
p.SetMode(PointerWrap::MODE_VERIFY);
|
2013-04-24 07:21:54 -06:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:16:12 -07:00
|
|
|
VideoCommon_DoState(p);
|
2012-01-01 14:52:31 -07:00
|
|
|
p.DoMarker("VideoCommon");
|
|
|
|
|
|
|
|
p.Do(s_swapRequested);
|
|
|
|
p.Do(s_efbAccessRequested);
|
|
|
|
p.Do(s_beginFieldArgs);
|
|
|
|
p.Do(s_accessEFBArgs);
|
|
|
|
p.Do(s_AccessEFBResult);
|
|
|
|
p.DoMarker("VideoBackendHardware");
|
2010-12-16 11:21:14 -07:00
|
|
|
|
2011-12-30 21:16:12 -07:00
|
|
|
// Refresh state.
|
|
|
|
if (p.GetMode() == PointerWrap::MODE_READ)
|
|
|
|
{
|
2012-12-23 05:32:23 -07:00
|
|
|
m_invalid = true;
|
2011-12-30 21:16:12 -07:00
|
|
|
RecomputeCachedArraybases();
|
2012-01-01 13:46:02 -07:00
|
|
|
|
|
|
|
// Clear all caches that touch RAM
|
|
|
|
// (? these don't appear to touch any emulation state that gets saved. moved to on load only.)
|
|
|
|
VertexLoaderManager::MarkAllDirty();
|
2010-12-16 11:21:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 07:21:54 -06:00
|
|
|
void VideoBackendHardware::CheckInvalidState()
|
|
|
|
{
|
2012-12-23 05:32:23 -07:00
|
|
|
if (m_invalid)
|
|
|
|
{
|
|
|
|
m_invalid = false;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2012-12-23 05:32:23 -07:00
|
|
|
BPReload();
|
|
|
|
TextureCache::Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-30 21:16:12 -07:00
|
|
|
void VideoBackendHardware::PauseAndLock(bool doLock, bool unpauseOnUnlock)
|
2010-12-16 11:21:14 -07:00
|
|
|
{
|
2011-12-30 21:16:12 -07:00
|
|
|
Fifo_PauseAndLock(doLock, unpauseOnUnlock);
|
2011-02-08 03:37:47 -07:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:16:12 -07:00
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::RunLoop(bool enable)
|
2011-02-08 03:37:47 -07:00
|
|
|
{
|
|
|
|
VideoCommon_RunLoop(enable);
|
2010-12-16 11:21:14 -07:00
|
|
|
}
|
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
void VideoFifo_CheckAsyncRequest()
|
|
|
|
{
|
|
|
|
VideoFifo_CheckSwapRequest();
|
|
|
|
VideoFifo_CheckEFBAccess();
|
2013-02-16 16:50:40 -07:00
|
|
|
VideoFifo_CheckPerfQueryRequest();
|
2014-11-13 15:26:49 -07:00
|
|
|
VideoFifo_CheckBBoxRequest();
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
void VideoBackendHardware::Video_GatherPipeBursted()
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
|
|
|
CommandProcessor::GatherPipeBursted();
|
|
|
|
}
|
|
|
|
|
2011-03-16 16:48:17 -06:00
|
|
|
bool VideoBackendHardware::Video_IsPossibleWaitingSetDrawDone()
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2011-02-09 21:47:02 -07:00
|
|
|
return CommandProcessor::isPossibleWaitingSetDrawDone;
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
2014-02-02 06:16:43 -07:00
|
|
|
void VideoBackendHardware::RegisterCPMMIO(MMIO::Mapping* mmio, u32 base)
|
|
|
|
{
|
|
|
|
CommandProcessor::RegisterMMIO(mmio, base);
|
|
|
|
}
|
|
|
|
|
2014-09-06 15:26:40 -06:00
|
|
|
void VideoBackendHardware::UpdateWantDeterminism(bool want)
|
|
|
|
{
|
|
|
|
Fifo_UpdateWantDeterminism(want);
|
|
|
|
}
|
|
|
|
|