42 changes: 30 additions & 12 deletions Source/Core/DolphinLib.props
Expand Up @@ -109,6 +109,7 @@
<ClInclude Include="Common\GL\GLUtil.h" />
<ClInclude Include="Common\GL\GLX11Window.h" />
<ClInclude Include="Common\Hash.h" />
<ClInclude Include="Common\HookableEvent.h" />
<ClInclude Include="Common\HRWrap.h" />
<ClInclude Include="Common\HttpRequest.h" />
<ClInclude Include="Common\Image.h" />
Expand Down Expand Up @@ -145,6 +146,7 @@
<ClInclude Include="Common\SFMLHelper.h" />
<ClInclude Include="Common\SocketContext.h" />
<ClInclude Include="Common\SPSCQueue.h" />
<ClInclude Include="Common\StringLiteral.h" />
<ClInclude Include="Common\StringUtil.h" />
<ClInclude Include="Common\Swap.h" />
<ClInclude Include="Common\SymbolDB.h" />
Expand Down Expand Up @@ -534,7 +536,7 @@
<ClInclude Include="VideoBackends\D3D\D3DBase.h" />
<ClInclude Include="VideoBackends\D3D\D3DBoundingBox.h" />
<ClInclude Include="VideoBackends\D3D\D3DPerfQuery.h" />
<ClInclude Include="VideoBackends\D3D\D3DRender.h" />
<ClInclude Include="VideoBackends\D3D\D3DGfx.h" />
<ClInclude Include="VideoBackends\D3D\D3DState.h" />
<ClInclude Include="VideoBackends\D3D\D3DSwapChain.h" />
<ClInclude Include="VideoBackends\D3D\D3DVertexManager.h" />
Expand All @@ -545,7 +547,7 @@
<ClInclude Include="VideoBackends\D3D12\Common.h" />
<ClInclude Include="VideoBackends\D3D12\D3D12BoundingBox.h" />
<ClInclude Include="VideoBackends\D3D12\D3D12PerfQuery.h" />
<ClInclude Include="VideoBackends\D3D12\D3D12Renderer.h" />
<ClInclude Include="VideoBackends\D3D12\D3D12Gfx.h" />
<ClInclude Include="VideoBackends\D3D12\D3D12StreamBuffer.h" />
<ClInclude Include="VideoBackends\D3D12\D3D12SwapChain.h" />
<ClInclude Include="VideoBackends\D3D12\D3D12VertexManager.h" />
Expand All @@ -561,17 +563,18 @@
<ClInclude Include="VideoBackends\D3DCommon\Shader.h" />
<ClInclude Include="VideoBackends\D3DCommon\SwapChain.h" />
<ClInclude Include="VideoBackends\Null\NullBoundingBox.h" />
<ClInclude Include="VideoBackends\Null\NullRender.h" />
<ClInclude Include="VideoBackends\Null\NullGfx.h" />
<ClInclude Include="VideoBackends\Null\NullTexture.h" />
<ClInclude Include="VideoBackends\Null\NullVertexManager.h" />
<ClInclude Include="VideoBackends\Null\PerfQuery.h" />
<ClInclude Include="VideoBackends\Null\TextureCache.h" />
<ClInclude Include="VideoBackends\Null\VideoBackend.h" />
<ClInclude Include="VideoBackends\OGL\GPUTimer.h" />
<ClInclude Include="VideoBackends\OGL\OGLBoundingBox.h" />
<ClInclude Include="VideoBackends\OGL\OGLConfig.h" />
<ClInclude Include="VideoBackends\OGL\OGLGfx.h" />
<ClInclude Include="VideoBackends\OGL\OGLPerfQuery.h" />
<ClInclude Include="VideoBackends\OGL\OGLPipeline.h" />
<ClInclude Include="VideoBackends\OGL\OGLRender.h" />
<ClInclude Include="VideoBackends\OGL\OGLShader.h" />
<ClInclude Include="VideoBackends\OGL\OGLStreamBuffer.h" />
<ClInclude Include="VideoBackends\OGL\OGLTexture.h" />
Expand All @@ -587,6 +590,7 @@
<ClInclude Include="VideoBackends\Software\Rasterizer.h" />
<ClInclude Include="VideoBackends\Software\SetupUnit.h" />
<ClInclude Include="VideoBackends\Software\SWBoundingBox.h" />
<ClInclude Include="VideoBackends\Software\SWGfx.h" />
<ClInclude Include="VideoBackends\Software\SWOGLWindow.h" />
<ClInclude Include="VideoBackends\Software\SWRenderer.h" />
<ClInclude Include="VideoBackends\Software\SWTexture.h" />
Expand All @@ -608,7 +612,7 @@
<ClInclude Include="VideoBackends\Vulkan\VKBoundingBox.h" />
<ClInclude Include="VideoBackends\Vulkan\VKPerfQuery.h" />
<ClInclude Include="VideoBackends\Vulkan\VKPipeline.h" />
<ClInclude Include="VideoBackends\Vulkan\VKRenderer.h" />
<ClInclude Include="VideoBackends\Vulkan\VKGfx.h" />
<ClInclude Include="VideoBackends\Vulkan\VKShader.h" />
<ClInclude Include="VideoBackends\Vulkan\VKStreamBuffer.h" />
<ClInclude Include="VideoBackends\Vulkan\VKSwapChain.h" />
Expand All @@ -618,6 +622,7 @@
<ClInclude Include="VideoBackends\Vulkan\VulkanContext.h" />
<ClInclude Include="VideoBackends\Vulkan\VulkanLoader.h" />
<ClInclude Include="VideoCommon\AbstractFramebuffer.h" />
<ClInclude Include="VideoCommon\AbstractGfx.h" />
<ClInclude Include="VideoCommon\AbstractPipeline.h" />
<ClInclude Include="VideoCommon\AbstractShader.h" />
<ClInclude Include="VideoCommon\AbstractStagingTexture.h" />
Expand All @@ -638,7 +643,8 @@
<ClInclude Include="VideoCommon\Fifo.h" />
<ClInclude Include="VideoCommon\FramebufferManager.h" />
<ClInclude Include="VideoCommon\FramebufferShaderGen.h" />
<ClInclude Include="VideoCommon\FrameDump.h" />
<ClInclude Include="VideoCommon\FrameDumpFFMpeg.h" />
<ClInclude Include="VideoCommon\FrameDumper.h" />
<ClInclude Include="VideoCommon\FreeLookCamera.h" />
<ClInclude Include="VideoCommon\GeometryShaderGen.h" />
<ClInclude Include="VideoCommon\GeometryShaderManager.h" />
Expand Down Expand Up @@ -668,6 +674,8 @@
<ClInclude Include="VideoCommon\NetPlayChatUI.h" />
<ClInclude Include="VideoCommon\NetPlayGolfUI.h" />
<ClInclude Include="VideoCommon\OnScreenDisplay.h" />
<ClInclude Include="VideoCommon\OnScreenUI.h" />
<ClInclude Include="VideoCommon\OnScreenUIKeyMap.h" />
<ClInclude Include="VideoCommon\OpcodeDecoding.h" />
<ClInclude Include="VideoCommon\PerfQueryBase.h" />
<ClInclude Include="VideoCommon\PerformanceMetrics.h" />
Expand All @@ -676,6 +684,7 @@
<ClInclude Include="VideoCommon\PixelShaderGen.h" />
<ClInclude Include="VideoCommon\PixelShaderManager.h" />
<ClInclude Include="VideoCommon\PostProcessing.h" />
<ClInclude Include="VideoCommon\Present.h" />
<ClInclude Include="VideoCommon\RenderBase.h" />
<ClInclude Include="VideoCommon\RenderState.h" />
<ClInclude Include="VideoCommon\ShaderCache.h" />
Expand Down Expand Up @@ -707,7 +716,9 @@
<ClInclude Include="VideoCommon\VideoBackendBase.h" />
<ClInclude Include="VideoCommon\VideoCommon.h" />
<ClInclude Include="VideoCommon\VideoConfig.h" />
<ClInclude Include="VideoCommon\VideoEvents.h" />
<ClInclude Include="VideoCommon\VideoState.h" />
<ClInclude Include="VideoCommon\Widescreen.h" />
<ClInclude Include="VideoCommon\XFMemory.h" />
<ClInclude Include="VideoCommon\XFStructs.h" />
</ItemGroup>
Expand Down Expand Up @@ -1142,7 +1153,7 @@
<ClCompile Include="VideoBackends\D3D\D3DMain.cpp" />
<ClCompile Include="VideoBackends\D3D\D3DNativeVertexFormat.cpp" />
<ClCompile Include="VideoBackends\D3D\D3DPerfQuery.cpp" />
<ClCompile Include="VideoBackends\D3D\D3DRender.cpp" />
<ClCompile Include="VideoBackends\D3D\D3DGfx.cpp" />
<ClCompile Include="VideoBackends\D3D\D3DState.cpp" />
<ClCompile Include="VideoBackends\D3D\D3DSwapChain.cpp" />
<ClCompile Include="VideoBackends\D3D\D3DVertexManager.cpp" />
Expand All @@ -1151,7 +1162,7 @@
<ClCompile Include="VideoBackends\D3D\DXTexture.cpp" />
<ClCompile Include="VideoBackends\D3D12\D3D12BoundingBox.cpp" />
<ClCompile Include="VideoBackends\D3D12\D3D12PerfQuery.cpp" />
<ClCompile Include="VideoBackends\D3D12\D3D12Renderer.cpp" />
<ClCompile Include="VideoBackends\D3D12\D3D12Gfx.cpp" />
<ClCompile Include="VideoBackends\D3D12\D3D12StreamBuffer.cpp" />
<ClCompile Include="VideoBackends\D3D12\D3D12SwapChain.cpp" />
<ClCompile Include="VideoBackends\D3D12\D3D12VertexManager.cpp" />
Expand All @@ -1167,15 +1178,16 @@
<ClCompile Include="VideoBackends\D3DCommon\Shader.cpp" />
<ClCompile Include="VideoBackends\D3DCommon\SwapChain.cpp" />
<ClCompile Include="VideoBackends\Null\NullBackend.cpp" />
<ClCompile Include="VideoBackends\Null\NullRender.cpp" />
<ClCompile Include="VideoBackends\Null\NullGfx.cpp" />
<ClCompile Include="VideoBackends\Null\NullTexture.cpp" />
<ClCompile Include="VideoBackends\Null\NullVertexManager.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLBoundingBox.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLConfig.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLGfx.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLMain.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLNativeVertexFormat.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLPerfQuery.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLPipeline.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLRender.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLShader.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLStreamBuffer.cpp" />
<ClCompile Include="VideoBackends\OGL\OGLTexture.cpp" />
Expand All @@ -1189,6 +1201,7 @@
<ClCompile Include="VideoBackends\Software\SetupUnit.cpp" />
<ClCompile Include="VideoBackends\Software\SWmain.cpp" />
<ClCompile Include="VideoBackends\Software\SWBoundingBox.cpp" />
<ClCompile Include="VideoBackends\Software\SWGfx.cpp" />
<ClCompile Include="VideoBackends\Software\SWOGLWindow.cpp" />
<ClCompile Include="VideoBackends\Software\SWRenderer.cpp" />
<ClCompile Include="VideoBackends\Software\SWTexture.cpp" />
Expand All @@ -1206,7 +1219,7 @@
<ClCompile Include="VideoBackends\Vulkan\VKMain.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VKPerfQuery.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VKPipeline.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VKRenderer.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VKGfx.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VKShader.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VKStreamBuffer.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VKSwapChain.cpp" />
Expand All @@ -1216,6 +1229,7 @@
<ClCompile Include="VideoBackends\Vulkan\VulkanContext.cpp" />
<ClCompile Include="VideoBackends\Vulkan\VulkanLoader.cpp" />
<ClCompile Include="VideoCommon\AbstractFramebuffer.cpp" />
<ClCompile Include="VideoCommon\AbstractGfx.cpp" />
<ClCompile Include="VideoCommon\AbstractStagingTexture.cpp" />
<ClCompile Include="VideoCommon\AbstractTexture.cpp" />
<ClCompile Include="VideoCommon\AsyncRequests.cpp" />
Expand All @@ -1231,7 +1245,8 @@
<ClCompile Include="VideoCommon\Fifo.cpp" />
<ClCompile Include="VideoCommon\FramebufferManager.cpp" />
<ClCompile Include="VideoCommon\FramebufferShaderGen.cpp" />
<ClCompile Include="VideoCommon\FrameDump.cpp" />
<ClCompile Include="VideoCommon\FrameDumpFFMpeg.cpp" />
<ClCompile Include="VideoCommon\FrameDumper.cpp" />
<ClCompile Include="VideoCommon\FreeLookCamera.cpp" />
<ClCompile Include="VideoCommon\GeometryShaderGen.cpp" />
<ClCompile Include="VideoCommon\GeometryShaderManager.cpp" />
Expand All @@ -1254,6 +1269,7 @@
<ClCompile Include="VideoCommon\NetPlayChatUI.cpp" />
<ClCompile Include="VideoCommon\NetPlayGolfUI.cpp" />
<ClCompile Include="VideoCommon\OnScreenDisplay.cpp" />
<ClCompile Include="VideoCommon\OnScreenUI.cpp" />
<ClCompile Include="VideoCommon\OpcodeDecoding.cpp" />
<ClCompile Include="VideoCommon\PerfQueryBase.cpp" />
<ClCompile Include="VideoCommon\PerformanceMetrics.cpp" />
Expand All @@ -1262,6 +1278,7 @@
<ClCompile Include="VideoCommon\PixelShaderGen.cpp" />
<ClCompile Include="VideoCommon\PixelShaderManager.cpp" />
<ClCompile Include="VideoCommon\PostProcessing.cpp" />
<ClCompile Include="VideoCommon\Present.cpp" />
<ClCompile Include="VideoCommon\RenderBase.cpp" />
<ClCompile Include="VideoCommon\RenderState.cpp" />
<ClCompile Include="VideoCommon\ShaderCache.cpp" />
Expand Down Expand Up @@ -1291,6 +1308,7 @@
<ClCompile Include="VideoCommon\VideoBackendBase.cpp" />
<ClCompile Include="VideoCommon\VideoConfig.cpp" />
<ClCompile Include="VideoCommon\VideoState.cpp" />
<ClCompile Include="VideoCommon\Widescreen.cpp" />
<ClCompile Include="VideoCommon\XFMemory.cpp" />
<ClCompile Include="VideoCommon\XFStructs.cpp" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Source/Core/DolphinNoGUI/MainNoGUI.cpp
Expand Up @@ -33,7 +33,6 @@

