summaryrefslogtreecommitdiff
path: root/src/mesa/shader/prog_execute.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/shader/prog_execute.c')
-rw-r--r--src/mesa/shader/prog_execute.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index fb29768935f..c212790dcd9 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -53,8 +53,18 @@
* Set x to positive or negative infinity.
*/
#if defined(USE_IEEE) || defined(_WIN32)
-#define SET_POS_INFINITY(x) ( *((GLuint *) (void *)&x) = 0x7F800000 )
-#define SET_NEG_INFINITY(x) ( *((GLuint *) (void *)&x) = 0xFF800000 )
+#define SET_POS_INFINITY(x) \
+ do { \
+ fi_type fi; \
+ fi.i = 0x7F800000; \
+ x = fi.f; \
+ } while (0)
+#define SET_NEG_INFINITY(x) \
+ do { \
+ fi_type fi; \
+ fi.i = 0xFF800000; \
+ x = fi.f; \
+ } while (0)
#elif defined(VMS)
#define SET_POS_INFINITY(x) x = __MAXFLOAT
#define SET_NEG_INFINITY(x) x = -__MAXFLOAT
@@ -695,9 +705,13 @@ _mesa_execute_program(GLcontext * ctx,
break;
case OPCODE_BGNLOOP:
/* no-op */
+ ASSERT(program->Instructions[inst->BranchTarget].Opcode
+ == OPCODE_ENDLOOP);
break;
case OPCODE_ENDLOOP:
/* subtract 1 here since pc is incremented by for(pc) loop */
+ ASSERT(program->Instructions[inst->BranchTarget].Opcode
+ == OPCODE_BGNLOOP);
pc = inst->BranchTarget - 1; /* go to matching BNGLOOP */
break;
case OPCODE_BGNSUB: /* begin subroutine */
@@ -705,12 +719,26 @@ _mesa_execute_program(GLcontext * ctx,
case OPCODE_ENDSUB: /* end subroutine */
break;
case OPCODE_BRA: /* branch (conditional) */
- /* fall-through */
+ if (eval_condition(machine, inst)) {
+ /* take branch */
+ /* Subtract 1 here since we'll do pc++ below */
+ pc = inst->BranchTarget - 1;
+ }
+ break;
case OPCODE_BRK: /* break out of loop (conditional) */
- /* fall-through */
+ ASSERT(program->Instructions[inst->BranchTarget].Opcode
+ == OPCODE_ENDLOOP);
+ if (eval_condition(machine, inst)) {
+ /* break out of loop */
+ /* pc++ at end of for-loop will put us after the ENDLOOP inst */
+ pc = inst->BranchTarget;
+ }
+ break;
case OPCODE_CONT: /* continue loop (conditional) */
+ ASSERT(program->Instructions[inst->BranchTarget].Opcode
+ == OPCODE_ENDLOOP);
if (eval_condition(machine, inst)) {
- /* take branch */
+ /* continue at ENDLOOP */
/* Subtract 1 here since we'll do pc++ at end of for-loop */
pc = inst->BranchTarget - 1;
}
@@ -903,6 +931,10 @@ _mesa_execute_program(GLcontext * ctx,
case OPCODE_IF:
{
GLboolean cond;
+ ASSERT(program->Instructions[inst->BranchTarget].Opcode
+ == OPCODE_ELSE ||
+ program->Instructions[inst->BranchTarget].Opcode
+ == OPCODE_ENDIF);
/* eval condition */
if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
GLfloat a[4];
@@ -922,14 +954,16 @@ _mesa_execute_program(GLcontext * ctx,
else {
/* go to the instruction after ELSE or ENDIF */
assert(inst->BranchTarget >= 0);
- pc = inst->BranchTarget - 1;
+ pc = inst->BranchTarget;
}
}
break;
case OPCODE_ELSE:
/* goto ENDIF */
+ ASSERT(program->Instructions[inst->BranchTarget].Opcode
+ == OPCODE_ENDIF);
assert(inst->BranchTarget >= 0);
- pc = inst->BranchTarget - 1;
+ pc = inst->BranchTarget;
break;
case OPCODE_ENDIF:
/* nothing */
@@ -1657,7 +1691,7 @@ _mesa_execute_program(GLcontext * ctx,
{
const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
GLfloat result[4];
- GLhalfNV hx, hy;
+ GLushort hx, hy;
hx = raw & 0xffff;
hy = raw >> 16;
result[0] = result[2] = _mesa_half_to_float(hx);