mesa: add new FRAG_ATTRIB_FACE and FRAG_ATTRIB_PNTC fragment program inputs

Previously, the FOGC attribute contained the fragment fog coord, front/back-
face flag and the gl_PointCoord.xy values.  Now each of those things are
separate fragment program attributes.  This simplifies quite a few things in
Mesa and gallium.

Need to test i965 driver and fix up point coord handling in the gallium/draw
module...
This commit is contained in:
Brian Paul
2009-07-29 20:07:41 -06:00
parent 0723cd1b0a
commit 9d0b8d72d8
11 changed files with 69 additions and 138 deletions

View File

@@ -376,14 +376,6 @@ static void emit_interp( struct brw_wm_compile *c,
}
break;
case FRAG_ATTRIB_FOGC:
/* The FOGC input is really special. When a program uses glFogFragCoord,
* the results returned are supposed to be (f,0,0,1). But for Mesa GLSL,
* the glFrontFacing and glPointCoord values are also stashed in FOGC.
* So, write the interpolated fog value to X, then either 0, 1, or the
* stashed values to Y, Z, W. Note that this means that
* glFogFragCoord.yzw can be wrong in those cases!
*/
/* Interpolate the fog coordinate */
emit_op(c,
WM_PINTERP,
@@ -393,26 +385,40 @@ static void emit_interp( struct brw_wm_compile *c,
deltas,
get_pixel_w(c));
/* Move the front facing value into FOGC.y if it's needed. */
if (c->fp->program.UsesFrontFacing) {
emit_op(c,
WM_FRONTFACING,
dst_mask(dst, WRITEMASK_Y),
0,
src_undef(),
src_undef(),
src_undef());
} else {
emit_op(c,
OPCODE_MOV,
dst_mask(dst, WRITEMASK_Y),
dst_mask(dst, WRITEMASK_YZW),
0,
src_swizzle1(interp, SWIZZLE_ZERO),
src_swizzle(interp,
SWIZZLE_ZERO,
SWIZZLE_ZERO,
SWIZZLE_ZERO,
SWIZZLE_ONE),
src_undef(),
src_undef());
}
break;
case FRAG_ATTRIB_FACE:
/* XXX review/test this case */
emit_op(c,
WM_FRONTFACING,
dst_mask(dst, WRITEMASK_X),
0,
src_undef(),
src_undef(),
src_undef());
break;
case FRAG_ATTRIB_PNTC:
/* XXX review/test this case */
emit_op(c,
WM_PINTERP,
dst_mask(dst, WRITEMASK_XY),
0,
interp,
deltas,
get_pixel_w(c));
/* Should do the PointCoord thing here. */
emit_op(c,
OPCODE_MOV,
dst_mask(dst, WRITEMASK_ZW),
@@ -425,6 +431,7 @@ static void emit_interp( struct brw_wm_compile *c,
src_undef(),
src_undef());
break;
default:
emit_op(c,
WM_PINTERP,

View File

@@ -227,7 +227,9 @@ typedef enum
FRAG_ATTRIB_TEX5 = 9,
FRAG_ATTRIB_TEX6 = 10,
FRAG_ATTRIB_TEX7 = 11,
FRAG_ATTRIB_VAR0 = 12, /**< shader varying */
FRAG_ATTRIB_FACE = 12, /**< front/back face */
FRAG_ATTRIB_PNTC = 13, /**< sprite/point coord */
FRAG_ATTRIB_VAR0 = 14, /**< shader varying */
FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
} gl_frag_attrib;
@@ -239,6 +241,8 @@ typedef enum
#define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0)
#define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1)
#define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC)
#define FRAG_BIT_FACE (1 << FRAG_ATTRIB_FACE)
#define FRAG_BIT_PNTC (1 << FRAG_ATTRIB_PNTC)
#define FRAG_BIT_TEX0 (1 << FRAG_ATTRIB_TEX0)
#define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1)
#define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2)
@@ -1834,9 +1838,6 @@ struct gl_fragment_program
struct gl_program Base; /**< base class */
GLenum FogOption;
GLboolean UsesKill; /**< shader uses KIL instruction */
GLboolean UsesPointCoord; /**< shader uses gl_PointCoord */
GLboolean UsesFrontFacing; /**< shader used gl_FrontFacing */
GLboolean UsesFogFragCoord; /**< shader used gl_FogFragCoord */
};

View File

@@ -3974,13 +3974,6 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target,
if (program->FogOption)
program->Base.InputsRead |= FRAG_BIT_FOGC;
/* XXX: assume that ARB fragment programs don't have access to the
* FrontFacing and PointCoord values stuffed into the fog
* coordinate in GLSL shaders.
*/
if (program->Base.InputsRead & FRAG_BIT_FOGC)
program->UsesFogFragCoord = GL_TRUE;
if (program->Base.Instructions)
_mesa_free(program->Base.Instructions);
program->Base.Instructions = ap.Base.Instructions;

View File

@@ -396,7 +396,6 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog)
fprog->Base.Instructions = newInst;
fprog->Base.NumInstructions = inst - newInst;
fprog->Base.InputsRead |= FRAG_BIT_FOGC;
fprog->UsesFogFragCoord = GL_TRUE;
/* XXX do this? fprog->FogOption = GL_NONE; */
}

