2010-11-18 02:21:26 +00:00
|
|
|
|
|
|
|
#include "MainBase.h"
|
|
|
|
#include "VideoState.h"
|
|
|
|
#include "VideoConfig.h"
|
|
|
|
#include "RenderBase.h"
|
|
|
|
#include "FramebufferManagerBase.h"
|
|
|
|
#include "TextureCacheBase.h"
|
2010-12-16 18:21:14 +00:00
|
|
|
#include "VertexLoaderManager.h"
|
2010-11-18 02:21:26 +00:00
|
|
|
#include "CommandProcessor.h"
|
|
|
|
#include "PixelEngine.h"
|
|
|
|
#include "Atomic.h"
|
|
|
|
#include "Fifo.h"
|
2010-12-16 18:21:14 +00:00
|
|
|
#include "BPStructs.h"
|
2010-11-18 02:21:26 +00:00
|
|
|
#include "OnScreenDisplay.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "VideoBackendBase.h"
|
|
|
|
#include "ConfigManager.h"
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2011-02-14 02:18:03 +00:00
|
|
|
bool s_BackendInitialized = false;
|
2010-11-18 02:21:26 +00:00
|
|
|
|
|
|
|
volatile u32 s_swapRequested = false;
|
|
|
|
u32 s_efbAccessRequested = false;
|
|
|
|
volatile u32 s_FifoShuttingDown = false;
|
|
|
|
|
|
|
|
static volatile struct
|
|
|
|
{
|
|
|
|
u32 xfbAddr;
|
|
|
|
FieldType field;
|
|
|
|
u32 fbWidth;
|
|
|
|
u32 fbHeight;
|
|
|
|
} s_beginFieldArgs;
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
EFBAccessType type;
|
|
|
|
u32 x;
|
|
|
|
u32 y;
|
|
|
|
u32 Data;
|
|
|
|
} s_accessEFBArgs;
|
|
|
|
|
|
|
|
static u32 s_AccessEFBResult = 0;
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::EmuStateChange(EMUSTATE_CHANGE newState)
|
2010-11-18 02:21:26 +00: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-17 04:25:21 +00:00
|
|
|
EmulatorState((newState == EMUSTATE_CHANGE_PLAY) ? true : false);
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enter and exit the video loop
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_EnterLoop()
|
2010-11-18 02:21:26 +00: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-17 04:25:21 +00:00
|
|
|
RunGpuLoop();
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_ExitLoop()
|
2010-11-18 02:21:26 +00: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-17 04:25:21 +00:00
|
|
|
ExitGpuLoop();
|
2010-11-18 02:21:26 +00:00
|
|
|
s_FifoShuttingDown = true;
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_SetRendering(bool bEnabled)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
Fifo_SetRendering(bEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the graphics thread (from Fifo.cpp)
|
|
|
|
void VideoFifo_CheckSwapRequest()
|
|
|
|
{
|
|
|
|
if(g_ActiveConfig.bUseXFB)
|
|
|
|
{
|
|
|
|
if (Common::AtomicLoadAcquire(s_swapRequested))
|
|
|
|
{
|
|
|
|
EFBRectangle rc;
|
|
|
|
g_renderer->Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.field, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight,rc);
|
2011-02-02 04:40:27 +00:00
|
|
|
Common::AtomicStoreRelease(s_swapRequested, false);
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the graphics thread (from Fifo.cpp)
|
|
|
|
void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
|
|
|
|
{
|
|
|
|
if (g_ActiveConfig.bUseXFB)
|
|
|
|
{
|
|
|
|
if(Common::AtomicLoadAcquire(s_swapRequested))
|
|
|
|
{
|
|
|
|
u32 aLower = xfbAddr;
|
|
|
|
u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight;
|
|
|
|
u32 bLower = s_beginFieldArgs.xfbAddr;
|
|
|
|
u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight;
|
|
|
|
|
|
|
|
if (addrRangesOverlap(aLower, aUpper, bLower, bUpper))
|
|
|
|
VideoFifo_CheckSwapRequest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-02-14 02:18:03 +00:00
|
|
|
if (s_BackendInitialized && g_ActiveConfig.bUseXFB)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
2010-11-18 02:21:26 +00:00
|
|
|
VideoFifo_CheckSwapRequest();
|
|
|
|
s_beginFieldArgs.xfbAddr = xfbAddr;
|
|
|
|
s_beginFieldArgs.field = field;
|
|
|
|
s_beginFieldArgs.fbWidth = fbWidth;
|
|
|
|
s_beginFieldArgs.fbHeight = fbHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_EndField()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-02-14 02:18:03 +00:00
|
|
|
if (s_BackendInitialized)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-02-02 04:40:27 +00:00
|
|
|
Common::AtomicStoreRelease(s_swapRequested, true);
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_AddMessage(const char* pstr, u32 milliseconds)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
OSD::AddMessage(pstr, milliseconds);
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_ClearMessages()
|
2011-02-02 04:40:27 +00:00
|
|
|
{
|
|
|
|
OSD::ClearMessages();
|
|
|
|
}
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
// Screenshot
|
2011-03-16 22:48:17 +00:00
|
|
|
bool VideoBackendHardware::Video_Screenshot(const char *_szFilename)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
Renderer::SetScreenshot(_szFilename);
|
2011-01-31 01:28:32 +00:00
|
|
|
return true;
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoFifo_CheckEFBAccess()
|
|
|
|
{
|
|
|
|
if (Common::AtomicLoadAcquire(s_efbAccessRequested))
|
|
|
|
{
|
|
|
|
s_AccessEFBResult = g_renderer->AccessEFB(s_accessEFBArgs.type, s_accessEFBArgs.x, s_accessEFBArgs.y, s_accessEFBArgs.Data);
|
|
|
|
|
2011-02-02 04:40:27 +00:00
|
|
|
Common::AtomicStoreRelease(s_efbAccessRequested, false);
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-02-14 02:18:03 +00:00
|
|
|
if (s_BackendInitialized)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
s_accessEFBArgs.type = type;
|
|
|
|
s_accessEFBArgs.x = x;
|
|
|
|
s_accessEFBArgs.y = y;
|
|
|
|
s_accessEFBArgs.Data = InputData;
|
|
|
|
|
2011-02-02 04:40:27 +00:00
|
|
|
Common::AtomicStoreRelease(s_efbAccessRequested, true);
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
while (Common::AtomicLoadAcquire(s_efbAccessRequested) && !s_FifoShuttingDown)
|
|
|
|
//Common::SleepCurrentThread(1);
|
|
|
|
Common::YieldCPU();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
VideoFifo_CheckEFBAccess();
|
|
|
|
|
|
|
|
return s_AccessEFBResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-31 04:16:12 +00:00
|
|
|
|
2012-01-02 10:20:22 +00:00
|
|
|
void VideoBackendHardware::InitializeShared()
|
|
|
|
{
|
|
|
|
VideoCommon_Init();
|
|
|
|
|
|
|
|
s_swapRequested = 0;
|
|
|
|
s_efbAccessRequested = 0;
|
|
|
|
s_FifoShuttingDown = 0;
|
|
|
|
memset((void*)&s_beginFieldArgs, 0, sizeof(s_beginFieldArgs));
|
|
|
|
memset(&s_accessEFBArgs, 0, sizeof(s_accessEFBArgs));
|
|
|
|
s_AccessEFBResult = 0;
|
2012-12-23 12:32:23 +00:00
|
|
|
m_invalid = false;
|
2012-01-02 10:20:22 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 04:16:12 +00:00
|
|
|
// Run from the CPU thread
|
|
|
|
void VideoBackendHardware::DoState(PointerWrap& p)
|
2011-02-08 10:37:47 +00:00
|
|
|
{
|
2011-12-31 04:16:12 +00:00
|
|
|
VideoCommon_DoState(p);
|
2012-01-01 21:52:31 +00: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 18:21:14 +00:00
|
|
|
|
2011-12-31 04:16:12 +00:00
|
|
|
// Refresh state.
|
|
|
|
if (p.GetMode() == PointerWrap::MODE_READ)
|
|
|
|
{
|
2012-12-23 12:32:23 +00:00
|
|
|
m_invalid = true;
|
2011-12-31 04:16:12 +00:00
|
|
|
RecomputeCachedArraybases();
|
2012-01-01 20:46:02 +00: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 18:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-23 12:32:23 +00:00
|
|
|
void VideoBackendHardware::CheckInvalidState() {
|
|
|
|
if (m_invalid)
|
|
|
|
{
|
|
|
|
m_invalid = false;
|
|
|
|
|
|
|
|
BPReload();
|
|
|
|
TextureCache::Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-31 04:16:12 +00:00
|
|
|
void VideoBackendHardware::PauseAndLock(bool doLock, bool unpauseOnUnlock)
|
2010-12-16 18:21:14 +00:00
|
|
|
{
|
2011-12-31 04:16:12 +00:00
|
|
|
Fifo_PauseAndLock(doLock, unpauseOnUnlock);
|
2011-02-08 10:37:47 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 04:16:12 +00:00
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::RunLoop(bool enable)
|
2011-02-08 10:37:47 +00:00
|
|
|
{
|
|
|
|
VideoCommon_RunLoop(enable);
|
2010-12-16 18:21:14 +00:00
|
|
|
}
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
void VideoFifo_CheckAsyncRequest()
|
|
|
|
{
|
|
|
|
VideoFifo_CheckSwapRequest();
|
|
|
|
VideoFifo_CheckEFBAccess();
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_GatherPipeBursted()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
CommandProcessor::GatherPipeBursted();
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
bool VideoBackendHardware::Video_IsPossibleWaitingSetDrawDone()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-02-10 04:47:02 +00:00
|
|
|
return CommandProcessor::isPossibleWaitingSetDrawDone;
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 05:40:10 +00:00
|
|
|
bool VideoBackendHardware::Video_IsHiWatermarkActive()
|
|
|
|
{
|
|
|
|
return CommandProcessor::isHiWatermarkActive;
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoBackendHardware::Video_AbortFrame()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
CommandProcessor::AbortFrame();
|
|
|
|
}
|
2011-03-16 22:48:17 +00:00
|
|
|
|
|
|
|
readFn16 VideoBackendHardware::Video_CPRead16()
|
|
|
|
{
|
|
|
|
return CommandProcessor::Read16;
|
|
|
|
}
|
|
|
|
writeFn16 VideoBackendHardware::Video_CPWrite16()
|
|
|
|
{
|
|
|
|
return CommandProcessor::Write16;
|
|
|
|
}
|
|
|
|
|
|
|
|
readFn16 VideoBackendHardware::Video_PERead16()
|
|
|
|
{
|
|
|
|
return PixelEngine::Read16;
|
|
|
|
}
|
|
|
|
writeFn16 VideoBackendHardware::Video_PEWrite16()
|
|
|
|
{
|
|
|
|
return PixelEngine::Write16;
|
|
|
|
}
|
|
|
|
writeFn32 VideoBackendHardware::Video_PEWrite32()
|
|
|
|
{
|
|
|
|
return PixelEngine::Write32;
|
|
|
|
}
|