panfrost: Stop passing screen around for BO operations
authorBoris Brezillon <boris.brezillon@collabora.com>
Sat, 14 Sep 2019 08:35:47 +0000 (10:35 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Wed, 18 Sep 2019 08:34:27 +0000 (10:34 +0200)
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@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_allocate.c
src/gallium/drivers/panfrost/pan_blend_cso.c
src/gallium/drivers/panfrost/pan_bo.c
src/gallium/drivers/panfrost/pan_bo.h
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_job.c
src/gallium/drivers/panfrost/pan_resource.c

index bdf6f26b77b88da22af7e69a88ec2aa481092641..7938196e3e4f321329a4feb4e4deecb302ea5e7a 100644 (file)
@@ -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;
index 83492e1ed03d6a3665dd0d4fa838b83a98ee42e8..90a1e2956a532a0159ed9e7f59108708a42ddab7 100644 (file)
@@ -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
index 23273abc5f22cf7275078a9abf6ba012a7e014b1..d9c4cb208bc83dc218ed3d230a9db0ff34cd1e0e 100644 (file)
@@ -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;
 
index 5afaa0c873d3ba1403e6370316b85397da6926d2..dfdb202e5d34c107f9fc16406aae55a24efaa3ff 100644 (file)
@@ -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);
 
index d3e08c03ffadb112c9a2423e53d8b1fcc01b5577..55fe9c2645481699401e8ba358a6c3211a40db70 100644 (file)
@@ -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);
 }
index 80ed730944b7d5f8316b07c2fc572f467f9f47f1..4ffc990a5334ce581fe6f8878446087bfce1751b 100644 (file)
@@ -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);
index 7083ee37bae25e8e38363854a58d4460ac2aab64..1e8a1eadb51d6d41b8674f67ab52268bdabdc022 100644 (file)
@@ -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);
         }
 }