summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-07-29 20:07:41 -0600
committerBrian Paul <brianp@vmware.com>2009-07-29 20:07:41 -0600
commit9d0b8d72d8d704ff4d8e10448b60cbb42f07eecb (patch)
tree86b13d3647665a05cd3b3237abee8565e25da5b5
parent0723cd1b0a8a76808844a2216d709f56fbad88e2 (diff)
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...
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm_fp.c61
-rw-r--r--src/mesa/main/mtypes.h9
-rw-r--r--src/mesa/shader/arbprogparse.c7
-rw-r--r--src/mesa/shader/programopt.c1
-rw-r--r--src/mesa/shader/slang/slang_codegen.c4
-rw-r--r--src/mesa/shader/slang/slang_link.c14
-rw-r--r--src/mesa/state_tracker/st_atom_shader.c17
-rw-r--r--src/mesa/state_tracker/st_mesa_to_tgsi.c21
-rw-r--r--src/mesa/state_tracker/st_program.c42
-rw-r--r--src/mesa/swrast/s_fragprog.c5
-rw-r--r--src/mesa/swrast/s_points.c26
11 files changed, 69 insertions, 138 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_wm_fp.c b/src/mesa/drivers/dri/i965/brw_wm_fp.c
index b9e8dd2e96e..606baab9675 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_fp.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_fp.c
@@ -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),
- 0,
- src_swizzle1(interp, SWIZZLE_ZERO),
- src_undef(),
- src_undef());
- }
+ emit_op(c,
+ OPCODE_MOV,
+ dst_mask(dst, WRITEMASK_YZW),
+ 0,
+ 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,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d0309f5e90d..da01c58c2d8 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -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 */
};
diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c
index bc65aba39a1..f428ee541b5 100644
--- a/src/mesa/shader/arbprogparse.c
+++ b/src/mesa/shader/arbprogparse.c
@@ -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;
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index ac5fe0f691f..f70c75cec8e 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -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; */
}
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 2b7e781f984..4fe68eafa7f 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -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;
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index f6032d1e9ad..6c19fc895b3 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -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));
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 8b3bb5cc033..ee649be885e 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index 6380cd6b2a8..210ca82c42e 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -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];
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 806e0ca8f65..d2da20ae424 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -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) {
- 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;
- }
+ case FRAG_ATTRIB_FOGC:
+ stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+ stfp->input_semantic_index[slot] = 0;
+ interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ 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:
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index b71fb9eae97..613a91b0ecd 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -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;
diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c
index 0a3ad97a71b..64c9cda5165 100644
--- a/src/mesa/swrast/s_points.c
+++ b/src/mesa/swrast/s_points.c
@@ -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,10 +222,7 @@ 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;
+ span.attrStart[tCoords[i]][1] = tcoord;
}
/* these might get changed by span clipping */