[Mesa-dev] [PATCH 4/4] radeonsi: fix buffer invalidation of unbound texture buffer objects

Marek Olšák maraeo at gmail.com
Mon Aug 11 13:46:21 PDT 2014


From: Marek Olšák <marek.olsak at amd.com>

This maintains a list of all TBOs in a pipe_context.
---
 src/gallium/drivers/radeonsi/si_descriptors.c | 13 ++++++++-----
 src/gallium/drivers/radeonsi/si_pipe.h        |  1 +
 src/gallium/drivers/radeonsi/si_state.c       | 10 ++++++++--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c
index c877797..0e95f48 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -914,6 +914,7 @@ static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource
 	uint64_t old_va = rbuffer->gpu_address;
 	unsigned num_elems = sctx->vertex_elements ?
 				       sctx->vertex_elements->count : 0;
+	struct si_pipe_sampler_view *view;
 
 	/* Reallocate the buffer in the same pipe_resource. */
 	r600_init_resource(&sctx->screen->b, rbuffer, rbuffer->b.b.width0,
@@ -1000,7 +1001,13 @@ static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource
 		}
 	}
 
-	/* Texture buffers. */
+	/* Texture buffers - update virtual addresses in sampler view descriptors. */
+	LIST_FOR_EACH_ENTRY(view, &sctx->b.texture_buffers, list) {
+		if (view->base.texture == buf) {
+			si_desc_reset_buffer_offset(ctx, view->state, old_va, buf);
+		}
+	}
+	/* Texture buffers - update bindings. */
 	for (shader = 0; shader < SI_NUM_SHADERS; shader++) {
 		struct si_sampler_views *views = &sctx->samplers[shader].views;
 		bool found = false;
@@ -1009,10 +1016,6 @@ static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource
 		while (mask) {
 			unsigned i = u_bit_scan(&mask);
 			if (views->views[i]->texture == buf) {
-				/* This updates the sampler view directly. */
-				si_desc_reset_buffer_offset(ctx, views->desc_data[i],
-							    old_va, buf);
-
 				r600_context_bo_reloc(&sctx->b, &sctx->b.rings.gfx,
 						      rbuffer, RADEON_USAGE_READ,
 						      RADEON_PRIO_SHADER_BUFFER_RO);
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h
index 7b6c860..10f7e23 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -47,6 +47,7 @@ struct si_screen {
 
 struct si_pipe_sampler_view {
 	struct pipe_sampler_view	base;
+	struct list_head		list;
 	struct r600_resource		*resource;
 	uint32_t			state[8];
 	uint32_t			fmask_state[8];
diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
index e85f601..a8b82cc 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -2358,6 +2358,7 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
 							struct pipe_resource *texture,
 							const struct pipe_sampler_view *state)
 {
+	struct si_context *sctx = (struct si_context*)ctx;
 	struct si_pipe_sampler_view *view = CALLOC_STRUCT(si_pipe_sampler_view);
 	struct r600_texture *tmp = (struct r600_texture*)texture;
 	const struct util_format_description *desc;
@@ -2402,6 +2403,8 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
 				 S_008F0C_DST_SEL_W(si_map_swizzle(desc->swizzle[3])) |
 				 S_008F0C_NUM_FORMAT(num_format) |
 				 S_008F0C_DATA_FORMAT(format);
+
+		LIST_ADDTAIL(&view->list, &sctx->b.texture_buffers);
 		return &view->base;
 	}
 
@@ -2606,10 +2609,13 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
 static void si_sampler_view_destroy(struct pipe_context *ctx,
 				    struct pipe_sampler_view *state)
 {
-	struct r600_pipe_sampler_view *resource = (struct r600_pipe_sampler_view *)state;
+	struct si_pipe_sampler_view *view = (struct si_pipe_sampler_view *)state;
+
+	if (view->resource->b.b.target == PIPE_BUFFER)
+		LIST_DELINIT(&view->list);
 
 	pipe_resource_reference(&state->texture, NULL);
-	FREE(resource);
+	FREE(view);
 }
 
 static bool wrap_mode_uses_border_color(unsigned wrap, bool linear_filter)
-- 
1.9.1



More information about the mesa-dev mailing list