#include "InputCommon/GCAdapter.h"

#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoBackendBase.h"

static std::unique_ptr<Platform> s_platform;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinNoGUI/PlatformFBDev.cpp
Expand Up @@ -12,6 +12,7 @@

#include <climits>
#include <cstdio>
#include <thread>

#include <fcntl.h>
#include <linux/fb.h>
Expand All @@ -21,7 +22,6 @@
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include "VideoCommon/RenderBase.h"

namespace
{
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/DolphinNoGUI/PlatformWin32.cpp
Expand Up @@ -13,7 +13,7 @@
#include <climits>
#include <cstdio>

#include "VideoCommon/RenderBase.h"
#include "VideoCommon/Present.h"
#include "resource.h"

namespace
Expand Down Expand Up @@ -181,8 +181,8 @@ LRESULT PlatformWin32::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam

case WM_SIZE:
{
if (g_renderer)
g_renderer->ResizeSurface();
if (g_presenter)
g_presenter->ResizeSurface();
}
break;

Expand Down
7 changes: 4 additions & 3 deletions Source/Core/DolphinNoGUI/PlatformX11.cpp
Expand Up @@ -19,13 +19,14 @@ static constexpr auto X_None = None;
#include <climits>
#include <cstdio>
#include <cstring>
#include <thread>

#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include "UICommon/X11Utils.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/Present.h"

#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
Expand Down Expand Up @@ -263,8 +264,8 @@ void PlatformX11::ProcessEvents()
break;
case ConfigureNotify:
{
if (g_renderer)
g_renderer->ResizeSurface();
if (g_presenter)
g_presenter->ResizeSurface();
}
break;
}
Expand Down
Expand Up @@ -21,7 +21,7 @@
#include "DolphinQt/Config/Graphics/EnhancementsWidget.h"

#include "VideoCommon/PostProcessing.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/VideoConfig.h"

using ConfigurationOption = VideoCommon::PostProcessingConfiguration::ConfigurationOption;
Expand All @@ -31,9 +31,9 @@ PostProcessingConfigWindow::PostProcessingConfigWindow(EnhancementsWidget* paren
const std::string& shader)
: QDialog(parent), m_shader(shader)
{
if (g_renderer && g_renderer->GetPostProcessor())
if (g_presenter && g_presenter->GetPostProcessor())
{
m_post_processor = g_renderer->GetPostProcessor()->GetConfig();
m_post_processor = g_presenter->GetPostProcessor()->GetConfig();
}
else
{
Expand All @@ -52,7 +52,7 @@ PostProcessingConfigWindow::PostProcessingConfigWindow(EnhancementsWidget* paren
PostProcessingConfigWindow::~PostProcessingConfigWindow()
{
m_post_processor->SaveOptionsConfiguration();
if (!(g_renderer && g_renderer->GetPostProcessor()))
if (!(g_presenter && g_presenter->GetPostProcessor()))
{
delete m_post_processor;
}
Expand Down
20 changes: 10 additions & 10 deletions Source/Core/DolphinQt/Host.cpp
Expand Up @@ -36,8 +36,9 @@

#include "UICommon/DiscordPresence.h"

#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/Fifo.cpp"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/VideoConfig.h"

static thread_local bool tls_is_host_thread = false;
Expand Down Expand Up @@ -76,9 +77,9 @@ void Host::SetRenderHandle(void* handle)
return;

m_render_handle = handle;
if (g_renderer)
if (g_presenter)
{
g_renderer->ChangeSurface(handle);
g_presenter->ChangeSurface(handle);
g_controller_interface.ChangeWindow(handle);
}
}
Expand Down Expand Up @@ -149,11 +150,11 @@ bool Host::GetRenderFullFocus()
void Host::SetRenderFocus(bool focus)
{
m_render_focus = focus;
if (g_renderer && m_render_fullscreen && g_ActiveConfig.ExclusiveFullscreenEnabled())
if (g_gfx && m_render_fullscreen && g_ActiveConfig.ExclusiveFullscreenEnabled())
{
RunWithGPUThreadInactive([focus] {
if (!Config::Get(Config::MAIN_RENDER_TO_MAIN))
g_renderer->SetFullscreen(focus);
g_gfx->SetFullscreen(focus);
});
}
}
Expand Down Expand Up @@ -181,17 +182,16 @@ void Host::SetRenderFullscreen(bool fullscreen)
{
m_render_fullscreen = fullscreen;

if (g_renderer && g_renderer->IsFullscreen() != fullscreen &&
g_ActiveConfig.ExclusiveFullscreenEnabled())
if (g_gfx && g_gfx->IsFullscreen() != fullscreen && g_ActiveConfig.ExclusiveFullscreenEnabled())
{
RunWithGPUThreadInactive([fullscreen] { g_renderer->SetFullscreen(fullscreen); });
RunWithGPUThreadInactive([fullscreen] { g_gfx->SetFullscreen(fullscreen); });
}
}

void Host::ResizeSurface(int new_width, int new_height)
{
if (g_renderer)
g_renderer->ResizeSurface();
if (g_presenter)
g_presenter->ResizeSurface();
}

std::vector<std::string> Host_GetPreferredLocales()
Expand Down
1 change: 0 additions & 1 deletion Source/Core/DolphinQt/HotkeyScheduler.cpp
Expand Up @@ -43,7 +43,6 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h"

#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoConfig.h"

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/MainWindow.cpp
Expand Up @@ -1383,15 +1383,15 @@ void MainWindow::SetStateSlot(int slot)

void MainWindow::IncrementSelectedStateSlot()
{
int state_slot = m_state_slot + 1;
u32 state_slot = m_state_slot + 1;
if (state_slot > State::NUM_STATES)
state_slot = 1;
m_menu_bar->SetStateSlot(state_slot);
}

void MainWindow::DecrementSelectedStateSlot()
{
int state_slot = m_state_slot - 1;
u32 state_slot = m_state_slot - 1;
if (state_slot < 1)
state_slot = State::NUM_STATES;
m_menu_bar->SetStateSlot(state_slot);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/MainWindow.h
Expand Up @@ -217,7 +217,7 @@ class MainWindow final : public QMainWindow
bool m_exit_requested = false;
bool m_fullscreen_requested = false;
bool m_is_screensaver_inhibited = false;
int m_state_slot = 1;
u32 m_state_slot = 1;
std::unique_ptr<BootParameters> m_pending_boot;

ControllersWindow* m_controllers_window = nullptr;
Expand Down
1 change: 0 additions & 1 deletion Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
Expand Up @@ -61,7 +61,6 @@

#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/NetPlayGolfUI.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoConfig.h"

namespace
Expand Down
77 changes: 29 additions & 48 deletions Source/Core/DolphinQt/RenderWidget.cpp
Expand Up @@ -19,8 +19,6 @@
#include <QTimer>
#include <QWindow>

#include <imgui.h>

#include "Core/Config/MainSettings.h"
#include "Core/Core.h"
#include "Core/State.h"
Expand All @@ -32,7 +30,8 @@

#include "InputCommon/ControllerInterface/ControllerInterface.h"

#include "VideoCommon/RenderBase.h"
#include "VideoCommon/OnScreenUI.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/VideoConfig.h"

#ifdef _WIN32
Expand Down Expand Up @@ -62,7 +61,7 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)

connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this](Core::State state) {
if (state == Core::State::Running)
SetImGuiKeyMap();
SetPresenterKeyMap();
});

// We have to use Qt::DirectConnection here because we don't want those signals to get queued
Expand Down Expand Up @@ -338,7 +337,7 @@ void RenderWidget::SetWaitingForMessageBox(bool waiting_for_message_box)

bool RenderWidget::event(QEvent* event)
{
PassEventToImGui(event);
PassEventToPresenter(event);

switch (event->type())
{
Expand Down Expand Up @@ -470,7 +469,7 @@ bool RenderWidget::event(QEvent* event)
return QWidget::event(event);
}

void RenderWidget::PassEventToImGui(const QEvent* event)
void RenderWidget::PassEventToPresenter(const QEvent* event)
{
if (!Core::IsRunningAndStarted())
return;
Expand All @@ -487,38 +486,40 @@ void RenderWidget::PassEventToImGui(const QEvent* event)
const QKeyEvent* key_event = static_cast<const QKeyEvent*>(event);
const bool is_down = event->type() == QEvent::KeyPress;
const u32 key = static_cast<u32>(key_event->key() & 0x1FF);
auto lock = g_renderer->GetImGuiLock();
if (key < std::size(ImGui::GetIO().KeysDown))
ImGui::GetIO().KeysDown[key] = is_down;

const char* chars = nullptr;

if (is_down)
{
auto utf8 = key_event->text().toUtf8();
ImGui::GetIO().AddInputCharactersUTF8(utf8.constData());

if (utf8.size())
chars = utf8.constData();
}

// Pass the key onto Presenter (for the imgui UI)
g_presenter->SetKey(key, is_down, chars);
}
break;

case QEvent::MouseMove:
{
auto lock = g_renderer->GetImGuiLock();

// Qt multiplies all coordinates by the scaling factor in highdpi mode, giving us "scaled" mouse
// coordinates (as if the screen was standard dpi). We need to update the mouse position in
// native coordinates, as the UI (and game) is rendered at native resolution.
const float scale = devicePixelRatio();
ImGui::GetIO().MousePos.x = static_cast<const QMouseEvent*>(event)->pos().x() * scale;
ImGui::GetIO().MousePos.y = static_cast<const QMouseEvent*>(event)->pos().y() * scale;
float x = static_cast<const QMouseEvent*>(event)->pos().x() * scale;
float y = static_cast<const QMouseEvent*>(event)->pos().y() * scale;

g_presenter->SetMousePos(x, y);
}
break;

case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
{
auto lock = g_renderer->GetImGuiLock();
const u32 button_mask = static_cast<u32>(static_cast<const QMouseEvent*>(event)->buttons());
for (size_t i = 0; i < std::size(ImGui::GetIO().MouseDown); i++)
ImGui::GetIO().MouseDown[i] = (button_mask & (1u << i)) != 0;
g_presenter->SetMousePress(button_mask);
}
break;

Expand All @@ -527,36 +528,16 @@ void RenderWidget::PassEventToImGui(const QEvent* event)
}
}

