summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends
diff options
context:
space:
mode:
authorStenzek <stenzek@users.noreply.github.com>2018-10-24 14:51:21 +1100
committerGitHub <noreply@github.com>2018-10-24 14:51:21 +1100
commitc4d1e4adffcd380cc87b841069ce2fe8b62d7b60 (patch)
treec61a0a07c14ccc3c1f7247bdcc82927a82c145bb /Source/Core/VideoBackends
parent9c9d598ec006527bc47aea306e5171d03c12c5f5 (diff)
parent2c6d96433c322b50470705d43005fd6308506d49 (diff)
Merge pull request #7450 from stenzek/glcontext
GLInterface refactoring/cleanup and runtime platform selection
Diffstat (limited to 'Source/Core/VideoBackends')
-rw-r--r--Source/Core/VideoBackends/D3D/D3DBase.cpp11
-rw-r--r--Source/Core/VideoBackends/D3D/Render.cpp14
-rw-r--r--Source/Core/VideoBackends/D3D/Render.h3
-rw-r--r--Source/Core/VideoBackends/D3D/VideoBackend.h4
-rw-r--r--Source/Core/VideoBackends/D3D/main.cpp9
-rw-r--r--Source/Core/VideoBackends/Null/NullBackend.cpp4
-rw-r--r--Source/Core/VideoBackends/Null/Render.cpp5
-rw-r--r--Source/Core/VideoBackends/Null/Render.h2
-rw-r--r--Source/Core/VideoBackends/Null/VideoBackend.h4
-rw-r--r--Source/Core/VideoBackends/OGL/FramebufferManager.cpp3
-rw-r--r--Source/Core/VideoBackends/OGL/OGLTexture.cpp1
-rw-r--r--Source/Core/VideoBackends/OGL/PerfQuery.cpp18
-rw-r--r--Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp11
-rw-r--r--Source/Core/VideoBackends/OGL/Render.cpp55
-rw-r--r--Source/Core/VideoBackends/OGL/Render.h14
-rw-r--r--Source/Core/VideoBackends/OGL/SamplerCache.cpp6
-rw-r--r--Source/Core/VideoBackends/OGL/TextureCache.cpp1
-rw-r--r--Source/Core/VideoBackends/OGL/VideoBackend.h8
-rw-r--r--Source/Core/VideoBackends/OGL/main.cpp29
-rw-r--r--Source/Core/VideoBackends/Software/SWOGLWindow.cpp60
-rw-r--r--Source/Core/VideoBackends/Software/SWOGLWindow.h25
-rw-r--r--Source/Core/VideoBackends/Software/SWRenderer.cpp15
-rw-r--r--Source/Core/VideoBackends/Software/SWRenderer.h11
-rw-r--r--Source/Core/VideoBackends/Software/SWmain.cpp16
-rw-r--r--Source/Core/VideoBackends/Software/VideoBackend.h4
-rw-r--r--Source/Core/VideoBackends/Vulkan/Renderer.cpp48
-rw-r--r--Source/Core/VideoBackends/Vulkan/Renderer.h2
-rw-r--r--Source/Core/VideoBackends/Vulkan/SwapChain.cpp26
-rw-r--r--Source/Core/VideoBackends/Vulkan/SwapChain.h9
-rw-r--r--Source/Core/VideoBackends/Vulkan/VideoBackend.h4
-rw-r--r--Source/Core/VideoBackends/Vulkan/main.cpp11
31 files changed, 222 insertions, 211 deletions
diff --git a/Source/Core/VideoBackends/D3D/D3DBase.cpp b/Source/Core/VideoBackends/D3D/D3DBase.cpp
index 6c4478c492..333fd969f5 100644
--- a/Source/Core/VideoBackends/D3D/D3DBase.cpp
+++ b/Source/Core/VideoBackends/D3D/D3DBase.cpp
@@ -429,10 +429,13 @@ HRESULT Create(HWND wnd)
// prevent DXGI from responding to Alt+Enter, unfortunately DXGI_MWA_NO_ALT_ENTER
// does not work so we disable all monitoring of window messages. However this
// may make it more difficult for DXGI to handle display mode changes.
- hr = s_dxgi_factory->MakeWindowAssociation(wnd, DXGI_MWA_NO_WINDOW_CHANGES);
- if (FAILED(hr))
- MessageBox(wnd, _T("Failed to associate the window"), _T("Dolphin Direct3D 11 backend"),
- MB_OK | MB_ICONERROR);
+ if (wnd)
+ {
+ hr = s_dxgi_factory->MakeWindowAssociation(wnd, DXGI_MWA_NO_WINDOW_CHANGES);
+ if (FAILED(hr))
+ MessageBox(wnd, _T("Failed to associate the window"), _T("Dolphin Direct3D 11 backend"),
+ MB_OK | MB_ICONERROR);
+ }
SetDebugObjectName(context, "device context");
diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp
index b179597204..bfaa5763ba 100644
--- a/Source/Core/VideoBackends/D3D/Render.cpp
+++ b/Source/Core/VideoBackends/D3D/Render.cpp
@@ -225,6 +225,11 @@ void Renderer::Create3DVisionTexture(int width, int height)
DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, &sys_data);
}
+bool Renderer::IsHeadless() const
+{
+ return D3D::swapchain == nullptr;
+}
+
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<DXTexture>(config);
@@ -698,12 +703,12 @@ void Renderer::CheckForSurfaceChange()
if (!m_surface_changed.TestAndClear())
return;
- m_surface_handle = m_new_surface_handle;
- m_new_surface_handle = nullptr;
-
SAFE_RELEASE(m_screenshot_texture);
SAFE_RELEASE(m_3d_vision_texture);
+
D3D::Reset(reinterpret_cast<HWND>(m_new_surface_handle));
+ m_new_surface_handle = nullptr;
+
UpdateBackbufferSize();
}
@@ -714,9 +719,6 @@ void Renderer::CheckForSurfaceResize()
if (!m_surface_resized.TestAndClear() && !exclusive_fullscreen_changed)
return;
- m_backbuffer_width = m_new_backbuffer_width;
- m_backbuffer_height = m_new_backbuffer_height;
-
SAFE_RELEASE(m_screenshot_texture);
SAFE_RELEASE(m_3d_vision_texture);
m_last_fullscreen_state = fullscreen_state;
diff --git a/Source/Core/VideoBackends/D3D/Render.h b/Source/Core/VideoBackends/D3D/Render.h
index 0927f6c934..24b02af672 100644
--- a/Source/Core/VideoBackends/D3D/Render.h
+++ b/Source/Core/VideoBackends/D3D/Render.h
@@ -22,6 +22,9 @@ public:
~Renderer() override;
StateCache& GetStateCache() { return m_state_cache; }
+
+ bool IsHeadless() const override;
+
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
diff --git a/Source/Core/VideoBackends/D3D/VideoBackend.h b/Source/Core/VideoBackends/D3D/VideoBackend.h
index 59bd8d9b73..e288dddb9a 100644
--- a/Source/Core/VideoBackends/D3D/VideoBackend.h
+++ b/Source/Core/VideoBackends/D3D/VideoBackend.h
@@ -11,7 +11,7 @@ namespace DX11
{
class VideoBackend : public VideoBackendBase
{
- bool Initialize(void*) override;
+ bool Initialize(const WindowSystemInfo& wsi) override;
void Shutdown() override;
std::string GetName() const override;
@@ -19,4 +19,4 @@ class VideoBackend : public VideoBackendBase
void InitBackendInfo() override;
};
-}
+} // namespace DX11
diff --git a/Source/Core/VideoBackends/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp
index 69b6f47804..7df5358b16 100644
--- a/Source/Core/VideoBackends/D3D/main.cpp
+++ b/Source/Core/VideoBackends/D3D/main.cpp
@@ -127,14 +127,11 @@ void VideoBackend::InitBackendInfo()
DX11::D3D::UnloadD3D();
}
-bool VideoBackend::Initialize(void* window_handle)
+bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
{
- if (window_handle == nullptr)
- return false;
-
InitializeShared();
- if (FAILED(D3D::Create(reinterpret_cast<HWND>(window_handle))))
+ if (FAILED(D3D::Create(reinterpret_cast<HWND>(wsi.render_surface))))
{
PanicAlert("Failed to create D3D device.");
return false;
@@ -188,4 +185,4 @@ void VideoBackend::Shutdown()
D3D::Close();
}
-}
+} // namespace DX11
diff --git a/Source/Core/VideoBackends/Null/NullBackend.cpp b/Source/Core/VideoBackends/Null/NullBackend.cpp
index f3743773c5..147d5916ff 100644
--- a/Source/Core/VideoBackends/Null/NullBackend.cpp
+++ b/Source/Core/VideoBackends/Null/NullBackend.cpp
@@ -54,7 +54,7 @@ void VideoBackend::InitBackendInfo()
g_Config.backend_info.AAModes = {1};
}
-bool VideoBackend::Initialize(void* window_handle)
+bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
{
InitializeShared();
@@ -80,4 +80,4 @@ void VideoBackend::Shutdown()
ShutdownShared();
}
-}
+} // namespace Null
diff --git a/Source/Core/VideoBackends/Null/Render.cpp b/Source/Core/VideoBackends/Null/Render.cpp
index c9c0e62325..c80506c15b 100644
--- a/Source/Core/VideoBackends/Null/Render.cpp
+++ b/Source/Core/VideoBackends/Null/Render.cpp
@@ -24,6 +24,11 @@ Renderer::~Renderer()
UpdateActiveConfig();
}
+bool Renderer::IsHeadless() const
+{
+ return true;
+}
+
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<NullTexture>(config);
diff --git a/Source/Core/VideoBackends/Null/Render.h b/Source/Core/VideoBackends/Null/Render.h
index c1bf9c122e..10f15f0304 100644
--- a/Source/Core/VideoBackends/Null/Render.h
+++ b/Source/Core/VideoBackends/Null/Render.h
@@ -14,6 +14,8 @@ public:
Renderer();
~Renderer() override;
+ bool IsHeadless() const override;
+
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
diff --git a/Source/Core/VideoBackends/Null/VideoBackend.h b/Source/Core/VideoBackends/Null/VideoBackend.h
index 2f5f0dc057..3076f7aed0 100644
--- a/Source/Core/VideoBackends/Null/VideoBackend.h
+++ b/Source/Core/VideoBackends/Null/VideoBackend.h
@@ -11,7 +11,7 @@ namespace Null
{
class VideoBackend : public VideoBackendBase
{
- bool Initialize(void* window_handle) override;
+ bool Initialize(const WindowSystemInfo& wsi) override;
void Shutdown() override;
std::string GetName() const override { return "Null"; }
@@ -22,4 +22,4 @@ class VideoBackend : public VideoBackendBase
}
void InitBackendInfo() override;
};
-}
+} // namespace Null
diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp
index a6cccdaaa2..12de898ff5 100644
--- a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp
+++ b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp
@@ -9,7 +9,6 @@
#include "Common/Common.h"
#include "Common/CommonTypes.h"
-#include "Common/GL/GLInterfaceBase.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
@@ -414,7 +413,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
glBindBuffer(GL_ARRAY_BUFFER,
static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBufferHandle());
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
+ if (!static_cast<Renderer*>(g_renderer.get())->IsGLES())
glEnable(GL_PROGRAM_POINT_SIZE);
}
diff --git a/Source/Core/VideoBackends/OGL/OGLTexture.cpp b/Source/Core/VideoBackends/OGL/OGLTexture.cpp
index 1efb650eeb..fbe7f576c7 100644
--- a/Source/Core/VideoBackends/OGL/OGLTexture.cpp
+++ b/Source/Core/VideoBackends/OGL/OGLTexture.cpp
@@ -4,7 +4,6 @@
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
-#include "Common/GL/GLInterfaceBase.h"
#include "Common/MsgHandler.h"
#include "VideoBackends/OGL/FramebufferManager.h"
diff --git a/Source/Core/VideoBackends/OGL/PerfQuery.cpp b/Source/Core/VideoBackends/OGL/PerfQuery.cpp
index b3b5df2265..77471cee19 100644
--- a/Source/Core/VideoBackends/OGL/PerfQuery.cpp
+++ b/Source/Core/VideoBackends/OGL/PerfQuery.cpp
@@ -6,25 +6,23 @@
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
-#include "Common/GL/GLInterfaceBase.h"
-#include "Common/GL/GLUtil.h"
+#include "Common/GL/GLExtensions/GLExtensions.h"
#include "VideoBackends/OGL/PerfQuery.h"
-#include "VideoCommon/RenderBase.h"
+#include "VideoBackends/OGL/Render.h"
#include "VideoCommon/VideoConfig.h"
namespace OGL
{
std::unique_ptr<PerfQueryBase> GetPerfQuery()
{
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3 &&
- GLExtensions::Supports("GL_NV_occlusion_query_samples"))
+ const bool is_gles = static_cast<Renderer*>(g_renderer.get())->IsGLES();
+ if (is_gles && GLExtensions::Supports("GL_NV_occlusion_query_samples"))
return std::make_unique<PerfQueryGLESNV>();
-
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
+ else if (is_gles)
return std::make_unique<PerfQueryGL>(GL_ANY_SAMPLES_PASSED);
-
- return std::make_unique<PerfQueryGL>(GL_SAMPLES_PASSED);
+ else
+ return std::make_unique<PerfQueryGL>(GL_SAMPLES_PASSED);
}
PerfQuery::PerfQuery() : m_query_read_pos()
@@ -266,4 +264,4 @@ void PerfQueryGLESNV::FlushResults()
FlushOne();
}
-} // namespace
+} // namespace OGL
diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
index 2d284ae4ef..78458aa3fe 100644
--- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
+++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
@@ -12,7 +12,7 @@
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
-#include "Common/GL/GLInterfaceBase.h"
+#include "Common/GL/GLContext.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
@@ -805,7 +805,8 @@ void ProgramShaderCache::CreateHeader()
bool SharedContextAsyncShaderCompiler::WorkerThreadInitMainThread(void** param)
{
- std::unique_ptr<cInterfaceBase> context = GLInterface->CreateSharedContext();
+ std::unique_ptr<GLContext> context =
+ static_cast<Renderer*>(g_renderer.get())->GetMainGLContext()->CreateSharedContext();
if (!context)
{
PanicAlert("Failed to create shared context for shader compiling.");
@@ -818,20 +819,20 @@ bool SharedContextAsyncShaderCompiler::WorkerThreadInitMainThread(void** param)
bool SharedContextAsyncShaderCompiler::WorkerThreadInitWorkerThread(void* param)
{
- cInterfaceBase* context = static_cast<cInterfaceBase*>(param);
+ GLContext* context = static_cast<GLContext*>(param);
if (!context->MakeCurrent())
return false;
s_is_shared_context = true;
if (g_ActiveConfig.backend_info.bSupportsPrimitiveRestart)
- GLUtil::EnablePrimitiveRestart();
+ GLUtil::EnablePrimitiveRestart(context);
return true;
}
void SharedContextAsyncShaderCompiler::WorkerThreadExit(void* param)
{
- cInterfaceBase* context = static_cast<cInterfaceBase*>(param);
+ GLContext* context = static_cast<GLContext*>(param);
context->ClearCurrent();
delete context;
}
diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp
index 27113a6b8b..360d4c2dcc 100644
--- a/Source/Core/VideoBackends/OGL/Render.cpp
+++ b/Source/Core/VideoBackends/OGL/Render.cpp
@@ -16,7 +16,7 @@
#include "Common/Assert.h"
#include "Common/Atomic.h"
#include "Common/CommonTypes.h"
-#include "Common/GL/GLInterfaceBase.h"
+#include "Common/GL/GLContext.h"
#include "Common/GL/GLUtil.h"
#include "Common/Logging/LogManager.h"
#include "Common/MathUtil.h"
@@ -353,9 +353,10 @@ static void InitDriverInfo()
}
// Init functions
-Renderer::Renderer()
- : ::Renderer(static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u)),
- static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u)))
+Renderer::Renderer(std::unique_ptr<GLContext> main_gl_context)
+ : ::Renderer(static_cast<int>(std::max(main_gl_context->GetBackBufferWidth(), 1u)),
+ static_cast<int>(std::max(main_gl_context->GetBackBufferHeight(), 1u))),
+ m_main_gl_context(std::move(main_gl_context))
{
bool bSuccess = true;
@@ -365,7 +366,7 @@ Renderer::Renderer()
InitDriverInfo();
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
+ if (!m_main_gl_context->IsGLES())
{
if (!GLExtensions::Supports("GL_ARB_framebuffer_object"))
{
@@ -500,7 +501,7 @@ Renderer::Renderer()
g_Config.backend_info.bSupportsBPTCTextures =
GLExtensions::Supports("GL_ARB_texture_compression_bptc");
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
+ if (m_main_gl_context->IsGLES())
{
g_ogl_config.SupportedESPointSize =
GLExtensions::Supports("GL_OES_geometry_point_size") ?
@@ -730,10 +731,9 @@ Renderer::Renderer()
if (!g_ogl_config.bSupportsGLBufferStorage && !g_ogl_config.bSupportsGLPinnedMemory)
{
- OSD::AddMessage(
- StringFromFormat("Your OpenGL driver does not support %s_buffer_storage.",
- GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3 ? "EXT" : "ARB"),
- 60000);
+ OSD::AddMessage(StringFromFormat("Your OpenGL driver does not support %s_buffer_storage.",
+ m_main_gl_context->IsGLES() ? "EXT" : "ARB"),
+ 60000);
OSD::AddMessage("This device's performance will be terrible.", 60000);
OSD::AddMessage("Please ask your device vendor for an updated OpenGL driver.", 60000);
}
@@ -761,7 +761,7 @@ Renderer::Renderer()
// Handle VSync on/off
s_vsync = g_ActiveConfig.IsVSync();
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC))
- GLInterface->SwapInterval(s_vsync);
+ m_main_gl_context->SwapInterval(s_vsync);
// Because of the fixed framebuffer size we need to disable the resolution
// options while running
@@ -796,7 +796,7 @@ Renderer::Renderer()
glClearDepthf(1.0f);
if (g_ActiveConfig.backend_info.bSupportsPrimitiveRestart)
- GLUtil::EnablePrimitiveRestart();
+ GLUtil::EnablePrimitiveRestart(m_main_gl_context.get());
IndexGenerator::Init();
UpdateActiveConfig();
@@ -805,6 +805,11 @@ Renderer::Renderer()
Renderer::~Renderer() = default;
+bool Renderer::IsHeadless() const
+{
+ return m_main_gl_context->IsHeadless();
+}
+
void Renderer::Shutdown()
{
::Renderer::Shutdown();
@@ -1044,7 +1049,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
std::unique_ptr<u32[]> colorMap(new u32[targetPixelRcWidth * targetPixelRcHeight]);
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
+ if (IsGLES())
// XXX: Swap colours
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth,
targetPixelRcHeight, GL_RGBA, GL_UNSIGNED_BYTE, colorMap.get());
@@ -1351,7 +1356,7 @@ void Renderer::ApplyBlendingState(const BlendingState state, bool force)
GL_XOR, GL_OR, GL_NOR, GL_EQUIV, GL_INVERT, GL_OR_REVERSE,
GL_COPY_INVERTED, GL_OR_INVERTED, GL_NAND, GL_SET};
- if (GLInterface->GetMode() != GLInterfaceMode::MODE_OPENGL)
+ if (IsGLES())
{
// Logic ops aren't available in GLES3
}
@@ -1421,7 +1426,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
OSD::DrawMessages();
// Swap the back and front buffers, presenting the image.
- GLInterface->Swap();
+ m_main_gl_context->Swap();
}
else
{
@@ -1466,7 +1471,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
{
s_vsync = g_ActiveConfig.IsVSync();
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC))
- GLInterface->SwapInterval(s_vsync);
+ m_main_gl_context->SwapInterval(s_vsync);
}
// Clean out old stuff from caches. It's not worth it to clean out the shader caches.
@@ -1500,14 +1505,12 @@ void Renderer::CheckForSurfaceChange()
if (!m_surface_changed.TestAndClear())
return;
- m_surface_handle = m_new_surface_handle;
+ m_main_gl_context->UpdateSurface(m_new_surface_handle);
m_new_surface_handle = nullptr;
- GLInterface->UpdateHandle(m_surface_handle);
- GLInterface->UpdateSurface();
// With a surface change, the window likely has new dimensions.
- m_backbuffer_width = GLInterface->GetBackBufferWidth();
- m_backbuffer_height = GLInterface->GetBackBufferHeight();
+ m_backbuffer_width = m_main_gl_context->GetBackBufferWidth();
+ m_backbuffer_height = m_main_gl_context->GetBackBufferHeight();
}
void Renderer::CheckForSurfaceResize()
@@ -1515,9 +1518,9 @@ void Renderer::CheckForSurfaceResize()
if (!m_surface_resized.TestAndClear())
return;
- GLInterface->Update();
- m_backbuffer_width = m_new_backbuffer_width;
- m_backbuffer_height = m_new_backbuffer_height;
+ m_main_gl_context->Update();
+ m_backbuffer_width = m_main_gl_context->GetBackBufferWidth();
+ m_backbuffer_height = m_main_gl_context->GetBackBufferHeight();
}
void Renderer::DrawEFB(GLuint framebuffer, const TargetRectangle& target_rc,
@@ -1538,7 +1541,7 @@ void Renderer::ResetAPIState()
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
+ if (!IsGLES())
glDisable(GL_COLOR_LOGIC_OP);
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
{
@@ -1717,4 +1720,4 @@ std::unique_ptr<VideoCommon::AsyncShaderCompiler> Renderer::CreateAsyncShaderCom
{
return std::make_unique<SharedContextAsyncShaderCompiler>();
}
-}
+} // namespace OGL
diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h
index c27c06308c..5beb4ecd75 100644
--- a/Source/Core/VideoBackends/OGL/Render.h
+++ b/Source/Core/VideoBackends/OGL/Render.h
@@ -7,7 +7,8 @@
#include <array>
#include <string>
-#include "Common/GL/GLUtil.h"
+#include "Common/GL/GLContext.h"
+#include "Common/GL/GLExtensions/GLExtensions.h"
#include "VideoCommon/RenderBase.h"
struct XFBSourceBase;
@@ -81,9 +82,11 @@ extern VideoConfig g_ogl_config;
class Renderer : public ::Renderer
{
public:
- Renderer();
+ Renderer(std::unique_ptr<GLContext> main_gl_context);
~Renderer() override;
+ bool IsHeadless() const override;
+
void Init();
void Shutdown() override;
@@ -141,6 +144,10 @@ public:
std::unique_ptr<VideoCommon::AsyncShaderCompiler> CreateAsyncShaderCompiler() override;
+ // Only call methods from this on the GPU thread.
+ GLContext* GetMainGLContext() const { return m_main_gl_context.get(); }
+ bool IsGLES() const { return m_main_gl_context->IsGLES(); }
+
private:
void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc,
const TargetRectangle& targetPixelRc, const void* data);
@@ -159,10 +166,11 @@ private:
void ApplyDepthState(const DepthState state, bool force = false);
void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size);
+ std::unique_ptr<GLContext> m_main_gl_context;
std::array<const AbstractTexture*, 8> m_bound_textures{};
const OGLPipeline* m_graphics_pipeline = nullptr;
RasterizationState m_current_rasterization_state = {};
DepthState m_current_depth_state = {};
BlendingState m_current_blend_state = {};
};
-}
+} // namespace OGL
diff --git a/Source/Core/VideoBackends/OGL/SamplerCache.cpp b/Source/Core/VideoBackends/OGL/SamplerCache.cpp
index 32be0ac4d9..364ec51c99 100644
--- a/Source/Core/VideoBackends/OGL/SamplerCache.cpp
+++ b/Source/Core/VideoBackends/OGL/SamplerCache.cpp
@@ -3,11 +3,11 @@
// Refer to the license.txt file included.
#include "VideoBackends/OGL/SamplerCache.h"
+#include "VideoBackends/OGL/Render.h"
#include <memory>
#include "Common/CommonTypes.h"
-#include "Common/GL/GLInterfaceBase.h"
#include "VideoCommon/SamplerCommon.h"
#include "VideoCommon/VideoConfig.h"
@@ -99,7 +99,7 @@ void SamplerCache::SetParameters(GLuint sampler_id, const SamplerState& params)
glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, params.min_lod / 16.f);
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, params.max_lod / 16.f);
- if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
+ if (!static_cast<Renderer*>(g_renderer.get())->IsGLES())
glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, params.lod_bias / 256.f);
if (params.anisotropic_filtering && g_ogl_config.bSupportsAniso)
@@ -117,4 +117,4 @@ void SamplerCache::Clear()
p.second = 0;
m_cache.clear();
}
-}
+} // namespace OGL
diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp
index 95a3d30e1a..10f191448e 100644
--- a/Source/Core/VideoBackends/OGL/TextureCache.cpp
+++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp
@@ -10,7 +10,6 @@
#include <vector>
#include "Common/Assert.h"
-#include "Common/GL/GLInterfaceBase.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
diff --git a/Source/Core/VideoBackends/OGL/VideoBackend.h b/Source/Core/VideoBackends/OGL/VideoBackend.h
index 1bb4cb3af1..74bc929e85 100644
--- a/Source/Core/VideoBackends/OGL/VideoBackend.h
+++ b/Source/Core/VideoBackends/OGL/VideoBackend.h
@@ -7,11 +7,13 @@
#include <string>
#include "VideoCommon/VideoBackendBase.h"
+class GLContext;
+
namespace OGL
{
class VideoBackend : public VideoBackendBase
{
- bool Initialize(void*) override;
+ bool Initialize(const WindowSystemInfo& wsi) override;
void Shutdown() override;
std::string GetName() const override;
@@ -20,7 +22,7 @@ class VideoBackend : public VideoBackendBase
void InitBackendInfo() override;
private:
- bool InitializeGLExtensions();
+ bool InitializeGLExtensions(GLContext* context);
bool FillBackendInfo();
};
-}
+} // namespace OGL
diff --git a/Source/Core/VideoBackends/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp
index d2e37f07a9..bc67b716cc 100644
--- a/Source/Core/VideoBackends/OGL/main.cpp
+++ b/Source/Core/VideoBackends/OGL/main.cpp
@@ -39,10 +39,12 @@ Make AA apply instantly during gameplay if possible
#include <vector>
#include "Common/Common.h"
-#include "Common/GL/GLInterfaceBase.h"
+#include "Common/GL/GLContext.h"
#include "Common/GL/GLUtil.h"
#include "Common/MsgHandler.h"
+#include "Core/Config/GraphicsSettings.h"
+
#include "VideoBackends/OGL/BoundingBox.h"
#include "VideoBackends/OGL/PerfQuery.h"
#include "VideoBackends/OGL/ProgramShaderCache.h"
@@ -66,7 +68,7 @@ std::string VideoBackend::GetName() const
std::string VideoBackend::GetDisplayName() const
{
- if (GLInterface != nullptr && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
+ if (g_renderer && static_cast<Renderer*>(g_renderer.get())->IsGLES())
return _trans("OpenGL ES");
else
return _trans("OpenGL");
@@ -108,10 +110,10 @@ void VideoBackend::InitBackendInfo()
g_Config.backend_info.AAModes = {1, 2, 4, 8};
}
-bool VideoBackend::InitializeGLExtensions()
+bool VideoBackend::InitializeGLExtensions(GLContext* context)
{
// Init extension support.
- if (!GLExtensions::Init())
+ if (!GLExtensions::Init(context))
{
// OpenGL 2.0 is required for all shader based drawings. There is no way to get this by
// extensions
@@ -157,20 +159,20 @@ bool VideoBackend::FillBackendInfo()
return true;
}
-bool VideoBackend::Initialize(void* window_handle)
+bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
{
InitializeShared();
- GLUtil::InitInterface();
- GLInterface->SetMode(GLInterfaceMode::MODE_DETECT);
- if (!GLInterface->Create(window_handle, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer))
+ std::unique_ptr<GLContext> main_gl_context =
+ GLContext::Create(wsi, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer, true, false,
+ Config::Get(Config::GFX_PREFER_GLES));
+ if (!main_gl_context)
return false;
- GLInterface->MakeCurrent();
- if (!InitializeGLExtensions() || !FillBackendInfo())
+ if (!InitializeGLExtensions(main_gl_context.get()) || !FillBackendInfo())
return false;
- g_renderer = std::make_unique<Renderer>();
+ g_renderer = std::make_unique<Renderer>(std::move(main_gl_context));
g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = GetPerfQuery();
ProgramShaderCache::Init();
@@ -196,9 +198,6 @@ void VideoBackend::Shutdown()
g_perf_query.reset();
g_vertex_manager.reset();
g_renderer.reset();
- GLInterface->ClearCurrent();
- GLInterface->Shutdown();
- GLInterface.reset();
ShutdownShared();
}
-}
+} // namespace OGL
diff --git a/Source/Core/VideoBackends/Software/SWOGLWindow.cpp b/Source/Core/VideoBackends/Software/SWOGLWindow.cpp
index 695f58cc1d..81216ff7ef 100644
--- a/Source/Core/VideoBackends/Software/SWOGLWindow.cpp
+++ b/Source/Core/VideoBackends/Software/SWOGLWindow.cpp
@@ -4,52 +4,51 @@
#include <memory>
-#include "Common/GL/GLInterfaceBase.h"
+#include "Common/GL/GLContext.h"
#include "Common/GL/GLUtil.h"
#include "Common/Logging/Log.h"
+#include "Common/MsgHandler.h"
#include "VideoBackends/Software/SWOGLWindow.h"
#include "VideoBackends/Software/SWTexture.h"
-std::unique_ptr<SWOGLWindow> SWOGLWindow::s_instance;
+SWOGLWindow::SWOGLWindow() = default;
+SWOGLWindow::~SWOGLWindow() = default;
-void SWOGLWindow::Init(void* window_handle)
+std::unique_ptr<SWOGLWindow> SWOGLWindow::Create(const WindowSystemInfo& wsi)
{
- GLUtil::InitInterface();
- GLInterface->SetMode(GLInterfaceMode::MODE_DETECT);
- if (!GLInterface->Create(window_handle))
+ std::unique_ptr<SWOGLWindow> window = std::unique_ptr<SWOGLWindow>(new SWOGLWindow());
+ if (!window->Initialize(wsi))
{
- ERROR_LOG(VIDEO, "GLInterface::Create failed.");
+ PanicAlert("Failed to create OpenGL window");
+ return nullptr;
}
- s_instance.reset(new SWOGLWindow());
+ return window;
}
-void SWOGLWindow::Shutdown()
+bool SWOGLWindow::IsHeadless() const
{
- GLInterface->Shutdown();
- GLInterface.reset();
-
- s_instance.reset();
+ return m_gl_context->IsHeadless();
}
-void SWOGLWindow::Prepare()
+bool SWOGLWindow::Initialize(const WindowSystemInfo& wsi)
{
- if (m_init)
- return;
- m_init = true;
+ m_gl_context = GLContext::Create(wsi);
+ if (!m_gl_context)
+ return false;
// Init extension support.
- if (!GLExtensions::Init())
+ if (!GLExtensions::Init(m_gl_context.get()))
{
ERROR_LOG(VIDEO, "GLExtensions::Init failed!Does your video card support OpenGL 2.0?");
- return;
+ return false;
}
else if (GLExtensions::Version() < 310)
{
ERROR_LOG(VIDEO, "OpenGL Version %d detected, but at least 3.1 is required.",
GLExtensions::Version());
- return;
+ return false;
}
std::string frag_shader = "in vec2 TexCoord;\n"
@@ -66,10 +65,9 @@ void SWOGLWindow::Prepare()
" TexCoord = vec2(rawpos.x, -rawpos.y);\n"
"}\n";
- std::string header = GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL ?
- "#version 140\n" :
- "#version 300 es\n"
- "precision highp float;\n";
+ std::string header = m_gl_context->IsGLES() ? "#version 300 es\n"
+ "precision highp float;\n" :
+ "#version 140\n";
m_image_program = GLUtil::CompileProgram(header + vertex_shader, header + frag_shader);
@@ -83,6 +81,7 @@ void SWOGLWindow::Prepare()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glGenVertexArrays(1, &m_image_vao);
+ return true;
}
void SWOGLWindow::PrintText(const std::string& text, int x, int y, u32 color)
@@ -93,10 +92,10 @@ void SWOGLWindow::PrintText(const std::string& text, int x, int y, u32 color)
void SWOGLWindow::ShowImage(AbstractTexture* image, const EFBRectangle& xfb_region)
{
SW::SWTexture* sw_image = static_cast<SW::SWTexture*>(image);
- GLInterface->Update(); // just updates the render window position and the backbuffer size
+ m_gl_context->Update(); // just updates the render window position and the backbuffer size
- GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();
- GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight();
+ GLsizei glWidth = (GLsizei)m_gl_context->GetBackBufferWidth();
+ GLsizei glHeight = (GLsizei)m_gl_context->GetBackBufferHeight();
glViewport(0, 0, glWidth, glHeight);
@@ -123,10 +122,5 @@ void SWOGLWindow::ShowImage(AbstractTexture* image, const EFBRectangle& xfb_regi
// }
m_text.clear();
- GLInterface->Swap();
-}
-
-int SWOGLWindow::PeekMessages()
-{
- return GLInterface->PeekMessages();
+ m_gl_context->Swap();
}
diff --git a/Source/Core/VideoBackends/Software/SWOGLWindow.h b/Source/Core/VideoBackends/Software/SWOGLWindow.h
index 64ee2414bc..38ae316d07 100644
--- a/Source/Core/VideoBackends/Software/SWOGLWindow.h
+++ b/Source/Core/VideoBackends/Software/SWOGLWindow.h
@@ -11,14 +11,18 @@
#include "Common/CommonTypes.h"
#include "VideoCommon/VideoCommon.h"
+class GLContext;
+
class AbstractTexture;
+struct WindowSystemInfo;
class SWOGLWindow
{
public:
- static void Init(void* window_handle);
- static void Shutdown();
- void Prepare();
+ ~SWOGLWindow();
+
+ GLContext* GetContext() const { return m_gl_context.get(); }
+ bool IsHeadless() const;
// Will be printed on the *next* image
void PrintText(const std::string& text, int x, int y, u32 color);
@@ -26,12 +30,13 @@ public:
// Image to show, will be swapped immediately
void ShowImage(AbstractTexture* image, const EFBRectangle& xfb_region);
- int PeekMessages();
-
- static std::unique_ptr<SWOGLWindow> s_instance;
+ static std::unique_ptr<SWOGLWindow> Create(const WindowSystemInfo& wsi);
private:
- SWOGLWindow() {}
+ SWOGLWindow();
+
+ bool Initialize(const WindowSystemInfo& wsi);
+
struct TextData
{
std::string text;
@@ -40,7 +45,9 @@ private:
};
std::vector<TextData> m_text;
- bool m_init{false};
+ u32 m_image_program = 0;
+ u32 m_image_texture = 0;
+ u32 m_image_vao = 0;
- u32 m_image_program, m_image_texture, m_image_vao;
+ std::unique_ptr<GLContext> m_gl_context;
};
diff --git a/Source/Core/VideoBackends/Software/SWRenderer.cpp b/Source/Core/VideoBackends/Software/SWRenderer.cpp
index f4e322619d..2c6a97027b 100644
--- a/Source/Core/VideoBackends/Software/SWRenderer.cpp
+++ b/Source/Core/VideoBackends/Software/SWRenderer.cpp
@@ -7,6 +7,7 @@
#include <string>
#include "Common/CommonTypes.h"
+#include "Common/GL/GLContext.h"
#include "Core/Config/GraphicsSettings.h"
#include "Core/HW/Memmap.h"
@@ -23,11 +24,17 @@
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoConfig.h"
-SWRenderer::SWRenderer()
- : ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT))
+SWRenderer::SWRenderer(std::unique_ptr<SWOGLWindow> window)
+ : ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT)),
+ m_window(std::move(window))
{
}
+bool SWRenderer::IsHeadless() const
+{
+ return m_window->IsHeadless();
+}
+
std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<SW::SWTexture>(config);
@@ -49,7 +56,7 @@ SWRenderer::CreateFramebuffer(const AbstractTexture* color_attachment,
void SWRenderer::RenderText(const std::string& pstr, int left, int top, u32 color)
{
- SWOGLWindow::s_instance->PrintText(pstr, left, top, color);
+ m_window->PrintText(pstr, left, top, color);
}
class SWShader final : public AbstractShader
@@ -94,7 +101,7 @@ void SWRenderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_regi
if (!IsHeadless())
{
DrawDebugText();
- SWOGLWindow::s_instance->ShowImage(texture, xfb_region);
+ m_window->ShowImage(texture, xfb_region);
}
UpdateActiveConfig();
diff --git a/Source/Core/VideoBackends/Software/SWRenderer.h b/Source/Core/VideoBackends/Software/SWRenderer.h
index 3c274edda7..936139516f 100644
--- a/Source/Core/VideoBackends/Software/SWRenderer.h
+++ b/Source/Core/VideoBackends/Software/SWRenderer.h
@@ -4,14 +4,20 @@
#pragma once
+#include <memory>
+
#include "Common/CommonTypes.h"
#include "VideoCommon/RenderBase.h"
+class SWOGLWindow;
+
class SWRenderer : public Renderer
{
public:
- SWRenderer();
+ SWRenderer(std::unique_ptr<SWOGLWindow> window);
+
+ bool IsHeadless() const override;
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractStagingTexture>
@@ -40,4 +46,7 @@ public:
u32 color, u32 z) override;
void ReinterpretPixelData(unsigned int convtype) override {}
+
+private:
+ std::unique_ptr<SWOGLWindow> m_window;
};
diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp
index 6ca183b57c..a0ad349849 100644
--- a/Source/Core/VideoBackends/Software/SWmain.cpp
+++ b/Source/Core/VideoBackends/Software/SWmain.cpp
@@ -9,7 +9,7 @@
#include "Common/Common.h"
#include "Common/CommonTypes.h"
-#include "Common/GL/GLInterfaceBase.h"
+#include "Common/GL/GLContext.h"
#include "VideoBackends/Software/Clipper.h"
#include "VideoBackends/Software/DebugUtil.h"
@@ -78,20 +78,19 @@ void VideoSoftware::InitBackendInfo()
g_Config.backend_info.AAModes = {1};
}
-bool VideoSoftware::Initialize(void* window_handle)
+bool VideoSoftware::Initialize(const WindowSystemInfo& wsi)
{
InitializeShared();
- SWOGLWindow::Init(window_handle);
+ std::unique_ptr<SWOGLWindow> window = SWOGLWindow::Create(wsi);
+ if (!window)
+ return false;
Clipper::Init();
Rasterizer::Init();
DebugUtil::Init();
- GLInterface->MakeCurrent();
- SWOGLWindow::s_instance->Prepare();
-
- g_renderer = std::make_unique<SWRenderer>();
+ g_renderer = std::make_unique<SWRenderer>(std::move(window));
g_vertex_manager = std::make_unique<SWVertexLoader>();
g_perf_query = std::make_unique<PerfQuery>();
g_texture_cache = std::make_unique<TextureCache>();
@@ -108,7 +107,6 @@ void VideoSoftware::Shutdown()
g_renderer->Shutdown();
DebugUtil::Shutdown();
- SWOGLWindow::Shutdown();
g_framebuffer_manager.reset();
g_texture_cache.reset();
g_perf_query.reset();
@@ -116,4 +114,4 @@ void VideoSoftware::Shutdown()
g_renderer.reset();
ShutdownShared();
}
-}
+} // namespace SW
diff --git a/Source/Core/VideoBackends/Software/VideoBackend.h b/Source/Core/VideoBackends/Software/VideoBackend.h
index f618ea44ab..bad120d6a1 100644
--- a/Source/Core/VideoBackends/Software/VideoBackend.h
+++ b/Source/Core/VideoBackends/Software/VideoBackend.h
@@ -11,7 +11,7 @@ namespace SW
{
class VideoSoftware : public VideoBackendBase
{
- bool Initialize(void* window_handle) override;
+ bool Initialize(const WindowSystemInfo& wsi) override;
void Shutdown() override;
std::string GetName() const override;
@@ -19,4 +19,4 @@ class VideoSoftware : public VideoBackendBase
void InitBackendInfo() override;
};
-}
+} // namespace SW
diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp
index 38d7bd0992..ce52b0718d 100644
--- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp
+++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp
@@ -70,6 +70,11 @@ Renderer* Renderer::GetInstance()
return static_cast<Renderer*>(g_renderer.get());
}
+bool Renderer::IsHeadless() const
+{
+ return m_swap_chain == nullptr;
+}
+
bool Renderer::Initialize()
{
BindEFBToStateTracker();
@@ -860,12 +865,9 @@ void Renderer::BlitScreen(VkRenderPass render_pass, const TargetRectangle& dst_r
void Renderer::CheckForSurfaceChange()
{
- if (!m_surface_changed.TestAndClear())
+ if (!m_surface_changed.TestAndClear() || !m_swap_chain)
return;
- m_surface_handle = m_new_surface_handle;
- m_new_surface_handle = nullptr;
-
// Submit the current draws up until rendering the XFB.
g_command_buffer_mgr->ExecuteCommandBuffer(false, false);
g_command_buffer_mgr->WaitForGPUIdle();
@@ -873,37 +875,10 @@ void Renderer::CheckForSurfaceChange()
// Clear the present failed flag, since we don't want to resize after recreating.
g_command_buffer_mgr->CheckLastPresentFail();
- // Did we previously have a swap chain?
- if (m_swap_chain)
- {
- if (!m_surface_handle)
- {
- // If there is no surface now, destroy the swap chain.
- m_swap_chain.reset();
- }
- else
- {
- // Recreate the surface. If this fails we're in trouble.
- if (!m_swap_chain->RecreateSurface(m_surface_handle))
- PanicAlert("Failed to recreate Vulkan surface. Cannot continue.");
- }
- }
- else
- {
- // Previously had no swap chain. So create one.
- VkSurfaceKHR surface =
- SwapChain::CreateVulkanSurface(g_vulkan_context->GetVulkanInstance(), m_surface_handle);
- if (surface != VK_NULL_HANDLE)
- {
- m_swap_chain = SwapChain::Create(m_surface_handle, surface, g_ActiveConfig.IsVSync());
- if (!m_swap_chain)
- PanicAlert("Failed to create swap chain.");
- }
- else
- {
- PanicAlert("Failed to create surface.");
- }
- }
+ // Recreate the surface. If this fails we're in trouble.
+ if (!m_swap_chain->RecreateSurface(m_new_surface_handle))
+ PanicAlert("Failed to recreate Vulkan surface. Cannot continue.");
+ m_new_surface_handle = nullptr;
// Handle case where the dimensions are now different.
OnSwapChainResized();
@@ -914,9 +889,6 @@ void Renderer::CheckForSurfaceResize()
if (!m_surface_resized.TestAndClear())
return;
- m_backbuffer_width = m_new_backbuffer_width;
- m_backbuffer_height = m_new_backbuffer_height;
-
// If we don't have a surface, how can we resize the swap chain?
// CheckForSurfaceChange should handle this case.
if (!m_swap_chain)
diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.h b/Source/Core/VideoBackends/Vulkan/Renderer.h
index ce15d12592..ba8fd889bd 100644
--- a/Source/Core/VideoBackends/Vulkan/Renderer.h
+++ b/Source/Core/VideoBackends/Vulkan/Renderer.h
@@ -35,6 +35,8 @@ public:
static Renderer* GetInstance();
+ bool IsHeadless() const override;
+
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
diff --git a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
index 3294b944ef..5222d88114 100644
--- a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
+++ b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
@@ -25,8 +25,9 @@
namespace Vulkan
{
-SwapChain::SwapChain(void* native_handle, VkSurfaceKHR surface, bool vsync)
- : m_native_handle(native_handle), m_surface(surface), m_vsync_enabled(vsync)
+SwapChain::SwapChain(void* display_handle, void* native_handle, VkSurfaceKHR surface, bool vsync)
+ : m_display_handle(display_handle), m_native_handle(native_handle), m_surface(surface),
+ m_vsync_enabled(vsync)
{
}
@@ -37,7 +38,7 @@ SwapChain::~SwapChain()
DestroySurface();
}
-VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, void* hwnd)
+VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, void* display_handle, void* hwnd)
{
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VkWin32SurfaceCreateInfoKHR surface_create_info = {
@@ -59,15 +60,11 @@ VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, void* hwnd)
return surface;
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
- // Assuming the display handles are compatible, or shared. This matches what we do in the
- // GL backend, but it's not ideal.
- Display* display = XOpenDisplay(nullptr);
-
VkXlibSurfaceCreateInfoKHR surface_create_info = {
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
nullptr, // const void* pNext
0, // VkXlibSurfaceCreateFlagsKHR flags
- display, // Display* dpy
+ static_cast<Display*>(display_handle), // Display* dpy
reinterpret_cast<Window>(hwnd) // Window window
};
@@ -83,8 +80,7 @@ VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, void* hwnd)
#elif defined(VK_USE_PLATFORM_XCB_KHR)
// If we ever switch to using xcb, we should pass the display handle as well.
- Display* display = XOpenDisplay(nullptr);
- xcb_connection_t* connection = XGetXCBConnection(display);
+ xcb_connection_t* connection = XGetXCBConnection(display_handle);
VkXcbSurfaceCreateInfoKHR surface_create_info = {
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
@@ -127,10 +123,11 @@ VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, void* hwnd)
#endif
}
-std::unique_ptr<SwapChain> SwapChain::Create(void* native_handle, VkSurfaceKHR surface, bool vsync)
+std::unique_ptr<SwapChain> SwapChain::Create(void* display_handle, void* native_handle,
+ VkSurfaceKHR surface, bool vsync)
{
std::unique_ptr<SwapChain> swap_chain =
- std::make_unique<SwapChain>(native_handle, surface, vsync);
+ std::make_unique<SwapChain>(display_handle, native_handle, surface, vsync);
if (!swap_chain->CreateSwapChain() || !swap_chain->CreateRenderPass() ||
!swap_chain->SetupSwapChainImages())
@@ -467,7 +464,8 @@ bool SwapChain::RecreateSurface(void* native_handle)
// Re-create the surface with the new native handle
m_native_handle = native_handle;
- m_surface = CreateVulkanSurface(g_vulkan_context->GetVulkanInstance(), native_handle);
+ m_surface =
+ CreateVulkanSurface(g_vulkan_context->GetVulkanInstance(), m_display_handle, native_handle);
if (m_surface == VK_NULL_HANDLE)
return false;
@@ -499,4 +497,4 @@ void SwapChain::DestroySurface()
vkDestroySurfaceKHR(g_vulkan_context->GetVulkanInstance(), m_surface, nullptr);
m_surface = VK_NULL_HANDLE;
}
-}
+} // namespace Vulkan
diff --git a/Source/Core/VideoBackends/Vulkan/SwapChain.h b/Source/Core/VideoBackends/Vulkan/SwapChain.h
index 1561103cb8..8cf2776a36 100644
--- a/Source/Core/VideoBackends/Vulkan/SwapChain.h
+++ b/Source/Core/VideoBackends/Vulkan/SwapChain.h
@@ -19,15 +19,17 @@ class ObjectCache;
class SwapChain
{
public:
- SwapChain(void* native_handle, VkSurfaceKHR surface, bool vsync);
+ SwapChain(void* display_handle, void* native_handle, VkSurfaceKHR surface, bool vsync);
~SwapChain();
// Creates a vulkan-renderable surface for the specified window handle.
- static VkSurfaceKHR CreateVulkanSurface(VkInstance instance, void* hwnd);
+ static VkSurfaceKHR CreateVulkanSurface(VkInstance instance, void* display_handle, void* hwnd);
// Create a new swap chain from a pre-existing surface.
- static std::unique_ptr<SwapChain> Create(void* native_handle, VkSurfaceKHR surface, bool vsync);
+ static std::unique_ptr<SwapChain> Create(void* display_handle, void* native_handle,
+ VkSurfaceKHR surface, bool vsync);
+ void* GetDisplayHandle() const { return m_display_handle; }
void* GetNativeHandle() const { return m_native_handle; }
VkSurfaceKHR GetSurface() const { return m_surface; }
VkSurfaceFormatKHR GetSurfaceFormat() const { return m_surface_format; }
@@ -81,6 +83,7 @@ private:
VkFramebuffer framebuffer;
};
+ void* m_display_handle;
void* m_native_handle;
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
VkSurfaceFormatKHR m_surface_format = {};
diff --git a/Source/Core/VideoBackends/Vulkan/VideoBackend.h b/Source/Core/VideoBackends/Vulkan/VideoBackend.h
index d4f284962b..83d960330e 100644
--- a/Source/Core/VideoBackends/Vulkan/VideoBackend.h
+++ b/Source/Core/VideoBackends/Vulkan/VideoBackend.h
@@ -12,11 +12,11 @@ namespace Vulkan
class VideoBackend : public VideoBackendBase
{
public:
- bool Initialize(void* window_handle) override;
+ bool Initialize(const WindowSystemInfo& wsi) override;
void Shutdown() override;
std::string GetName() const override { return "Vulkan"; }
std::string GetDisplayName() const override { return _trans("Vulkan"); }
void InitBackendInfo() override;
};
-}
+} // namespace Vulkan
diff --git a/Source/Core/VideoBackends/Vulkan/main.cpp b/Source/Core/VideoBackends/Vulkan/main.cpp
index 9bd4039138..40798934e7 100644
--- a/Source/Core/VideoBackends/Vulkan/main.cpp
+++ b/Source/Core/VideoBackends/Vulkan/main.cpp
@@ -89,7 +89,7 @@ static bool ShouldEnableDebugReports(bool enable_validation_layers)
return enable_validation_layers || IsHostGPULoggingEnabled();
}
-bool VideoBackend::Initialize(void* window_handle)
+bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
{
if (!LoadVulkanLibrary())
{
@@ -107,7 +107,7 @@ bool VideoBackend::Initialize(void* window_handle)
// Create Vulkan instance, needed before we can create a surface, or enumerate devices.
// We use this instance to fill in backend info, then re-use it for the actual device.
- bool enable_surface = window_handle != nullptr;
+ bool enable_surface = wsi.render_surface != nullptr;
bool enable_debug_reports = ShouldEnableDebugReports(enable_validation_layer);
VkInstance instance = VulkanContext::CreateVulkanInstance(enable_surface, enable_debug_reports,
enable_validation_layer);
@@ -146,7 +146,7 @@ bool VideoBackend::Initialize(void* window_handle)
VkSurfaceKHR surface = VK_NULL_HANDLE;
if (enable_surface)
{
- surface = SwapChain::CreateVulkanSurface(instance, window_handle);
+ surface = SwapChain::CreateVulkanSurface(instance, wsi.display_connection, wsi.render_surface);
if (surface == VK_NULL_HANDLE)
{
PanicAlert("Failed to create Vulkan surface.");
@@ -209,7 +209,8 @@ bool VideoBackend::Initialize(void* window_handle)
std::unique_ptr<SwapChain> swap_chain;
if (surface != VK_NULL_HANDLE)
{
- swap_chain = SwapChain::Create(window_handle, surface, g_Config.IsVSync());
+ swap_chain =
+ SwapChain::Create(wsi.display_connection, wsi.render_surface, surface, g_Config.IsVSync());
if (!swap_chain)
{
PanicAlert("Failed to create Vulkan swap chain.");
@@ -271,4 +272,4 @@ void VideoBackend::Shutdown()
ShutdownShared();
UnloadVulkanLibrary();
}
-}
+} // namespace Vulkan