2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-05-14 16:33:19 +00:00
|
|
|
#include <atomic>
|
2015-10-09 18:50:36 +00:00
|
|
|
#include <memory>
|
2014-03-12 19:33:41 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2014-06-05 23:29:54 +00:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2014-08-02 06:21:03 +00:00
|
|
|
#include "Core/Host.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "VideoBackends/Software/Clipper.h"
|
|
|
|
#include "VideoBackends/Software/DebugUtil.h"
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoBackends/Software/EfbCopy.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/Software/EfbInterface.h"
|
|
|
|
#include "VideoBackends/Software/Rasterizer.h"
|
2015-09-26 08:07:48 +00:00
|
|
|
#include "VideoBackends/Software/SWOGLWindow.h"
|
2014-02-19 11:14:09 +00:00
|
|
|
#include "VideoBackends/Software/SWRenderer.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/Software/SWVertexLoader.h"
|
|
|
|
#include "VideoBackends/Software/VideoBackend.h"
|
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoCommon/BPStructs.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
2014-07-08 14:49:33 +00:00
|
|
|
#include "VideoCommon/Fifo.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "VideoCommon/FramebufferManagerBase.h"
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoCommon/IndexGenerator.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoCommon/OpcodeDecoding.h"
|
2014-03-29 02:22:15 +00:00
|
|
|
#include "VideoCommon/PixelEngine.h"
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
|
|
|
#include "VideoCommon/VideoConfig.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
|
|
|
{
|
2015-10-09 18:50:36 +00:00
|
|
|
class PerfQuery : public PerfQueryBase
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2015-10-09 18:50:36 +00:00
|
|
|
public:
|
2016-06-24 08:43:46 +00:00
|
|
|
PerfQuery() {}
|
|
|
|
~PerfQuery() {}
|
|
|
|
void EnableQuery(PerfQueryGroup type) override {}
|
|
|
|
void DisableQuery(PerfQueryGroup type) override {}
|
|
|
|
void ResetQuery() override
|
|
|
|
{
|
|
|
|
memset(EfbInterface::perf_values, 0, sizeof(EfbInterface::perf_values));
|
|
|
|
}
|
|
|
|
u32 GetQueryResult(PerfQueryType type) override { return EfbInterface::perf_values[type]; };
|
|
|
|
void FlushResults() override {}
|
|
|
|
bool IsFlushed() const override { return true; };
|
2015-10-09 18:50:36 +00:00
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
class TextureCache : public TextureCacheBase
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2015-10-09 18:50:36 +00:00
|
|
|
public:
|
2016-06-24 08:43:46 +00:00
|
|
|
void CompileShaders() override{};
|
|
|
|
void DeleteShaders() override{};
|
|
|
|
void ConvertTexture(TCacheEntryBase* entry, TCacheEntryBase* unconverted, void* palette,
|
|
|
|
TlutFormat format) override{};
|
|
|
|
void CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y,
|
|
|
|
u32 memory_stride, PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
|
|
|
bool isIntensity, bool scaleByHalf) override
|
|
|
|
{
|
|
|
|
EfbCopy::CopyEfb();
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
private:
|
2016-06-24 08:43:46 +00:00
|
|
|
struct TCacheEntry : TCacheEntryBase
|
|
|
|
{
|
|
|
|
TCacheEntry(const TCacheEntryConfig& _config) : TCacheEntryBase(_config) {}
|
|
|
|
~TCacheEntry() {}
|
|
|
|
void Load(unsigned int width, unsigned int height, unsigned int expanded_width,
|
|
|
|
unsigned int level) override
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FromRenderTarget(u8* dst, PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
|
|
|
bool scaleByHalf, unsigned int cbufid, const float* colmat) override
|
|
|
|
{
|
|
|
|
EfbCopy::CopyEfb();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CopyRectangleFromTexture(const TCacheEntryBase* source,
|
|
|
|
const MathUtil::Rectangle<int>& srcrect,
|
|
|
|
const MathUtil::Rectangle<int>& dstrect) override
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bind(unsigned int stage) override {}
|
|
|
|
bool Save(const std::string& filename, unsigned int level) override { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
TCacheEntryBase* CreateTexture(const TCacheEntryConfig& config) override
|
|
|
|
{
|
|
|
|
return new TCacheEntry(config);
|
|
|
|
}
|
2015-10-09 18:50:36 +00:00
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
class XFBSource : public XFBSourceBase
|
2011-02-08 11:02:34 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) override {}
|
|
|
|
void CopyEFB(float Gamma) override {}
|
2015-10-09 18:50:36 +00:00
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
class FramebufferManager : public FramebufferManagerBase
|
2010-06-24 20:54:03 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::unique_ptr<XFBSourceBase> CreateXFBSource(unsigned int target_width,
|
|
|
|
unsigned int target_height,
|
|
|
|
unsigned int layers) override
|
|
|
|
{
|
|
|
|
return std::make_unique<XFBSource>();
|
|
|
|
}
|
|
|
|
void GetTargetSize(unsigned int* width, unsigned int* height) override{};
|
|
|
|
void CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc,
|
|
|
|
float Gamma = 1.0f) override
|
|
|
|
{
|
|
|
|
EfbCopy::CopyEfb();
|
|
|
|
}
|
2015-10-09 18:50:36 +00:00
|
|
|
};
|
2013-04-13 05:48:53 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
std::string VideoSoftware::GetName() const
|
2013-02-26 15:42:32 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return "Software Renderer";
|
2013-02-26 15:42:32 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
std::string VideoSoftware::GetDisplayName() const
|
2012-12-17 20:54:20 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return "Software Renderer";
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
static void InitBackendInfo()
|
2013-10-29 05:23:17 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
g_Config.backend_info.APIType = API_NONE;
|
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
|
|
|
g_Config.backend_info.bSupportsEarlyZ = true;
|
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = true;
|
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = false;
|
|
|
|
|
|
|
|
// aamodes
|
|
|
|
g_Config.backend_info.AAModes = {1};
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void VideoSoftware::ShowConfig(void* hParent)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!m_initialized)
|
|
|
|
InitBackendInfo();
|
|
|
|
Host_ShowVideoConfig(hParent, GetDisplayName(), "gfx_software");
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
bool VideoSoftware::Initialize(void* window_handle)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
InitializeShared();
|
|
|
|
InitBackendInfo();
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
g_Config.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_software.ini").c_str());
|
|
|
|
g_Config.GameIniLoad();
|
|
|
|
g_Config.UpdateProjectionHack();
|
|
|
|
g_Config.VerifyValidity();
|
|
|
|
UpdateActiveConfig();
|
2013-04-14 03:54:02 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SWOGLWindow::Init(window_handle);
|
2013-04-14 03:54:02 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
PixelEngine::Init();
|
|
|
|
Clipper::Init();
|
|
|
|
Rasterizer::Init();
|
|
|
|
SWRenderer::Init();
|
|
|
|
DebugUtil::Init();
|
2013-04-14 03:54:02 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Do our OSD callbacks
|
|
|
|
OSD::DoCallbacks(OSD::CallbackType::Initialization);
|
2013-04-14 03:54:02 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
m_initialized = true;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return true;
|
2013-02-16 23:50:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
void VideoSoftware::Shutdown()
|
2014-11-13 22:26:49 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_initialized = false;
|
2014-11-13 22:26:49 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Do our OSD callbacks
|
|
|
|
OSD::DoCallbacks(OSD::CallbackType::Shutdown);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SWOGLWindow::Shutdown();
|
2013-08-20 11:51:39 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
void VideoSoftware::Video_Cleanup()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (g_renderer)
|
|
|
|
{
|
|
|
|
Fifo::Shutdown();
|
|
|
|
SWRenderer::Shutdown();
|
|
|
|
DebugUtil::Shutdown();
|
|
|
|
// The following calls are NOT Thread Safe
|
|
|
|
// And need to be called from the video thread
|
|
|
|
SWRenderer::Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
|
|
|
g_framebuffer_manager.reset();
|
|
|
|
g_texture_cache.reset();
|
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
g_perf_query.reset();
|
|
|
|
g_vertex_manager.reset();
|
|
|
|
OpcodeDecoder::Shutdown();
|
|
|
|
g_renderer.reset();
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
// This is called after Video_Initialize() from the Core
|
|
|
|
void VideoSoftware::Video_Prepare()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
g_renderer = std::make_unique<SWRenderer>();
|
|
|
|
|
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
|
|
|
|
|
|
|
BPInit();
|
|
|
|
g_vertex_manager = std::make_unique<SWVertexLoader>();
|
|
|
|
g_perf_query = std::make_unique<PerfQuery>();
|
|
|
|
Fifo::Init(); // must be done before OpcodeDecoder::Init()
|
|
|
|
OpcodeDecoder::Init();
|
|
|
|
IndexGenerator::Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderManager::Init();
|
|
|
|
g_texture_cache = std::make_unique<TextureCache>();
|
|
|
|
SWRenderer::Init();
|
|
|
|
VertexLoaderManager::Init();
|
|
|
|
g_framebuffer_manager = std::make_unique<FramebufferManager>();
|
|
|
|
|
|
|
|
// Notify the core that the video backend is ready
|
|
|
|
Host_Message(WM_USER_CREATE);
|
|
|
|
|
|
|
|
INFO_LOG(VIDEO, "Video backend initialized.");
|
2014-02-02 13:16:43 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 22:48:17 +00:00
|
|
|
unsigned int VideoSoftware::PeekMessages()
|
2011-02-07 22:01:08 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return SWOGLWindow::s_instance->PeekMessages();
|
2011-02-07 22:01:08 +00:00
|
|
|
}
|
2011-03-16 22:58:24 +00:00
|
|
|
}
|