gallium: switch dedicated centroid field to interpolation location

The new location field can be either center, centroid, or sample, which
indicates the location that the shader should interpolate at.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
This commit is contained in:
Ilia Mirkin
2014-07-01 20:54:01 -04:00
parent e3b16294cb
commit 4c97ed4411
17 changed files with 57 additions and 31 deletions

View File

@@ -200,7 +200,7 @@ tgsi_default_declaration_interp( void )
struct tgsi_declaration_interp di; struct tgsi_declaration_interp di;
di.Interpolate = TGSI_INTERPOLATE_CONSTANT; di.Interpolate = TGSI_INTERPOLATE_CONSTANT;
di.Centroid = 0; di.Location = TGSI_INTERPOLATE_LOC_CENTER;
di.CylindricalWrap = 0; di.CylindricalWrap = 0;
di.Padding = 0; di.Padding = 0;
@@ -209,7 +209,7 @@ tgsi_default_declaration_interp( void )
static struct tgsi_declaration_interp static struct tgsi_declaration_interp
tgsi_build_declaration_interp(unsigned interpolate, tgsi_build_declaration_interp(unsigned interpolate,
unsigned centroid, unsigned interpolate_location,
unsigned cylindrical_wrap, unsigned cylindrical_wrap,
struct tgsi_declaration *declaration, struct tgsi_declaration *declaration,
struct tgsi_header *header) struct tgsi_header *header)
@@ -217,7 +217,7 @@ tgsi_build_declaration_interp(unsigned interpolate,
struct tgsi_declaration_interp di; struct tgsi_declaration_interp di;
di.Interpolate = interpolate; di.Interpolate = interpolate;
di.Centroid = centroid; di.Location = interpolate_location;
di.CylindricalWrap = cylindrical_wrap; di.CylindricalWrap = cylindrical_wrap;
di.Padding = 0; di.Padding = 0;
@@ -433,7 +433,7 @@ tgsi_build_full_declaration(
size++; size++;
*di = tgsi_build_declaration_interp(full_decl->Interp.Interpolate, *di = tgsi_build_declaration_interp(full_decl->Interp.Interpolate,
full_decl->Interp.Centroid, full_decl->Interp.Location,
full_decl->Interp.CylindricalWrap, full_decl->Interp.CylindricalWrap,
declaration, declaration,
header); header);

View File

@@ -349,8 +349,9 @@ iter_declaration(
ENM( decl->Interp.Interpolate, tgsi_interpolate_names ); ENM( decl->Interp.Interpolate, tgsi_interpolate_names );
} }
if (decl->Interp.Centroid) { if (decl->Interp.Location != TGSI_INTERPOLATE_LOC_CENTER) {
TXT( ", CENTROID" ); TXT( ", " );
ENM( decl->Interp.Location, tgsi_interpolate_locations );
} }
if (decl->Interp.CylindricalWrap) { if (decl->Interp.CylindricalWrap) {

View File

@@ -187,7 +187,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
info->input_semantic_name[reg] = (ubyte) semName; info->input_semantic_name[reg] = (ubyte) semName;
info->input_semantic_index[reg] = (ubyte) semIndex; info->input_semantic_index[reg] = (ubyte) semIndex;
info->input_interpolate[reg] = (ubyte)fulldecl->Interp.Interpolate; info->input_interpolate[reg] = (ubyte)fulldecl->Interp.Interpolate;
info->input_centroid[reg] = (ubyte)fulldecl->Interp.Centroid; info->input_interpolate_loc[reg] = (ubyte)fulldecl->Interp.Location;
info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Interp.CylindricalWrap; info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Interp.CylindricalWrap;
info->num_inputs++; info->num_inputs++;

View File

@@ -45,7 +45,7 @@ struct tgsi_shader_info
ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */ ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */
ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
ubyte input_interpolate[PIPE_MAX_SHADER_INPUTS]; ubyte input_interpolate[PIPE_MAX_SHADER_INPUTS];
ubyte input_centroid[PIPE_MAX_SHADER_INPUTS]; ubyte input_interpolate_loc[PIPE_MAX_SHADER_INPUTS];
ubyte input_usage_mask[PIPE_MAX_SHADER_INPUTS]; ubyte input_usage_mask[PIPE_MAX_SHADER_INPUTS];
ubyte input_cylindrical_wrap[PIPE_MAX_SHADER_INPUTS]; ubyte input_cylindrical_wrap[PIPE_MAX_SHADER_INPUTS];
ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */ ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */

View File

@@ -142,6 +142,13 @@ const char *tgsi_interpolate_names[TGSI_INTERPOLATE_COUNT] =
"COLOR" "COLOR"
}; };
const char *tgsi_interpolate_locations[TGSI_INTERPOLATE_LOC_COUNT] =
{
"CENTER",
"CENTROID",
"SAMPLE",
};
const char *tgsi_primitive_names[PIPE_PRIM_MAX] = const char *tgsi_primitive_names[PIPE_PRIM_MAX] =
{ {
"POINTS", "POINTS",

View File

@@ -50,6 +50,8 @@ extern const char *tgsi_type_names[5];
extern const char *tgsi_interpolate_names[TGSI_INTERPOLATE_COUNT]; extern const char *tgsi_interpolate_names[TGSI_INTERPOLATE_COUNT];
extern const char *tgsi_interpolate_locations[TGSI_INTERPOLATE_LOC_COUNT];
extern const char *tgsi_primitive_names[PIPE_PRIM_MAX]; extern const char *tgsi_primitive_names[PIPE_PRIM_MAX];
extern const char *tgsi_fs_coord_origin_names[2]; extern const char *tgsi_fs_coord_origin_names[2];

View File

@@ -103,7 +103,7 @@ struct ureg_program
unsigned semantic_index; unsigned semantic_index;
unsigned interp; unsigned interp;
unsigned char cylindrical_wrap; unsigned char cylindrical_wrap;
unsigned char centroid; unsigned interp_location;
} fs_input[UREG_MAX_INPUT]; } fs_input[UREG_MAX_INPUT];
unsigned nr_fs_inputs; unsigned nr_fs_inputs;
@@ -345,7 +345,7 @@ ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg,
unsigned semantic_index, unsigned semantic_index,
unsigned interp_mode, unsigned interp_mode,
unsigned cylindrical_wrap, unsigned cylindrical_wrap,
unsigned centroid) unsigned interp_location)
{ {
unsigned i; unsigned i;
@@ -361,7 +361,7 @@ ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg,
ureg->fs_input[i].semantic_index = semantic_index; ureg->fs_input[i].semantic_index = semantic_index;
ureg->fs_input[i].interp = interp_mode; ureg->fs_input[i].interp = interp_mode;
ureg->fs_input[i].cylindrical_wrap = cylindrical_wrap; ureg->fs_input[i].cylindrical_wrap = cylindrical_wrap;
ureg->fs_input[i].centroid = centroid; ureg->fs_input[i].interp_location = interp_location;
ureg->nr_fs_inputs++; ureg->nr_fs_inputs++;
} else { } else {
set_bad(ureg); set_bad(ureg);
@@ -1288,7 +1288,7 @@ emit_decl_fs(struct ureg_program *ureg,
unsigned semantic_index, unsigned semantic_index,
unsigned interpolate, unsigned interpolate,
unsigned cylindrical_wrap, unsigned cylindrical_wrap,
unsigned centroid) unsigned interpolate_location)
{ {
union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 4); union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 4);
@@ -1307,7 +1307,7 @@ emit_decl_fs(struct ureg_program *ureg,
out[2].value = 0; out[2].value = 0;
out[2].decl_interp.Interpolate = interpolate; out[2].decl_interp.Interpolate = interpolate;
out[2].decl_interp.CylindricalWrap = cylindrical_wrap; out[2].decl_interp.CylindricalWrap = cylindrical_wrap;
out[2].decl_interp.Centroid = centroid; out[2].decl_interp.Location = interpolate_location;
out[3].value = 0; out[3].value = 0;
out[3].decl_semantic.Name = semantic_name; out[3].decl_semantic.Name = semantic_name;
@@ -1539,7 +1539,7 @@ static void emit_decls( struct ureg_program *ureg )
ureg->fs_input[i].semantic_index, ureg->fs_input[i].semantic_index,
ureg->fs_input[i].interp, ureg->fs_input[i].interp,
ureg->fs_input[i].cylindrical_wrap, ureg->fs_input[i].cylindrical_wrap,
ureg->fs_input[i].centroid); ureg->fs_input[i].interp_location);
} }
} else { } else {
for (i = 0; i < ureg->nr_gs_inputs; i++) { for (i = 0; i < ureg->nr_gs_inputs; i++) {

View File

@@ -199,7 +199,7 @@ ureg_DECL_fs_input_cyl_centroid(struct ureg_program *,
unsigned semantic_index, unsigned semantic_index,
unsigned interp_mode, unsigned interp_mode,
unsigned cylindrical_wrap, unsigned cylindrical_wrap,
unsigned centroid); unsigned interp_location);
static INLINE struct ureg_src static INLINE struct ureg_src
ureg_DECL_fs_input_cyl(struct ureg_program *ureg, ureg_DECL_fs_input_cyl(struct ureg_program *ureg,

View File

@@ -2735,6 +2735,11 @@ This token is only valid for fragment shader INPUT declarations.
The Interpolate field specifes the way input is being interpolated by The Interpolate field specifes the way input is being interpolated by
the rasteriser and is one of TGSI_INTERPOLATE_*. the rasteriser and is one of TGSI_INTERPOLATE_*.
The Location field specifies the location inside the pixel that the
interpolation should be done at, one of ``TGSI_INTERPOLATE_LOC_*``. Note that
when per-sample shading is enabled, the implementation may choose to
interpolate at the sample irrespective of the Location field.
The CylindricalWrap bitfield specifies which register components The CylindricalWrap bitfield specifies which register components
should be subject to cylindrical wrapping when interpolating by the should be subject to cylindrical wrapping when interpolating by the
rasteriser. If TGSI_CYLINDRICAL_WRAP_X is set to 1, the X component rasteriser. If TGSI_CYLINDRICAL_WRAP_X is set to 1, the X component

View File

@@ -2298,7 +2298,7 @@ decl_add_in(struct toy_tgsi *tgsi, const struct tgsi_full_declaration *decl)
tgsi->inputs[slot].semantic_index = index; tgsi->inputs[slot].semantic_index = index;
} }
tgsi->inputs[slot].interp = interp->Interpolate; tgsi->inputs[slot].interp = interp->Interpolate;
tgsi->inputs[slot].centroid = interp->Centroid; tgsi->inputs[slot].centroid = interp->Location == TGSI_INTERPOLATE_LOC_CENTROID;
} }
} }

View File

@@ -950,7 +950,7 @@ bool Source::scanDeclaration(const struct tgsi_full_declaration *decl)
default: default:
break; break;
} }
if (decl->Interp.Centroid || info->io.sampleInterp) if (decl->Interp.Location || info->io.sampleInterp)
info->in[i].centroid = 1; info->in[i].centroid = 1;
} }
} }

View File

@@ -579,7 +579,7 @@ static int tgsi_declaration(struct r600_shader_ctx *ctx)
ctx->shader->input[i].name = d->Semantic.Name; ctx->shader->input[i].name = d->Semantic.Name;
ctx->shader->input[i].sid = d->Semantic.Index; ctx->shader->input[i].sid = d->Semantic.Index;
ctx->shader->input[i].interpolate = d->Interp.Interpolate; ctx->shader->input[i].interpolate = d->Interp.Interpolate;
ctx->shader->input[i].centroid = d->Interp.Centroid; ctx->shader->input[i].centroid = d->Interp.Location == TGSI_INTERPOLATE_LOC_CENTROID;
ctx->shader->input[i].gpr = ctx->file_offset[TGSI_FILE_INPUT] + d->Range.First; ctx->shader->input[i].gpr = ctx->file_offset[TGSI_FILE_INPUT] + d->Range.First;
if (ctx->type == TGSI_PROCESSOR_FRAGMENT) { if (ctx->type == TGSI_PROCESSOR_FRAGMENT) {
ctx->shader->input[i].spi_sid = r600_spi_sid(&ctx->shader->input[i]); ctx->shader->input[i].spi_sid = r600_spi_sid(&ctx->shader->input[i]);
@@ -735,7 +735,7 @@ static int evergreen_gpr_count(struct r600_shader_ctx *ctx)
ctx->input_linear = TRUE; ctx->input_linear = TRUE;
if (ctx->info.input_interpolate[i] == TGSI_INTERPOLATE_PERSPECTIVE) if (ctx->info.input_interpolate[i] == TGSI_INTERPOLATE_PERSPECTIVE)
ctx->input_perspective = TRUE; ctx->input_perspective = TRUE;
if (ctx->info.input_centroid[i]) if (ctx->info.input_interpolate_loc[i] == TGSI_INTERPOLATE_LOC_CENTROID)
ctx->input_centroid = TRUE; ctx->input_centroid = TRUE;
} }

