[Mesa-dev] [PATCH 3/3] r600g: tgsi-to-llvm emits right input intrinsics

Tom Stellard tom at stellard.net
Mon Oct 22 06:31:22 PDT 2012


On Fri, Oct 19, 2012 at 11:19:34PM +0200, Vincent Lejeune wrote:
> ---
>  src/gallium/drivers/r600/r600_llvm.c   | 62 +++++++++++++++++++++++++++-------
>  src/gallium/drivers/r600/r600_shader.c | 22 +++++++-----
>  2 files changed, 62 insertions(+), 22 deletions(-)
> 
> diff --git a/src/gallium/drivers/r600/r600_llvm.c b/src/gallium/drivers/r600/r600_llvm.c
> index 321966e..3dec8ae 100644
> --- a/src/gallium/drivers/r600/r600_llvm.c
> +++ b/src/gallium/drivers/r600/r600_llvm.c
> @@ -90,11 +90,11 @@ llvm_face_select_helper(
>  
>  	LLVMValueRef backcolor = llvm_load_input_helper(
>  		ctx,
> -		"llvm.R600.load.input",
> +		intrinsic,
>  		backcolor_regiser);
>  	LLVMValueRef front_color = llvm_load_input_helper(
>  		ctx,
> -		"llvm.R600.load.input",
> +		intrinsic,
>  		frontcolor_register);
>  	LLVMValueRef face = llvm_load_input_helper(
>  		ctx,
> @@ -120,6 +120,29 @@ static void llvm_load_input(
>  {
>  	unsigned chan;
>  
> +	const char *intrinsics = "llvm.R600.load.input";
> +	unsigned offset = 4 * ctx->reserved_reg_count;
> +
> +	if (ctx->type == TGSI_PROCESSOR_FRAGMENT && ctx->chip_class >= EVERGREEN) {
> +		switch (decl->Interp.Interpolate) {
> +		case TGSI_INTERPOLATE_COLOR:
> +		case TGSI_INTERPOLATE_PERSPECTIVE:
> +			offset = 0;
> +			intrinsics = "llvm.R600.load.input.perspective";
> +			break;
> +		case TGSI_INTERPOLATE_LINEAR:
> +			offset = 0;
> +			intrinsics = "llvm.R600.load.input.linear";
> +			break;
> +		case TGSI_INTERPOLATE_CONSTANT:
> +			offset = 0;
> +			intrinsics = "llvm.R600.load.input.constant";
> +			break;
> +		default:
> +			assert(0 && "Unknow Interpolate mode");
> +		}
> +	}
> +
>  	for (chan = 0; chan < 4; chan++) {
>  		unsigned soa_index = radeon_llvm_reg_index_soa(input_index,
>  								chan);
> @@ -145,24 +168,37 @@ static void llvm_load_input(
>  			break;
>  		case TGSI_SEMANTIC_COLOR:
>  			if (ctx->two_side) {
> +				unsigned front_location, back_location;
>  				unsigned back_reg = ctx->r600_inputs[input_index]
>  					.potential_back_facing_reg;
> -				unsigned back_soa_index = radeon_llvm_reg_index_soa(
> -					ctx->r600_inputs[back_reg].gpr,
> -					chan);
> +				if (ctx->chip_class >= EVERGREEN) {
> +					front_location = 4 * ctx->r600_inputs[input_index].lds_pos + chan;
> +					back_location = 4 * ctx->r600_inputs[back_reg].lds_pos + chan;
> +				} else {
> +					front_location = soa_index + 4 * ctx->reserved_reg_count;
> +					back_location = radeon_llvm_reg_index_soa(
> +						ctx->r600_inputs[back_reg].gpr,
> +						chan);
> +				}
>  				ctx->inputs[soa_index] = llvm_face_select_helper(ctx,
> -				"llvm.R600.load.input",
> -					4 * ctx->face_input,
> -					soa_index + 4 * ctx->reserved_reg_count,
> -					back_soa_index);
> +					intrinsics,
> +					4 * ctx->face_input, front_location, back_location);
>  				break;
>  			}
>  		default:
> -			/* The * 4 is assuming that we are in soa mode. */
> -			ctx->inputs[soa_index] = llvm_load_input_helper(ctx,
> -				"llvm.R600.load.input",
> -				soa_index + (ctx->reserved_reg_count * 4));
> +			{
> +				unsigned location;
> +				if (ctx->chip_class >= EVERGREEN) {
> +					location = 4 * ctx->r600_inputs[input_index].lds_pos + chan;
> +				} else {
> +					location = soa_index + 4 * ctx->reserved_reg_count;
> +				}
> +				/* The * 4 is assuming that we are in soa mode. */
> +				ctx->inputs[soa_index] = llvm_load_input_helper(ctx,
> +					intrinsics, location);
> +					
>  			break;
> +			}
>  		}
>  	}
>  }
> diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
> index 2e3d805..7e0bf7d 100644
> --- a/src/gallium/drivers/r600/r600_shader.c
> +++ b/src/gallium/drivers/r600/r600_shader.c
> @@ -751,16 +751,18 @@ static int r600_spi_sid(struct r600_shader_io * io)
>  };
>  
>  /* turn input into interpolate on EG */
> -static int evergreen_interp_input(struct r600_shader_ctx *ctx, int index)
> +static int evergreen_interp_input(struct r600_shader_ctx *ctx, int index, unsigned use_llvm)
>  {
>  	int r = 0;
>  
>  	if (ctx->shader->input[index].spi_sid) {
>  		ctx->shader->input[index].lds_pos = ctx->shader->nlds++;
> -		if (ctx->shader->input[index].interpolate > 0) {
> -			r = evergreen_interp_alu(ctx, index);
> -		} else {
> -			r = evergreen_interp_flat(ctx, index);
> +		if (!use_llvm) {
> +			if (ctx->shader->input[index].interpolate > 0) {
> +				r = evergreen_interp_alu(ctx, index);
> +			} else {
> +				r = evergreen_interp_flat(ctx, index);
> +			}
>  		}
>  	}
>  	return r;
> @@ -795,7 +797,7 @@ static int select_twoside_color(struct r600_shader_ctx *ctx, int front, int back
>  	return 0;
>  }
>  
> -static int tgsi_declaration(struct r600_shader_ctx *ctx)
> +static int tgsi_declaration(struct r600_shader_ctx *ctx, unsigned use_llvm)
>  {
>  	struct tgsi_full_declaration *d = &ctx->parse.FullToken.FullDeclaration;
>  	unsigned i;
> @@ -823,7 +825,7 @@ static int tgsi_declaration(struct r600_shader_ctx *ctx)
>  				break;
>  			}
>  			if (ctx->bc->chip_class >= EVERGREEN) {
> -				if ((r = evergreen_interp_input(ctx, i)))
> +				if ((r = evergreen_interp_input(ctx, i, use_llvm)))
>  					return r;

I think we should just add use_llvm as a member of struct
r600_shader_ctx, rather than modifying all the function signatures.

>  			}
>  		}
> @@ -1137,7 +1139,7 @@ static int process_twoside_color_inputs(struct r600_shader_ctx *ctx, unsigned us
>  		if (ctx->shader->input[i].name == TGSI_SEMANTIC_COLOR) {
>  			unsigned back_facing_reg = ctx->shader->input[i].potential_back_facing_reg;
>  			if (ctx->bc->chip_class >= EVERGREEN) {
> -				if ((r = evergreen_interp_input(ctx, back_facing_reg)))
> +				if ((r = evergreen_interp_input(ctx, back_facing_reg, use_llvm)))
>  					return r;
>  			}
>  			
> @@ -1281,7 +1283,7 @@ static int r600_shader_from_tgsi(struct r600_screen *rscreen,
>  			ctx.nliterals++;
>  			break;
>  		case TGSI_TOKEN_TYPE_DECLARATION:
> -			r = tgsi_declaration(&ctx);
> +			r = tgsi_declaration(&ctx, use_llvm);
>  			if (r)
>  				goto out_err;
>  			break;
> @@ -1309,6 +1311,7 @@ static int r600_shader_from_tgsi(struct r600_screen *rscreen,
>  	/* Process two side if needed */
>  	if (shader->two_side && ctx.colors_used) {
>  		int i, count = ctx.shader->ninput;
> +		unsigned next_lds_loc = ctx.shader->nlds;
>  
>  		/* additional inputs will be allocated right after the existing inputs,
>  		 * we won't need them after the color selection, so we don't need to
> @@ -1332,6 +1335,7 @@ static int r600_shader_from_tgsi(struct r600_screen *rscreen,
>  				ctx.shader->input[ni].name = TGSI_SEMANTIC_BCOLOR;
>  				ctx.shader->input[ni].spi_sid = r600_spi_sid(&ctx.shader->input[ni]);
>  				ctx.shader->input[ni].gpr = gpr++;
> +				ctx.shader->input[ni].lds_pos = next_lds_loc++;

Why was this line added here?

>  				ctx.shader->input[i].potential_back_facing_reg = ni;
>  			}
>  		}
> -- 
> 1.7.11.7
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list