void RenderWidget::SetImGuiKeyMap()
void RenderWidget::SetPresenterKeyMap()
{
static constexpr std::array<std::array<int, 2>, 21> key_map{{
{ImGuiKey_Tab, Qt::Key_Tab},
{ImGuiKey_LeftArrow, Qt::Key_Left},
{ImGuiKey_RightArrow, Qt::Key_Right},
{ImGuiKey_UpArrow, Qt::Key_Up},
{ImGuiKey_DownArrow, Qt::Key_Down},
{ImGuiKey_PageUp, Qt::Key_PageUp},
{ImGuiKey_PageDown, Qt::Key_PageDown},
{ImGuiKey_Home, Qt::Key_Home},
{ImGuiKey_End, Qt::Key_End},
{ImGuiKey_Insert, Qt::Key_Insert},
{ImGuiKey_Delete, Qt::Key_Delete},
{ImGuiKey_Backspace, Qt::Key_Backspace},
{ImGuiKey_Space, Qt::Key_Space},
{ImGuiKey_Enter, Qt::Key_Return},
{ImGuiKey_Escape, Qt::Key_Escape},
{ImGuiKey_A, Qt::Key_A},
{ImGuiKey_C, Qt::Key_C},
{ImGuiKey_V, Qt::Key_V},
{ImGuiKey_X, Qt::Key_X},
{ImGuiKey_Y, Qt::Key_Y},
{ImGuiKey_Z, Qt::Key_Z},
}};
auto lock = g_renderer->GetImGuiLock();

if (!ImGui::GetCurrentContext())
return;

for (auto [imgui_key, qt_key] : key_map)
ImGui::GetIO().KeyMap[imgui_key] = (qt_key & 0x1FF);
static constexpr DolphinKeyMap key_map = {
Qt::Key_Tab, Qt::Key_Left, Qt::Key_Right, Qt::Key_Up, Qt::Key_Down,
Qt::Key_PageUp, Qt::Key_PageDown, Qt::Key_Home, Qt::Key_End, Qt::Key_Insert,
Qt::Key_Delete, Qt::Key_Backspace, Qt::Key_Space, Qt::Key_Return, Qt::Key_Escape,
Qt::Key_Enter, // Keypad enter
Qt::Key_A, Qt::Key_C, Qt::Key_V, Qt::Key_X, Qt::Key_Y,
Qt::Key_Z,
};

g_presenter->SetKeyMap(key_map);
}
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/RenderWidget.h
Expand Up @@ -39,8 +39,8 @@ class RenderWidget final : public QWidget
void OnLockCursorChanged();
void OnKeepOnTopChanged(bool top);
void UpdateCursor();
void PassEventToImGui(const QEvent* event);
void SetImGuiKeyMap();
void PassEventToPresenter(const QEvent* event);
void SetPresenterKeyMap();
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;

Expand Down
1 change: 0 additions & 1 deletion Source/Core/DolphinQt/Settings.cpp
Expand Up @@ -46,7 +46,6 @@

#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/NetPlayGolfUI.h"
#include "VideoCommon/RenderBase.h"

Settings::Settings()
{
Expand Down
1 change: 0 additions & 1 deletion Source/Core/DolphinTool/ToolHeadlessPlatform.cpp
Expand Up @@ -15,7 +15,6 @@
#include "Core/Host.h"

// Begin stubs needed to satisfy Core dependencies
#include "VideoCommon/RenderBase.h"

std::vector<std::string> Host_GetPreferredLocales()
{
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/InputCommon/DynamicInputTextureManager.cpp
Expand Up @@ -13,7 +13,7 @@

#include "InputCommon/DynamicInputTextures/DITConfiguration.h"
#include "VideoCommon/HiresTextures.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/TextureCacheBase.h"

namespace InputCommon
{
Expand Down Expand Up @@ -48,7 +48,7 @@ void DynamicInputTextureManager::GenerateTextures(const IniFile& file,
any_dirty |= configuration.GenerateTextures(file, controller_names);
}

if (any_dirty && g_renderer && Core::GetState() != Core::State::Starting)
g_renderer->ForceReloadTextures();
if (any_dirty && g_texture_cache && Core::GetState() != Core::State::Starting)
g_texture_cache->ForceReloadTextures();
}
} // namespace InputCommon
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/CMakeLists.txt
Expand Up @@ -7,8 +7,8 @@ add_library(videod3d
D3DNativeVertexFormat.cpp
D3DPerfQuery.cpp
D3DPerfQuery.h
D3DRender.cpp
D3DRender.h
D3DGfx.cpp
D3DGfx.h
D3DState.cpp
D3DState.h
D3DSwapChain.cpp
Expand Down
@@ -1,7 +1,7 @@
// Copyright 2010 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoBackends/D3D/D3DRender.h"
#include "VideoBackends/D3D/D3DGfx.h"

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -30,48 +30,46 @@
#include "VideoCommon/BPFunctions.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/PostProcessing.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/RenderState.h"
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h"

namespace DX11
{
Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale)
: ::Renderer(swap_chain ? swap_chain->GetWidth() : 0, swap_chain ? swap_chain->GetHeight() : 0,
backbuffer_scale,
swap_chain ? swap_chain->GetFormat() : AbstractTextureFormat::Undefined),
m_swap_chain(std::move(swap_chain))
Gfx::Gfx(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale)
: m_backbuffer_scale(backbuffer_scale), m_swap_chain(std::move(swap_chain))
{
}

Renderer::~Renderer() = default;
Gfx::~Gfx() = default;

bool Renderer::IsHeadless() const
bool Gfx::IsHeadless() const
{
return !m_swap_chain;
}

std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config,
std::string_view name)
std::unique_ptr<AbstractTexture> Gfx::CreateTexture(const TextureConfig& config,
std::string_view name)
{
return DXTexture::Create(config, name);
}

std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTextureType type,
const TextureConfig& config)
std::unique_ptr<AbstractStagingTexture> Gfx::CreateStagingTexture(StagingTextureType type,
const TextureConfig& config)
{
return DXStagingTexture::Create(type, config);
}

std::unique_ptr<AbstractFramebuffer> Renderer::CreateFramebuffer(AbstractTexture* color_attachment,
AbstractTexture* depth_attachment)
std::unique_ptr<AbstractFramebuffer> Gfx::CreateFramebuffer(AbstractTexture* color_attachment,
AbstractTexture* depth_attachment)
{
return DXFramebuffer::Create(static_cast<DXTexture*>(color_attachment),
static_cast<DXTexture*>(depth_attachment));
}

std::unique_ptr<AbstractShader>
Renderer::CreateShaderFromSource(ShaderStage stage, std::string_view source, std::string_view name)
Gfx::CreateShaderFromSource(ShaderStage stage, std::string_view source, std::string_view name)
{
auto bytecode = DXShader::CompileShader(D3D::feature_level, stage, source);
if (!bytecode)
Expand All @@ -80,21 +78,20 @@ Renderer::CreateShaderFromSource(ShaderStage stage, std::string_view source, std
return DXShader::CreateFromBytecode(stage, std::move(*bytecode), name);
}

std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length,
std::string_view name)
std::unique_ptr<AbstractShader> Gfx::CreateShaderFromBinary(ShaderStage stage, const void* data,
size_t length, std::string_view name)
{
return DXShader::CreateFromBytecode(stage, DXShader::CreateByteCode(data, length), name);
}

std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config,
const void* cache_data,
size_t cache_data_length)
std::unique_ptr<AbstractPipeline> Gfx::CreatePipeline(const AbstractPipelineConfig& config,
const void* cache_data,
size_t cache_data_length)
{
return DXPipeline::Create(config);
}

void Renderer::SetPipeline(const AbstractPipeline* pipeline)
void Gfx::SetPipeline(const AbstractPipeline* pipeline)
{
const DXPipeline* dx_pipeline = static_cast<const DXPipeline*>(pipeline);
if (m_current_pipeline == dx_pipeline)
Expand Down Expand Up @@ -122,83 +119,83 @@ void Renderer::SetPipeline(const AbstractPipeline* pipeline)
}
}

void Renderer::SetScissorRect(const MathUtil::Rectangle<int>& rc)
void Gfx::SetScissorRect(const MathUtil::Rectangle<int>& rc)
{
// TODO: Move to stateman
const CD3D11_RECT rect(rc.left, rc.top, std::max(rc.right, rc.left + 1),
std::max(rc.bottom, rc.top + 1));
D3D::context->RSSetScissorRects(1, &rect);
}

void Renderer::SetViewport(float x, float y, float width, float height, float near_depth,
float far_depth)
void Gfx::SetViewport(float x, float y, float width, float height, float near_depth,
float far_depth)
{
// TODO: Move to stateman
const CD3D11_VIEWPORT vp(x, y, width, height, near_depth, far_depth);
D3D::context->RSSetViewports(1, &vp);
}

void Renderer::Draw(u32 base_vertex, u32 num_vertices)
void Gfx::Draw(u32 base_vertex, u32 num_vertices)
{
D3D::stateman->Apply();
D3D::context->Draw(num_vertices, base_vertex);
}

void Renderer::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex)
void Gfx::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex)
{
D3D::stateman->Apply();
D3D::context->DrawIndexed(num_indices, base_index, base_vertex);
}

void Renderer::DispatchComputeShader(const AbstractShader* shader, u32 groupsize_x, u32 groupsize_y,
u32 groupsize_z, u32 groups_x, u32 groups_y, u32 groups_z)
void Gfx::DispatchComputeShader(const AbstractShader* shader, u32 groupsize_x, u32 groupsize_y,
u32 groupsize_z, u32 groups_x, u32 groups_y, u32 groups_z)
{
D3D::stateman->SetComputeShader(static_cast<const DXShader*>(shader)->GetD3DComputeShader());
D3D::stateman->SyncComputeBindings();
D3D::context->Dispatch(groups_x, groups_y, groups_z);
}

void Renderer::BindBackbuffer(const ClearColor& clear_color)
void Gfx::BindBackbuffer(const ClearColor& clear_color)
{
CheckForSwapChainChanges();
SetAndClearFramebuffer(m_swap_chain->GetFramebuffer(), clear_color);
}

