ac: rename and move si_const_array into common code
authorMarek Olšák <marek.olsak@amd.com>
Sun, 31 Dec 2017 22:35:59 +0000 (23:35 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 27 Jan 2018 01:09:09 +0000 (02:09 +0100)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_internal.h
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c

index fa2f7f5097eadf96fd7fdd88d59d6c13826210ad..5e08508fedb1c2996a09ef7f42c262ff16ff25d6 100644 (file)
@@ -1876,3 +1876,9 @@ LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
                                                           ctx->i32_0, ""),
                               LLVMConstInt(ctx->i32, -1, 0), lsb, "");
 }
+
+LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type)
+{
+       return LLVMPointerType(LLVMArrayType(elem_type, 0),
+                              AC_CONST_ADDR_SPACE);
+}
index 2ca7a97e76ed385a371048687cc6aab37587be42..78437d603e370ebff245b5e8be0d2cdd8c17fdc1 100644 (file)
@@ -328,6 +328,9 @@ void ac_lds_store(struct ac_llvm_context *ctx,
 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
                         LLVMTypeRef dst_type,
                         LLVMValueRef src0);
+
+LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
+
 #ifdef __cplusplus
 }
 #endif
index 92188cfb8e384b12805c4979058efb0e48022fac..dbbac9053531583a1954dad2619efbe92c340761 100644 (file)
@@ -355,12 +355,6 @@ create_llvm_function(LLVMContextRef ctx, LLVMModuleRef module,
        return main_function;
 }
 
-static LLVMTypeRef const_array(LLVMTypeRef elem_type, int num_elements)
-{
-       return LLVMPointerType(LLVMArrayType(elem_type, num_elements),
-                              AC_CONST_ADDR_SPACE);
-}
-
 static int get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type)
 {
        if (LLVMGetTypeKind(type) == LLVMVectorTypeKind)
@@ -647,7 +641,7 @@ declare_global_input_sgprs(struct nir_to_llvm_context *ctx,
                           struct arg_info *args,
                           LLVMValueRef *desc_sets)
 {
-       LLVMTypeRef type = const_array(ctx->ac.i8, 1024 * 1024);
+       LLVMTypeRef type = ac_array_in_const_addr_space(ctx->ac.i8);
        unsigned num_sets = ctx->options->layout ?
                            ctx->options->layout->num_sets : 0;
        unsigned stage_mask = 1 << stage;
@@ -664,7 +658,7 @@ declare_global_input_sgprs(struct nir_to_llvm_context *ctx,
                        }
                }
        } else {
-               add_array_arg(args, const_array(type, 32), desc_sets);
+               add_array_arg(args, ac_array_in_const_addr_space(type), desc_sets);
        }
 
        if (ctx->shader_info->info.loads_push_constants) {
@@ -684,7 +678,7 @@ declare_vs_specific_input_sgprs(struct nir_to_llvm_context *ctx,
            (stage == MESA_SHADER_VERTEX ||
             (has_previous_stage && previous_stage == MESA_SHADER_VERTEX))) {
                if (ctx->shader_info->info.vs.has_vertex_buffers) {
-                       add_arg(args, ARG_SGPR, const_array(ctx->ac.v4i32, 16),
+                       add_arg(args, ARG_SGPR, ac_array_in_const_addr_space(ctx->ac.v4i32),
                                &ctx->vertex_buffers);
                }
                add_arg(args, ARG_SGPR, ctx->ac.i32, &ctx->abi.base_vertex);
@@ -799,7 +793,7 @@ static void create_function(struct nir_to_llvm_context *ctx,
        allocate_user_sgprs(ctx, stage, needs_view_index, &user_sgpr_info);
 
        if (user_sgpr_info.need_ring_offsets && !ctx->options->supports_spill) {
-               add_arg(&args, ARG_SGPR, const_array(ctx->ac.v4i32, 16),
+               add_arg(&args, ARG_SGPR, ac_array_in_const_addr_space(ctx->ac.v4i32),
                        &ctx->ring_offsets);
        }
 
@@ -1082,7 +1076,7 @@ static void create_function(struct nir_to_llvm_context *ctx,
                                                               LLVMPointerType(ctx->ac.i8, AC_CONST_ADDR_SPACE),
                                                               NULL, 0, AC_FUNC_ATTR_READNONE);
                        ctx->ring_offsets = LLVMBuildBitCast(ctx->builder, ctx->ring_offsets,
-                                                            const_array(ctx->ac.v4i32, 16), "");
+                                                            ac_array_in_const_addr_space(ctx->ac.v4i32), "");
                }
        }
        
@@ -4039,7 +4033,7 @@ static LLVMValueRef load_sample_position(struct nir_to_llvm_context *ctx,
        LLVMValueRef ptr = ac_build_gep0(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->ac.i32, RING_PS_SAMPLE_POSITIONS, false));
 
        ptr = LLVMBuildBitCast(ctx->builder, ptr,
-                              const_array(ctx->ac.v2f32, 64), "");
+                              ac_array_in_const_addr_space(ctx->ac.v2f32), "");
 
        sample_id = LLVMBuildAdd(ctx->builder, sample_id, ctx->sample_pos_offset, "");
        result = ac_build_load_invariant(&ctx->ac, ptr, sample_id);
@@ -4650,7 +4644,7 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
        index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->ac.i32, stride / type_size, 0), "");
 
        list = ac_build_gep0(&ctx->ac, list, LLVMConstInt(ctx->ac.i32, offset, 0));
-       list = LLVMBuildPointerCast(builder, list, const_array(type, 0), "");
+       list = LLVMBuildPointerCast(builder, list, ac_array_in_const_addr_space(type), "");
 
        return ac_build_load_to_sgpr(&ctx->ac, list, index);
 }
