Mesa (master): freedreno/a3xx: fix const confusion

Rob Clark robclark at kemper.freedesktop.org
Sat Feb 1 17:05:12 UTC 2014


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

Author: Rob Clark <robclark at freedesktop.org>
Date:   Tue Jan 14 09:54:02 2014 -0500

freedreno/a3xx: fix const confusion

Gallium can leave const buffers bound above what is used by the current
shader.  Which can have a couple bad effects:

1) write beyond const space assigned, which can trigger HLSQ lockup
2) double emit of immed consts, first with bound const buffer vals
followed by with actual immed vals.  This seems to be a sort of
undefined condition.

Signed-off-by: Rob Clark <robclark at freedesktop.org>

---

 src/gallium/drivers/freedreno/a3xx/fd3_compiler.c |    2 +-
 src/gallium/drivers/freedreno/a3xx/fd3_emit.c     |   16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_compiler.c b/src/gallium/drivers/freedreno/a3xx/fd3_compiler.c
index 3fd3c5a..c8e66fc 100644
--- a/src/gallium/drivers/freedreno/a3xx/fd3_compiler.c
+++ b/src/gallium/drivers/freedreno/a3xx/fd3_compiler.c
@@ -157,7 +157,7 @@ compile_init(struct fd3_compile_context *ctx, struct fd3_shader_stateobj *so,
 			info->file_max[TGSI_FILE_OUTPUT] + 1;
 
 	so->first_immediate = ctx->base_reg[TGSI_FILE_IMMEDIATE];
-	ctx->immediate_idx = 4 * (info->file_max[TGSI_FILE_IMMEDIATE] + 1);
+	ctx->immediate_idx = 4 * (ctx->info.file_max[TGSI_FILE_IMMEDIATE] + 1);
 
 	ret = tgsi_parse_init(&ctx->parser, tokens);
 	if (ret != TGSI_PARSE_OK)
diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_emit.c b/src/gallium/drivers/freedreno/a3xx/fd3_emit.c
index c479666..543c116 100644
--- a/src/gallium/drivers/freedreno/a3xx/fd3_emit.c
+++ b/src/gallium/drivers/freedreno/a3xx/fd3_emit.c
@@ -115,12 +115,10 @@ emit_constants(struct fd_ringbuffer *ring,
 		// I expect that size should be a multiple of vec4's:
 		assert(size == align(size, 4));
 
-		/* gallium could have const-buffer still bound, even though the
-		 * shader is not using it.  Writing consts above constlen (or
-		 * rather, HLSQ_{VS,FS}_CONTROL_REG.CONSTLENGTH) will cause a
-		 * hang.
+		/* gallium could leave const buffers bound above what the
+		 * current shader uses.. don't let that confuse us.
 		 */
-		if ((base / 4) >= shader->constlen)
+		if (base >= (4 * shader->first_immediate))
 			break;
 
 		if (constbuf->dirty_mask & (1 << index)) {
@@ -137,9 +135,11 @@ emit_constants(struct fd_ringbuffer *ring,
 	/* emit shader immediates: */
 	if (shader) {
 		for (i = 0; i < shader->immediates_count; i++) {
-			fd3_emit_constant(ring, sb,
-					4 * (shader->first_immediate + i),
-					0, 4, shader->immediates[i].val, NULL);
+			base = 4 * (shader->first_immediate + i);
+			if (base >= (4 * shader->constlen))
+				break;
+			fd3_emit_constant(ring, sb, base,
+				0, 4, shader->immediates[i].val, NULL);
 		}
 	}
 }




More information about the mesa-commit mailing list