void Renderer::PresentBackbuffer()
void Gfx::PresentBackbuffer()
{
m_swap_chain->Present();
}

void Renderer::OnConfigChanged(u32 bits)
void Gfx::OnConfigChanged(u32 bits)
{
AbstractGfx::OnConfigChanged(bits);

// Quad-buffer changes require swap chain recreation.
if (bits & CONFIG_CHANGE_BIT_STEREO_MODE && m_swap_chain)
m_swap_chain->SetStereo(SwapChain::WantsStereo());
}

void Renderer::CheckForSwapChainChanges()
void Gfx::CheckForSwapChainChanges()
{
const bool surface_changed = m_surface_changed.TestAndClear();
const bool surface_changed = g_presenter->SurfaceChangedTestAndClear();
const bool surface_resized =
m_surface_resized.TestAndClear() || m_swap_chain->CheckForFullscreenChange();
g_presenter->SurfaceResizedTestAndClear() || m_swap_chain->CheckForFullscreenChange();
if (!surface_changed && !surface_resized)
return;

if (surface_changed)
{
m_swap_chain->ChangeSurface(m_new_surface_handle);
m_new_surface_handle = nullptr;
m_swap_chain->ChangeSurface(g_presenter->GetNewSurfaceHandle());
}
else
{
m_swap_chain->ResizeSwapChain();
}

m_backbuffer_width = m_swap_chain->GetWidth();
m_backbuffer_height = m_swap_chain->GetHeight();
g_presenter->SetBackbuffer(m_swap_chain->GetWidth(), m_swap_chain->GetHeight());
}

void Renderer::SetFramebuffer(AbstractFramebuffer* framebuffer)
void Gfx::SetFramebuffer(AbstractFramebuffer* framebuffer)
{
if (m_current_framebuffer == framebuffer)
return;
Expand All @@ -219,13 +216,13 @@ void Renderer::SetFramebuffer(AbstractFramebuffer* framebuffer)
m_current_framebuffer = fb;
}

void Renderer::SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer)
void Gfx::SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer)
{
SetFramebuffer(framebuffer);
}

void Renderer::SetAndClearFramebuffer(AbstractFramebuffer* framebuffer,
const ClearColor& color_value, float depth_value)
void Gfx::SetAndClearFramebuffer(AbstractFramebuffer* framebuffer, const ClearColor& color_value,
float depth_value)
{
SetFramebuffer(framebuffer);
D3D::stateman->Apply();
Expand All @@ -242,53 +239,55 @@ void Renderer::SetAndClearFramebuffer(AbstractFramebuffer* framebuffer,
}
}

void Renderer::SetTexture(u32 index, const AbstractTexture* texture)
void Gfx::SetTexture(u32 index, const AbstractTexture* texture)
{
D3D::stateman->SetTexture(index, texture ? static_cast<const DXTexture*>(texture)->GetD3DSRV() :
nullptr);
}

void Renderer::SetSamplerState(u32 index, const SamplerState& state)
void Gfx::SetSamplerState(u32 index, const SamplerState& state)
{
D3D::stateman->SetSampler(index, m_state_cache.Get(state));
}

void Renderer::SetComputeImageTexture(AbstractTexture* texture, bool read, bool write)
void Gfx::SetComputeImageTexture(AbstractTexture* texture, bool read, bool write)
{
D3D::stateman->SetComputeUAV(texture ? static_cast<DXTexture*>(texture)->GetD3DUAV() : nullptr);
}

void Renderer::UnbindTexture(const AbstractTexture* texture)
void Gfx::UnbindTexture(const AbstractTexture* texture)
{
if (D3D::stateman->UnsetTexture(static_cast<const DXTexture*>(texture)->GetD3DSRV()) != 0)
D3D::stateman->ApplyTextures();
}

std::unique_ptr<BoundingBox> Renderer::CreateBoundingBox() const
{
return std::make_unique<D3DBoundingBox>();
}

void Renderer::Flush()
void Gfx::Flush()
{
D3D::context->Flush();
}

void Renderer::WaitForGPUIdle()
void Gfx::WaitForGPUIdle()
{
// There is no glFinish() equivalent in D3D.
D3D::context->Flush();
}

void Renderer::SetFullscreen(bool enable_fullscreen)
void Gfx::SetFullscreen(bool enable_fullscreen)
{
if (m_swap_chain)
m_swap_chain->SetFullscreen(enable_fullscreen);
}

bool Renderer::IsFullscreen() const
bool Gfx::IsFullscreen() const
{
return m_swap_chain && m_swap_chain->GetFullscreen();
}

SurfaceInfo Gfx::GetSurfaceInfo() const
{
return {m_swap_chain ? static_cast<u32>(m_swap_chain->GetWidth()) : 0,
m_swap_chain ? static_cast<u32>(m_swap_chain->GetHeight()) : 0, m_backbuffer_scale,
m_swap_chain ? m_swap_chain->GetFormat() : AbstractTextureFormat::Undefined};
}

} // namespace DX11
Expand Up @@ -6,7 +6,7 @@
#include <d3d11.h>
#include <string_view>
#include "VideoBackends/D3D/D3DState.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/AbstractGfx.h"

class BoundingBox;

Expand All @@ -16,11 +16,11 @@ class SwapChain;
class DXTexture;
class DXFramebuffer;

class Renderer : public ::Renderer
class Gfx final : public ::AbstractGfx
{
public:
Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale);
~Renderer() override;
Gfx(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale);
~Gfx() override;

StateCache& GetStateCache() { return m_state_cache; }

Expand Down Expand Up @@ -69,14 +69,14 @@ class Renderer : public ::Renderer

void OnConfigChanged(u32 bits) override;

protected:
std::unique_ptr<BoundingBox> CreateBoundingBox() const override;
SurfaceInfo GetSurfaceInfo() const override;

private:
void CheckForSwapChainChanges();

StateCache m_state_cache;

float m_backbuffer_scale;
std::unique_ptr<SwapChain> m_swap_chain;
};
} // namespace DX11
36 changes: 9 additions & 27 deletions Source/Core/VideoBackends/D3D/D3DMain.cpp
Expand Up @@ -13,12 +13,13 @@

#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DBoundingBox.h"
#include "VideoBackends/D3D/D3DGfx.h"
#include "VideoBackends/D3D/D3DPerfQuery.h"
#include "VideoBackends/D3D/D3DRender.h"
#include "VideoBackends/D3D/D3DSwapChain.h"
#include "VideoBackends/D3D/D3DVertexManager.h"
#include "VideoBackends/D3DCommon/D3DCommon.h"

#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/ShaderCache.h"
#include "VideoCommon/TextureCacheBase.h"
Expand Down Expand Up @@ -143,7 +144,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
return false;

FillBackendInfo();
InitializeShared();
UpdateActiveConfig();

std::unique_ptr<SwapChain> swap_chain;
if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
Expand All @@ -154,36 +155,17 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
return false;
}

g_renderer = std::make_unique<Renderer>(std::move(swap_chain), wsi.render_surface_scale);
g_vertex_manager = std::make_unique<VertexManager>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_texture_cache = std::make_unique<TextureCacheBase>();
g_perf_query = std::make_unique<PerfQuery>();
if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
!g_renderer->Initialize() || !g_framebuffer_manager->Initialize() ||
!g_texture_cache->Initialize())
{
Shutdown();
return false;
}
auto gfx = std::make_unique<DX11::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
auto vertex_manager = std::make_unique<VertexManager>();
auto perf_query = std::make_unique<PerfQuery>();
auto bounding_box = std::make_unique<D3DBoundingBox>();

g_shader_cache->InitializeShaderCache();
return true;
return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
std::move(bounding_box));
}

