diff options
author | Brian <[email protected]> | 2007-03-23 14:47:46 -0600 |
---|---|---|
committer | Brian <[email protected]> | 2007-03-23 14:47:46 -0600 |
commit | 63556fa9949f543a8134b6b5ff3d216acb71dd9f (patch) | |
tree | 347e41773e171e24ef3a6a476567e2b706bd341d /src/mesa/shader/prog_execute.c | |
parent | bf020d8d7f719dfea7ea3c65bd2833df6439b59e (diff) |
Add the ability to generate programs that doesn't use condition codes.
ctx->Shader.EmitCondCodes determines if we use condition codes.
If not, IF statement uses first operand's X component as the condition.
Added OPCODE_BRK0, OPCODE_BRK1, OPCODE_CONT0, OPCODE_CONT1 to handle
the common cases of conditional break/continue.
Diffstat (limited to 'src/mesa/shader/prog_execute.c')
-rw-r--r-- | src/mesa/shader/prog_execute.c | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c index 092c07f7b65..f881d477caa 100644 --- a/src/mesa/shader/prog_execute.c +++ b/src/mesa/shader/prog_execute.c @@ -720,6 +720,32 @@ _mesa_execute_program(GLcontext * ctx, pc = inst->BranchTarget - 1; } break; + case OPCODE_BRK0: /* Break if zero */ + /* fall-through */ + case OPCODE_CONT0: /* Continue if zero */ + { + GLfloat a[4]; + fetch_vector1(&inst->SrcReg[0], machine, a); + if (a[0] == 0.0) { + /* take branch */ + /* Subtract 1 here since we'll do pc++ at end of for-loop */ + pc = inst->BranchTarget - 1; + } + } + break; + case OPCODE_BRK1: /* Break if non-zero */ + /* fall-through */ + case OPCODE_CONT1: /* Continue if non-zero */ + { + GLfloat a[4]; + fetch_vector1(&inst->SrcReg[0], machine, a); + if (a[0] != 0.0) { + /* take branch */ + /* Subtract 1 here since we'll do pc++ at end of for-loop */ + pc = inst->BranchTarget - 1; + } + } + break; case OPCODE_CAL: /* Call subroutine (conditional) */ if (eval_condition(machine, inst)) { /* call the subroutine */ @@ -914,13 +940,26 @@ _mesa_execute_program(GLcontext * ctx, } break; case OPCODE_IF: - if (eval_condition(machine, inst)) { - /* do if-clause (just continue execution) */ - } - else { - /* go to the instruction after ELSE or ENDIF */ - assert(inst->BranchTarget >= 0); - pc = inst->BranchTarget - 1; + { + GLboolean cond; + /* eval condition */ + if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { + GLfloat a[4]; + fetch_vector1(&inst->SrcReg[0], machine, a); + cond = (a[0] != 0.0); + } + else { + cond = eval_condition(machine, inst); + } + /* do if/else */ + if (cond) { + /* do if-clause (just continue execution) */ + } + else { + /* go to the instruction after ELSE or ENDIF */ + assert(inst->BranchTarget >= 0); + pc = inst->BranchTarget - 1; + } } break; case OPCODE_ELSE: |