2010-06-09 01:37:08 +00:00
|
|
|
// Copyright (C) 2003-2009 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
2010-12-02 05:38:48 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
#include "VideoConfigDialog.h"
|
|
|
|
#endif // HAVE_WX
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
|
2011-02-03 19:55:30 +00:00
|
|
|
#include "SWCommandProcessor.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
#include "OpcodeDecoder.h"
|
2011-01-29 06:26:03 +00:00
|
|
|
#include "SWVideoConfig.h"
|
2011-02-03 19:55:30 +00:00
|
|
|
#include "SWPixelEngine.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
#include "BPMemLoader.h"
|
|
|
|
#include "XFMemLoader.h"
|
|
|
|
#include "Clipper.h"
|
|
|
|
#include "Rasterizer.h"
|
2011-02-03 19:55:30 +00:00
|
|
|
#include "SWRenderer.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
#include "HwRasterizer.h"
|
|
|
|
#include "LogManager.h"
|
|
|
|
#include "EfbInterface.h"
|
|
|
|
#include "DebugUtil.h"
|
2010-12-02 05:38:48 +00:00
|
|
|
#include "FileUtil.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "VideoBackend.h"
|
2011-02-25 21:14:13 +00:00
|
|
|
#include "Core.h"
|
2013-02-26 01:05:02 +00:00
|
|
|
#include "OpcodeDecoder.h"
|
|
|
|
#include "SWVertexLoader.h"
|
2013-02-26 23:28:56 +00:00
|
|
|
#include "SWStatistics.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2012-12-17 20:54:20 +00:00
|
|
|
#define VSYNC_ENABLED 0
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
namespace SW
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
|
|
|
|
2011-03-16 23:57:13 +00:00
|
|
|
static volatile bool fifoStateRun = false;
|
|
|
|
static volatile bool emuRunningState = false;
|
2011-12-31 04:16:12 +00:00
|
|
|
static std::mutex m_csSWVidOccupied;
|
2011-03-16 22:48:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
std::string VideoSoftware::GetName()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-04-17 21:39:58 +00:00
|
|
|
return _trans("Software Renderer");
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 02:05:28 +00:00
|
|
|
void *DllDebugger(void *_hParent, bool Show)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2010-07-22 02:05:28 +00:00
|
|
|
return NULL;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::ShowConfig(void *_hParent)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2010-12-02 05:38:48 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2011-03-16 22:22:21 +00:00
|
|
|
VideoConfigDialog diag((wxWindow*)_hParent, "Software", "gfx_software");
|
|
|
|
diag.ShowModal();
|
2010-12-02 05:38:48 +00:00
|
|
|
#endif
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
bool VideoSoftware::Initialize(void *&window_handle)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2013-01-19 08:18:39 +00:00
|
|
|
g_SWVideoConfig.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_software.ini").c_str());
|
2012-12-17 20:54:20 +00:00
|
|
|
InitInterface();
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2012-12-26 06:07:43 +00:00
|
|
|
if (!GLInterface->Create(window_handle))
|
2011-02-25 21:14:13 +00:00
|
|
|
{
|
2011-03-15 23:09:12 +00:00
|
|
|
INFO_LOG(VIDEO, "%s", "SWRenderer::Create failed\n");
|
2011-02-25 21:14:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-19 08:18:39 +00:00
|
|
|
InitBPMemory();
|
|
|
|
InitXFMemory();
|
|
|
|
SWCommandProcessor::Init();
|
|
|
|
SWPixelEngine::Init();
|
|
|
|
OpcodeDecoder::Init();
|
|
|
|
Clipper::Init();
|
|
|
|
Rasterizer::Init();
|
|
|
|
HwRasterizer::Init();
|
|
|
|
SWRenderer::Init();
|
|
|
|
DebugUtil::Init();
|
2011-02-25 21:14:13 +00:00
|
|
|
|
|
|
|
return true;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 01:05:02 +00:00
|
|
|
void VideoSoftware::DoState(PointerWrap& p)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2013-02-26 23:28:56 +00:00
|
|
|
bool software = true;
|
|
|
|
p.Do(software);
|
|
|
|
if (p.GetMode() == PointerWrap::MODE_READ && software == false)
|
|
|
|
// change mode to abort load of incompatible save state.
|
|
|
|
p.SetMode(PointerWrap::MODE_VERIFY);
|
2013-02-26 23:43:37 +00:00
|
|
|
|
|
|
|
// TODO: incomplete?
|
2013-02-26 01:05:02 +00:00
|
|
|
SWCommandProcessor::DoState(p);
|
|
|
|
SWPixelEngine::DoState(p);
|
|
|
|
EfbInterface::DoState(p);
|
|
|
|
OpcodeDecoder::DoState(p);
|
2013-02-26 04:49:24 +00:00
|
|
|
Clipper::DoState(p);
|
|
|
|
p.Do(swxfregs);
|
|
|
|
p.Do(bpmem);
|
2013-02-26 23:28:56 +00:00
|
|
|
p.Do(swstats);
|
2013-02-26 04:49:24 +00:00
|
|
|
|
|
|
|
// CP Memory
|
|
|
|
p.DoArray(arraybases, 16);
|
|
|
|
p.DoArray(arraystrides, 16);
|
|
|
|
p.Do(MatrixIndexA);
|
|
|
|
p.Do(MatrixIndexB);
|
|
|
|
p.Do(g_VtxDesc.Hex);
|
|
|
|
p.DoArray(g_VtxAttr, 8);
|
|
|
|
p.DoMarker("CP Memory");
|
|
|
|
|
2011-12-31 04:16:12 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 12:32:23 +00:00
|
|
|
void VideoSoftware::CheckInvalidState()
|
|
|
|
{
|
|
|
|
// there is no state to invalidate
|
|
|
|
}
|
|
|
|
|
2011-12-31 04:16:12 +00:00
|
|
|
void VideoSoftware::PauseAndLock(bool doLock, bool unpauseOnUnlock)
|
|
|
|
{
|
|
|
|
if (doLock)
|
|
|
|
{
|
|
|
|
EmuStateChange(EMUSTATE_CHANGE_PAUSE);
|
|
|
|
if (!Core::IsGPUThread())
|
|
|
|
m_csSWVidOccupied.lock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (unpauseOnUnlock)
|
|
|
|
EmuStateChange(EMUSTATE_CHANGE_PLAY);
|
|
|
|
if (!Core::IsGPUThread())
|
|
|
|
m_csSWVidOccupied.unlock();
|
|
|
|
}
|
2011-02-08 11:02:34 +00:00
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::RunLoop(bool enable)
|
2011-02-08 11:02:34 +00:00
|
|
|
{
|
2011-03-16 23:57:13 +00:00
|
|
|
emuRunningState = enable;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::EmuStateChange(EMUSTATE_CHANGE newState)
|
2010-06-24 20:54:03 +00:00
|
|
|
{
|
2011-03-16 23:57:13 +00:00
|
|
|
emuRunningState = (newState == EMUSTATE_CHANGE_PLAY) ? true : false;
|
2010-06-24 20:54:03 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Shutdown()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2013-02-26 15:42:32 +00:00
|
|
|
// TODO: should be in Video_Cleanup
|
2013-01-19 08:18:39 +00:00
|
|
|
HwRasterizer::Shutdown();
|
|
|
|
SWRenderer::Shutdown();
|
2013-02-26 15:42:32 +00:00
|
|
|
|
2012-12-17 20:54:20 +00:00
|
|
|
GLInterface->Shutdown();
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 15:42:32 +00:00
|
|
|
void VideoSoftware::Video_Cleanup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
// This is called after Video_Initialize() from the Core
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_Prepare()
|
2012-12-17 20:54:20 +00:00
|
|
|
{
|
|
|
|
GLInterface->MakeCurrent();
|
2013-01-31 11:20:17 +00:00
|
|
|
// Init extension support.
|
2012-12-17 20:54:20 +00:00
|
|
|
#ifndef USE_GLES
|
2013-01-31 11:20:17 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
glewExperimental = 1;
|
|
|
|
#endif
|
2012-12-17 20:54:20 +00:00
|
|
|
if (glewInit() != GLEW_OK) {
|
2013-01-19 08:18:39 +00:00
|
|
|
ERROR_LOG(VIDEO, "glewInit() failed!Does your video card support OpenGL 2.x?");
|
|
|
|
return;
|
|
|
|
}
|
2012-12-17 20:54:20 +00:00
|
|
|
#endif
|
2013-01-24 16:31:08 +00:00
|
|
|
// Handle VSync on/off
|
|
|
|
GLInterface->SwapInterval(VSYNC_ENABLED);
|
2012-12-17 20:54:20 +00:00
|
|
|
|
2013-01-19 08:18:39 +00:00
|
|
|
HwRasterizer::Prepare();
|
|
|
|
SWRenderer::Prepare();
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-01-19 08:18:39 +00:00
|
|
|
INFO_LOG(VIDEO, "Video backend initialized.");
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_EndField()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
u32 VideoSoftware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
|
|
|
u32 value = 0;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PEEK_Z:
|
|
|
|
{
|
|
|
|
value = EfbInterface::GetDepth(x, y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case POKE_Z:
|
|
|
|
break;
|
|
|
|
case PEEK_COLOR:
|
|
|
|
{
|
|
|
|
u32 color = 0;
|
|
|
|
EfbInterface::GetColor(x, y, (u8*)&color);
|
|
|
|
|
|
|
|
// rgba to argb
|
|
|
|
value = (color >> 8) | (color & 0xff) << 24;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case POKE_COLOR:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
u32 VideoSoftware::Video_GetQueryResult(PerfQueryType type)
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
bool VideoSoftware::Video_Screenshot(const char *_szFilename)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
return false;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// Enter and exit the video loop
|
|
|
|
// -------------------------------
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_EnterLoop()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-12-31 04:16:12 +00:00
|
|
|
std::lock_guard<std::mutex> lk(m_csSWVidOccupied);
|
2011-03-16 22:48:17 +00:00
|
|
|
fifoStateRun = true;
|
|
|
|
|
2011-03-16 23:57:13 +00:00
|
|
|
while (fifoStateRun)
|
|
|
|
{
|
2011-03-16 22:48:17 +00:00
|
|
|
g_video_backend->PeekMessages();
|
2011-03-16 23:57:13 +00:00
|
|
|
|
|
|
|
if (!SWCommandProcessor::RunBuffer())
|
|
|
|
{
|
|
|
|
Common::YieldCPU();
|
2011-03-16 22:48:17 +00:00
|
|
|
}
|
2011-03-16 23:57:13 +00:00
|
|
|
|
2011-03-17 10:17:45 +00:00
|
|
|
while (!emuRunningState && fifoStateRun)
|
2011-03-16 23:57:13 +00:00
|
|
|
{
|
2011-03-17 10:17:45 +00:00
|
|
|
g_video_backend->PeekMessages();
|
2011-12-31 04:16:12 +00:00
|
|
|
m_csSWVidOccupied.unlock();
|
2011-03-17 10:17:45 +00:00
|
|
|
Common::SleepCurrentThread(1);
|
2011-12-31 04:16:12 +00:00
|
|
|
m_csSWVidOccupied.lock();
|
2011-03-16 23:57:13 +00:00
|
|
|
}
|
2011-03-17 10:17:45 +00:00
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_ExitLoop()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-03-16 22:48:17 +00:00
|
|
|
fifoStateRun = false;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
// TODO : could use the OSD class in video common, we would need to implement the Renderer class
|
|
|
|
// however most of it is useless for the SW backend so we could as well move it to its own class
|
|
|
|
void VideoSoftware::Video_AddMessage(const char* pstr, u32 milliseconds)
|
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_ClearMessages()
|
2011-02-03 19:55:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_SetRendering(bool bEnabled)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-03-16 22:48:17 +00:00
|
|
|
SWCommandProcessor::SetRendering(bEnabled);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_GatherPipeBursted()
|
|
|
|
{
|
|
|
|
SWCommandProcessor::GatherPipeBursted();
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
bool VideoSoftware::Video_IsPossibleWaitingSetDrawDone(void)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
return false;
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 05:40:10 +00:00
|
|
|
bool VideoSoftware::Video_IsHiWatermarkActive(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::Video_AbortFrame(void)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2011-02-03 19:55:30 +00:00
|
|
|
}
|
2010-06-24 13:28:54 +00:00
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
readFn16 VideoSoftware::Video_CPRead16()
|
|
|
|
{
|
|
|
|
return SWCommandProcessor::Read16;
|
|
|
|
}
|
|
|
|
writeFn16 VideoSoftware::Video_CPWrite16()
|
|
|
|
{
|
|
|
|
return SWCommandProcessor::Write16;
|
|
|
|
}
|
|
|
|
|
|
|
|
readFn16 VideoSoftware::Video_PERead16()
|
|
|
|
{
|
|
|
|
return SWPixelEngine::Read16;
|
|
|
|
}
|
|
|
|
writeFn16 VideoSoftware::Video_PEWrite16()
|
|
|
|
{
|
|
|
|
return SWPixelEngine::Write16;
|
|
|
|
}
|
|
|
|
writeFn32 VideoSoftware::Video_PEWrite32()
|
|
|
|
{
|
|
|
|
return SWPixelEngine::Write32;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-07 22:01:08 +00:00
|
|
|
// Draw messages on top of the screen
|
2011-03-16 22:48:17 +00:00
|
|
|
unsigned int VideoSoftware::PeekMessages()
|
2011-02-07 22:01:08 +00:00
|
|
|
{
|
2012-12-17 20:54:20 +00:00
|
|
|
return GLInterface->PeekMessages();
|
2011-02-07 22:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show the current FPS
|
2011-03-16 22:48:17 +00:00
|
|
|
void VideoSoftware::UpdateFPSDisplay(const char *text)
|
2011-02-07 22:01:08 +00:00
|
|
|
{
|
|
|
|
char temp[100];
|
2011-08-21 21:30:19 +00:00
|
|
|
snprintf(temp, sizeof temp, "%s | Software | %s", scm_rev_str, text);
|
2012-12-17 20:54:20 +00:00
|
|
|
GLInterface->UpdateFPSDisplay(temp);
|
2011-02-07 22:01:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:58:24 +00:00
|
|
|
}
|