freedreno/drm: Consider allocation flags in bo-cache
authorRob Clark <robdclark@chromium.org>
Fri, 18 Jun 2021 16:58:11 +0000 (09:58 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 17 Sep 2021 18:24:34 +0000 (18:24 +0000)
It hasn't really mattered until now, as we keep a separate cache for
cmdstream (which is FD_BO_GPU_READONLY), and the only other flag so
far is FD_BO_SCANOUT (which the bo cache probably messes up, but it
does not matter on most hw, and on hw where it does the scanout buffer
will be imported (and therefore won't end up in the bo cache).

But when we add cached-coherent (or if we wanted to use GPU_READONLY
more) it starts to matter.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11176>

src/freedreno/drm/freedreno_bo.c
src/freedreno/drm/freedreno_bo_cache.c
src/freedreno/drm/freedreno_priv.h

index 8ff1070..b9eab54 100644 (file)
@@ -106,6 +106,7 @@ bo_new(struct fd_device *dev, uint32_t size, uint32_t flags,
    bo = bo_from_handle(dev, size, handle);
    simple_mtx_unlock(&table_lock);
 
+   bo->alloc_flags = flags;
    bo->max_fences = 1;
    bo->fences = &bo->_inline_fence;
 
index 618f4b1..dbc21a6 100644 (file)
@@ -135,13 +135,13 @@ find_in_bucket(struct fd_bo_bucket *bucket, uint32_t flags)
     * (MRU, since likely to be in GPU cache), rather than head (LRU)..
     */
    simple_mtx_lock(&table_lock);
-   if (!list_is_empty(&bucket->list)) {
-      bo = LIST_ENTRY(struct fd_bo, bucket->list.next, list);
-      /* TODO check for compatible flags? */
-      if (fd_bo_state(bo) == FD_BO_STATE_IDLE) {
+   list_for_each_entry (struct fd_bo, entry, &bucket->list, list) {
+      if (fd_bo_state(entry) != FD_BO_STATE_IDLE)
+         break;
+      if (entry->alloc_flags == flags) {
+         bo = entry;
          list_del(&bo->list);
-      } else {
-         bo = NULL;
+         break;
       }
    }
    simple_mtx_unlock(&table_lock);
index dab9296..8e8523a 100644 (file)
@@ -285,6 +285,7 @@ struct fd_bo {
    uint32_t name;
    int32_t refcnt;
    uint32_t reloc_flags; /* flags like FD_RELOC_DUMP to use for relocs to this BO */
+   uint32_t alloc_flags; /* flags that control allocation/mapping, ie. FD_BO_x */
    uint64_t iova;
    void *map;
    const struct fd_bo_funcs *funcs;