[Mesa-dev] [PATCH v2 12/25] winsys/amdgpu: extract amdgpu_do_add_real_buffer

Nicolai Hähnle nhaehnle at gmail.com
Tue Mar 28 09:12:02 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

We will use it for delayed adding of sparse buffers' backing buffers.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
---
 src/gallium/winsys/amdgpu/drm/amdgpu_cs.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
index cdd8e6c..0381359 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
@@ -308,44 +308,39 @@ int amdgpu_lookup_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *
           * will collide here: ^ and here:   ^,
           * meaning that we should get very few collisions in the end. */
          cs->buffer_indices_hashlist[hash] = i;
          return i;
       }
    }
    return -1;
 }
 
 static int
-amdgpu_lookup_or_add_real_buffer(struct amdgpu_cs *acs, struct amdgpu_winsys_bo *bo)
+amdgpu_do_add_real_buffer(struct amdgpu_cs_context *cs, struct amdgpu_winsys_bo *bo)
 {
-   struct amdgpu_cs_context *cs = acs->csc;
    struct amdgpu_cs_buffer *buffer;
-   unsigned hash;
-   int idx = amdgpu_lookup_buffer(cs, bo);
-
-   if (idx >= 0)
-      return idx;
+   int idx;
 
    /* New buffer, check if the backing array is large enough. */
    if (cs->num_real_buffers >= cs->max_real_buffers) {
       unsigned new_max =
          MAX2(cs->max_real_buffers + 16, (unsigned)(cs->max_real_buffers * 1.3));
       struct amdgpu_cs_buffer *new_buffers;
       amdgpu_bo_handle *new_handles;
       uint8_t *new_flags;
 
       new_buffers = MALLOC(new_max * sizeof(*new_buffers));
       new_handles = MALLOC(new_max * sizeof(*new_handles));
       new_flags = MALLOC(new_max * sizeof(*new_flags));
 
       if (!new_buffers || !new_handles || !new_flags) {
-         fprintf(stderr, "amdgpu_lookup_or_add_buffer: allocation failed\n");
+         fprintf(stderr, "amdgpu_do_add_buffer: allocation failed\n");
          FREE(new_buffers);
          FREE(new_handles);
          FREE(new_flags);
          return -1;
       }
 
       memcpy(new_buffers, cs->real_buffers, cs->num_real_buffers * sizeof(*new_buffers));
       memcpy(new_handles, cs->handles, cs->num_real_buffers * sizeof(*new_handles));
       memcpy(new_flags, cs->flags, cs->num_real_buffers * sizeof(*new_flags));
 
@@ -362,20 +357,35 @@ amdgpu_lookup_or_add_real_buffer(struct amdgpu_cs *acs, struct amdgpu_winsys_bo
    idx = cs->num_real_buffers;
    buffer = &cs->real_buffers[idx];
 
    memset(buffer, 0, sizeof(*buffer));
    amdgpu_winsys_bo_reference(&buffer->bo, bo);
    cs->handles[idx] = bo->bo;
    cs->flags[idx] = 0;
    p_atomic_inc(&bo->num_cs_references);
    cs->num_real_buffers++;
 
+   return idx;
+}
+
+static int
+amdgpu_lookup_or_add_real_buffer(struct amdgpu_cs *acs, struct amdgpu_winsys_bo *bo)
+{
+   struct amdgpu_cs_context *cs = acs->csc;
+   unsigned hash;
+   int idx = amdgpu_lookup_buffer(cs, bo);
+
+   if (idx >= 0)
+      return idx;
+
+   idx = amdgpu_do_add_real_buffer(cs, bo);
+
    hash = bo->unique_id & (ARRAY_SIZE(cs->buffer_indices_hashlist)-1);
    cs->buffer_indices_hashlist[hash] = idx;
 
    if (bo->initial_domain & RADEON_DOMAIN_VRAM)
       acs->main.base.used_vram += bo->base.size;
    else if (bo->initial_domain & RADEON_DOMAIN_GTT)
       acs->main.base.used_gart += bo->base.size;
 
    return idx;
 }
-- 
2.9.3



More information about the mesa-dev mailing list