mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #5832 from stenzek/ubershader-prereq
Ubershader prerequisites
This commit is contained in:
@@ -148,6 +148,10 @@ void Host_YieldToUI()
|
||||
{
|
||||
}
|
||||
|
||||
void Host_UpdateProgressDialog(const char* caption, int position, int total)
|
||||
{
|
||||
}
|
||||
|
||||
static bool MsgAlert(const char* caption, const char* text, bool yes_no, int /*Style*/)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "%s:%s", caption, text);
|
||||
|
||||
@@ -141,6 +141,8 @@ public:
|
||||
|
||||
constexpr T Value() const { return Value(std::is_signed<T>()); }
|
||||
constexpr operator T() const { return Value(); }
|
||||
constexpr std::size_t StartBit() const { return position; }
|
||||
constexpr std::size_t NumBits() const { return bits; }
|
||||
private:
|
||||
// StorageType is T for non-enum types and the underlying type of T if
|
||||
// T is an enumeration. Note that T is wrapped within an enable_if in the
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#import <AppKit/AppKit.h>
|
||||
#else
|
||||
struct NSOpenGLContext;
|
||||
struct NSOpenGLPixelFormat;
|
||||
struct NSView;
|
||||
#endif
|
||||
|
||||
@@ -18,13 +19,16 @@ class cInterfaceAGL : public cInterfaceBase
|
||||
public:
|
||||
void Swap() override;
|
||||
bool Create(void* window_handle, bool stereo, bool core) override;
|
||||
bool Create(cInterfaceBase* main_context) override;
|
||||
bool MakeCurrent() override;
|
||||
bool ClearCurrent() override;
|
||||
void Shutdown() override;
|
||||
void Update() override;
|
||||
void SwapInterval(int interval) override;
|
||||
std::unique_ptr<cInterfaceBase> CreateSharedContext() override;
|
||||
|
||||
private:
|
||||
NSView* m_view;
|
||||
NSOpenGLContext* m_context;
|
||||
NSView* m_view = nullptr;
|
||||
NSOpenGLContext* m_context = nullptr;
|
||||
NSOpenGLPixelFormat* m_pixel_format = nullptr;
|
||||
};
|
||||
|
||||
@@ -60,15 +60,14 @@ bool cInterfaceAGL::Create(void* window_handle, bool stereo, bool core)
|
||||
NSOpenGLPFAAccelerated,
|
||||
stereo ? NSOpenGLPFAStereo : static_cast<NSOpenGLPixelFormatAttribute>(0),
|
||||
0};
|
||||
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
||||
if (fmt == nil)
|
||||
m_pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
||||
if (m_pixel_format == nil)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "failed to create pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
|
||||
[fmt release];
|
||||
m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixel_format shareContext:nil];
|
||||
if (m_context == nil)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "failed to create context");
|
||||
@@ -82,6 +81,30 @@ bool cInterfaceAGL::Create(void* window_handle, bool stereo, bool core)
|
||||
return AttachContextToView(m_context, m_view, &s_backbuffer_width, &s_backbuffer_height);
|
||||
}
|
||||
|
||||
bool cInterfaceAGL::Create(cInterfaceBase* main_context)
|
||||
{
|
||||
cInterfaceAGL* agl_context = static_cast<cInterfaceAGL*>(main_context);
|
||||
NSOpenGLPixelFormat* pixel_format = agl_context->m_pixel_format;
|
||||
NSOpenGLContext* share_context = agl_context->m_context;
|
||||
|
||||
m_context = [[NSOpenGLContext alloc] initWithFormat:pixel_format shareContext:share_context];
|
||||
if (m_context == nil)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "failed to create shared context");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<cInterfaceBase> cInterfaceAGL::CreateSharedContext()
|
||||
{
|
||||
std::unique_ptr<cInterfaceBase> context = std::make_unique<cInterfaceAGL>();
|
||||
if (!context->Create(this))
|
||||
return nullptr;
|
||||
return context;
|
||||
}
|
||||
|
||||
bool cInterfaceAGL::MakeCurrent()
|
||||
{
|
||||
[m_context makeCurrentContext];
|
||||
@@ -100,6 +123,8 @@ void cInterfaceAGL::Shutdown()
|
||||
[m_context clearDrawable];
|
||||
[m_context release];
|
||||
m_context = nil;
|
||||
[m_pixel_format release];
|
||||
m_pixel_format = nil;
|
||||
}
|
||||
|
||||
void cInterfaceAGL::Update()
|
||||
|
||||
@@ -212,7 +212,10 @@ bool cInterfaceEGL::Create(void* window_handle, bool stereo, bool core)
|
||||
|
||||
egl_ctx = eglCreateContext(egl_dpy, m_config, EGL_NO_CONTEXT, &core_attribs[0]);
|
||||
if (egl_ctx)
|
||||
{
|
||||
m_attribs = std::move(core_attribs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +223,7 @@ bool cInterfaceEGL::Create(void* window_handle, bool stereo, bool core)
|
||||
{
|
||||
m_core = false;
|
||||
egl_ctx = eglCreateContext(egl_dpy, m_config, EGL_NO_CONTEXT, &ctx_attribs[0]);
|
||||
m_attribs = std::move(ctx_attribs);
|
||||
}
|
||||
|
||||
if (!egl_ctx)
|
||||
@@ -255,31 +259,13 @@ bool cInterfaceEGL::Create(cInterfaceBase* main_context)
|
||||
m_is_shared = true;
|
||||
m_has_handle = false;
|
||||
|
||||
EGLint ctx_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
||||
|
||||
switch (egl_context->GetMode())
|
||||
{
|
||||
case GLInterfaceMode::MODE_OPENGL:
|
||||
ctx_attribs[0] = EGL_NONE;
|
||||
break;
|
||||
case GLInterfaceMode::MODE_OPENGLES2:
|
||||
ctx_attribs[1] = 2;
|
||||
break;
|
||||
case GLInterfaceMode::MODE_OPENGLES3:
|
||||
ctx_attribs[1] = 3;
|
||||
break;
|
||||
default:
|
||||
INFO_LOG(VIDEO, "Unknown opengl mode set");
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (egl_context->GetMode() == GLInterfaceMode::MODE_OPENGL)
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
else
|
||||
eglBindAPI(EGL_OPENGL_ES_API);
|
||||
|
||||
egl_ctx = eglCreateContext(egl_dpy, m_config, egl_context->egl_ctx, ctx_attribs);
|
||||
egl_ctx =
|
||||
eglCreateContext(egl_dpy, m_config, egl_context->egl_ctx, egl_context->m_attribs.data());
|
||||
if (!egl_ctx)
|
||||
{
|
||||
INFO_LOG(VIDEO, "Error: eglCreateContext failed 0x%04x", eglGetError());
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/GL/GLInterfaceBase.h"
|
||||
|
||||
@@ -17,6 +18,7 @@ private:
|
||||
bool m_has_handle;
|
||||
EGLNativeWindowType m_host_window;
|
||||
bool m_supports_surfaceless = false;
|
||||
std::vector<int> m_attribs;
|
||||
|
||||
bool CreateWindowSurface();
|
||||
void DestroyWindowSurface();
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
|
||||
#include "Common/GL/GLInterface/GLX.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
@@ -17,6 +18,9 @@ typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int interval);
|
||||
static PFNGLXCREATECONTEXTATTRIBSPROC glXCreateContextAttribs = nullptr;
|
||||
static PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr;
|
||||
|
||||
static PFNGLXCREATEGLXPBUFFERSGIXPROC glXCreateGLXPbufferSGIX = nullptr;
|
||||
static PFNGLXDESTROYGLXPBUFFERSGIXPROC glXDestroyGLXPbufferSGIX = nullptr;
|
||||
|
||||
static bool s_glxError;
|
||||
static int ctxErrorHandler(Display* dpy, XErrorEvent* ev)
|
||||
{
|
||||
@@ -26,7 +30,7 @@ static int ctxErrorHandler(Display* dpy, XErrorEvent* ev)
|
||||
|
||||
void cInterfaceGLX::SwapInterval(int Interval)
|
||||
{
|
||||
if (glXSwapIntervalSGI)
|
||||
if (glXSwapIntervalSGI && m_has_handle)
|
||||
glXSwapIntervalSGI(Interval);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
||||
@@ -45,6 +49,9 @@ void cInterfaceGLX::Swap()
|
||||
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
||||
bool cInterfaceGLX::Create(void* window_handle, bool stereo, bool core)
|
||||
{
|
||||
m_has_handle = !!window_handle;
|
||||
m_host_window = (Window)window_handle;
|
||||
|
||||
dpy = XOpenDisplay(nullptr);
|
||||
int screen = DefaultScreen(dpy);
|
||||
|
||||
@@ -100,51 +107,43 @@ bool cInterfaceGLX::Create(void* window_handle, bool stereo, bool core)
|
||||
fbconfig = *fbc;
|
||||
XFree(fbc);
|
||||
|
||||
// Get an appropriate visual
|
||||
XVisualInfo* vi = glXGetVisualFromFBConfig(dpy, fbconfig);
|
||||
|
||||
s_glxError = false;
|
||||
XErrorHandler oldHandler = XSetErrorHandler(&ctxErrorHandler);
|
||||
|
||||
// Create a GLX context.
|
||||
// We try to get a 4.0 core profile, else we try 3.3, else try it with anything we get.
|
||||
int context_attribs[] = {GLX_CONTEXT_MAJOR_VERSION_ARB,
|
||||
4,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB,
|
||||
0,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB,
|
||||
GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
GLX_CONTEXT_FLAGS_ARB,
|
||||
GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
||||
None};
|
||||
std::array<int, 9> context_attribs = {
|
||||
{GLX_CONTEXT_MAJOR_VERSION_ARB, 4, GLX_CONTEXT_MINOR_VERSION_ARB, 0,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, GLX_CONTEXT_FLAGS_ARB,
|
||||
GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None}};
|
||||
ctx = nullptr;
|
||||
if (core)
|
||||
{
|
||||
ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, context_attribs);
|
||||
ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, &context_attribs[0]);
|
||||
XSync(dpy, False);
|
||||
m_attribs.insert(m_attribs.end(), context_attribs.begin(), context_attribs.end());
|
||||
}
|
||||
if (core && (!ctx || s_glxError))
|
||||
{
|
||||
int context_attribs_33[] = {GLX_CONTEXT_MAJOR_VERSION_ARB,
|
||||
3,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB,
|
||||
3,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB,
|
||||
GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
GLX_CONTEXT_FLAGS_ARB,
|
||||
GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
||||
None};
|
||||
std::array<int, 9> context_attribs_33 = {
|
||||
{GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, GLX_CONTEXT_FLAGS_ARB,
|
||||
GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None}};
|
||||
s_glxError = false;
|
||||
ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, context_attribs_33);
|
||||
ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, &context_attribs_33[0]);
|
||||
XSync(dpy, False);
|
||||
m_attribs.clear();
|
||||
m_attribs.insert(m_attribs.end(), context_attribs_33.begin(), context_attribs_33.end());
|
||||
}
|
||||
if (!ctx || s_glxError)
|
||||
{
|
||||
int context_attribs_legacy[] = {GLX_CONTEXT_MAJOR_VERSION_ARB, 1, GLX_CONTEXT_MINOR_VERSION_ARB,
|
||||
0, None};
|
||||
std::array<int, 5> context_attribs_legacy = {
|
||||
{GLX_CONTEXT_MAJOR_VERSION_ARB, 1, GLX_CONTEXT_MINOR_VERSION_ARB, 0, None}};
|
||||
s_glxError = false;
|
||||
ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, context_attribs_legacy);
|
||||
ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, &context_attribs_legacy[0]);
|
||||
XSync(dpy, False);
|
||||
m_attribs.clear();
|
||||
m_attribs.insert(m_attribs.end(), context_attribs_legacy.begin(), context_attribs_legacy.end());
|
||||
}
|
||||
if (!ctx || s_glxError)
|
||||
{
|
||||
@@ -153,30 +152,116 @@ bool cInterfaceGLX::Create(void* window_handle, bool stereo, bool core)
|
||||
}
|
||||
XSetErrorHandler(oldHandler);
|
||||
|
||||
XWindow.Initialize(dpy);
|
||||
|
||||
Window parent = (Window)window_handle;
|
||||
|
||||
XWindowAttributes attribs;
|
||||
if (!XGetWindowAttributes(dpy, parent, &attribs))
|
||||
std::string tmp;
|
||||
std::istringstream buffer(glXQueryExtensionsString(dpy, screen));
|
||||
while (buffer >> tmp)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Window attribute retrieval failed");
|
||||
return false;
|
||||
if (tmp == "GLX_SGIX_pbuffer")
|
||||
m_supports_pbuffer = true;
|
||||
}
|
||||
|
||||
s_backbuffer_width = attribs.width;
|
||||
s_backbuffer_height = attribs.height;
|
||||
if (m_supports_pbuffer)
|
||||
{
|
||||
// Get the function pointers we require
|
||||
glXCreateGLXPbufferSGIX =
|
||||
(PFNGLXCREATEGLXPBUFFERSGIXPROC)GetFuncAddress("glXCreateGLXPbufferSGIX");
|
||||
glXDestroyGLXPbufferSGIX =
|
||||
(PFNGLXDESTROYGLXPBUFFERSGIXPROC)GetFuncAddress("glXDestroyGLXPbufferSGIX");
|
||||
}
|
||||
|
||||
win = XWindow.CreateXWindow(parent, vi);
|
||||
XFree(vi);
|
||||
if (!CreateWindowSurface())
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cInterfaceGLX::Create(cInterfaceBase* main_context)
|
||||
{
|
||||
cInterfaceGLX* glx_context = static_cast<cInterfaceGLX*>(main_context);
|
||||
|
||||
m_has_handle = false;
|
||||
dpy = glx_context->dpy;
|
||||
fbconfig = glx_context->fbconfig;
|
||||
s_glxError = false;
|
||||
XErrorHandler oldHandler = XSetErrorHandler(&ctxErrorHandler);
|
||||
|
||||
ctx = glXCreateContextAttribs(dpy, fbconfig, glx_context->ctx, True, &glx_context->m_attribs[0]);
|
||||
XSync(dpy, False);
|
||||
|
||||
if (!ctx || s_glxError)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Unable to create GL context.");
|
||||
return false;
|
||||
}
|
||||
XSetErrorHandler(oldHandler);
|
||||
|
||||
if (!CreateWindowSurface())
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<cInterfaceBase> cInterfaceGLX::CreateSharedContext()
|
||||
{
|
||||
std::unique_ptr<cInterfaceBase> context = std::make_unique<cInterfaceGLX>();
|
||||
if (!context->Create(this))
|
||||
return nullptr;
|
||||
return context;
|
||||
}
|
||||
|
||||
bool cInterfaceGLX::CreateWindowSurface()
|
||||
{
|
||||
if (m_has_handle)
|
||||
{
|
||||
// Get an appropriate visual
|
||||
XVisualInfo* vi = glXGetVisualFromFBConfig(dpy, fbconfig);
|
||||
|
||||
XWindow.Initialize(dpy);
|
||||
|
||||
XWindowAttributes attribs;
|
||||
if (!XGetWindowAttributes(dpy, m_host_window, &attribs))
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Window attribute retrieval failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
s_backbuffer_width = attribs.width;
|
||||
s_backbuffer_height = attribs.height;
|
||||
|
||||
win = XWindow.CreateXWindow(m_host_window, vi);
|
||||
XFree(vi);
|
||||
}
|
||||
else
|
||||
{
|
||||
win = m_pbuffer = glXCreateGLXPbufferSGIX(dpy, fbconfig, 1, 1, nullptr);
|
||||
if (!m_pbuffer)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void cInterfaceGLX::DestroyWindowSurface()
|
||||
{
|
||||
if (!m_pbuffer)
|
||||
{
|
||||
XWindow.DestroyXWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
glXDestroyGLXPbufferSGIX(dpy, m_pbuffer);
|
||||
m_pbuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool cInterfaceGLX::MakeCurrent()
|
||||
{
|
||||
bool success = glXMakeCurrent(dpy, win, ctx);
|
||||
if (success)
|
||||
if (success && !glXSwapIntervalSGI)
|
||||
{
|
||||
// load this function based on the current bound context
|
||||
glXSwapIntervalSGI =
|
||||
@@ -193,11 +278,18 @@ bool cInterfaceGLX::ClearCurrent()
|
||||
// Close backend
|
||||
void cInterfaceGLX::Shutdown()
|
||||
{
|
||||
XWindow.DestroyXWindow();
|
||||
DestroyWindowSurface();
|
||||
if (ctx)
|
||||
{
|
||||
glXDestroyContext(dpy, ctx);
|
||||
XCloseDisplay(dpy);
|
||||
ctx = nullptr;
|
||||
|
||||
// Don't close the display connection if we are a shared context.
|
||||
// Saves doing reference counting on this object, and the main context will always
|
||||
// be shut down last anyway.
|
||||
if (m_has_handle)
|
||||
{
|
||||
XCloseDisplay(dpy);
|
||||
ctx = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glxext.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/GL/GLInterface/X11_Util.h"
|
||||
#include "Common/GL/GLInterfaceBase.h"
|
||||
@@ -13,11 +16,19 @@
|
||||
class cInterfaceGLX : public cInterfaceBase
|
||||
{
|
||||
private:
|
||||
Window m_host_window;
|
||||
cX11Window XWindow;
|
||||
Display* dpy;
|
||||
Window win;
|
||||
GLXContext ctx;
|
||||
GLXFBConfig fbconfig;
|
||||
bool m_has_handle;
|
||||
bool m_supports_pbuffer = false;
|
||||
GLXPbufferSGIX m_pbuffer = 0;
|
||||
std::vector<int> m_attribs;
|
||||
|
||||
bool CreateWindowSurface();
|
||||
void DestroyWindowSurface();
|
||||
|
||||
public:
|
||||
friend class cX11Window;
|
||||
@@ -25,7 +36,9 @@ public:
|
||||
void Swap() override;
|
||||
void* GetFuncAddress(const std::string& name) override;
|
||||
bool Create(void* window_handle, bool stereo, bool core) override;
|
||||
bool Create(cInterfaceBase* main_context) override;
|
||||
bool MakeCurrent() override;
|
||||
bool ClearCurrent() override;
|
||||
void Shutdown() override;
|
||||
std::unique_ptr<cInterfaceBase> CreateSharedContext() override;
|
||||
};
|
||||
|
||||
@@ -35,6 +35,7 @@ void Host_UpdateMainFrame();
|
||||
void Host_UpdateTitle(const std::string& title);
|
||||
void Host_ShowVideoConfig(void* parent, const std::string& backend_name);
|
||||
void Host_YieldToUI();
|
||||
void Host_UpdateProgressDialog(const char* caption, int position, int total);
|
||||
|
||||
// TODO (neobrain): Remove this from host!
|
||||
void* Host_GetRenderHandle();
|
||||
|
||||
@@ -136,6 +136,10 @@ void Host_YieldToUI()
|
||||
{
|
||||
}
|
||||
|
||||
void Host_UpdateProgressDialog(const char* caption, int position, int total)
|
||||
{
|
||||
}
|
||||
|
||||
#if HAVE_X11
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
@@ -84,6 +84,9 @@ void Host_YieldToUI()
|
||||
{
|
||||
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
void Host_UpdateProgressDialog(const char* caption, int position, int total)
|
||||
{
|
||||
}
|
||||
|
||||
// We ignore these, and their purpose should be questioned individually.
|
||||
// In particular, RequestRenderWindowSize, RequestFullscreen, and
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <wx/menu.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/progdlg.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/statusbr.h>
|
||||
#include <wx/textctrl.h>
|
||||
@@ -817,6 +818,37 @@ void CFrame::OnHostMessage(wxCommandEvent& event)
|
||||
case IDM_STOPPED:
|
||||
OnStopped();
|
||||
break;
|
||||
|
||||
case IDM_UPDATE_PROGRESS_DIALOG:
|
||||
{
|
||||
int current = event.GetInt();
|
||||
int total = static_cast<int>(event.GetExtraLong());
|
||||
if (total < 0 || current >= total)
|
||||
{
|
||||
if (m_progress_dialog)
|
||||
{
|
||||
delete m_progress_dialog;
|
||||
m_progress_dialog = nullptr;
|
||||
}
|
||||
}
|
||||
else if (total > 0 && current < total)
|
||||
{
|
||||
if (!m_progress_dialog)
|
||||
{
|
||||
m_progress_dialog = new wxProgressDialog(
|
||||
_("Operation in progress..."), event.GetString(), total, m_render_frame,
|
||||
wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_SMOOTH | wxPD_REMAINING_TIME);
|
||||
m_progress_dialog->Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_progress_dialog->GetRange() != total)
|
||||
m_progress_dialog->SetRange(total);
|
||||
m_progress_dialog->Update(current, event.GetString());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ class wxAuiNotebook;
|
||||
class wxAuiNotebookEvent;
|
||||
class wxListEvent;
|
||||
class wxMenuItem;
|
||||
class wxProgressDialog;
|
||||
|
||||
class CRenderFrame : public wxFrame
|
||||
{
|
||||
@@ -154,6 +155,7 @@ private:
|
||||
FifoPlayerDlg* m_fifo_player_dialog = nullptr;
|
||||
std::array<TASInputDlg*, 8> m_tas_input_dialogs{};
|
||||
wxCheatsWindow* m_cheats_window = nullptr;
|
||||
wxProgressDialog* m_progress_dialog = nullptr;
|
||||
bool m_use_debugger = false;
|
||||
bool m_batch_mode = false;
|
||||
bool m_editing_perspectives = false;
|
||||
|
||||
@@ -307,6 +307,7 @@ enum
|
||||
IDM_WINDOW_SIZE_REQUEST,
|
||||
IDM_STOPPED,
|
||||
IDM_HOST_MESSAGE,
|
||||
IDM_UPDATE_PROGRESS_DIALOG,
|
||||
|
||||
IDM_MPANEL,
|
||||
ID_STATUSBAR,
|
||||
|
||||
@@ -488,3 +488,12 @@ void Host_YieldToUI()
|
||||
{
|
||||
wxGetApp().GetMainLoop()->YieldFor(wxEVT_CATEGORY_UI);
|
||||
}
|
||||
|
||||
void Host_UpdateProgressDialog(const char* caption, int position, int total)
|
||||
{
|
||||
wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATE_PROGRESS_DIALOG);
|
||||
event.SetString(caption);
|
||||
event.SetInt(position);
|
||||
event.SetExtraLong(total);
|
||||
main_frame->GetEventHandler()->AddPendingEvent(event);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ set(SRCS
|
||||
PostProcessing.cpp
|
||||
RasterFont.cpp
|
||||
Renderer.cpp
|
||||
ShaderCache.cpp
|
||||
ShaderCompiler.cpp
|
||||
StateTracker.cpp
|
||||
StagingBuffer.cpp
|
||||
|
||||
@@ -435,8 +435,8 @@ void FramebufferManager::ReinterpretPixelData(int convtype)
|
||||
|
||||
UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
|
||||
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
|
||||
m_efb_load_render_pass, g_object_cache->GetScreenQuadVertexShader(),
|
||||
g_object_cache->GetScreenQuadGeometryShader(), pixel_shader);
|
||||
m_efb_load_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
|
||||
g_shader_cache->GetScreenQuadGeometryShader(), pixel_shader);
|
||||
|
||||
RasterizationState rs_state = Util::GetNoCullRasterizationState();
|
||||
rs_state.samples = m_efb_samples;
|
||||
@@ -510,8 +510,8 @@ Texture2D* FramebufferManager::ResolveEFBDepthTexture(const VkRect2D& region)
|
||||
// Draw using resolve shader to write the minimum depth of all samples to the resolve texture.
|
||||
UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
|
||||
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
|
||||
m_depth_resolve_render_pass, g_object_cache->GetScreenQuadVertexShader(),
|
||||
g_object_cache->GetScreenQuadGeometryShader(), m_ps_depth_resolve);
|
||||
m_depth_resolve_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
|
||||
g_shader_cache->GetScreenQuadGeometryShader(), m_ps_depth_resolve);
|
||||
draw.BeginRenderPass(m_depth_resolve_framebuffer, region);
|
||||
draw.SetPSSampler(0, m_efb_depth_texture->GetView(), g_object_cache->GetPointSampler());
|
||||
draw.SetViewportAndScissor(region.offset.x, region.offset.y, region.extent.width,
|
||||
@@ -641,7 +641,7 @@ bool FramebufferManager::CompileConversionShaders()
|
||||
}
|
||||
)";
|
||||
|
||||
std::string header = g_object_cache->GetUtilityShaderHeader();
|
||||
std::string header = g_shader_cache->GetUtilityShaderHeader();
|
||||
DestroyConversionShaders();
|
||||
|
||||
m_ps_rgb8_to_rgba6 = Util::CompileAndCreateFragmentShader(header + RGB8_TO_RGBA6_SHADER_SOURCE);
|
||||
@@ -698,7 +698,7 @@ bool FramebufferManager::PopulateColorReadbackTexture()
|
||||
|
||||
UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
|
||||
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
|
||||
m_copy_color_render_pass, g_object_cache->GetScreenQuadVertexShader(),
|
||||
m_copy_color_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
|
||||
VK_NULL_HANDLE, m_copy_color_shader);
|
||||
|
||||
VkRect2D rect = {{0, 0}, {EFB_WIDTH, EFB_HEIGHT}};
|
||||
@@ -781,7 +781,7 @@ bool FramebufferManager::PopulateDepthReadbackTexture()
|
||||
|
||||
UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
|
||||
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
|
||||
m_copy_depth_render_pass, g_object_cache->GetScreenQuadVertexShader(),
|
||||
m_copy_depth_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
|
||||
VK_NULL_HANDLE, m_copy_depth_shader);
|
||||
|
||||
VkRect2D rect = {{0, 0}, {EFB_WIDTH, EFB_HEIGHT}};
|
||||
@@ -956,10 +956,10 @@ bool FramebufferManager::CompileReadbackShaders()
|
||||
}
|
||||
)";
|
||||
|
||||
source = g_object_cache->GetUtilityShaderHeader() + COPY_COLOR_SHADER_SOURCE;
|
||||
source = g_shader_cache->GetUtilityShaderHeader() + COPY_COLOR_SHADER_SOURCE;
|
||||
m_copy_color_shader = Util::CompileAndCreateFragmentShader(source);
|
||||
|
||||
source = g_object_cache->GetUtilityShaderHeader() + COPY_DEPTH_SHADER_SOURCE;
|
||||
source = g_shader_cache->GetUtilityShaderHeader() + COPY_DEPTH_SHADER_SOURCE;
|
||||
m_copy_depth_shader = Util::CompileAndCreateFragmentShader(source);
|
||||
|
||||
return m_copy_color_shader != VK_NULL_HANDLE && m_copy_depth_shader != VK_NULL_HANDLE;
|
||||
@@ -1176,7 +1176,7 @@ void FramebufferManager::DrawPokeVertices(const EFBPokeVertex* vertices, size_t
|
||||
pipeline_info.depth_stencil_state.compare_op = VK_COMPARE_OP_ALWAYS;
|
||||
}
|
||||
|
||||
VkPipeline pipeline = g_object_cache->GetPipeline(pipeline_info);
|
||||
VkPipeline pipeline = g_shader_cache->GetPipeline(pipeline_info);
|
||||
if (pipeline == VK_NULL_HANDLE)
|
||||
{
|
||||
PanicAlert("Failed to get pipeline for EFB poke draw");
|
||||
@@ -1309,7 +1309,7 @@ bool FramebufferManager::CompilePokeShaders()
|
||||
}
|
||||
)";
|
||||
|
||||
std::string source = g_object_cache->GetUtilityShaderHeader();
|
||||
std::string source = g_shader_cache->GetUtilityShaderHeader();
|
||||
if (m_poke_primitive_topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
|
||||
source += "#define USE_POINT_SIZE 1\n";
|
||||
source += POKE_VERTEX_SHADER_SOURCE;
|
||||
@@ -1319,13 +1319,13 @@ bool FramebufferManager::CompilePokeShaders()
|
||||
|
||||
if (g_vulkan_context->SupportsGeometryShaders())
|
||||
{
|
||||
source = g_object_cache->GetUtilityShaderHeader() + POKE_GEOMETRY_SHADER_SOURCE;
|
||||
source = g_shader_cache->GetUtilityShaderHeader() + POKE_GEOMETRY_SHADER_SOURCE;
|
||||
m_poke_geometry_shader = Util::CompileAndCreateGeometryShader(source);
|
||||
if (m_poke_geometry_shader == VK_NULL_HANDLE)
|
||||
return false;
|
||||
}
|
||||
|
||||
source = g_object_cache->GetUtilityShaderHeader() + POKE_PIXEL_SHADER_SOURCE;
|
||||
source = g_shader_cache->GetUtilityShaderHeader() + POKE_PIXEL_SHADER_SOURCE;
|
||||
m_poke_fragment_shader = Util::CompileAndCreateFragmentShader(source);
|
||||
if (m_poke_fragment_shader == VK_NULL_HANDLE)
|
||||
return false;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,52 +27,6 @@ class CommandBufferManager;
|
||||
class VertexFormat;
|
||||
class StreamBuffer;
|
||||
|
||||
struct PipelineInfo
|
||||
{
|
||||
// These are packed in descending order of size, to avoid any padding so that the structure
|
||||
// can be copied/compared as a single block of memory. 64-bit pointer size is assumed.
|
||||
const VertexFormat* vertex_format;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
VkShaderModule vs;
|
||||
VkShaderModule gs;
|
||||
VkShaderModule ps;
|
||||
VkRenderPass render_pass;
|
||||
BlendingState blend_state;
|
||||
RasterizationState rasterization_state;
|
||||
DepthStencilState depth_stencil_state;
|
||||
VkPrimitiveTopology primitive_topology;
|
||||
};
|
||||
|
||||
struct PipelineInfoHash
|
||||
{
|
||||
std::size_t operator()(const PipelineInfo& key) const;
|
||||
};
|
||||
|
||||
bool operator==(const PipelineInfo& lhs, const PipelineInfo& rhs);
|
||||
bool operator!=(const PipelineInfo& lhs, const PipelineInfo& rhs);
|
||||
bool operator<(const PipelineInfo& lhs, const PipelineInfo& rhs);
|
||||
bool operator>(const PipelineInfo& lhs, const PipelineInfo& rhs);
|
||||
bool operator==(const SamplerState& lhs, const SamplerState& rhs);
|
||||
bool operator!=(const SamplerState& lhs, const SamplerState& rhs);
|
||||
bool operator>(const SamplerState& lhs, const SamplerState& rhs);
|
||||
bool operator<(const SamplerState& lhs, const SamplerState& rhs);
|
||||
|
||||
struct ComputePipelineInfo
|
||||
{
|
||||
VkPipelineLayout pipeline_layout;
|
||||
VkShaderModule cs;
|
||||
};
|
||||
|
||||
struct ComputePipelineInfoHash
|
||||
{
|
||||
std::size_t operator()(const ComputePipelineInfo& key) const;
|
||||
};
|
||||
|
||||
bool operator==(const ComputePipelineInfo& lhs, const ComputePipelineInfo& rhs);
|
||||
bool operator!=(const ComputePipelineInfo& lhs, const ComputePipelineInfo& rhs);
|
||||
bool operator<(const ComputePipelineInfo& lhs, const ComputePipelineInfo& rhs);
|
||||
bool operator>(const ComputePipelineInfo& lhs, const ComputePipelineInfo& rhs);
|
||||
|
||||
class ObjectCache
|
||||
{
|
||||
public:
|
||||
@@ -103,14 +57,6 @@ public:
|
||||
return m_utility_shader_uniform_buffer.get();
|
||||
}
|
||||
|
||||
// Get utility shader header based on current config.
|
||||
std::string GetUtilityShaderHeader() const;
|
||||
|
||||
// Accesses ShaderGen shader caches
|
||||
VkShaderModule GetVertexShaderForUid(const VertexShaderUid& uid);
|
||||
VkShaderModule GetGeometryShaderForUid(const GeometryShaderUid& uid);
|
||||
VkShaderModule GetPixelShaderForUid(const PixelShaderUid& uid);
|
||||
|
||||
// Static samplers
|
||||
VkSampler GetPointSampler() const { return m_point_sampler; }
|
||||
VkSampler GetLinearSampler() const { return m_linear_sampler; }
|
||||
@@ -119,64 +65,17 @@ public:
|
||||
// Perform at startup, create descriptor layouts, compiles all static shaders.
|
||||
bool Initialize();
|
||||
|
||||
// Creates a pipeline for the specified description. The resulting pipeline, if successful
|
||||
// is not stored anywhere, this is left up to the caller.
|
||||
VkPipeline CreatePipeline(const PipelineInfo& info);
|
||||
|
||||
// Find a pipeline by the specified description, if not found, attempts to create it.
|
||||
VkPipeline GetPipeline(const PipelineInfo& info);
|
||||
|
||||
// Find a pipeline by the specified description, if not found, attempts to create it. If this
|
||||
// resulted in a pipeline being created, the second field of the return value will be false,
|
||||
// otherwise for a cache hit it will be true.
|
||||
std::pair<VkPipeline, bool> GetPipelineWithCacheResult(const PipelineInfo& info);
|
||||
|
||||
// Creates a compute pipeline, and does not track the handle.
|
||||
VkPipeline CreateComputePipeline(const ComputePipelineInfo& info);
|
||||
|
||||
// Find a pipeline by the specified description, if not found, attempts to create it
|
||||
VkPipeline GetComputePipeline(const ComputePipelineInfo& info);
|
||||
|
||||
// Clears our pipeline cache of all objects. This is necessary when recompiling shaders,
|
||||
// as drivers are free to return the same pointer again, which means that we may end up using
|
||||
// and old pipeline object if they are not cleared first. Some stutter may be experienced
|
||||
// while our cache is rebuilt on use, but the pipeline cache object should mitigate this.
|
||||
// NOTE: Ensure that none of these objects are in use before calling.
|
||||
void ClearPipelineCache();
|
||||
|
||||
// Saves the pipeline cache to disk. Call when shutting down.
|
||||
void SavePipelineCache();
|
||||
|
||||
// Clear sampler cache, use when anisotropy mode changes
|
||||
// WARNING: Ensure none of the objects from here are in use when calling
|
||||
void ClearSamplerCache();
|
||||
|
||||
// Recompile shared shaders, call when stereo mode changes.
|
||||
void RecompileSharedShaders();
|
||||
|
||||
// Reload pipeline cache. This will destroy all pipelines.
|
||||
void ReloadShaderAndPipelineCaches();
|
||||
|
||||
// Shared shader accessors
|
||||
VkShaderModule GetScreenQuadVertexShader() const { return m_screen_quad_vertex_shader; }
|
||||
VkShaderModule GetPassthroughVertexShader() const { return m_passthrough_vertex_shader; }
|
||||
VkShaderModule GetScreenQuadGeometryShader() const { return m_screen_quad_geometry_shader; }
|
||||
VkShaderModule GetPassthroughGeometryShader() const { return m_passthrough_geometry_shader; }
|
||||
private:
|
||||
bool CreatePipelineCache();
|
||||
bool LoadPipelineCache();
|
||||
bool ValidatePipelineCache(const u8* data, size_t data_length);
|
||||
void DestroyPipelineCache();
|
||||
void LoadShaderCaches();
|
||||
void DestroyShaderCaches();
|
||||
bool CreateDescriptorSetLayouts();
|
||||
void DestroyDescriptorSetLayouts();
|
||||
bool CreatePipelineLayouts();
|
||||
void DestroyPipelineLayouts();
|
||||
bool CreateUtilityShaderVertexFormat();
|
||||
bool CreateStaticSamplers();
|
||||
bool CompileSharedShaders();
|
||||
void DestroySharedShaders();
|
||||
void DestroySamplers();
|
||||
|
||||
std::array<VkDescriptorSetLayout, NUM_DESCRIPTOR_SET_LAYOUTS> m_descriptor_set_layouts = {};
|
||||
@@ -186,32 +85,10 @@ private:
|
||||
std::unique_ptr<StreamBuffer> m_utility_shader_vertex_buffer;
|
||||
std::unique_ptr<StreamBuffer> m_utility_shader_uniform_buffer;
|
||||
|
||||
template <typename Uid>
|
||||
struct ShaderCache
|
||||
{
|
||||
std::map<Uid, VkShaderModule> shader_map;
|
||||
LinearDiskCache<Uid, u32> disk_cache;
|
||||
};
|
||||
ShaderCache<VertexShaderUid> m_vs_cache;
|
||||
ShaderCache<GeometryShaderUid> m_gs_cache;
|
||||
ShaderCache<PixelShaderUid> m_ps_cache;
|
||||
|
||||
std::unordered_map<PipelineInfo, VkPipeline, PipelineInfoHash> m_pipeline_objects;
|
||||
std::unordered_map<ComputePipelineInfo, VkPipeline, ComputePipelineInfoHash>
|
||||
m_compute_pipeline_objects;
|
||||
VkPipelineCache m_pipeline_cache = VK_NULL_HANDLE;
|
||||
std::string m_pipeline_cache_filename;
|
||||
|
||||
VkSampler m_point_sampler = VK_NULL_HANDLE;
|
||||
VkSampler m_linear_sampler = VK_NULL_HANDLE;
|
||||
|
||||
std::map<SamplerState, VkSampler> m_sampler_cache;
|
||||
|
||||
// Utility/shared shaders
|
||||
VkShaderModule m_screen_quad_vertex_shader = VK_NULL_HANDLE;
|
||||
VkShaderModule m_passthrough_vertex_shader = VK_NULL_HANDLE;
|
||||
VkShaderModule m_screen_quad_geometry_shader = VK_NULL_HANDLE;
|
||||
VkShaderModule m_passthrough_geometry_shader = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
extern std::unique_ptr<ObjectCache> g_object_cache;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "VideoBackends/Vulkan/CommandBufferManager.h"
|
||||
#include "VideoBackends/Vulkan/ObjectCache.h"
|
||||
#include "VideoBackends/Vulkan/ShaderCache.h"
|
||||
#include "VideoBackends/Vulkan/Texture2D.h"
|
||||
#include "VideoBackends/Vulkan/Util.h"
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
@@ -43,12 +44,12 @@ void VulkanPostProcessing::BlitFromTexture(const TargetRectangle& dst, const Tar
|
||||
{
|
||||
// If the source layer is negative we simply copy all available layers.
|
||||
VkShaderModule geometry_shader =
|
||||
src_layer < 0 ? g_object_cache->GetPassthroughGeometryShader() : VK_NULL_HANDLE;
|
||||
src_layer < 0 ? g_shader_cache->GetPassthroughGeometryShader() : VK_NULL_HANDLE;
|
||||
VkShaderModule fragment_shader =
|
||||
m_fragment_shader != VK_NULL_HANDLE ? m_fragment_shader : m_default_fragment_shader;
|
||||
UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
|
||||
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD), render_pass,
|
||||
g_object_cache->GetPassthroughVertexShader(), geometry_shader,
|
||||
g_shader_cache->GetPassthroughVertexShader(), geometry_shader,
|
||||
fragment_shader);
|
||||
|
||||
// Source is always bound.
|
||||
@@ -240,7 +241,7 @@ bool VulkanPostProcessing::RecompileShader()
|
||||
if (m_fragment_shader != VK_NULL_HANDLE)
|
||||
{
|
||||
g_command_buffer_mgr->WaitForGPUIdle();
|
||||
g_object_cache->ClearPipelineCache();
|
||||
g_shader_cache->ClearPipelineCache();
|
||||
vkDestroyShaderModule(g_vulkan_context->GetDevice(), m_fragment_shader, nullptr);
|
||||
m_fragment_shader = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user