Refactor ShaderVariables to store fields in the base.
Instead of only storing structure information in Varyings, Uniforms
and Interface Block Fields, store it in the base class. Also only
store base variable information for struct fields, instead of fully
typed information. This works because stuff like interpolation type,
invariance, and other properties are for the entire variable, not
individual fields.
Also add new fields for interface block instance name, varying
invariance and structure name for all struct types.
BUG=angle:466
Change-Id: If03fc071e6becb7aad6dea5093989bba7daee69e
Reviewed-on: https://chromium-review.googlesource.com/213501
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/common/blocklayout.cpp b/src/common/blocklayout.cpp
index c1f0c3a..2aa776f 100644
--- a/src/common/blocklayout.cpp
+++ b/src/common/blocklayout.cpp
@@ -15,15 +15,17 @@
{
BlockLayoutEncoder::BlockLayoutEncoder()
- : mCurrentOffset(0)
+ : mCurrentOffset(0),
+ mInRowMajorField(false)
{
}
-void BlockLayoutEncoder::encodeInterfaceBlockFields(const std::vector<InterfaceBlockField> &fields)
+template <typename VarT>
+void BlockLayoutEncoder::encodeVariables(const std::vector<VarT> &fields)
{
for (unsigned int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++)
{
- const InterfaceBlockField &variable = fields[fieldIndex];
+ const VarT &variable = fields[fieldIndex];
if (variable.fields.size() > 0)
{
@@ -32,28 +34,38 @@
for (unsigned int elementIndex = 0; elementIndex < elementCount; elementIndex++)
{
enterAggregateType();
- encodeInterfaceBlockFields(variable.fields);
+ encodeVariables(variable.fields);
exitAggregateType();
}
}
else
{
- encodeInterfaceBlockField(variable);
+ encodeVariable(variable);
}
}
}
-BlockMemberInfo BlockLayoutEncoder::encodeInterfaceBlockField(const InterfaceBlockField &field)
+// Only defined for interface block fields, and shader variable base
+template void BlockLayoutEncoder::encodeVariables(const std::vector<ShaderVariable> &);
+template void BlockLayoutEncoder::encodeVariables(const std::vector<InterfaceBlockField> &);
+
+BlockMemberInfo BlockLayoutEncoder::encodeVariable(const InterfaceBlockField &field)
+{
+ mInRowMajorField = field.isRowMajorMatrix;
+ return encodeVariable(static_cast<ShaderVariable>(field));
+}
+
+BlockMemberInfo BlockLayoutEncoder::encodeVariable(const sh::ShaderVariable &field)
{
int arrayStride;
int matrixStride;
ASSERT(field.fields.empty());
- getBlockLayoutInfo(field.type, field.arraySize, field.isRowMajorMatrix, &arrayStride, &matrixStride);
+ getBlockLayoutInfo(field.type, field.arraySize, mInRowMajorField, &arrayStride, &matrixStride);
- const BlockMemberInfo memberInfo(mCurrentOffset * BytesPerComponent, arrayStride * BytesPerComponent, matrixStride * BytesPerComponent, field.isRowMajorMatrix);
+ const BlockMemberInfo memberInfo(mCurrentOffset * BytesPerComponent, arrayStride * BytesPerComponent, matrixStride * BytesPerComponent, mInRowMajorField);
- advanceOffset(field.type, field.arraySize, field.isRowMajorMatrix, arrayStride, matrixStride);
+ advanceOffset(field.type, field.arraySize, mInRowMajorField, arrayStride, matrixStride);
return memberInfo;
}