ac: clean up ac_build_indexed_load function interfaces
authorMarek Olšák <marek.olsak@amd.com>
Sun, 8 Oct 2017 18:05:44 +0000 (20:05 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 17 Oct 2017 20:03:03 +0000 (22:03 +0200)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.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_tgsi_mem.c

index 1d97b09cd4f772558399414884a6012aa9227354..949f181aace05c0517b2f4d0a8fa0b2316a14fca 100644 (file)
@@ -717,32 +717,40 @@ ac_build_indexed_store(struct ac_llvm_context *ctx,
  * \param base_ptr  Where the array starts.
  * \param index     The element index into the array.
  * \param uniform   Whether the base_ptr and index can be assumed to be
- *                  dynamically uniform
+ *                  dynamically uniform (i.e. load to an SGPR)
+ * \param invariant Whether the load is invariant (no other opcodes affect it)
  */
-LLVMValueRef
-ac_build_indexed_load(struct ac_llvm_context *ctx,
-                     LLVMValueRef base_ptr, LLVMValueRef index,
-                     bool uniform)
+static LLVMValueRef
+ac_build_load_custom(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
+                    LLVMValueRef index, bool uniform, bool invariant)
 {
-       LLVMValueRef pointer;
+       LLVMValueRef pointer, result;
 
        pointer = ac_build_gep0(ctx, base_ptr, index);
        if (uniform)
                LLVMSetMetadata(pointer, ctx->uniform_md_kind, ctx->empty_md);
-       return LLVMBuildLoad(ctx->builder, pointer, "");
+       result = LLVMBuildLoad(ctx->builder, pointer, "");
+       if (invariant)
+               LLVMSetMetadata(result, ctx->invariant_load_md_kind, ctx->empty_md);
+       return result;
 }
 
-/**
- * Do a load from &base_ptr[index], but also add a flag that it's loading
- * a constant from a dynamically uniform index.
- */
-LLVMValueRef
-ac_build_indexed_load_const(struct ac_llvm_context *ctx,
-                           LLVMValueRef base_ptr, LLVMValueRef index)
+LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
+                          LLVMValueRef index)
 {
-       LLVMValueRef result = ac_build_indexed_load(ctx, base_ptr, index, true);
-       LLVMSetMetadata(result, ctx->invariant_load_md_kind, ctx->empty_md);
-       return result;
+       return ac_build_load_custom(ctx, base_ptr, index, false, false);
+}
+
+LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
+                                    LLVMValueRef base_ptr, LLVMValueRef index)
+{
+       return ac_build_load_custom(ctx, base_ptr, index, false, true);
+}
+
+LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
+                                  LLVMValueRef base_ptr, LLVMValueRef index)
+{
+       return ac_build_load_custom(ctx, base_ptr, index, true, true);
 }
 
 /* TBUFFER_STORE_FORMAT_{X,XY,XYZ,XYZW} <- the suffix is selected by num_channels=1..4.
index ac8ea9c4152e1814384059ba7185744a3af49fef..f0b5875b42391d70eb34f53ce66f7a003a37fad6 100644 (file)
@@ -150,14 +150,12 @@ ac_build_indexed_store(struct ac_llvm_context *ctx,
                       LLVMValueRef base_ptr, LLVMValueRef index,
                       LLVMValueRef value);
 
-LLVMValueRef
-ac_build_indexed_load(struct ac_llvm_context *ctx,
-                     LLVMValueRef base_ptr, LLVMValueRef index,
-                     bool uniform);
-
-LLVMValueRef
-ac_build_indexed_load_const(struct ac_llvm_context *ctx,
-                           LLVMValueRef base_ptr, LLVMValueRef index);
+LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
+                          LLVMValueRef index);
+LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
+                                    LLVMValueRef base_ptr, LLVMValueRef index);
+LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
+                                  LLVMValueRef base_ptr, LLVMValueRef index);
 
 void
 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
index 11ba487f3753febf1147ce7ed1df9c97aa667343..3ba3ebf051e2bc7c82f22c71f8784fac10fb007b 100644 (file)
@@ -798,7 +798,7 @@ static void create_function(struct nir_to_llvm_context *ctx)
                for (unsigned i = 0; i < num_sets; ++i) {
                        if (ctx->options->layout->set[i].layout->shader_stages & (1 << ctx->stage)) {
                                set_userdata_location_indirect(&ctx->shader_info->user_sgprs_locs.descriptor_sets[i], desc_sgpr_idx, 2, i * 8);
-                               ctx->descriptor_sets[i] = ac_build_indexed_load_const(&ctx->ac, desc_sets, LLVMConstInt(ctx->i32, i, false));
+                               ctx->descriptor_sets[i] = ac_build_load_to_sgpr(&ctx->ac, desc_sets, LLVMConstInt(ctx->i32, i, false));
 
                        } else
                                ctx->descriptor_sets[i] = NULL;
@@ -2524,7 +2524,7 @@ lds_load(struct nir_to_llvm_context *ctx,
         LLVMValueRef dw_addr)
 {
        LLVMValueRef value;
-       value = ac_build_indexed_load(&ctx->ac, ctx->lds, dw_addr, false);
+       value = ac_build_load(&ctx->ac, ctx->lds, dw_addr);
        return value;
 }
 
@@ -3739,7 +3739,7 @@ static LLVMValueRef load_sample_position(struct nir_to_llvm_context *ctx,
                               const_array(ctx->v2f32, 64), "");
 
        sample_id = LLVMBuildAdd(ctx->builder, sample_id, ctx->sample_pos_offset, "");
-       result = ac_build_indexed_load(&ctx->ac, ptr, sample_id, false);
+       result = ac_build_load_invariant(&ctx->ac, ptr, sample_id);
 
        return result;
 }
@@ -4230,7 +4230,7 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
        list = ac_build_gep0(&ctx->ac, list, LLVMConstInt(ctx->i32, offset, 0));
        list = LLVMBuildPointerCast(builder, list, const_array(type, 0), "");
 
-       return ac_build_indexed_load_const(&ctx->ac, list, index);
+       return ac_build_load_to_sgpr(&ctx->ac, list, index);
 }
 
 static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
@@ -4927,7 +4927,7 @@ handle_vs_input_decl(struct nir_to_llvm_context *ctx,
        for (unsigned i = 0; i < attrib_count; ++i, ++idx) {
                t_offset = LLVMConstInt(ctx->i32, index + i, false);
 
-               t_list = ac_build_indexed_load_const(&ctx->ac, t_list_ptr, t_offset);
+               t_list = ac_build_load_to_sgpr(&ctx->ac, t_list_ptr, t_offset);
 
                input = ac_build_buffer_load_format(&ctx->ac, t_list,
                                                    buffer_index,
@@ -6217,16 +6217,16 @@ ac_setup_rings(struct nir_to_llvm_context *ctx)
 {
        if ((ctx->stage == MESA_SHADER_VERTEX && ctx->options->key.vs.as_es) ||
            (ctx->stage == MESA_SHADER_TESS_EVAL && ctx->options->key.tes.as_es)) {
-               ctx->esgs_ring = ac_build_indexed_load_const(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_ESGS_VS, false));
+               ctx->esgs_ring = ac_build_load_to_sgpr(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_ESGS_VS, false));
        }
 
        if (ctx->is_gs_copy_shader) {
-               ctx->gsvs_ring = ac_build_indexed_load_const(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_GSVS_VS, false));
+               ctx->gsvs_ring = ac_build_load_to_sgpr(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_GSVS_VS, false));
        }
        if (ctx->stage == MESA_SHADER_GEOMETRY) {
                LLVMValueRef tmp;
-               ctx->esgs_ring = ac_build_indexed_load_const(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_ESGS_GS, false));
-               ctx->gsvs_ring = ac_build_indexed_load_const(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_GSVS_GS, false));
+               ctx->esgs_ring = ac_build_load_to_sgpr(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_ESGS_GS, false));
+               ctx->gsvs_ring = ac_build_load_to_sgpr(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_GSVS_GS, false));
 
                ctx->gsvs_ring = LLVMBuildBitCast(ctx->builder, ctx->gsvs_ring, ctx->v4i32, "");
 
@@ -6238,8 +6238,8 @@ ac_setup_rings(struct nir_to_llvm_context *ctx)
 
        if (ctx->stage == MESA_SHADER_TESS_CTRL ||
            ctx->stage == MESA_SHADER_TESS_EVAL) {
-               ctx->hs_ring_tess_offchip = ac_build_indexed_load_const(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_HS_TESS_OFFCHIP, false));
-               ctx->hs_ring_tess_factor = ac_build_indexed_load_const(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_HS_TESS_FACTOR, false));
+               ctx->hs_ring_tess_offchip = ac_build_load_to_sgpr(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_HS_TESS_OFFCHIP, false));
+               ctx->hs_ring_tess_factor = ac_build_load_to_sgpr(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->i32, RING_HS_TESS_FACTOR, false));
        }
 }
 
index ff372ae0531b528ed091f7eebc62d4724cc6b82b..f72e5af31fd0a28f2be8769e882100487aedad7c 100644 (file)
@@ -561,7 +561,7 @@ void si_llvm_load_input_vs(
 
        t_offset = LLVMConstInt(ctx->i32, input_index, 0);
 
-       t_list = ac_build_indexed_load_const(&ctx->ac, t_list_ptr, t_offset);
+       t_list = ac_build_load_to_sgpr(&ctx->ac, t_list_ptr, t_offset);
 
        vertex_index = LLVMGetParam(ctx->main_fn,
                                    ctx->param_vertex_index0 +
@@ -1099,12 +1099,12 @@ static LLVMValueRef lds_load(struct lp_build_tgsi_context *bld_base,
        dw_addr = lp_build_add(&bld_base->uint_bld, dw_addr,
                            LLVMConstInt(ctx->i32, swizzle, 0));
 
-       value = ac_build_indexed_load(&ctx->ac, ctx->lds, dw_addr, false);
+       value = ac_build_load(&ctx->ac, ctx->lds, dw_addr);
        if (tgsi_type_is_64bit(type)) {
                LLVMValueRef value2;
                dw_addr = lp_build_add(&bld_base->uint_bld, dw_addr,
                                       ctx->i32_1);
-               value2 = ac_build_indexed_load(&ctx->ac, ctx->lds, dw_addr, false);
+               value2 = ac_build_load(&ctx->ac, ctx->lds, dw_addr);
                return si_llvm_emit_fetch_64bit(bld_base, type, value, value2);
        }
 
@@ -1617,7 +1617,7 @@ static LLVMValueRef load_sample_position(struct si_shader_context *ctx, LLVMValu
        struct lp_build_context *uint_bld = &ctx->bld_base.uint_bld;
        LLVMValueRef desc = LLVMGetParam(ctx->main_fn, ctx->param_rw_buffers);
        LLVMValueRef buf_index = LLVMConstInt(ctx->i32, SI_PS_CONST_SAMPLE_POSITIONS, 0);
-       LLVMValueRef resource = ac_build_indexed_load_const(&ctx->ac, desc, buf_index);
+       LLVMValueRef resource = ac_build_load_to_sgpr(&ctx->ac, desc, buf_index);
 
        /* offset = sample_id * 8  (8 = 2 floats containing samplepos.xy) */
        LLVMValueRef offset0 = lp_build_mul_imm(uint_bld, sample_id, 8);
