On Tue, 2 Jul 2019 06:56:50 -0700 Alyssa Rosenzweig <alyssa.rosenzw...@collabora.com> wrote:
> Question: Does this allow us to map arbitrary CPU buffers into GPU > space? Depends what you mean by arbitrary. You can map any dmabuf, that means the buffer has to be created kernel side and exported as a DMAbuf. > Stuff with no relation to the winsys, just... arbitrary user > memory? Nope, I don't think so. That might work if you allocate things through udmabuf, but then you're better off allocating a BO directly. > That might be useful for index/vertex buffers (which we > currently are forced to memcpy() into a BO we create if given a user > pointer rather than a resource), but maybe not actually because of sync > requirements. > > On Tue, Jul 02, 2019 at 03:23:49PM +0200, Boris Brezillon wrote: > > Let's keep a clear split between ioctl wrappers and the rest of the > > driver. All the import BO function need is a dmabuf FD and the screen > > object, and the export one should only take care of generating a dmabuf > > FD out of a BO object. Winsys handle manipulation should stay in the > > resource.c file. > > > > Signed-off-by: Boris Brezillon <boris.brezil...@collabora.com> > > --- > > src/gallium/drivers/panfrost/pan_drm.c | 17 +++++++---------- > > src/gallium/drivers/panfrost/pan_resource.c | 16 +++++++++++----- > > src/gallium/drivers/panfrost/pan_screen.h | 6 ++---- > > 3 files changed, 20 insertions(+), 19 deletions(-) > > > > diff --git a/src/gallium/drivers/panfrost/pan_drm.c > > b/src/gallium/drivers/panfrost/pan_drm.c > > index f17f56bc6307..b88ab0e5ce2b 100644 > > --- a/src/gallium/drivers/panfrost/pan_drm.c > > +++ b/src/gallium/drivers/panfrost/pan_drm.c > > @@ -114,7 +114,7 @@ panfrost_drm_free_slab(struct panfrost_screen *screen, > > struct panfrost_memory *m > > } > > > > struct panfrost_bo * > > -panfrost_drm_import_bo(struct panfrost_screen *screen, struct > > winsys_handle *whandle) > > +panfrost_drm_import_bo(struct panfrost_screen *screen, int fd) > > { > > struct panfrost_bo *bo = rzalloc(screen, struct panfrost_bo); > > struct drm_panfrost_get_bo_offset get_bo_offset = {0,}; > > @@ -122,7 +122,7 @@ panfrost_drm_import_bo(struct panfrost_screen *screen, > > struct winsys_handle *wha > > int ret; > > unsigned gem_handle; > > > > - ret = drmPrimeFDToHandle(screen->fd, whandle->handle, &gem_handle); > > + ret = drmPrimeFDToHandle(screen->fd, fd, &gem_handle); > > assert(!ret); > > > > get_bo_offset.handle = gem_handle; > > @@ -141,7 +141,7 @@ panfrost_drm_import_bo(struct panfrost_screen *screen, > > struct winsys_handle *wha > > assert(0); > > } > > > > - bo->size = lseek(whandle->handle, 0, SEEK_END); > > + bo->size = lseek(fd, 0, SEEK_END); > > assert(bo->size > 0); > > bo->cpu = os_mmap(NULL, bo->size, PROT_READ | PROT_WRITE, > > MAP_SHARED, > > screen->fd, mmap_bo.offset); > > @@ -158,21 +158,18 @@ panfrost_drm_import_bo(struct panfrost_screen > > *screen, struct winsys_handle *wha > > } > > > > int > > -panfrost_drm_export_bo(struct panfrost_screen *screen, int gem_handle, > > unsigned int stride, struct winsys_handle *whandle) > > +panfrost_drm_export_bo(struct panfrost_screen *screen, const struct > > panfrost_bo *bo) > > { > > struct drm_prime_handle args = { > > - .handle = gem_handle, > > + .handle = bo->gem_handle, > > .flags = DRM_CLOEXEC, > > }; > > > > int ret = drmIoctl(screen->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, > > &args); > > if (ret == -1) > > - return FALSE; > > + return -1; > > > > - whandle->handle = args.fd; > > - whandle->stride = stride; > > - > > - return TRUE; > > + return args.fd; > > } > > > > static int > > diff --git a/src/gallium/drivers/panfrost/pan_resource.c > > b/src/gallium/drivers/panfrost/pan_resource.c > > index 8901aeee09b1..f86617f80c20 100644 > > --- a/src/gallium/drivers/panfrost/pan_resource.c > > +++ b/src/gallium/drivers/panfrost/pan_resource.c > > @@ -70,7 +70,7 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen, > > pipe_reference_init(&prsc->reference, 1); > > prsc->screen = pscreen; > > > > - rsc->bo = panfrost_drm_import_bo(screen, whandle); > > + rsc->bo = panfrost_drm_import_bo(screen, whandle->handle); > > rsc->slices[0].stride = whandle->stride; > > rsc->slices[0].initialized = true; > > > > @@ -120,10 +120,16 @@ panfrost_resource_get_handle(struct pipe_screen > > *pscreen, > > handle->handle = args.fd; > > > > return TRUE; > > - } else > > - return panfrost_drm_export_bo(screen, > > rsrc->bo->gem_handle, > > - > > rsrc->slices[0].stride, > > - handle); > > + } else { > > + int fd = panfrost_drm_export_bo(screen, rsrc->bo); > > + > > + if (fd < 0) > > + return FALSE; > > + > > + handle->handle = fd; > > + handle->stride = rsrc->slices[0].stride; > > + return TRUE; > > + } > > } > > > > return FALSE; > > diff --git a/src/gallium/drivers/panfrost/pan_screen.h > > b/src/gallium/drivers/panfrost/pan_screen.h > > index 83186ebb2f7f..1a1eb2f8bf27 100644 > > --- a/src/gallium/drivers/panfrost/pan_screen.h > > +++ b/src/gallium/drivers/panfrost/pan_screen.h > > @@ -83,11 +83,9 @@ void > > panfrost_drm_free_slab(struct panfrost_screen *screen, > > struct panfrost_memory *mem); > > struct panfrost_bo * > > -panfrost_drm_import_bo(struct panfrost_screen *screen, > > - struct winsys_handle *whandle); > > +panfrost_drm_import_bo(struct panfrost_screen *screen, int fd); > > int > > -panfrost_drm_export_bo(struct panfrost_screen *screen, int gem_handle, > > - unsigned int stride, struct winsys_handle *whandle); > > +panfrost_drm_export_bo(struct panfrost_screen *screen, const struct > > panfrost_bo *bo); > > int > > panfrost_drm_submit_vs_fs_job(struct panfrost_context *ctx, bool has_draws, > > bool is_scanout); > > -- > > 2.21.0 > > _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev