This function will be used when we want to map an item
that it's already in the pool.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 45 ++++++++++++++++++++++++++
 src/gallium/drivers/r600/compute_memory_pool.h |  3 ++
 2 files changed, 48 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index e1f9c88..624b50d 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -383,6 +383,51 @@ 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)
+{
+       /* 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);
+       }
+
+       /* We transfer the memory from the item in the pool to the
+        * temporary buffer */
+       ((struct r600_context *)pipe)->b.b.resource_copy_region(pipe,
+               (struct pipe_resource *)item->real_buffer,
+               0, 0, 0, 0,
+               (struct pipe_resource *)pool->bo,
+               0, &(struct pipe_box) { .x = item->start_in_dw * 4,
+               .width = item->size_in_dw * 4, .height = 1, .depth = 1});
+
+       /* 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 6a45fb2..1eb60da 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -85,6 +85,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
 
-- 
2.0.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to