View File

@@ -172,7 +172,7 @@ static int si_store_shader_io_attribs(struct si_shader *shader,
shader->input[i].sid = d->Semantic.Index; shader->input[i].sid = d->Semantic.Index;
shader->input[i].index = d->Range.First; shader->input[i].index = d->Range.First;
shader->input[i].interpolate = d->Interp.Interpolate; shader->input[i].interpolate = d->Interp.Interpolate;
shader->input[i].centroid = d->Interp.Centroid; shader->input[i].centroid = d->Interp.Location == TGSI_INTERPOLATE_LOC_CENTROID;
return -1; return -1;
case TGSI_FILE_OUTPUT: case TGSI_FILE_OUTPUT:
@@ -427,7 +427,7 @@ static void declare_input_fs(
case TGSI_INTERPOLATE_LINEAR: case TGSI_INTERPOLATE_LINEAR:
if (si_shader_ctx->shader->key.ps.interp_at_sample) if (si_shader_ctx->shader->key.ps.interp_at_sample)
interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_SAMPLE); interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_SAMPLE);
else if (decl->Interp.Centroid) else if (decl->Interp.Location == TGSI_INTERPOLATE_LOC_CENTROID)
interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_CENTROID); interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_CENTROID);
else else
interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_CENTER); interp_param = LLVMGetParam(main_fn, SI_PARAM_LINEAR_CENTER);
@@ -441,7 +441,7 @@ static void declare_input_fs(
case TGSI_INTERPOLATE_PERSPECTIVE: case TGSI_INTERPOLATE_PERSPECTIVE:
if (si_shader_ctx->shader->key.ps.interp_at_sample) if (si_shader_ctx->shader->key.ps.interp_at_sample)
interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_SAMPLE); interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_SAMPLE);
else if (decl->Interp.Centroid) else if (decl->Interp.Location == TGSI_INTERPOLATE_LOC_CENTROID)
interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTROID); interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTROID);
else else
interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTER); interp_param = LLVMGetParam(main_fn, SI_PARAM_PERSP_CENTER);

View File

@@ -103,6 +103,11 @@ enum tgsi_file_type {
#define TGSI_INTERPOLATE_COLOR 3 /* special color case for smooth/flat */ #define TGSI_INTERPOLATE_COLOR 3 /* special color case for smooth/flat */
#define TGSI_INTERPOLATE_COUNT 4 #define TGSI_INTERPOLATE_COUNT 4
#define TGSI_INTERPOLATE_LOC_CENTER 0
#define TGSI_INTERPOLATE_LOC_CENTROID 1
#define TGSI_INTERPOLATE_LOC_SAMPLE 2
#define TGSI_INTERPOLATE_LOC_COUNT 3
#define TGSI_CYLINDRICAL_WRAP_X (1 << 0) #define TGSI_CYLINDRICAL_WRAP_X (1 << 0)
#define TGSI_CYLINDRICAL_WRAP_Y (1 << 1) #define TGSI_CYLINDRICAL_WRAP_Y (1 << 1)
#define TGSI_CYLINDRICAL_WRAP_Z (1 << 2) #define TGSI_CYLINDRICAL_WRAP_Z (1 << 2)
@@ -138,9 +143,9 @@ struct tgsi_declaration_dimension
struct tgsi_declaration_interp struct tgsi_declaration_interp
{ {
unsigned Interpolate : 4; /**< one of TGSI_INTERPOLATE_x */ unsigned Interpolate : 4; /**< one of TGSI_INTERPOLATE_x */
unsigned Centroid : 1; /**< centroid sampling? */ unsigned Location : 2; /**< one of TGSI_INTERPOLATE_LOC_x */
unsigned CylindricalWrap:4; /**< TGSI_CYLINDRICAL_WRAP_x flags */ unsigned CylindricalWrap:4; /**< TGSI_CYLINDRICAL_WRAP_x flags */
unsigned Padding : 23; unsigned Padding : 22;
}; };
#define TGSI_SEMANTIC_POSITION 0 #define TGSI_SEMANTIC_POSITION 0

View File

@@ -4848,6 +4848,7 @@ emit_edgeflags(struct st_translate *t)
* \param inputSemanticIndex the semantic index (ex: which texcoord) for * \param inputSemanticIndex the semantic index (ex: which texcoord) for
* each input * each input
* \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input * \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
* \param interpLocation the TGSI_INTERPOLATE_LOC_* location for each input
* \param numOutputs number of output registers used * \param numOutputs number of output registers used
* \param outputMapping maps Mesa fragment program outputs to TGSI * \param outputMapping maps Mesa fragment program outputs to TGSI
* generic outputs * generic outputs
@@ -4869,7 +4870,7 @@ st_translate_program(
const ubyte inputSemanticName[], const ubyte inputSemanticName[],
const ubyte inputSemanticIndex[], const ubyte inputSemanticIndex[],
const GLuint interpMode[], const GLuint interpMode[],
const GLboolean is_centroid[], const GLuint interpLocation[],
GLuint numOutputs, GLuint numOutputs,
const GLuint outputMapping[], const GLuint outputMapping[],
const ubyte outputSemanticName[], const ubyte outputSemanticName[],
@@ -4915,7 +4916,7 @@ st_translate_program(
inputSemanticName[i], inputSemanticName[i],
inputSemanticIndex[i], inputSemanticIndex[i],
interpMode[i], 0, interpMode[i], 0,
is_centroid[i]); interpLocation[i]);
} }
if (proginfo->InputsRead & VARYING_BIT_POS) { if (proginfo->InputsRead & VARYING_BIT_POS) {

View File

@@ -45,7 +45,7 @@ enum pipe_error st_translate_program(
const ubyte inputSemanticName[], const ubyte inputSemanticName[],
const ubyte inputSemanticIndex[], const ubyte inputSemanticIndex[],
const GLuint interpMode[], const GLuint interpMode[],
const GLboolean is_centroid[], const GLuint interpLocation[],
GLuint numOutputs, GLuint numOutputs,
const GLuint outputMapping[], const GLuint outputMapping[],
const ubyte outputSemanticName[], const ubyte outputSemanticName[],

View File

@@ -351,7 +351,7 @@ st_translate_vertex_program(struct st_context *st,
NULL, /* input semantic name */ NULL, /* input semantic name */
NULL, /* input semantic index */ NULL, /* input semantic index */
NULL, /* interp mode */ NULL, /* interp mode */
NULL, /* is centroid */ NULL, /* interp location */
/* outputs */ /* outputs */
num_outputs, num_outputs,
stvp->result_to_output, stvp->result_to_output,
@@ -481,6 +481,7 @@ st_translate_fragment_program(struct st_context *st,
GLuint outputMapping[FRAG_RESULT_MAX]; GLuint outputMapping[FRAG_RESULT_MAX];
GLuint inputMapping[VARYING_SLOT_MAX]; GLuint inputMapping[VARYING_SLOT_MAX];
GLuint interpMode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */ GLuint interpMode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */
GLuint interpLocation[PIPE_MAX_SHADER_INPUTS];
GLuint attr; GLuint attr;
GLbitfield64 inputsRead; GLbitfield64 inputsRead;
struct ureg_program *ureg; struct ureg_program *ureg;
@@ -489,7 +490,6 @@ st_translate_fragment_program(struct st_context *st,
ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
GLboolean is_centroid[PIPE_MAX_SHADER_INPUTS];
uint fs_num_inputs = 0; uint fs_num_inputs = 0;
ubyte fs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; ubyte fs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
@@ -541,7 +541,12 @@ st_translate_fragment_program(struct st_context *st,
const GLuint slot = fs_num_inputs++; const GLuint slot = fs_num_inputs++;
inputMapping[attr] = slot; inputMapping[attr] = slot;
is_centroid[slot] = (stfp->Base.IsCentroid & BITFIELD64_BIT(attr)) != 0; if (stfp->Base.IsCentroid & BITFIELD64_BIT(attr))
interpLocation[slot] = TGSI_INTERPOLATE_LOC_CENTROID;
else if (stfp->Base.IsSample & BITFIELD64_BIT(attr))
interpLocation[slot] = TGSI_INTERPOLATE_LOC_SAMPLE;
else
interpLocation[slot] = TGSI_INTERPOLATE_LOC_CENTER;
switch (attr) { switch (attr) {
case VARYING_SLOT_POS: case VARYING_SLOT_POS:
@@ -768,7 +773,7 @@ st_translate_fragment_program(struct st_context *st,
input_semantic_name, input_semantic_name,
input_semantic_index, input_semantic_index,
interpMode, interpMode,
is_centroid, interpLocation,
/* outputs */ /* outputs */
fs_num_outputs, fs_num_outputs,
outputMapping, outputMapping,