index b75dab7cfbb43907c6448e26c65b8eb04b9fbb5a..b18b4f63b861d47044d22ee2f3870bbf8fad067d 100644 (file)
@@ -3945,12 +3945,6 @@ static void clock_emit(
                LLVMBuildExtractElement(ctx->ac.builder, tmp, ctx->i32_1, "");
 }
 
-LLVMTypeRef si_const_array(LLVMTypeRef elem_type, int num_elements)
-{
-       return LLVMPointerType(LLVMArrayType(elem_type, num_elements),
-                              AC_CONST_ADDR_SPACE);
-}
-
 static void si_llvm_emit_ddxy(
        const struct lp_build_tgsi_action *action,
        struct lp_build_tgsi_context *bld_base,
@@ -4562,12 +4556,11 @@ static void declare_per_stage_desc_pointers(struct si_shader_context *ctx,
 
        unsigned const_and_shader_buffers =
                add_arg(fninfo, ARG_SGPR,
-                       si_const_array(const_shader_buf_type, 0));
+                       ac_array_in_const_addr_space(const_shader_buf_type));
 
        unsigned samplers_and_images =
                add_arg(fninfo, ARG_SGPR,
-                       si_const_array(ctx->v8i32,
-                                      SI_NUM_IMAGES + SI_NUM_SAMPLERS * 2));
+                       ac_array_in_const_addr_space(ctx->v8i32));
 
        if (assign_params) {
                ctx->param_const_and_shader_buffers = const_and_shader_buffers;
@@ -4579,16 +4572,16 @@ static void declare_global_desc_pointers(struct si_shader_context *ctx,
                                         struct si_function_info *fninfo)
 {
        ctx->param_rw_buffers = add_arg(fninfo, ARG_SGPR,
-               si_const_array(ctx->v4i32, SI_NUM_RW_BUFFERS));
+               ac_array_in_const_addr_space(ctx->v4i32));
        ctx->param_bindless_samplers_and_images = add_arg(fninfo, ARG_SGPR,
-               si_const_array(ctx->v8i32, 0));
+               ac_array_in_const_addr_space(ctx->v8i32));
 }
 
 static void declare_vs_specific_input_sgprs(struct si_shader_context *ctx,
                                            struct si_function_info *fninfo)
 {
        ctx->param_vertex_buffers = add_arg(fninfo, ARG_SGPR,
-               si_const_array(ctx->v4i32, SI_NUM_VERTEX_BUFFERS));
+               ac_array_in_const_addr_space(ctx->v4i32));
        add_arg_assign(fninfo, ARG_SGPR, ctx->i32, &ctx->abi.base_vertex);
        add_arg_assign(fninfo, ARG_SGPR, ctx->i32, &ctx->abi.start_instance);
        add_arg_assign(fninfo, ARG_SGPR, ctx->i32, &ctx->abi.draw_id);
@@ -7083,7 +7076,7 @@ static LLVMValueRef si_prolog_get_rw_buffers(struct si_shader_context *ctx)
        list = lp_build_gather_values(&ctx->gallivm, ptr, 2);
        list = LLVMBuildBitCast(ctx->ac.builder, list, ctx->i64, "");
        list = LLVMBuildIntToPtr(ctx->ac.builder, list,
-                                si_const_array(ctx->v4i32, SI_NUM_RW_BUFFERS), "");
+                                ac_array_in_const_addr_space(ctx->v4i32), "");
        return list;
 }
 
index 7306481ccd9e92e919edb7417f1e6e275945a862..3084d88fad6df81af1252de20475679947152f0c 100644 (file)
@@ -310,8 +310,6 @@ LLVMValueRef si_get_bounded_indirect_index(struct si_shader_context *ctx,
                                           const struct tgsi_ind_register *ind,
                                           int rel_index, unsigned num);
 
-LLVMTypeRef si_const_array(LLVMTypeRef elem_type, int num_elements);
-
 void si_shader_context_init_alu(struct lp_build_tgsi_context *bld_base);
 void si_shader_context_init_mem(struct si_shader_context *ctx);
 
index 7bffc26ba6c65cc7b938ee08c5cf3fb3a87944c9..c80dc8ef0ee6751d756ce1707df0894711c5a3c7 100644 (file)
@@ -140,7 +140,7 @@ LLVMValueRef si_load_image_desc(struct si_shader_context *ctx,
                index = LLVMBuildAdd(builder, index,
                                     ctx->i32_1, "");
                list = LLVMBuildPointerCast(builder, list,
-                                           si_const_array(ctx->v4i32, 0), "");
+                                           ac_array_in_const_addr_space(ctx->v4i32), "");
        } else {
                assert(desc_type == AC_DESC_IMAGE);
        }
@@ -1102,7 +1102,7 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
                index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 4, 0), "");
                index = LLVMBuildAdd(builder, index, ctx->i32_1, "");
                list = LLVMBuildPointerCast(builder, list,
-                                           si_const_array(ctx->v4i32, 0), "");
+                                           ac_array_in_const_addr_space(ctx->v4i32), "");
                break;
        case AC_DESC_FMASK:
                /* The FMASK is at [8:15]. */
@@ -1114,7 +1114,7 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
                index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 4, 0), "");
                index = LLVMBuildAdd(builder, index, LLVMConstInt(ctx->i32, 3, 0), "");
                list = LLVMBuildPointerCast(builder, list,
-                                           si_const_array(ctx->v4i32, 0), "");
+                                           ac_array_in_const_addr_space(ctx->v4i32), "");
                break;
        }