void VideoBackend::Shutdown()
{
g_shader_cache->Shutdown();
g_renderer->Shutdown();

g_perf_query.reset();
g_texture_cache.reset();
g_framebuffer_manager.reset();
g_shader_cache.reset();
g_vertex_manager.reset();
g_renderer.reset();

ShutdownShared();
D3D::Destroy();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp
Expand Up @@ -7,7 +7,7 @@
#include "Common/EnumMap.h"

#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DRender.h"
#include "VideoBackends/D3D/D3DGfx.h"
#include "VideoBackends/D3D/D3DState.h"
#include "VideoBackends/D3D/D3DVertexManager.h"
#include "VideoBackends/D3D/DXShader.h"
Expand All @@ -18,7 +18,7 @@ namespace DX11
std::mutex s_input_layout_lock;

std::unique_ptr<NativeVertexFormat>
Renderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
Gfx::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{
return std::make_unique<D3DVertexFormat>(vtx_decl);
}
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoBackends/D3D/D3DPerfQuery.cpp
Expand Up @@ -6,7 +6,7 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "VideoBackends/D3D/D3DBase.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/VideoCommon.h"

namespace DX11
Expand Down Expand Up @@ -114,8 +114,8 @@ void PerfQuery::FlushOne()
// NOTE: Reported pixel metrics should be referenced to native resolution
// TODO: Dropping the lower 2 bits from this count should be closer to actual
// hardware behavior when drawing triangles.
const u64 native_res_result = result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT /
g_renderer->GetTargetHeight();
const u64 native_res_result = result * EFB_WIDTH / g_framebuffer_manager->GetEFBWidth() *
EFB_HEIGHT / g_framebuffer_manager->GetEFBHeight();
m_results[entry.query_group].fetch_add(static_cast<u32>(native_res_result),
std::memory_order_relaxed);

Expand Down Expand Up @@ -143,8 +143,8 @@ void PerfQuery::WeakFlush()
if (hr == S_OK)
{
// NOTE: Reported pixel metrics should be referenced to native resolution
const u64 native_res_result = result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT /
g_renderer->GetTargetHeight();
const u64 native_res_result = result * EFB_WIDTH / g_framebuffer_manager->GetEFBWidth() *
EFB_HEIGHT / g_framebuffer_manager->GetEFBHeight();
m_results[entry.query_group].store(static_cast<u32>(native_res_result),
std::memory_order_relaxed);

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D/D3DVertexManager.cpp
Expand Up @@ -13,7 +13,7 @@

#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DBoundingBox.h"
#include "VideoBackends/D3D/D3DRender.h"
#include "VideoBackends/D3D/D3DGfx.h"
#include "VideoBackends/D3D/D3DState.h"
#include "VideoBackends/D3DCommon/D3DCommon.h"

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/DXPipeline.cpp
Expand Up @@ -7,7 +7,7 @@
#include "Common/Logging/Log.h"

#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DRender.h"
#include "VideoBackends/D3D/D3DGfx.h"
#include "VideoBackends/D3D/D3DState.h"
#include "VideoBackends/D3D/D3DVertexManager.h"
#include "VideoBackends/D3D/DXShader.h"
Expand All @@ -32,7 +32,7 @@ DXPipeline::~DXPipeline() = default;

std::unique_ptr<DXPipeline> DXPipeline::Create(const AbstractPipelineConfig& config)
{
StateCache& state_cache = static_cast<Renderer*>(g_renderer.get())->GetStateCache();
StateCache& state_cache = static_cast<Gfx*>(g_gfx.get())->GetStateCache();
ID3D11RasterizerState* rasterizer_state = state_cache.Get(config.rasterization_state);
ID3D11DepthStencilState* depth_state = state_cache.Get(config.depth_state);
ID3D11BlendState* blend_state = state_cache.Get(config.blending_state);
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D12/CMakeLists.txt
Expand Up @@ -3,8 +3,8 @@ add_library(videod3d12
D3D12BoundingBox.h
D3D12PerfQuery.cpp
D3D12PerfQuery.h
D3D12Renderer.cpp
D3D12Renderer.h
D3D12Gfx.cpp
D3D12Gfx.h
D3D12StreamBuffer.cpp
D3D12StreamBuffer.h
D3D12SwapChain.cpp
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/VideoBackends/D3D12/D3D12BoundingBox.cpp
Expand Up @@ -6,7 +6,7 @@
#include "Common/Assert.h"
#include "Common/Logging/Log.h"

#include "VideoBackends/D3D12/D3D12Renderer.h"
#include "VideoBackends/D3D12/D3D12Gfx.h"
#include "VideoBackends/D3D12/DX12Context.h"

namespace DX12
Expand All @@ -22,7 +22,7 @@ bool D3D12BoundingBox::Initialize()
if (!CreateBuffers())
return false;

Renderer::GetInstance()->SetPixelShaderUAV(m_gpu_descriptor.cpu_handle);
Gfx::GetInstance()->SetPixelShaderUAV(m_gpu_descriptor.cpu_handle);
return true;
}

Expand All @@ -35,7 +35,7 @@ std::vector<BBoxType> D3D12BoundingBox::Read(u32 index, u32 length)
0, BUFFER_SIZE);
ResourceBarrier(g_dx_context->GetCommandList(), m_gpu_buffer.Get(),
D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
Renderer::GetInstance()->ExecuteCommandList(true);
Gfx::GetInstance()->ExecuteCommandList(true);

// Read back to cached values.
std::vector<BBoxType> values(length);
Expand All @@ -62,7 +62,7 @@ void D3D12BoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
if (!m_upload_buffer.ReserveMemory(copy_size, sizeof(BBoxType)))
{
WARN_LOG_FMT(VIDEO, "Executing command list while waiting for space in bbox stream buffer");
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);
if (!m_upload_buffer.ReserveMemory(copy_size, sizeof(BBoxType)))
{
PanicAlertFmt("Failed to allocate bbox stream buffer space");
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -6,9 +6,7 @@
#include <d3d12.h>
#include "VideoBackends/D3D12/DescriptorAllocator.h"
#include "VideoBackends/D3D12/DescriptorHeapManager.h"
#include "VideoCommon/RenderBase.h"

class BoundingBox;
#include "VideoCommon/AbstractGfx.h"

namespace DX12
{
Expand All @@ -18,19 +16,16 @@ class DXShader;
class DXPipeline;
class SwapChain;

class Renderer final : public ::Renderer
class Gfx final : public ::AbstractGfx
{
public:
Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale);
~Renderer() override;
Gfx(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale);
~Gfx() override;

static Renderer* GetInstance() { return static_cast<Renderer*>(g_renderer.get()); }
static Gfx* GetInstance() { return static_cast<Gfx*>(g_gfx.get()); }

bool IsHeadless() const override;

bool Initialize() override;
void Shutdown() override;

std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
std::string_view name) override;
std::unique_ptr<AbstractStagingTexture>
Expand All @@ -52,7 +47,7 @@ class Renderer final : public ::Renderer
void Flush() override;
void WaitForGPUIdle() override;

void ClearScreen(const MathUtil::Rectangle<int>& rc, bool color_enable, bool alpha_enable,
void ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool color_enable, bool alpha_enable,
bool z_enable, u32 color, u32 z) override;

void SetPipeline(const AbstractPipeline* pipeline) override;
Expand All @@ -74,6 +69,8 @@ class Renderer final : public ::Renderer
void BindBackbuffer(const ClearColor& clear_color = {}) override;
void PresentBackbuffer() override;

SurfaceInfo GetSurfaceInfo() const override;

// Completes the current render pass, executes the command buffer, and restores state ready for
// next render. Use when you want to kick the current buffer to make room for new data.
void ExecuteCommandList(bool wait_for_completion);
Expand All @@ -98,8 +95,6 @@ class Renderer final : public ::Renderer
protected:
void OnConfigChanged(u32 bits) override;

std::unique_ptr<BoundingBox> CreateBoundingBox() const override;

private:
static const u32 MAX_TEXTURES = 8;
static const u32 NUM_CONSTANT_BUFFERS = 3;
Expand Down Expand Up @@ -152,6 +147,8 @@ class Renderer final : public ::Renderer
bool UpdateComputeUAVDescriptorTable();
bool UpdateSamplerDescriptorTable();

float m_backbuffer_scale;

// Owned objects
std::unique_ptr<SwapChain> m_swap_chain;

Expand Down
11 changes: 6 additions & 5 deletions Source/Core/VideoBackends/D3D12/D3D12PerfQuery.cpp
Expand Up @@ -9,8 +9,9 @@
#include "Common/Logging/Log.h"

#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3D12/D3D12Renderer.h"
#include "VideoBackends/D3D12/D3D12Gfx.h"
#include "VideoBackends/D3D12/DX12Context.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/VideoCommon.h"

namespace DX12
Expand Down Expand Up @@ -64,7 +65,7 @@ void PerfQuery::EnableQuery(PerfQueryGroup group)
// This is because we can't leave a query open when submitting a command list, and the draw
// call itself may need to execute a command list if we run out of descriptors. Note that
// this assumes that the caller has bound all required state prior to enabling the query.
Renderer::GetInstance()->ApplyState();
Gfx::GetInstance()->ApplyState();

if (group == PQG_ZCOMP_ZCOMPLOC || group == PQG_ZCOMP)
{
Expand Down Expand Up @@ -244,8 +245,8 @@ void PerfQuery::AccumulateQueriesFromBuffer(u32 query_count)

// NOTE: Reported pixel metrics should be referenced to native resolution
const u64 native_res_result = static_cast<u64>(result) * EFB_WIDTH /
g_renderer->GetTargetWidth() * EFB_HEIGHT /
g_renderer->GetTargetHeight();
g_framebuffer_manager->GetEFBWidth() * EFB_HEIGHT /
g_framebuffer_manager->GetEFBHeight();
m_results[entry.query_group].fetch_add(static_cast<u32>(native_res_result),
std::memory_order_relaxed);
}
Expand All @@ -261,7 +262,7 @@ void PerfQuery::PartialFlush(bool resolve, bool blocking)
{
// Submit a command buffer if there are unresolved queries (to write them to the buffer).
if (resolve && m_unresolved_queries > 0)
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);

ReadbackQueries(blocking);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D12/D3D12PerfQuery.h
Expand Up @@ -17,7 +17,7 @@ class PerfQuery final : public PerfQueryBase

static PerfQuery* GetInstance() { return static_cast<PerfQuery*>(g_perf_query.get()); }

bool Initialize();
bool Initialize() override;
void ResolveQueries();

void EnableQuery(PerfQueryGroup group) override;
Expand Down
52 changes: 26 additions & 26 deletions Source/Core/VideoBackends/D3D12/D3D12VertexManager.cpp
Expand Up @@ -10,7 +10,7 @@

#include "Core/System.h"

#include "VideoBackends/D3D12/D3D12Renderer.h"
#include "VideoBackends/D3D12/D3D12Gfx.h"
#include "VideoBackends/D3D12/D3D12StreamBuffer.h"
#include "VideoBackends/D3D12/DX12Context.h"

Expand Down Expand Up @@ -92,7 +92,7 @@ void VertexManager::ResetBuffer(u32 vertex_stride)
{
// Flush any pending commands first, so that we can wait on the fences
WARN_LOG_FMT(VIDEO, "Executing command list while waiting for space in vertex/index buffer");
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);

// Attempt to allocate again, this may cause a fence wait
if (!has_vbuffer_allocation)
Expand Down Expand Up @@ -129,11 +129,11 @@ void VertexManager::CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_in
ADDSTAT(g_stats.this_frame.bytes_vertex_streamed, static_cast<int>(vertex_data_size));
ADDSTAT(g_stats.this_frame.bytes_index_streamed, static_cast<int>(index_data_size));

Renderer::GetInstance()->SetVertexBuffer(m_vertex_stream_buffer.GetGPUPointer(),
m_vertex_srv.cpu_handle, vertex_stride,
m_vertex_stream_buffer.GetSize());
Renderer::GetInstance()->SetIndexBuffer(m_index_stream_buffer.GetGPUPointer(),
m_index_stream_buffer.GetSize(), DXGI_FORMAT_R16_UINT);
Gfx::GetInstance()->SetVertexBuffer(m_vertex_stream_buffer.GetGPUPointer(),
m_vertex_srv.cpu_handle, vertex_stride,
m_vertex_stream_buffer.GetSize());
Gfx::GetInstance()->SetIndexBuffer(m_index_stream_buffer.GetGPUPointer(),
m_index_stream_buffer.GetSize(), DXGI_FORMAT_R16_UINT);
}

void VertexManager::UploadUniforms()
Expand All @@ -151,7 +151,7 @@ void VertexManager::UpdateVertexShaderConstants()
if (!vertex_shader_manager.dirty || !ReserveConstantStorage())
return;

Renderer::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer());
Gfx::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer());
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), &vertex_shader_manager.constants,
sizeof(VertexShaderConstants));
m_uniform_stream_buffer.CommitMemory(sizeof(VertexShaderConstants));
Expand All @@ -167,7 +167,7 @@ void VertexManager::UpdateGeometryShaderConstants()
if (!geometry_shader_manager.dirty || !ReserveConstantStorage())
return;

Renderer::GetInstance()->SetConstantBuffer(2, m_uniform_stream_buffer.GetCurrentGPUPointer());
Gfx::GetInstance()->SetConstantBuffer(2, m_uniform_stream_buffer.GetCurrentGPUPointer());
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), &geometry_shader_manager.constants,
sizeof(GeometryShaderConstants));
m_uniform_stream_buffer.CommitMemory(sizeof(GeometryShaderConstants));
Expand All @@ -183,7 +183,7 @@ void VertexManager::UpdatePixelShaderConstants()
if (!pixel_shader_manager.dirty || !ReserveConstantStorage())
return;

Renderer::GetInstance()->SetConstantBuffer(0, m_uniform_stream_buffer.GetCurrentGPUPointer());
Gfx::GetInstance()->SetConstantBuffer(0, m_uniform_stream_buffer.GetCurrentGPUPointer());
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), &pixel_shader_manager.constants,
sizeof(PixelShaderConstants));
m_uniform_stream_buffer.CommitMemory(sizeof(PixelShaderConstants));
Expand All @@ -204,7 +204,7 @@ bool VertexManager::ReserveConstantStorage()

// The only places that call constant updates are safe to have state restored.
WARN_LOG_FMT(VIDEO, "Executing command list while waiting for space in uniform buffer");
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);

// Since we are on a new command buffer, all constants have been invalidated, and we need
// to reupload them. We may as well do this now, since we're issuing a draw anyway.
Expand Down Expand Up @@ -234,12 +234,12 @@ void VertexManager::UploadAllConstants()
}

// Update bindings
Renderer::GetInstance()->SetConstantBuffer(0, m_uniform_stream_buffer.GetCurrentGPUPointer() +
pixel_constants_offset);
Renderer::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer() +
vertex_constants_offset);
Renderer::GetInstance()->SetConstantBuffer(2, m_uniform_stream_buffer.GetCurrentGPUPointer() +
geometry_constants_offset);
Gfx::GetInstance()->SetConstantBuffer(0, m_uniform_stream_buffer.GetCurrentGPUPointer() +
pixel_constants_offset);
Gfx::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer() +
vertex_constants_offset);
Gfx::GetInstance()->SetConstantBuffer(2, m_uniform_stream_buffer.GetCurrentGPUPointer() +
geometry_constants_offset);

auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
Expand Down Expand Up @@ -271,12 +271,12 @@ void VertexManager::UploadUtilityUniforms(const void* data, u32 data_size)
D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT))
{
WARN_LOG_FMT(VIDEO, "Executing command buffer while waiting for ext space in uniform buffer");
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);
}

Renderer::GetInstance()->SetConstantBuffer(0, m_uniform_stream_buffer.GetCurrentGPUPointer());
Renderer::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer());
Renderer::GetInstance()->SetConstantBuffer(2, m_uniform_stream_buffer.GetCurrentGPUPointer());
Gfx::GetInstance()->SetConstantBuffer(0, m_uniform_stream_buffer.GetCurrentGPUPointer());
Gfx::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer());
Gfx::GetInstance()->SetConstantBuffer(2, m_uniform_stream_buffer.GetCurrentGPUPointer());
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), data, data_size);
m_uniform_stream_buffer.CommitMemory(data_size);
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, data_size);
Expand All @@ -293,7 +293,7 @@ bool VertexManager::UploadTexelBuffer(const void* data, u32 data_size, TexelBuff
{
// Try submitting cmdbuffer.
WARN_LOG_FMT(VIDEO, "Submitting command buffer while waiting for space in texel buffer");
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);
if (!m_texel_stream_buffer.ReserveMemory(data_size, elem_size))
{
PanicAlertFmt("Failed to allocate {} bytes from texel buffer", data_size);
Expand All @@ -305,7 +305,7 @@ bool VertexManager::UploadTexelBuffer(const void* data, u32 data_size, TexelBuff
*out_offset = static_cast<u32>(m_texel_stream_buffer.GetCurrentOffset()) / elem_size;
m_texel_stream_buffer.CommitMemory(data_size);
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, data_size);
Renderer::GetInstance()->SetTextureDescriptor(0, m_texel_buffer_views[format].cpu_handle);
Gfx::GetInstance()->SetTextureDescriptor(0, m_texel_buffer_views[format].cpu_handle);
return true;
}

Expand All @@ -323,7 +323,7 @@ bool VertexManager::UploadTexelBuffer(const void* data, u32 data_size, TexelBuff
{
// Try submitting cmdbuffer.
WARN_LOG_FMT(VIDEO, "Submitting command buffer while waiting for space in texel buffer");
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);
if (!m_texel_stream_buffer.ReserveMemory(reserve_size, elem_size))
{
PanicAlertFmt("Failed to allocate {} bytes from texel buffer", reserve_size);
Expand All @@ -342,8 +342,8 @@ bool VertexManager::UploadTexelBuffer(const void* data, u32 data_size, TexelBuff

m_texel_stream_buffer.CommitMemory(palette_byte_offset + palette_size);
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, palette_byte_offset + palette_size);
Renderer::GetInstance()->SetTextureDescriptor(0, m_texel_buffer_views[format].cpu_handle);
Renderer::GetInstance()->SetTextureDescriptor(1, m_texel_buffer_views[palette_format].cpu_handle);
Gfx::GetInstance()->SetTextureDescriptor(0, m_texel_buffer_views[format].cpu_handle);
Gfx::GetInstance()->SetTextureDescriptor(1, m_texel_buffer_views[palette_format].cpu_handle);
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/D3D12/DX12Texture.cpp
Expand Up @@ -8,7 +8,7 @@
#include "Common/StringUtil.h"

#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3D12/D3D12Renderer.h"
#include "VideoBackends/D3D12/D3D12Gfx.h"
#include "VideoBackends/D3D12/D3D12StreamBuffer.h"
#include "VideoBackends/D3D12/DX12Context.h"
#include "VideoBackends/D3D12/DescriptorHeapManager.h"
Expand Down Expand Up @@ -254,7 +254,7 @@ void DXTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8*
{
WARN_LOG_FMT(VIDEO,
"Executing command list while waiting for space in texture upload buffer");
Renderer::GetInstance()->ExecuteCommandList(false);
Gfx::GetInstance()->ExecuteCommandList(false);
if (!g_dx_context->GetTextureUploadBuffer().ReserveMemory(
upload_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT))
{
Expand Down Expand Up @@ -632,7 +632,7 @@ void DXStagingTexture::Flush()
// the current list and wait for it to complete. This is the slowest path. Otherwise, if the
// command list with the copy has been submitted, we only need to wait for the fence.
if (m_completed_fence == g_dx_context->GetCurrentFenceValue())
Renderer::GetInstance()->ExecuteCommandList(true);
Gfx::GetInstance()->ExecuteCommandList(true);
else
g_dx_context->WaitForFence(m_completed_fence);
}
Expand Down
46 changes: 12 additions & 34 deletions Source/Core/VideoBackends/D3D12/VideoBackend.cpp
Expand Up @@ -11,8 +11,9 @@
#include "Core/ConfigManager.h"

#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3D12/D3D12BoundingBox.h"
#include "VideoBackends/D3D12/D3D12Gfx.h"
#include "VideoBackends/D3D12/D3D12PerfQuery.h"
#include "VideoBackends/D3D12/D3D12Renderer.h"
#include "VideoBackends/D3D12/D3D12SwapChain.h"
#include "VideoBackends/D3D12/D3D12VertexManager.h"
#include "VideoBackends/D3D12/DX12Context.h"
Expand Down Expand Up @@ -111,7 +112,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
}

FillBackendInfo();
InitializeShared();
UpdateActiveConfig();

if (!g_dx_context->CreateGlobalResources())
{
Expand All @@ -131,45 +132,22 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
}

// Create main wrapper instances.
g_renderer = std::make_unique<Renderer>(std::move(swap_chain), wsi.render_surface_scale);
g_vertex_manager = std::make_unique<VertexManager>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_texture_cache = std::make_unique<TextureCacheBase>();
g_perf_query = std::make_unique<PerfQuery>();

if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
!g_renderer->Initialize() || !g_framebuffer_manager->Initialize() ||
!g_texture_cache->Initialize() || !PerfQuery::GetInstance()->Initialize())
{
PanicAlertFmtT("Failed to initialize renderer classes");
Shutdown();
return false;
}
auto gfx = std::make_unique<DX12::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
auto vertex_manager = std::make_unique<DX12::VertexManager>();
auto perf_query = std::make_unique<DX12::PerfQuery>();
auto bounding_box = std::make_unique<DX12::D3D12BoundingBox>();

g_shader_cache->InitializeShaderCache();
return true;
return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
std::move(bounding_box));
}

void VideoBackend::Shutdown()
{
// Keep the debug runtime happy...
if (g_renderer)
Renderer::GetInstance()->ExecuteCommandList(true);

if (g_shader_cache)
g_shader_cache->Shutdown();
if (g_gfx)
Gfx::GetInstance()->ExecuteCommandList(true);

if (g_renderer)
g_renderer->Shutdown();

g_perf_query.reset();
g_texture_cache.reset();
g_framebuffer_manager.reset();
g_shader_cache.reset();
g_vertex_manager.reset();
g_renderer.reset();
DXContext::Destroy();
ShutdownShared();
DXContext::Destroy();
}
} // namespace DX12
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Metal/CMakeLists.txt
Expand Up @@ -2,15 +2,15 @@ add_library(videometal
MRCHelpers.h
MTLBoundingBox.mm
MTLBoundingBox.h
MTLGfx.mm
MTLGfx.h
MTLMain.mm
MTLObjectCache.h
MTLObjectCache.mm
MTLPerfQuery.mm
MTLPerfQuery.h
MTLPipeline.mm
MTLPipeline.h
MTLRenderer.mm
MTLRenderer.h
MTLShader.mm
MTLShader.h
MTLStateTracker.mm
Expand Down
Expand Up @@ -6,7 +6,7 @@
#include <Metal/Metal.h>
#include <QuartzCore/QuartzCore.h>

#include "VideoCommon/RenderBase.h"
#include "VideoCommon/AbstractGfx.h"

#include "VideoBackends/Metal/MRCHelpers.h"

Expand All @@ -15,16 +15,14 @@ namespace Metal
class Framebuffer;
class Texture;

class Renderer final : public ::Renderer
class Gfx final : public ::AbstractGfx
{
public:
Renderer(MRCOwned<CAMetalLayer*> layer, int width, int height, float layer_scale);
~Renderer() override;
Gfx(MRCOwned<CAMetalLayer*> layer);
~Gfx() override;

bool IsHeadless() const override;

bool Initialize() override;

std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
std::string_view name) override;
std::unique_ptr<AbstractStagingTexture>
Expand All @@ -49,7 +47,7 @@ class Renderer final : public ::Renderer
void WaitForGPUIdle() override;
void OnConfigChanged(u32 bits) override;

void ClearScreen(const MathUtil::Rectangle<int>& rc, bool color_enable, bool alpha_enable,
void ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool color_enable, bool alpha_enable,
bool z_enable, u32 color, u32 z) override;

void SetPipeline(const AbstractPipeline* pipeline) override;
Expand All @@ -71,8 +69,7 @@ class Renderer final : public ::Renderer
void BindBackbuffer(const ClearColor& clear_color = {}) override;
void PresentBackbuffer() override;

protected:
std::unique_ptr<::BoundingBox> CreateBoundingBox() const override;
SurfaceInfo GetSurfaceInfo() const override;

private:
MRCOwned<CAMetalLayer*> m_layer;
Expand Down
@@ -1,7 +1,7 @@
// Copyright 2022 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoBackends/Metal/MTLRenderer.h"
#include "VideoBackends/Metal/MTLGfx.h"

#include "VideoBackends/Metal/MTLBoundingBox.h"
#include "VideoBackends/Metal/MTLObjectCache.h"
Expand All @@ -13,36 +13,31 @@
#include "VideoBackends/Metal/MTLVertexManager.h"

#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/VideoBackendBase.h"

Metal::Renderer::Renderer(MRCOwned<CAMetalLayer*> layer, int width, int height, float layer_scale)
: ::Renderer(width, height, layer_scale, Util::ToAbstract([layer pixelFormat])),
m_layer(std::move(layer))
#include <fstream>

Metal::Gfx::Gfx(MRCOwned<CAMetalLayer*> layer) : m_layer(std::move(layer))
{
UpdateActiveConfig();
[m_layer setDisplaySyncEnabled:g_ActiveConfig.bVSyncActive];

SetupSurface();
g_state_tracker->FlushEncoders();
}

Metal::Renderer::~Renderer() = default;
Metal::Gfx::~Gfx() = default;

bool Metal::Renderer::IsHeadless() const
bool Metal::Gfx::IsHeadless() const
{
return m_layer == nullptr;
}

bool Metal::Renderer::Initialize()
{
if (!::Renderer::Initialize())
return false;
SetupSurface();
g_state_tracker->FlushEncoders();
return true;
}

// MARK: Texture Creation

std::unique_ptr<AbstractTexture> Metal::Renderer::CreateTexture(const TextureConfig& config,
std::string_view name)
std::unique_ptr<AbstractTexture> Metal::Gfx::CreateTexture(const TextureConfig& config,
std::string_view name)
{
@autoreleasepool
{
Expand Down Expand Up @@ -77,7 +72,7 @@
}

std::unique_ptr<AbstractStagingTexture>
Metal::Renderer::CreateStagingTexture(StagingTextureType type, const TextureConfig& config)
Metal::Gfx::CreateStagingTexture(StagingTextureType type, const TextureConfig& config)
{
@autoreleasepool
{
Expand All @@ -98,8 +93,7 @@
}

std::unique_ptr<AbstractFramebuffer>
Metal::Renderer::CreateFramebuffer(AbstractTexture* color_attachment,
AbstractTexture* depth_attachment)
Metal::Gfx::CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment)
{
AbstractTexture* const either_attachment = color_attachment ? color_attachment : depth_attachment;
return std::make_unique<Framebuffer>(
Expand All @@ -110,9 +104,9 @@

// MARK: Pipeline Creation

std::unique_ptr<AbstractShader> Metal::Renderer::CreateShaderFromSource(ShaderStage stage,
std::string_view source,
std::string_view name)
std::unique_ptr<AbstractShader> Metal::Gfx::CreateShaderFromSource(ShaderStage stage,
std::string_view source,
std::string_view name)
{
std::optional<std::string> msl = Util::TranslateShaderToMSL(stage, source);
if (!msl.has_value())
Expand All @@ -124,10 +118,9 @@
return CreateShaderFromMSL(stage, std::move(*msl), source, name);
}

std::unique_ptr<AbstractShader> Metal::Renderer::CreateShaderFromBinary(ShaderStage stage,
const void* data,
size_t length,
std::string_view name)
std::unique_ptr<AbstractShader> Metal::Gfx::CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length,
std::string_view name)
{
return CreateShaderFromMSL(stage, std::string(static_cast<const char*>(data), length), {}, name);
}
Expand Down Expand Up @@ -158,10 +151,9 @@

// clang-format on

std::unique_ptr<AbstractShader> Metal::Renderer::CreateShaderFromMSL(ShaderStage stage,
std::string msl,
std::string_view glsl,
std::string_view name)
std::unique_ptr<AbstractShader> Metal::Gfx::CreateShaderFromMSL(ShaderStage stage, std::string msl,
std::string_view glsl,
std::string_view name)
{
@autoreleasepool
{
Expand Down Expand Up @@ -243,30 +235,30 @@
}

std::unique_ptr<NativeVertexFormat>
Metal::Renderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
Metal::Gfx::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{
@autoreleasepool
{
return std::make_unique<VertexFormat>(vtx_decl);
}
}

std::unique_ptr<AbstractPipeline>
Metal::Renderer::CreatePipeline(const AbstractPipelineConfig& config, const void* cache_data,
size_t cache_data_length)
std::unique_ptr<AbstractPipeline> Metal::Gfx::CreatePipeline(const AbstractPipelineConfig& config,
const void* cache_data,
size_t cache_data_length)
{
return g_object_cache->CreatePipeline(config);
}

void Metal::Renderer::Flush()
void Metal::Gfx::Flush()
{
@autoreleasepool
{
g_state_tracker->FlushEncoders();
}
}

void Metal::Renderer::WaitForGPUIdle()
void Metal::Gfx::WaitForGPUIdle()
{
@autoreleasepool
{
Expand All @@ -275,8 +267,10 @@
}
}

void Metal::Renderer::OnConfigChanged(u32 bits)
void Metal::Gfx::OnConfigChanged(u32 bits)
{
AbstractGfx::OnConfigChanged(bits);

if (bits & CONFIG_CHANGE_BIT_VSYNC)
[m_layer setDisplaySyncEnabled:g_ActiveConfig.bVSyncActive];

Expand All @@ -287,14 +281,13 @@
}
}

void Metal::Renderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool color_enable,
bool alpha_enable, bool z_enable, u32 color, u32 z)
void Metal::Gfx::ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool color_enable,
bool alpha_enable, bool z_enable, u32 color, u32 z)
{
MathUtil::Rectangle<int> target_rc = Renderer::ConvertEFBRectangle(rc);
target_rc.ClampUL(0, 0, m_target_width, m_target_height);

u32 framebuffer_width = m_current_framebuffer->GetWidth();
u32 framebuffer_height = m_current_framebuffer->GetHeight();
// All Metal render passes are fullscreen, so we can only run a fast clear if the target is too
if (target_rc == MathUtil::Rectangle<int>(0, 0, m_target_width, m_target_height))
if (target_rc == MathUtil::Rectangle<int>(0, 0, framebuffer_width, framebuffer_height))
{
// Determine whether the EFB has an alpha channel. If it doesn't, we can clear the alpha
// channel to 0xFF. This hopefully allows us to use the fast path in most cases.
Expand Down Expand Up @@ -334,16 +327,16 @@
}

g_state_tracker->EnableEncoderLabel(false);
g_framebuffer_manager->ClearEFB(rc, color_enable, alpha_enable, z_enable, color, z);
AbstractGfx::ClearRegion(target_rc, color_enable, alpha_enable, z_enable, color, z);
g_state_tracker->EnableEncoderLabel(true);
}

void Metal::Renderer::SetPipeline(const AbstractPipeline* pipeline)
void Metal::Gfx::SetPipeline(const AbstractPipeline* pipeline)
{
g_state_tracker->SetPipeline(static_cast<const Pipeline*>(pipeline));
}

void Metal::Renderer::SetFramebuffer(AbstractFramebuffer* framebuffer)
void Metal::Gfx::SetFramebuffer(AbstractFramebuffer* framebuffer)
{
// Shouldn't be bound as a texture.
if (AbstractTexture* color = framebuffer->GetColorAttachment())
Expand All @@ -355,7 +348,7 @@
g_state_tracker->SetCurrentFramebuffer(static_cast<Framebuffer*>(framebuffer));
}

void Metal::Renderer::SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer)
void Metal::Gfx::SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer)
{
@autoreleasepool
{
Expand All @@ -364,8 +357,8 @@
}
}

