mesa: Branch 'glsl-compiler-1' - 3 commits
Brian Paul
brianp at kemper.freedesktop.org
Sat Mar 10 10:32:09 PST 2007
src/mesa/shader/slang/slang_codegen.c | 60 ++++++++++++++++++++--------------
src/mesa/shader/slang/slang_emit.c | 8 +++-
src/mesa/swrast/s_context.c | 21 ++++++-----
src/mesa/swrast/s_fragprog.c | 4 ++
src/mesa/swrast_setup/ss_triangle.c | 4 +-
src/mesa/swrast_setup/ss_tritmp.h | 3 -
6 files changed, 61 insertions(+), 39 deletions(-)
New commits:
diff-tree 10b5895597d5e069183cb647d17eb412effceb4f (from 1fcb4ecc07685872c9c42569ba13faa1cad54d3c)
Author: Brian <brian at yutani.localnet.net>
Date: Sat Mar 10 11:30:19 2007 -0700
Implement gl_FrontFacing for fragment shaders.
For the time being, we put the gl_FrontFacing value in the FOGC.Y input
register. Combining FOGC and FrontFacing in one register is a bit of a
hack and may need to be changed someday.
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 64bb914..640b87a 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -209,35 +209,37 @@ sampler_to_texture_index(const slang_typ
* XXX return size too
*/
static GLint
-_slang_input_index(const char *name, GLenum target)
+_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut)
{
struct input_info {
const char *Name;
GLuint Attrib;
+ GLuint Swizzle;
};
static const struct input_info vertInputs[] = {
- { "gl_Vertex", VERT_ATTRIB_POS },
- { "gl_Normal", VERT_ATTRIB_NORMAL },
- { "gl_Color", VERT_ATTRIB_COLOR0 },
- { "gl_SecondaryColor", VERT_ATTRIB_COLOR1 },
- { "gl_FogCoord", VERT_ATTRIB_FOG },
- { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0 },
- { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1 },
- { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2 },
- { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3 },
- { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4 },
- { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5 },
- { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6 },
- { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7 },
- { NULL, 0 }
+ { "gl_Vertex", VERT_ATTRIB_POS, SWIZZLE_NOOP },
+ { "gl_Normal", VERT_ATTRIB_NORMAL, SWIZZLE_NOOP },
+ { "gl_Color", VERT_ATTRIB_COLOR0, SWIZZLE_NOOP },
+ { "gl_SecondaryColor", VERT_ATTRIB_COLOR1, SWIZZLE_NOOP },
+ { "gl_FogCoord", VERT_ATTRIB_FOG, SWIZZLE_XXXX },
+ { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0, SWIZZLE_NOOP },
+ { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1, SWIZZLE_NOOP },
+ { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2, SWIZZLE_NOOP },
+ { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3, SWIZZLE_NOOP },
+ { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4, SWIZZLE_NOOP },
+ { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5, SWIZZLE_NOOP },
+ { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6, SWIZZLE_NOOP },
+ { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7, SWIZZLE_NOOP },
+ { NULL, 0, SWIZZLE_NOOP }
};
static const struct input_info fragInputs[] = {
- { "gl_FragCoord", FRAG_ATTRIB_WPOS },
- { "gl_Color", FRAG_ATTRIB_COL0 },
- { "gl_SecondaryColor", FRAG_ATTRIB_COL1 },
- { "gl_FogFragCoord", FRAG_ATTRIB_FOGC },
- { "gl_TexCoord", FRAG_ATTRIB_TEX0 },
- { NULL, 0 }
+ { "gl_FragCoord", FRAG_ATTRIB_WPOS, SWIZZLE_NOOP },
+ { "gl_Color", FRAG_ATTRIB_COL0, SWIZZLE_NOOP },
+ { "gl_SecondaryColor", FRAG_ATTRIB_COL1, SWIZZLE_NOOP },
+ { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX },
+ { "gl_TexCoord", FRAG_ATTRIB_TEX0, SWIZZLE_NOOP },
+ { "gl_FrontFacing", FRAG_ATTRIB_FOGC, SWIZZLE_YYYY }, /*XXX*/
+ { NULL, 0, SWIZZLE_NOOP }
};
GLuint i;
const struct input_info *inputs
@@ -248,6 +250,7 @@ _slang_input_index(const char *name, GLe
for (i = 0; inputs[i].Name; i++) {
if (strcmp(inputs[i].Name, name) == 0) {
/* found */
+ *swizzleOut = inputs[i].Swizzle;
return inputs[i].Attrib;
}
}
@@ -2571,9 +2574,12 @@ _slang_codegen_global_variable(slang_ass
else {
/* pre-defined varying, like gl_Color or gl_TexCoord */
if (type == SLANG_UNIT_FRAGMENT_BUILTIN) {
- GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB);
+ GLuint swizzle;
+ GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB,
+ &swizzle);
assert(index >= 0);
store = _slang_new_ir_storage(PROGRAM_INPUT, index, size);
+ store->Swizzle = swizzle;
assert(index < FRAG_ATTRIB_MAX);
}
else {
@@ -2600,17 +2606,23 @@ _slang_codegen_global_variable(slang_ass
}
else {
/* pre-defined vertex attrib */
- GLint index = _slang_input_index(varName, GL_VERTEX_PROGRAM_ARB);
+ GLuint swizzle;
+ GLint index = _slang_input_index(varName, GL_VERTEX_PROGRAM_ARB,
+ &swizzle);
GLint size = 4; /* XXX? */
assert(index >= 0);
store = _slang_new_ir_storage(PROGRAM_INPUT, index, size);
+ store->Swizzle = swizzle;
}
if (dbg) printf("ATTRIB ");
}
else if (var->type.qualifier == SLANG_QUAL_FIXEDINPUT) {
- GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB);
+ GLuint swizzle;
+ GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB,
+ &swizzle);
GLint size = 4; /* XXX? */
store = _slang_new_ir_storage(PROGRAM_INPUT, index, size);
+ store->Swizzle = swizzle;
if (dbg) printf("INPUT ");
}
else if (var->type.qualifier == SLANG_QUAL_FIXEDOUTPUT) {
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index 698925c..dbfc1b8 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -113,6 +113,10 @@ init_machine(GLcontext *ctx, struct gl_p
/* Setup pointer to input attributes */
machine->Attribs = span->array->attribs;
+
+ /* Store front/back facing value in register FOGC.Y */
+ machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = (GLfloat) ctx->_Facing;
+
machine->CurElement = col;
/* init condition codes */
diff --git a/src/mesa/swrast_setup/ss_triangle.c b/src/mesa/swrast_setup/ss_triangle.c
index 09244d9..628e928 100644
--- a/src/mesa/swrast_setup/ss_triangle.c
+++ b/src/mesa/swrast_setup/ss_triangle.c
@@ -290,8 +290,10 @@ void _swsetup_choose_trifuncs( GLcontext
ctx->Polygon.OffsetFill)
ind |= SS_OFFSET_BIT;
+ /* Note: gl_FrontFacing lives in fragment input FOGC.Y at this time */
if ((ctx->Light.Enabled && ctx->Light.Model.TwoSide) ||
- (ctx->VertexProgram._Enabled && ctx->VertexProgram.TwoSideEnabled))
+ (ctx->VertexProgram._Enabled && ctx->VertexProgram.TwoSideEnabled) ||
+ (ctx->FragmentProgram._Current && ctx->FragmentProgram._Current->Base.InputsRead & (1 << FRAG_ATTRIB_FOGC)))
ind |= SS_TWOSIDE_BIT;
/* We piggyback the two-sided stencil front/back determination on the
diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h
index 61c9b28..5b14b28 100644
--- a/src/mesa/swrast_setup/ss_tritmp.h
+++ b/src/mesa/swrast_setup/ss_tritmp.h
@@ -55,8 +55,7 @@ static void TAG(triangle)(GLcontext *ctx
if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT))
{
facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
- if (ctx->Stencil.TestTwoSide)
- ctx->_Facing = facing; /* for 2-sided stencil test */
+ ctx->_Facing = facing;
if (IND & SS_UNFILLED_BIT)
mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
diff-tree 1fcb4ecc07685872c9c42569ba13faa1cad54d3c (from c9872b80c874ce7891c6b07c2d4f2fe099fdd8cd)
Author: Brian <brian at yutani.localnet.net>
Date: Sat Mar 10 10:56:06 2007 -0700
clean-up formatting
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 031d74f..8864c21 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -125,27 +125,28 @@ _swrast_update_rasterflags( GLcontext *c
static void
_swrast_update_polygon( GLcontext *ctx )
{
- GLfloat backface_sign = 1;
+ GLfloat backface_sign;
if (ctx->Polygon.CullFlag) {
- backface_sign = 1;
- switch(ctx->Polygon.CullFaceMode) {
+ backface_sign = 1.0;
+ switch (ctx->Polygon.CullFaceMode) {
case GL_BACK:
- if(ctx->Polygon.FrontFace==GL_CCW)
- backface_sign = -1;
+ if (ctx->Polygon.FrontFace == GL_CCW)
+ backface_sign = -1.0;
break;
case GL_FRONT:
- if(ctx->Polygon.FrontFace!=GL_CCW)
- backface_sign = -1;
+ if (ctx->Polygon.FrontFace != GL_CCW)
+ backface_sign = -1.0;
break;
- default:
case GL_FRONT_AND_BACK:
- backface_sign = 0;
+ /* fallthrough */
+ default:
+ backface_sign = 0.0;
break;
}
}
else {
- backface_sign = 0;
+ backface_sign = 0.0;
}
SWRAST_CONTEXT(ctx)->_BackfaceSign = backface_sign;
diff-tree c9872b80c874ce7891c6b07c2d4f2fe099fdd8cd (from 46bd63819e0fb108d13df0672372e500cf56bbbe)
Author: Brian <brian at yutani.localnet.net>
Date: Sat Mar 10 10:37:18 2007 -0700
add NULL ptr check in emit_cond()
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 8ad61d8..6d39354 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1014,8 +1014,12 @@ emit_cond(slang_emit_info *emitInfo, sla
* Need to update condition code register.
* Next instruction is typically an IR_IF.
*/
- /* last child expr instruction: */
- struct prog_instruction *inst = emit(emitInfo, n->Children[0]);
+ struct prog_instruction *inst;
+
+ if (!n->Children[0])
+ return NULL;
+
+ inst = emit(emitInfo, n->Children[0]);
if (inst) {
/* set inst's CondUpdate flag */
inst->CondUpdate = GL_TRUE;
More information about the mesa-commit
mailing list