2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2011 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2011-01-31 02:28:32 +01:00
|
|
|
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
|
|
|
|
2016-02-16 03:29:24 +01:00
|
|
|
#include <algorithm>
|
2018-03-18 20:24:15 +01:00
|
|
|
#include <cstring>
|
2016-02-16 03:29:24 +01:00
|
|
|
#include <memory>
|
2016-01-17 22:54:31 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-11-14 04:33:26 +01:00
|
|
|
#include <fmt/format.h>
|
2020-01-24 09:29:38 +01:00
|
|
|
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "Common/ChunkFile.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/Event.h"
|
2020-11-04 20:59:34 +01:00
|
|
|
#include "Common/FileUtil.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "Common/Logging/Log.h"
|
2020-01-24 09:29:38 +01:00
|
|
|
|
2020-05-04 01:21:51 +02:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2018-09-28 06:22:18 +02:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2023-05-07 02:18:17 +02:00
|
|
|
#include "Core/DolphinAnalytics.h"
|
2022-01-07 03:50:18 +01:00
|
|
|
#include "Core/System.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
|
2011-01-31 02:28:32 +01:00
|
|
|
// TODO: ugly
|
|
|
|
#ifdef _WIN32
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
2019-03-28 11:35:46 +01:00
|
|
|
#include "VideoBackends/D3D12/VideoBackend.h"
|
2011-01-31 02:28:32 +01:00
|
|
|
#endif
|
2014-02-03 14:02:17 +01:00
|
|
|
#include "VideoBackends/Null/VideoBackend.h"
|
2019-11-26 05:31:45 +01:00
|
|
|
#ifdef HAS_OPENGL
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoBackends/OGL/VideoBackend.h"
|
|
|
|
#include "VideoBackends/Software/VideoBackend.h"
|
2019-11-26 05:31:45 +01:00
|
|
|
#endif
|
2020-10-23 23:51:10 +02:00
|
|
|
#ifdef HAS_VULKAN
|
2016-08-13 14:57:50 +02:00
|
|
|
#include "VideoBackends/Vulkan/VideoBackend.h"
|
2020-10-23 23:51:10 +02:00
|
|
|
#endif
|
2022-06-01 11:58:13 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include "VideoBackends/Metal/VideoBackend.h"
|
|
|
|
#endif
|
2011-03-16 23:48:17 +01:00
|
|
|
|
2023-01-27 01:21:09 +01:00
|
|
|
#include "VideoCommon/AbstractGfx.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/AsyncRequests.h"
|
|
|
|
#include "VideoCommon/BPStructs.h"
|
2023-01-27 01:21:09 +01:00
|
|
|
#include "VideoCommon/BoundingBox.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
|
|
|
#include "VideoCommon/Fifo.h"
|
2023-01-27 05:03:15 +01:00
|
|
|
#include "VideoCommon/FrameDumper.h"
|
2022-07-25 07:20:33 +02:00
|
|
|
#include "VideoCommon/FramebufferManager.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/GeometryShaderManager.h"
|
2023-01-29 17:01:05 +01:00
|
|
|
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/IndexGenerator.h"
|
|
|
|
#include "VideoCommon/OpcodeDecoding.h"
|
|
|
|
#include "VideoCommon/PixelEngine.h"
|
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
2023-01-27 05:03:15 +01:00
|
|
|
#include "VideoCommon/Present.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2021-10-10 04:49:59 +02:00
|
|
|
#include "VideoCommon/TMEM.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
2019-06-29 10:35:12 +02:00
|
|
|
#include "VideoCommon/VertexManagerBase.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
2019-07-17 02:18:48 +02:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2018-03-18 20:24:15 +01:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
#include "VideoCommon/VideoState.h"
|
2023-01-31 05:58:54 +01:00
|
|
|
#include "VideoCommon/Widescreen.h"
|
2023-11-25 23:23:54 +01:00
|
|
|
#include "VideoCommon/XFStateManager.h"
|
2014-02-19 02:27:20 +01:00
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
VideoBackendBase* g_video_backend = nullptr;
|
2011-01-31 02:28:32 +01:00
|
|
|
|
2011-03-19 13:58:55 +01:00
|
|
|
#ifdef _WIN32
|
2013-08-11 16:30:19 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
2014-10-04 21:12:15 +02:00
|
|
|
// Nvidia drivers >= v302 will check if the application exports a global
|
|
|
|
// variable named NvOptimusEnablement to know if it should run the app in high
|
|
|
|
// performance graphics mode or using the IGP.
|
2020-09-10 07:09:34 +02:00
|
|
|
// AMD drivers >= 13.35 do the same, but for the variable
|
|
|
|
// named AmdPowerXpressRequestHighPerformance instead.
|
2014-10-04 21:12:15 +02:00
|
|
|
extern "C" {
|
|
|
|
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
|
2020-09-10 07:09:34 +02:00
|
|
|
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
|
2014-10-04 21:12:15 +02:00
|
|
|
}
|
2011-03-19 13:58:55 +01:00
|
|
|
#endif
|
|
|
|
|
2020-01-24 09:29:38 +01:00
|
|
|
std::string VideoBackendBase::BadShaderFilename(const char* shader_stage, int counter)
|
|
|
|
{
|
|
|
|
return fmt::format("{}bad_{}_{}_{}.txt", File::GetUserPath(D_DUMP_IDX), shader_stage,
|
|
|
|
g_video_backend->GetName(), counter);
|
|
|
|
}
|
|
|
|
|
2018-03-18 20:24:15 +01:00
|
|
|
void VideoBackendBase::Video_ExitLoop()
|
|
|
|
{
|
2022-12-09 20:01:25 +01:00
|
|
|
auto& system = Core::System::GetInstance();
|
2023-12-19 03:31:32 +01:00
|
|
|
system.GetFifo().ExitGpuLoop();
|
2018-03-18 20:24:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run from the CPU thread (from VideoInterface.cpp)
|
2021-08-04 00:55:38 +02:00
|
|
|
void VideoBackendBase::Video_OutputXFB(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height,
|
|
|
|
u64 ticks)
|
2018-03-18 20:24:15 +01:00
|
|
|
{
|
2023-01-30 13:19:19 +01:00
|
|
|
if (m_initialized && g_presenter && !g_ActiveConfig.bImmediateXFB)
|
2018-03-18 20:24:15 +01:00
|
|
|
{
|
2022-12-09 20:01:25 +01:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
system.GetFifo().SyncGPU(Fifo::SyncGPUReason::Swap);
|
2018-03-18 20:24:15 +01:00
|
|
|
|
|
|
|
AsyncRequests::Event e;
|
|
|
|
e.time = ticks;
|
|
|
|
e.type = AsyncRequests::Event::SWAP_EVENT;
|
|
|
|
|
2018-05-20 22:20:21 +02:00
|
|
|
e.swap_event.xfbAddr = xfb_addr;
|
|
|
|
e.swap_event.fbWidth = fb_width;
|
|
|
|
e.swap_event.fbStride = fb_stride;
|
|
|
|
e.swap_event.fbHeight = fb_height;
|
2018-03-18 20:24:15 +01:00
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-20 22:20:21 +02:00
|
|
|
u32 VideoBackendBase::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 data)
|
2018-03-18 20:24:15 +01:00
|
|
|
{
|
|
|
|
if (!g_ActiveConfig.bEFBAccessEnable || x >= EFB_WIDTH || y >= EFB_HEIGHT)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == EFBAccessType::PokeColor || type == EFBAccessType::PokeZ)
|
|
|
|
{
|
|
|
|
AsyncRequests::Event e;
|
|
|
|
e.type = type == EFBAccessType::PokeColor ? AsyncRequests::Event::EFB_POKE_COLOR :
|
|
|
|
AsyncRequests::Event::EFB_POKE_Z;
|
|
|
|
e.time = 0;
|
2018-05-20 22:20:21 +02:00
|
|
|
e.efb_poke.data = data;
|
2018-03-18 20:24:15 +01:00
|
|
|
e.efb_poke.x = x;
|
|
|
|
e.efb_poke.y = y;
|
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AsyncRequests::Event e;
|
|
|
|
u32 result;
|
|
|
|
e.type = type == EFBAccessType::PeekColor ? 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;
|
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, true);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 VideoBackendBase::Video_GetQueryResult(PerfQueryType type)
|
|
|
|
{
|
|
|
|
if (!g_perf_query->ShouldEmulate())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-12-09 20:01:25 +01:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
system.GetFifo().SyncGPU(Fifo::SyncGPUReason::PerfQuery);
|
2018-03-18 20:24:15 +01:00
|
|
|
|
|
|
|
AsyncRequests::Event e;
|
|
|
|
e.time = 0;
|
|
|
|
e.type = AsyncRequests::Event::PERF_QUERY;
|
|
|
|
|
|
|
|
if (!g_perf_query->IsFlushed())
|
|
|
|
AsyncRequests::GetInstance()->PushEvent(e, true);
|
|
|
|
|
|
|
|
return g_perf_query->GetQueryResult(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 VideoBackendBase::Video_GetBoundingBox(int index)
|
|
|
|
{
|
2023-05-07 02:18:17 +02:00
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::READS_BOUNDING_BOX);
|
|
|
|
|
2018-03-18 20:24:15 +01:00
|
|
|
if (!g_ActiveConfig.bBBoxEnable)
|
|
|
|
{
|
|
|
|
static bool warn_once = true;
|
|
|
|
if (warn_once)
|
|
|
|
{
|
2020-11-14 04:33:26 +01:00
|
|
|
ERROR_LOG_FMT(VIDEO,
|
|
|
|
"BBox shall be used but it is disabled. Please use a gameini to enable it "
|
|
|
|
"for this game.");
|
2018-03-18 20:24:15 +01:00
|
|
|
}
|
|
|
|
warn_once = false;
|
|
|
|
}
|
2021-05-31 22:31:27 +02:00
|
|
|
else if (!g_ActiveConfig.backend_info.bSupportsBBox)
|
2018-03-18 20:24:15 +01:00
|
|
|
{
|
|
|
|
static bool warn_once = true;
|
|
|
|
if (warn_once)
|
|
|
|
{
|
2020-11-14 04:33:26 +01:00
|
|
|
PanicAlertFmtT(
|
|
|
|
"This game requires bounding box emulation to run properly but your graphics "
|
|
|
|
"card or its drivers do not support it. As a result you will experience bugs or "
|
|
|
|
"freezes while running this game.");
|
2018-03-18 20:24:15 +01:00
|
|
|
}
|
|
|
|
warn_once = false;
|
|
|
|
}
|
|
|
|
|
2022-12-09 20:01:25 +01:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
system.GetFifo().SyncGPU(Fifo::SyncGPUReason::BBox);
|
2018-03-18 20:24:15 +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);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-10-21 21:34:38 +02:00
|
|
|
static VideoBackendBase* GetDefaultVideoBackend()
|
|
|
|
{
|
|
|
|
const auto& backends = VideoBackendBase::GetAvailableBackends();
|
|
|
|
if (backends.empty())
|
|
|
|
return nullptr;
|
|
|
|
return backends.front().get();
|
|
|
|
}
|
|
|
|
|
2020-09-06 12:56:45 +02:00
|
|
|
std::string VideoBackendBase::GetDefaultBackendName()
|
|
|
|
{
|
2020-10-21 21:41:28 +02:00
|
|
|
auto* default_backend = GetDefaultVideoBackend();
|
|
|
|
return default_backend ? default_backend->GetName() : "";
|
2020-09-06 12:56:45 +02:00
|
|
|
}
|
|
|
|
|
2020-10-21 21:34:38 +02:00
|
|
|
const std::vector<std::unique_ptr<VideoBackendBase>>& VideoBackendBase::GetAvailableBackends()
|
2011-01-31 02:28:32 +01:00
|
|
|
{
|
2020-10-21 21:34:38 +02:00
|
|
|
static auto s_available_backends = [] {
|
|
|
|
std::vector<std::unique_ptr<VideoBackendBase>> backends;
|
|
|
|
|
2011-01-31 02:28:32 +01:00
|
|
|
#ifdef _WIN32
|
2020-10-21 21:34:38 +02:00
|
|
|
backends.push_back(std::make_unique<DX11::VideoBackend>());
|
|
|
|
backends.push_back(std::make_unique<DX12::VideoBackend>());
|
2012-12-17 21:54:20 +01:00
|
|
|
#endif
|
2024-03-16 01:51:04 +01:00
|
|
|
#ifdef HAS_OPENGL
|
|
|
|
backends.push_back(std::make_unique<OGL::VideoBackend>());
|
|
|
|
#endif
|
2020-10-23 23:51:10 +02:00
|
|
|
#ifdef HAS_VULKAN
|
2023-02-15 19:22:56 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// Emplace the Vulkan backend at the beginning so it takes precedence over OpenGL.
|
2024-03-16 01:51:04 +01:00
|
|
|
// On macOS, we prefer Vulkan over OpenGL due to OpenGL support being deprecated by Apple.
|
2023-02-15 19:22:56 +01:00
|
|
|
backends.emplace(backends.begin(), std::make_unique<Vulkan::VideoBackend>());
|
|
|
|
#else
|
2022-06-02 04:49:56 +02:00
|
|
|
backends.push_back(std::make_unique<Vulkan::VideoBackend>());
|
2021-07-25 22:11:01 +02:00
|
|
|
#endif
|
2018-09-03 18:09:23 +02:00
|
|
|
#endif
|
2023-02-15 19:22:56 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
backends.emplace(backends.begin(), std::make_unique<Metal::VideoBackend>());
|
|
|
|
#endif
|
2019-11-26 05:31:45 +01:00
|
|
|
#ifdef HAS_OPENGL
|
2020-10-21 21:34:38 +02:00
|
|
|
backends.push_back(std::make_unique<SW::VideoSoftware>());
|
2019-11-26 05:31:45 +01:00
|
|
|
#endif
|
2020-10-21 21:34:38 +02:00
|
|
|
backends.push_back(std::make_unique<Null::VideoBackend>());
|
2016-02-16 03:29:24 +01:00
|
|
|
|
2020-10-21 21:34:38 +02:00
|
|
|
if (!backends.empty())
|
|
|
|
g_video_backend = backends.front().get();
|
2016-02-16 03:29:24 +01:00
|
|
|
|
2020-10-21 21:34:38 +02:00
|
|
|
return backends;
|
|
|
|
}();
|
|
|
|
return s_available_backends;
|
2011-01-31 02:28:32 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::ActivateBackend(const std::string& name)
|
2011-01-31 02:28:32 +01:00
|
|
|
{
|
2016-02-16 03:29:24 +01:00
|
|
|
// If empty, set it to the default backend (expected behavior)
|
|
|
|
if (name.empty())
|
2020-10-21 21:34:38 +02:00
|
|
|
g_video_backend = GetDefaultVideoBackend();
|
2012-09-25 02:47:37 +02:00
|
|
|
|
2020-10-21 21:34:38 +02:00
|
|
|
const auto& backends = GetAvailableBackends();
|
|
|
|
const auto iter = std::find_if(backends.begin(), backends.end(), [&name](const auto& backend) {
|
|
|
|
return name == backend->GetName();
|
|
|
|
});
|
2016-02-16 03:29:24 +01:00
|
|
|
|
2020-10-21 21:34:38 +02:00
|
|
|
if (iter == backends.end())
|
2016-02-16 03:29:24 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_video_backend = iter->get();
|
2011-01-31 02:28:32 +01:00
|
|
|
}
|
2018-03-18 20:24:15 +01:00
|
|
|
|
2023-03-26 01:16:53 +01:00
|
|
|
void VideoBackendBase::PopulateBackendInfo(const WindowSystemInfo& wsi)
|
2018-09-28 06:22:18 +02:00
|
|
|
{
|
2022-05-17 01:59:23 +02:00
|
|
|
g_Config.Refresh();
|
2022-07-13 09:55:54 +02:00
|
|
|
// Reset backend_info so if the backend forgets to initialize something it doesn't end up using
|
|
|
|
// a value from the previously used renderer
|
|
|
|
g_Config.backend_info = {};
|
2020-05-04 01:21:51 +02:00
|
|
|
ActivateBackend(Config::Get(Config::MAIN_GFX_BACKEND));
|
2022-10-23 02:48:50 +02:00
|
|
|
g_Config.backend_info.DisplayName = g_video_backend->GetDisplayName();
|
2023-03-26 01:16:53 +01:00
|
|
|
g_video_backend->InitBackendInfo(wsi);
|
2022-05-17 01:59:23 +02:00
|
|
|
// We validate the config after initializing the backend info, as system-specific settings
|
|
|
|
// such as anti-aliasing, or the selected adapter may be invalid, and should be checked.
|
|
|
|
g_Config.VerifyValidity();
|
2018-09-28 06:22:18 +02:00
|
|
|
}
|
|
|
|
|
2023-03-26 01:16:53 +01:00
|
|
|
void VideoBackendBase::PopulateBackendInfoFromUI(const WindowSystemInfo& wsi)
|
2020-05-04 01:21:51 +02:00
|
|
|
{
|
|
|
|
// If the core is running, the backend info will have been populated already.
|
|
|
|
// If we did it here, the UI thread can race with the with the GPU thread.
|
2024-04-09 05:33:55 +02:00
|
|
|
if (!Core::IsRunning(Core::System::GetInstance()))
|
2023-03-26 01:16:53 +01:00
|
|
|
PopulateBackendInfo(wsi);
|
2020-05-04 01:21:51 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 20:24:15 +01:00
|
|
|
void VideoBackendBase::DoState(PointerWrap& p)
|
2019-06-29 10:35:12 +02:00
|
|
|
{
|
2022-12-09 20:01:25 +01:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
if (!system.IsDualCoreMode())
|
2019-06-29 10:35:12 +02:00
|
|
|
{
|
2019-06-29 11:27:53 +02:00
|
|
|
VideoCommon_DoState(p);
|
2019-06-29 10:35:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AsyncRequests::Event ev = {};
|
|
|
|
ev.do_save_state.p = &p;
|
|
|
|
ev.type = AsyncRequests::Event::DO_SAVE_STATE;
|
|
|
|
AsyncRequests::GetInstance()->PushEvent(ev, true);
|
|
|
|
|
|
|
|
// Let the GPU thread sleep after loading the state, so we're not spinning if paused after loading
|
|
|
|
// a state. The next GP burst will wake it up again.
|
2022-12-09 20:01:25 +01:00
|
|
|
system.GetFifo().GpuMaySleep();
|
2019-06-29 10:35:12 +02:00
|
|
|
}
|
|
|
|
|
2023-01-28 02:53:19 +01:00
|
|
|
bool VideoBackendBase::InitializeShared(std::unique_ptr<AbstractGfx> gfx,
|
|
|
|
std::unique_ptr<VertexManagerBase> vertex_manager,
|
|
|
|
std::unique_ptr<PerfQueryBase> perf_query,
|
|
|
|
std::unique_ptr<BoundingBox> bounding_box)
|
|
|
|
{
|
|
|
|
// All hardware backends use the default RendererBase and TextureCacheBase.
|
|
|
|
// Only Null and Software backends override them
|
|
|
|
|
|
|
|
return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
|
|
|
|
std::move(bounding_box), std::make_unique<Renderer>(),
|
|
|
|
std::make_unique<TextureCacheBase>());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoBackendBase::InitializeShared(std::unique_ptr<AbstractGfx> gfx,
|
|
|
|
std::unique_ptr<VertexManagerBase> vertex_manager,
|
|
|
|
std::unique_ptr<PerfQueryBase> perf_query,
|
|
|
|
std::unique_ptr<BoundingBox> bounding_box,
|
|
|
|
std::unique_ptr<Renderer> renderer,
|
|
|
|
std::unique_ptr<TextureCacheBase> texture_cache)
|
2018-03-18 20:24:15 +01:00
|
|
|
{
|
2020-12-16 15:01:20 +01:00
|
|
|
memset(reinterpret_cast<u8*>(&g_main_cp_state), 0, sizeof(g_main_cp_state));
|
|
|
|
memset(reinterpret_cast<u8*>(&g_preprocess_cp_state), 0, sizeof(g_preprocess_cp_state));
|
2024-04-13 18:29:52 +02:00
|
|
|
s_tex_mem.fill(0);
|
2018-03-18 20:24:15 +01:00
|
|
|
|
|
|
|
// do not initialize again for the config window
|
|
|
|
m_initialized = true;
|
|
|
|
|
2023-01-28 02:53:19 +01:00
|
|
|
g_gfx = std::move(gfx);
|
|
|
|
g_vertex_manager = std::move(vertex_manager);
|
|
|
|
g_perf_query = std::move(perf_query);
|
|
|
|
g_bounding_box = std::move(bounding_box);
|
|
|
|
|
|
|
|
// Null and Software Backends supply their own derived Renderer and Texture Cache
|
|
|
|
g_texture_cache = std::move(texture_cache);
|
|
|
|
g_renderer = std::move(renderer);
|
|
|
|
|
2023-01-27 05:03:15 +01:00
|
|
|
g_presenter = std::make_unique<VideoCommon::Presenter>();
|
2023-01-26 23:34:59 +01:00
|
|
|
g_frame_dumper = std::make_unique<FrameDumper>();
|
2023-01-27 01:21:09 +01:00
|
|
|
g_framebuffer_manager = std::make_unique<FramebufferManager>();
|
|
|
|
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
|
2023-01-29 17:01:05 +01:00
|
|
|
g_graphics_mod_manager = std::make_unique<GraphicsModManager>();
|
2023-01-31 05:58:54 +01:00
|
|
|
g_widescreen = std::make_unique<WidescreenManager>();
|
2023-01-27 05:03:15 +01:00
|
|
|
|
2023-01-31 10:40:43 +01:00
|
|
|
if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
|
|
|
|
!g_perf_query->Initialize() || !g_presenter->Initialize() ||
|
|
|
|
!g_framebuffer_manager->Initialize() || !g_texture_cache->Initialize() ||
|
2024-01-20 12:34:24 +01:00
|
|
|
(g_ActiveConfig.backend_info.bSupportsBBox && !g_bounding_box->Initialize()) ||
|
|
|
|
!g_graphics_mod_manager->Initialize())
|
2023-01-31 10:40:43 +01:00
|
|
|
{
|
|
|
|
PanicAlertFmtT("Failed to initialize renderer classes");
|
|
|
|
Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-27 13:50:50 +01:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
auto& command_processor = system.GetCommandProcessor();
|
2023-12-20 14:40:38 +01:00
|
|
|
command_processor.Init();
|
2023-12-19 03:31:32 +01:00
|
|
|
system.GetFifo().Init();
|
2023-12-22 19:54:24 +01:00
|
|
|
system.GetPixelEngine().Init();
|
2018-03-18 20:24:15 +01:00
|
|
|
BPInit();
|
|
|
|
VertexLoaderManager::Init();
|
2022-12-28 15:38:46 +01:00
|
|
|
system.GetVertexShaderManager().Init();
|
2022-12-29 15:27:48 +01:00
|
|
|
system.GetGeometryShaderManager().Init();
|
2022-12-27 17:42:02 +01:00
|
|
|
system.GetPixelShaderManager().Init();
|
2023-11-25 23:23:54 +01:00
|
|
|
system.GetXFStateManager().Init();
|
2021-10-10 04:49:59 +02:00
|
|
|
TMEM::Init();
|
2023-01-26 23:34:59 +01:00
|
|
|
|
2019-03-09 14:31:40 +01:00
|
|
|
g_Config.VerifyValidity();
|
2018-03-18 20:24:15 +01:00
|
|
|
UpdateActiveConfig();
|
2023-01-27 01:21:09 +01:00
|
|
|
|
|
|
|
g_shader_cache->InitializeShaderCache();
|
2023-01-28 02:53:19 +01:00
|
|
|
|
|
|
|
return true;
|
2018-03-18 20:24:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackendBase::ShutdownShared()
|
|
|
|
{
|
2023-01-27 05:03:15 +01:00
|
|
|
g_frame_dumper.reset();
|
|
|
|
g_presenter.reset();
|
|
|
|
|
2022-07-25 07:20:33 +02:00
|
|
|
if (g_shader_cache)
|
|
|
|
g_shader_cache->Shutdown();
|
|
|
|
if (g_texture_cache)
|
|
|
|
g_texture_cache->Shutdown();
|
|
|
|
|
2023-01-27 01:21:09 +01:00
|
|
|
g_bounding_box.reset();
|
2022-07-25 07:20:33 +02:00
|
|
|
g_perf_query.reset();
|
2023-09-03 21:57:51 +02:00
|
|
|
g_graphics_mod_manager.reset();
|
2022-07-25 07:20:33 +02:00
|
|
|
g_texture_cache.reset();
|
|
|
|
g_framebuffer_manager.reset();
|
|
|
|
g_shader_cache.reset();
|
|
|
|
g_vertex_manager.reset();
|
|
|
|
g_renderer.reset();
|
2023-01-31 05:58:54 +01:00
|
|
|
g_widescreen.reset();
|
2023-01-27 01:21:09 +01:00
|
|
|
g_presenter.reset();
|
|
|
|
g_gfx.reset();
|
2022-07-25 07:20:33 +02:00
|
|
|
|
2018-03-18 20:24:15 +01:00
|
|
|
m_initialized = false;
|
|
|
|
|
2022-12-09 20:01:25 +01:00
|
|
|
auto& system = Core::System::GetInstance();
|
2018-03-18 20:24:15 +01:00
|
|
|
VertexLoaderManager::Clear();
|
2022-12-09 20:01:25 +01:00
|
|
|
system.GetFifo().Shutdown();
|
2018-03-18 20:24:15 +01:00
|
|
|
}
|