summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2017-05-17 21:11:13 +0200
committerMarek Olšák <[email protected]>2017-05-18 22:15:02 +0200
commitb8f8d9e46c6ac625928c9b098491fa26e4cf8f71 (patch)
treee737dd133f4cea60b253e16df0a07e61b10f03bc /src/gallium/drivers
parentf07c15ef807fb50659bf7a648393991f582f6a7f (diff)
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 <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/radeonsi/si_shader.c2
-rw-r--r--src/gallium/drivers/radeonsi/si_shader_internal.h6
-rw-r--r--src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c6
-rw-r--r--src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c5
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 f847e46e5dc..61f1384ad7a 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 5094023831d..5ccde713c77 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 89f3f94f55c..bd8ecb70f8c 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 ad586c39c22..1f8e91343f9 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,