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
|
|
|
|
|
|
|
bool s_PluginInitialized = false;
|
|
|
|
|
|
|
|
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-02-02 04:40:27 +00:00
|
|
|
void VideoBackendHLE::EmuStateChange(EMUSTATE_CHANGE newState)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-02-02 04:40:27 +00:00
|
|
|
Fifo_RunLoop((newState == EMUSTATE_CHANGE_PLAY) ? true : false);
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enter and exit the video loop
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::Video_EnterLoop()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
Fifo_EnterLoop();
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::Video_ExitLoop()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
Fifo_ExitLoop();
|
|
|
|
s_FifoShuttingDown = true;
|
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::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-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
if (s_PluginInitialized && g_ActiveConfig.bUseXFB)
|
|
|
|
{
|
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-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::Video_EndField()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
if (s_PluginInitialized)
|
|
|
|
{
|
2011-02-02 04:40:27 +00:00
|
|
|
Common::AtomicStoreRelease(s_swapRequested, true);
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::Video_AddMessage(const char* pstr, u32 milliseconds)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
OSD::AddMessage(pstr, milliseconds);
|
|
|
|
}
|
|
|
|
|
2011-02-02 04:40:27 +00:00
|
|
|
void VideoBackendHLE::Video_ClearMessages()
|
|
|
|
{
|
|
|
|
OSD::ClearMessages();
|
|
|
|
}
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
// Screenshot
|
2011-01-31 01:28:32 +00:00
|
|
|
bool VideoBackendHLE::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-01-31 01:28:32 +00:00
|
|
|
u32 VideoBackendHLE::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
if (s_PluginInitialized)
|
|
|
|
{
|
|
|
|
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-02-02 04:40:27 +00:00
|
|
|
static volatile u32 s_doStateRequested = false;
|
2010-12-16 18:39:57 +00:00
|
|
|
|
2010-12-16 18:21:14 +00:00
|
|
|
static volatile struct
|
|
|
|
{
|
|
|
|
unsigned char **ptr;
|
|
|
|
int mode;
|
|
|
|
} s_doStateArgs;
|
|
|
|
|
2011-01-30 21:20:33 +00:00
|
|
|
// Depending on the threading mode (DC/SC) this can be called
|
|
|
|
// from either the GPU thread or the CPU thread
|
2011-02-08 10:37:47 +00:00
|
|
|
void VideoFifo_CheckStateRequest()
|
|
|
|
{
|
2010-12-16 18:21:14 +00:00
|
|
|
if (Common::AtomicLoadAcquire(s_doStateRequested))
|
|
|
|
{
|
|
|
|
// Clear all caches that touch RAM
|
|
|
|
TextureCache::Invalidate(false);
|
|
|
|
VertexLoaderManager::MarkAllDirty();
|
|
|
|
|
|
|
|
PointerWrap p(s_doStateArgs.ptr, s_doStateArgs.mode);
|
|
|
|
VideoCommon_DoState(p);
|
|
|
|
|
|
|
|
// Refresh state.
|
|
|
|
if (s_doStateArgs.mode == PointerWrap::MODE_READ)
|
|
|
|
{
|
|
|
|
BPReload();
|
|
|
|
RecomputeCachedArraybases();
|
|
|
|
}
|
|
|
|
|
2011-02-02 04:40:27 +00:00
|
|
|
Common::AtomicStoreRelease(s_doStateRequested, false);
|
2010-12-16 18:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 21:26:29 +00:00
|
|
|
// Run from the CPU thread
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::DoState(PointerWrap& p)
|
2010-12-16 18:21:14 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
s_doStateArgs.ptr = p.ptr;
|
|
|
|
s_doStateArgs.mode = p.mode;
|
2011-02-02 04:40:27 +00:00
|
|
|
Common::AtomicStoreRelease(s_doStateRequested, true);
|
2011-01-31 01:28:32 +00:00
|
|
|
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
2010-12-16 18:21:14 +00:00
|
|
|
{
|
|
|
|
while (Common::AtomicLoadAcquire(s_doStateRequested) && !s_FifoShuttingDown)
|
|
|
|
//Common::SleepCurrentThread(1);
|
|
|
|
Common::YieldCPU();
|
|
|
|
}
|
|
|
|
else
|
2011-02-08 10:37:47 +00:00
|
|
|
VideoFifo_CheckStateRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackendHLE::RunLoop(bool enable)
|
|
|
|
{
|
|
|
|
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-01-31 01:28:32 +00:00
|
|
|
void VideoBackend::Video_GatherPipeBursted()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
CommandProcessor::GatherPipeBursted();
|
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::Video_WaitForFrameFinish()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
CommandProcessor::WaitForFrameFinish();
|
|
|
|
}
|
|
|
|
|
2011-02-10 04:47:02 +00:00
|
|
|
bool VideoBackendHLE::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
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackendHLE::Video_AbortFrame()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
CommandProcessor::AbortFrame();
|
|
|
|
}
|