etnaviv: Use hash table to track BO indexes
[mesa.git] / src / etnaviv / drm / etnaviv_cmd_stream.c
index e591df297a3ea9068cbbd9b3a8c453e88fc308c3..894ad603c0808c09637e68def2cb8f4c8defd75c 100644 (file)
@@ -153,14 +153,20 @@ static uint32_t bo2idx(struct etna_cmd_stream *stream, struct etna_bo *bo,
        if (bo->current_stream == stream) {
                idx = bo->idx;
        } else {
-               /* slow-path: */
-               for (idx = 0; idx < priv->nr_bos; idx++)
-                       if (priv->bos[idx] == bo)
-                               break;
-               if (idx == priv->nr_bos) {
-                       /* not found */
+               void *val;
+
+               if (!priv->bo_table)
+                       priv->bo_table = drmHashCreate();
+
+               if (!drmHashLookup(priv->bo_table, bo->handle, &val)) {
+                       /* found */
+                       idx = (uint32_t)(uintptr_t)val;
+               } else {
                        idx = append_bo(stream, bo);
+                       val = (void *)(uintptr_t)idx;
+                       drmHashInsert(priv->bo_table, bo->handle, val);
                }
+
                bo->current_stream = stream;
                bo->idx = idx;
        }
@@ -217,6 +223,11 @@ static void flush(struct etna_cmd_stream *stream, int in_fence_fd,
                etna_bo_del(bo);
        }
 
+       if (priv->bo_table) {
+               drmHashDestroy(priv->bo_table);
+               priv->bo_table = NULL;
+       }
+
        if (out_fence_fd)
                *out_fence_fd = req.fence_fd;
 }