r600g/compute: divide the item list in two
Now we will have a list with the items that are in the pool (item_list) and the items that are outside it (unallocated_list) Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
This commit is contained in:
parent
e3dfe3f7b2
commit
4d1e4429e6
|
@ -108,14 +108,12 @@ int64_t compute_memory_prealloc_chunk(
|
||||||
size_in_dw);
|
size_in_dw);
|
||||||
|
|
||||||
for (item = pool->item_list; item; item = item->next) {
|
for (item = pool->item_list; item; item = item->next) {
|
||||||
if (item->start_in_dw > -1) {
|
|
||||||
if (last_end + size_in_dw <= item->start_in_dw) {
|
if (last_end + size_in_dw <= item->start_in_dw) {
|
||||||
return last_end;
|
return last_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_end = item->start_in_dw + align(item->size_in_dw, ITEM_ALIGNMENT);
|
last_end = item->start_in_dw + align(item->size_in_dw, ITEM_ALIGNMENT);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (pool->size_in_dw - last_end < size_in_dw) {
|
if (pool->size_in_dw - last_end < size_in_dw) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -226,7 +224,6 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
|
||||||
int compute_memory_finalize_pending(struct compute_memory_pool* pool,
|
int compute_memory_finalize_pending(struct compute_memory_pool* pool,
|
||||||
struct pipe_context * pipe)
|
struct pipe_context * pipe)
|
||||||
{
|
{
|
||||||
struct compute_memory_item *pending_list = NULL, *end_p = NULL;
|
|
||||||
struct compute_memory_item *item, *next;
|
struct compute_memory_item *item, *next;
|
||||||
|
|
||||||
int64_t allocated = 0;
|
int64_t allocated = 0;
|
||||||
|
@ -244,45 +241,16 @@ int compute_memory_finalize_pending(struct compute_memory_pool* pool,
|
||||||
item->size_in_dw, item->size_in_dw * 4);
|
item->size_in_dw, item->size_in_dw * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search through the list of memory items in the pool */
|
/* Calculate the total allocated size */
|
||||||
for (item = pool->item_list; item; item = next) {
|
for (item = pool->item_list; item; item = next) {
|
||||||
next = item->next;
|
next = item->next;
|
||||||
|
allocated += align(item->size_in_dw, ITEM_ALIGNMENT);
|
||||||
/* Check if the item is pending. */
|
|
||||||
if (item->start_in_dw == -1) {
|
|
||||||
/* It is pending, so add it to the pending_list... */
|
|
||||||
if (end_p) {
|
|
||||||
end_p->next = item;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pending_list = item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... and then remove it from the item list. */
|
/* Calculate the total unallocated size */
|
||||||
if (item->prev) {
|
for (item = pool->unallocated_list; item; item = next) {
|
||||||
item->prev->next = next;
|
next = item->next;
|
||||||
}
|
unallocated += align(item->size_in_dw, ITEM_ALIGNMENT);
|
||||||
else {
|
|
||||||
pool->item_list = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next) {
|
|
||||||
next->prev = item->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This sequence makes the item be at the end of the list */
|
|
||||||
item->prev = end_p;
|
|
||||||
item->next = NULL;
|
|
||||||
end_p = item;
|
|
||||||
|
|
||||||
/* Update the amount of space we will need to allocate. */
|
|
||||||
unallocated += item->size_in_dw+1024;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* The item is not pending, so update the amount of space
|
|
||||||
* that has already been allocated. */
|
|
||||||
allocated += item->size_in_dw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we require more space than the size of the pool, then grow the
|
/* If we require more space than the size of the pool, then grow the
|
||||||
|
@ -308,9 +276,9 @@ int compute_memory_finalize_pending(struct compute_memory_pool* pool,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop through all the pending items, allocate space for them and
|
/* Loop through all the unallocated items, allocate space for them
|
||||||
* add them back to the item_list. */
|
* and add them to the item_list. */
|
||||||
for (item = pending_list; item; item = next) {
|
for (item = pool->unallocated_list; item; item = next) {
|
||||||
next = item->next;
|
next = item->next;
|
||||||
|
|
||||||
struct pipe_screen *screen = (struct pipe_screen *)pool->screen;
|
struct pipe_screen *screen = (struct pipe_screen *)pool->screen;
|
||||||
|
@ -383,6 +351,8 @@ int compute_memory_finalize_pending(struct compute_memory_pool* pool,
|
||||||
allocated += item->size_in_dw;
|
allocated += item->size_in_dw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pool->unallocated_list = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,6 +392,33 @@ void compute_memory_free(struct compute_memory_pool* pool, int64_t id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (item = pool->unallocated_list; item; item = next) {
|
||||||
|
next = item->next;
|
||||||
|
|
||||||
|
if (item->id == id) {
|
||||||
|
if (item->prev) {
|
||||||
|
item->prev->next = item->next;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pool->unallocated_list = item->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item->next) {
|
||||||
|
item->next->prev = item->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item->real_buffer) {
|
||||||
|
res = (struct pipe_resource *)item->real_buffer;
|
||||||
|
pool->screen->b.b.resource_destroy(
|
||||||
|
screen, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(item);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Internal error, invalid id %"PRIi64" "
|
fprintf(stderr, "Internal error, invalid id %"PRIi64" "
|
||||||
"for compute_memory_free\n", id);
|
"for compute_memory_free\n", id);
|
||||||
|
|
||||||
|
@ -452,15 +449,15 @@ struct compute_memory_item* compute_memory_alloc(
|
||||||
new_item->real_buffer = (struct r600_resource*)r600_compute_buffer_alloc_vram(
|
new_item->real_buffer = (struct r600_resource*)r600_compute_buffer_alloc_vram(
|
||||||
pool->screen, size_in_dw * 4);
|
pool->screen, size_in_dw * 4);
|
||||||
|
|
||||||
if (pool->item_list) {
|
if (pool->unallocated_list) {
|
||||||
for (last_item = pool->item_list; last_item->next;
|
for (last_item = pool->unallocated_list; last_item->next;
|
||||||
last_item = last_item->next);
|
last_item = last_item->next);
|
||||||
|
|
||||||
last_item->next = new_item;
|
last_item->next = new_item;
|
||||||
new_item->prev = last_item;
|
new_item->prev = last_item;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pool->item_list = new_item;
|
pool->unallocated_list = new_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPUTE_DBG(pool->screen, " + Adding item %p id = %u size = %u (%u bytes)\n",
|
COMPUTE_DBG(pool->screen, " + Adding item %p id = %u size = %u (%u bytes)\n",
|
||||||
|
|
|
@ -58,6 +58,7 @@ struct compute_memory_pool
|
||||||
|
|
||||||
struct r600_resource *bo; ///The pool buffer object resource
|
struct r600_resource *bo; ///The pool buffer object resource
|
||||||
struct compute_memory_item* item_list; ///Allocated memory chunks in the buffer,they must be ordered by "start_in_dw"
|
struct compute_memory_item* item_list; ///Allocated memory chunks in the buffer,they must be ordered by "start_in_dw"
|
||||||
|
struct compute_memory_item* unallocated_list; ///Unallocated memory chunks
|
||||||
struct r600_screen *screen;
|
struct r600_screen *screen;
|
||||||
|
|
||||||
uint32_t *shadow; ///host copy of the pool, used for defragmentation
|
uint32_t *shadow; ///host copy of the pool, used for defragmentation
|
||||||
|
|
Loading…
Reference in New Issue