Merge pull request #3504 from degasus/master

VideoBackend: Cleanup API a bit.
This commit is contained in:
Pierre Bourdon 2016-01-13 01:27:24 +01:00
commit 8f8134f5f4
38 changed files with 142 additions and 264 deletions

View File

@ -189,7 +189,7 @@ void ConfigCache::RestoreConfig(SConfig* config)
config->m_strVideoBackend = strBackend;
config->sBackend = sBackend;
config->m_strGPUDeterminismMode = m_strGPUDeterminismMode;
VideoBackend::ActivateBackend(config->m_strVideoBackend);
VideoBackendBase::ActivateBackend(config->m_strVideoBackend);
}
static ConfigCache config_cache;
@ -264,7 +264,7 @@ bool BootCore(const std::string& _rFilename)
config_cache.bSetVolume = true;
dsp_section->Get("EnableJIT", &SConfig::GetInstance().m_DSPEnableJIT, SConfig::GetInstance().m_DSPEnableJIT);
dsp_section->Get("Backend", &SConfig::GetInstance().sBackend, SConfig::GetInstance().sBackend);
VideoBackend::ActivateBackend(StartUp.m_strVideoBackend);
VideoBackendBase::ActivateBackend(StartUp.m_strVideoBackend);
core_section->Get("GPUDeterminismMode", &StartUp.m_strGPUDeterminismMode, StartUp.m_strGPUDeterminismMode);
for (unsigned int i = 0; i < MAX_SI_CHANNELS; ++i)

View File

@ -64,7 +64,9 @@
#include "DiscIO/FileMonitor.h"
#include "InputCommon/GCAdapter.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoBackendBase.h"
// This can mostly be removed when we move to VS2015
@ -165,7 +167,7 @@ void DisplayMessage(const std::string& message, int time_in_ms)
return;
}
g_video_backend->Video_AddMessage(message, time_in_ms);
OSD::AddMessage(message, time_in_ms);
Host_UpdateTitle(message);
}
@ -262,7 +264,7 @@ void Stop() // - Hammertime!
s_is_stopping = true;
g_video_backend->EmuStateChange(EMUSTATE_CHANGE_STOP);
Fifo::EmulatorState(false);
INFO_LOG(CONSOLE, "Stop [Main Thread]\t\t---- Shutting down ----");
@ -534,7 +536,7 @@ void EmuThread()
s_cpu_thread = std::thread(cpuThreadFunc);
// become the GPU thread
g_video_backend->Video_EnterLoop();
Fifo::RunGpuLoop();
// We have now exited the Video Loop
INFO_LOG(CONSOLE, "%s", StopMessage(false, "Video Loop Ended").c_str());
@ -602,7 +604,7 @@ void EmuThread()
INFO_LOG(CONSOLE, "%s", StopMessage(true, "Main Emu thread stopped").c_str());
// Clear on screen messages that haven't expired
g_video_backend->Video_ClearMessages();
OSD::ClearMessages();
// Reload sysconf file in order to see changes committed during emulation
if (core_parameter.bWii)
@ -693,7 +695,7 @@ void SaveScreenShot()
SetState(CORE_PAUSE);
g_video_backend->Video_Screenshot(GenerateScreenshotName());
Renderer::SetScreenshot(GenerateScreenshotName());
if (!bPaused)
SetState(CORE_RUN);
@ -707,7 +709,7 @@ void SaveScreenShot(const std::string& name)
std::string filePath = GenerateScreenshotFolderPath() + name + ".png";
g_video_backend->Video_Screenshot(filePath);
Renderer::SetScreenshot(filePath);
if (!bPaused)
SetState(CORE_RUN);
@ -736,7 +738,7 @@ bool PauseAndLock(bool doLock, bool unpauseOnUnlock)
DSP::GetDSPEmulator()->PauseAndLock(doLock, unpauseOnUnlock);
// video has to come after CPU, because CPU thread can wait for video thread (s_efbAccessRequested).
g_video_backend->PauseAndLock(doLock, unpauseOnUnlock);
Fifo::PauseAndLock(doLock, unpauseOnUnlock);
#if defined(__LIBUSB__) || defined(_WIN32)
GCAdapter::ResetRumble();
@ -888,7 +890,7 @@ void UpdateWantDeterminism(bool initial)
g_want_determinism = new_want_determinism;
WiiSockMan::GetInstance().UpdateWantDeterminism(new_want_determinism);
g_video_backend->UpdateWantDeterminism(new_want_determinism);
Fifo::UpdateWantDeterminism(new_want_determinism);
// We need to clear the cache because some parts of the JIT depend on want_determinism, e.g. use of FMA.
JitInterface::ClearCache();
Common::InitializeWiiRoot(g_want_determinism);

View File

@ -17,6 +17,7 @@
#include "Core/CoreTiming.h"
#include "Core/PowerPC/PowerPC.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/VideoBackendBase.h"
#define MAX_SLICE_LENGTH 20000
@ -445,7 +446,7 @@ void Idle()
//the VI will be desynchronized. So, We are waiting until the FIFO finish and
//while we process only the events required by the FIFO.
ProcessFifoWaitEvents();
g_video_backend->Video_Sync(0);
Fifo::Update(0);
}
idledCycles += DowncountToCycles(PowerPC::ppcState.downcount);

