Mesa (master): r600g/compute: Try to use a temporary resource when growing the pool

Tom Stellard tstellar at kemper.freedesktop.org
Fri Jul 25 21:53:31 UTC 2014


Module: Mesa
Branch: master
Commit: 4ca04f31122cacce249e98ed8985964bcb0d91e9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4ca04f31122cacce249e98ed8985964bcb0d91e9

Author: Bruno Jiménez <brunojimen at gmail.com>
Date:   Mon Jul  7 17:50:05 2014 +0200

r600g/compute: Try to use a temporary resource when growing the pool

Now, before moving everything to host memory, we try to create a
new resource to use as a pool. I we succeed we just use this resource
and delete the previous one. If we fail we fallback to using the
shadow.

This should make growing the pool faster, and we can also save
64KB of memory that were allocated for the 'shadow', even if they
weren't used.

Reviewed-by: Tom Stellard <thomas.stellard at amd.com>

---

 src/gallium/drivers/r600/compute_memory_pool.c |   61 +++++++++++++++++-------
 1 file changed, 43 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c b/src/gallium/drivers/r600/compute_memory_pool.c
index a66ead5..dbf6682 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -73,10 +73,6 @@ static void compute_memory_pool_init(struct compute_memory_pool * pool,
 	COMPUTE_DBG(pool->screen, "* compute_memory_pool_init() initial_size_in_dw = %ld\n",
 		initial_size_in_dw);
 
-	pool->shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
-	if (pool->shadow == NULL)
-		return;
-
 	pool->size_in_dw = initial_size_in_dw;
 	pool->bo = (struct r600_resource*)r600_compute_buffer_alloc_vram(pool->screen,
 							pool->size_in_dw * 4);
@@ -184,27 +180,56 @@ int compute_memory_grow_pool(struct compute_memory_pool* pool,
 
 	if (!pool->bo) {
 		compute_memory_pool_init(pool, MAX2(new_size_in_dw, 1024 * 16));
-		if (pool->shadow == NULL)
-			return -1;
 	} else {
+		struct r600_resource *temp = NULL;
+
 		new_size_in_dw = align(new_size_in_dw, ITEM_ALIGNMENT);
 
 		COMPUTE_DBG(pool->screen, "  Aligned size = %d (%d bytes)\n",
 			new_size_in_dw, new_size_in_dw * 4);
 
-		compute_memory_shadow(pool, pipe, 1);
-		pool->shadow = realloc(pool->shadow, new_size_in_dw*4);
-		if (pool->shadow == NULL)
-			return -1;
+		temp = (struct r600_resource *)r600_compute_buffer_alloc_vram(
+							pool->screen, new_size_in_dw * 4);
 
-		pool->size_in_dw = new_size_in_dw;
-		pool->screen->b.b.resource_destroy(
-			(struct pipe_screen *)pool->screen,
-			(struct pipe_resource *)pool->bo);
-		pool->bo = (struct r600_resource*)r600_compute_buffer_alloc_vram(
-							pool->screen,
-							pool->size_in_dw * 4);
-		compute_memory_shadow(pool, pipe, 0);
+		if (temp != NULL) {
+			struct r600_context *rctx = (struct r600_context *)pipe;
+			struct pipe_resource *src = (struct pipe_resource *)pool->bo;
+			struct pipe_resource *dst = (struct pipe_resource *)temp;
+			struct pipe_box box;
+
+			COMPUTE_DBG(pool->screen, "  Growing the pool using a temporary resource\n");
+
+			u_box_1d(0, pool->size_in_dw * 4, &box);
+
+			rctx->b.b.resource_copy_region(pipe,
+					dst, 0, 0, 0 ,0,
+					src, 0, &box);
+
+			pool->screen->b.b.resource_destroy(
+					(struct pipe_screen *)pool->screen,
+					src);
+
+			pool->bo = temp;
+			pool->size_in_dw = new_size_in_dw;
+		}
+		else {
+			COMPUTE_DBG(pool->screen, "  The creation of the temporary resource failed\n"
+				"  Falling back to using 'shadow'\n");
+
+			compute_memory_shadow(pool, pipe, 1);
+			pool->shadow = realloc(pool->shadow, new_size_in_dw * 4);
+			if (pool->shadow == NULL)
+				return -1;
+
+			pool->size_in_dw = new_size_in_dw;
+			pool->screen->b.b.resource_destroy(
+					(struct pipe_screen *)pool->screen,
+					(struct pipe_resource *)pool->bo);
+			pool->bo = (struct r600_resource*)r600_compute_buffer_alloc_vram(
+					pool->screen,
+					pool->size_in_dw * 4);
+			compute_memory_shadow(pool, pipe, 0);
+		}
 	}
 
 	return 0;




More information about the mesa-commit mailing list