From 2f1e60ccd9cf00d784a6b9abf5ad2fb545fc8431 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 18 Jul 2013 15:28:37 -0400 Subject: [PATCH 2/3] radeonsi: Add helper function for emitting constant loads --- src/gallium/drivers/radeonsi/radeonsi_shader.c | 49 +++++++++++++++----------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/gallium/drivers/radeonsi/radeonsi_shader.c b/src/gallium/drivers/radeonsi/radeonsi_shader.c index 4c5f8c1..775d04f 100644 --- a/src/gallium/drivers/radeonsi/radeonsi_shader.c +++ b/src/gallium/drivers/radeonsi/radeonsi_shader.c @@ -115,6 +115,22 @@ static LLVMValueRef build_indexed_load( return result; } +static LLVMValueRef build_constant_load( + struct si_shader_context * si_shader_ctx, + LLVMValueRef base_ptr, + LLVMValueRef offset) +{ + struct lp_build_context * base = + &si_shader_ctx->radeon_bld.soa.bld_base.base; + LLVMValueRef args[2]; + args[0] = base_ptr; + args[1] = offset; + return build_intrinsic(base->gallivm->builder, "llvm.SI.load.const", + base->elem_type, args, 2, + LLVMReadNoneAttribute | LLVMNoUnwindAttribute); + +} + static LLVMValueRef get_instance_index( struct radeon_llvm_context * radeon_bld, unsigned divisor) @@ -428,7 +444,6 @@ static LLVMValueRef fetch_constant( const struct tgsi_ind_register *ireg = ®->Indirect; unsigned idx; - LLVMValueRef args[2]; LLVMValueRef addr; LLVMValueRef result; @@ -445,15 +460,14 @@ static LLVMValueRef fetch_constant( if (!reg->Register.Indirect) return bitcast(bld_base, type, si_shader_ctx->constants[idx]); - args[0] = si_shader_ctx->const_resource; - args[1] = lp_build_const_int32(base->gallivm, idx * 4); addr = si_shader_ctx->radeon_bld.soa.addr[ireg->Index][ireg->Swizzle]; addr = LLVMBuildLoad(base->gallivm->builder, addr, "load addr reg"); addr = lp_build_mul_imm(&bld_base->uint_bld, addr, 16); - args[1] = lp_build_add(&bld_base->uint_bld, addr, args[1]); + addr = lp_build_add(&bld_base->uint_bld, addr, + lp_build_const_int32(base->gallivm, idx * 4)); - result = build_intrinsic(base->gallivm->builder, "llvm.SI.load.const", base->elem_type, - args, 2, LLVMReadNoneAttribute | LLVMNoUnwindAttribute); + result = build_constant_load(si_shader_ctx, + si_shader_ctx->const_resource, addr); return bitcast(bld_base, type, result); } @@ -626,15 +640,11 @@ static void si_llvm_emit_clipvertex(struct lp_build_tgsi_context * bld_base, /* Compute dot products of position and user clip plane vectors */ for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { for (const_chan = 0; const_chan < TGSI_NUM_CHANNELS; const_chan++) { - args[0] = const_resource; - args[1] = lp_build_const_int32(base->gallivm, - ((reg_index * 4 + chan) * 4 + - const_chan) * 4); - base_elt = build_intrinsic(base->gallivm->builder, - "llvm.SI.load.const", - base->elem_type, - args, 2, - LLVMReadNoneAttribute | LLVMNoUnwindAttribute); + base_elt = build_constant_load(si_shader_ctx, + const_resource, + lp_build_const_int32(base->gallivm, + ((reg_index * 4 + chan) * 4 + + const_chan) * 4)); args[5 + chan] = lp_build_add(base, args[5 + chan], lp_build_mul(base, base_elt, @@ -1433,12 +1443,9 @@ static void preload_constants(struct si_shader_context *si_shader_ctx) /* Load the constants, we rely on the code sinking to do the rest */ for (i = 0; i < num_const * 4; ++i) { - LLVMValueRef args[2] = { - si_shader_ctx->const_resource, - lp_build_const_int32(gallivm, i * 4) - }; - si_shader_ctx->constants[i] = build_intrinsic(gallivm->builder, "llvm.SI.load.const", - bld_base->base.elem_type, args, 2, LLVMReadNoneAttribute | LLVMNoUnwindAttribute); + si_shader_ctx->constants[i] = build_constant_load(si_shader_ctx, + si_shader_ctx->const_resource, + lp_build_const_int32(gallivm, i * 4)); } } -- 1.8.1.5