summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/nvvertparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/shader/nvvertparse.c')
-rw-r--r--src/mesa/shader/nvvertparse.c121
1 files changed, 58 insertions, 63 deletions
diff --git a/src/mesa/shader/nvvertparse.c b/src/mesa/shader/nvvertparse.c
index b02143a2e66..23a01c7617f 100644
--- a/src/mesa/shader/nvvertparse.c
+++ b/src/mesa/shader/nvvertparse.c
@@ -563,6 +563,7 @@ static GLboolean
Parse_MaskedDstReg(struct parse_state *parseState, struct vp_dst_register *dstReg)
{
GLubyte token[100];
+ GLint idx;
/* Dst reg can be R<n> or o[n] */
if (!Peek_Token(parseState, token))
@@ -571,22 +572,25 @@ Parse_MaskedDstReg(struct parse_state *parseState, struct vp_dst_register *dstRe
if (token[0] == 'R') {
/* a temporary register */
dstReg->File = PROGRAM_TEMPORARY;
- if (!Parse_TempReg(parseState, &dstReg->Index))
+ if (!Parse_TempReg(parseState, &idx))
RETURN_ERROR;
+ dstReg->Index = idx;
}
else if (!parseState->isStateProgram && token[0] == 'o') {
/* an output register */
dstReg->File = PROGRAM_OUTPUT;
- if (!Parse_OutputReg(parseState, &dstReg->Index))
+ if (!Parse_OutputReg(parseState, &idx))
RETURN_ERROR;
+ dstReg->Index = idx;
}
else if (parseState->isStateProgram && token[0] == 'c' &&
parseState->isStateProgram) {
/* absolute program parameter register */
/* Only valid for vertex state programs */
dstReg->File = PROGRAM_ENV_PARAM;
- if (!Parse_AbsParamReg(parseState, &dstReg->Index))
+ if (!Parse_AbsParamReg(parseState, &idx))
RETURN_ERROR;
+ dstReg->Index = idx;
}
else {
RETURN_ERROR1("Bad destination register name");
@@ -606,25 +610,22 @@ Parse_MaskedDstReg(struct parse_state *parseState, struct vp_dst_register *dstRe
if (!Parse_Token(parseState, token))
RETURN_ERROR;
- dstReg->WriteMask[0] = GL_FALSE;
- dstReg->WriteMask[1] = GL_FALSE;
- dstReg->WriteMask[2] = GL_FALSE;
- dstReg->WriteMask[3] = GL_FALSE;
+ dstReg->WriteMask = 0;
if (token[k] == 'x') {
- dstReg->WriteMask[0] = GL_TRUE;
+ dstReg->WriteMask |= WRITEMASK_X;
k++;
}
if (token[k] == 'y') {
- dstReg->WriteMask[1] = GL_TRUE;
+ dstReg->WriteMask |= WRITEMASK_Y;
k++;
}
if (token[k] == 'z') {
- dstReg->WriteMask[2] = GL_TRUE;
+ dstReg->WriteMask |= WRITEMASK_Z;
k++;
}
if (token[k] == 'w') {
- dstReg->WriteMask[3] = GL_TRUE;
+ dstReg->WriteMask |= WRITEMASK_W;
k++;
}
if (k == 0) {
@@ -633,10 +634,7 @@ Parse_MaskedDstReg(struct parse_state *parseState, struct vp_dst_register *dstRe
return GL_TRUE;
}
else {
- dstReg->WriteMask[0] = GL_TRUE;
- dstReg->WriteMask[1] = GL_TRUE;
- dstReg->WriteMask[2] = GL_TRUE;
- dstReg->WriteMask[3] = GL_TRUE;
+ dstReg->WriteMask = WRITEMASK_XYZW;
return GL_TRUE;
}
}
@@ -646,6 +644,7 @@ static GLboolean
Parse_SwizzleSrcReg(struct parse_state *parseState, struct vp_src_register *srcReg)
{
GLubyte token[100];
+ GLint idx;
srcReg->RelAddr = GL_FALSE;
@@ -665,8 +664,9 @@ Parse_SwizzleSrcReg(struct parse_state *parseState, struct vp_src_register *srcR
/* Src reg can be R<n>, c[n], c[n +/- offset], or a named vertex attrib */
if (token[0] == 'R') {
srcReg->File = PROGRAM_TEMPORARY;
- if (!Parse_TempReg(parseState, &srcReg->Index))
+ if (!Parse_TempReg(parseState, &idx))
RETURN_ERROR;
+ srcReg->Index = idx;
}
else if (token[0] == 'c') {
if (!Parse_ParamReg(parseState, srcReg))
@@ -674,18 +674,16 @@ Parse_SwizzleSrcReg(struct parse_state *parseState, struct vp_src_register *srcR
}
else if (token[0] == 'v') {
srcReg->File = PROGRAM_INPUT;
- if (!Parse_AttribReg(parseState, &srcReg->Index))
+ if (!Parse_AttribReg(parseState, &idx))
RETURN_ERROR;
+ srcReg->Index = idx;
}
else {
RETURN_ERROR2("Bad source register name", token);
}
/* init swizzle fields */
- srcReg->Swizzle[0] = 0;
- srcReg->Swizzle[1] = 1;
- srcReg->Swizzle[2] = 2;
- srcReg->Swizzle[3] = 3;
+ srcReg->Swizzle = SWIZZLE_NOOP;
/* Look for optional swizzle suffix */
if (!Peek_Token(parseState, token))
@@ -699,13 +697,13 @@ Parse_SwizzleSrcReg(struct parse_state *parseState, struct vp_src_register *srcR
if (token[1] == 0) {
/* single letter swizzle */
if (token[0] == 'x')
- ASSIGN_4V(srcReg->Swizzle, 0, 0, 0, 0);
+ srcReg->Swizzle = MAKE_SWIZZLE4(0, 0, 0, 0);
else if (token[0] == 'y')
- ASSIGN_4V(srcReg->Swizzle, 1, 1, 1, 1);
+ srcReg->Swizzle = MAKE_SWIZZLE4(1, 1, 1, 1);
else if (token[0] == 'z')
- ASSIGN_4V(srcReg->Swizzle, 2, 2, 2, 2);
+ srcReg->Swizzle = MAKE_SWIZZLE4(2, 2, 2, 2);
else if (token[0] == 'w')
- ASSIGN_4V(srcReg->Swizzle, 3, 3, 3, 3);
+ srcReg->Swizzle = MAKE_SWIZZLE4(3, 3, 3, 3);
else
RETURN_ERROR1("Expected x, y, z, or w");
}
@@ -714,13 +712,13 @@ Parse_SwizzleSrcReg(struct parse_state *parseState, struct vp_src_register *srcR
GLint k;
for (k = 0; token[k] && k < 5; k++) {
if (token[k] == 'x')
- srcReg->Swizzle[k] = 0;
+ srcReg->Swizzle |= 0 << (k*3);
else if (token[k] == 'y')
- srcReg->Swizzle[k] = 1;
+ srcReg->Swizzle |= 1 << (k*3);
else if (token[k] == 'z')
- srcReg->Swizzle[k] = 2;
+ srcReg->Swizzle |= 2 << (k*3);
else if (token[k] == 'w')
- srcReg->Swizzle[k] = 3;
+ srcReg->Swizzle |= 3 << (k*3);
else
RETURN_ERROR;
}
@@ -737,6 +735,7 @@ static GLboolean
Parse_ScalarSrcReg(struct parse_state *parseState, struct vp_src_register *srcReg)
{
GLubyte token[100];
+ GLint idx;
srcReg->RelAddr = GL_FALSE;
@@ -756,8 +755,9 @@ Parse_ScalarSrcReg(struct parse_state *parseState, struct vp_src_register *srcRe
/* Src reg can be R<n>, c[n], c[n +/- offset], or a named vertex attrib */
if (token[0] == 'R') {
srcReg->File = PROGRAM_TEMPORARY;
- if (!Parse_TempReg(parseState, &srcReg->Index))
+ if (!Parse_TempReg(parseState, &idx))
RETURN_ERROR;
+ srcReg->Index = idx;
}
else if (token[0] == 'c') {
if (!Parse_ParamReg(parseState, srcReg))
@@ -765,8 +765,9 @@ Parse_ScalarSrcReg(struct parse_state *parseState, struct vp_src_register *srcRe
}
else if (token[0] == 'v') {
srcReg->File = PROGRAM_INPUT;
- if (!Parse_AttribReg(parseState, &srcReg->Index))
+ if (!Parse_AttribReg(parseState, &idx))
RETURN_ERROR;
+ srcReg->Index = idx;
}
else {
RETURN_ERROR2("Bad source register name", token);
@@ -780,21 +781,20 @@ Parse_ScalarSrcReg(struct parse_state *parseState, struct vp_src_register *srcRe
RETURN_ERROR;
if (token[0] == 'x' && token[1] == 0) {
- srcReg->Swizzle[0] = 0;
+ srcReg->Swizzle = 0;
}
else if (token[0] == 'y' && token[1] == 0) {
- srcReg->Swizzle[0] = 1;
+ srcReg->Swizzle = 1;
}
else if (token[0] == 'z' && token[1] == 0) {
- srcReg->Swizzle[0] = 2;
+ srcReg->Swizzle = 2;
}
else if (token[0] == 'w' && token[1] == 0) {
- srcReg->Swizzle[0] = 3;
+ srcReg->Swizzle = 3;
}
else {
RETURN_ERROR1("Bad scalar source suffix");
}
- srcReg->Swizzle[1] = srcReg->Swizzle[2] = srcReg->Swizzle[3] = 0;
return GL_TRUE;
}
@@ -1042,6 +1042,7 @@ Parse_PrintInstruction(struct parse_state *parseState, struct vp_instruction *in
GLuint len;
GLubyte token[100];
struct vp_src_register *srcReg = &inst->SrcReg[0];
+ GLint idx;
inst->Opcode = VP_OPCODE_PRINT;
inst->StringPos = parseState->curLine - parseState->start;
@@ -1069,18 +1070,16 @@ Parse_PrintInstruction(struct parse_state *parseState, struct vp_instruction *in
srcReg->RelAddr = GL_FALSE;
srcReg->Negate = GL_FALSE;
- srcReg->Swizzle[0] = 0;
- srcReg->Swizzle[1] = 1;
- srcReg->Swizzle[2] = 2;
- srcReg->Swizzle[3] = 3;
+ srcReg->Swizzle = SWIZZLE_NOOP;
/* Register can be R<n>, c[n], c[n +/- offset], a named vertex attrib,
* or an o[n] output register.
*/
if (token[0] == 'R') {
srcReg->File = PROGRAM_TEMPORARY;
- if (!Parse_TempReg(parseState, &srcReg->Index))
+ if (!Parse_TempReg(parseState, &idx))
RETURN_ERROR;
+ srcReg->Index = idx;
}
else if (token[0] == 'c') {
srcReg->File = PROGRAM_ENV_PARAM;
@@ -1089,13 +1088,15 @@ Parse_PrintInstruction(struct parse_state *parseState, struct vp_instruction *in
}
else if (token[0] == 'v') {
srcReg->File = PROGRAM_INPUT;
- if (!Parse_AttribReg(parseState, &srcReg->Index))
+ if (!Parse_AttribReg(parseState, &idx))
RETURN_ERROR;
+ srcReg->Index = idx;
}
else if (token[0] == 'o') {
srcReg->File = PROGRAM_OUTPUT;
- if (!Parse_OutputReg(parseState, &srcReg->Index))
+ if (!Parse_OutputReg(parseState, &idx))
RETURN_ERROR;
+ srcReg->Index = idx;
}
else {
RETURN_ERROR2("Bad source register name", token);
@@ -1448,20 +1449,17 @@ PrintSrcReg(const struct vp_src_register *src)
_mesa_printf("R%d", src->Index);
}
- if (src->Swizzle[0] == src->Swizzle[1] &&
- src->Swizzle[0] == src->Swizzle[2] &&
- src->Swizzle[0] == src->Swizzle[3]) {
- _mesa_printf(".%c", comps[src->Swizzle[0]]);
+ if (GET_SWZ(src->Swizzle, 0) == GET_SWZ(src->Swizzle, 1) &&
+ GET_SWZ(src->Swizzle, 0) == GET_SWZ(src->Swizzle, 2) &&
+ GET_SWZ(src->Swizzle, 0) == GET_SWZ(src->Swizzle, 3)) {
+ _mesa_printf(".%c", comps[GET_SWZ(src->Swizzle, 0)]);
}
- else if (src->Swizzle[0] != 0 ||
- src->Swizzle[1] != 1 ||
- src->Swizzle[2] != 2 ||
- src->Swizzle[3] != 3) {
+ else if (src->Swizzle != SWIZZLE_NOOP) {
_mesa_printf(".%c%c%c%c",
- comps[src->Swizzle[0]],
- comps[src->Swizzle[1]],
- comps[src->Swizzle[2]],
- comps[src->Swizzle[3]]);
+ comps[GET_SWZ(src->Swizzle, 0)],
+ comps[GET_SWZ(src->Swizzle, 1)],
+ comps[GET_SWZ(src->Swizzle, 2)],
+ comps[GET_SWZ(src->Swizzle, 3)]);
}
}
@@ -1469,9 +1467,6 @@ PrintSrcReg(const struct vp_src_register *src)
static void
PrintDstReg(const struct vp_dst_register *dst)
{
- GLint w = dst->WriteMask[0] + dst->WriteMask[1]
- + dst->WriteMask[2] + dst->WriteMask[3];
-
if (dst->File == PROGRAM_OUTPUT) {
_mesa_printf("o[%s]", OutputRegisters[dst->Index]);
}
@@ -1486,15 +1481,15 @@ PrintDstReg(const struct vp_dst_register *dst)
_mesa_printf("R%d", dst->Index);
}
- if (w != 0 && w != 4) {
+ if (dst->WriteMask != 0 && dst->WriteMask != 0xf) {
_mesa_printf(".");
- if (dst->WriteMask[0])
+ if (dst->WriteMask & 0x1)
_mesa_printf("x");
- if (dst->WriteMask[1])
+ if (dst->WriteMask & 0x2)
_mesa_printf("y");
- if (dst->WriteMask[2])
+ if (dst->WriteMask & 0x4)
_mesa_printf("z");
- if (dst->WriteMask[3])
+ if (dst->WriteMask & 0x8)
_mesa_printf("w");
}
}