[Mesa-dev] [PATCH 11/12] winsys/radeon: don't pre-allocate the relocations array

Nicolai Hähnle nhaehnle at gmail.com
Fri Sep 9 17:34:13 UTC 2016


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

It's really not necessary. Switch to an exponential resizing strategy.
---
 src/gallium/winsys/radeon/drm/radeon_drm_cs.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
index 612a876..f0dcac0 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
@@ -91,33 +91,20 @@ static void radeon_drm_ctx_destroy(struct radeon_winsys_ctx *ctx)
 {
     /* No context support here. */
 }
 
 static bool radeon_init_cs_context(struct radeon_cs_context *csc,
                                    struct radeon_drm_winsys *ws)
 {
     int i;
 
     csc->fd = ws->fd;
-    csc->nrelocs = 512;
-    csc->relocs_bo = (struct radeon_bo_item*)
-                     CALLOC(1, csc->nrelocs * sizeof(csc->relocs_bo[0]));
-    if (!csc->relocs_bo) {
-        return false;
-    }
-
-    csc->relocs = (struct drm_radeon_cs_reloc*)
-                  CALLOC(1, csc->nrelocs * sizeof(struct drm_radeon_cs_reloc));
-    if (!csc->relocs) {
-        FREE(csc->relocs_bo);
-        return false;
-    }
 
     csc->chunks[0].chunk_id = RADEON_CHUNK_ID_IB;
     csc->chunks[0].length_dw = 0;
     csc->chunks[0].chunk_data = (uint64_t)(uintptr_t)csc->buf;
     csc->chunks[1].chunk_id = RADEON_CHUNK_ID_RELOCS;
     csc->chunks[1].length_dw = 0;
     csc->chunks[1].chunk_data = (uint64_t)(uintptr_t)csc->relocs;
     csc->chunks[2].chunk_id = RADEON_CHUNK_ID_FLAGS;
     csc->chunks[2].length_dw = 2;
     csc->chunks[2].chunk_data = (uint64_t)(uintptr_t)&csc->flags;
@@ -280,21 +267,21 @@ static unsigned radeon_add_buffer(struct radeon_drm_cs *cs,
          * because there is no offset patching with virtual memory.
          */
         if (cs->ring_type != RING_DMA || cs->ws->info.has_virtual_memory) {
             return i;
         }
     }
 
     /* New relocation, check if the backing array is large enough. */
     if (csc->crelocs >= csc->nrelocs) {
         uint32_t size;
-        csc->nrelocs += 10;
+        csc->nrelocs = MAX2(csc->nrelocs + 16, (unsigned)(csc->nrelocs * 1.3));
 
         size = csc->nrelocs * sizeof(csc->relocs_bo[0]);
         csc->relocs_bo = realloc(csc->relocs_bo, size);
 
         size = csc->nrelocs * sizeof(struct drm_radeon_cs_reloc);
         csc->relocs = realloc(csc->relocs, size);
 
         csc->chunks[1].chunk_data = (uint64_t)(uintptr_t)csc->relocs;
     }
 
-- 
2.7.4



More information about the mesa-dev mailing list