2015-05-24 06:32:32 +02:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
2016-01-17 16:54:31 -05:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
#include "Common/ChunkFile.h"
|
2016-01-02 15:01:12 -05:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-08-24 19:13:46 -04:00
|
|
|
#include "Common/Event.h"
|
2016-01-02 15:01:12 -05:00
|
|
|
#include "Common/Flag.h"
|
2016-01-17 16:54:31 -05:00
|
|
|
#include "Common/Logging/Log.h"
|
2015-01-31 11:38:23 +01:00
|
|
|
#include "VideoCommon/AsyncRequests.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "VideoCommon/BPStructs.h"
|
|
|
|
|
#include "VideoCommon/Fifo.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-18 02:21:26 +00:00
|
|
|
|
2014-08-24 19:13:46 -04:00
|
|
|
static Common::Flag s_FifoShuttingDown;
|
2010-11-18 02:21:26 +00:00
|
|
|
|
|
|
|
|
static volatile struct
|
|
|
|
|
{
|
|
|
|
|
u32 xfbAddr;
|
|
|
|
|
u32 fbWidth;
|
2014-05-02 00:08:44 -07:00
|
|
|
u32 fbStride;
|
2010-11-18 02:21:26 +00:00
|
|
|
u32 fbHeight;
|
|
|
|
|
} s_beginFieldArgs;
|
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::Video_ExitLoop()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2016-01-12 22:44:58 +01:00
|
|
|
Fifo::ExitGpuLoop();
|
2014-08-24 19:13:46 -04:00
|
|
|
s_FifoShuttingDown.Set();
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2016-01-02 15:01:12 -05:00
|
|
|
if (m_initialized && g_ActiveConfig.bUseXFB)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
|
|
|
|
s_beginFieldArgs.xfbAddr = xfbAddr;
|
|
|
|
|
s_beginFieldArgs.fbWidth = fbWidth;
|
2014-05-02 00:08:44 -07:00
|
|
|
s_beginFieldArgs.fbStride = fbStride;
|
2010-11-18 02:21:26 +00:00
|
|
|
s_beginFieldArgs.fbHeight = fbHeight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::Video_EndField()
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2016-01-02 15:01:12 -05:00
|
|
|
if (m_initialized && g_ActiveConfig.bUseXFB && g_renderer)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2016-01-12 22:44:58 +01:00
|
|
|
Fifo::SyncGPU(Fifo::SYNC_GPU_SWAP);
|
2015-01-12 19:40:43 +11:00
|
|
|
|
2015-01-31 12:01:01 +01:00
|
|
|
AsyncRequests::Event e;
|
|
|
|
|
e.time = 0;
|
|
|
|
|
e.type = AsyncRequests::Event::SWAP_EVENT;
|
|
|
|
|
|
|
|
|
|
e.swap_event.xfbAddr = s_beginFieldArgs.xfbAddr;
|
|
|
|
|
e.swap_event.fbWidth = s_beginFieldArgs.fbWidth;
|
|
|
|
|
e.swap_event.fbStride = s_beginFieldArgs.fbStride;
|
|
|
|
|
e.swap_event.fbHeight = s_beginFieldArgs.fbHeight;
|
|
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, false);
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
u32 VideoBackendBase::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2015-01-31 11:38:23 +01:00
|
|
|
if (!g_ActiveConfig.bEFBAccessEnable)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2015-01-31 11:38:23 +01:00
|
|
|
return 0;
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-31 11:38:23 +01:00
|
|
|
if (type == POKE_COLOR || type == POKE_Z)
|
|
|
|
|
{
|
|
|
|
|
AsyncRequests::Event e;
|
|
|
|
|
e.type = type == POKE_COLOR ? AsyncRequests::Event::EFB_POKE_COLOR : AsyncRequests::Event::EFB_POKE_Z;
|
|
|
|
|
e.time = 0;
|
|
|
|
|
e.efb_poke.data = InputData;
|
|
|
|
|
e.efb_poke.x = x;
|
|
|
|
|
e.efb_poke.y = y;
|
2015-01-31 13:09:25 +01:00
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, false);
|
2015-01-31 11:38:23 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AsyncRequests::Event e;
|
|
|
|
|
u32 result;
|
|
|
|
|
e.type = type == PEEK_COLOR ? AsyncRequests::Event::EFB_PEEK_COLOR : AsyncRequests::Event::EFB_PEEK_Z;
|
|
|
|
|
e.time = 0;
|
|
|
|
|
e.efb_peek.x = x;
|
|
|
|
|
e.efb_peek.y = y;
|
|
|
|
|
e.efb_peek.data = &result;
|
2015-01-31 13:09:25 +01:00
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, true);
|
2015-01-31 11:38:23 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
u32 VideoBackendBase::Video_GetQueryResult(PerfQueryType type)
|
2013-02-16 17:50:40 -06:00
|
|
|
{
|
2014-03-11 00:30:55 +13:00
|
|
|
if (!g_perf_query->ShouldEmulate())
|
2014-01-09 18:37:59 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 22:44:58 +01:00
|
|
|
Fifo::SyncGPU(Fifo::SYNC_GPU_PERFQUERY);
|
2014-08-27 22:56:19 -04:00
|
|
|
|
2015-01-31 13:09:25 +01:00
|
|
|
AsyncRequests::Event e;
|
|
|
|
|
e.time = 0;
|
|
|
|
|
e.type = AsyncRequests::Event::PERF_QUERY;
|
|
|
|
|
|
2013-02-16 17:50:40 -06:00
|
|
|
if (!g_perf_query->IsFlushed())
|
2015-01-31 13:09:25 +01:00
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, true);
|
2013-03-01 23:02:11 +01:00
|
|
|
|
2013-02-16 17:50:40 -06:00
|
|
|
return g_perf_query->GetQueryResult(type);
|
|
|
|
|
}
|
2011-12-30 20:16:12 -08:00
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
u16 VideoBackendBase::Video_GetBoundingBox(int index)
|
2014-11-13 23:26:49 +01:00
|
|
|
{
|
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsBBox)
|
2015-05-23 16:05:21 +02:00
|
|
|
return 0;
|
2014-11-13 23:26:49 +01:00
|
|
|
|
2015-05-23 16:08:49 +02:00
|
|
|
if (!g_ActiveConfig.bBBoxEnable)
|
|
|
|
|
{
|
|
|
|
|
static bool warn_once = true;
|
|
|
|
|
if (warn_once)
|
|
|
|
|
ERROR_LOG(VIDEO, "BBox shall be used but it is disabled. Please use a gameini to enable it for this game.");
|
|
|
|
|
warn_once = false;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-11-13 23:26:49 +01:00
|
|
|
|
2016-01-12 22:44:58 +01:00
|
|
|
Fifo::SyncGPU(Fifo::SYNC_GPU_BBOX);
|
2014-11-13 23:26:49 +01:00
|
|
|
|
2015-01-31 12:43:58 +01:00
|
|
|
AsyncRequests::Event e;
|
|
|
|
|
u16 result;
|
|
|
|
|
e.time = 0;
|
|
|
|
|
e.type = AsyncRequests::Event::BBOX_READ;
|
|
|
|
|
e.bbox.index = index;
|
|
|
|
|
e.bbox.data = &result;
|
|
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, true);
|
2014-11-13 23:26:49 +01:00
|
|
|
|
2015-01-31 12:43:58 +01:00
|
|
|
return result;
|
2014-11-13 23:26:49 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::InitializeShared()
|
2012-01-02 02:20:22 -08:00
|
|
|
{
|
|
|
|
|
VideoCommon_Init();
|
|
|
|
|
|
2014-08-24 19:13:46 -04:00
|
|
|
s_FifoShuttingDown.Clear();
|
2012-01-02 02:20:22 -08:00
|
|
|
memset((void*)&s_beginFieldArgs, 0, sizeof(s_beginFieldArgs));
|
2012-12-23 13:32:23 +01:00
|
|
|
m_invalid = false;
|
2012-01-02 02:20:22 -08:00
|
|
|
}
|
|
|
|
|
|
2011-01-30 21:26:29 +00:00
|
|
|
// Run from the CPU thread
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::DoState(PointerWrap& p)
|
2010-12-16 18:21:14 +00:00
|
|
|
{
|
2013-02-26 18:28:56 -05:00
|
|
|
bool software = false;
|
|
|
|
|
p.Do(software);
|
2013-04-24 09:21:54 -04:00
|
|
|
|
2013-02-26 18:28:56 -05:00
|
|
|
if (p.GetMode() == PointerWrap::MODE_READ && software == true)
|
2013-04-24 09:21:54 -04:00
|
|
|
{
|
2013-02-26 18:28:56 -05:00
|
|
|
// change mode to abort load of incompatible save state.
|
|
|
|
|
p.SetMode(PointerWrap::MODE_VERIFY);
|
2013-04-24 09:21:54 -04:00
|
|
|
}
|
|
|
|
|
|
2011-12-30 20:16:12 -08:00
|
|
|
VideoCommon_DoState(p);
|
2012-01-01 13:52:31 -08:00
|
|
|
p.DoMarker("VideoCommon");
|
|
|
|
|
|
|
|
|
|
p.Do(s_beginFieldArgs);
|
2016-01-12 09:35:24 +01:00
|
|
|
p.DoMarker("VideoBackendBase");
|
2011-12-30 20:16:12 -08:00
|
|
|
|
|
|
|
|
// Refresh state.
|
|
|
|
|
if (p.GetMode() == PointerWrap::MODE_READ)
|
2010-12-16 18:21:14 +00:00
|
|
|
{
|
2012-12-23 13:32:23 +01:00
|
|
|
m_invalid = true;
|
2012-01-01 12:46:02 -08: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
|
|
|
}
|
2011-02-08 10:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::CheckInvalidState()
|
2013-04-24 09:21:54 -04:00
|
|
|
{
|
2012-12-23 13:32:23 +01:00
|
|
|
if (m_invalid)
|
|
|
|
|
{
|
|
|
|
|
m_invalid = false;
|
2013-10-29 01:23:17 -04:00
|
|
|
|
2012-12-23 13:32:23 +01:00
|
|
|
BPReload();
|
2015-11-06 01:28:05 +01:00
|
|
|
TextureCacheBase::Invalidate();
|
2012-12-23 13:32:23 +01:00
|
|
|
}
|
|
|
|
|
}
|