diff options
author | Brian Paul <brianp@vmware.com> | 2009-04-14 22:14:30 -0600 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2009-04-14 22:14:30 -0600 |
commit | 7db7ff878d3e5a6b345228e6eaee4797bb68b360 (patch) | |
tree | 9dbdcfc3d9bc37d88f7e86f22f7c8f18b9420b14 /src/mesa/shader | |
parent | 0115a4f8f1952b166eaad09f317ff8bc465e0f28 (diff) |
mesa: merge the prog_src_register::NegateBase and NegateAbs fields
There's really no need for two negation fields. This came from the
GL_NV_fragment_program extension. The new, unified Negate bitfield applies
after the absolute value step.
Diffstat (limited to 'src/mesa/shader')
-rw-r--r-- | src/mesa/shader/arbprogparse.c | 8 | ||||
-rw-r--r-- | src/mesa/shader/nvfragparse.c | 33 | ||||
-rw-r--r-- | src/mesa/shader/nvvertparse.c | 10 | ||||
-rw-r--r-- | src/mesa/shader/prog_execute.c | 27 | ||||
-rw-r--r-- | src/mesa/shader/prog_instruction.h | 32 | ||||
-rw-r--r-- | src/mesa/shader/prog_print.c | 20 | ||||
-rw-r--r-- | src/mesa/shader/programopt.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_emit.c | 2 |
8 files changed, 52 insertions, 82 deletions
diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 35253daa2e..b47bf360cf 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -2669,7 +2669,7 @@ parse_vector_src_reg(GLcontext *ctx, const GLubyte **inst, reg->File = file; reg->Index = index; reg->Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], swizzle[3]); - reg->NegateBase = negateMask; + reg->Negate = negateMask; reg->RelAddr = isRelOffset; return 0; } @@ -2703,7 +2703,7 @@ parse_scalar_src_reg(GLcontext *ctx, const GLubyte **inst, reg->File = file; reg->Index = index; reg->Swizzle = (swizzle[0] << 0); - reg->NegateBase = negateMask; + reg->Negate = negateMask; reg->RelAddr = isRelOffset; return 0; } @@ -3019,7 +3019,7 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, parse_extended_swizzle_mask(inst, swizzle, &negateMask); fp->SrcReg[0].File = file; fp->SrcReg[0].Index = index; - fp->SrcReg[0].NegateBase = negateMask; + fp->SrcReg[0].Negate = negateMask; fp->SrcReg[0].Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], @@ -3363,7 +3363,7 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, parse_extended_swizzle_mask (inst, swizzle, &negateMask); vp->SrcReg[0].File = file; vp->SrcReg[0].Index = index; - vp->SrcReg[0].NegateBase = negateMask; + vp->SrcReg[0].Negate = negateMask; vp->SrcReg[0].Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c index 56b7c29bea..0fd55524ab 100644 --- a/src/mesa/shader/nvfragparse.c +++ b/src/mesa/shader/nvfragparse.c @@ -957,6 +957,7 @@ Parse_VectorSrc(struct parse_state *parseState, GLfloat sign = 1.0F; GLubyte token[100]; GLint idx; + GLuint negateBase, negateAbs; /* * First, take care of +/- and absolute value stuff. @@ -968,21 +969,23 @@ Parse_VectorSrc(struct parse_state *parseState, if (Parse_String(parseState, "|")) { srcReg->Abs = GL_TRUE; - srcReg->NegateAbs = (sign < 0.0F) ? GL_TRUE : GL_FALSE; + negateAbs = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; if (Parse_String(parseState, "-")) - srcReg->NegateBase = NEGATE_XYZW; + negateBase = NEGATE_XYZW; else if (Parse_String(parseState, "+")) - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; else - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; } else { srcReg->Abs = GL_FALSE; - srcReg->NegateAbs = GL_FALSE; - srcReg->NegateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; + negateAbs = NEGATE_NONE; + negateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; } + srcReg->Negate = srcReg->Abs ? negateAbs : negateBase; + /* This should be the real src vector/register name */ if (!Peek_Token(parseState, token)) RETURN_ERROR; @@ -1083,6 +1086,7 @@ Parse_ScalarSrcReg(struct parse_state *parseState, GLfloat sign = 1.0F; GLboolean needSuffix = GL_TRUE; GLint idx; + GLuint negateBase, negateAbs; /* * First, take care of +/- and absolute value stuff. @@ -1094,21 +1098,23 @@ Parse_ScalarSrcReg(struct parse_state *parseState, if (Parse_String(parseState, "|")) { srcReg->Abs = GL_TRUE; - srcReg->NegateAbs = (sign < 0.0F) ? GL_TRUE : GL_FALSE; + negateAbs = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; if (Parse_String(parseState, "-")) - srcReg->NegateBase = NEGATE_XYZW; + negateBase = NEGATE_XYZW; else if (Parse_String(parseState, "+")) - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; else - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; } else { srcReg->Abs = GL_FALSE; - srcReg->NegateAbs = GL_FALSE; - srcReg->NegateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; + negateAbs = NEGATE_NONE; + negateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; } + srcReg->Negate = srcReg->Abs ? negateAbs : negateBase; + if (!Peek_Token(parseState, token)) RETURN_ERROR; @@ -1247,9 +1253,8 @@ Parse_PrintInstruction(struct parse_state *parseState, } inst->SrcReg[0].Swizzle = SWIZZLE_NOOP; - inst->SrcReg[0].NegateBase = NEGATE_NONE; inst->SrcReg[0].Abs = GL_FALSE; - inst->SrcReg[0].NegateAbs = GL_FALSE; + inst->SrcReg[0].Negate = NEGATE_NONE; return GL_TRUE; } diff --git a/src/mesa/shader/nvvertparse.c b/src/mesa/shader/nvvertparse.c index 624262395b..f5e2df2670 100644 --- a/src/mesa/shader/nvvertparse.c +++ b/src/mesa/shader/nvvertparse.c @@ -641,12 +641,12 @@ Parse_SwizzleSrcReg(struct parse_state *parseState, struct prog_src_register *sr RETURN_ERROR; if (token[0] == '-') { (void) Parse_String(parseState, "-"); - srcReg->NegateBase = NEGATE_XYZW; + srcReg->Negate = NEGATE_XYZW; if (!Peek_Token(parseState, token)) RETURN_ERROR; } else { - srcReg->NegateBase = NEGATE_NONE; + srcReg->Negate = NEGATE_NONE; } /* Src reg can be R<n>, c[n], c[n +/- offset], or a named vertex attrib */ @@ -734,13 +734,13 @@ Parse_ScalarSrcReg(struct parse_state *parseState, struct prog_src_register *src if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '-') { - srcReg->NegateBase = NEGATE_XYZW; + srcReg->Negate = NEGATE_XYZW; (void) Parse_String(parseState, "-"); /* consume '-' */ if (!Peek_Token(parseState, token)) RETURN_ERROR; } else { - srcReg->NegateBase = NEGATE_NONE; + srcReg->Negate = NEGATE_NONE; } /* Src reg can be R<n>, c[n], c[n +/- offset], or a named vertex attrib */ @@ -1062,7 +1062,7 @@ Parse_PrintInstruction(struct parse_state *parseState, struct prog_instruction * RETURN_ERROR; srcReg->RelAddr = GL_FALSE; - srcReg->NegateBase = NEGATE_NONE; + srcReg->Negate = NEGATE_NONE; srcReg->Swizzle = SWIZZLE_NOOP; /* Register can be R<n>, c[n], c[n +/- offset], a named vertex attrib, diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c index bdac1d4f8a..68a59350a1 100644 --- a/src/mesa/shader/prog_execute.c +++ b/src/mesa/shader/prog_execute.c @@ -212,19 +212,14 @@ fetch_vector4(const struct prog_src_register *source, result[3] = src[GET_SWZ(source->Swizzle, 3)]; } - if (source->NegateBase) { - result[0] = -result[0]; - result[1] = -result[1]; - result[2] = -result[2]; - result[3] = -result[3]; - } if (source->Abs) { result[0] = FABSF(result[0]); result[1] = FABSF(result[1]); result[2] = FABSF(result[2]); result[3] = FABSF(result[3]); } - if (source->NegateAbs) { + if (source->Negate) { + ASSERT(source->Negate == NEGATE_XYZW); result[0] = -result[0]; result[1] = -result[1]; result[2] = -result[2]; @@ -259,7 +254,7 @@ fetch_vector4ui(const struct prog_src_register *source, result[3] = src[GET_SWZ(source->Swizzle, 3)]; } - /* Note: no NegateBase, Abs, NegateAbs here */ + /* Note: no Negate or Abs here */ } @@ -299,19 +294,14 @@ fetch_vector4_deriv(GLcontext * ctx, result[2] = deriv[GET_SWZ(source->Swizzle, 2)]; result[3] = deriv[GET_SWZ(source->Swizzle, 3)]; - if (source->NegateBase) { - result[0] = -result[0]; - result[1] = -result[1]; - result[2] = -result[2]; - result[3] = -result[3]; - } if (source->Abs) { result[0] = FABSF(result[0]); result[1] = FABSF(result[1]); result[2] = FABSF(result[2]); result[3] = FABSF(result[3]); } - if (source->NegateAbs) { + if (source->Negate) { + ASSERT(source->Negate == NEGATE_XYZW); result[0] = -result[0]; result[1] = -result[1]; result[2] = -result[2]; @@ -336,13 +326,10 @@ fetch_vector1(const struct prog_src_register *source, result[0] = src[GET_SWZ(source->Swizzle, 0)]; - if (source->NegateBase) { - result[0] = -result[0]; - } if (source->Abs) { result[0] = FABSF(result[0]); } - if (source->NegateAbs) { + if (source->Negate) { result[0] = -result[0]; } } @@ -1514,7 +1501,7 @@ _mesa_execute_program(GLcontext * ctx, ASSERT(swz <= 3); result[i] = src[swz]; } - if (source->NegateBase & (1 << i)) + if (source->Negate & (1 << i)) result[i] = -result[i]; } store_vector4(inst, machine, result); diff --git a/src/mesa/shader/prog_instruction.h b/src/mesa/shader/prog_instruction.h index 4adce11f95..3109f6cbae 100644 --- a/src/mesa/shader/prog_instruction.h +++ b/src/mesa/shader/prog_instruction.h @@ -261,37 +261,15 @@ struct prog_src_register GLuint Swizzle:12; GLuint RelAddr:1; - /** - * \name Source register "sign" control. - * - * The ARB and NV extensions allow varrying degrees of control over the - * sign of the source vector components. These values allow enough control - * for all flavors of the extensions. - */ - /*@{*/ - /** - * Per-component negation for the SWZ instruction. For non-SWZ - * instructions the only possible values are NEGATE_XYZW and NEGATE_NONE. - * - * \since - * ARB_vertex_program, ARB_fragment_program - */ - GLuint NegateBase:4; - - /** - * Take the component-wise absolute value. - * - * \since - * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2, - * NV_vertex_program2_option. - */ + /** Take the component-wise absolute value */ GLuint Abs:1; /** - * Post-absolute value negation (all components). + * Post-Abs negation. + * This will either be NEGATE_NONE or NEGATE_XYZW, except for the SWZ + * instruction which allows per-component negation. */ - GLuint NegateAbs:1; - /*@}*/ + GLuint Negate:4; }; diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c index b832ddb477..d73c619fea 100644 --- a/src/mesa/shader/prog_print.c +++ b/src/mesa/shader/prog_print.c @@ -325,19 +325,19 @@ reg_string(gl_register_file f, GLint index, gl_prog_print_mode mode, * \param extended if true, also allow 0, 1 values */ const char * -_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended) +_mesa_swizzle_string(GLuint swizzle, GLuint negateMask, GLboolean extended) { static const char swz[] = "xyzw01!?"; /* See SWIZZLE_x definitions */ static char s[20]; GLuint i = 0; - if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0) + if (!extended && swizzle == SWIZZLE_NOOP && negateMask == 0) return ""; /* no swizzle/negation */ if (!extended) s[i++] = '.'; - if (negateBase & NEGATE_X) + if (negateMask & NEGATE_X) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 0)]; @@ -345,7 +345,7 @@ _mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended) s[i++] = ','; } - if (negateBase & NEGATE_Y) + if (negateMask & NEGATE_Y) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 1)]; @@ -353,7 +353,7 @@ _mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended) s[i++] = ','; } - if (negateBase & NEGATE_Z) + if (negateMask & NEGATE_Z) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 2)]; @@ -361,7 +361,7 @@ _mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended) s[i++] = ','; } - if (negateBase & NEGATE_W) + if (negateMask & NEGATE_W) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 3)]; @@ -465,14 +465,14 @@ fprint_src_reg(FILE *f, reg_string((gl_register_file) srcReg->File, srcReg->Index, mode, srcReg->RelAddr, prog), _mesa_swizzle_string(srcReg->Swizzle, - srcReg->NegateBase, GL_FALSE), + srcReg->Negate, GL_FALSE), abs); #if 0 _mesa_fprintf(f, "%s[%d]%s", file_string((gl_register_file) srcReg->File, mode), srcReg->Index, _mesa_swizzle_string(srcReg->Swizzle, - srcReg->NegateBase, GL_FALSE)); + srcReg->Negate, GL_FALSE)); #endif } @@ -566,7 +566,7 @@ _mesa_fprint_instruction_opt(FILE *f, mode), inst->SrcReg[0].Index, _mesa_swizzle_string(inst->SrcReg[0].Swizzle, - inst->SrcReg[0].NegateBase, GL_FALSE)); + inst->SrcReg[0].Negate, GL_FALSE)); } if (inst->Comment) _mesa_fprintf(f, " # %s", inst->Comment); @@ -583,7 +583,7 @@ _mesa_fprint_instruction_opt(FILE *f, mode), inst->SrcReg[0].Index, _mesa_swizzle_string(inst->SrcReg[0].Swizzle, - inst->SrcReg[0].NegateBase, GL_TRUE)); + inst->SrcReg[0].Negate, GL_TRUE)); fprint_comment(f, inst); break; case OPCODE_TEX: diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c index e283f8933b..ecd98dc85c 100644 --- a/src/mesa/shader/programopt.c +++ b/src/mesa/shader/programopt.c @@ -241,7 +241,7 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) inst->DstReg.WriteMask = WRITEMASK_X; inst->SrcReg[0].File = PROGRAM_TEMPORARY; inst->SrcReg[0].Index = fogFactorTemp; - inst->SrcReg[0].NegateBase = NEGATE_XYZW; + inst->SrcReg[0].Negate = NEGATE_XYZW; inst->SrcReg[0].Swizzle = SWIZZLE_XXXX; inst->SaturateMode = SATURATE_ZERO_ONE; inst++; diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 8493c490fb..3f455e0640 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -1135,7 +1135,7 @@ emit_negation(slang_emit_info *emitInfo, slang_ir_node *n) n->Children[0]->Store, NULL, NULL); - inst->SrcReg[0].NegateBase = NEGATE_XYZW; + inst->SrcReg[0].Negate = NEGATE_XYZW; return inst; } |