drmPrimeHandleToFD() will return the same GEM handle every time the same buffer is imported, even from a different prime FD. Since GEM handles are not reference counted, we need to make sure that each GEM handle is referenced only by one display target struct, by looking it up in kms_sw->bo_list first and bumping the refcount of the found dt on hit and falling back to creating a new dt only on miss.
v2: Split into separate function. Use helper function for lookup. Signed-off-by: Tomasz Figa <tf...@chromium.org> CC: <mesa-sta...@lists.freedesktop.org> --- src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c | 4 ++++ 1 file changed, 4 insertions(+) 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 cb02b22..4ee2696 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 @@ -244,6 +244,10 @@ kms_sw_displaytarget_add_from_prime(struct kms_sw_winsys *kms_sw, int fd, if (ret) return NULL; + kms_sw_dt = kms_sw_displaytarget_lookup(kms_sw, handle); + if (kms_sw_dt) + return kms_sw_dt; + kms_sw_dt = CALLOC_STRUCT(kms_sw_displaytarget); if (!kms_sw_dt) return NULL; -- 2.8.0.rc3.226.g39d4020 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev