pos = lookup_statevar(var, index1, index2, field, &swizzle, paramList);
assert(pos >= 0);
if (pos >= 0) {
- /* XXX should overwrite Store's fields instead of changing pointers
- * since there may be a child storage_info pointing to this one.
- */
- n0->Store = _slang_new_ir_storage_swz(PROGRAM_STATE_VAR,
- pos,
- n0->Store->Size,
- swizzle);
+ /* newly resolved storage for the statevar/constant/uniform */
+ n0->Store->File = PROGRAM_STATE_VAR;
+ n0->Store->Index = pos;
+ n0->Store->Swizzle = swizzle;
+ n0->Store->Parent = NULL;
}
return pos;
}
}
+
+/**
+ * Return the number of components actually named by the swizzle.
+ * Recall that swizzles may have undefined/don't-care values.
+ */
+static GLuint
+swizzle_size(GLuint swizzle)
+{
+ GLuint size = 0, i;
+ for (i = 0; i < 4; i++) {
+ GLuint swz = GET_SWZ(swizzle, i);
+ size += (swz >= 0 && swz <= 3);
+ }
+ return size;
+}
+
+
static slang_ir_node *
_slang_gen_swizzle(slang_ir_node *child, GLuint swizzle)
{
- /* XXX should rewrite this to use relative/Parent storage */
slang_ir_node *n = new_node1(IR_SWIZZLE, child);
assert(child);
if (n) {
- n->Store = _slang_new_ir_storage_swz(PROGRAM_UNDEFINED, -1, -1, swizzle);
+ assert(!n->Store);
+ n->Store = _slang_new_ir_storage_relative(0,
+ swizzle_size(swizzle),
+ child->Store);
+ n->Store->Swizzle = swizzle;
}
return n;
}
}
-/**
- * Return the number of components actually named by the swizzle.
- * Recall that swizzles may have undefined/don't-care values.
- */
-static GLuint
-swizzle_size(GLuint swizzle)
-{
- GLuint size = 0, i;
- for (i = 0; i < 4; i++) {
- GLuint swz = GET_SWZ(swizzle, i);
- size += (swz >= 0 && swz <= 3);
- }
- return size;
-}
-
-
static struct prog_instruction *
emit_swizzle(slang_emit_info *emitInfo, slang_ir_node *n)
{
- GLuint swizzle;
struct prog_instruction *inst;
inst = emit(emitInfo, n->Children[0]);
- /* For debug: n->Var = n->Children[0]->Var; */
+ /* setup storage info, if needed */
+ if (!n->Store->Parent)
+ n->Store->Parent = n->Children[0]->Store;
- /* "pull-up" the child's storage info, applying our swizzle info */
- n->Store->File = n->Children[0]->Store->File;
- n->Store->Index = n->Children[0]->Store->Index;
- n->Store->Size = swizzle_size(n->Store->Swizzle);
-#if 0
- printf("Emit Swizzle %s reg %d chSize %d mySize %d\n",
- _mesa_swizzle_string(n->Store->Swizzle, 0, 0),
- n->Store->Index, n->Children[0]->Store->Size,
- n->Store->Size);
-#endif
-
- /* apply this swizzle to child's swizzle to get composed swizzle */
- swizzle = fix_swizzle(n->Store->Swizzle); /* remove the don't care terms */
-
-#ifdef DEBUG
- {
- assert(GET_SWZ(swizzle, 0) != SWIZZLE_NIL);
- assert(GET_SWZ(swizzle, 1) != SWIZZLE_NIL);
- assert(GET_SWZ(swizzle, 2) != SWIZZLE_NIL);
- assert(GET_SWZ(swizzle, 3) != SWIZZLE_NIL);
- }
-#endif
-
- n->Store->Swizzle = _slang_swizzle_swizzle(n->Children[0]->Store->Swizzle,
- swizzle);
+ assert(n->Store->Parent);
return inst;
}
/* resolve new absolute storage location */
assert(n->Store);
n->Store->File = root->File;
- n->Store->Index = index;
+ if (root->File == PROGRAM_STATE_VAR)
+ n->Store->Index = 0;
+ else
+ n->Store->Index = index;
+
n->Store->Parent = NULL;
}
else {
n->Store->RelAddr = GL_TRUE;
}
+ /* if array element size is one, make sure we only access X */
+ if (n->Store->Size == 1)
+ n->Store->Swizzle = SWIZZLE_XXXX;
+
return NULL; /* no instruction */
}