Mesa (master): radeonsi: clamp indirect index to the number of declared shader resources

Marek Olšák mareko at kemper.freedesktop.org
Thu May 18 20:15:16 UTC 2017


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

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Wed May 17 21:11:13 2017 +0200

radeonsi: clamp indirect index to the number of declared shader resources

We'll do partial uploads of descriptor arrays, so we need to clamp
against what shaders declare.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

---

 src/gallium/drivers/radeonsi/si_shader.c            | 2 +-
 src/gallium/drivers/radeonsi/si_shader_internal.h   | 6 ++++++
 src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c   | 6 +++---
 src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c | 5 +++++
 4 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index f847e46e5d..61f1384ad7 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -1763,7 +1763,7 @@ static LLVMValueRef fetch_constant(
 		LLVMValueRef index;
 		index = si_get_bounded_indirect_index(ctx, &reg->DimIndirect,
 						      reg->Dimension.Index,
-						      SI_NUM_CONST_BUFFERS);
+						      ctx->num_const_buffers);
 		index = LLVMBuildAdd(ctx->gallivm.builder, index,
 				     LLVMConstInt(ctx->i32, SI_NUM_SHADER_BUFFERS, 0), "");
 		bufp = ac_build_indexed_load_const(&ctx->ac, ptr, index);
diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h b/src/gallium/drivers/radeonsi/si_shader_internal.h
index 5094023831..5ccde713c7 100644
--- a/src/gallium/drivers/radeonsi/si_shader_internal.h
+++ b/src/gallium/drivers/radeonsi/si_shader_internal.h
@@ -57,6 +57,12 @@ struct si_shader_context {
 
 	unsigned type; /* PIPE_SHADER_* specifies the type of shader. */
 
+	/* For clamping the non-constant index in resource indexing: */
+	unsigned num_const_buffers;
+	unsigned num_shader_buffers;
+	unsigned num_images;
+	unsigned num_samplers;
+
 	/* Whether the prolog will be compiled separately. */
 	bool separate_prolog;
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
index 89f3f94f55..bd8ecb70f8 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
@@ -92,7 +92,7 @@ shader_buffer_fetch_rsrc(struct si_shader_context *ctx,
 	} else {
 		index = si_get_bounded_indirect_index(ctx, &reg->Indirect,
 						      reg->Register.Index,
-						      SI_NUM_SHADER_BUFFERS);
+						      ctx->num_shader_buffers);
 		index = LLVMBuildSub(ctx->gallivm.builder,
 				     LLVMConstInt(ctx->i32, SI_NUM_SHADER_BUFFERS - 1, 0),
 				     index, "");
@@ -208,7 +208,7 @@ image_fetch_rsrc(
 		 */
 		index = si_get_bounded_indirect_index(ctx, &image->Indirect,
 						      image->Register.Index,
-						      SI_NUM_IMAGES);
+						      ctx->num_images);
 		index = LLVMBuildSub(ctx->gallivm.builder,
 				     LLVMConstInt(ctx->i32, SI_NUM_IMAGES - 1, 0),
 				     index, "");
@@ -1199,7 +1199,7 @@ static void tex_fetch_ptrs(
 		index = si_get_bounded_indirect_index(ctx,
 						      &reg->Indirect,
 						      reg->Register.Index,
-						      SI_NUM_SAMPLERS);
+						      ctx->num_samplers);
 		index = LLVMBuildAdd(ctx->gallivm.builder, index,
 				     LLVMConstInt(ctx->i32, SI_NUM_IMAGES / 2, 0), "");
 	} else {
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index ad586c39c2..1f8e91343f 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -1354,6 +1354,11 @@ void si_llvm_context_set_tgsi(struct si_shader_context *ctx,
 	ctx->bld_base.emit_fetch_funcs[TGSI_FILE_TEMPORARY] = si_llvm_emit_fetch;
 	ctx->bld_base.emit_fetch_funcs[TGSI_FILE_OUTPUT] = si_llvm_emit_fetch;
 	ctx->bld_base.emit_fetch_funcs[TGSI_FILE_SYSTEM_VALUE] = fetch_system_value;
+
+	ctx->num_const_buffers = util_last_bit(info->const_buffers_declared);
+	ctx->num_shader_buffers = util_last_bit(info->shader_buffers_declared);
+	ctx->num_samplers = util_last_bit(info->samplers_declared);
+	ctx->num_images = util_last_bit(info->images_declared);
 }
 
 void si_llvm_create_func(struct si_shader_context *ctx,




More information about the mesa-commit mailing list