[Mesa-dev] [PATCH v2 13/37] panfrost: Stop passing screen around for BO operations

Alyssa Rosenzweig alyssa at rosenzweig.io
Mon Sep 16 12:26:48 UTC 2019


R-b, this is a nice cleanup and can probably prevent some WATs down the
line.

On Mon, Sep 16, 2019 at 11:36:51AM +0200, Boris Brezillon wrote:
> Store a screen pointer in panfrost_bo so we don't have to pass a screen
> object to all functions manipulating the BO.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
> ---
>  src/gallium/drivers/panfrost/pan_allocate.c  |  2 +-
>  src/gallium/drivers/panfrost/pan_blend_cso.c |  2 +-
>  src/gallium/drivers/panfrost/pan_bo.c        | 40 ++++++++++----------
>  src/gallium/drivers/panfrost/pan_bo.h        | 11 +++---
>  src/gallium/drivers/panfrost/pan_context.c   |  9 ++---
>  src/gallium/drivers/panfrost/pan_job.c       |  2 +-
>  src/gallium/drivers/panfrost/pan_resource.c  |  8 ++--
>  7 files changed, 37 insertions(+), 37 deletions(-)
> 
> diff --git a/src/gallium/drivers/panfrost/pan_allocate.c b/src/gallium/drivers/panfrost/pan_allocate.c
> index bdf6f26b77b8..7938196e3e4f 100644
> --- a/src/gallium/drivers/panfrost/pan_allocate.c
> +++ b/src/gallium/drivers/panfrost/pan_allocate.c
> @@ -71,7 +71,7 @@ panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz)
>  
>                  /* Creating a BO adds a reference, and then the job adds a
>                   * second one. So we need to pop back one reference */
> -                panfrost_bo_unreference(&screen->base, bo);
> +                panfrost_bo_unreference(bo);
>  
>                  if (sz < TRANSIENT_SLAB_SIZE) {
>                          batch->transient_bo = bo;
> diff --git a/src/gallium/drivers/panfrost/pan_blend_cso.c b/src/gallium/drivers/panfrost/pan_blend_cso.c
> index 83492e1ed03d..90a1e2956a53 100644
> --- a/src/gallium/drivers/panfrost/pan_blend_cso.c
> +++ b/src/gallium/drivers/panfrost/pan_blend_cso.c
> @@ -278,7 +278,7 @@ panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
>  
>          /* Pass BO ownership to job */
>          panfrost_batch_add_bo(batch, final.shader.bo);
> -        panfrost_bo_unreference(ctx->base.screen, final.shader.bo);
> +        panfrost_bo_unreference(final.shader.bo);
>  
>          if (shader->patch_index) {
>                  /* We have to specialize the blend shader to use constants, so
> diff --git a/src/gallium/drivers/panfrost/pan_bo.c b/src/gallium/drivers/panfrost/pan_bo.c
> index 23273abc5f22..d9c4cb208bc8 100644
> --- a/src/gallium/drivers/panfrost/pan_bo.c
> +++ b/src/gallium/drivers/panfrost/pan_bo.c
> @@ -114,7 +114,7 @@ panfrost_bo_cache_fetch(
>  
>                          ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_MADVISE, &madv);
>                          if (!ret && !madv.retained) {
> -                                panfrost_bo_release(screen, entry, false);
> +                                panfrost_bo_release(entry, false);
>                                  continue;
>                          }
>                          /* Let's go! */
> @@ -131,10 +131,10 @@ panfrost_bo_cache_fetch(
>   * successful */
>  
>  static bool
> -panfrost_bo_cache_put(
> -                struct panfrost_screen *screen,
> -                struct panfrost_bo *bo)
> +panfrost_bo_cache_put(struct panfrost_bo *bo)
>  {
> +        struct panfrost_screen *screen = bo->screen;
> +
>          pthread_mutex_lock(&screen->bo_cache_lock);
>          struct list_head *bucket = pan_bucket(screen, bo->size);
>          struct drm_panfrost_madvise madv;
> @@ -168,14 +168,14 @@ panfrost_bo_cache_evict_all(
>  
>                  list_for_each_entry_safe(struct panfrost_bo, entry, bucket, link) {
>                          list_del(&entry->link);
> -                        panfrost_bo_release(screen, entry, false);
> +                        panfrost_bo_release(entry, false);
>                  }
>          }
>          pthread_mutex_unlock(&screen->bo_cache_lock);
>  }
>  
>  void
> -panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
> +panfrost_bo_mmap(struct panfrost_bo *bo)
>  {
>          struct drm_panfrost_mmap_bo mmap_bo = { .handle = bo->gem_handle };
>          int ret;
> @@ -183,14 +183,14 @@ panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
>          if (bo->cpu)
>                  return;
>  
> -        ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_MMAP_BO, &mmap_bo);
> +        ret = drmIoctl(bo->screen->fd, DRM_IOCTL_PANFROST_MMAP_BO, &mmap_bo);
>          if (ret) {
>                  fprintf(stderr, "DRM_IOCTL_PANFROST_MMAP_BO failed: %m\n");
>                  assert(0);
>          }
>  
>          bo->cpu = os_mmap(NULL, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
> -                          screen->fd, mmap_bo.offset);
> +                          bo->screen->fd, mmap_bo.offset);
>          if (bo->cpu == MAP_FAILED) {
>                  fprintf(stderr, "mmap failed: %p %m\n", bo->cpu);
>                  assert(0);
> @@ -202,7 +202,7 @@ panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
>  }
>  
>  static void
> -panfrost_bo_munmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
> +panfrost_bo_munmap(struct panfrost_bo *bo)
>  {
>          if (!bo->cpu)
>                  return;
> @@ -277,7 +277,7 @@ panfrost_bo_create(struct panfrost_screen *screen, size_t size,
>           * for GPU-internal use. But we do trace them anyway. */
>  
>          if (!(flags & (PAN_BO_INVISIBLE | PAN_BO_DELAY_MMAP)))
> -                panfrost_bo_mmap(screen, bo);
> +                panfrost_bo_mmap(bo);
>          else if (flags & PAN_BO_INVISIBLE) {
>                  if (pan_debug & PAN_DBG_TRACE)
>                          pandecode_inject_mmap(bo->gpu, NULL, bo->size, NULL);
> @@ -288,8 +288,7 @@ panfrost_bo_create(struct panfrost_screen *screen, size_t size,
>  }
>  
>  void
> -panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
> -                    bool cacheable)
> +panfrost_bo_release(struct panfrost_bo *bo, bool cacheable)
>  {
>          if (!bo)
>                  return;
> @@ -300,10 +299,10 @@ panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
>          /* Rather than freeing the BO now, we'll cache the BO for later
>           * allocations if we're allowed to */
>  
> -        panfrost_bo_munmap(screen, bo);
> +        panfrost_bo_munmap(bo);
>  
>          if (cacheable) {
> -                bool cached = panfrost_bo_cache_put(screen, bo);
> +                bool cached = panfrost_bo_cache_put(bo);
>  
>                  if (cached)
>                          return;
> @@ -311,7 +310,7 @@ panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
>  
>          /* Otherwise, if the BO wasn't cached, we'll legitimately free the BO */
>  
> -        ret = drmIoctl(screen->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
> +        ret = drmIoctl(bo->screen->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
>          if (ret) {
>                  fprintf(stderr, "DRM_IOCTL_GEM_CLOSE failed: %m\n");
>                  assert(0);
> @@ -328,7 +327,7 @@ panfrost_bo_reference(struct panfrost_bo *bo)
>  }
>  
>  void
> -panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
> +panfrost_bo_unreference(struct panfrost_bo *bo)
>  {
>          if (!bo)
>                  return;
> @@ -336,7 +335,7 @@ panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
>          /* When the reference count goes to zero, we need to cleanup */
>  
>          if (pipe_reference(&bo->reference, NULL))
> -                panfrost_bo_release(pan_screen(screen), bo, true);
> +                panfrost_bo_release(bo, true);
>  }
>  
>  struct panfrost_bo *
> @@ -354,6 +353,7 @@ panfrost_bo_import(struct panfrost_screen *screen, int fd)
>          ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_GET_BO_OFFSET, &get_bo_offset);
>          assert(!ret);
>  
> +        bo->screen = screen;
>          bo->gem_handle = gem_handle;
>          bo->gpu = (mali_ptr) get_bo_offset.offset;
>          bo->size = lseek(fd, 0, SEEK_END);
> @@ -361,19 +361,19 @@ panfrost_bo_import(struct panfrost_screen *screen, int fd)
>          pipe_reference_init(&bo->reference, 1);
>  
>          // TODO map and unmap on demand?
> -        panfrost_bo_mmap(screen, bo);
> +        panfrost_bo_mmap(bo);
>          return bo;
>  }
>  
>  int
> -panfrost_bo_export(struct panfrost_screen *screen, const struct panfrost_bo *bo)
> +panfrost_bo_export(struct panfrost_bo *bo)
>  {
>          struct drm_prime_handle args = {
>                  .handle = bo->gem_handle,
>                  .flags = DRM_CLOEXEC,
>          };
>  
> -        int ret = drmIoctl(screen->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
> +        int ret = drmIoctl(bo->screen->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
>          if (ret == -1)
>                  return -1;
>  
> diff --git a/src/gallium/drivers/panfrost/pan_bo.h b/src/gallium/drivers/panfrost/pan_bo.h
> index 5afaa0c873d3..dfdb202e5d34 100644
> --- a/src/gallium/drivers/panfrost/pan_bo.h
> +++ b/src/gallium/drivers/panfrost/pan_bo.h
> @@ -58,6 +58,8 @@ struct panfrost_bo {
>  
>          struct pipe_reference reference;
>  
> +        struct panfrost_screen *screen;
> +
>          /* Mapping for the entire object (all levels) */
>          uint8_t *cpu;
>  
> @@ -75,19 +77,18 @@ struct panfrost_bo {
>  void
>  panfrost_bo_reference(struct panfrost_bo *bo);
>  void
> -panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo);
> +panfrost_bo_unreference(struct panfrost_bo *bo);
>  struct panfrost_bo *
>  panfrost_bo_create(struct panfrost_screen *screen, size_t size,
>                     uint32_t flags);
>  void
> -panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo);
> +panfrost_bo_mmap(struct panfrost_bo *bo);
>  void
> -panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
> -                    bool cacheable);
> +panfrost_bo_release(struct panfrost_bo *bo, bool cacheable);
>  struct panfrost_bo *
>  panfrost_bo_import(struct panfrost_screen *screen, int fd);
>  int
> -panfrost_bo_export(struct panfrost_screen *screen, const struct panfrost_bo *bo);
> +panfrost_bo_export(struct panfrost_bo *bo);
>  void
>  panfrost_bo_cache_evict_all(struct panfrost_screen *screen);
>  
> diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
> index d3e08c03ffad..55fe9c264548 100644
> --- a/src/gallium/drivers/panfrost/pan_context.c
> +++ b/src/gallium/drivers/panfrost/pan_context.c
> @@ -1751,7 +1751,7 @@ panfrost_delete_shader_state(
>  
>          for (unsigned i = 0; i < cso->variant_count; ++i) {
>                  struct panfrost_shader_state *shader_state = &cso->variants[i];
> -                panfrost_bo_unreference(pctx->screen, shader_state->bo);
> +                panfrost_bo_unreference(shader_state->bo);
>                  shader_state->bo = NULL;
>          }
>  
> @@ -2418,7 +2418,6 @@ static void
>  panfrost_destroy(struct pipe_context *pipe)
>  {
>          struct panfrost_context *panfrost = pan_context(pipe);
> -        struct panfrost_screen *screen = pan_screen(pipe->screen);
>  
>          if (panfrost->blitter)
>                  util_blitter_destroy(panfrost->blitter);
> @@ -2426,9 +2425,9 @@ panfrost_destroy(struct pipe_context *pipe)
>          if (panfrost->blitter_wallpaper)
>                  util_blitter_destroy(panfrost->blitter_wallpaper);
>  
> -        panfrost_bo_release(screen, panfrost->scratchpad, false);
> -        panfrost_bo_release(screen, panfrost->tiler_heap, false);
> -        panfrost_bo_release(screen, panfrost->tiler_dummy, false);
> +        panfrost_bo_release(panfrost->scratchpad, false);
> +        panfrost_bo_release(panfrost->tiler_heap, false);
> +        panfrost_bo_release(panfrost->tiler_dummy, false);
>  
>          ralloc_free(pipe);
>  }
> diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
> index 80ed730944b7..4ffc990a5334 100644
> --- a/src/gallium/drivers/panfrost/pan_job.c
> +++ b/src/gallium/drivers/panfrost/pan_job.c
> @@ -69,7 +69,7 @@ panfrost_free_batch(struct panfrost_batch *batch)
>  
>          set_foreach(batch->bos, entry) {
>                  struct panfrost_bo *bo = (struct panfrost_bo *)entry->key;
> -                panfrost_bo_unreference(ctx->base.screen, bo);
> +                panfrost_bo_unreference(bo);
>          }
>  
>          _mesa_hash_table_remove_key(ctx->batches, &batch->key);
> diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
> index 7083ee37bae2..1e8a1eadb51d 100644
> --- a/src/gallium/drivers/panfrost/pan_resource.c
> +++ b/src/gallium/drivers/panfrost/pan_resource.c
> @@ -134,7 +134,7 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen,
>  
>                          return true;
>                  } else {
> -                        int fd = panfrost_bo_export(screen, rsrc->bo);
> +                        int fd = panfrost_bo_export(rsrc->bo);
>  
>                          if (fd < 0)
>                                  return false;
> @@ -533,7 +533,7 @@ panfrost_resource_destroy(struct pipe_screen *screen,
>                  renderonly_scanout_destroy(rsrc->scanout, pscreen->ro);
>  
>          if (rsrc->bo)
> -                panfrost_bo_unreference(screen, rsrc->bo);
> +                panfrost_bo_unreference(rsrc->bo);
>  
>          util_range_destroy(&rsrc->valid_buffer_range);
>          ralloc_free(rsrc);
> @@ -561,7 +561,7 @@ panfrost_transfer_map(struct pipe_context *pctx,
>          *out_transfer = &transfer->base;
>  
>          /* If we haven't already mmaped, now's the time */
> -        panfrost_bo_mmap(pan_screen(pctx->screen), bo);
> +        panfrost_bo_mmap(bo);
>  
>          /* Check if we're bound for rendering and this is a read pixels. If so,
>           * we need to flush */
> @@ -839,7 +839,7 @@ panfrost_resource_hint_layout(
>  
>          /* If we grew in size, reallocate the BO */
>          if (new_size > rsrc->bo->size) {
> -                panfrost_bo_release(screen, rsrc->bo, true);
> +                panfrost_bo_release(rsrc->bo, true);
>                  rsrc->bo = panfrost_bo_create(screen, new_size, PAN_BO_DELAY_MMAP);
>          }
>  }
> -- 
> 2.21.0


More information about the mesa-dev mailing list