From patchwork Thu Sep 11 12:16:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Stone X-Patchwork-Id: 4885151 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8AA18C0338 for ; Thu, 11 Sep 2014 12:17:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D3F920260 for ; Thu, 11 Sep 2014 12:16:58 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7975720254 for ; Thu, 11 Sep 2014 12:16:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8FE796E57A; Thu, 11 Sep 2014 05:16:55 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 11BCD6E57A for ; Thu, 11 Sep 2014 05:16:53 -0700 (PDT) Received: by mail-we0-f177.google.com with SMTP id u57so6278268wes.22 for ; Thu, 11 Sep 2014 05:16:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=1AvWpdQ0NexdkNXeEl88a4eCx8mv/zOFCtcOkFMwqwI=; b=dnSFx0j3+sEmg0tqoz/EXBt1AGetVTrbwtoC5IegJGY/bcB8zBYiw2GEDfhFJQqDOv hHd15LlFl6DcwZD3Q461zEQQSaKVy+HxQoH5QNT+wr+KL8GmaI6oCMULbkRB+Lm0JxQt JdxHJxLaRcxElREXtvfXKJonU4NZrLph2PjfVdE3OuaPQKFFDp1ogvgIRoeoj39dFOv5 /lauWMr6BjnUTsHrdMihn3+Nwjty3lTMuvzxFg09IUs+l79zwmeF680iFaWLqF/MTmW1 RcnK9N7CM9XLMxpcqh57eM8d0Ms/ePdGH/WV5e4hUyLR+UBgZkk9arBY2+JeK1FO1+uQ vcow== X-Gm-Message-State: ALoCoQmPiMRtO2tkrtr3j/qMUngJupBWmfzQ/o6N6huNfRGqXnN7+XiEeDLD4WE4Zi5KzxVJc2RC MIME-Version: 1.0 X-Received: by 10.180.99.34 with SMTP id en2mr6738828wib.34.1410437808063; Thu, 11 Sep 2014 05:16:48 -0700 (PDT) Received: by 10.194.104.193 with HTTP; Thu, 11 Sep 2014 05:16:47 -0700 (PDT) X-Originating-IP: [93.96.195.58] In-Reply-To: <20140911115227.GK28332@nuc-i3427.alporthouse.com> References: <1410435221-16419-1-git-send-email-lionel.g.landwerlin@intel.com> <1410435221-16419-2-git-send-email-lionel.g.landwerlin@intel.com> <20140911115227.GK28332@nuc-i3427.alporthouse.com> Date: Thu, 11 Sep 2014 13:16:47 +0100 Message-ID: Subject: Re: [PATCH] intel: make bufmgr_gem shareable from different API From: Daniel Stone To: Chris Wilson , Lionel Landwerlin , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, On 11 September 2014 12:52, Chris Wilson wrote: > On Thu, Sep 11, 2014 at 12:33:41PM +0100, Lionel Landwerlin wrote: > > When using Mesa and LibVA in the same process, one would like to be > > able bind buffers from the output of the decoder to a GL texture > > through an EGLImage. > > > > LibVA can reuse buffers allocated by Gbm through a file descriptor. It > > will then wrap it into a drm_intel_bo with > > drm_intel_bo_gem_create_from_prime(). > > > > Given both libraries are using libdrm to allocate and use buffer > > objects, there is a need to have the buffer objects properly > > refcounted. That is possible if both API use the same drm_intel_bo > > objects, but that also requires that both API use the same > > drm_intel_bufmgr object. > > The description is wrong though. Reusing buffers export and import > through a dmabuf, should work and be correctly refcounted already. > Indeed. I've been using the attached patch to deal with the case where we have two EGLDisplays/DRIscreens that can share DRIimage objects (long story, and a much more ugly patch), and it works perfectly. The cover letter's description is right though, in that you get a cryptic message thanks to relocation having been totally skipped when you submit objects from a foreign bufmgr. Cheers, Daniel diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 23aa528..54df6a8 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1262,7 +1262,8 @@ dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, return NULL; } - dri_image = dri2_dpy->image->fromPlanar(buffer->driver_buffer, plane, NULL); + dri_image = dri2_dpy->image->fromPlanar(buffer->driver_buffer, plane, + dri2_dpy->dri_screen); if (dri_image == NULL) { _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer"); diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index 9bd4fda..667620b 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -739,6 +739,9 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate) struct intel_image_format *f; uint32_t mask_x, mask_y; __DRIimage *image; + const __DRIscreen *dri_screen = loaderPrivate; + const struct intel_screen *const intel_screen = + (struct intel_screen *) dri_screen->driverPrivate; if (parent == NULL || parent->planar_format == NULL) return NULL; @@ -771,13 +774,42 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate) return NULL; } + if (parent->region->bo->bufmgr == intel_screen->bufmgr) { + + + image->region->bo = parent->region->bo; + drm_intel_bo_reference(image->region->bo); + } else { + int err, fd; + + + + err = drm_intel_bo_gem_export_to_prime(parent->region->bo, &fd); + if (err != 0) { + _mesa_warning(NULL, "intel_create_sub_image: prime export failed: %d\n", + -err); + free(image->region); + free(image); + return NULL; + } + + image->region->bo = + drm_intel_bo_gem_create_from_prime(intel_screen->bufmgr, fd, + parent->region->bo->size); + close(fd); + if (!image->region->bo) { + _mesa_warning(NULL, "intel_create_sub_image: prime import failed\n"); + free(image->region); + free(image); + return NULL; + } + } + image->region->cpp = _mesa_get_format_bytes(image->format); image->region->width = width; image->region->height = height; image->region->pitch = stride; image->region->refcount = 1; - image->region->bo = parent->region->bo; - drm_intel_bo_reference(image->region->bo); image->region->tiling = parent->region->tiling; image->offset = offset; intel_setup_image_from_dimensions(image);