[Mesa-dev] [PATCH 2/2] Add a new capabilities for drivers that can't share buffers
Giovanni Campagna
scampa.giovanni at gmail.com
Fri Apr 11 17:25:40 PDT 2014
From: Giovanni Campagna <gcampagna at src.gnome.org>
The kms-dri swrast driver cannot share buffers using the GEM,
so it must tell the loader to disable extensions relying on
that, without disabling the image DRI extension altogheter
(which would prevent the loader from working at all).
This requires a new gallium capability (which is queried on
the pipe_screen and for swrast drivers it's forwared to the
winsys), and requires a new version of the DRI image extension.
---
include/GL/internal/dri_interface.h | 15 +++++++++++++
src/egl/drivers/dri2/egl_dri2.c | 10 ++++++++-
src/egl/drivers/dri2/platform_drm.c | 17 +++++++++++---
src/gallium/drivers/freedreno/freedreno_screen.c | 1 +
src/gallium/drivers/i915/i915_screen.c | 1 +
src/gallium/drivers/ilo/ilo_screen.c | 2 ++
src/gallium/drivers/llvmpipe/lp_screen.c | 7 ++++++
src/gallium/drivers/nouveau/nv30/nv30_screen.c | 1 +
src/gallium/drivers/nouveau/nv50/nv50_screen.c | 2 ++
src/gallium/drivers/nouveau/nvc0/nvc0_screen.c | 2 ++
src/gallium/drivers/r300/r300_screen.c | 1 +
src/gallium/drivers/r600/r600_pipe.c | 1 +
src/gallium/drivers/radeonsi/si_pipe.c | 1 +
src/gallium/drivers/softpipe/sp_screen.c | 7 ++++++
src/gallium/drivers/svga/svga_screen.c | 2 ++
src/gallium/include/pipe/p_defines.h | 1 +
src/gallium/include/state_tracker/sw_winsys.h | 5 +++++
src/gallium/state_trackers/dri/common/dri_screen.h | 1 +
src/gallium/state_trackers/dri/drm/dri2.c | 23 +++++++++++++++++--
src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c | 26 +++++++++++++++++++---
20 files changed, 117 insertions(+), 9 deletions(-)
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index d028d05..85d4afa 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1133,6 +1133,13 @@ enum __DRIChromaSiting {
#define __DRI_IMAGE_ERROR_BAD_PARAMETER 3
/*@}*/
+/**
+ * \name Capabilities that might be returned by __DRIimageExtensionRec::getCapabilities
+ */
+/*@{*/
+#define __DRI_IMAGE_CAP_GLOBAL_NAMES 1
+/*@}*/
+
typedef struct __DRIimageRec __DRIimage;
typedef struct __DRIimageExtensionRec __DRIimageExtension;
struct __DRIimageExtensionRec {
@@ -1239,6 +1246,14 @@ struct __DRIimageExtensionRec {
enum __DRIChromaSiting vert_siting,
unsigned *error,
void *loaderPrivate);
+
+ /**
+ * Query for general capabilities of the driver that concern
+ * buffer sharing and image importing.
+ *
+ * \since 9
+ */
+ int (*getCapabilities)(__DRIscreen *screen);
};
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index dc541ad..26f9fd4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -521,7 +521,15 @@ dri2_setup_screen(_EGLDisplay *disp)
}
if (dri2_dpy->image) {
- disp->Extensions.MESA_drm_image = EGL_TRUE;
+ if (dri2_dpy->image->base.version >= 9 &&
+ dri2_dpy->image->getCapabilities != NULL) {
+ int capabilities;
+
+ capabilities = dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen);
+ disp->Extensions.MESA_drm_image = (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
+ } else
+ disp->Extensions.MESA_drm_image = EGL_TRUE;
+
disp->Extensions.KHR_image_base = EGL_TRUE;
disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
if (dri2_dpy->image->base.version >= 5 &&
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 17b93db..2b79612 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -266,7 +266,10 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
bo = (struct gbm_dri_bo *) dri2_surf->back->bo;
- dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name);
+ if (dri2_surf->base.Resource.Display->Extensions.MESA_drm_image)
+ dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name);
+ else
+ dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE, &name);
dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &pitch);
buffer->attachment = __DRI_BUFFER_BACK_LEFT;
@@ -719,8 +722,16 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
disp->Extensions.EXT_buffer_age = EGL_TRUE;
#ifdef HAVE_WAYLAND_PLATFORM
- if (dri2_dpy->image)
- disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
+ if (dri2_dpy->image) {
+ if (dri2_dpy->image->base.version >= 9 &&
+ dri2_dpy->image->getCapabilities != NULL) {
+ int capabilities;
+
+ capabilities = dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen);
+ disp->Extensions.WL_bind_wayland_display = (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
+ } else
+ disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
+ }
#endif
/* we're supporting EGL 1.4 */
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c
index 08556a4..26dcf87 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -175,6 +175,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
case PIPE_CAP_TEXTURE_MULTISAMPLE:
case PIPE_CAP_USER_CONSTANT_BUFFERS:
+ case PIPE_CAP_BUFFER_SHARE:
return 1;
case PIPE_CAP_SHADER_STENCIL_EXPORT:
diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c
index b484d36..055f7d2 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -186,6 +186,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
case PIPE_CAP_USER_VERTEX_BUFFERS:
case PIPE_CAP_USER_INDEX_BUFFERS:
case PIPE_CAP_USER_CONSTANT_BUFFERS:
+ case PIPE_CAP_BUFFER_SHARE:
return 1;
/* Unsupported features (boolean caps). */
diff --git a/src/gallium/drivers/ilo/ilo_screen.c b/src/gallium/drivers/ilo/ilo_screen.c
index 4bea564..d91c82b 100644
--- a/src/gallium/drivers/ilo/ilo_screen.c
+++ b/src/gallium/drivers/ilo/ilo_screen.c
@@ -441,6 +441,8 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap param)
case PIPE_CAP_FAKE_SW_MSAA:
case PIPE_CAP_TEXTURE_QUERY_LOD:
return 0;
+ case PIPE_CAP_BUFFER_SHARE:
+ return 1;
default:
return 0;
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
index 8fbc58f..05cd221 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -105,6 +105,8 @@ llvmpipe_get_name(struct pipe_screen *screen)
static int
llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
{
+ struct llvmpipe_screen *lp_screen = llvmpipe_screen(screen);
+
switch (param) {
case PIPE_CAP_NPOT_TEXTURES:
case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
@@ -244,6 +246,11 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
return 0;
case PIPE_CAP_FAKE_SW_MSAA:
return 1;
+ case PIPE_CAP_BUFFER_SHARE:
+ if (lp_screen->winsys->get_param != NULL)
+ return lp_screen->winsys->get_param(lp_screen->winsys, param);
+ else
+ return 1;
}
/* should only get here on unhandled cases */
debug_printf("Unexpected PIPE_CAP %d query\n", param);
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 0e10679..003dcba 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -79,6 +79,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
case PIPE_CAP_TGSI_TEXCOORD:
case PIPE_CAP_USER_CONSTANT_BUFFERS:
case PIPE_CAP_USER_INDEX_BUFFERS:
+ case PIPE_CAP_BUFFER_SHARE:
return 1;
case PIPE_CAP_USER_VERTEX_BUFFERS:
return 0;
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 4a8423f..00e5ded 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -205,6 +205,8 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
return (class_3d >= NVA3_3D_CLASS) ? 4 : 0;
case PIPE_CAP_TEXTURE_QUERY_LOD:
return class_3d >= NVA3_3D_CLASS;
+ case PIPE_CAP_BUFFER_SHARE:
+ return 1;
default:
NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
return 0;
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
index 64674f7..8997057 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
@@ -188,6 +188,8 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
return 1;
case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
return 4;
+ case PIPE_CAP_BUFFER_SHARE:
+ return 1;
default:
NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
return 0;
diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
index a60cdca..8466237 100644
--- a/src/gallium/drivers/r300/r300_screen.c
+++ b/src/gallium/drivers/r300/r300_screen.c
@@ -107,6 +107,7 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
case PIPE_CAP_USER_CONSTANT_BUFFERS:
case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
+ case PIPE_CAP_BUFFER_SHARE:
return 1;
case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index c037662..43d06ab 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -325,6 +325,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
case PIPE_CAP_TEXTURE_MULTISAMPLE:
case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
+ case PIPE_CAP_BUFFER_SHARE:
return 1;
case PIPE_CAP_COMPUTE:
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index 03f73ac..5a19c69 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -258,6 +258,7 @@ static int si_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
case PIPE_CAP_TGSI_VS_LAYER:
case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
+ case PIPE_CAP_BUFFER_SHARE:
return 1;
case PIPE_CAP_TEXTURE_MULTISAMPLE:
diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index b4ca728..2c22d1d 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -63,6 +63,8 @@ softpipe_get_name(struct pipe_screen *screen)
static int
softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
{
+ struct softpipe_screen *sp_screen = softpipe_screen(screen);
+
switch (param) {
case PIPE_CAP_NPOT_TEXTURES:
case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
@@ -195,6 +197,11 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
return 0;
+ case PIPE_CAP_BUFFER_SHARE:
+ if (sp_screen->winsys->get_param != NULL)
+ return sp_screen->winsys->get_param(sp_screen->winsys, param);
+ else
+ return 1;
}
/* should only get here on unhandled cases */
debug_printf("Unexpected PIPE_CAP %d query\n", param);
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index 5a0436a..1f0d9b6 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -282,6 +282,8 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
return 1;
case PIPE_CAP_ENDIANNESS:
return PIPE_ENDIAN_LITTLE;
+ case PIPE_CAP_BUFFER_SHARE:
+ return 1;
}
debug_printf("Unexpected PIPE_CAP_ query %u\n", param);
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index a3a1ae1..1e1b47a 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -556,6 +556,7 @@ enum pipe_cap {
PIPE_CAP_TEXTURE_QUERY_LOD = 94,
PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET = 95,
PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET = 96,
+ PIPE_CAP_BUFFER_SHARE = 97
};
#define PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 (1 << 0)
diff --git a/src/gallium/include/state_tracker/sw_winsys.h b/src/gallium/include/state_tracker/sw_winsys.h
index a3479eb..21250ff 100644
--- a/src/gallium/include/state_tracker/sw_winsys.h
+++ b/src/gallium/include/state_tracker/sw_winsys.h
@@ -37,6 +37,7 @@
#include "pipe/p_compiler.h" /* for boolean */
#include "pipe/p_format.h"
+#include "pipe/p_defines.h" /* for pipe_cap */
#ifdef __cplusplus
@@ -135,6 +136,10 @@ struct sw_winsys
void
(*displaytarget_destroy)( struct sw_winsys *ws,
struct sw_displaytarget *dt );
+
+ int
+ (*get_param)( struct sw_winsys *ws,
+ enum pipe_cap param );
};
diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h b/src/gallium/state_trackers/dri/common/dri_screen.h
index 7c8e582..446dbcd 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.h
+++ b/src/gallium/state_trackers/dri/common/dri_screen.h
@@ -69,6 +69,7 @@ struct dri_screen
/* drm */
int fd;
+ boolean can_share_buffer;
/* gallium */
boolean d_depth_bits_last;
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index 4f2a87e..30f92e3 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -308,6 +308,10 @@ dri2_drawable_process_buffers(struct dri_context *ctx,
whandle.type = DRM_API_HANDLE_TYPE_SHARED;
whandle.handle = buf->name;
whandle.stride = buf->pitch;
+ if (screen->can_share_buffer)
+ whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+ else
+ whandle.type = DRM_API_HANDLE_TYPE_KMS;
drawable->textures[statt] =
screen->base.screen->resource_from_handle(screen->base.screen,
@@ -476,7 +480,10 @@ dri2_allocate_buffer(__DRIscreen *sPriv,
}
memset(&whandle, 0, sizeof(whandle));
- whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+ if (screen->can_share_buffer)
+ whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+ else
+ whandle.type = DRM_API_HANDLE_TYPE_KMS;
screen->base.screen->resource_get_handle(screen->base.screen,
buffer->resource, &whandle);
@@ -1035,8 +1042,16 @@ dri2_destroy_image(__DRIimage *img)
FREE(img);
}
+static int
+dri2_get_capabilities(__DRIscreen *_screen)
+{
+ struct dri_screen *screen = dri_screen(_screen);
+
+ return (screen->can_share_buffer ? __DRI_IMAGE_CAP_GLOBAL_NAMES : 0);
+}
+
static struct __DRIimageExtensionRec dri2ImageExtension = {
- { __DRI_IMAGE, 6 },
+ { __DRI_IMAGE, 9 },
dri2_create_image_from_name,
dri2_create_image_from_renderbuffer,
dri2_destroy_image,
@@ -1047,6 +1062,9 @@ static struct __DRIimageExtensionRec dri2ImageExtension = {
dri2_from_names,
dri2_from_planar,
dri2_create_from_texture,
+ NULL, /* from fds */
+ NULL, /* from dma bufs */
+ dri2_get_capabilities,
};
/*
@@ -1116,6 +1134,7 @@ dri2_init_screen(__DRIscreen * sPriv)
if (!configs)
goto fail;
+ screen->can_share_buffer = pscreen->get_param(pscreen, PIPE_CAP_BUFFER_SHARE);
screen->auto_fake_front = dri_with_format(sPriv);
screen->broken_invalidate = !sPriv->dri2.useInvalidate;
screen->lookup_egl_image = dri2_lookup_egl_image;
diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
index 745b857..c51eb8e 100644
--- a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
+++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
@@ -230,6 +230,8 @@ kms_sw_displaytarget_from_handle(struct sw_winsys *ws,
struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
struct kms_sw_displaytarget *kms_sw_dt;
+ assert(whandle->type == DRM_API_HANDLE_TYPE_KMS);
+
LIST_FOR_EACH_ENTRY(kms_sw_dt, &kms_sw->bo_list, link) {
if (kms_sw_dt->handle == whandle->handle) {
kms_sw_dt->ref_count++;
@@ -252,9 +254,13 @@ kms_sw_displaytarget_get_handle(struct sw_winsys *winsys,
{
struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
- assert(whandle->type == DRM_API_HANDLE_TYPE_SHARED);
- whandle->handle = kms_sw_dt->handle;
- whandle->stride = kms_sw_dt->stride;
+ if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
+ whandle->handle = kms_sw_dt->handle;
+ whandle->stride = kms_sw_dt->stride;
+ } else {
+ whandle->handle = 0;
+ whandle->stride = 0;
+ }
return TRUE;
}
@@ -269,6 +275,18 @@ kms_sw_displaytarget_display(struct sw_winsys *ws,
assert(0);
}
+static int
+kms_sw_get_param(struct sw_winsys *ws,
+ enum pipe_cap param)
+{
+ switch (param) {
+ case PIPE_CAP_BUFFER_SHARE:
+ return 0;
+
+ default:
+ return 0;
+ }
+}
static void
kms_destroy_sw_winsys(struct sw_winsys *winsys)
@@ -304,6 +322,8 @@ kms_dri_create_winsys(int fd)
ws->base.displaytarget_display = kms_sw_displaytarget_display;
+ ws->base.get_param = kms_sw_get_param;
+
return &ws->base;
}
--
1.9.0
More information about the mesa-dev
mailing list