mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Fix for crash on Linux.
This commit is contained in:
parent
26b0bc771d
commit
d1a74e1b96
@ -1651,12 +1651,6 @@ static bool vulkan_context_init_gpu(gfx_ctx_vulkan_data_t *vk)
|
||||
|
||||
video_driver_set_gpu_api_devices(GFX_CTX_VULKAN_API, vulkan_gpu_list);
|
||||
|
||||
if (vk->context.gpu != VK_NULL_HANDLE)
|
||||
{
|
||||
free(gpus);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (0 <= settings->ints.vulkan_gpu_index && settings->ints.vulkan_gpu_index < (int)gpu_count)
|
||||
{
|
||||
RARCH_LOG("[Vulkan]: Using GPU index %d.\n", settings->ints.vulkan_gpu_index);
|
||||
@ -1908,11 +1902,8 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vk->context.queue == VK_NULL_HANDLE)
|
||||
{
|
||||
vkGetDeviceQueue(vk->context.device,
|
||||
vk->context.graphics_queue_index, 0, &vk->context.queue);
|
||||
}
|
||||
vkGetDeviceQueue(vk->context.device,
|
||||
vk->context.graphics_queue_index, 0, &vk->context.queue);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
vk->context.queue_lock = slock_new();
|
||||
@ -2677,13 +2668,17 @@ void vulkan_context_destroy(gfx_ctx_vulkan_data_t *vk,
|
||||
else
|
||||
{
|
||||
if (vk->context.device)
|
||||
{
|
||||
vkDestroyDevice(vk->context.device, NULL);
|
||||
vk->context.device = NULL;
|
||||
}
|
||||
if (vk->context.instance)
|
||||
{
|
||||
if (vk->context.destroy_device)
|
||||
vk->context.destroy_device();
|
||||
|
||||
vkDestroyInstance(vk->context.instance, NULL);
|
||||
vk->context.instance = NULL;
|
||||
|
||||
if (vulkan_library)
|
||||
{
|
||||
|
@ -64,9 +64,9 @@ typedef Bool (*GLXGETMSCRATEOMLPROC)(Display *dpy, GLXDrawable drawable, int3
|
||||
int32_t *denominator);
|
||||
typedef int64_t (*GLXSWAPBUFFERSMSCOMLPROC)(Display *dpy, GLXDrawable drawable,
|
||||
int64_t target_msc, int64_t divisor,
|
||||
int64_t remainder);
|
||||
int64_t g_remainder);
|
||||
typedef Bool (*GLXWAITFORMSCOMLPROC)(Display *dpy, GLXDrawable drawable, int64_t target_msc,
|
||||
int64_t divisor, int64_t remainder, int64_t *ust,
|
||||
int64_t divisor, int64_t g_remainder, int64_t *ust,
|
||||
int64_t *msc, int64_t *sbc);
|
||||
typedef Bool (*GLXWAITFORSBCOMLPROC)(Display *dpy, GLXDrawable drawable, int64_t target_sbc,
|
||||
int64_t *ust, int64_t *msc, int64_t *sbc);
|
||||
@ -76,38 +76,34 @@ static GLXGETMSCRATEOMLPROC glXGetMscRateOML;
|
||||
static GLXSWAPBUFFERSMSCOMLPROC glXSwapBuffersMscOML;
|
||||
static GLXWAITFORMSCOMLPROC glXWaitForMscOML;
|
||||
static GLXWAITFORSBCOMLPROC glXWaitForSbcOML;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct gfx_ctx_x_data
|
||||
{
|
||||
int64_t ust;
|
||||
int64_t msc;
|
||||
int64_t sbc;
|
||||
static int64_t ust;
|
||||
static int64_t msc;
|
||||
static int64_t sbc;
|
||||
|
||||
int divisor;
|
||||
int remainder;
|
||||
bool g_use_hw_ctx;
|
||||
bool g_core_es;
|
||||
bool g_core_es_core;
|
||||
bool g_debug;
|
||||
bool g_should_reset_mode;
|
||||
bool g_is_double;
|
||||
bool core_hw_context_enable;
|
||||
static int divisor;
|
||||
static int g_remainder;
|
||||
static bool g_use_hw_ctx;
|
||||
static bool g_core_es;
|
||||
static bool g_core_es_core;
|
||||
static bool g_debug;
|
||||
static bool g_should_reset_mode;
|
||||
static bool g_is_double;
|
||||
static bool core_hw_context_enable;
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
GLXWindow g_glx_win;
|
||||
GLXContext g_ctx, g_hw_ctx;
|
||||
GLXFBConfig g_fbc;
|
||||
unsigned swap_mode;
|
||||
static GLXWindow g_glx_win;
|
||||
static GLXContext g_ctx, g_hw_ctx;
|
||||
static GLXFBConfig g_fbc;
|
||||
static unsigned swap_mode;
|
||||
#endif
|
||||
|
||||
int g_interval;
|
||||
static int g_interval;
|
||||
|
||||
#ifdef HAVE_VULKAN
|
||||
gfx_ctx_vulkan_data_t vk;
|
||||
static gfx_ctx_vulkan_data_t x_vk;
|
||||
#endif
|
||||
} gfx_ctx_x_data_t;
|
||||
|
||||
static bool x_adaptive_vsync = false;
|
||||
static bool x_enable_msaa = false;
|
||||
@ -115,8 +111,6 @@ static unsigned g_major = 0;
|
||||
static unsigned g_minor = 0;
|
||||
static enum gfx_ctx_api x_api = GFX_CTX_NONE;
|
||||
|
||||
static gfx_ctx_x_data_t *current_context_data = NULL;
|
||||
|
||||
typedef struct Hints
|
||||
{
|
||||
unsigned long flags;
|
||||
@ -176,6 +170,11 @@ static int GLXExtensionSupported(Display *dpy, const char *extension)
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct gfx_ctx_cgl_data
|
||||
{
|
||||
void *empty;
|
||||
} gfx_ctx_x_data_t;
|
||||
|
||||
static int x_log_error_handler(Display *dpy, XErrorEvent *event)
|
||||
{
|
||||
char buf[1024];
|
||||
@ -192,60 +191,58 @@ static int x_nul_handler(Display *dpy, XErrorEvent *event)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gfx_ctx_x_destroy_resources(gfx_ctx_x_data_t *x)
|
||||
static void gfx_ctx_x_destroy(void *data)
|
||||
{
|
||||
x11_input_ctx_destroy();
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t *)data;
|
||||
|
||||
if (g_x11_dpy)
|
||||
switch (x_api)
|
||||
{
|
||||
switch (x_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
case GFX_CTX_OPENGL_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
if (x->g_ctx)
|
||||
if (g_ctx)
|
||||
{
|
||||
if (x->swap_mode)
|
||||
glXSwapBuffersMscOML(g_x11_dpy, x->g_glx_win, 0, x->divisor, x->remainder);
|
||||
if (swap_mode)
|
||||
glXSwapBuffersMscOML(g_x11_dpy, g_glx_win, 0, divisor, g_remainder);
|
||||
else
|
||||
glXSwapBuffers(g_x11_dpy, x->g_glx_win);
|
||||
glXSwapBuffers(g_x11_dpy, g_glx_win);
|
||||
|
||||
glFinish();
|
||||
glXMakeContextCurrent(g_x11_dpy, None, None, NULL);
|
||||
|
||||
if (!video_driver_is_video_cache_context())
|
||||
{
|
||||
if (x->g_hw_ctx)
|
||||
glXDestroyContext(g_x11_dpy, x->g_hw_ctx);
|
||||
if (x->g_ctx)
|
||||
glXDestroyContext(g_x11_dpy, x->g_ctx);
|
||||
if (g_hw_ctx)
|
||||
glXDestroyContext(g_x11_dpy, g_hw_ctx);
|
||||
if (g_ctx)
|
||||
glXDestroyContext(g_x11_dpy, g_ctx);
|
||||
|
||||
x->g_ctx = NULL;
|
||||
x->g_hw_ctx = NULL;
|
||||
g_ctx = NULL;
|
||||
g_hw_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_x11_win)
|
||||
{
|
||||
if (x->g_glx_win)
|
||||
glXDestroyWindow(g_x11_dpy, x->g_glx_win);
|
||||
x->g_glx_win = 0;
|
||||
if (g_glx_win)
|
||||
glXDestroyWindow(g_x11_dpy, g_glx_win);
|
||||
g_glx_win = 0;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case GFX_CTX_VULKAN_API:
|
||||
break;
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
vulkan_context_destroy(&x->vk, g_x11_win != 0);
|
||||
vulkan_context_destroy(&x_vk, g_x11_win != 0);
|
||||
#ifdef HAVE_THREADS
|
||||
if (x_vk.context.queue_lock)
|
||||
slock_free(x_vk.context.queue_lock);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (g_x11_win && g_x11_dpy)
|
||||
{
|
||||
#ifdef HAVE_XINERAMA
|
||||
@ -259,10 +256,10 @@ static void gfx_ctx_x_destroy_resources(gfx_ctx_x_data_t *x)
|
||||
|
||||
if (g_x11_dpy)
|
||||
{
|
||||
if (x->g_should_reset_mode)
|
||||
if (g_should_reset_mode)
|
||||
{
|
||||
x11_exit_fullscreen(g_x11_dpy);
|
||||
x->g_should_reset_mode = false;
|
||||
g_should_reset_mode = false;
|
||||
}
|
||||
|
||||
if (!video_driver_is_video_cache_context())
|
||||
@ -271,6 +268,9 @@ static void gfx_ctx_x_destroy_resources(gfx_ctx_x_data_t *x)
|
||||
g_x11_dpy = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (x)
|
||||
free(x);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
g_pglSwapInterval = NULL;
|
||||
@ -279,59 +279,35 @@ static void gfx_ctx_x_destroy_resources(gfx_ctx_x_data_t *x)
|
||||
#endif
|
||||
g_major = 0;
|
||||
g_minor = 0;
|
||||
x->g_core_es = false;
|
||||
}
|
||||
|
||||
static void gfx_ctx_x_destroy(void *data)
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
if (!x)
|
||||
return;
|
||||
|
||||
gfx_ctx_x_destroy_resources(x);
|
||||
|
||||
switch (x_api)
|
||||
{
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#if defined(HAVE_VULKAN) && defined(HAVE_THREADS)
|
||||
if (x->vk.context.queue_lock)
|
||||
slock_free(x->vk.context.queue_lock);
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free(data);
|
||||
g_core_es = false;
|
||||
}
|
||||
|
||||
static void gfx_ctx_x_swap_interval(void *data, int interval)
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
(void)data;
|
||||
|
||||
switch (x_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
x->g_interval = interval;
|
||||
g_interval = interval;
|
||||
|
||||
if (g_pglSwapIntervalEXT)
|
||||
{
|
||||
RARCH_LOG("[GLX]: glXSwapIntervalEXT(%i)\n", x->g_interval);
|
||||
g_pglSwapIntervalEXT(g_x11_dpy, x->g_glx_win, x->g_interval);
|
||||
RARCH_LOG("[GLX]: glXSwapIntervalEXT(%i)\n", g_interval);
|
||||
g_pglSwapIntervalEXT(g_x11_dpy, g_glx_win, g_interval);
|
||||
}
|
||||
else if (g_pglSwapInterval)
|
||||
{
|
||||
RARCH_LOG("[GLX]: glXSwapInterval(%i)\n", x->g_interval);
|
||||
if (g_pglSwapInterval(x->g_interval) != 0)
|
||||
RARCH_LOG("[GLX]: glXSwapInterval(%i)\n", g_interval);
|
||||
if (g_pglSwapInterval(g_interval) != 0)
|
||||
RARCH_WARN("[GLX]: glXSwapInterval() failed.\n");
|
||||
}
|
||||
else if (g_pglSwapIntervalSGI)
|
||||
{
|
||||
RARCH_LOG("[GLX]: glXSwapIntervalSGI(%i)\n", x->g_interval);
|
||||
if (g_pglSwapIntervalSGI(x->g_interval) != 0)
|
||||
RARCH_LOG("[GLX]: glXSwapIntervalSGI(%i)\n", g_interval);
|
||||
if (g_pglSwapIntervalSGI(g_interval) != 0)
|
||||
RARCH_WARN("[GLX]: glXSwapIntervalSGI() failed.\n");
|
||||
}
|
||||
#endif
|
||||
@ -339,11 +315,11 @@ static void gfx_ctx_x_swap_interval(void *data, int interval)
|
||||
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
if (x->g_interval != interval)
|
||||
if (g_interval != interval)
|
||||
{
|
||||
x->g_interval = interval;
|
||||
if (x->vk.swapchain)
|
||||
x->vk.need_new_swapchain = true;
|
||||
g_interval = interval;
|
||||
if (x_vk.swapchain)
|
||||
x_vk.need_new_swapchain = true;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
@ -356,39 +332,36 @@ static void gfx_ctx_x_swap_interval(void *data, int interval)
|
||||
|
||||
static void gfx_ctx_x_swap_buffers(void *data, void *data2)
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
(void)data;
|
||||
|
||||
switch (x_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
if (x->swap_mode)
|
||||
if (swap_mode)
|
||||
{
|
||||
if (x->g_interval)
|
||||
if (g_interval)
|
||||
{
|
||||
glXWaitForMscOML(g_x11_dpy, x->g_glx_win, x->msc + x->g_interval,
|
||||
0, 0, &x->ust, &x->msc, &x->sbc);
|
||||
glXSwapBuffersMscOML(g_x11_dpy, x->g_glx_win, 0, 0, 0);
|
||||
glXWaitForMscOML(g_x11_dpy, g_glx_win, msc + g_interval,
|
||||
0, 0, &ust, &msc, &sbc);
|
||||
glXSwapBuffersMscOML(g_x11_dpy, g_glx_win, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
glXSwapBuffersMscOML(g_x11_dpy, x->g_glx_win, 0, x->divisor, x->remainder);
|
||||
#if 0
|
||||
RARCH_LOG("UST: %d, MSC: %d, SBC: %d\n", x->ust, x->msc, x->sbc);
|
||||
#endif
|
||||
glXSwapBuffersMscOML(g_x11_dpy, g_glx_win, 0, divisor, g_remainder);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x->g_is_double)
|
||||
glXSwapBuffers(g_x11_dpy, x->g_glx_win);
|
||||
if (g_is_double)
|
||||
glXSwapBuffers(g_x11_dpy, g_glx_win);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
vulkan_present(&x->vk, x->vk.context.current_swapchain_index);
|
||||
vulkan_acquire_next_image(&x->vk);
|
||||
vulkan_present(&x_vk, x_vk.context.current_swapchain_index);
|
||||
vulkan_acquire_next_image(&x_vk);
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -402,6 +375,7 @@ static void gfx_ctx_x_check_window(void *data, bool *quit,
|
||||
bool *resize, unsigned *width, unsigned *height,
|
||||
bool is_shutdown)
|
||||
{
|
||||
(void)data;
|
||||
x11_check_window(data, quit, resize, width, height,
|
||||
is_shutdown);
|
||||
|
||||
@ -410,8 +384,7 @@ static void gfx_ctx_x_check_window(void *data, bool *quit,
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
if (x->vk.need_new_swapchain)
|
||||
if (x_vk.need_new_swapchain)
|
||||
*resize = true;
|
||||
}
|
||||
#endif
|
||||
@ -434,23 +407,16 @@ static bool gfx_ctx_x_set_resize(void *data,
|
||||
{
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
if (!vulkan_create_swapchain(&x_vk, width, height, g_interval))
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
|
||||
/* FIXME/TODO - threading error here */
|
||||
|
||||
if (!vulkan_create_swapchain(&x->vk, width, height, x->g_interval))
|
||||
{
|
||||
RARCH_ERR("[X/Vulkan]: Failed to update swapchain.\n");
|
||||
x->vk.swapchain = VK_NULL_HANDLE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x->vk.created_new_swapchain)
|
||||
vulkan_acquire_next_image(&x->vk);
|
||||
x->vk.context.invalid_swapchain = true;
|
||||
x->vk.need_new_swapchain = false;
|
||||
RARCH_ERR("[X/Vulkan]: Failed to update swapchain.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x_vk.created_new_swapchain)
|
||||
vulkan_acquire_next_image(&x_vk);
|
||||
x_vk.context.invalid_swapchain = true;
|
||||
x_vk.need_new_swapchain = false;
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -494,10 +460,8 @@ static void *gfx_ctx_x_init(video_frame_info_t *video_info, void *data)
|
||||
if (!x)
|
||||
return NULL;
|
||||
|
||||
current_context_data = x;
|
||||
|
||||
XInitThreads();
|
||||
|
||||
|
||||
if (!x11_connect())
|
||||
goto error;
|
||||
|
||||
@ -506,6 +470,7 @@ static void *gfx_ctx_x_init(video_frame_info_t *video_info, void *data)
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGLES) || defined(HAVE_OPENGL_CORE)
|
||||
RARCH_LOG("[TEST] GFX_CTX_OPENGL_API\n");
|
||||
glXQueryVersion(g_x11_dpy, &major, &minor);
|
||||
|
||||
/* GLX 1.3+ minimum required. */
|
||||
@ -516,28 +481,32 @@ static void *gfx_ctx_x_init(video_frame_info_t *video_info, void *data)
|
||||
glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
|
||||
|
||||
#ifdef GL_DEBUG
|
||||
x->g_debug = true;
|
||||
g_debug = true;
|
||||
#else
|
||||
x->g_debug = hwr->debug_context;
|
||||
g_debug = hwr->debug_context;
|
||||
#endif
|
||||
|
||||
/* Have to use ContextAttribs */
|
||||
#ifdef HAVE_OPENGLES2
|
||||
x->g_core_es = true;
|
||||
x->g_core_es_core = true;
|
||||
g_core_es = true;
|
||||
g_core_es_core = true;
|
||||
#else
|
||||
x->g_core_es = (g_major * 1000 + g_minor) >= 3001;
|
||||
x->g_core_es_core = (g_major * 1000 + g_minor) >= 3002;
|
||||
g_core_es = (g_major * 1000 + g_minor) >= 3001;
|
||||
g_core_es_core = (g_major * 1000 + g_minor) >= 3002;
|
||||
#endif
|
||||
|
||||
if ((x->g_core_es || x->g_debug) && !glx_create_context_attribs)
|
||||
if ((g_core_es || g_debug) && !glx_create_context_attribs)
|
||||
goto error;
|
||||
|
||||
fbcs = glXChooseFBConfig(g_x11_dpy, DefaultScreen(g_x11_dpy),
|
||||
visual_attribs, &nelements);
|
||||
|
||||
|
||||
RARCH_LOG("[TEST] fbcs\n");
|
||||
|
||||
if (!fbcs)
|
||||
goto error;
|
||||
|
||||
RARCH_LOG("[TEST] nelements\n");
|
||||
|
||||
if (!nelements)
|
||||
{
|
||||
@ -545,15 +514,17 @@ static void *gfx_ctx_x_init(video_frame_info_t *video_info, void *data)
|
||||
goto error;
|
||||
}
|
||||
|
||||
x->g_fbc = fbcs[0];
|
||||
g_fbc = fbcs[0];
|
||||
XFree(fbcs);
|
||||
#endif
|
||||
break;
|
||||
case GFX_CTX_VULKAN_API:
|
||||
#ifdef HAVE_VULKAN
|
||||
RARCH_LOG("[TEST] GFX_CTX_VULKAN_API\n");
|
||||
/* Use XCB WSI since it's the most supported WSI over legacy Xlib. */
|
||||
if (!vulkan_context_init(&x->vk, VULKAN_WSI_XCB))
|
||||
if (!vulkan_context_init(&x_vk, VULKAN_WSI_XCB))
|
||||
goto error;
|
||||
RARCH_LOG("[TEST] vulkan_context_init success (vk->context: 0x%08X\n", x_vk.context);
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -577,7 +548,7 @@ static void *gfx_ctx_x_init(video_frame_info_t *video_info, void *data)
|
||||
{
|
||||
RARCH_LOG("[GLX]: GLX_OML_sync_control and GLX_MESA_swap_control supported, using better swap control method...\n");
|
||||
|
||||
x->swap_mode = 1;
|
||||
swap_mode = 1;
|
||||
|
||||
glXGetSyncValuesOML = (GLXGETSYNCVALUESOMLPROC)glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML");
|
||||
glXGetMscRateOML = (GLXGETMSCRATEOMLPROC)glXGetProcAddress((unsigned char *)"glXGetMscRateOML");
|
||||
@ -585,10 +556,10 @@ static void *gfx_ctx_x_init(video_frame_info_t *video_info, void *data)
|
||||
glXWaitForMscOML = (GLXWAITFORMSCOMLPROC)glXGetProcAddress((unsigned char *)"glXWaitForMscOML");
|
||||
glXWaitForSbcOML = (GLXWAITFORSBCOMLPROC)glXGetProcAddress((unsigned char *)"glXWaitForSbcOML");
|
||||
|
||||
glXGetSyncValuesOML(g_x11_dpy, g_x11_win, &x->ust, &x->msc, &x->sbc);
|
||||
glXGetSyncValuesOML(g_x11_dpy, g_x11_win, &ust, &msc, &sbc);
|
||||
|
||||
#if 0
|
||||
RARCH_LOG("[GLX]: UST: %d, MSC: %d, SBC: %d\n", x->ust, x->msc, x->sbc);
|
||||
RARCH_LOG("[GLX]: UST: %d, MSC: %d, SBC: %d\n", ust, msc, sbc);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -602,7 +573,6 @@ static void *gfx_ctx_x_init(video_frame_info_t *video_info, void *data)
|
||||
error:
|
||||
if (x)
|
||||
{
|
||||
gfx_ctx_x_destroy_resources(x);
|
||||
free(x);
|
||||
}
|
||||
g_x11_screen = 0;
|
||||
@ -644,7 +614,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
vi = glXGetVisualFromFBConfig(g_x11_dpy, x->g_fbc);
|
||||
vi = glXGetVisualFromFBConfig(g_x11_dpy, g_fbc);
|
||||
if (!vi)
|
||||
goto error;
|
||||
#endif
|
||||
@ -677,7 +647,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
{
|
||||
if (x11_enter_fullscreen(video_info, g_x11_dpy, width, height))
|
||||
{
|
||||
x->g_should_reset_mode = true;
|
||||
g_should_reset_mode = true;
|
||||
true_full = true;
|
||||
}
|
||||
else
|
||||
@ -767,7 +737,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
x->g_glx_win = glXCreateWindow(g_x11_dpy, x->g_fbc, g_x11_win, 0);
|
||||
g_glx_win = glXCreateWindow(g_x11_dpy, g_fbc, g_x11_win, 0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -821,21 +791,21 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
if (!x->g_ctx)
|
||||
if (!g_ctx)
|
||||
{
|
||||
if (x->g_core_es || x->g_debug)
|
||||
if (g_core_es || g_debug)
|
||||
{
|
||||
int attribs[16] = {0};
|
||||
int *aptr = attribs;
|
||||
|
||||
if (x->g_core_es)
|
||||
if (g_core_es)
|
||||
{
|
||||
*aptr++ = GLX_CONTEXT_MAJOR_VERSION_ARB;
|
||||
*aptr++ = g_major;
|
||||
*aptr++ = GLX_CONTEXT_MINOR_VERSION_ARB;
|
||||
*aptr++ = g_minor;
|
||||
|
||||
if (x->g_core_es_core)
|
||||
if (g_core_es_core)
|
||||
{
|
||||
/* Technically, we don't have core/compat until 3.2.
|
||||
* Version 3.1 is either compat or not depending on
|
||||
@ -850,7 +820,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
}
|
||||
}
|
||||
|
||||
if (x->g_debug)
|
||||
if (g_debug)
|
||||
{
|
||||
*aptr++ = GLX_CONTEXT_FLAGS_ARB;
|
||||
*aptr++ = GLX_CONTEXT_DEBUG_BIT_ARB;
|
||||
@ -895,28 +865,28 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
* The following code can hopefully be removed in the future:
|
||||
*/
|
||||
RARCH_LOG("[GLX]: Creating context for requested version %u.%u.\n", g_major, g_minor);
|
||||
x->g_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
x->g_fbc, NULL, True, attribs);
|
||||
g_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
g_fbc, NULL, True, attribs);
|
||||
|
||||
if (x->g_ctx)
|
||||
if (g_ctx)
|
||||
{
|
||||
const char *version;
|
||||
|
||||
if (x->g_use_hw_ctx)
|
||||
if (g_use_hw_ctx)
|
||||
{
|
||||
RARCH_LOG("[GLX]: Creating shared HW context.\n");
|
||||
x->g_hw_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
x->g_fbc, x->g_ctx, True, attribs);
|
||||
g_hw_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
g_fbc, g_ctx, True, attribs);
|
||||
|
||||
if (!x->g_hw_ctx)
|
||||
if (!g_hw_ctx)
|
||||
RARCH_ERR("[GLX]: Failed to create new shared context.\n");
|
||||
}
|
||||
|
||||
glXMakeContextCurrent(g_x11_dpy,
|
||||
x->g_glx_win, x->g_glx_win, x->g_ctx);
|
||||
g_glx_win, g_glx_win, g_ctx);
|
||||
|
||||
version = (const char*)glGetString(GL_VERSION);
|
||||
if (strstr(version, " Mesa ") != NULL || !x->g_core_es)
|
||||
if (strstr(version, " Mesa ") != NULL || !g_core_es)
|
||||
{
|
||||
/* we are done, break switch case */
|
||||
XSetErrorHandler(old_handler);
|
||||
@ -924,7 +894,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
}
|
||||
|
||||
glXMakeContextCurrent(g_x11_dpy, None, None, NULL);
|
||||
glXDestroyContext(g_x11_dpy, x->g_ctx);
|
||||
glXDestroyContext(g_x11_dpy, g_ctx);
|
||||
|
||||
RARCH_LOG("[GLX]: Not running Mesa, trying higher versions...\n");
|
||||
}
|
||||
@ -935,14 +905,14 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
}
|
||||
/* end of Mesa workaround / code to be removed */
|
||||
|
||||
/* only try higher versions when x->g_core_es is true */
|
||||
if (!x->g_core_es)
|
||||
/* only try higher versions when g_core_es is true */
|
||||
if (!g_core_es)
|
||||
version_rows = 1;
|
||||
|
||||
/* try versions from highest down to requested version */
|
||||
for (i = 0; i < version_rows; i++)
|
||||
{
|
||||
if (x->g_core_es)
|
||||
if (g_core_es)
|
||||
{
|
||||
attribs[1] = versions[i][0];
|
||||
attribs[3] = versions[i][1];
|
||||
@ -951,18 +921,18 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
else
|
||||
RARCH_LOG("[GLX]: Creating context for version %u.%u.\n", g_major, g_minor);
|
||||
|
||||
x->g_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
x->g_fbc, NULL, True, attribs);
|
||||
g_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
g_fbc, NULL, True, attribs);
|
||||
|
||||
if (x->g_ctx)
|
||||
if (g_ctx)
|
||||
{
|
||||
if (x->g_use_hw_ctx)
|
||||
if (g_use_hw_ctx)
|
||||
{
|
||||
RARCH_LOG("[GLX]: Creating shared HW context.\n");
|
||||
x->g_hw_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
x->g_fbc, x->g_ctx, True, attribs);
|
||||
g_hw_ctx = glx_create_context_attribs(g_x11_dpy,
|
||||
g_fbc, g_ctx, True, attribs);
|
||||
|
||||
if (!x->g_hw_ctx)
|
||||
if (!g_hw_ctx)
|
||||
RARCH_ERR("[GLX]: Failed to create new shared context.\n");
|
||||
}
|
||||
|
||||
@ -980,21 +950,21 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
}
|
||||
else
|
||||
{
|
||||
x->g_ctx = glXCreateNewContext(g_x11_dpy, x->g_fbc,
|
||||
g_ctx = glXCreateNewContext(g_x11_dpy, g_fbc,
|
||||
GLX_RGBA_TYPE, 0, True);
|
||||
|
||||
if (x->g_use_hw_ctx)
|
||||
if (g_use_hw_ctx)
|
||||
{
|
||||
RARCH_LOG("[GLX]: Creating shared HW context.\n");
|
||||
x->g_hw_ctx = glXCreateNewContext(g_x11_dpy, x->g_fbc,
|
||||
GLX_RGBA_TYPE, x->g_ctx, True);
|
||||
g_hw_ctx = glXCreateNewContext(g_x11_dpy, g_fbc,
|
||||
GLX_RGBA_TYPE, g_ctx, True);
|
||||
|
||||
if (!x->g_hw_ctx)
|
||||
if (!g_hw_ctx)
|
||||
RARCH_ERR("[GLX]: Failed to create new shared context.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!x->g_ctx)
|
||||
if (!g_ctx)
|
||||
{
|
||||
RARCH_ERR("[GLX]: Failed to create new context.\n");
|
||||
goto error;
|
||||
@ -1007,7 +977,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
}
|
||||
|
||||
glXMakeContextCurrent(g_x11_dpy,
|
||||
x->g_glx_win, x->g_glx_win, x->g_ctx);
|
||||
g_glx_win, g_glx_win, g_ctx);
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -1024,9 +994,9 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
|
||||
/* Use XCB surface since it's the most supported WSI.
|
||||
* We can obtain the XCB connection directly from X11. */
|
||||
if (!vulkan_surface_create(&x->vk, VULKAN_WSI_XCB,
|
||||
if (!vulkan_surface_create(&x_vk, VULKAN_WSI_XCB,
|
||||
g_x11_dpy, &g_x11_win,
|
||||
width, height, x->g_interval))
|
||||
width, height, g_interval))
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
@ -1047,9 +1017,9 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
glXGetConfig(g_x11_dpy, vi, GLX_DOUBLEBUFFER, &val);
|
||||
x->g_is_double = val;
|
||||
g_is_double = val;
|
||||
|
||||
if (x->g_is_double)
|
||||
if (g_is_double)
|
||||
{
|
||||
const char *swap_func = NULL;
|
||||
|
||||
@ -1082,7 +1052,7 @@ static bool gfx_ctx_x_set_video_mode(void *data,
|
||||
break;
|
||||
}
|
||||
|
||||
gfx_ctx_x_swap_interval(data, x->g_interval);
|
||||
gfx_ctx_x_swap_interval(data, g_interval);
|
||||
|
||||
/* This can blow up on some drivers.
|
||||
* It's not fatal, so override errors for this call. */
|
||||
@ -1103,8 +1073,6 @@ error:
|
||||
if (vi)
|
||||
XFree(vi);
|
||||
|
||||
gfx_ctx_x_destroy_resources(x);
|
||||
|
||||
if (x)
|
||||
free(x);
|
||||
g_x11_screen = 0;
|
||||
@ -1228,21 +1196,18 @@ static void gfx_ctx_x_show_mouse(void *data, bool state)
|
||||
|
||||
static void gfx_ctx_x_bind_hw_render(void *data, bool enable)
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
|
||||
if (!x)
|
||||
return;
|
||||
(void)data;
|
||||
|
||||
switch (x_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
|
||||
x->g_use_hw_ctx = enable;
|
||||
if (!g_x11_dpy || !x->g_glx_win)
|
||||
g_use_hw_ctx = enable;
|
||||
if (!g_x11_dpy || !g_glx_win)
|
||||
return;
|
||||
glXMakeContextCurrent(g_x11_dpy, x->g_glx_win,
|
||||
x->g_glx_win, enable ? x->g_hw_ctx : x->g_ctx);
|
||||
glXMakeContextCurrent(g_x11_dpy, g_glx_win,
|
||||
g_glx_win, enable ? g_hw_ctx : g_ctx);
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -1255,15 +1220,15 @@ static void gfx_ctx_x_bind_hw_render(void *data, bool enable)
|
||||
#ifdef HAVE_VULKAN
|
||||
static void *gfx_ctx_x_get_context_data(void *data)
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
return &x->vk.context;
|
||||
(void)data;
|
||||
return &x_vk.context;
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint32_t gfx_ctx_x_get_flags(void *data)
|
||||
{
|
||||
uint32_t flags = 0;
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
(void)data;
|
||||
|
||||
switch (x_api)
|
||||
{
|
||||
@ -1272,7 +1237,7 @@ static uint32_t gfx_ctx_x_get_flags(void *data)
|
||||
if (x_adaptive_vsync)
|
||||
BIT32_SET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC);
|
||||
|
||||
if (x->core_hw_context_enable || x->g_core_es)
|
||||
if (core_hw_context_enable || g_core_es)
|
||||
BIT32_SET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT);
|
||||
|
||||
if (x_enable_msaa)
|
||||
@ -1288,7 +1253,7 @@ static uint32_t gfx_ctx_x_get_flags(void *data)
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_CG
|
||||
if (!(x->core_hw_context_enable || x->g_core_es))
|
||||
if (!(core_hw_context_enable || g_core_es))
|
||||
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_CG);
|
||||
#endif
|
||||
#ifdef HAVE_GLSL
|
||||
@ -1311,7 +1276,7 @@ static uint32_t gfx_ctx_x_get_flags(void *data)
|
||||
|
||||
static void gfx_ctx_x_set_flags(void *data, uint32_t flags)
|
||||
{
|
||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||
(void)data;
|
||||
|
||||
switch (x_api)
|
||||
{
|
||||
@ -1320,7 +1285,7 @@ static void gfx_ctx_x_set_flags(void *data, uint32_t flags)
|
||||
if (BIT32_GET(flags, GFX_CTX_FLAGS_ADAPTIVE_VSYNC))
|
||||
x_adaptive_vsync = true;
|
||||
if (BIT32_GET(flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT))
|
||||
x->core_hw_context_enable = true;
|
||||
core_hw_context_enable = true;
|
||||
if (BIT32_GET(flags, GFX_CTX_FLAGS_MULTISAMPLING))
|
||||
x_enable_msaa = true;
|
||||
break;
|
||||
@ -1332,9 +1297,6 @@ static void gfx_ctx_x_set_flags(void *data, uint32_t flags)
|
||||
|
||||
static void gfx_ctx_x_make_current(bool release)
|
||||
{
|
||||
if (!current_context_data)
|
||||
return;
|
||||
|
||||
switch (x_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_API:
|
||||
@ -1343,9 +1305,7 @@ static void gfx_ctx_x_make_current(bool release)
|
||||
if (release)
|
||||
glXMakeContextCurrent(g_x11_dpy, None, None, NULL);
|
||||
else
|
||||
glXMakeContextCurrent(g_x11_dpy,
|
||||
current_context_data->g_glx_win,
|
||||
current_context_data->g_glx_win, current_context_data->g_ctx);
|
||||
glXMakeContextCurrent(g_x11_dpy, g_glx_win, g_glx_win, g_ctx);
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user