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; break;
case FRAG_ATTRIB_FOGC: 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 */ /* Interpolate the fog coordinate */
emit_op(c, emit_op(c,
WM_PINTERP, WM_PINTERP,
@@ -393,26 +385,40 @@ static void emit_interp( struct brw_wm_compile *c,
deltas, deltas,
get_pixel_w(c)); get_pixel_w(c));
/* Move the front facing value into FOGC.y if it's needed. */ emit_op(c,
if (c->fp->program.UsesFrontFacing) { OPCODE_MOV,
emit_op(c, dst_mask(dst, WRITEMASK_YZW),
WM_FRONTFACING, 0,
dst_mask(dst, WRITEMASK_Y), src_swizzle(interp,
0, SWIZZLE_ZERO,
src_undef(), SWIZZLE_ZERO,
src_undef(), SWIZZLE_ZERO,
src_undef()); SWIZZLE_ONE),
} else { src_undef(),
emit_op(c, src_undef());
OPCODE_MOV, break;
dst_mask(dst, WRITEMASK_Y),
0, case FRAG_ATTRIB_FACE:
src_swizzle1(interp, SWIZZLE_ZERO), /* XXX review/test this case */
src_undef(), emit_op(c,
src_undef()); 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, emit_op(c,
OPCODE_MOV, OPCODE_MOV,
dst_mask(dst, WRITEMASK_ZW), dst_mask(dst, WRITEMASK_ZW),
@@ -425,6 +431,7 @@ static void emit_interp( struct brw_wm_compile *c,
src_undef(), src_undef(),
src_undef()); src_undef());
break; break;
default: default:
emit_op(c, emit_op(c,
WM_PINTERP, WM_PINTERP,

View File

@@ -227,7 +227,9 @@ typedef enum
FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX5 = 9,
FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX6 = 10,
FRAG_ATTRIB_TEX7 = 11, 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) FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
} gl_frag_attrib; } gl_frag_attrib;
@@ -239,6 +241,8 @@ typedef enum
#define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0) #define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0)
#define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1) #define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1)
#define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC) #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_TEX0 (1 << FRAG_ATTRIB_TEX0)
#define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1) #define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1)
#define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2) #define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2)
@@ -1834,9 +1838,6 @@ struct gl_fragment_program
struct gl_program Base; /**< base class */ struct gl_program Base; /**< base class */
GLenum FogOption; GLenum FogOption;
GLboolean UsesKill; /**< shader uses KIL instruction */ 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) if (program->FogOption)
program->Base.InputsRead |= FRAG_BIT_FOGC; 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) if (program->Base.Instructions)
_mesa_free(program->Base.Instructions); _mesa_free(program->Base.Instructions);
program->Base.Instructions = ap.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.Instructions = newInst;
fprog->Base.NumInstructions = inst - newInst; fprog->Base.NumInstructions = inst - newInst;
fprog->Base.InputsRead |= FRAG_BIT_FOGC; fprog->Base.InputsRead |= FRAG_BIT_FOGC;
fprog->UsesFogFragCoord = GL_TRUE;
/* XXX do this? fprog->FogOption = GL_NONE; */ /* 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 }, { "gl_TexCoord", FRAG_ATTRIB_TEX0, SWIZZLE_NOOP },
/* note: we're packing several quantities into the fogcoord vector */ /* note: we're packing several quantities into the fogcoord vector */
{ "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX }, { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX },
{ "gl_FrontFacing", FRAG_ATTRIB_FOGC, SWIZZLE_YYYY }, /*XXX*/ { "gl_PointCoord", FRAG_ATTRIB_PNTC, SWIZZLE_XYZW },
{ "gl_PointCoord", FRAG_ATTRIB_FOGC, SWIZZLE_ZWWW }, { "gl_FrontFacing", FRAG_ATTRIB_FACE, SWIZZLE_XXXX },
{ NULL, 0, SWIZZLE_NOOP } { NULL, 0, SWIZZLE_NOOP }
}; };
GLuint i; GLuint i;

View File

@@ -484,20 +484,6 @@ _slang_update_inputs_outputs(struct gl_program *prog)
for (j = 0; j < numSrc; j++) { for (j = 0; j < numSrc; j++) {
if (inst->SrcReg[j].File == PROGRAM_INPUT) { if (inst->SrcReg[j].File == PROGRAM_INPUT) {
prog->InputsRead |= 1 << inst->SrcReg[j].Index; 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) { else if (inst->SrcReg[j].File == PROGRAM_ADDRESS) {
maxAddrReg = MAX2(maxAddrReg, (GLuint) (inst->SrcReg[j].Index + 1)); 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)) { if (fragInputsRead & (1 << inAttr)) {
stfp->input_to_slot[inAttr] = numIn; stfp->input_to_slot[inAttr] = numIn;
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 { else {
stfp->input_to_slot[inAttr] = UNUSED; stfp->input_to_slot[inAttr] = UNUSED;

View File

@@ -112,27 +112,6 @@ map_register_file_index(
{ {
switch( file ) { switch( file ) {
case TGSI_FILE_INPUT: 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 */ /* inputs are mapped according to the user-defined map */
return inputMapping[index]; return inputMapping[index];

View File

@@ -458,34 +458,20 @@ st_translate_fragment_program(struct st_context *st,
stfp->input_semantic_index[slot] = 1; stfp->input_semantic_index[slot] = 1;
interpMode[slot] = TGSI_INTERPOLATE_LINEAR; interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
break; break;
case FRAG_ATTRIB_FOGC: { case FRAG_ATTRIB_FOGC:
int extra_decls = 0; stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
if (stfp->Base.UsesFogFragCoord) { stfp->input_semantic_index[slot] = 0;
stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG; interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
stfp->input_semantic_index[slot] = 0; break;
interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE; case FRAG_ATTRIB_FACE:
input_flags[slot] = stfp->Base.Base.InputFlags[attr]; stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
++extra_decls; stfp->input_semantic_index[slot] = num_generic++;
} interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
if (stfp->Base.UsesFrontFacing) { break;
GLint idx = slot + extra_decls; case FRAG_ATTRIB_PNTC:
stfp->input_semantic_name[idx] = TGSI_SEMANTIC_FACE; stfp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
stfp->input_semantic_index[idx] = 0; stfp->input_semantic_index[slot] = num_generic++;
interpMode[idx] = TGSI_INTERPOLATE_CONSTANT; interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
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; break;
case FRAG_ATTRIB_TEX0: case FRAG_ATTRIB_TEX0:
case FRAG_ATTRIB_TEX1: 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 running a GLSL program (not ARB_fragment_program) */
if (ctx->Shader.CurrentProgram) { if (ctx->Shader.CurrentProgram) {
/* Store front/back facing value in register FOGC.Y */ /* Store front/back facing value */
machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = 1.0 - span->facing; machine->Attribs[FRAG_ATTRIB_FACE][col][0] = 1.0 - span->facing;
/* Note FOGC.ZW is gl_PointCoord if drawing a sprite */
} }
machine->CurElement = col; machine->CurElement = col;

View File

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