2013-11-04 18:15:51 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Keith Packard
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Portions of this code were adapted from dri2_glx.c which carries the
|
|
|
|
|
* following copyright:
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2008 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Soft-
|
|
|
|
|
* ware"), to deal in the Software without restriction, including without
|
|
|
|
|
* limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, provided that the above copyright
|
|
|
|
|
* notice(s) and this permission notice appear in all copies of the Soft-
|
|
|
|
|
* ware and that both the above copyright notice(s) and this permission
|
|
|
|
|
* notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
|
|
|
|
|
* ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
|
|
|
|
|
* RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
|
|
|
|
|
* THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
|
|
|
|
|
* QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
|
|
|
|
|
* MANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Except as contained in this notice, the name of a copyright holder shall
|
|
|
|
|
* not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
|
* other dealings in this Software without prior written authorization of
|
|
|
|
|
* the copyright holder.
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* Kristian Høgsberg (krh@redhat.com)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
|
#include <X11/xshmfence.h>
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
#include <xcb/dri3.h>
|
|
|
|
|
#include <xcb/present.h>
|
|
|
|
|
#include <GL/gl.h>
|
|
|
|
|
#include "glxclient.h"
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
|
|
#include "dri_common.h"
|
|
|
|
|
#include "dri3_priv.h"
|
2014-01-11 02:24:43 +00:00
|
|
|
#include "loader.h"
|
2024-07-19 13:03:47 -04:00
|
|
|
#include "loader_x11.h"
|
2022-07-11 12:01:27 -07:00
|
|
|
#include "loader_dri_helper.h"
|
2024-03-12 14:59:55 -04:00
|
|
|
#include "util/u_debug.h"
|
2024-07-22 10:14:27 -04:00
|
|
|
#include "dri_util.h"
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
static struct dri3_drawable *
|
|
|
|
|
loader_drawable_to_dri3_drawable(struct loader_dri3_drawable *draw) {
|
|
|
|
|
size_t offset = offsetof(struct dri3_drawable, loader_drawable);
|
2017-01-27 11:58:41 +01:00
|
|
|
if (!draw)
|
|
|
|
|
return NULL;
|
2015-07-21 23:43:55 +08:00
|
|
|
return (struct dri3_drawable *)(((void*) draw) - offset);
|
|
|
|
|
}
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
static void
|
|
|
|
|
glx_dri3_set_drawable_size(struct loader_dri3_drawable *draw,
|
|
|
|
|
int width, int height)
|
2013-11-04 18:15:51 -08:00
|
|
|
{
|
2015-07-21 23:43:55 +08:00
|
|
|
/* Nothing to do */
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
static bool
|
|
|
|
|
glx_dri3_in_current_context(struct loader_dri3_drawable *draw)
|
2013-11-04 18:15:51 -08:00
|
|
|
{
|
2015-07-21 23:43:55 +08:00
|
|
|
struct dri3_drawable *priv = loader_drawable_to_dri3_drawable(draw);
|
2017-02-02 18:01:06 +01:00
|
|
|
|
|
|
|
|
if (!priv)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-08-02 13:19:44 -04:00
|
|
|
struct glx_context *pcp = __glXGetCurrentContext();
|
2015-07-21 23:43:55 +08:00
|
|
|
struct dri3_screen *psc = (struct dri3_screen *) priv->base.psc;
|
|
|
|
|
|
2022-08-02 13:19:44 -04:00
|
|
|
return (pcp != &dummyContext) && pcp->psc == &psc->base;
|
2015-07-21 23:43:55 +08:00
|
|
|
}
|
|
|
|
|
|
2024-10-21 01:47:24 -04:00
|
|
|
static struct dri_context *
|
2015-07-21 23:43:55 +08:00
|
|
|
glx_dri3_get_dri_context(struct loader_dri3_drawable *draw)
|
|
|
|
|
{
|
|
|
|
|
struct glx_context *gc = __glXGetCurrentContext();
|
|
|
|
|
|
2022-08-02 13:19:44 -04:00
|
|
|
return (gc != &dummyContext) ? gc->driContext : NULL;
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
2024-10-21 01:47:24 -04:00
|
|
|
static struct dri_screen *
|
2018-02-09 09:37:19 +01:00
|
|
|
glx_dri3_get_dri_screen(void)
|
|
|
|
|
{
|
|
|
|
|
struct glx_context *gc = __glXGetCurrentContext();
|
2022-08-02 13:19:44 -04:00
|
|
|
struct dri3_screen *psc = (struct dri3_screen *) gc->psc;
|
2018-02-09 09:37:19 +01:00
|
|
|
|
2024-08-01 15:44:35 -04:00
|
|
|
return (gc != &dummyContext && psc) ? psc->base.frontend_screen : NULL;
|
2018-02-09 09:37:19 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
static void
|
|
|
|
|
glx_dri3_flush_drawable(struct loader_dri3_drawable *draw, unsigned flags)
|
|
|
|
|
{
|
|
|
|
|
loader_dri3_flush(draw, flags, __DRI2_THROTTLE_SWAPBUFFER);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 11:08:30 +01:00
|
|
|
static const struct loader_dri3_vtable glx_dri3_vtable = {
|
2015-07-21 23:43:55 +08:00
|
|
|
.set_drawable_size = glx_dri3_set_drawable_size,
|
|
|
|
|
.in_current_context = glx_dri3_in_current_context,
|
|
|
|
|
.get_dri_context = glx_dri3_get_dri_context,
|
2018-02-09 09:37:19 +01:00
|
|
|
.get_dri_screen = glx_dri3_get_dri_screen,
|
2015-07-21 23:43:55 +08:00
|
|
|
.flush_drawable = glx_dri3_flush_drawable,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct glx_context_vtable dri3_context_vtable;
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
static void
|
|
|
|
|
dri3_destroy_drawable(__GLXDRIdrawable *base)
|
|
|
|
|
{
|
|
|
|
|
struct dri3_drawable *pdraw = (struct dri3_drawable *) base;
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
loader_dri3_drawable_fini(&pdraw->loader_drawable);
|
2013-11-21 21:30:07 -08:00
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
free(pdraw);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-12 10:25:11 +08:00
|
|
|
static enum loader_dri3_drawable_type
|
|
|
|
|
glx_to_loader_dri3_drawable_type(int type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case GLX_WINDOW_BIT:
|
|
|
|
|
return LOADER_DRI3_DRAWABLE_WINDOW;
|
|
|
|
|
case GLX_PIXMAP_BIT:
|
|
|
|
|
return LOADER_DRI3_DRAWABLE_PIXMAP;
|
|
|
|
|
case GLX_PBUFFER_BIT:
|
|
|
|
|
return LOADER_DRI3_DRAWABLE_PBUFFER;
|
|
|
|
|
default:
|
|
|
|
|
return LOADER_DRI3_DRAWABLE_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
static __GLXDRIdrawable *
|
|
|
|
|
dri3_create_drawable(struct glx_screen *base, XID xDrawable,
|
2021-11-09 17:19:44 +08:00
|
|
|
GLXDrawable drawable, int type,
|
|
|
|
|
struct glx_config *config_base)
|
2013-11-04 18:15:51 -08:00
|
|
|
{
|
|
|
|
|
struct dri3_drawable *pdraw;
|
|
|
|
|
struct dri3_screen *psc = (struct dri3_screen *) base;
|
|
|
|
|
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
|
2017-07-07 02:54:26 -04:00
|
|
|
bool has_multibuffer = false;
|
2013-11-04 18:15:51 -08:00
|
|
|
|
|
|
|
|
pdraw = calloc(1, sizeof(*pdraw));
|
|
|
|
|
if (!pdraw)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
pdraw->base.destroyDrawable = dri3_destroy_drawable;
|
|
|
|
|
pdraw->base.xDrawable = xDrawable;
|
|
|
|
|
pdraw->base.drawable = drawable;
|
|
|
|
|
pdraw->base.psc = &psc->base;
|
2014-01-26 16:14:29 -08:00
|
|
|
|
2024-07-25 13:36:55 -04:00
|
|
|
has_multibuffer = base->display->has_multibuffer;
|
2017-07-07 02:54:26 -04:00
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
(void) __glXInitialize(psc->base.dpy);
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
if (loader_dri3_drawable_init(XGetXCBConnection(base->dpy),
|
2021-11-12 10:25:11 +08:00
|
|
|
xDrawable,
|
|
|
|
|
glx_to_loader_dri3_drawable_type(type),
|
2024-08-01 15:44:35 -04:00
|
|
|
psc->base.frontend_screen, psc->driScreenDisplayGPU,
|
2022-12-17 23:57:50 +05:30
|
|
|
has_multibuffer,
|
2021-09-14 10:57:39 +02:00
|
|
|
psc->prefer_back_buffer_reuse,
|
2017-07-07 02:54:26 -04:00
|
|
|
config->driConfig,
|
2024-07-26 09:03:29 -04:00
|
|
|
&glx_dri3_vtable,
|
2015-07-21 23:43:55 +08:00
|
|
|
&pdraw->loader_drawable)) {
|
2013-11-04 18:15:51 -08:00
|
|
|
free(pdraw);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-01 10:42:33 -04:00
|
|
|
pdraw->base.dri_drawable = pdraw->loader_drawable.dri_drawable;
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
return &pdraw->base;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 21:21:40 -08:00
|
|
|
/** dri3_wait_for_msc
|
|
|
|
|
*
|
|
|
|
|
* Get the X server to send an event when the target msc/divisor/remainder is
|
|
|
|
|
* reached.
|
|
|
|
|
*/
|
2013-11-04 18:15:51 -08:00
|
|
|
static int
|
|
|
|
|
dri3_wait_for_msc(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
|
|
|
|
|
int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
|
|
|
|
|
{
|
|
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
loader_dri3_wait_for_msc(&priv->loader_drawable, target_msc, divisor,
|
|
|
|
|
remainder, ust, msc, sbc);
|
2013-11-04 18:15:51 -08:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 21:21:40 -08:00
|
|
|
/** dri3_drawable_get_msc
|
|
|
|
|
*
|
|
|
|
|
* Return the current UST/MSC/SBC triplet by asking the server
|
|
|
|
|
* for an event
|
|
|
|
|
*/
|
2013-11-04 18:15:51 -08:00
|
|
|
static int
|
|
|
|
|
dri3_drawable_get_msc(struct glx_screen *psc, __GLXDRIdrawable *pdraw,
|
|
|
|
|
int64_t *ust, int64_t *msc, int64_t *sbc)
|
|
|
|
|
{
|
|
|
|
|
return dri3_wait_for_msc(pdraw, 0, 0, 0, ust, msc,sbc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** dri3_wait_for_sbc
|
|
|
|
|
*
|
2013-11-25 21:21:40 -08:00
|
|
|
* Wait for the completed swap buffer count to reach the specified
|
|
|
|
|
* target. Presumably the application knows that this will be reached with
|
|
|
|
|
* outstanding complete events, or we're going to be here awhile.
|
2013-11-04 18:15:51 -08:00
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
dri3_wait_for_sbc(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
|
|
|
|
|
int64_t *msc, int64_t *sbc)
|
|
|
|
|
{
|
|
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
return loader_dri3_wait_for_sbc(&priv->loader_drawable, target_sbc,
|
|
|
|
|
ust, msc, sbc);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dri3_copy_sub_buffer(__GLXDRIdrawable *pdraw, int x, int y,
|
|
|
|
|
int width, int height,
|
|
|
|
|
Bool flush)
|
|
|
|
|
{
|
|
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
loader_dri3_copy_sub_buffer(&priv->loader_drawable, x, y,
|
|
|
|
|
width, height, flush);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dri3_wait_x(struct glx_context *gc)
|
|
|
|
|
{
|
|
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *)
|
2021-05-03 08:38:02 -04:00
|
|
|
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2015-12-19 15:29:14 -05:00
|
|
|
if (priv)
|
|
|
|
|
loader_dri3_wait_x(&priv->loader_drawable);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dri3_wait_gl(struct glx_context *gc)
|
|
|
|
|
{
|
|
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *)
|
2021-05-03 08:38:02 -04:00
|
|
|
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
|
2014-05-17 12:12:11 -04:00
|
|
|
|
2015-12-19 15:29:14 -05:00
|
|
|
if (priv)
|
|
|
|
|
loader_dri3_wait_gl(&priv->loader_drawable);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called by the driver when it needs to update the real front buffer with the
|
|
|
|
|
* contents of its fake front buffer.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2024-10-21 01:47:24 -04:00
|
|
|
dri3_flush_front_buffer(struct dri_drawable *driDrawable, void *loaderPrivate)
|
2013-11-04 18:15:51 -08:00
|
|
|
{
|
2015-07-21 23:43:55 +08:00
|
|
|
struct loader_dri3_drawable *draw = loaderPrivate;
|
|
|
|
|
struct dri3_drawable *pdraw = loader_drawable_to_dri3_drawable(draw);
|
2013-11-04 18:15:51 -08:00
|
|
|
struct dri3_screen *psc;
|
|
|
|
|
|
|
|
|
|
if (!pdraw)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!pdraw->base.psc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
psc = (struct dri3_screen *) pdraw->base.psc;
|
|
|
|
|
|
|
|
|
|
(void) __glXInitialize(psc->base.dpy);
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
loader_dri3_flush(draw, __DRI2_FLUSH_DRAWABLE, __DRI2_THROTTLE_FLUSHFRONT);
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2024-07-25 11:53:59 -04:00
|
|
|
dri_invalidate_drawable(driDrawable);
|
2015-07-21 23:43:55 +08:00
|
|
|
loader_dri3_wait_gl(draw);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
2017-08-02 13:53:54 +02:00
|
|
|
/**
|
|
|
|
|
* Make sure all pending swapbuffers have been submitted to hardware
|
|
|
|
|
*
|
|
|
|
|
* \param driDrawable[in] Pointer to the dri drawable whose swaps we are
|
|
|
|
|
* flushing.
|
|
|
|
|
* \param loaderPrivate[in] Pointer to the corresponding struct
|
|
|
|
|
* loader_dri_drawable.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2024-10-21 01:47:24 -04:00
|
|
|
dri3_flush_swap_buffers(struct dri_drawable *driDrawable, void *loaderPrivate)
|
2017-08-02 13:53:54 +02:00
|
|
|
{
|
|
|
|
|
struct loader_dri3_drawable *draw = loaderPrivate;
|
|
|
|
|
struct dri3_drawable *pdraw = loader_drawable_to_dri3_drawable(draw);
|
|
|
|
|
struct dri3_screen *psc;
|
|
|
|
|
|
|
|
|
|
if (!pdraw)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!pdraw->base.psc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
psc = (struct dri3_screen *) pdraw->base.psc;
|
|
|
|
|
|
|
|
|
|
(void) __glXInitialize(psc->base.dpy);
|
|
|
|
|
loader_dri3_swapbuffer_barrier(draw);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-14 15:50:27 -08:00
|
|
|
static void
|
|
|
|
|
dri_set_background_context(void *loaderPrivate)
|
|
|
|
|
{
|
2022-08-02 13:19:44 -04:00
|
|
|
__glXSetCurrentContext(loaderPrivate);
|
2012-11-14 15:50:27 -08:00
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:18:26 +02:00
|
|
|
static GLboolean
|
|
|
|
|
dri_is_thread_safe(void *loaderPrivate)
|
|
|
|
|
{
|
|
|
|
|
/* Unlike DRI2, DRI3 doesn't call GetBuffers/GetBuffersWithFormat
|
|
|
|
|
* during draw so we're safe here.
|
|
|
|
|
*/
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
/* The image loader extension record for DRI3
|
|
|
|
|
*/
|
|
|
|
|
static const __DRIimageLoaderExtension imageLoaderExtension = {
|
2017-08-02 13:53:54 +02:00
|
|
|
.base = { __DRI_IMAGE_LOADER, 3 },
|
2014-02-12 18:46:32 +00:00
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
.getBuffers = loader_dri3_get_buffers,
|
2014-02-12 18:46:32 +00:00
|
|
|
.flushFrontBuffer = dri3_flush_front_buffer,
|
2017-08-02 13:53:54 +02:00
|
|
|
.flushSwapBuffers = dri3_flush_swap_buffers,
|
2013-11-04 18:15:51 -08:00
|
|
|
};
|
|
|
|
|
|
2024-06-28 10:45:29 -04:00
|
|
|
static const __DRIbackgroundCallableExtension dri3BackgroundCallable = {
|
2017-05-29 13:18:26 +02:00
|
|
|
.base = { __DRI_BACKGROUND_CALLABLE, 2 },
|
2012-11-14 15:50:27 -08:00
|
|
|
|
|
|
|
|
.setBackgroundContext = dri_set_background_context,
|
2017-05-29 13:18:26 +02:00
|
|
|
.isThreadSafe = dri_is_thread_safe,
|
2012-11-14 15:50:27 -08:00
|
|
|
};
|
|
|
|
|
|
2014-03-16 01:17:46 +00:00
|
|
|
static const __DRIextension *loader_extensions[] = {
|
|
|
|
|
&imageLoaderExtension.base,
|
2024-06-28 10:45:29 -04:00
|
|
|
&dri3BackgroundCallable.base,
|
2014-03-16 01:17:46 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
/** dri3_swap_buffers
|
|
|
|
|
*
|
|
|
|
|
* Make the current back buffer visible using the present extension
|
|
|
|
|
*/
|
|
|
|
|
static int64_t
|
|
|
|
|
dri3_swap_buffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
|
|
|
|
|
int64_t remainder, Bool flush)
|
|
|
|
|
{
|
|
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
|
|
|
|
unsigned flags = __DRI2_FLUSH_DRAWABLE;
|
2015-07-21 23:43:55 +08:00
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
if (flush)
|
|
|
|
|
flags |= __DRI2_FLUSH_CONTEXT;
|
|
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
return loader_dri3_swap_buffers_msc(&priv->loader_drawable,
|
|
|
|
|
target_msc, divisor, remainder,
|
2020-05-23 01:45:42 +02:00
|
|
|
flags, NULL, 0, false);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
2024-08-01 10:06:04 -04:00
|
|
|
int
|
|
|
|
|
dri3_get_buffer_age(__GLXDRIdrawable *pdraw);
|
|
|
|
|
int
|
2014-02-24 20:44:42 +01:00
|
|
|
dri3_get_buffer_age(__GLXDRIdrawable *pdraw)
|
|
|
|
|
{
|
2015-07-21 23:43:55 +08:00
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *)pdraw;
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
return loader_dri3_query_buffer_age(&priv->loader_drawable);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** dri3_destroy_screen
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2024-08-01 12:49:07 -04:00
|
|
|
dri3_deinit_screen(struct glx_screen *base)
|
2013-11-04 18:15:51 -08:00
|
|
|
{
|
|
|
|
|
struct dri3_screen *psc = (struct dri3_screen *) base;
|
|
|
|
|
|
|
|
|
|
/* Free the direct rendering per screen data */
|
2023-01-23 16:36:48 +05:30
|
|
|
if (psc->fd_render_gpu != psc->fd_display_gpu && psc->driScreenDisplayGPU) {
|
|
|
|
|
loader_dri3_close_screen(psc->driScreenDisplayGPU);
|
2024-07-22 10:44:15 -04:00
|
|
|
driDestroyScreen(psc->driScreenDisplayGPU);
|
2021-05-03 23:22:28 +05:30
|
|
|
}
|
2023-01-23 16:36:48 +05:30
|
|
|
if (psc->fd_render_gpu != psc->fd_display_gpu)
|
|
|
|
|
close(psc->fd_display_gpu);
|
2024-08-01 15:44:35 -04:00
|
|
|
loader_dri3_close_screen(psc->base.frontend_screen);
|
2023-01-23 16:34:40 +05:30
|
|
|
close(psc->fd_render_gpu);
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** dri3_set_swap_interval
|
|
|
|
|
*
|
|
|
|
|
* Record the application swap interval specification,
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
dri3_set_swap_interval(__GLXDRIdrawable *pdraw, int interval)
|
|
|
|
|
{
|
2017-02-02 18:06:27 +01:00
|
|
|
assert(pdraw != NULL);
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
|
|
|
|
struct dri3_screen *psc = (struct dri3_screen *) priv->base.psc;
|
|
|
|
|
|
2024-08-01 15:44:35 -04:00
|
|
|
if (!dri_valid_swap_interval(psc->base.frontend_screen, interval))
|
2022-07-11 12:01:27 -07:00
|
|
|
return GLX_BAD_VALUE;
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2015-07-21 23:43:55 +08:00
|
|
|
loader_dri3_set_swap_interval(&priv->loader_drawable, interval);
|
2013-11-04 18:15:51 -08:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** dri3_get_swap_interval
|
|
|
|
|
*
|
|
|
|
|
* Return the stored swap interval
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
dri3_get_swap_interval(__GLXDRIdrawable *pdraw)
|
|
|
|
|
{
|
2017-02-02 18:06:27 +01:00
|
|
|
assert(pdraw != NULL);
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
|
|
|
|
|
|
2019-03-29 10:16:05 -07:00
|
|
|
return priv->loader_drawable.swap_interval;
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct glx_context_vtable dri3_context_vtable = {
|
2024-08-01 11:15:00 -04:00
|
|
|
.destroy = dri_destroy_context,
|
2024-08-01 11:10:44 -04:00
|
|
|
.bind = dri_bind_context,
|
2024-08-01 11:13:28 -04:00
|
|
|
.unbind = dri_unbind_context,
|
2014-02-18 19:26:27 +00:00
|
|
|
.wait_gl = dri3_wait_gl,
|
|
|
|
|
.wait_x = dri3_wait_x,
|
2013-11-04 18:15:51 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** dri3_create_screen
|
|
|
|
|
*
|
|
|
|
|
* Initialize DRI3 on the specified screen.
|
|
|
|
|
*
|
|
|
|
|
* Opens the DRI device, locates the appropriate DRI driver
|
|
|
|
|
* and loads that.
|
|
|
|
|
*
|
|
|
|
|
* Checks to see if the driver supports the necessary extensions
|
|
|
|
|
*
|
|
|
|
|
* Initializes the driver for the screen and sets up our structures
|
|
|
|
|
*/
|
|
|
|
|
|
2024-07-19 07:39:41 -04:00
|
|
|
struct glx_screen *
|
2024-07-19 10:17:07 -04:00
|
|
|
dri3_create_screen(int screen, struct glx_display * priv, bool driver_name_is_inferred, bool *return_zink)
|
2013-11-04 18:15:51 -08:00
|
|
|
{
|
2013-11-07 15:44:57 -08:00
|
|
|
xcb_connection_t *c = XGetXCBConnection(priv->dpy);
|
2024-10-21 02:19:46 -04:00
|
|
|
const struct dri_config **driver_configs;
|
2013-11-04 18:15:51 -08:00
|
|
|
struct dri3_screen *psc;
|
|
|
|
|
__GLXDRIscreen *psp;
|
2024-08-01 15:47:48 -04:00
|
|
|
char *driverName, *driverNameDisplayGPU;
|
2024-07-19 10:17:07 -04:00
|
|
|
*return_zink = false;
|
2013-11-04 18:15:51 -08:00
|
|
|
|
|
|
|
|
psc = calloc(1, sizeof *psc);
|
|
|
|
|
if (psc == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2021-05-03 22:57:07 +05:30
|
|
|
psc->fd_display_gpu = -1;
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2024-07-19 13:03:47 -04:00
|
|
|
psc->fd_render_gpu = x11_dri3_open(c, RootWindow(priv->dpy, screen), None);
|
2023-01-23 16:34:40 +05:30
|
|
|
if (psc->fd_render_gpu < 0) {
|
2013-11-07 15:44:57 -08:00
|
|
|
int conn_error = xcb_connection_has_error(c);
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
glx_screen_cleanup(&psc->base);
|
|
|
|
|
free(psc);
|
|
|
|
|
InfoMessageF("screen %d does not appear to be DRI3 capable\n", screen);
|
2013-11-07 15:44:57 -08:00
|
|
|
|
|
|
|
|
if (conn_error)
|
|
|
|
|
ErrorMessageF("Connection closed during DRI3 initialization failure");
|
|
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-05-17 12:12:11 -04:00
|
|
|
|
2023-01-23 16:36:48 +05:30
|
|
|
loader_get_user_preferred_fd(&psc->fd_render_gpu, &psc->fd_display_gpu);
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2023-01-23 16:34:40 +05:30
|
|
|
driverName = loader_get_driver_for_fd(psc->fd_render_gpu);
|
2013-11-04 18:15:51 -08:00
|
|
|
if (!driverName) {
|
|
|
|
|
ErrorMessageF("No driver found\n");
|
|
|
|
|
goto handle_error;
|
|
|
|
|
}
|
2024-07-30 14:00:56 -04:00
|
|
|
psc->base.driverName = driverName;
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2024-03-12 14:59:55 -04:00
|
|
|
if (!strcmp(driverName, "zink") && !debug_get_bool_option("LIBGL_KOPPER_DISABLE", false)) {
|
2024-07-19 10:17:07 -04:00
|
|
|
*return_zink = true;
|
2024-02-20 13:10:29 +10:00
|
|
|
goto handle_error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 16:36:48 +05:30
|
|
|
if (psc->fd_render_gpu != psc->fd_display_gpu) {
|
2021-05-03 23:22:28 +05:30
|
|
|
driverNameDisplayGPU = loader_get_driver_for_fd(psc->fd_display_gpu);
|
|
|
|
|
if (driverNameDisplayGPU) {
|
|
|
|
|
|
|
|
|
|
/* check if driver name is matching so that non mesa drivers
|
|
|
|
|
* will not crash. Also need this check since image extension
|
|
|
|
|
* pointer from render gpu is shared with display gpu. Image
|
|
|
|
|
* extension pointer is shared because it keeps things simple.
|
|
|
|
|
*/
|
|
|
|
|
if (strcmp(driverName, driverNameDisplayGPU) == 0) {
|
2024-07-22 10:14:27 -04:00
|
|
|
psc->driScreenDisplayGPU = driCreateNewScreen3(screen, psc->fd_display_gpu,
|
|
|
|
|
loader_extensions,
|
2024-07-30 15:02:10 -04:00
|
|
|
DRI_SCREEN_DRI3,
|
2024-08-01 08:35:13 -04:00
|
|
|
&driver_configs, driver_name_is_inferred,
|
|
|
|
|
priv->has_multibuffer, psc);
|
2021-05-03 23:22:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(driverNameDisplayGPU);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-01 16:45:10 -04:00
|
|
|
priv->driver = GLX_DRIVER_DRI3;
|
2021-05-03 23:22:28 +05:30
|
|
|
|
2024-08-01 16:45:10 -04:00
|
|
|
if (!dri_screen_init(&psc->base, priv, screen, psc->fd_render_gpu, loader_extensions, driver_name_is_inferred)) {
|
2022-03-20 08:01:24 +08:00
|
|
|
ErrorMessageF("glx: failed to create dri3 screen\n");
|
2013-11-04 18:15:51 -08:00
|
|
|
goto handle_error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 16:36:48 +05:30
|
|
|
if (psc->fd_render_gpu == psc->fd_display_gpu)
|
2024-08-01 15:44:35 -04:00
|
|
|
psc->driScreenDisplayGPU = psc->base.frontend_screen;
|
2023-01-23 16:36:48 +05:30
|
|
|
|
2021-08-06 17:53:38 -04:00
|
|
|
psc->base.context_vtable = &dri3_context_vtable;
|
2024-08-01 16:19:40 -04:00
|
|
|
psp = &psc->base.driScreen;
|
2024-08-01 12:49:07 -04:00
|
|
|
psp->deinitScreen = dri3_deinit_screen;
|
2013-11-04 18:15:51 -08:00
|
|
|
psp->createDrawable = dri3_create_drawable;
|
|
|
|
|
psp->swapBuffers = dri3_swap_buffers;
|
|
|
|
|
|
|
|
|
|
psp->getDrawableMSC = dri3_drawable_get_msc;
|
|
|
|
|
psp->waitForMSC = dri3_wait_for_msc;
|
|
|
|
|
psp->waitForSBC = dri3_wait_for_sbc;
|
|
|
|
|
psp->setSwapInterval = dri3_set_swap_interval;
|
|
|
|
|
psp->getSwapInterval = dri3_get_swap_interval;
|
2022-04-28 17:19:13 -04:00
|
|
|
psp->maxSwapInterval = INT_MAX;
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2024-07-30 14:27:38 -04:00
|
|
|
/* when on a different gpu than the server, the server pixmaps
|
|
|
|
|
* can have a tiling mode we can't read. Thus we can't create
|
|
|
|
|
* a texture from them.
|
|
|
|
|
*/
|
|
|
|
|
psc->base.can_EXT_texture_from_pixmap = psc->fd_render_gpu == psc->fd_display_gpu;
|
2013-11-04 18:15:51 -08:00
|
|
|
psp->copySubBuffer = dri3_copy_sub_buffer;
|
|
|
|
|
|
2015-05-06 13:31:30 +03:00
|
|
|
InfoMessageF("Using DRI3 for screen %d\n", screen);
|
|
|
|
|
|
2021-09-14 10:57:39 +02:00
|
|
|
psc->prefer_back_buffer_reuse = 1;
|
2024-07-25 10:23:21 -04:00
|
|
|
if (psc->fd_render_gpu != psc->fd_display_gpu) {
|
2021-09-14 10:57:39 +02:00
|
|
|
unsigned value;
|
2024-08-01 15:44:35 -04:00
|
|
|
if (dri_query_renderer_integer(psc->base.frontend_screen,
|
2024-07-25 10:23:21 -04:00
|
|
|
__DRI2_RENDERER_PREFER_BACK_BUFFER_REUSE,
|
|
|
|
|
&value) == 0)
|
2021-09-14 10:57:39 +02:00
|
|
|
psc->prefer_back_buffer_reuse = value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-19 09:57:07 -04:00
|
|
|
|
2013-11-04 18:15:51 -08:00
|
|
|
return &psc->base;
|
|
|
|
|
|
|
|
|
|
handle_error:
|
2024-07-19 10:17:07 -04:00
|
|
|
if (!*return_zink)
|
2024-02-20 13:10:29 +10:00
|
|
|
CriticalErrorMessageF("failed to load driver: %s\n", driverName ? driverName : "(null)");
|
2013-11-04 18:15:51 -08:00
|
|
|
|
2023-01-23 16:36:48 +05:30
|
|
|
if (psc->fd_render_gpu != psc->fd_display_gpu && psc->driScreenDisplayGPU)
|
2024-07-22 10:44:15 -04:00
|
|
|
driDestroyScreen(psc->driScreenDisplayGPU);
|
2021-05-03 23:22:28 +05:30
|
|
|
psc->driScreenDisplayGPU = NULL;
|
2023-01-23 16:36:48 +05:30
|
|
|
if (psc->fd_display_gpu >= 0 && psc->fd_render_gpu != psc->fd_display_gpu)
|
|
|
|
|
close(psc->fd_display_gpu);
|
2023-01-23 16:34:40 +05:30
|
|
|
if (psc->fd_render_gpu >= 0)
|
|
|
|
|
close(psc->fd_render_gpu);
|
2013-11-04 18:15:51 -08:00
|
|
|
|
|
|
|
|
glx_screen_cleanup(&psc->base);
|
|
|
|
|
free(psc);
|
|
|
|
|
|
2024-07-19 10:17:07 -04:00
|
|
|
return NULL;
|
2013-11-04 18:15:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* GLX_DIRECT_RENDERING */
|