From e57ad3d38cab091ef341838b651dbda16cee007b Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Wed, 23 Jul 2014 19:28:52 +0100 Subject: dri: Add a new capabilities for drivers that can't share buffers 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 altogether (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 forwarded to the winsys), and requires a new version of the DRI image extension. [Emil Velikov] - Rebased on top of gallium-dri megadrivers. - Drop PIPE_CAP_BUFFER_SHARE and sw_winsys::get_param hook. The can_share_buffer cap is set at InitScreen. We use a different InitScreen (and thus value for the cap) function for kms_dri, due to deeper differences originating from dri megadrivers. Signed-off-by: Emil Velikov --- src/gallium/state_trackers/dri/dri2.c | 25 +++++++++++++++++++++---- src/gallium/state_trackers/dri/dri_screen.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src/gallium/state_trackers/dri') diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index f70b723a07b..ef192e36f7a 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -322,7 +322,11 @@ 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); @@ -501,10 +505,12 @@ dri2_allocate_textures(struct dri_context *ctx, templ.height0 = dri_drawable->h; templ.format = format; templ.bind = bind; - 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, &templ, &whandle); @@ -1186,9 +1192,17 @@ 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); +} + /* The extension is modified during runtime if DRI_PRIME is detected */ static __DRIimageExtension dri2ImageExtension = { - .base = { __DRI_IMAGE, 9 }, + .base = { __DRI_IMAGE, 10 }, .createImageFromName = dri2_create_image_from_name, .createImageFromRenderbuffer = dri2_create_image_from_renderbuffer, @@ -1203,6 +1217,7 @@ static __DRIimageExtension dri2ImageExtension = { .createImageFromFds = NULL, .createImageFromDmaBufs = NULL, .blitImage = dri2_blit_image, + .getCapabilities = dri2_get_capabilities, }; /* @@ -1282,6 +1297,7 @@ dri2_init_screen(__DRIscreen * sPriv) if (!configs) goto fail; + screen->can_share_buffer = true; screen->auto_fake_front = dri_with_format(sPriv); screen->broken_invalidate = !sPriv->dri2.useInvalidate; screen->lookup_egl_image = dri2_lookup_egl_image; @@ -1327,6 +1343,7 @@ dri_kms_init_screen(__DRIscreen * sPriv) if (!configs) goto fail; + screen->can_share_buffer = false; 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/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 993ad2abe09..07c989807f3 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -70,6 +70,7 @@ struct dri_screen /* drm */ int fd; + boolean can_share_buffer; struct pipe_loader_device *dev; -- cgit v1.2.3