Compiler - access struct fields

TRAC #11379
Signed-off-by: Daniel Koch

Author:    Nicolas Capens <nicolas@transgaming.com>

git-svn-id: https://angleproject.googlecode.com/svn/trunk@14 736b8ea6-26fd-11df-bfd4-992fa37f6226
This commit is contained in:
daniel@transgaming.com 2010-03-11 19:41:29 +00:00
Родитель fbb6dfa3d6
Коммит 45d035808a
3 изменённых файлов: 101 добавлений и 91 удалений

Просмотреть файл

@ -387,25 +387,25 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
switch (node->getOp())
{
case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break;
case EOpInitialize: outputTriplet(visit, NULL, " = ", NULL); break;
case EOpAddAssign: outputTriplet(visit, NULL, " += ", NULL); break;
case EOpSubAssign: outputTriplet(visit, NULL, " -= ", NULL); break;
case EOpMulAssign: outputTriplet(visit, NULL, " *= ", NULL); break;
case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break;
case EOpInitialize: outputTriplet(visit, NULL, " = ", NULL); break;
case EOpAddAssign: outputTriplet(visit, NULL, " += ", NULL); break;
case EOpSubAssign: outputTriplet(visit, NULL, " -= ", NULL); break;
case EOpMulAssign: outputTriplet(visit, NULL, " *= ", NULL); break;
case EOpVectorTimesMatrixAssign: UNIMPLEMENTED(); /* FIXME */ out << "matrix mult second child into first child"; break;
case EOpVectorTimesScalarAssign: outputTriplet(visit, NULL, " *= ", NULL); break;
case EOpVectorTimesScalarAssign: outputTriplet(visit, NULL, " *= ", NULL); break;
case EOpMatrixTimesScalarAssign: UNIMPLEMENTED(); /* FIXME */ out << "matrix scale second child into first child"; break;
case EOpMatrixTimesMatrixAssign: UNIMPLEMENTED(); /* FIXME */ out << "matrix mult second child into first child"; break;
case EOpDivAssign: outputTriplet(visit, NULL, " /= ", NULL); break;
case EOpDivAssign: outputTriplet(visit, NULL, " /= ", NULL); break;
case EOpModAssign: UNIMPLEMENTED(); /* FIXME */ out << "mod second child into first child"; break;
case EOpAndAssign: UNIMPLEMENTED(); /* FIXME */ out << "and second child into first child"; break;
case EOpInclusiveOrAssign: UNIMPLEMENTED(); /* FIXME */ out << "or second child into first child"; break;
case EOpExclusiveOrAssign: UNIMPLEMENTED(); /* FIXME */ out << "exclusive or second child into first child"; break;
case EOpLeftShiftAssign: UNIMPLEMENTED(); /* FIXME */ out << "left shift second child into first child"; break;
case EOpRightShiftAssign: UNIMPLEMENTED(); /* FIXME */ out << "right shift second child into first child"; break;
case EOpIndexDirect: outputTriplet(visit, NULL, "[", "]"); break;
case EOpIndexIndirect: outputTriplet(visit, NULL, "[", "]"); break;
case EOpIndexDirectStruct: UNIMPLEMENTED(); /* FIXME */ out << "direct index for structure"; break;
case EOpIndexDirect: outputTriplet(visit, NULL, "[", "]"); break;
case EOpIndexIndirect: outputTriplet(visit, NULL, "[", "]"); break;
case EOpIndexDirectStruct: outputTriplet(visit, NULL, ".", NULL); break;
case EOpVectorSwizzle:
if (visit == InVisit)
{
@ -540,9 +540,9 @@ bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node)
case EOpFract: outputTriplet(visit, "frac(", NULL, ")"); break;
case EOpLength: outputTriplet(visit, "length(", NULL, ")"); break;
case EOpNormalize: outputTriplet(visit, "normalize(", NULL, ")"); break;
// case EOpDPdx: outputTriplet(visit, "ddx(", NULL, ")"); break;
// case EOpDPdy: outputTriplet(visit, "ddy(", NULL, ")"); break;
// case EOpFwidth: outputTriplet(visit, "fwidth(", NULL, ")"); break;
// case EOpDPdx: outputTriplet(visit, "ddx(", NULL, ")"); break;
// case EOpDPdy: outputTriplet(visit, "ddy(", NULL, ")"); break;
// case EOpFwidth: outputTriplet(visit, "fwidth(", NULL, ")"); break;
case EOpAny: outputTriplet(visit, "any(", NULL, ")"); break;
case EOpAll: outputTriplet(visit, "all(", NULL, ")"); break;
default: UNREACHABLE();
@ -919,100 +919,109 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
{
TInfoSinkBase &out = context.infoSink.obj;
int size = node->getType().getObjectSize();
bool matrix = node->getType().isMatrix();
TBasicType type = node->getUnionArrayPointer()[0].getType();
TType &type = node->getType();
switch (type)
{
case EbtBool:
if (!matrix)
{
switch (size)
{
case 1: out << "bool("; break;
case 2: out << "bool2("; break;
case 3: out << "bool3("; break;
case 4: out << "bool4("; break;
default: UNREACHABLE();
}
}
else
{
UNIMPLEMENTED();
}
break;
case EbtFloat:
if (!matrix)
{
switch (size)
{
case 1: out << "float("; break;
case 2: out << "float2("; break;
case 3: out << "float3("; break;
case 4: out << "float4("; break;
default: UNREACHABLE();
}
}
else
{
switch (size)
{
case 4: out << "float2x2("; break;
case 9: out << "float3x3("; break;
case 16: out << "float4x4("; break;
default: UNREACHABLE();
}
}
break;
case EbtInt:
if (!matrix)
{
switch (size)
{
case 1: out << "int("; break;
case 2: out << "int2("; break;
case 3: out << "int3("; break;
case 4: out << "int4("; break;
default: UNREACHABLE();
}
}
else
{
UNIMPLEMENTED();
}
break;
default:
UNIMPLEMENTED(); // FIXME
}
for (int i = 0; i < size; i++)
{
switch (type)
if(type.isField())
{
out << type.getFieldName();
}
else
{
int size = type.getObjectSize();
bool matrix = type.isMatrix();
TBasicType basicType = node->getUnionArrayPointer()[0].getType();
switch (basicType)
{
case EbtBool:
if (node->getUnionArrayPointer()[i].getBConst())
if (!matrix)
{
out << "true";
switch (size)
{
case 1: out << "bool("; break;
case 2: out << "bool2("; break;
case 3: out << "bool3("; break;
case 4: out << "bool4("; break;
default: UNREACHABLE();
}
}
else
{
out << "false";
UNIMPLEMENTED();
}
break;
case EbtFloat:
out << node->getUnionArrayPointer()[i].getFConst();
if (!matrix)
{
switch (size)
{
case 1: out << "float("; break;
case 2: out << "float2("; break;
case 3: out << "float3("; break;
case 4: out << "float4("; break;
default: UNREACHABLE();
}
}
else
{
switch (size)
{
case 4: out << "float2x2("; break;
case 9: out << "float3x3("; break;
case 16: out << "float4x4("; break;
default: UNREACHABLE();
}
}
break;
case EbtInt:
out << node->getUnionArrayPointer()[i].getIConst();
if (!matrix)
{
switch (size)
{
case 1: out << "int("; break;
case 2: out << "int2("; break;
case 3: out << "int3("; break;
case 4: out << "int4("; break;
default: UNREACHABLE();
}
}
else
{
UNIMPLEMENTED();
}
break;
default:
default:
UNIMPLEMENTED(); // FIXME
}
if (i != size - 1)
for (int i = 0; i < size; i++)
{
out << ", ";
switch (basicType)
{
case EbtBool:
if (node->getUnionArrayPointer()[i].getBConst())
{
out << "true";
}
else
{
out << "false";
}
break;
case EbtFloat:
out << node->getUnionArrayPointer()[i].getFConst();
break;
case EbtInt:
out << node->getUnionArrayPointer()[i].getIConst();
break;
default:
UNIMPLEMENTED(); // FIXME
}
if (i != size - 1)
{
out << ", ";
}
}
}

Просмотреть файл

@ -205,6 +205,7 @@ public:
virtual bool isMatrix() const { return matrix ? true : false; }
virtual bool isArray() const { return array ? true : false; }
bool isField() const { return fieldName != 0; }
int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; }
void setMaxArraySize (int s) { maxArraySize = s; }

Просмотреть файл

@ -422,7 +422,7 @@ postfix_expression
} else {
constUnion *unionArray = new constUnion[1];
unionArray->setIConst(i);
TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), $3.line);
TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, *(*fields)[i].type, $3.line);
$$ = parseContext.intermediate.addIndex(EOpIndexDirectStruct, $1, index, $2.line);
$$->setType(*(*fields)[i].type);
}