View File

@@ -381,8 +381,8 @@ _slang_input_index(const char *name, GLenum target, GLuint *swizzleOut)
{ "gl_TexCoord", FRAG_ATTRIB_TEX0, SWIZZLE_NOOP },
/* note: we're packing several quantities into the fogcoord vector */
{ "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX },
{ "gl_FrontFacing", FRAG_ATTRIB_FOGC, SWIZZLE_YYYY }, /*XXX*/
{ "gl_PointCoord", FRAG_ATTRIB_FOGC, SWIZZLE_ZWWW },
{ "gl_PointCoord", FRAG_ATTRIB_PNTC, SWIZZLE_XYZW },
{ "gl_FrontFacing", FRAG_ATTRIB_FACE, SWIZZLE_XXXX },
{ NULL, 0, SWIZZLE_NOOP }
};
GLuint i;

View File

@@ -484,20 +484,6 @@ _slang_update_inputs_outputs(struct gl_program *prog)
for (j = 0; j < numSrc; j++) {
if (inst->SrcReg[j].File == PROGRAM_INPUT) {
prog->InputsRead |= 1 << inst->SrcReg[j].Index;
if (prog->Target == GL_FRAGMENT_PROGRAM_ARB &&
inst->SrcReg[j].Index == FRAG_ATTRIB_FOGC) {
/* The fragment shader FOGC input is used for fog,
* front-facing and sprite/point coord.
*/
struct gl_fragment_program *fp = fragment_program(prog);
const GLint swz = GET_SWZ(inst->SrcReg[j].Swizzle, 0);
if (swz == SWIZZLE_X)
fp->UsesFogFragCoord = GL_TRUE;
else if (swz == SWIZZLE_Y)
fp->UsesFrontFacing = GL_TRUE;
else if (swz == SWIZZLE_Z || swz == SWIZZLE_W)
fp->UsesPointCoord = GL_TRUE;
}
}
else if (inst->SrcReg[j].File == PROGRAM_ADDRESS) {
maxAddrReg = MAX2(maxAddrReg, (GLuint) (inst->SrcReg[j].Index + 1));

View File

@@ -139,23 +139,6 @@ find_translated_vp(struct st_context *st,
if (fragInputsRead & (1 << inAttr)) {
stfp->input_to_slot[inAttr] = numIn;
numIn++;
if (((1 << inAttr) & FRAG_BIT_FOGC)) {
/* leave placeholders for the
* extra registers we extract from fog */
if (stfp->Base.UsesFrontFacing) {
if (!stfp->Base.UsesFogFragCoord)
--stfp->input_to_slot[inAttr];
else
++numIn;
}
if (stfp->Base.UsesPointCoord) {
if (!stfp->Base.UsesFrontFacing &&
!stfp->Base.UsesFogFragCoord)
stfp->input_to_slot[inAttr] -= 2;
else
++numIn;
}
}
}
else {
stfp->input_to_slot[inAttr] = UNUSED;

View File

@@ -112,27 +112,6 @@ map_register_file_index(
{
switch( file ) {
case TGSI_FILE_INPUT:
if (procType == TGSI_PROCESSOR_FRAGMENT &&
index == FRAG_ATTRIB_FOGC) {
if (GET_SWZ(*swizzle, 0) == SWIZZLE_X) {
/* do nothing we're, ok */
} else if (GET_SWZ(*swizzle, 0) == SWIZZLE_Y) {
/* replace the swizzle with xxxx */
*swizzle = MAKE_SWIZZLE4(SWIZZLE_X,
SWIZZLE_X,
SWIZZLE_X,
SWIZZLE_X);
/* register after fog */
return inputMapping[index] + 1;
} else {
*swizzle = MAKE_SWIZZLE4(SWIZZLE_Z,
SWIZZLE_W,
SWIZZLE_Z,
SWIZZLE_W);
/* register after frontface */
return inputMapping[index] + 2;
}
}
/* inputs are mapped according to the user-defined map */
return inputMapping[index];

View File

@@ -458,34 +458,20 @@ st_translate_fragment_program(struct st_context *st,
stfp->input_semantic_index[slot] = 1;
interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
break;
case FRAG_ATTRIB_FOGC: {
int extra_decls = 0;
if (stfp->Base.UsesFogFragCoord) {
case FRAG_ATTRIB_FOGC:
stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
stfp->input_semantic_index[slot] = 0;
interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
input_flags[slot] = stfp->Base.Base.InputFlags[attr];
++extra_decls;
}
if (stfp->Base.UsesFrontFacing) {
GLint idx = slot + extra_decls;
stfp->input_semantic_name[idx] = TGSI_SEMANTIC_FACE;
stfp->input_semantic_index[idx] = 0;
interpMode[idx] = TGSI_INTERPOLATE_CONSTANT;
input_flags[idx] = stfp->Base.Base.InputFlags[attr];
++extra_decls;
}
if (stfp->Base.UsesPointCoord) {
GLint idx = slot + extra_decls;
stfp->input_semantic_name[idx] = TGSI_SEMANTIC_GENERIC;
stfp->input_semantic_index[idx] = num_generic++;
interpMode[idx] = TGSI_INTERPOLATE_PERSPECTIVE;
input_flags[idx] = stfp->Base.Base.InputFlags[attr];
++extra_decls;
}
fs_num_inputs += extra_decls - 1;
continue;
}
break;
case FRAG_ATTRIB_FACE:
stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
stfp->input_semantic_index[slot] = num_generic++;
interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
break;
case FRAG_ATTRIB_PNTC:
stfp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
stfp->input_semantic_index[slot] = num_generic++;
interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
break;
case FRAG_ATTRIB_TEX0:
case FRAG_ATTRIB_TEX1:

View File

@@ -157,9 +157,8 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine,
/* if running a GLSL program (not ARB_fragment_program) */
if (ctx->Shader.CurrentProgram) {
/* Store front/back facing value in register FOGC.Y */
machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = 1.0 - span->facing;
/* Note FOGC.ZW is gl_PointCoord if drawing a sprite */
/* Store front/back facing value */
machine->Attribs[FRAG_ATTRIB_FACE][col][0] = 1.0 - span->facing;
}
machine->CurElement = col;

View File

@@ -139,7 +139,8 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
}
ATTRIB_LOOP_BEGIN
if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0) {
if ((attr >= FRAG_ATTRIB_TEX0 && attr <= FRAG_ATTRIB_TEX7) ||
attr >= FRAG_ATTRIB_VAR0) {
const GLuint u = attr - FRAG_ATTRIB_TEX0;
/* a texcoord */
if (ctx->Point.CoordReplace[u]) {
@@ -170,15 +171,15 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
continue;
}
}
else if (attr == FRAG_ATTRIB_FOGC) {
/* GLSL gl_PointCoord is stored in fog.zw */
span.attrStart[FRAG_ATTRIB_FOGC][2] = 0.0;
span.attrStart[FRAG_ATTRIB_FOGC][3] = 0.0; /* t0 set below */
span.attrStepX[FRAG_ATTRIB_FOGC][2] = dsdx;
span.attrStepX[FRAG_ATTRIB_FOGC][3] = 0.0;
span.attrStepY[FRAG_ATTRIB_FOGC][2] = 0.0;
span.attrStepY[FRAG_ATTRIB_FOGC][3] = dtdy;
tCoords[numTcoords++] = FRAG_ATTRIB_FOGC;
else if (attr == FRAG_ATTRIB_PNTC) {
/* GLSL gl_PointCoord.xy (.zw undefined) */
span.attrStart[FRAG_ATTRIB_PNTC][0] = 0.0;
span.attrStart[FRAG_ATTRIB_PNTC][1] = 0.0; /* t0 set below */
span.attrStepX[FRAG_ATTRIB_PNTC][0] = dsdx;
span.attrStepX[FRAG_ATTRIB_PNTC][1] = 0.0;
span.attrStepY[FRAG_ATTRIB_PNTC][0] = 0.0;
span.attrStepY[FRAG_ATTRIB_PNTC][1] = dtdy;
tCoords[numTcoords++] = FRAG_ATTRIB_PNTC;
continue;
}
/* use vertex's texcoord/attrib */
@@ -221,9 +222,6 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
GLuint i;
/* setup texcoord T for this row */
for (i = 0; i < numTcoords; i++) {
if (tCoords[i] == FRAG_ATTRIB_FOGC)
span.attrStart[FRAG_ATTRIB_FOGC][3] = tcoord;
else
span.attrStart[tCoords[i]][1] = tcoord;
}