@@ -1792,7 +1792,7 @@ void si_load_system_value(struct si_shader_context *ctx,
 
                slot = LLVMConstInt(ctx->i32, SI_HS_CONST_DEFAULT_TESS_LEVELS, 0);
                buf = LLVMGetParam(ctx->main_fn, ctx->param_rw_buffers);
-               buf = ac_build_indexed_load_const(&ctx->ac, buf, slot);
+               buf = ac_build_load_to_sgpr(&ctx->ac, buf, slot);
                offset = decl->Semantic.Name == TGSI_SEMANTIC_DEFAULT_TESSINNER_SI ? 4 : 0;
 
                for (i = 0; i < 4; i++)
@@ -1935,8 +1935,8 @@ static LLVMValueRef load_const_buffer_desc(struct si_shader_context *ctx, int i)
        LLVMValueRef list_ptr = LLVMGetParam(ctx->main_fn,
                                             ctx->param_const_and_shader_buffers);
 
-       return ac_build_indexed_load_const(&ctx->ac, list_ptr,
-                       LLVMConstInt(ctx->i32, si_get_constbuf_slot(i), 0));
+       return ac_build_load_to_sgpr(&ctx->ac, list_ptr,
+                                    LLVMConstInt(ctx->i32, si_get_constbuf_slot(i), 0));
 }
 
 static LLVMValueRef load_ubo(struct ac_shader_abi *abi, LLVMValueRef index)
