All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] intel: make bufmgr_gem shareable from different API
Date: Thu, 11 Sep 2014 13:21:13 +0100	[thread overview]
Message-ID: <541193B9.5070205@intel.com> (raw)
In-Reply-To: <20140911115227.GK28332@nuc-i3427.alporthouse.com>

On 11/09/14 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.
>
> This patch adds the ability to use the same /dev/dri/card0 device fd
> between two libraries. This implies that they share the same context and
> address space, which is probably not what you want, but nevertheless
> seems sensible if they are sharing the device fd in the first place.

That's what I meant, sorry if it was unclear.

>
> I suspect this may break unwary users such as igt, which would fork
> after creating a bufmgr, close the fds, but then open their own device
> fd with the same fd as before. Not a huge issue, just something to check
> in case it causes some fun fallout.
Will have a look, thanks.

>   
>> This patch modifies drm_intel_bufmgr_gem_init() so given a file
>> descriptor, it will look for an already existing drm_intel_bufmgr
>> using the same file descriptor and return that object.
>>
>> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>> ---
>>   intel/intel_bufmgr_gem.c | 100 +++++++++++++++++++++++++++++++++++++++++------
>>   1 file changed, 88 insertions(+), 12 deletions(-)
>>
>> diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
>> index 0e1cb0d..125c81c 100644
>> --- a/intel/intel_bufmgr_gem.c
>> +++ b/intel/intel_bufmgr_gem.c
>> @@ -94,6 +94,8 @@ struct drm_intel_gem_bo_bucket {
>>   typedef struct _drm_intel_bufmgr_gem {
>>   	drm_intel_bufmgr bufmgr;
>>   
>> +	atomic_t refcount;
>> +
>>   	int fd;
>>   
>>   	int max_relocs;
>> @@ -3186,6 +3188,85 @@ drm_intel_bufmgr_gem_set_aub_annotations(drm_intel_bo *bo,
>>   	bo_gem->aub_annotation_count = count;
>>   }
>>   
>> +static pthread_mutex_t bufmgr_list_mutex = PTHREAD_MUTEX_INITIALIZER;
>> +static drm_intel_bufmgr_gem **bufmgr_list = NULL;
>> +static unsigned bufmgr_list_size = 0, bufmgr_list_nb;
>> +
>> +static drm_intel_bufmgr_gem *
>> +drm_intel_bufmgr_gem_find_or_create_for_fd(int fd, int *found)
>> +{
>> +        drm_intel_bufmgr_gem *bufmgr_gem;
>> +
>> +        assert(pthread_mutex_lock(&bufmgr_list_mutex) == 0);
>> +
>> +        if (bufmgr_list == NULL) {
> Just use an embedded list rather than array, that would greatly simplify
> the search, cration and deletion.
> -Chris
>

I tried to use the embedded list, but from my understanding I need the 
embedded structure at the top of the bufmgr struct. Is that possible? 
Sounds like an ABI break.

Thanks,

-
Lionel

  parent reply	other threads:[~2014-09-11 12:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11 11:33 Shareable bufmgr objects Lionel Landwerlin
2014-09-11 11:33 ` [PATCH] intel: make bufmgr_gem shareable from different API Lionel Landwerlin
2014-09-11 11:52   ` Chris Wilson
2014-09-11 12:16     ` Daniel Stone
2014-09-11 12:21     ` Lionel Landwerlin [this message]
2014-09-11 12:29       ` Chris Wilson
  -- strict thread matches above, loose matches on Subject: below --
2014-09-11 15:36 Shareable bufmgr objects v2 Lionel Landwerlin
2014-09-11 15:36 ` [PATCH] intel: make bufmgr_gem shareable from different API Lionel Landwerlin
2014-09-11 15:53   ` Chris Wilson
2014-09-11 16:59     ` Lionel Landwerlin
2014-09-12  6:13       ` Chris Wilson
2014-09-12 10:27         ` Shareable bufmgr objects v3 Lionel Landwerlin
2014-09-12 10:27           ` [PATCH] intel: make bufmgr_gem shareable from different API Lionel Landwerlin
2014-09-12 10:41             ` Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=541193B9.5070205@intel.com \
    --to=lionel.g.landwerlin@intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.