Simplify and rationalize constant folding for dereferences (array, matrix, vector, swizzle, struct).
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24259 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
1fbaa35ce7
commit
3591813a8b
8 changed files with 95 additions and 180 deletions
|
|
@ -753,4 +753,56 @@ TIntermTyped* TIntermediate::foldConstructor(TIntermAggregate* aggrNode)
|
|||
return addConstantUnion(unionArray, aggrNode->getType(), aggrNode->getLoc());
|
||||
}
|
||||
|
||||
//
|
||||
// Constant folding of a bracket (array-style) dereference or struct-like dot
|
||||
// dereference. Can handle any thing except a multi-character swizzle, though
|
||||
// all swizzles may go to foldSwizzle().
|
||||
//
|
||||
TIntermTyped* TIntermediate::foldDereference(TIntermTyped* node, int index, TSourceLoc loc)
|
||||
{
|
||||
TType dereferencedType(node->getType(), index);
|
||||
dereferencedType.getQualifier().storage = EvqConst;
|
||||
TIntermTyped* result = 0;
|
||||
int size = dereferencedType.getObjectSize();
|
||||
|
||||
int start;
|
||||
if (node->isStruct()) {
|
||||
start = 0;
|
||||
for (int i = 0; i < index; ++i)
|
||||
start += (*node->getType().getStruct())[i].type->getObjectSize();
|
||||
} else
|
||||
start = size * index;
|
||||
|
||||
result = addConstantUnion(TConstUnionArray(node->getAsConstantUnion()->getConstArray(), start, size), node->getType(), loc);
|
||||
|
||||
if (result == 0)
|
||||
result = node;
|
||||
else
|
||||
result->setType(dereferencedType);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Make a constant vector node or constant scalar node, representing a given
|
||||
// constant vector and constant swizzle into it.
|
||||
//
|
||||
TIntermTyped* TIntermediate::foldSwizzle(TIntermTyped* node, TVectorFields& fields, TSourceLoc loc)
|
||||
{
|
||||
const TConstUnionArray& unionArray = node->getAsConstantUnion()->getConstArray();
|
||||
TConstUnionArray constArray(fields.num);
|
||||
|
||||
for (int i = 0; i < fields.num; i++)
|
||||
constArray[i] = unionArray[fields.offsets[i]];
|
||||
|
||||
TIntermTyped* result = addConstantUnion(constArray, node->getType(), loc);
|
||||
|
||||
if (result == 0)
|
||||
result = node;
|
||||
else
|
||||
result->setType(TType(node->getBasicType(), EvqConst, fields.num));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue