On Fri, Jun 13, 2014 at 10:35:33PM +0200, Bruno Jiménez wrote:
Reviewed-by: Tom Stellard
> ---
> src/gallium/drivers/r600/compute_memory_pool.c | 140
> +++--
> src/gallium/drivers/r600/compute_memory_pool.h | 5 +
> 2 files changed, 87 insertions(+), 58 deletions(-)
>
> diff --git a/src/gallium/drivers/r600/compute_memory_pool.c
> b/src/gallium/drivers/r600/compute_memory_pool.c
> index 5a5ef12..1da4609 100644
> --- a/src/gallium/drivers/r600/compute_memory_pool.c
> +++ b/src/gallium/drivers/r600/compute_memory_pool.c
> @@ -229,8 +229,6 @@ int compute_memory_finalize_pending(struct
> compute_memory_pool* pool,
> int64_t allocated = 0;
> int64_t unallocated = 0;
>
> - int64_t start_in_dw = 0;
> -
> int err = 0;
>
> COMPUTE_DBG(pool->screen, "* compute_memory_finalize_pending()\n");
> @@ -247,10 +245,12 @@ int compute_memory_finalize_pending(struct
> compute_memory_pool* pool,
> allocated += align(item->size_in_dw, ITEM_ALIGNMENT);
> }
>
> - /* Calculate the total unallocated size */
> + /* Calculate the total unallocated size of the items that
> + * will be promoted to the pool */
> for (item = pool->unallocated_list; item; item = next) {
> next = item->next;
> - unallocated += align(item->size_in_dw, ITEM_ALIGNMENT);
> + if (item->status & ITEM_FOR_PROMOTING)
> + unallocated += align(item->size_in_dw, ITEM_ALIGNMENT);
> }
>
> /* If we require more space than the size of the pool, then grow the
> @@ -276,83 +276,107 @@ int compute_memory_finalize_pending(struct
> compute_memory_pool* pool,
> return -1;
> }
>
> - /* Loop through all the unallocated items, allocate space for them
> - * and add them to the item_list. */
> + /* Loop through all the unallocated items, check if they are marked
> + * for promoting, allocate space for them and add them to the
> item_list. */
> for (item = pool->unallocated_list; item; item = next) {
> next = item->next;
>
> - /* 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) {
> - need = pool->size_in_dw / 10;
> - }
> + if (item->status & ITEM_FOR_PROMOTING) {
> + err = compute_memory_promote_item(pool, item, pipe,
> allocated);
> + item->status ^= ITEM_FOR_PROMOTING;
>
> - need = align(need, ITEM_ALIGNMENT);
> -
> - err = compute_memory_grow_pool(pool,
> - pipe,
> - pool->size_in_dw + need);
> + allocated += align(item->size_in_dw, ITEM_ALIGNMENT);
>
> if (err == -1)
> return -1;
> }
> - COMPUTE_DBG(pool->screen, " + Found space for Item %p id = %u "
> + }
> +
> + return 0;
> +}
> +
> +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;
> + 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) {
> + need = pool->size_in_dw / 10;
> + }
> +
> + need = align(need, ITEM_ALIGNMENT);
> +
> + err = compute_memory_grow_pool(pool,
> + pipe,
> + pool->size_in_dw + need);
> +
> + if (err == -1)
> + return -1;
> + }
> + 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,
> item->size_in_dw, item->size_in_dw * 4);
>
> - item->start_in_dw = start_in_dw;
> - item->next = NULL;
> - item->prev = NULL;
> -
> - if (pool->item_list) {
> - struct compute_memory_item *pos;
> -
> - pos = compute_memory_postalloc_chunk(pool, start_in_dw);
> - if (pos) {
> - item->pre