From: Marek Olšák Date: Thu, 1 Jun 2017 20:18:58 +0000 (+0200) Subject: radeonsi: add si_build_fs_interp helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f8d6dd9b3d8393329ad5c092cdf153cef6869362;p=mesa.git radeonsi: add si_build_fs_interp helper This is much simpler. Reviewed-by: Nicolai Hähnle --- diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 4c0cda58fb7..a26de99f509 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -1202,6 +1202,24 @@ static int lookup_interp_param_index(unsigned interpolate, unsigned location) } } +static LLVMValueRef si_build_fs_interp(struct si_shader_context *ctx, + unsigned attr_index, unsigned chan, + LLVMValueRef prim_mask, + LLVMValueRef i, LLVMValueRef j) +{ + if (i || j) { + return ac_build_fs_interp(&ctx->ac, + LLVMConstInt(ctx->i32, chan, 0), + LLVMConstInt(ctx->i32, attr_index, 0), + prim_mask, i, j); + } + return ac_build_fs_interp_mov(&ctx->ac, + LLVMConstInt(ctx->i32, 2, 0), /* P0 */ + LLVMConstInt(ctx->i32, chan, 0), + LLVMConstInt(ctx->i32, attr_index, 0), + prim_mask); +} + /** * Interpolate a fragment shader input. * @@ -1228,9 +1246,7 @@ static void interp_fs_input(struct si_shader_context *ctx, LLVMValueRef result[4]) { struct gallivm_state *gallivm = &ctx->gallivm; - LLVMValueRef attr_number; - LLVMValueRef i, j; - + LLVMValueRef i = NULL, j = NULL; unsigned chan; /* fs.constant returns the param from the middle vertex, so it's not @@ -1248,8 +1264,6 @@ static void interp_fs_input(struct si_shader_context *ctx, */ bool interp = interp_param != NULL; - attr_number = LLVMConstInt(ctx->i32, input_index, 0); - if (interp) { interp_param = LLVMBuildBitCast(gallivm->builder, interp_param, LLVMVectorType(ctx->f32, 2), ""); @@ -1263,7 +1277,6 @@ static void interp_fs_input(struct si_shader_context *ctx, if (semantic_name == TGSI_SEMANTIC_COLOR && ctx->shader->key.part.ps.prolog.color_two_side) { LLVMValueRef is_face_positive; - LLVMValueRef back_attr_number; /* If BCOLOR0 is used, BCOLOR1 is at offset "num_inputs + 1", * otherwise it's at offset "num_inputs". @@ -1272,30 +1285,18 @@ static void interp_fs_input(struct si_shader_context *ctx, if (semantic_index == 1 && colors_read_mask & 0xf) back_attr_offset += 1; - back_attr_number = LLVMConstInt(ctx->i32, back_attr_offset, 0); - is_face_positive = LLVMBuildICmp(gallivm->builder, LLVMIntNE, face, ctx->i32_0, ""); for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { - LLVMValueRef llvm_chan = LLVMConstInt(ctx->i32, chan, 0); LLVMValueRef front, back; - if (interp) { - front = ac_build_fs_interp(&ctx->ac, llvm_chan, - attr_number, prim_mask, - i, j); - back = ac_build_fs_interp(&ctx->ac, llvm_chan, - back_attr_number, prim_mask, - i, j); - } else { - front = ac_build_fs_interp_mov(&ctx->ac, - LLVMConstInt(ctx->i32, 2, 0), /* P0 */ - llvm_chan, attr_number, prim_mask); - back = ac_build_fs_interp_mov(&ctx->ac, - LLVMConstInt(ctx->i32, 2, 0), /* P0 */ - llvm_chan, back_attr_number, prim_mask); - } + front = si_build_fs_interp(ctx, + input_index, chan, + prim_mask, i, j); + back = si_build_fs_interp(ctx, + back_attr_offset, chan, + prim_mask, i, j); result[chan] = LLVMBuildSelect(gallivm->builder, is_face_positive, @@ -1304,29 +1305,16 @@ static void interp_fs_input(struct si_shader_context *ctx, ""); } } else if (semantic_name == TGSI_SEMANTIC_FOG) { - if (interp) { - result[0] = ac_build_fs_interp(&ctx->ac, ctx->i32_0, - attr_number, prim_mask, i, j); - } else { - result[0] = ac_build_fs_interp_mov(&ctx->ac, ctx->i32_0, - LLVMConstInt(ctx->i32, 2, 0), /* P0 */ - attr_number, prim_mask); - } + result[0] = si_build_fs_interp(ctx, input_index, + 0, prim_mask, i, j); result[1] = result[2] = LLVMConstReal(ctx->f32, 0.0f); result[3] = LLVMConstReal(ctx->f32, 1.0f); } else { for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { - LLVMValueRef llvm_chan = LLVMConstInt(ctx->i32, chan, 0); - - if (interp) { - result[chan] = ac_build_fs_interp(&ctx->ac, - llvm_chan, attr_number, prim_mask, i, j); - } else { - result[chan] = ac_build_fs_interp_mov(&ctx->ac, - LLVMConstInt(ctx->i32, 2, 0), /* P0 */ - llvm_chan, attr_number, prim_mask); - } + result[chan] = si_build_fs_interp(ctx, + input_index, chan, + prim_mask, i, j); } } } @@ -3531,7 +3519,7 @@ static void build_interp_intrinsic(const struct lp_build_tgsi_action *action, int input_base, input_array_size; int chan; int i; - LLVMValueRef params = LLVMGetParam(ctx->main_fn, SI_PARAM_PRIM_MASK); + LLVMValueRef prim_mask = LLVMGetParam(ctx->main_fn, SI_PARAM_PRIM_MASK); LLVMValueRef array_idx; int interp_param_idx; unsigned interp; @@ -3618,35 +3606,25 @@ static void build_interp_intrinsic(const struct lp_build_tgsi_action *action, } for (chan = 0; chan < 4; chan++) { - LLVMValueRef llvm_chan; LLVMValueRef gather = LLVMGetUndef(LLVMVectorType(ctx->f32, input_array_size)); - unsigned schan; - - schan = tgsi_util_get_full_src_register_swizzle(&inst->Src[0], chan); - llvm_chan = LLVMConstInt(ctx->i32, schan, 0); + unsigned schan = tgsi_util_get_full_src_register_swizzle(&inst->Src[0], chan); - for (unsigned i = 0; i < input_array_size; ++i) { - LLVMValueRef attr_number = LLVMConstInt(ctx->i32, input_base + i, false); - LLVMValueRef v; + for (unsigned idx = 0; idx < input_array_size; ++idx) { + LLVMValueRef v, i = NULL, j = NULL; if (interp_param) { interp_param = LLVMBuildBitCast(gallivm->builder, interp_param, LLVMVectorType(ctx->f32, 2), ""); - LLVMValueRef i = LLVMBuildExtractElement( + i = LLVMBuildExtractElement( gallivm->builder, interp_param, ctx->i32_0, ""); - LLVMValueRef j = LLVMBuildExtractElement( + j = LLVMBuildExtractElement( gallivm->builder, interp_param, ctx->i32_1, ""); - v = ac_build_fs_interp(&ctx->ac, - llvm_chan, attr_number, params, - i, j); - } else { - v = ac_build_fs_interp_mov(&ctx->ac, - LLVMConstInt(ctx->i32, 2, 0), /* P0 */ - llvm_chan, attr_number, params); } + v = si_build_fs_interp(ctx, input_base + idx, schan, + prim_mask, i, j); gather = LLVMBuildInsertElement(gallivm->builder, - gather, v, LLVMConstInt(ctx->i32, i, false), ""); + gather, v, LLVMConstInt(ctx->i32, idx, false), ""); } emit_data->output[chan] = LLVMBuildExtractElement(