summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-01-18 17:29:23 -0700
committerBrian <[email protected]>2007-01-18 17:29:23 -0700
commit16183e6430d782ff3576e352e24310dfe53fa8ab (patch)
treedaca9cdd9f8b98aca4cf7d21388a488312975120 /src/mesa
parentce6640001dd9a1f3062dc58b199973d6ca94b883 (diff)
Implement constant sharing so that 4 float constants can share a single
float[4] register slot.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c6
-rw-r--r--src/mesa/shader/slang/slang_emit.c25
2 files changed, 19 insertions, 12 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index b389f411773..ea08c46fcfe 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -546,8 +546,12 @@ new_label(slang_atom labName)
static slang_ir_node *
new_float_literal(float x, float y, float z, float w)
{
- GLuint size = 4; /* XXX fix */
+ GLuint size;
slang_ir_node *n = new_node(IR_FLOAT, NULL, NULL);
+ if (x == y && x == z && x == w)
+ size = 1;
+ else
+ size = 4;
n->Value[0] = x;
n->Value[1] = y;
n->Value[2] = z;
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index a30552b909c..ee348e53267 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -36,6 +36,7 @@
#include "prog_parameter.h"
#include "prog_print.h"
#include "slang_emit.h"
+#include "slang_error.h"
/**
@@ -125,22 +126,20 @@ slang_ir_name(slang_ir_opcode opcode)
}
-#if 0
/**
- * Swizzle a swizzle.
+ * Swizzle a swizzle. That is, return swz2(swz1)
*/
static GLuint
-swizzle_compose(GLuint swz1, GLuint swz2)
+swizzle_swizzle(GLuint swz1, GLuint swz2)
{
GLuint i, swz, s[4];
for (i = 0; i < 4; i++) {
- GLuint c = GET_SWZ(swz1, i);
- s[i] = GET_SWZ(swz2, c);
+ GLuint c = GET_SWZ(swz2, i);
+ s[i] = GET_SWZ(swz1, c);
}
swz = MAKE_SWIZZLE4(s[0], s[1], s[2], s[3]);
return swz;
}
-#endif
slang_ir_storage *
@@ -381,7 +380,7 @@ storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st,
assert(st->Size >= 1);
assert(st->Size <= 4);
/* XXX swizzling logic here may need some work */
- /*src->Swizzle = swizzle_compose(swizzle, defaultSwizzle[st->Size - 1]);*/
+ /*src->Swizzle = swizzle_swizzlee(swizzle, defaultSwizzle[st->Size - 1]);*/
if (st->Swizzle != SWIZZLE_NOOP)
src->Swizzle = st->Swizzle;
else
@@ -767,7 +766,8 @@ emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog)
n->Store->Index = n->Children[0]->Store->Index;
n->Store->Size = n->Children[0]->Store->Size;
assert(n->Store->Index >= 0);
- /* XXX compose swizzles here!!! */
+ n->Store->Swizzle = swizzle_swizzle(n->Children[0]->Store->Swizzle,
+ n->Store->Swizzle);
return NULL;
/* Simple binary operators */
@@ -806,10 +806,13 @@ emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog)
case IR_NEG:
return emit_negation(vt, n, prog);
case IR_FLOAT:
- /* find storage location for this float */
+ /* find storage location for this float constant */
n->Store->Index = _mesa_add_unnamed_constant(prog->Parameters, n->Value,
- 4, &n->Store->Swizzle);
- assert(n->Store->Index >= 0);
+ n->Store->Size/*4*/,
+ &n->Store->Swizzle);
+ if (n->Store->Index < 0) {
+ RETURN_ERROR("Ran out of space for constants.", 0);
+ }
return NULL;
case IR_MOVE: