radeonsi: clamp indirect index to the number of declared shader resources
authorMarek Olšák <marek.olsak@amd.com>
Wed, 17 May 2017 19:11:13 +0000 (21:11 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 18 May 2017 20:15:02 +0000 (22:15 +0200)
We'll do partial uploads of descriptor arrays, so we need to clamp
against what shaders declare.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_internal.h
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c

index f847e46e5dcfc42ec760d38682711554429b3fe4..61f1384ad7abc4ced380cc2aee76cee7d8288afa 100644 (file)
@@ -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);
index 5094023831d552af8c85aa59f439c3f5ff0af843..5ccde713c77f5f47d5030fd20791ca48bad05ae6 100644 (file)
@@ -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;
 
index 89f3f94f55cdb28ea7318d5389e889165a08b9e9..bd8ecb70f8cf6dd3b273ac162f386f7eded30e95 100644 (file)
@@ -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 {
index ad586c39c22bf15d1301e22f63e4bf87fc62749c..1f8e91343f9d5ba5b7f27e971c686239d207f121 100644 (file)
@@ -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,