View File

@ -15,6 +15,7 @@
#include "Core/HW/DSP.h"
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/PowerPC.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/VideoBackendBase.h"
namespace
@ -114,7 +115,7 @@ void EnableStepping(const bool stepping)
{
PowerPC::Pause();
m_StepEvent.Reset();
g_video_backend->EmuStateChange(EMUSTATE_CHANGE_PAUSE);
Fifo::EmulatorState(false);
AudioCommon::ClearAudioBuffer(true);
}
else
@ -137,7 +138,7 @@ void EnableStepping(const bool stepping)
}
PowerPC::Start();
m_StepEvent.Set();
g_video_backend->EmuStateChange(EMUSTATE_CHANGE_PLAY);
Fifo::EmulatorState(true);
AudioCommon::ClearAudioBuffer(false);
}
}

View File

@ -14,6 +14,7 @@
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PowerPC.h"
#include "VideoCommon/CommandProcessor.h"
#include "VideoCommon/VideoBackendBase.h"
namespace GPFifo
@ -80,7 +81,7 @@ static void UpdateGatherPipe()
ProcessorInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE;
}
g_video_backend->Video_GatherPipeBursted();
CommandProcessor::GatherPipeBursted();
}
// move back the spill bytes

View File

@ -35,6 +35,7 @@
#include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
#include "VideoCommon/CommandProcessor.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/VideoBackendBase.h"
@ -68,7 +69,7 @@ MMIO::Mapping* mmio_mapping;
static void InitMMIO(MMIO::Mapping* mmio)
{
g_video_backend->RegisterCPMMIO(mmio, 0x0C000000);
CommandProcessor::RegisterMMIO(mmio, 0x0C000000);
PixelEngine::RegisterMMIO(mmio, 0x0C001000);
VideoInterface::RegisterMMIO(mmio, 0x0C002000);
ProcessorInterface::RegisterMMIO(mmio, 0x0C003000);

View File

@ -128,7 +128,7 @@ static void VICallback(u64 userdata, int cyclesLate)
static void CPCallback(u64 userdata, int cyclesLate)
{
u64 now = CoreTiming::GetTicks();
int next = g_video_backend->Video_Sync((int)(now - s_last_sync_gpu_tick));
int next = Fifo::Update((int)(now - s_last_sync_gpu_tick));
s_last_sync_gpu_tick = now;
if (next > 0)
@ -181,7 +181,7 @@ static void PatchEngineCallback(u64 userdata, int cyclesLate)
static void ThrottleCallback(u64 last_time, int cyclesLate)
{
// Allow the GPU thread to sleep. Setting this flag here limits the wakeups to 1 kHz.
GpuMaySleep();
Fifo::GpuMaySleep();
u32 time = Common::Timer::GetTimeMs();

View File

@ -35,6 +35,7 @@
#include "Core/IPC_HLE/WII_IPC_HLE_WiiMote.h"
#include "Core/PowerPC/PowerPC.h"
#include "InputCommon/GCPadStatus.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/VideoConfig.h"
// The chunk to allocate movie data in multiples of.
@ -240,7 +241,7 @@ void SetFrameSkipping(unsigned int framesToSkip)
// Don't forget to re-enable rendering in case it wasn't...
// as this won't be changed anymore when frameskip is turned off
if (framesToSkip == 0)
g_video_backend->Video_SetRendering(true);
Fifo::SetRendering(true);
}
void SetPolledDevice()
@ -288,7 +289,7 @@ void FrameSkipping()
if (s_frameSkipCounter > s_framesToSkip || Core::ShouldSkipFrame(s_frameSkipCounter) == false)
s_frameSkipCounter = 0;
g_video_backend->Video_SetRendering(!s_frameSkipCounter);
Fifo::SetRendering(!s_frameSkipCounter);
}
}

View File

@ -121,7 +121,7 @@ bool DolphinApp::OnInit()
if (m_select_audio_emulation)
SConfig::GetInstance().bDSPHLE = (m_audio_emulation_name.Upper() == "HLE");
VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
VideoBackendBase::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
// Enable the PNG image handler for screenshots
wxImage::AddHandler(new wxPNGHandler);

View File

