summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian@yutani.localnet.net>2007-03-28 13:23:44 -0600
committerBrian <brian@yutani.localnet.net>2007-03-28 13:23:44 -0600
commit7e4a7fdddd0b333d6825ac0154affeb520c5f0fe (patch)
tree4077e48ade05c76c3ea4f9044512493315650299
parentee2f31e281969fb505a767630cd04b9e08db1b9a (diff)
Use constant_to_src_reg() to simplify some code
-rw-r--r--src/mesa/shader/slang/slang_emit.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index cbc71f36f6..eeaeab1626 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -232,6 +232,27 @@ storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st)
}
+/*
+ * Setup an instrucion src register to point to a scalar constant.
+ */
+static void
+constant_to_src_reg(struct prog_src_register *src, GLfloat val,
+ slang_emit_info *emitInfo)
+{
+ GLuint zeroSwizzle;
+ GLint zeroReg;
+ GLfloat value[4];
+
+ value[0] = val;
+ zeroReg = _mesa_add_unnamed_constant(emitInfo->prog->Parameters,
+ value, 1, &zeroSwizzle);
+ assert(zeroReg >= 0);
+
+ src->File = PROGRAM_CONSTANT;
+ src->Index = zeroReg;
+ src->Swizzle = zeroSwizzle;
+}
+
/**
* Add new instruction at end of given program.
@@ -556,14 +577,9 @@ emit_compare(slang_emit_info *emitInfo, slang_ir_node *n)
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
}
else if (size <= 4) {
- static const GLfloat zero[4] = { 0, 0, 0, 0 };
- GLuint zeroSwizzle, swizzle;
- GLint zeroReg = _mesa_add_unnamed_constant(emitInfo->prog->Parameters,
- zero, 4, &zeroSwizzle);
+ GLuint swizzle;
gl_inst_opcode dotOp;
- assert(zeroReg >= 0);
-
assert(!n->Store);
if (!n->Store) {
if (!alloc_temp_storage(emitInfo, n, size)) /* 'size' bools */
@@ -606,9 +622,7 @@ emit_compare(slang_emit_info *emitInfo, slang_ir_node *n)
/* compute tmp2.x = !tmp2.x via tmp2.x = (tmp2.x == 0) */
inst = new_instruction(emitInfo, OPCODE_SEQ);
storage_to_src_reg(&inst->SrcReg[0], n->Store);
- inst->SrcReg[1].File = PROGRAM_CONSTANT;
- inst->SrcReg[1].Index = zeroReg;
- inst->SrcReg[1].Swizzle = zeroSwizzle;
+ constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
inst->Comment = _mesa_strdup("Invert true/false");
}
@@ -1029,16 +1043,8 @@ emit_cond(slang_emit_info *emitInfo, slang_ir_node *n)
static struct prog_instruction *
emit_not(slang_emit_info *emitInfo, slang_ir_node *n)
{
- GLfloat zero = 0.0;
- slang_ir_storage st;
struct prog_instruction *inst;
- /* need zero constant */
- st.File = PROGRAM_CONSTANT;
- st.Size = 1;
- st.Index = _mesa_add_unnamed_constant(emitInfo->prog->Parameters, &zero,
- 1, &st.Swizzle);
-
/* child expr */
(void) emit(emitInfo, n->Children[0]);
/* XXXX if child instr is SGT convert to SLE, if SEQ, SNE, etc */
@@ -1050,8 +1056,7 @@ emit_not(slang_emit_info *emitInfo, slang_ir_node *n)
inst = new_instruction(emitInfo, OPCODE_SEQ);
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
- storage_to_src_reg(&inst->SrcReg[1], &st);
-
+ constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
free_temp_storage(emitInfo->vt, n->Children[0]);
inst->Comment = _mesa_strdup("NOT");