void Metal::Renderer::SetAndClearFramebuffer(AbstractFramebuffer* framebuffer,
const ClearColor& color_value, float depth_value)
void Metal::Gfx::SetAndClearFramebuffer(AbstractFramebuffer* framebuffer,
const ClearColor& color_value, float depth_value)
{
@autoreleasepool
{
Expand All @@ -376,57 +369,57 @@
}
}

void Metal::Renderer::SetScissorRect(const MathUtil::Rectangle<int>& rc)
void Metal::Gfx::SetScissorRect(const MathUtil::Rectangle<int>& rc)
{
g_state_tracker->SetScissor(rc);
}

void Metal::Renderer::SetTexture(u32 index, const AbstractTexture* texture)
void Metal::Gfx::SetTexture(u32 index, const AbstractTexture* texture)
{
g_state_tracker->SetTexture(
index, texture ? static_cast<const Texture*>(texture)->GetMTLTexture() : nullptr);
}

void Metal::Renderer::SetSamplerState(u32 index, const SamplerState& state)
void Metal::Gfx::SetSamplerState(u32 index, const SamplerState& state)
{
g_state_tracker->SetSampler(index, state);
}

void Metal::Renderer::SetComputeImageTexture(AbstractTexture* texture, bool read, bool write)
void Metal::Gfx::SetComputeImageTexture(AbstractTexture* texture, bool read, bool write)
{
g_state_tracker->SetComputeTexture(static_cast<const Texture*>(texture));
}

void Metal::Renderer::UnbindTexture(const AbstractTexture* texture)
void Metal::Gfx::UnbindTexture(const AbstractTexture* texture)
{
g_state_tracker->UnbindTexture(static_cast<const Texture*>(texture)->GetMTLTexture());
}

void Metal::Renderer::SetViewport(float x, float y, float width, float height, float near_depth,
float far_depth)
void Metal::Gfx::SetViewport(float x, float y, float width, float height, float near_depth,
float far_depth)
{
g_state_tracker->SetViewport(x, y, width, height, near_depth, far_depth);
}

void Metal::Renderer::Draw(u32 base_vertex, u32 num_vertices)
void Metal::Gfx::Draw(u32 base_vertex, u32 num_vertices)
{
@autoreleasepool
{
g_state_tracker->Draw(base_vertex, num_vertices);
}
}

void Metal::Renderer::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex)
void Metal::Gfx::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex)
{
@autoreleasepool
{
g_state_tracker->DrawIndexed(base_index, num_indices, base_vertex);
}
}

void Metal::Renderer::DispatchComputeShader(const AbstractShader* shader, //
u32 groupsize_x, u32 groupsize_y, u32 groupsize_z,
u32 groups_x, u32 groups_y, u32 groups_z)
void Metal::Gfx::DispatchComputeShader(const AbstractShader* shader, //
u32 groupsize_x, u32 groupsize_y, u32 groupsize_z,
u32 groups_x, u32 groups_y, u32 groups_z)
{
@autoreleasepool
{
Expand All @@ -436,7 +429,7 @@
}
}

void Metal::Renderer::BindBackbuffer(const ClearColor& clear_color)
void Metal::Gfx::BindBackbuffer(const ClearColor& clear_color)
{
@autoreleasepool
{
Expand All @@ -448,7 +441,7 @@
}
}

void Metal::Renderer::PresentBackbuffer()
void Metal::Gfx::PresentBackbuffer()
{
@autoreleasepool
{
Expand All @@ -473,40 +466,45 @@
}
}

std::unique_ptr<::BoundingBox> Metal::Renderer::CreateBoundingBox() const
void Metal::Gfx::CheckForSurfaceChange()
{
return std::make_unique<BoundingBox>();
}

void Metal::Renderer::CheckForSurfaceChange()
{
if (!m_surface_changed.TestAndClear())
if (!g_presenter->SurfaceChangedTestAndClear())
return;
m_layer = MRCRetain(static_cast<CAMetalLayer*>(m_new_surface_handle));
m_new_surface_handle = nullptr;
m_layer = MRCRetain(static_cast<CAMetalLayer*>(g_presenter->GetNewSurfaceHandle()));
SetupSurface();
}

void Metal::Renderer::CheckForSurfaceResize()
void Metal::Gfx::CheckForSurfaceResize()
{
if (!m_surface_resized.TestAndClear())
if (!g_presenter->SurfaceResizedTestAndClear())
return;
SetupSurface();
}

void Metal::Renderer::SetupSurface()
void Metal::Gfx::SetupSurface()
{
CGSize size = [m_layer bounds].size;
// TODO: Update m_backbuffer_scale (need to make doing that not break everything)
const float backbuffer_scale = [m_layer contentsScale];
size.width *= backbuffer_scale;
size.height *= backbuffer_scale;
[m_layer setDrawableSize:size];
m_backbuffer_width = size.width;
m_backbuffer_height = size.height;
TextureConfig cfg(m_backbuffer_width, m_backbuffer_height, 1, 1, 1, m_backbuffer_format,
auto info = GetSurfaceInfo();

[m_layer setDrawableSize:{static_cast<double>(info.width), static_cast<double>(info.height)}];

TextureConfig cfg(info.width, info.height, 1, 1, 1, info.format,
AbstractTextureFlag_RenderTarget);
m_bb_texture = std::make_unique<Texture>(nullptr, cfg);
m_backbuffer = std::make_unique<Framebuffer>(m_bb_texture.get(), nullptr, //
m_backbuffer_width, m_backbuffer_height, 1, 1);
info.width, info.height, 1, 1);

if (g_presenter)
g_presenter->SetBackbuffer(info);
}

SurfaceInfo Metal::Gfx::GetSurfaceInfo() const
{
if (!m_layer) // Headless
return {};

CGSize size = [m_layer bounds].size;
const float scale = [m_layer contentsScale];

return {static_cast<u32>(size.width * scale), static_cast<u32>(size.height * scale), scale,
Util::ToAbstract([m_layer pixelFormat])};
}
45 changes: 9 additions & 36 deletions Source/Core/VideoBackends/Metal/MTLMain.mm
Expand Up @@ -16,13 +16,15 @@
#include "Common/Common.h"
#include "Common/MsgHandler.h"

#include "VideoBackends/Metal/MTLBoundingBox.h"
#include "VideoBackends/Metal/MTLGfx.h"
#include "VideoBackends/Metal/MTLObjectCache.h"
#include "VideoBackends/Metal/MTLPerfQuery.h"
#include "VideoBackends/Metal/MTLRenderer.h"
#include "VideoBackends/Metal/MTLStateTracker.h"
#include "VideoBackends/Metal/MTLUtil.h"
#include "VideoBackends/Metal/MTLVertexManager.h"

#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
Expand Down Expand Up @@ -93,57 +95,28 @@ static bool WindowSystemTypeSupportsMetal(WindowSystemType type)
MRCOwned<id<MTLDevice>> adapter = std::move(devs[selected_adapter_index]);
Util::PopulateBackendInfoFeatures(&g_Config, adapter);

// With the backend information populated, we can now initialize videocommon.
InitializeShared();
UpdateActiveConfig();

MRCOwned<CAMetalLayer*> layer = MRCRetain(static_cast<CAMetalLayer*>(wsi.render_surface));
[layer setDevice:adapter];
if (Util::ToAbstract([layer pixelFormat]) == AbstractTextureFormat::Undefined)
[layer setPixelFormat:MTLPixelFormatBGRA8Unorm];
CGSize size = [layer bounds].size;
float scale = [layer contentsScale];
if (!layer) // headless
scale = 1.0;

ObjectCache::Initialize(std::move(adapter));
g_state_tracker = std::make_unique<StateTracker>();
g_renderer = std::make_unique<Renderer>(std::move(layer), size.width * scale,
size.height * scale, scale);
g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = std::make_unique<PerfQuery>();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_texture_cache = std::make_unique<TextureCacheBase>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();

if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
!g_renderer->Initialize() || !g_framebuffer_manager->Initialize() ||
!g_texture_cache->Initialize())
{
PanicAlertFmt("Failed to initialize renderer classes");
Shutdown();
return false;
}

g_shader_cache->InitializeShaderCache();

return true;
return InitializeShared(
std::make_unique<Metal::Gfx>(std::move(layer)), std::make_unique<Metal::VertexManager>(),
std::make_unique<Metal::PerfQuery>(), std::make_unique<Metal::BoundingBox>());
}
}

void Metal::VideoBackend::Shutdown()
{
g_shader_cache->Shutdown();
g_renderer->Shutdown();

g_shader_cache.reset();
g_texture_cache.reset();
g_framebuffer_manager.reset();
g_perf_query.reset();
g_vertex_manager.reset();
g_renderer.reset();
ShutdownShared();

g_state_tracker.reset();
ObjectCache::Shutdown();
ShutdownShared();
}

void Metal::VideoBackend::InitBackendInfo()
Expand Down
1 change: 1 addition & 0 deletions Source/Core/VideoBackends/Metal/MTLObjectCache.h
Expand Up @@ -8,6 +8,7 @@

#include "VideoBackends/Metal/MRCHelpers.h"

#include "VideoCommon/BPMemory.h"
#include "VideoCommon/RenderState.h"

struct AbstractPipelineConfig;
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/VideoBackends/Metal/MTLPerfQuery.mm
Expand Up @@ -77,8 +77,9 @@
{
for (size_t i = 0; i < count; ++i)
{
u64 native_res_result = data[i] * (EFB_WIDTH * EFB_HEIGHT) /
(g_renderer->GetTargetWidth() * g_renderer->GetTargetHeight());
u64 native_res_result =
data[i] * (EFB_WIDTH * EFB_HEIGHT) /
(g_framebuffer_manager->GetEFBWidth() * g_framebuffer_manager->GetEFBHeight());

native_res_result /= g_ActiveConfig.iMultisamples;

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Metal/MTLStateTracker.h
Expand Up @@ -17,8 +17,8 @@
#include "VideoBackends/Metal/MTLTexture.h"
#include "VideoBackends/Metal/MTLUtil.h"

#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/PerfQueryBase.h"
#include "VideoCommon/RenderBase.h"

namespace Metal
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Metal/MTLTexture.mm
Expand Up @@ -6,7 +6,7 @@
#include "Common/Align.h"
#include "Common/Assert.h"

#include "VideoBackends/Metal/MTLRenderer.h"
#include "VideoBackends/Metal/MTLGfx.h"
#include "VideoBackends/Metal/MTLStateTracker.h"

Metal::Texture::Texture(MRCOwned<id<MTLTexture>> tex, const TextureConfig& config)
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Null/CMakeLists.txt
@@ -1,8 +1,8 @@
add_library(videonull
NullBackend.cpp
NullBoundingBox.h
NullRender.cpp
NullRender.h
NullGfx.cpp
NullGfx.h
NullTexture.cpp
NullTexture.h
NullVertexManager.cpp
Expand Down
36 changes: 6 additions & 30 deletions Source/Core/VideoBackends/Null/NullBackend.cpp
Expand Up @@ -11,12 +11,14 @@
#include "Common/Common.h"
#include "Common/MsgHandler.h"

#include "VideoBackends/Null/NullRender.h"
#include "VideoBackends/Null/NullBoundingBox.h"
#include "VideoBackends/Null/NullGfx.h"
#include "VideoBackends/Null/NullVertexManager.h"
#include "VideoBackends/Null/PerfQuery.h"
#include "VideoBackends/Null/TextureCache.h"

#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
Expand Down Expand Up @@ -69,39 +71,13 @@ void VideoBackend::InitBackendInfo()

bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
{
InitializeShared();

g_renderer = std::make_unique<Renderer>();
g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = std::make_unique<PerfQuery>();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_texture_cache = std::make_unique<TextureCache>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();

if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
!g_renderer->Initialize() || !g_framebuffer_manager->Initialize() ||
!g_texture_cache->Initialize())
{
PanicAlertFmt("Failed to initialize renderer classes");
Shutdown();
return false;
}

g_shader_cache->InitializeShaderCache();
return true;
return InitializeShared(std::make_unique<NullGfx>(), std::make_unique<VertexManager>(),
std::make_unique<PerfQuery>(), std::make_unique<NullBoundingBox>(),
std::make_unique<NullRenderer>(), std::make_unique<TextureCache>());
}

void VideoBackend::Shutdown()
{
g_shader_cache->Shutdown();
g_renderer->Shutdown();

g_texture_cache.reset();
g_perf_query.reset();
g_vertex_manager.reset();
g_framebuffer_manager.reset();
g_renderer.reset();

ShutdownShared();
}

Expand Down
95 changes: 95 additions & 0 deletions Source/Core/VideoBackends/Null/NullGfx.cpp
@@ -0,0 +1,95 @@
// Copyright 2015 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoBackends/Null/NullGfx.h"

#include "VideoBackends/Null/NullBoundingBox.h"
#include "VideoBackends/Null/NullTexture.h"

#include "VideoCommon/AbstractPipeline.h"
#include "VideoCommon/AbstractShader.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/VideoConfig.h"

namespace Null
{
// Init functions
NullGfx::NullGfx()
{
UpdateActiveConfig();
}

NullGfx::~NullGfx()
{
UpdateActiveConfig();
}

bool NullGfx::IsHeadless() const
{
return true;
}

bool NullGfx::SupportsUtilityDrawing() const
{
return false;
}

std::unique_ptr<AbstractTexture> NullGfx::CreateTexture(const TextureConfig& config,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<NullTexture>(config);
}

std::unique_ptr<AbstractStagingTexture> NullGfx::CreateStagingTexture(StagingTextureType type,
const TextureConfig& config)
{
return std::make_unique<NullStagingTexture>(type, config);
}

class NullShader final : public AbstractShader
{
public:
explicit NullShader(ShaderStage stage) : AbstractShader(stage) {}
};

std::unique_ptr<AbstractShader>
NullGfx::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<NullShader>(stage);
}

std::unique_ptr<AbstractShader>
NullGfx::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<NullShader>(stage);
}

class NullPipeline final : public AbstractPipeline
{
};

std::unique_ptr<AbstractPipeline> NullGfx::CreatePipeline(const AbstractPipelineConfig& config,
const void* cache_data,
size_t cache_data_length)
{
return std::make_unique<NullPipeline>();
}

std::unique_ptr<AbstractFramebuffer> NullGfx::CreateFramebuffer(AbstractTexture* color_attachment,
AbstractTexture* depth_attachment)
{
return NullFramebuffer::Create(static_cast<NullTexture*>(color_attachment),
static_cast<NullTexture*>(depth_attachment));
}

std::unique_ptr<NativeVertexFormat>
NullGfx::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{
return std::make_unique<NativeVertexFormat>(vtx_decl);
}

NullRenderer::~NullRenderer() = default;

} // namespace Null
Expand Up @@ -3,19 +3,19 @@

#pragma once

#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/RenderBase.h"

class BoundingBox;

namespace Null
{
class Renderer final : public ::Renderer
class NullGfx final : public AbstractGfx
{
public:
Renderer();
~Renderer() override;
NullGfx();
~NullGfx() override;

bool IsHeadless() const override;
virtual bool SupportsUtilityDrawing() const override;

std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
std::string_view name) override;
Expand All @@ -34,18 +34,18 @@ class Renderer final : public ::Renderer
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
const void* cache_data = nullptr,
size_t cache_data_length = 0) override;
};

class NullRenderer final : public Renderer
{
public:
NullRenderer() {}
~NullRenderer() override;

u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}

void ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
bool zEnable, u32 color, u32 z) override
{
}

void ReinterpretPixelData(EFBReinterpretType convtype) override {}

protected:
std::unique_ptr<BoundingBox> CreateBoundingBox() const override;
};

} // namespace Null
92 changes: 0 additions & 92 deletions Source/Core/VideoBackends/Null/NullRender.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Null/TextureCache.h
Expand Up @@ -18,7 +18,7 @@ class TextureCache final : public TextureCacheBase
{
}

void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy,
void CopyEFBToCacheEntry(RcTcacheEntry& entry, bool is_depth_copy,
const MathUtil::Rectangle<int>& src_rect, bool scale_by_half,
bool linear_filter, EFBCopyFormat dst_format, bool is_intensity,
float gamma, bool clamp_top, bool clamp_bottom,
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/VideoBackends/OGL/CMakeLists.txt
Expand Up @@ -2,14 +2,16 @@ add_library(videoogl
GPUTimer.h
OGLBoundingBox.cpp
OGLBoundingBox.h
OGLConfig.cpp
OGLConfig.h
OGLGfx.cpp
OGLGfx.h
OGLMain.cpp
OGLNativeVertexFormat.cpp
OGLPerfQuery.cpp
OGLPerfQuery.h
OGLPipeline.cpp
OGLPipeline.h
OGLRender.cpp
OGLRender.h
OGLShader.cpp
OGLShader.h
OGLStreamBuffer.cpp
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp
Expand Up @@ -3,7 +3,7 @@

#include "VideoBackends/OGL/OGLBoundingBox.h"

#include "VideoBackends/OGL/OGLRender.h"
#include "VideoBackends/OGL/OGLGfx.h"
#include "VideoCommon/DriverDetails.h"

namespace OGL
Expand Down Expand Up @@ -35,7 +35,7 @@ std::vector<BBoxType> OGLBoundingBox::Read(u32 index, u32 length)
// on nVidia drivers. This is more noticeable at higher internal resolutions.
// Using glGetBufferSubData instead does not seem to exhibit this slowdown.
if (!DriverDetails::HasBug(DriverDetails::BUG_SLOW_GETBUFFERSUBDATA) &&
!static_cast<Renderer*>(g_renderer.get())->IsGLES())
!static_cast<OGLGfx*>(g_gfx.get())->IsGLES())
{
// We also need to ensure the the CPU does not receive stale values which have been updated by
// the GPU. Apparently the buffer here is not coherent on NVIDIA drivers. Not sure if this is a
Expand Down