[Mesa-dev] [PATCH 1/3] radeonsi: clean up 'radeon_bld' references
Nicolai Hähnle
nhaehnle at gmail.com
Mon Apr 3 09:00:26 UTC 2017
On 03.04.2017 02:01, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
> src/gallium/drivers/radeonsi/si_shader.c | 108 ++++++++++++++-----------------
> 1 file changed, 48 insertions(+), 60 deletions(-)
>
> diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
> index 3876010..2da00f9 100644
> --- a/src/gallium/drivers/radeonsi/si_shader.c
> +++ b/src/gallium/drivers/radeonsi/si_shader.c
> @@ -293,37 +293,35 @@ get_tcs_out_current_patch_data_offset(struct si_shader_context *ctx)
> LLVMValueRef patch_stride = get_tcs_out_patch_stride(ctx);
> LLVMValueRef rel_patch_id = get_rel_patch_id(ctx);
>
> return LLVMBuildAdd(gallivm->builder, patch0_patch_data_offset,
> LLVMBuildMul(gallivm->builder, patch_stride,
> rel_patch_id, ""),
> "");
> }
>
> static LLVMValueRef get_instance_index_for_fetch(
> - struct si_shader_context *radeon_bld,
> + struct si_shader_context *ctx,
> unsigned param_start_instance, unsigned divisor)
> {
> - struct si_shader_context *ctx =
> - si_shader_context(&radeon_bld->bld_base);
> - struct gallivm_state *gallivm = radeon_bld->bld_base.base.gallivm;
> + struct gallivm_state *gallivm = ctx->bld_base.base.gallivm;
This could just be &ctx->gallivm. Apart from that, the series is
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> - LLVMValueRef result = LLVMGetParam(radeon_bld->main_fn,
> + LLVMValueRef result = LLVMGetParam(ctx->main_fn,
> ctx->param_instance_id);
>
> /* The division must be done before START_INSTANCE is added. */
> if (divisor > 1)
> result = LLVMBuildUDiv(gallivm->builder, result,
> lp_build_const_int32(gallivm, divisor), "");
>
> return LLVMBuildAdd(gallivm->builder, result,
> - LLVMGetParam(radeon_bld->main_fn, param_start_instance), "");
> + LLVMGetParam(ctx->main_fn, param_start_instance), "");
> }
>
> /* Bitcast <4 x float> to <2 x double>, extract the component, and convert
> * to float. */
> static LLVMValueRef extract_double_to_float(struct si_shader_context *ctx,
> LLVMValueRef vec4,
> unsigned double_index)
> {
> LLVMBuilderRef builder = ctx->gallivm.builder;
> LLVMTypeRef f64 = LLVMDoubleTypeInContext(ctx->gallivm.context);
> @@ -1279,30 +1277,28 @@ static void interp_fs_input(struct si_shader_context *ctx,
> } else {
> result[chan] = ac_build_fs_interp_mov(&ctx->ac,
> lp_build_const_int32(gallivm, 2), /* P0 */
> llvm_chan, attr_number, prim_mask);
> }
> }
> }
> }
>
> static void declare_input_fs(
> - struct si_shader_context *radeon_bld,
> + struct si_shader_context *ctx,
> unsigned input_index,
> const struct tgsi_full_declaration *decl,
> LLVMValueRef out[4])
> {
> - struct lp_build_context *base = &radeon_bld->bld_base.base;
> - struct si_shader_context *ctx =
> - si_shader_context(&radeon_bld->bld_base);
> + struct lp_build_context *base = &ctx->bld_base.base;
> struct si_shader *shader = ctx->shader;
> - LLVMValueRef main_fn = radeon_bld->main_fn;
> + LLVMValueRef main_fn = ctx->main_fn;
> LLVMValueRef interp_param = NULL;
> int interp_param_idx;
>
> /* Get colors from input VGPRs (set by the prolog). */
> if (decl->Semantic.Name == TGSI_SEMANTIC_COLOR) {
> unsigned i = decl->Semantic.Index;
> unsigned colors_read = shader->selector->info.colors_read;
> unsigned mask = colors_read >> (i * 4);
> unsigned offset = SI_PARAM_POS_FIXED_PT + 1 +
> (i ? util_bitcount(colors_read & 0xf) : 0);
> @@ -1328,171 +1324,165 @@ static void declare_input_fs(
> interp_param = NULL; /* load the constant color */
>
> interp_fs_input(ctx, input_index, decl->Semantic.Name,
> decl->Semantic.Index, shader->selector->info.num_inputs,
> shader->selector->info.colors_read, interp_param,
> LLVMGetParam(main_fn, SI_PARAM_PRIM_MASK),
> LLVMGetParam(main_fn, SI_PARAM_FRONT_FACE),
> &out[0]);
> }
>
> -static LLVMValueRef get_sample_id(struct si_shader_context *radeon_bld)
> +static LLVMValueRef get_sample_id(struct si_shader_context *ctx)
> {
> - return unpack_param(si_shader_context(&radeon_bld->bld_base),
> - SI_PARAM_ANCILLARY, 8, 4);
> + return unpack_param(ctx, SI_PARAM_ANCILLARY, 8, 4);
> }
>
>
> /**
> * Load a dword from a constant buffer.
> */
> static LLVMValueRef buffer_load_const(struct si_shader_context *ctx,
> LLVMValueRef resource,
> LLVMValueRef offset)
> {
> LLVMBuilderRef builder = ctx->gallivm.builder;
> LLVMValueRef args[2] = {resource, offset};
>
> return lp_build_intrinsic(builder, "llvm.SI.load.const", ctx->f32, args, 2,
> LP_FUNC_ATTR_READNONE |
> LP_FUNC_ATTR_LEGACY);
> }
>
> -static LLVMValueRef load_sample_position(struct si_shader_context *radeon_bld, LLVMValueRef sample_id)
> +static LLVMValueRef load_sample_position(struct si_shader_context *ctx, LLVMValueRef sample_id)
> {
> - struct si_shader_context *ctx =
> - si_shader_context(&radeon_bld->bld_base);
> - struct lp_build_context *uint_bld = &radeon_bld->bld_base.uint_bld;
> - struct gallivm_state *gallivm = &radeon_bld->gallivm;
> + struct lp_build_context *uint_bld = &ctx->bld_base.uint_bld;
> + struct gallivm_state *gallivm = &ctx->gallivm;
> LLVMBuilderRef builder = gallivm->builder;
> LLVMValueRef desc = LLVMGetParam(ctx->main_fn, SI_PARAM_RW_BUFFERS);
> LLVMValueRef buf_index = lp_build_const_int32(gallivm, SI_PS_CONST_SAMPLE_POSITIONS);
> LLVMValueRef resource = ac_build_indexed_load_const(&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);
> LLVMValueRef offset1 = LLVMBuildAdd(builder, offset0, lp_build_const_int32(gallivm, 4), "");
>
> LLVMValueRef pos[4] = {
> buffer_load_const(ctx, resource, offset0),
> buffer_load_const(ctx, resource, offset1),
> lp_build_const_float(gallivm, 0),
> lp_build_const_float(gallivm, 0)
> };
>
> return lp_build_gather_values(gallivm, pos, 4);
> }
>
> -static void declare_system_value(
> - struct si_shader_context *radeon_bld,
> - unsigned index,
> - const struct tgsi_full_declaration *decl)
> +static void declare_system_value(struct si_shader_context *ctx,
> + unsigned index,
> + const struct tgsi_full_declaration *decl)
> {
> - struct si_shader_context *ctx =
> - si_shader_context(&radeon_bld->bld_base);
> - struct lp_build_context *bld = &radeon_bld->bld_base.base;
> - struct gallivm_state *gallivm = &radeon_bld->gallivm;
> + struct lp_build_context *bld = &ctx->bld_base.base;
> + struct gallivm_state *gallivm = &ctx->gallivm;
> LLVMValueRef value = 0;
>
> switch (decl->Semantic.Name) {
> case TGSI_SEMANTIC_INSTANCEID:
> - value = LLVMGetParam(radeon_bld->main_fn,
> + value = LLVMGetParam(ctx->main_fn,
> ctx->param_instance_id);
> break;
>
> case TGSI_SEMANTIC_VERTEXID:
> value = LLVMBuildAdd(gallivm->builder,
> - LLVMGetParam(radeon_bld->main_fn,
> + LLVMGetParam(ctx->main_fn,
> ctx->param_vertex_id),
> - LLVMGetParam(radeon_bld->main_fn,
> + LLVMGetParam(ctx->main_fn,
> SI_PARAM_BASE_VERTEX), "");
> break;
>
> case TGSI_SEMANTIC_VERTEXID_NOBASE:
> - value = LLVMGetParam(radeon_bld->main_fn,
> + value = LLVMGetParam(ctx->main_fn,
> ctx->param_vertex_id);
> break;
>
> case TGSI_SEMANTIC_BASEVERTEX:
> - value = LLVMGetParam(radeon_bld->main_fn,
> + value = LLVMGetParam(ctx->main_fn,
> SI_PARAM_BASE_VERTEX);
> break;
>
> case TGSI_SEMANTIC_BASEINSTANCE:
> - value = LLVMGetParam(radeon_bld->main_fn,
> + value = LLVMGetParam(ctx->main_fn,
> SI_PARAM_START_INSTANCE);
> break;
>
> case TGSI_SEMANTIC_DRAWID:
> - value = LLVMGetParam(radeon_bld->main_fn,
> + value = LLVMGetParam(ctx->main_fn,
> SI_PARAM_DRAWID);
> break;
>
> case TGSI_SEMANTIC_INVOCATIONID:
> if (ctx->type == PIPE_SHADER_TESS_CTRL)
> value = unpack_param(ctx, SI_PARAM_REL_IDS, 8, 5);
> else if (ctx->type == PIPE_SHADER_GEOMETRY)
> - value = LLVMGetParam(radeon_bld->main_fn,
> + value = LLVMGetParam(ctx->main_fn,
> SI_PARAM_GS_INSTANCE_ID);
> else
> assert(!"INVOCATIONID not implemented");
> break;
>
> case TGSI_SEMANTIC_POSITION:
> {
> LLVMValueRef pos[4] = {
> - LLVMGetParam(radeon_bld->main_fn, SI_PARAM_POS_X_FLOAT),
> - LLVMGetParam(radeon_bld->main_fn, SI_PARAM_POS_Y_FLOAT),
> - LLVMGetParam(radeon_bld->main_fn, SI_PARAM_POS_Z_FLOAT),
> - lp_build_emit_llvm_unary(&radeon_bld->bld_base, TGSI_OPCODE_RCP,
> - LLVMGetParam(radeon_bld->main_fn,
> + LLVMGetParam(ctx->main_fn, SI_PARAM_POS_X_FLOAT),
> + LLVMGetParam(ctx->main_fn, SI_PARAM_POS_Y_FLOAT),
> + LLVMGetParam(ctx->main_fn, SI_PARAM_POS_Z_FLOAT),
> + lp_build_emit_llvm_unary(&ctx->bld_base, TGSI_OPCODE_RCP,
> + LLVMGetParam(ctx->main_fn,
> SI_PARAM_POS_W_FLOAT)),
> };
> value = lp_build_gather_values(gallivm, pos, 4);
> break;
> }
>
> case TGSI_SEMANTIC_FACE:
> - value = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_FRONT_FACE);
> + value = LLVMGetParam(ctx->main_fn, SI_PARAM_FRONT_FACE);
> break;
>
> case TGSI_SEMANTIC_SAMPLEID:
> - value = get_sample_id(radeon_bld);
> + value = get_sample_id(ctx);
> break;
>
> case TGSI_SEMANTIC_SAMPLEPOS: {
> LLVMValueRef pos[4] = {
> - LLVMGetParam(radeon_bld->main_fn, SI_PARAM_POS_X_FLOAT),
> - LLVMGetParam(radeon_bld->main_fn, SI_PARAM_POS_Y_FLOAT),
> + LLVMGetParam(ctx->main_fn, SI_PARAM_POS_X_FLOAT),
> + LLVMGetParam(ctx->main_fn, SI_PARAM_POS_Y_FLOAT),
> lp_build_const_float(gallivm, 0),
> lp_build_const_float(gallivm, 0)
> };
> - pos[0] = lp_build_emit_llvm_unary(&radeon_bld->bld_base,
> + pos[0] = lp_build_emit_llvm_unary(&ctx->bld_base,
> TGSI_OPCODE_FRC, pos[0]);
> - pos[1] = lp_build_emit_llvm_unary(&radeon_bld->bld_base,
> + pos[1] = lp_build_emit_llvm_unary(&ctx->bld_base,
> TGSI_OPCODE_FRC, pos[1]);
> value = lp_build_gather_values(gallivm, pos, 4);
> break;
> }
>
> case TGSI_SEMANTIC_SAMPLEMASK:
> /* This can only occur with the OpenGL Core profile, which
> * doesn't support smoothing.
> */
> - value = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_SAMPLE_COVERAGE);
> + value = LLVMGetParam(ctx->main_fn, SI_PARAM_SAMPLE_COVERAGE);
> break;
>
> case TGSI_SEMANTIC_TESSCOORD:
> {
> LLVMValueRef coord[4] = {
> - LLVMGetParam(radeon_bld->main_fn, ctx->param_tes_u),
> - LLVMGetParam(radeon_bld->main_fn, ctx->param_tes_v),
> + LLVMGetParam(ctx->main_fn, ctx->param_tes_u),
> + LLVMGetParam(ctx->main_fn, ctx->param_tes_v),
> bld->zero,
> bld->zero
> };
>
> /* For triangles, the vector should be (u, v, 1-u-v). */
> if (ctx->shader->selector->info.properties[TGSI_PROPERTY_TES_PRIM_MODE] ==
> PIPE_PRIM_TRIANGLES)
> coord[2] = lp_build_sub(bld, bld->one,
> lp_build_add(bld, coord[0], coord[1]));
>
> @@ -1517,21 +1507,21 @@ static void declare_system_value(
>
> rw_buffers = LLVMGetParam(ctx->main_fn,
> SI_PARAM_RW_BUFFERS);
> buffer = ac_build_indexed_load_const(&ctx->ac, rw_buffers,
> lp_build_const_int32(gallivm, SI_HS_RING_TESS_OFFCHIP));
>
> base = LLVMGetParam(ctx->main_fn, ctx->param_oc_lds);
> addr = get_tcs_tes_buffer_address(ctx, get_rel_patch_id(ctx), NULL,
> lp_build_const_int32(gallivm, param));
>
> - value = buffer_load(&radeon_bld->bld_base, TGSI_TYPE_FLOAT,
> + value = buffer_load(&ctx->bld_base, TGSI_TYPE_FLOAT,
> ~0, buffer, base, addr, true);
>
> break;
> }
>
> case TGSI_SEMANTIC_DEFAULT_TESSOUTER_SI:
> case TGSI_SEMANTIC_DEFAULT_TESSINNER_SI:
> {
> LLVMValueRef buf, slot, val[4];
> int i, offset;
> @@ -1542,56 +1532,56 @@ static void declare_system_value(
> offset = decl->Semantic.Name == TGSI_SEMANTIC_DEFAULT_TESSINNER_SI ? 4 : 0;
>
> for (i = 0; i < 4; i++)
> val[i] = buffer_load_const(ctx, buf,
> lp_build_const_int32(gallivm, (offset + i) * 4));
> value = lp_build_gather_values(gallivm, val, 4);
> break;
> }
>
> case TGSI_SEMANTIC_PRIMID:
> - value = get_primitive_id(&radeon_bld->bld_base, 0);
> + value = get_primitive_id(&ctx->bld_base, 0);
> break;
>
> case TGSI_SEMANTIC_GRID_SIZE:
> - value = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_GRID_SIZE);
> + value = LLVMGetParam(ctx->main_fn, SI_PARAM_GRID_SIZE);
> break;
>
> case TGSI_SEMANTIC_BLOCK_SIZE:
> {
> LLVMValueRef values[3];
> unsigned i;
> unsigned *properties = ctx->shader->selector->info.properties;
>
> if (properties[TGSI_PROPERTY_CS_FIXED_BLOCK_WIDTH] != 0) {
> unsigned sizes[3] = {
> properties[TGSI_PROPERTY_CS_FIXED_BLOCK_WIDTH],
> properties[TGSI_PROPERTY_CS_FIXED_BLOCK_HEIGHT],
> properties[TGSI_PROPERTY_CS_FIXED_BLOCK_DEPTH]
> };
>
> for (i = 0; i < 3; ++i)
> values[i] = lp_build_const_int32(gallivm, sizes[i]);
>
> value = lp_build_gather_values(gallivm, values, 3);
> } else {
> - value = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_BLOCK_SIZE);
> + value = LLVMGetParam(ctx->main_fn, SI_PARAM_BLOCK_SIZE);
> }
> break;
> }
>
> case TGSI_SEMANTIC_BLOCK_ID:
> - value = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_BLOCK_ID);
> + value = LLVMGetParam(ctx->main_fn, SI_PARAM_BLOCK_ID);
> break;
>
> case TGSI_SEMANTIC_THREAD_ID:
> - value = LLVMGetParam(radeon_bld->main_fn, SI_PARAM_THREAD_ID);
> + value = LLVMGetParam(ctx->main_fn, SI_PARAM_THREAD_ID);
> break;
>
> case TGSI_SEMANTIC_HELPER_INVOCATION:
> if (HAVE_LLVM >= 0x0309) {
> value = lp_build_intrinsic(gallivm->builder,
> "llvm.amdgcn.ps.live",
> ctx->i1, NULL, 0,
> LP_FUNC_ATTR_READNONE);
> value = LLVMBuildNot(gallivm->builder, value, "");
> value = LLVMBuildSExt(gallivm->builder, value, ctx->i32, "");
> @@ -1599,30 +1589,28 @@ static void declare_system_value(
> assert(!"TGSI_SEMANTIC_HELPER_INVOCATION unsupported");
> return;
> }
> break;
>
> default:
> assert(!"unknown system value");
> return;
> }
>
> - radeon_bld->system_values[index] = value;
> + ctx->system_values[index] = value;
> }
>
> -static void declare_compute_memory(struct si_shader_context *radeon_bld,
> +static void declare_compute_memory(struct si_shader_context *ctx,
> const struct tgsi_full_declaration *decl)
> {
> - struct si_shader_context *ctx =
> - si_shader_context(&radeon_bld->bld_base);
> struct si_shader_selector *sel = ctx->shader->selector;
> - struct gallivm_state *gallivm = &radeon_bld->gallivm;
> + struct gallivm_state *gallivm = &ctx->gallivm;
>
> LLVMTypeRef i8p = LLVMPointerType(ctx->i8, LOCAL_ADDR_SPACE);
> LLVMValueRef var;
>
> assert(decl->Declaration.MemType == TGSI_MEMORY_TYPE_SHARED);
> assert(decl->Range.First == decl->Range.Last);
> assert(!ctx->shared_memory);
>
> var = LLVMAddGlobalInAddressSpace(gallivm->module,
> LLVMArrayType(ctx->i8, sel->local_size),
>
--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
More information about the mesa-dev
mailing list