util/hash_table: update users to use new optimal integer hash functions
[mesa.git] / src / gallium / drivers / vc4 / vc4_cl.c
index 29b956e6e9a8bd0af294e1a4fd5673f59d3c1e8d..7ae092ebce3091191a2fce5c5870d8c919df5102 100644 (file)
  */
 
 #include "util/u_math.h"
+#include "util/ralloc.h"
 #include "vc4_context.h"
 
 void
-vc4_init_cl(struct vc4_context *vc4, struct vc4_cl *cl)
+vc4_init_cl(struct vc4_job *job, struct vc4_cl *cl)
 {
+        cl->base = rzalloc_size(job, 1); /* TODO: don't use rzalloc */
+        cl->next = cl->base;
+        cl->size = 0;
+        cl->job = job;
 }
 
 void
-vc4_grow_cl(struct vc4_cl *cl)
+cl_ensure_space(struct vc4_cl *cl, uint32_t space)
 {
-        uint32_t size = MAX2((cl->end - cl->base) * 2, 4096);
-        uint32_t offset = cl->next -cl->base;
+        uint32_t offset = cl_offset(cl);
+
+        if (offset + space <= cl->size)
+                return;
 
-        cl->base = realloc(cl->base, size);
-        cl->end = cl->base + size;
+        uint32_t size = MAX2(cl->size + space, cl->size * 2);
+
+        cl->base = reralloc(ralloc_parent(cl->base), cl->base, uint8_t, size);
+        cl->size = size;
         cl->next = cl->base + offset;
 }
 
@@ -48,20 +57,37 @@ vc4_reset_cl(struct vc4_cl *cl)
 }
 
 uint32_t
-vc4_gem_hindex(struct vc4_context *vc4, struct vc4_bo *bo)
+vc4_gem_hindex(struct vc4_job *job, struct vc4_bo *bo)
 {
         uint32_t hindex;
-        uint32_t *current_handles = vc4->bo_handles.base;
+        uint32_t *current_handles = job->bo_handles.base;
+        uint32_t cl_hindex_count = cl_offset(&job->bo_handles) / 4;
+        uint32_t last_hindex = bo->last_hindex; /* volatile read! */
+
+        if (last_hindex < cl_hindex_count &&
+            current_handles[last_hindex] == bo->handle) {
+                return last_hindex;
+        }
 
-        for (hindex = 0;
-             hindex < (vc4->bo_handles.next - vc4->bo_handles.base) / 4;
-             hindex++) {
-                if (current_handles[hindex] == bo->handle)
+        for (hindex = 0; hindex < cl_hindex_count; hindex++) {
+                if (current_handles[hindex] == bo->handle) {
+                        bo->last_hindex = hindex;
                         return hindex;
+                }
         }
 
-        cl_u32(&vc4->bo_handles, bo->handle);
-        cl_ptr(&vc4->bo_pointers, vc4_bo_reference(bo));
+        struct vc4_cl_out *out;
+
+        out = cl_start(&job->bo_handles);
+        cl_u32(&out, bo->handle);
+        cl_end(&job->bo_handles, out);
+
+        out = cl_start(&job->bo_pointers);
+        cl_ptr(&out, vc4_bo_reference(bo));
+        cl_end(&job->bo_pointers, out);
+
+        job->bo_space += bo->size;
 
+        bo->last_hindex = hindex;
         return hindex;
 }