r600g/compute: Remove unneeded code from compute_memory_promote_item
authorBruno Jiménez <brunojimen@gmail.com>
Wed, 16 Jul 2014 21:12:47 +0000 (23:12 +0200)
committerTom Stellard <thomas.stellard@amd.com>
Wed, 23 Jul 2014 14:29:17 +0000 (10:29 -0400)
Now that we know that the pool is defragmented, we positively know
that allocated + unallocated will be the total size of the
current pool plus all the items that will be promoted. So we only
need to grow the pool once.

This will allow us to just add the new items to the end of the
item_list without the need of looking for a place to the new item.

Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
src/gallium/drivers/r600/compute_memory_pool.c
src/gallium/drivers/r600/compute_memory_pool.h

index 75a8bd30dd750c0f944ef7162942e95540abd46a..04aaac92a4aa24c9498304f433a4e4ae41d65b91 100644 (file)
@@ -239,6 +239,7 @@ int compute_memory_finalize_pending(struct compute_memory_pool* pool,
 
        int64_t allocated = 0;
        int64_t unallocated = 0;
+       int64_t last_pos;
 
        int err = 0;
 
@@ -276,14 +277,18 @@ int compute_memory_finalize_pending(struct compute_memory_pool* pool,
                        return -1;
        }
 
+       /* After defragmenting the pool, allocated is equal to the first available
+        * position for new items in the pool */
+       last_pos = allocated;
+
        /* Loop through all the unallocated items, check if they are marked
         * for promoting, allocate space for them and add them to the item_list. */
        LIST_FOR_EACH_ENTRY_SAFE(item, next, pool->unallocated_list, link) {
                if (item->status & ITEM_FOR_PROMOTING) {
-                       err = compute_memory_promote_item(pool, item, pipe, allocated);
-                       item->status ^= ITEM_FOR_PROMOTING;
+                       err = compute_memory_promote_item(pool, item, pipe, last_pos);
+                       item->status &= ~ITEM_FOR_PROMOTING;
 
-                       allocated += align(item->size_in_dw, ITEM_ALIGNMENT);
+                       last_pos += align(item->size_in_dw, ITEM_ALIGNMENT);
 
                        if (err == -1)
                                return -1;
@@ -321,42 +326,14 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
 
 int compute_memory_promote_item(struct compute_memory_pool *pool,
                struct compute_memory_item *item, struct pipe_context *pipe,
-               int64_t allocated)
+               int64_t start_in_dw)
 {
        struct pipe_screen *screen = (struct pipe_screen *)pool->screen;
        struct r600_context *rctx = (struct r600_context *)pipe;
        struct pipe_resource *src = (struct pipe_resource *)item->real_buffer;
-       struct pipe_resource *dst = NULL;
+       struct pipe_resource *dst = (struct pipe_resource *)pool->bo;
        struct pipe_box box;
 
-       struct list_head *pos;
-       int64_t start_in_dw;
-       int err = 0;
-
-
-       /* Search for free space in the pool for this item. */
-       while ((start_in_dw=compute_memory_prealloc_chunk(pool,
-                                       item->size_in_dw)) == -1) {
-               int64_t need = item->size_in_dw + 2048 -
-                       (pool->size_in_dw - allocated);
-
-               if (need <= 0) {
-                       /* There's enough free space, but it's too
-                        * fragmented. Assume half of the item can fit
-                        * int the last chunk */
-                       need = (item->size_in_dw / 2) + ITEM_ALIGNMENT;
-               }
-
-               need = align(need, ITEM_ALIGNMENT);
-
-               err = compute_memory_grow_pool(pool,
-                               pipe,
-                               pool->size_in_dw + need);
-
-               if (err == -1)
-                       return -1;
-       }
-       dst = (struct pipe_resource *)pool->bo;
        COMPUTE_DBG(pool->screen, "  + Found space for Item %p id = %u "
                        "start_in_dw = %u (%u bytes) size_in_dw = %u (%u bytes)\n",
                        item, item->id, start_in_dw, start_in_dw * 4,
@@ -366,8 +343,7 @@ int compute_memory_promote_item(struct compute_memory_pool *pool,
        list_del(&item->link);
 
        /* Add it back to the item_list */
-       pos = compute_memory_postalloc_chunk(pool, start_in_dw);
-       list_add(&item->link, pos);
+       list_addtail(&item->link, pool->item_list);
        item->start_in_dw = start_in_dw;
 
        if (src != NULL) {
index acc68ea172f56011e9483b3f09c5fde4edb6cbf1..5a1b33bab281032ab6844fbf562ac53f946f894d 100644 (file)
@@ -95,7 +95,7 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
 
 int compute_memory_promote_item(struct compute_memory_pool *pool,
                struct compute_memory_item *item, struct pipe_context *pipe,
-               int64_t allocated);
+               int64_t start_in_dw);
 
 void compute_memory_demote_item(struct compute_memory_pool *pool,
        struct compute_memory_item *item, struct pipe_context *pipe);