[Mesa-dev] [PATCH 07/11] r600g/compute: Implement compute_memory_demote_item

Bruno Jiménez brunojimen at gmail.com
Wed Jun 18 08:01:57 PDT 2014


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
---
 src/gallium/drivers/r600/compute_memory_pool.c | 51 ++++++++++++++++++++++++++
 src/gallium/drivers/r600/compute_memory_pool.h |  3 ++
 2 files changed, 54 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c b/src/gallium/drivers/r600/compute_memory_pool.c
index f232f9f..6409b34 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 faadeea..0bb695c 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
 
-- 
2.0.0



More information about the mesa-dev mailing list