diff options
author | Bruno Jiménez <[email protected]> | 2014-06-18 17:01:57 +0200 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2014-06-20 13:44:04 -0400 |
commit | 9b933b73a9baf6031e5974fc2aa76011a50949d3 (patch) | |
tree | e70c55394791ca22c6f75f0c276468d0b0a082a3 | |
parent | 0b8c29915ba9451e57b256a3c7e0abb986739937 (diff) |
r600g/compute: Implement compute_memory_demote_item
This function will be used when we want to map an item
that it's already in the pool.
v2: Use temporary variables to avoid so many castings in functions,
as suggested by Tom Stellard
Reviewed-by: Tom Stellard <[email protected]>
-rw-r--r-- | src/gallium/drivers/r600/compute_memory_pool.c | 51 | ||||
-rw-r--r-- | src/gallium/drivers/r600/compute_memory_pool.h | 3 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/gallium/drivers/r600/compute_memory_pool.c b/src/gallium/drivers/r600/compute_memory_pool.c index f232f9fbc4f..6409b349cd0 100644 --- a/src/gallium/drivers/r600/compute_memory_pool.c +++ b/src/gallium/drivers/r600/compute_memory_pool.c @@ -387,6 +387,57 @@ int compute_memory_promote_item(struct compute_memory_pool *pool, return 0; } +void compute_memory_demote_item(struct compute_memory_pool *pool, + struct compute_memory_item *item, struct pipe_context *pipe) +{ + struct r600_context *rctx = (struct r600_context *)pipe; + struct pipe_resource *src = (struct pipe_resource *)pool->bo; + struct pipe_resource *dst; + struct pipe_box box; + + /* First, we remove the item from the item_list */ + if (item->prev == NULL) + pool->item_list = item->next; + else + item->prev->next = item->next; + + if (item->next != NULL) + item->next->prev = item->prev; + + + /* Now we add it to the beginning of the unallocated list + * NOTE: we could also add it to the end, but this is easier */ + item->next = NULL; + item->prev = NULL; + if (pool->unallocated_list) { + item->next = pool->unallocated_list; + item->next->prev = item; + pool->unallocated_list = item; + } + else + pool->unallocated_list = item; + + /* We check if the intermediate buffer exists, and if it + * doesn't, we create it again */ + if (item->real_buffer == NULL) { + item->real_buffer = (struct r600_resource*)r600_compute_buffer_alloc_vram( + pool->screen, item->size_in_dw * 4); + } + + dst = (struct pipe_resource *)item->real_buffer; + + /* We transfer the memory from the item in the pool to the + * temporary buffer */ + u_box_1d(item->start_in_dw * 4, item->size_in_dw * 4, &box); + + rctx->b.b.resource_copy_region(pipe, + dst, 0, 0, 0, 0, + src, 0, &box); + + /* Remember to mark the buffer as 'pending' by setting start_in_dw to -1 */ + item->start_in_dw = -1; +} + void compute_memory_free(struct compute_memory_pool* pool, int64_t id) { struct compute_memory_item *item, *next; diff --git a/src/gallium/drivers/r600/compute_memory_pool.h b/src/gallium/drivers/r600/compute_memory_pool.h index faadeea1dc1..0bb695c2b65 100644 --- a/src/gallium/drivers/r600/compute_memory_pool.h +++ b/src/gallium/drivers/r600/compute_memory_pool.h @@ -90,6 +90,9 @@ int compute_memory_promote_item(struct compute_memory_pool *pool, struct compute_memory_item *item, struct pipe_context *pipe, int64_t allocated); +void compute_memory_demote_item(struct compute_memory_pool *pool, + struct compute_memory_item *item, struct pipe_context *pipe); + void compute_memory_free(struct compute_memory_pool* pool, int64_t id); struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* pool, int64_t size_in_dw); ///Creates pending allocations |