[Mesa-dev] [PATCH 08/11] freedreno: add support for state tracking shader buffers

Ilia Mirkin imirkin at alum.mit.edu
Sat Sep 26 23:33:24 PDT 2015


Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 src/gallium/drivers/freedreno/freedreno_context.h  |  2 ++
 src/gallium/drivers/freedreno/freedreno_draw.c     |  8 ++++++++
 src/gallium/drivers/freedreno/freedreno_resource.c |  8 ++++++++
 src/gallium/drivers/freedreno/freedreno_state.c    | 24 ++++++++++++++++++++++
 4 files changed, 42 insertions(+)

diff --git a/src/gallium/drivers/freedreno/freedreno_context.h b/src/gallium/drivers/freedreno/freedreno_context.h
index 61c4c6d..3a01f1f 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.h
+++ b/src/gallium/drivers/freedreno/freedreno_context.h
@@ -336,6 +336,7 @@ struct fd_context {
 		FD_DIRTY_STREAMOUT   = (1 << 18),
 		FD_DIRTY_UCP         = (1 << 19),
 		FD_DIRTY_BLEND_DUAL  = (1 << 20),
+		FD_DIRTY_BUFFERS     = (1 << 21),
 	} dirty;
 
 	struct pipe_blend_state *blend;
@@ -358,6 +359,7 @@ struct fd_context {
 	struct pipe_index_buffer indexbuf;
 	struct fd_streamout_stateobj streamout;
 	struct pipe_clip_state ucp;
+	struct pipe_shader_buffer buffers[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
 
 	/* GMEM/tile handling fxns: */
 	void (*emit_tile_init)(struct fd_context *ctx);
diff --git a/src/gallium/drivers/freedreno/freedreno_draw.c b/src/gallium/drivers/freedreno/freedreno_draw.c
index 6831a58..097c4f2 100644
--- a/src/gallium/drivers/freedreno/freedreno_draw.c
+++ b/src/gallium/drivers/freedreno/freedreno_draw.c
@@ -165,6 +165,14 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 		if (ctx->streamout.targets[i])
 			resource_written(ctx, ctx->streamout.targets[i]->buffer);
 
+	/* Mark shader buffers as being read and written */
+	for (i = 0; i < PIPE_MAX_SHADER_BUFFERS; i++) {
+		resource_used(ctx, ctx->buffers[PIPE_SHADER_VERTEX][i].buffer,
+					  FD_PENDING_READ | FD_PENDING_WRITE);
+		resource_used(ctx, ctx->buffers[PIPE_SHADER_FRAGMENT][i].buffer,
+					  FD_PENDING_READ | FD_PENDING_WRITE);
+	}
+
 	ctx->num_draws++;
 
 	prims = u_reduced_prims_for_vertices(info->mode, info->count);
diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index 98de096..3b14575 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -68,6 +68,14 @@ fd_invalidate_resource(struct fd_context *ctx, struct pipe_resource *prsc)
 			ctx->dirty |= FD_DIRTY_CONSTBUF;
 	}
 
+	/* Buffers */
+	for (i = 0; i < 16 && !(ctx->dirty & FD_DIRTY_BUFFERS); i++) {
+		if (ctx->buffers[PIPE_SHADER_VERTEX][i].buffer == prsc)
+			ctx->dirty |= FD_DIRTY_BUFFERS;
+		if (ctx->buffers[PIPE_SHADER_FRAGMENT][i].buffer == prsc)
+			ctx->dirty |= FD_DIRTY_BUFFERS;
+	}
+
 	/* VBOs */
 	for (i = 0; i < ctx->vtx.vertexbuf.count && !(ctx->dirty & FD_DIRTY_VTXBUF); i++) {
 		if (ctx->vtx.vertexbuf.vb[i].buffer == prsc)
diff --git a/src/gallium/drivers/freedreno/freedreno_state.c b/src/gallium/drivers/freedreno/freedreno_state.c
index 685d3a7..aba806b 100644
--- a/src/gallium/drivers/freedreno/freedreno_state.c
+++ b/src/gallium/drivers/freedreno/freedreno_state.c
@@ -373,6 +373,28 @@ fd_set_stream_output_targets(struct pipe_context *pctx,
 	ctx->dirty |= FD_DIRTY_STREAMOUT;
 }
 
+static void
+fd_set_shader_buffers(struct pipe_context *pctx, unsigned shader,
+					  unsigned start, unsigned nr,
+					  struct pipe_shader_buffer *buffers)
+{
+	struct fd_context *ctx = fd_context(pctx);
+	int i;
+
+	for (i = 0; i < nr; i++) {
+		struct pipe_shader_buffer *buf = &ctx->buffers[shader][start + i];
+		struct pipe_resource *res = buffers ? buffers[i].buffer : NULL;
+		if (buf->buffer != res)
+			pipe_resource_reference(&buf->buffer, res);
+		if (res) {
+			buf->buffer_offset = buffers[i].buffer_offset;
+			buf->buffer_size = buffers[i].buffer_size;
+		}
+	}
+
+	ctx->dirty |= FD_DIRTY_BUFFERS;
+}
+
 void
 fd_state_init(struct pipe_context *pctx)
 {
@@ -405,4 +427,6 @@ fd_state_init(struct pipe_context *pctx)
 	pctx->create_stream_output_target = fd_create_stream_output_target;
 	pctx->stream_output_target_destroy = fd_stream_output_target_destroy;
 	pctx->set_stream_output_targets = fd_set_stream_output_targets;
+
+	pctx->set_shader_buffers = fd_set_shader_buffers;
 }
-- 
2.4.9



More information about the mesa-dev mailing list