[Mesa-dev] [PATCH] radeonsi: fix elimination of literal VS outputs

Samuel Pitoiset samuel.pitoiset at gmail.com
Tue Mar 7 00:50:10 UTC 2017


Yeah, "llvm.amdgcn.exp." is probably not what we want. :)

Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>

On 03/07/2017 12:55 AM, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> broken when switched to the new intrinsics.
> ---
>  src/gallium/drivers/radeonsi/si_shader.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
> index ba29661..2c98715 100644
> --- a/src/gallium/drivers/radeonsi/si_shader.c
> +++ b/src/gallium/drivers/radeonsi/si_shader.c
> @@ -6503,32 +6503,35 @@ static void si_init_shader_ctx(struct si_shader_context *ctx,
>  	bld_base->op_actions[TGSI_OPCODE_DDX].emit = si_llvm_emit_ddxy;
>  	bld_base->op_actions[TGSI_OPCODE_DDY].emit = si_llvm_emit_ddxy;
>  	bld_base->op_actions[TGSI_OPCODE_DDX_FINE].emit = si_llvm_emit_ddxy;
>  	bld_base->op_actions[TGSI_OPCODE_DDY_FINE].emit = si_llvm_emit_ddxy;
>
>  	bld_base->op_actions[TGSI_OPCODE_EMIT].emit = si_llvm_emit_vertex;
>  	bld_base->op_actions[TGSI_OPCODE_ENDPRIM].emit = si_llvm_emit_primitive;
>  	bld_base->op_actions[TGSI_OPCODE_BARRIER].emit = si_llvm_emit_barrier;
>  }
>
> +#define EXP_TARGET (HAVE_LLVM >= 0x0500 ? 0 : 3)
> +#define EXP_OUT0 (HAVE_LLVM >= 0x0500 ? 2 : 5)
> +
>  /* Return true if the PARAM export has been eliminated. */
>  static bool si_eliminate_const_output(struct si_shader_context *ctx,
>  				      LLVMValueRef inst, unsigned offset)
>  {
>  	struct si_shader *shader = ctx->shader;
>  	unsigned num_outputs = shader->selector->info.num_outputs;
>  	unsigned i, default_val; /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL */
>  	bool is_zero[4] = {}, is_one[4] = {};
>
>  	for (i = 0; i < 4; i++) {
>  		LLVMBool loses_info;
> -		LLVMValueRef p = LLVMGetOperand(inst, (HAVE_LLVM >= 0x0500 ? 2 : 5) + i);
> +		LLVMValueRef p = LLVMGetOperand(inst, EXP_OUT0 + i);
>
>  		/* It's a constant expression. Undef outputs are eliminated too. */
>  		if (LLVMIsUndef(p)) {
>  			is_zero[i] = true;
>  			is_one[i] = true;
>  		} else if (LLVMIsAConstantFP(p)) {
>  			double a = LLVMConstRealGetDouble(p, &loses_info);
>
>  			if (a == 0)
>  				is_zero[i] = true;
> @@ -6600,24 +6603,24 @@ static void si_eliminate_const_vs_outputs(struct si_shader_context *ctx)
>
>  			if (!lp_is_function(callee))
>  				continue;
>
>  			const char *name = LLVMGetValueName(callee);
>  			unsigned num_args = LLVMCountParams(callee);
>
>  			/* Check if this is an export instruction. */
>  			if ((num_args != 9 && num_args != 8) ||
>  			    (strcmp(name, "llvm.SI.export") &&
> -			     strcmp(name, "llvm.amdgcn.exp.")))
> +			     strcmp(name, "llvm.amdgcn.exp.f32")))
>  				continue;
>
> -			LLVMValueRef arg = LLVMGetOperand(cur, HAVE_LLVM >= 0x0500 ? 0 : 3);
> +			LLVMValueRef arg = LLVMGetOperand(cur, EXP_TARGET);
>  			unsigned target = LLVMConstIntGetZExtValue(arg);
>
>  			if (target < V_008DFC_SQ_EXP_PARAM)
>  				continue;
>
>  			target -= V_008DFC_SQ_EXP_PARAM;
>
>  			/* Eliminate constant value PARAM exports. */
>  			if (si_eliminate_const_output(ctx, cur, target)) {
>  				removed_any = true;
> @@ -6645,21 +6648,21 @@ static void si_eliminate_const_vs_outputs(struct si_shader_context *ctx)
>  		memcpy(current_offset, shader->info.vs_output_param_offset,
>  		       sizeof(current_offset));
>
>  		for (i = 0; i < exports.num; i++) {
>  			unsigned offset = exports.offset[i];
>
>  			for (out = 0; out < info->num_outputs; out++) {
>  				if (current_offset[out] != offset)
>  					continue;
>
> -				LLVMSetOperand(exports.inst[i], 3,
> +				LLVMSetOperand(exports.inst[i], EXP_TARGET,
>  					       LLVMConstInt(ctx->i32,
>  							    V_008DFC_SQ_EXP_PARAM + new_count, 0));
>  				shader->info.vs_output_param_offset[out] = new_count;
>  				new_count++;
>  				break;
>  			}
>  		}
>  		shader->info.nr_param_exports = new_count;
>  	}
>  }
>


More information about the mesa-dev mailing list