@@ -1948,7 +1948,7 @@ static LLVMValueRef load_ubo(struct ac_shader_abi *abi, LLVMValueRef index)
        index = LLVMBuildAdd(ctx->ac.builder, index,
                             LLVMConstInt(ctx->i32, SI_NUM_SHADER_BUFFERS, 0), "");
 
-       return ac_build_indexed_load_const(&ctx->ac, ptr, index);
+       return ac_build_load_to_sgpr(&ctx->ac, ptr, index);
 }
 
 static LLVMValueRef
@@ -1963,7 +1963,7 @@ load_ssbo(struct ac_shader_abi *abi, LLVMValueRef index, bool write)
                             LLVMConstInt(ctx->i32, SI_NUM_SHADER_BUFFERS - 1, 0),
                             index, "");
 
-       return ac_build_indexed_load_const(&ctx->ac, rsrc_ptr, index);
+       return ac_build_load_to_sgpr(&ctx->ac, rsrc_ptr, index);
 }
 
 static LLVMValueRef fetch_constant(
@@ -2008,7 +2008,7 @@ static LLVMValueRef fetch_constant(
                                                      ctx->num_const_buffers);
                index = LLVMBuildAdd(ctx->ac.builder, index,
                                     LLVMConstInt(ctx->i32, SI_NUM_SHADER_BUFFERS, 0), "");
-               bufp = ac_build_indexed_load_const(&ctx->ac, ptr, index);
+               bufp = ac_build_load_to_sgpr(&ctx->ac, ptr, index);
        } else
                bufp = load_const_buffer_desc(ctx, buf);
 
@@ -2283,7 +2283,7 @@ static void si_llvm_emit_clipvertex(struct lp_build_tgsi_context *bld_base,
        LLVMValueRef ptr = LLVMGetParam(ctx->main_fn, ctx->param_rw_buffers);
        LLVMValueRef constbuf_index = LLVMConstInt(ctx->i32,
                                                   SI_VS_CONST_CLIP_PLANES, 0);
-       LLVMValueRef const_resource = ac_build_indexed_load_const(&ctx->ac, ptr, constbuf_index);
+       LLVMValueRef const_resource = ac_build_load_to_sgpr(&ctx->ac, ptr, constbuf_index);
 
        for (reg_index = 0; reg_index < 2; reg_index ++) {
                struct ac_export_args *args = &pos[2 + reg_index];
@@ -2440,7 +2440,7 @@ static void si_llvm_emit_streamout(struct si_shader_context *ctx,
                        LLVMValueRef offset = LLVMConstInt(ctx->i32,
                                                           SI_VS_STREAMOUT_BUF0 + i, 0);
 
-                       so_buffers[i] = ac_build_indexed_load_const(&ctx->ac, buf_ptr, offset);
+                       so_buffers[i] = ac_build_load_to_sgpr(&ctx->ac, buf_ptr, offset);
 
                        LLVMValueRef so_offset = LLVMGetParam(ctx->main_fn,
                                                              ctx->param_streamout_offset[i]);
@@ -4722,20 +4722,20 @@ static void preload_ring_buffers(struct si_shader_context *ctx)
                LLVMValueRef offset = LLVMConstInt(ctx->i32, ring, 0);
 
                ctx->esgs_ring =
-                       ac_build_indexed_load_const(&ctx->ac, buf_ptr, offset);
+                       ac_build_load_to_sgpr(&ctx->ac, buf_ptr, offset);
        }
 
        if (ctx->shader->is_gs_copy_shader) {
                LLVMValueRef offset = LLVMConstInt(ctx->i32, SI_RING_GSVS, 0);
 
                ctx->gsvs_ring[0] =
-                       ac_build_indexed_load_const(&ctx->ac, buf_ptr, offset);
+                       ac_build_load_to_sgpr(&ctx->ac, buf_ptr, offset);
        } else if (ctx->type == PIPE_SHADER_GEOMETRY) {
                const struct si_shader_selector *sel = ctx->shader->selector;
                LLVMValueRef offset = LLVMConstInt(ctx->i32, SI_RING_GSVS, 0);
                LLVMValueRef base_ring;
 
-               base_ring = ac_build_indexed_load_const(&ctx->ac, buf_ptr, offset);
+               base_ring = ac_build_load_to_sgpr(&ctx->ac, buf_ptr, offset);
 
                /* The conceptual layout of the GSVS ring is
                 *   v0c0 .. vLv0 v0c1 .. vLc1 ..
@@ -4818,7 +4818,7 @@ static void si_llvm_emit_polygon_stipple(struct si_shader_context *ctx,
 
        /* Load the buffer descriptor. */
        slot = LLVMConstInt(ctx->i32, SI_PS_CONST_POLY_STIPPLE, 0);
-       desc = ac_build_indexed_load_const(&ctx->ac, param_rw_buffers, slot);
+       desc = ac_build_load_to_sgpr(&ctx->ac, param_rw_buffers, slot);
 
        /* The stipple pattern is 32x32, each row has 32 bits. */
        offset = LLVMBuildMul(builder, address[1],
@@ -6887,7 +6887,7 @@ static void si_build_vs_prolog_function(struct si_shader_context *ctx,
                LLVMValueRef buf_index =
                        LLVMConstInt(ctx->i32, SI_VS_CONST_INSTANCE_DIVISORS, 0);
                instance_divisor_constbuf =
-                       ac_build_indexed_load_const(&ctx->ac, list, buf_index);
+                       ac_build_load_to_sgpr(&ctx->ac, list, buf_index);
        }
 
        for (i = 0; i <= key->vs_prolog.last_input; i++) {
index a2b2b874d71fffcf42f5c05d3e2f93ccb47ab0dc..ec11c75b888c9d9ae489940ec66591f72608f7f3 100644 (file)
@@ -145,7 +145,7 @@ LLVMValueRef si_load_image_desc(struct si_shader_context *ctx,
                assert(desc_type == AC_DESC_IMAGE);
        }
 
-       rsrc = ac_build_indexed_load_const(&ctx->ac, list, index);
+       rsrc = ac_build_load_to_sgpr(&ctx->ac, list, index);
        if (dcc_off)
                rsrc = force_dcc_off(ctx, rsrc);
        return rsrc;
@@ -1134,7 +1134,7 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
                break;
        }
 
-       return ac_build_indexed_load_const(&ctx->ac, list, index);
+       return ac_build_load_to_sgpr(&ctx->ac, list, index);
 }
 
 /* Disable anisotropic filtering if BASE_LEVEL == LAST_LEVEL.