mirror of
https://gitee.com/openharmony/third_party_mesa3d
synced 2024-11-24 16:00:56 +00:00
Add DRI3+Present loader
Uses the __DRIimage loader interfaces. v2: Fix _XIOErrors when DRI3 isn't present (change by anholt). Apparently XCB just terminates your connection if you don't check for extensions before using them, instead of returning an error like you'd expect. Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Kristian Høgsberg <krh@bitplanet.net> Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
parent
442442026e
commit
2d94601582
12
configure.ac
12
configure.ac
@ -34,6 +34,9 @@ LIBDRM_NVVIEUX_REQUIRED=2.4.33
|
||||
LIBDRM_NOUVEAU_REQUIRED="2.4.33 libdrm >= 2.4.41"
|
||||
LIBDRM_FREEDRENO_REQUIRED=2.4.39
|
||||
DRI2PROTO_REQUIRED=2.6
|
||||
DRI3PROTO_REQUIRED=1.0
|
||||
PRESENTPROTO_REQUIRED=1.0
|
||||
LIBUDEV_REQUIRED=151
|
||||
GLPROTO_REQUIRED=1.4.14
|
||||
|
||||
dnl Check for progs
|
||||
@ -808,10 +811,13 @@ xyesno)
|
||||
fi
|
||||
PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED])
|
||||
GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV libdrm >= $LIBDRM_REQUIRED"
|
||||
PKG_CHECK_MODULES([DRI3PROTO], [dri3proto >= $DRI3PROTO_REQUIRED])
|
||||
PKG_CHECK_MODULES([PRESENTPROTO], [presentproto >= $PRESENTPROTO_REQUIRED])
|
||||
PKG_CHECK_MODULES([LIBUDEV], [libudev >= $LIBUDEV_REQUIRED])
|
||||
fi
|
||||
|
||||
# find the DRI deps for libGL
|
||||
dri_modules="x11 xext xdamage xfixes x11-xcb xcb-glx >= 1.8.1 xcb-dri2 >= 1.8"
|
||||
dri_modules="x11 xext xdamage xfixes x11-xcb xcb-glx >= 1.8.1 xcb-dri2 >= 1.8 xcb-dri3 xcb-present xcb-sync xshmfence"
|
||||
|
||||
# add xf86vidmode if available
|
||||
PKG_CHECK_MODULES([XF86VIDMODE], [xxf86vm], HAVE_XF86VIDMODE=yes, HAVE_XF86VIDMODE=no)
|
||||
@ -821,8 +827,8 @@ xyesno)
|
||||
|
||||
PKG_CHECK_MODULES([DRIGL], [$dri_modules])
|
||||
GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules"
|
||||
X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS"
|
||||
GL_LIB_DEPS="$DRIGL_LIBS"
|
||||
X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS $LIBUDEV_CFLAGS"
|
||||
GL_LIB_DEPS="$DRIGL_LIBS $LIBUDEV_LIBS"
|
||||
|
||||
# need DRM libs, $PTHREAD_LIBS, etc.
|
||||
GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
|
||||
|
@ -94,6 +94,8 @@ libglx_la_SOURCES = \
|
||||
dri2_glx.c \
|
||||
dri2.c \
|
||||
dri2_query_renderer.c \
|
||||
dri3_glx.c \
|
||||
dri3_common.c \
|
||||
applegl_glx.c
|
||||
|
||||
GL_LIBS = \
|
||||
|
146
src/glx/dri3_common.c
Normal file
146
src/glx/dri3_common.c
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is derived from src/egl/drivers/dri2/common.c which
|
||||
* carries the following copyright:
|
||||
*
|
||||
* Copyright © 2011 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Kristian Høgsberg <krh@bitplanet.net>
|
||||
* Benjamin Franzke <benjaminfranzke@googlemail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <GL/gl.h>
|
||||
#include "glapi.h"
|
||||
#include "glxclient.h"
|
||||
#include "xf86dri.h"
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
#include "xf86drm.h"
|
||||
#include "dri_common.h"
|
||||
#include "dri3_priv.h"
|
||||
|
||||
#define DRIVER_MAP_DRI3_ONLY
|
||||
#include "pci_ids/pci_id_driver_map.h"
|
||||
|
||||
#include <libudev.h>
|
||||
|
||||
static struct udev_device *
|
||||
dri3_udev_device_new_from_fd(struct udev *udev, int fd)
|
||||
{
|
||||
struct udev_device *device;
|
||||
struct stat buf;
|
||||
|
||||
if (fstat(fd, &buf) < 0) {
|
||||
ErrorMessageF("DRI3: failed to stat fd %d", fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
|
||||
if (device == NULL) {
|
||||
ErrorMessageF("DRI3: could not create udev device for fd %d", fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
char *
|
||||
dri3_get_driver_for_fd(int fd)
|
||||
{
|
||||
struct udev *udev;
|
||||
struct udev_device *device, *parent;
|
||||
const char *pci_id;
|
||||
char *driver = NULL;
|
||||
int vendor_id, chip_id, i, j;
|
||||
|
||||
udev = udev_new();
|
||||
device = dri3_udev_device_new_from_fd(udev, fd);
|
||||
if (device == NULL)
|
||||
return NULL;
|
||||
|
||||
parent = udev_device_get_parent(device);
|
||||
if (parent == NULL) {
|
||||
ErrorMessageF("DRI3: could not get parent device");
|
||||
goto out;
|
||||
}
|
||||
|
||||
pci_id = udev_device_get_property_value(parent, "PCI_ID");
|
||||
if (pci_id == NULL ||
|
||||
sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) {
|
||||
ErrorMessageF("DRI3: malformed or no PCI ID");
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; driver_map[i].driver; i++) {
|
||||
if (vendor_id != driver_map[i].vendor_id)
|
||||
continue;
|
||||
if (driver_map[i].num_chips_ids == -1) {
|
||||
driver = strdup(driver_map[i].driver);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (j = 0; j < driver_map[i].num_chips_ids; j++)
|
||||
if (driver_map[i].chip_ids[j] == chip_id) {
|
||||
driver = strdup(driver_map[i].driver);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
udev_device_unref(device);
|
||||
udev_unref(udev);
|
||||
|
||||
return driver;
|
||||
}
|
1831
src/glx/dri3_glx.c
Normal file
1831
src/glx/dri3_glx.c
Normal file
File diff suppressed because it is too large
Load Diff
209
src/glx/dri3_priv.h
Normal file
209
src/glx/dri3_priv.h
Normal file
@ -0,0 +1,209 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* This file was derived from dri2_priv.h 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)
|
||||
*/
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/dri3.h>
|
||||
#include <xcb/present.h>
|
||||
#include <xcb/sync.h>
|
||||
|
||||
/* From xmlpool/options.h, user exposed so should be stable */
|
||||
#define DRI_CONF_VBLANK_NEVER 0
|
||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
|
||||
#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
|
||||
#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
|
||||
|
||||
enum dri3_buffer_type {
|
||||
dri3_buffer_back = 0,
|
||||
dri3_buffer_front = 1
|
||||
};
|
||||
|
||||
struct dri3_buffer {
|
||||
__DRIimage *image;
|
||||
uint32_t pixmap;
|
||||
|
||||
/* Synchronization between the client and X server is done using an
|
||||
* xshmfence that is mapped into an X server SyncFence. This lets the
|
||||
* client check whether the X server is done using a buffer with a simple
|
||||
* xshmfence call, rather than going to read X events from the wire.
|
||||
*
|
||||
* However, we can only wait for one xshmfence to be triggered at a time,
|
||||
* so we need to know *which* buffer is going to be idle next. We do that
|
||||
* by waiting for a PresentIdleNotify event. When that event arrives, the
|
||||
* 'busy' flag gets cleared and the client knows that the fence has been
|
||||
* triggered, and that the wait call will not block.
|
||||
*/
|
||||
|
||||
uint32_t sync_fence; /* XID of X SyncFence object */
|
||||
int32_t *shm_fence; /* pointer to xshmfence object */
|
||||
GLboolean busy; /* Set on swap, cleared on IdleNotify */
|
||||
void *driverPrivate;
|
||||
|
||||
uint32_t size;
|
||||
uint32_t pitch;
|
||||
uint32_t cpp;
|
||||
uint32_t flags;
|
||||
uint32_t width, height;
|
||||
|
||||
enum dri3_buffer_type buffer_type;
|
||||
};
|
||||
|
||||
struct dri3_display
|
||||
{
|
||||
__GLXDRIdisplay base;
|
||||
|
||||
const __DRIextension *loader_extensions[8];
|
||||
|
||||
/* DRI3 bits */
|
||||
int dri3Major;
|
||||
int dri3Minor;
|
||||
|
||||
/* Present bits */
|
||||
int hasPresent;
|
||||
int presentMajor;
|
||||
int presentMinor;
|
||||
};
|
||||
|
||||
struct dri3_screen {
|
||||
struct glx_screen base;
|
||||
|
||||
__DRIscreen *driScreen;
|
||||
__GLXDRIscreen vtable;
|
||||
|
||||
const __DRIimageExtension *image;
|
||||
const __DRIimageDriverExtension *image_driver;
|
||||
const __DRIcoreExtension *core;
|
||||
const __DRI2flushExtension *f;
|
||||
const __DRI2configQueryExtension *config;
|
||||
const __DRItexBufferExtension *texBuffer;
|
||||
const __DRIconfig **driver_configs;
|
||||
|
||||
void *driver;
|
||||
int fd;
|
||||
|
||||
Bool show_fps;
|
||||
};
|
||||
|
||||
struct dri3_context
|
||||
{
|
||||
struct glx_context base;
|
||||
__DRIcontext *driContext;
|
||||
};
|
||||
|
||||
#define DRI3_MAX_BACK 2
|
||||
#define DRI3_BACK_ID(i) (i)
|
||||
#define DRI3_FRONT_ID (DRI3_MAX_BACK)
|
||||
|
||||
static inline int
|
||||
dri3_buf_id_next(int buf_id)
|
||||
{
|
||||
if (buf_id == DRI3_MAX_BACK - 1)
|
||||
return 0;
|
||||
return buf_id + 1;
|
||||
}
|
||||
|
||||
static inline int
|
||||
dri3_buf_id_prev(int buf_id)
|
||||
{
|
||||
if (buf_id == 0)
|
||||
return DRI3_MAX_BACK - 1;
|
||||
return buf_id - 1;
|
||||
}
|
||||
|
||||
static inline int
|
||||
dri3_pixmap_buf_id(enum dri3_buffer_type buffer_type)
|
||||
{
|
||||
if (buffer_type == dri3_buffer_back)
|
||||
return DRI3_BACK_ID(0);
|
||||
else
|
||||
return DRI3_FRONT_ID;
|
||||
}
|
||||
|
||||
struct dri3_drawable {
|
||||
__GLXDRIdrawable base;
|
||||
__DRIdrawable *driDrawable;
|
||||
int width, height;
|
||||
int swap_interval;
|
||||
uint8_t have_back;
|
||||
uint8_t have_fake_front;
|
||||
uint8_t is_pixmap;
|
||||
|
||||
uint32_t present_request_serial;
|
||||
uint32_t present_event_serial;
|
||||
|
||||
uint64_t sbc;
|
||||
|
||||
uint64_t ust, msc;
|
||||
|
||||
/* For WaitMSC */
|
||||
uint32_t present_msc_request_serial;
|
||||
uint32_t present_msc_event_serial;
|
||||
|
||||
uint64_t previous_time;
|
||||
unsigned frames;
|
||||
|
||||
struct dri3_buffer *buffers[1 + DRI3_MAX_BACK];
|
||||
int cur_back;
|
||||
int depth;
|
||||
|
||||
uint32_t *stamp;
|
||||
|
||||
xcb_present_event_t eid;
|
||||
xcb_gcontext_t gc;
|
||||
xcb_special_event_t *special_event;
|
||||
};
|
||||
|
||||
char *
|
||||
dri3_get_driver_for_fd(int fd);
|
@ -150,6 +150,7 @@ extern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy);
|
||||
extern void dri2InvalidateBuffers(Display *dpy, XID drawable);
|
||||
extern unsigned dri2GetSwapEventType(Display *dpy, XID drawable);
|
||||
|
||||
extern __GLXDRIdisplay *dri3_create_display(Display * dpy);
|
||||
|
||||
/*
|
||||
** Functions to obtain driver configuration information from a direct
|
||||
@ -587,6 +588,7 @@ struct glx_display
|
||||
__GLXDRIdisplay *driswDisplay;
|
||||
__GLXDRIdisplay *driDisplay;
|
||||
__GLXDRIdisplay *dri2Display;
|
||||
__GLXDRIdisplay *dri3Display;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -770,7 +770,9 @@ AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv)
|
||||
for (i = 0; i < screens; i++, psc++) {
|
||||
psc = NULL;
|
||||
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
|
||||
if (priv->dri2Display)
|
||||
if (priv->dri3Display)
|
||||
psc = (*priv->dri3Display->createScreen) (i, priv);
|
||||
if (psc == NULL && priv->dri2Display)
|
||||
psc = (*priv->dri2Display->createScreen) (i, priv);
|
||||
if (psc == NULL && priv->driDisplay)
|
||||
psc = (*priv->driDisplay->createScreen) (i, priv);
|
||||
@ -863,6 +865,8 @@ __glXInitialize(Display * dpy)
|
||||
** (e.g., those called in AllocAndFetchScreenConfigs).
|
||||
*/
|
||||
if (glx_direct && glx_accel) {
|
||||
if (!getenv("LIBGL_DRI3_DISABLE"))
|
||||
dpyPriv->dri3Display = dri3_create_display(dpy);
|
||||
dpyPriv->dri2Display = dri2CreateDisplay(dpy);
|
||||
dpyPriv->driDisplay = driCreateDisplay(dpy);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user