HLSL: Fix handling nested structs in interface blocks
Make sure that the type definitions for nested structs get added to
the HLSL header, and that the std140 padding information gets
recorded. Prior to this trying to use nested structs in interface
blocks crashed.
BUG=angleproject:2084
TEST=angle_end2end_tests
Change-Id: If57870285c6feaf0c2e462f98f50f20730dd6470
Reviewed-on: https://chromium-review.googlesource.com/608449
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/StructureHLSL.cpp b/src/compiler/translator/StructureHLSL.cpp
index 57c7c75..6d36a17 100644
--- a/src/compiler/translator/StructureHLSL.cpp
+++ b/src/compiler/translator/StructureHLSL.cpp
@@ -248,6 +248,20 @@
const TStructure *structure = type.getStruct();
if (structure)
{
+ const TFieldList &fields = structure->fields();
+ for (const TField *field : fields)
+ {
+ const TType *fieldType = field->type();
+ if (!IsSampler(fieldType->getBasicType()))
+ {
+ ctorParameters.push_back(*fieldType);
+ }
+ if (fieldType->getBasicType() == EbtStruct)
+ {
+ addConstructor(*fieldType, StructNameString(*fieldType->getStruct()), nullptr);
+ }
+ }
+
mStructNames.insert(name);
// Add element index
@@ -275,15 +289,6 @@
mStructDeclarations.push_back(std140RowMajorString);
}
- const TFieldList &fields = structure->fields();
- for (const TField *field : fields)
- {
- const TType *fieldType = field->type();
- if (!IsSampler(fieldType->getBasicType()))
- {
- ctorParameters.push_back(*fieldType);
- }
- }
constructorFunctionName = TString(name);
}
else if (parameters)
@@ -556,9 +561,9 @@
Std140PaddingHelper padHelper = getPaddingHelper();
const TFieldList &fields = structure.fields();
- for (unsigned int i = 0; i < fields.size(); i++)
+ for (const TField *field : fields)
{
- padHelper.prePadding(*fields[i]->type());
+ padHelper.prePadding(*field->type());
}
// Add remaining element index to the global map, for use with nested structs in standard
@@ -566,4 +571,5 @@
const TString &structName = QualifiedStructNameString(structure, useHLSLRowMajorPacking, true);
mStd140StructElementIndexes[structName] = padHelper.elementIndex();
}
-}
+
+} // namespace sh