@ -61,7 +61,7 @@ SoftwareVideoConfigDialog::SoftwareVideoConfigDialog(wxWindow* parent, const std
wxStaticText* const label_backend = new wxStaticText(page_general, wxID_ANY, _("Backend:"));
wxChoice* const choice_backend = new wxChoice(page_general, wxID_ANY);
for (const VideoBackend* backend : g_available_video_backends)
for (const VideoBackendBase* backend : g_available_video_backends)
{
choice_backend->AppendString(StrToWxStr(backend->GetDisplayName()));
}

View File

@ -24,7 +24,7 @@ public:
void Event_Backend(wxCommandEvent &ev)
{
VideoBackend* new_backend = g_available_video_backends[ev.GetInt()];
VideoBackendBase* new_backend = g_available_video_backends[ev.GetInt()];
if (g_video_backend != new_backend)
{

View File

@ -235,7 +235,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con
choice_backend = new wxChoice(page_general, wxID_ANY);
RegisterControl(choice_backend, wxGetTranslation(backend_desc));
for (const VideoBackend* backend : g_available_video_backends)
for (const VideoBackendBase* backend : g_available_video_backends)
{
choice_backend->AppendString(wxGetTranslation(StrToWxStr(backend->GetDisplayName())));
}

View File

@ -82,7 +82,7 @@ public:
protected:
void Event_Backend(wxCommandEvent &ev)
{
VideoBackend* new_backend = g_available_video_backends[ev.GetInt()];
VideoBackendBase* new_backend = g_available_video_backends[ev.GetInt()];
if (g_video_backend != new_backend)
{
bool do_switch = !Core::IsRunning();

View File

@ -26,10 +26,10 @@ void Init()
{
LogManager::Init();
SConfig::Init();
VideoBackend::PopulateList();
VideoBackendBase::PopulateList();
WiimoteReal::LoadSettings();
GCAdapter::Init();
VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
VideoBackendBase::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
SetEnableAlert(SConfig::GetInstance().bUsePanicHandlers);
}
@ -38,7 +38,7 @@ void Shutdown()
{
GCAdapter::Shutdown();
WiimoteReal::Shutdown();
VideoBackend::ClearList();
VideoBackendBase::ClearList();
SConfig::Shutdown();
LogManager::Shutdown();
}

View File

@ -718,7 +718,7 @@ void formatBufferDump(const u8* in, u8* out, int w, int h, int p)
// This function has the final picture. We adjust the aspect ratio here.
void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma)
{
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
if (Fifo::g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
{
if (SConfig::GetInstance().m_DumpFrames && !frame_data.empty())
AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight);

View File

@ -10,7 +10,7 @@
namespace DX11
{
class VideoBackend : public VideoBackendHardware
class VideoBackend : public VideoBackendBase
{
bool Initialize(void*) override;
void Shutdown() override;

View File

@ -183,7 +183,7 @@ void VideoBackend::Video_Prepare()
// VideoCommon
BPInit();
Fifo_Init();
Fifo::Init();
IndexGenerator::Init();
VertexLoaderManager::Init();
OpcodeDecoder_Init();
@ -206,7 +206,7 @@ void VideoBackend::Shutdown()
if (g_renderer)
{
// VideoCommon
Fifo_Shutdown();
Fifo::Shutdown();
CommandProcessor::Shutdown();
GeometryShaderManager::Shutdown();
PixelShaderManager::Shutdown();

View File

@ -1235,7 +1235,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
}
static int w = 0, h = 0;
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
if (Fifo::g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
{
DumpFrame(frame_data, w, h);
Core::Callback_VideoCopiedToXFB(false);

View File

@ -10,7 +10,7 @@
namespace OGL
{
class VideoBackend : public VideoBackendHardware
class VideoBackend : public VideoBackendBase
{
bool Initialize(void *) override;
void Shutdown() override;

View File

@ -181,7 +181,7 @@ void VideoBackend::Video_Prepare()
BPInit();
g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = GetPerfQuery();
Fifo_Init(); // must be done before OpcodeDecoder_Init()
Fifo::Init(); // must be done before OpcodeDecoder_Init()
OpcodeDecoder_Init();
IndexGenerator::Init();
VertexShaderManager::Init();
@ -215,7 +215,7 @@ void VideoBackend::Video_Cleanup()
if (!g_renderer)
return;
Fifo_Shutdown();
Fifo::Shutdown();
// The following calls are NOT Thread Safe
// And need to be called from the video thread

View File

@ -191,7 +191,7 @@ void CopyTempBuffer(s16 x, s16 y, int bufferBase, int subBuffer, const char *nam
void OnObjectBegin()
{
if (!g_bSkipCurrentFrame)
if (!Fifo::g_bSkipCurrentFrame)
{
if (g_ActiveConfig.bDumpTextures && stats.thisFrame.numDrawnObjects >= g_ActiveConfig.drawStart && stats.thisFrame.numDrawnObjects < g_ActiveConfig.drawEnd)
DumpActiveTextures();
@ -200,7 +200,7 @@ void OnObjectBegin()
void OnObjectEnd()
{
if (!g_bSkipCurrentFrame)
if (!Fifo::g_bSkipCurrentFrame)
{
if (g_ActiveConfig.bDumpObjects && stats.thisFrame.numDrawnObjects >= g_ActiveConfig.drawStart && stats.thisFrame.numDrawnObjects < g_ActiveConfig.drawEnd)
DumpEfb(StringFromFormat("%sobject%i.png",

View File

@ -73,7 +73,7 @@ namespace EfbCopy
rc.right = rc.left + (int)bpmem.copyTexSrcWH.x + 1;
rc.bottom = rc.top + (int)bpmem.copyTexSrcWH.y + 1;
if (!g_bSkipCurrentFrame)
if (!Fifo::g_bSkipCurrentFrame)
{
if (bpmem.triggerEFBCopy.copy_to_xfb)
{

View File

@ -108,7 +108,7 @@ void SWRenderer::UpdateColorTexture(EfbInterface::yuv422_packed *xfb, u32 fbWidt
// Called on the GPU thread
void SWRenderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma)
{
if (!g_bSkipCurrentFrame)
if (!Fifo::g_bSkipCurrentFrame)
{
if (g_ActiveConfig.bUseXFB)

View File

@ -198,8 +198,7 @@ void VideoSoftware::Video_Cleanup()
{
if (g_renderer)
{
Fifo_Shutdown();
Fifo::Shutdown();
SWRenderer::Shutdown();
DebugUtil::Shutdown();
// The following calls are NOT Thread Safe
@ -228,7 +227,7 @@ void VideoSoftware::Video_Prepare()
BPInit();
g_vertex_manager = std::make_unique<SWVertexLoader>();
g_perf_query = std::make_unique<PerfQuery>();
Fifo_Init(); // must be done before OpcodeDecoder_Init()
Fifo::Init(); // must be done before OpcodeDecoder_Init()
OpcodeDecoder_Init();
IndexGenerator::Init();
VertexShaderManager::Init();

View File

@ -12,7 +12,7 @@ namespace MMIO { class Mapping; }
namespace SW
{
class VideoSoftware : public VideoBackendHardware
class VideoSoftware : public VideoBackendBase
{
bool Initialize(void *window_handle) override;
void Shutdown() override;

View File

@ -81,7 +81,7 @@ void AsyncRequests::PushEvent(const AsyncRequests::Event& event, bool blocking)
m_queue.push(event);
RunGpu();
Fifo::RunGpu();
if (blocking)
{
m_cond.wait(lock, [this]{return m_queue.empty();});

View File

@ -177,7 +177,7 @@ static void BPWritten(const BPCmd& bp)
switch (bp.newvalue & 0xFF)
{
case 0x02:
if (!g_use_deterministic_gpu_thread)
if (!Fifo::g_use_deterministic_gpu_thread)
PixelEngine::SetFinish(); // may generate interrupt
DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (bp.newvalue & 0xFFFF));
return;
@ -188,12 +188,12 @@ static void BPWritten(const BPCmd& bp)
}
return;
case BPMEM_PE_TOKEN_ID: // Pixel Engine Token ID
if (!g_use_deterministic_gpu_thread)
if (!Fifo::g_use_deterministic_gpu_thread)
PixelEngine::SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), false);
DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (bp.newvalue & 0xFFFF));
return;
case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
if (!g_use_deterministic_gpu_thread)
if (!Fifo::g_use_deterministic_gpu_thread)
PixelEngine::SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), true);
DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (bp.newvalue & 0xFFFF));
return;
@ -378,7 +378,7 @@ static void BPWritten(const BPCmd& bp)
case BPMEM_CLEARBBOX2:
// Don't compute bounding box if this frame is being skipped!
// Wrong but valid values are better than bogus values...
if (!g_bSkipCurrentFrame)
if (!Fifo::g_bSkipCurrentFrame)
{
u8 offset = bp.address & 2;
BoundingBox::active = true;

View File

@ -223,7 +223,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
UCPCtrlReg tmp(val);
m_CPCtrlReg.Hex = tmp.Hex;
SetCpControlRegister();
RunGpu();
Fifo::RunGpu();
})
);
@ -233,7 +233,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
UCPClearReg tmp(val);
m_CPClearReg.Hex = tmp.Hex;
SetCpClearRegister();
RunGpu();
Fifo::RunGpu();
})
);
@ -265,17 +265,17 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
: MMIO::DirectRead<u16>(MMIO::Utils::HighPart(&fifo.CPReadWriteDistance)),
MMIO::ComplexWrite<u16>([](u32, u16 val) {
WriteHigh(fifo.CPReadWriteDistance, val);
SyncGPU(SYNC_GPU_OTHER);
Fifo::SyncGPU(Fifo::SYNC_GPU_OTHER);
if (fifo.CPReadWriteDistance == 0)
{
GPFifo::ResetGatherPipe();
ResetVideoBuffer();
Fifo::ResetVideoBuffer();
}
else
{
ResetVideoBuffer();
Fifo::ResetVideoBuffer();
}
RunGpu();
Fifo::RunGpu();
})
);
mmio->Register(base | FIFO_READ_POINTER_LO,
@ -306,7 +306,7 @@ void GatherPipeBursted()
// if we aren't linked, we don't care about gather pipe data
if (!m_CPCtrlReg.GPLinkEnable)
{
if (IsOnThread() && !g_use_deterministic_gpu_thread)
if (IsOnThread() && !Fifo::g_use_deterministic_gpu_thread)
{
// In multibuffer mode is not allowed write in the same FIFO attached to the GPU.
// Fix Pokemon XD in DC mode.
@ -314,10 +314,10 @@ void GatherPipeBursted()
(ProcessorInterface::Fifo_CPUBase == fifo.CPBase) &&
fifo.CPReadWriteDistance > 0)
{
FlushGpu();
Fifo::FlushGpu();
}
}
RunGpu();
Fifo::RunGpu();
return;
}
@ -340,7 +340,7 @@ void GatherPipeBursted()
Common::AtomicAdd(fifo.CPReadWriteDistance, GATHER_PIPE_SIZE);
RunGpu();
Fifo::RunGpu();
_assert_msg_(COMMANDPROCESSOR, fifo.CPReadWriteDistance <= fifo.CPEnd - fifo.CPBase,
"FIFO is overflowed by GatherPipe !\nCPU thread is too fast!");
@ -367,12 +367,12 @@ void UpdateInterrupts(u64 userdata)
}
CoreTiming::ForceExceptionCheck(0);
s_interrupt_waiting.store(false);
RunGpu();
Fifo::RunGpu();
}
void UpdateInterruptsFromVideoBackend(u64 userdata)
{
if (!g_use_deterministic_gpu_thread)
if (!Fifo::g_use_deterministic_gpu_thread)
CoreTiming::ScheduleEvent_Threadsafe(0, et_UpdateInterrupts, userdata);
}
@ -494,7 +494,7 @@ void SetCpStatusRegister()
// Here always there is one fifo attached to the GPU
m_CPStatusReg.Breakpoint = fifo.bFF_Breakpoint;
m_CPStatusReg.ReadIdle = !fifo.CPReadWriteDistance || (fifo.CPReadPointer == fifo.CPWritePointer);
m_CPStatusReg.CommandIdle = !fifo.CPReadWriteDistance || AtBreakpoint() || !fifo.bFF_GPReadEnable;
m_CPStatusReg.CommandIdle = !fifo.CPReadWriteDistance || Fifo::AtBreakpoint() || !fifo.bFF_GPReadEnable;
m_CPStatusReg.UnderflowLoWatermark = fifo.bFF_LoWatermark;
m_CPStatusReg.OverflowHiWatermark = fifo.bFF_HiWatermark;
@ -519,7 +519,7 @@ void SetCpControlRegister()
if (fifo.bFF_GPReadEnable && !m_CPCtrlReg.GPReadEnable)
{
fifo.bFF_GPReadEnable = m_CPCtrlReg.GPReadEnable;
FlushGpu();
Fifo::FlushGpu();
}
else
{

View File

@ -30,6 +30,9 @@
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VideoConfig.h"
namespace Fifo
{
static constexpr u32 FIFO_SIZE = 2 * 1024 * 1024;
bool g_bSkipCurrentFrame = false;
@ -66,7 +69,7 @@ static u8* s_video_buffer_pp_read_ptr;
static std::atomic<int> s_sync_ticks;
static Common::Event s_sync_wakeup_event;
void Fifo_DoState(PointerWrap &p)
void DoState(PointerWrap &p)
{
p.DoArray(s_video_buffer, FIFO_SIZE);
u8* write_ptr = s_video_buffer_write_ptr;
@ -81,7 +84,7 @@ void Fifo_DoState(PointerWrap &p)
p.Do(g_bSkipCurrentFrame);
}
void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock)
void PauseAndLock(bool doLock, bool unpauseOnUnlock)
{
if (doLock)
{
@ -97,7 +100,7 @@ void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock)
}
void Fifo_Init()
void Init()
{
// Padded so that SIMD overreads in the vertex loader are safe
s_video_buffer = (u8*)AllocateMemoryPages(FIFO_SIZE + 4);
@ -107,7 +110,7 @@ void Fifo_Init()
s_sync_ticks.store(0);
}
void Fifo_Shutdown()
void Shutdown()
{
if (s_gpu_mainloop.IsRunning())
PanicAlert("Fifo shutting down while active");
@ -122,7 +125,7 @@ void Fifo_Shutdown()
s_fifo_aux_read_ptr = nullptr;
}
void Fifo_SetRendering(bool enabled)
void SetRendering(bool enabled)
{
g_bSkipCurrentFrame = !enabled;
}
@ -450,7 +453,7 @@ void RunGpu()
}
}
void Fifo_UpdateWantDeterminism(bool want)
void UpdateWantDeterminism(bool want)
{
// We are paused (or not running at all yet), so
// it should be safe to change this.
@ -492,7 +495,7 @@ void Fifo_UpdateWantDeterminism(bool want)
}
}
int Fifo_Update(int ticks)
int Update(int ticks)
{
const SConfig& param = SConfig::GetInstance();
@ -528,3 +531,5 @@ int Fifo_Update(int ticks)
return param.iSyncGpuMaxDistance - s_sync_ticks.load();
}
}

View File

@ -9,6 +9,9 @@
class PointerWrap;
namespace Fifo
{
extern bool g_bSkipCurrentFrame;
// This could be in SConfig, but it depends on multiple settings
@ -16,11 +19,11 @@ extern bool g_bSkipCurrentFrame;
extern bool g_use_deterministic_gpu_thread;
extern std::atomic<u8*> g_video_buffer_write_ptr_xthread;
void Fifo_Init();
void Fifo_Shutdown();
void Fifo_DoState(PointerWrap &f);
void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock);
void Fifo_UpdateWantDeterminism(bool want);
void Init();
void Shutdown();
void DoState(PointerWrap &f);
void PauseAndLock(bool doLock, bool unpauseOnUnlock);
void UpdateWantDeterminism(bool want);
// Used for diagnostics.
enum SyncGPUReason
@ -47,5 +50,7 @@ void ExitGpuLoop();
void EmulatorState(bool running);
bool AtBreakpoint();
void ResetVideoBuffer();
void Fifo_SetRendering(bool bEnabled);
int Fifo_Update(int ticks);
void SetRendering(bool bEnabled);
int Update(int ticks);
};

View File

@ -29,30 +29,14 @@ static volatile struct
u32 fbHeight;
} s_beginFieldArgs;
void VideoBackendHardware::EmuStateChange(EMUSTATE_CHANGE newState)
void VideoBackendBase::Video_ExitLoop()
{
EmulatorState(newState == EMUSTATE_CHANGE_PLAY);
}
// Enter and exit the video loop
void VideoBackendHardware::Video_EnterLoop()
{
RunGpuLoop();
}
void VideoBackendHardware::Video_ExitLoop()
{
ExitGpuLoop();
Fifo::ExitGpuLoop();
s_FifoShuttingDown.Set();
}
void VideoBackendHardware::Video_SetRendering(bool bEnabled)
{
Fifo_SetRendering(bEnabled);
}
// Run from the CPU thread (from VideoInterface.cpp)
void VideoBackendHardware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight)
void VideoBackendBase::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight)
{
if (m_initialized && g_ActiveConfig.bUseXFB)
{
@ -64,11 +48,11 @@ void VideoBackendHardware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStri
}
// Run from the CPU thread (from VideoInterface.cpp)
void VideoBackendHardware::Video_EndField()
void VideoBackendBase::Video_EndField()
{
if (m_initialized && g_ActiveConfig.bUseXFB && g_renderer)
{
SyncGPU(SYNC_GPU_SWAP);
Fifo::SyncGPU(Fifo::SYNC_GPU_SWAP);
AsyncRequests::Event e;
e.time = 0;
@ -82,24 +66,7 @@ void VideoBackendHardware::Video_EndField()
}
}
void VideoBackendHardware::Video_AddMessage(const std::string& msg, u32 milliseconds)
{
OSD::AddMessage(msg, milliseconds);
}
void VideoBackendHardware::Video_ClearMessages()
{
OSD::ClearMessages();
}
// Screenshot
bool VideoBackendHardware::Video_Screenshot(const std::string& filename)
{
Renderer::SetScreenshot(filename.c_str());
return true;
}
u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
u32 VideoBackendBase::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
{
if (!g_ActiveConfig.bEFBAccessEnable)
{
@ -131,14 +98,14 @@ u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32
}
}
u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
u32 VideoBackendBase::Video_GetQueryResult(PerfQueryType type)
{
if (!g_perf_query->ShouldEmulate())
{
return 0;
}
SyncGPU(SYNC_GPU_PERFQUERY);
Fifo::SyncGPU(Fifo::SYNC_GPU_PERFQUERY);
AsyncRequests::Event e;
e.time = 0;
@ -150,7 +117,7 @@ u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
return g_perf_query->GetQueryResult(type);
}
u16 VideoBackendHardware::Video_GetBoundingBox(int index)
u16 VideoBackendBase::Video_GetBoundingBox(int index)
{
if (!g_ActiveConfig.backend_info.bSupportsBBox)
return 0;
@ -164,7 +131,7 @@ u16 VideoBackendHardware::Video_GetBoundingBox(int index)
return 0;
}
SyncGPU(SYNC_GPU_BBOX);
Fifo::SyncGPU(Fifo::SYNC_GPU_BBOX);
AsyncRequests::Event e;
u16 result;
@ -177,7 +144,7 @@ u16 VideoBackendHardware::Video_GetBoundingBox(int index)
return result;
}
void VideoBackendHardware::InitializeShared()
void VideoBackendBase::InitializeShared()
{
VideoCommon_Init();
@ -187,7 +154,7 @@ void VideoBackendHardware::InitializeShared()
}
// Run from the CPU thread
void VideoBackendHardware::DoState(PointerWrap& p)
void VideoBackendBase::DoState(PointerWrap& p)
{
bool software = false;
p.Do(software);
@ -202,7 +169,7 @@ void VideoBackendHardware::DoState(PointerWrap& p)
p.DoMarker("VideoCommon");
p.Do(s_beginFieldArgs);
p.DoMarker("VideoBackendHardware");
p.DoMarker("VideoBackendBase");
// Refresh state.
if (p.GetMode() == PointerWrap::MODE_READ)
@ -215,7 +182,7 @@ void VideoBackendHardware::DoState(PointerWrap& p)
}
}
void VideoBackendHardware::CheckInvalidState()
void VideoBackendBase::CheckInvalidState()
{
if (m_invalid)
{
@ -225,34 +192,3 @@ void VideoBackendHardware::CheckInvalidState()
TextureCacheBase::Invalidate();
}
}
void VideoBackendHardware::PauseAndLock(bool doLock, bool unpauseOnUnlock)
{
Fifo_PauseAndLock(doLock, unpauseOnUnlock);
}
void VideoBackendHardware::RunLoop(bool enable)
{
VideoCommon_RunLoop(enable);
}
void VideoBackendHardware::Video_GatherPipeBursted()
{
CommandProcessor::GatherPipeBursted();
}
int VideoBackendHardware::Video_Sync(int ticks)
{
return Fifo_Update(ticks);
}
void VideoBackendHardware::RegisterCPMMIO(MMIO::Mapping* mmio, u32 base)
{
CommandProcessor::RegisterMMIO(mmio, base);
}
void VideoBackendHardware::UpdateWantDeterminism(bool want)
{
Fifo_UpdateWantDeterminism(want);
}

View File

@ -39,8 +39,8 @@ static u32 InterpretDisplayList(u32 address, u32 size)
{
u8* startAddress;
if (g_use_deterministic_gpu_thread)
startAddress = (u8*)PopFifoAuxBuffer(size);
if (Fifo::g_use_deterministic_gpu_thread)
startAddress = (u8*)Fifo::PopFifoAuxBuffer(size);
else
startAddress = Memory::GetPointer(address);
@ -66,7 +66,7 @@ static void InterpretDisplayListPreprocess(u32 address, u32 size)
{
u8* startAddress = Memory::GetPointer(address);
PushFifoAuxBuffer(startAddress, size);
Fifo::PushFifoAuxBuffer(startAddress, size);
if (startAddress != nullptr)
{
@ -278,7 +278,7 @@ u8* OpcodeDecoder_Run(DataReader src, u32* cycles, bool in_display_list)
(cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT,
num_vertices,
src,
g_bSkipCurrentFrame,
Fifo::g_bSkipCurrentFrame,
is_preprocess);
if (bytes < 0)

View File

@ -298,7 +298,7 @@ void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
CommandProcessor::SetInterruptTokenWaiting(true);
if (!SConfig::GetInstance().bCPUThread || g_use_deterministic_gpu_thread)
if (!SConfig::GetInstance().bCPUThread || Fifo::g_use_deterministic_gpu_thread)
CoreTiming::ScheduleEvent(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16));
else
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16));
@ -310,7 +310,7 @@ void SetFinish()
{
CommandProcessor::SetInterruptFinishWaiting(true);
if (!SConfig::GetInstance().bCPUThread || g_use_deterministic_gpu_thread)
if (!SConfig::GetInstance().bCPUThread || Fifo::g_use_deterministic_gpu_thread)
CoreTiming::ScheduleEvent(0, et_SetFinishOnMainThread, 0);
else
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetFinishOnMainThread, 0);

View File

@ -11,9 +11,9 @@
#include "VideoCommon/VideoBackendBase.h"
std::vector<VideoBackend*> g_available_video_backends;
VideoBackend* g_video_backend = nullptr;
static VideoBackend* s_default_backend = nullptr;
std::vector<VideoBackendBase*> g_available_video_backends;
VideoBackendBase* g_video_backend = nullptr;
static VideoBackendBase* s_default_backend = nullptr;
#ifdef _WIN32
#include <windows.h>
@ -26,9 +26,9 @@ __declspec(dllexport) DWORD NvOptimusEnablement = 1;
}
#endif
void VideoBackend::PopulateList()
void VideoBackendBase::PopulateList()
{
VideoBackend* backends[4] = { nullptr };
VideoBackendBase* backends[4] = { nullptr };
// OGL > D3D11 > SW
g_available_video_backends.push_back(backends[0] = new OGL::VideoBackend);
@ -37,7 +37,7 @@ void VideoBackend::PopulateList()
#endif
g_available_video_backends.push_back(backends[3] = new SW::VideoSoftware);
for (VideoBackend* backend : backends)
for (VideoBackendBase* backend : backends)
{
if (backend)
{
@ -47,7 +47,7 @@ void VideoBackend::PopulateList()
}
}
void VideoBackend::ClearList()
void VideoBackendBase::ClearList()
{
while (!g_available_video_backends.empty())
{
@ -56,12 +56,12 @@ void VideoBackend::ClearList()
}
}
void VideoBackend::ActivateBackend(const std::string& name)
void VideoBackendBase::ActivateBackend(const std::string& name)
{
if (name.length() == 0) // If nullptr, set it to the default backend (expected behavior)
g_video_backend = s_default_backend;
for (VideoBackend* backend : g_available_video_backends)
for (VideoBackendBase* backend : g_available_video_backends)
if (name == backend->GetName())
g_video_backend = backend;
}

View File

@ -57,18 +57,15 @@ struct SCPFifoStruct
volatile u32 bFF_HiWatermark;
};
class VideoBackend
class VideoBackendBase
{
public:
virtual ~VideoBackend() {}
virtual void EmuStateChange(EMUSTATE_CHANGE) = 0;
virtual ~VideoBackendBase() {}
virtual unsigned int PeekMessages() = 0;
virtual bool Initialize(void* window_handle) = 0;
virtual void Shutdown() = 0;
virtual void RunLoop(bool enable) = 0;
virtual std::string GetName() const = 0;
virtual std::string GetDisplayName() const { return GetName(); }
@ -76,91 +73,31 @@ public:
virtual void ShowConfig(void*) = 0;
virtual void Video_Prepare() = 0;
virtual void Video_EnterLoop() = 0;
virtual void Video_ExitLoop() = 0;
void Video_ExitLoop();
virtual void Video_Cleanup() = 0; // called from gl/d3d thread
virtual void Video_BeginField(u32, u32, u32, u32) = 0;
virtual void Video_EndField() = 0;
void Video_BeginField(u32, u32, u32, u32);
void Video_EndField();
virtual u32 Video_AccessEFB(EFBAccessType, u32, u32, u32) = 0;
virtual u32 Video_GetQueryResult(PerfQueryType type) = 0;
virtual u16 Video_GetBoundingBox(int index) = 0;
virtual void Video_AddMessage(const std::string& msg, unsigned int milliseconds) = 0;
virtual void Video_ClearMessages() = 0;
virtual bool Video_Screenshot(const std::string& filename) = 0;
virtual void Video_SetRendering(bool bEnabled) = 0;
virtual void Video_GatherPipeBursted() = 0;
virtual int Video_Sync(int ticks) = 0;
// Registers MMIO handlers for the CommandProcessor registers.
virtual void RegisterCPMMIO(MMIO::Mapping* mmio, u32 base) = 0;
u32 Video_AccessEFB(EFBAccessType, u32, u32, u32);
u32 Video_GetQueryResult(PerfQueryType type);
u16 Video_GetBoundingBox(int index);
static void PopulateList();
static void ClearList();
static void ActivateBackend(const std::string& name);
// waits until is paused and fully idle, and acquires a lock on that state.
// or, if doLock is false, releases a lock on that state and optionally unpauses.
// calls must be balanced and non-recursive (once with doLock true, then once with doLock false).
virtual void PauseAndLock(bool doLock, bool unpauseOnUnlock = true) = 0;
// the implementation needs not do synchronization logic, because calls to it are surrounded by PauseAndLock now
virtual void DoState(PointerWrap &p) = 0;
void DoState(PointerWrap &p);
virtual void CheckInvalidState() = 0;
virtual void UpdateWantDeterminism(bool want) {}
protected:
bool m_initialized = false;
};
extern std::vector<VideoBackend*> g_available_video_backends;
extern VideoBackend* g_video_backend;
// inherited by D3D/OGL backends
class VideoBackendHardware : public VideoBackend
{
void RunLoop(bool enable) override;
void EmuStateChange(EMUSTATE_CHANGE) override;
void Video_EnterLoop() override;
void Video_ExitLoop() override;
void Video_BeginField(u32, u32, u32, u32) override;
void Video_EndField() override;
u32 Video_AccessEFB(EFBAccessType, u32, u32, u32) override;
u32 Video_GetQueryResult(PerfQueryType type) override;
u16 Video_GetBoundingBox(int index) override;
void Video_AddMessage(const std::string& pstr, unsigned int milliseconds) override;
void Video_ClearMessages() override;
bool Video_Screenshot(const std::string& filename) override;
void Video_SetRendering(bool bEnabled) override;
void Video_GatherPipeBursted() override;
int Video_Sync(int ticks) override;
void RegisterCPMMIO(MMIO::Mapping* mmio, u32 base) override;
void PauseAndLock(bool doLock, bool unpauseOnUnlock = true) override;
void DoState(PointerWrap &p) override;
void UpdateWantDeterminism(bool want) override;
bool m_invalid;
public:
void CheckInvalidState() override;
void CheckInvalidState();
protected:
void InitializeShared();
bool m_initialized = false;
bool m_invalid = false;
};
extern std::vector<VideoBackendBase*> g_available_video_backends;
extern VideoBackendBase* g_video_backend;

View File

@ -17,7 +17,7 @@
#include "VideoCommon/VideoState.h"
#include "VideoCommon/XFMemory.h"
static void DoState(PointerWrap &p)
void VideoCommon_DoState(PointerWrap &p)
{
// BP Memory
p.Do(bpmem);
@ -35,7 +35,7 @@ static void DoState(PointerWrap &p)
p.DoMarker("texMem");
// FIFO
Fifo_DoState(p);
Fifo::DoState(p);
p.DoMarker("Fifo");
CommandProcessor::DoState(p);
@ -64,16 +64,6 @@ static void DoState(PointerWrap &p)
// TODO: search for more data that should be saved and add it here
}
void VideoCommon_DoState(PointerWrap &p)
{
DoState(p);
}
void VideoCommon_RunLoop(bool enable)
{
EmulatorState(enable);
}
void VideoCommon_Init()
{
memset(&g_main_cp_state, 0, sizeof(g_main_cp_state));

View File

@ -7,5 +7,4 @@
class PointerWrap;
void VideoCommon_DoState(PointerWrap &p);
void VideoCommon_RunLoop(bool enable);
void VideoCommon_Init();

View File

@ -258,9 +258,9 @@ void LoadIndexedXF(u32 val, int refarray)
u32* currData = (u32*)(&xfmem) + address;
u32* newData;
if (g_use_deterministic_gpu_thread)
if (Fifo::g_use_deterministic_gpu_thread)
{
newData = (u32*)PopFifoAuxBuffer(size * sizeof(u32));
newData = (u32*)Fifo::PopFifoAuxBuffer(size * sizeof(u32));
}
else
{
@ -291,5 +291,5 @@ void PreprocessIndexedXF(u32 val, int refarray)
u32* new_data = (u32*)Memory::GetPointer(g_preprocess_cp_state.array_bases[refarray] + g_preprocess_cp_state.array_strides[refarray] * index);
size_t buf_size = size * sizeof(u32);
PushFifoAuxBuffer(new_data, buf_size);
Fifo::PushFifoAuxBuffer(new_data, buf_size);
}