Fix std140 UBO layouts.
A call to "prePadding" instaed of "prePaddingString" was confusing
the HLSL output engine.
A separate bug was causing HLSL errors because HLSL puts all cbuffer
members in a flattened namespace, which caused our internal padding
variables to overlap.
BUG=angle:725
Change-Id: I69a01fefa430a83e433385c64a532a69e6851ae8
Reviewed-on: https://chromium-review.googlesource.com/212930
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/compiler/translator/StructureHLSL.cpp b/src/compiler/translator/StructureHLSL.cpp
index 7aaf47c..48929af 100644
--- a/src/compiler/translator/StructureHLSL.cpp
+++ b/src/compiler/translator/StructureHLSL.cpp
@@ -17,12 +17,19 @@
namespace sh
{
-Std140PaddingHelper::Std140PaddingHelper(const std::map<TString, int> &structElementIndexes)
- : mPaddingCounter(0),
+Std140PaddingHelper::Std140PaddingHelper(const std::map<TString, int> &structElementIndexes,
+ unsigned *uniqueCounter)
+ : mPaddingCounter(uniqueCounter),
mElementIndex(0),
mStructElementIndexes(structElementIndexes)
{}
+TString Std140PaddingHelper::next()
+{
+ unsigned value = (*mPaddingCounter)++;
+ return str(value);
+}
+
int Std140PaddingHelper::prePadding(const TType &type)
{
if (type.getBasicType() == EbtStruct || type.isMatrix() || type.isArray())
@@ -68,7 +75,7 @@
for (int paddingIndex = 0; paddingIndex < paddingCount; paddingIndex++)
{
- padding += " float pad_" + str(mPaddingCounter++) + ";\n";
+ padding += " float pad_" + next() + ";\n";
}
return padding;
@@ -116,19 +123,25 @@
TString padding;
for (int paddingOffset = numComponents; paddingOffset < 4; paddingOffset++)
{
- padding += " float pad_" + str(mPaddingCounter++) + ";\n";
+ padding += " float pad_" + next() + ";\n";
}
return padding;
}
StructureHLSL::StructureHLSL()
+ : mUniquePaddingCounter(0)
{}
+Std140PaddingHelper StructureHLSL::getPaddingHelper()
+{
+ return Std140PaddingHelper(mStd140StructElementIndexes, &mUniquePaddingCounter);
+}
+
TString StructureHLSL::defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing)
{
if (useStd140Packing)
{
- Std140PaddingHelper padHelper(mStd140StructElementIndexes);
+ Std140PaddingHelper padHelper = getPaddingHelper();
return define(structure, useHLSLRowMajorPacking, useStd140Packing, &padHelper);
}
else
@@ -461,7 +474,7 @@
void StructureHLSL::storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking)
{
- Std140PaddingHelper padHelper(mStd140StructElementIndexes);
+ Std140PaddingHelper padHelper = getPaddingHelper();
const TFieldList &fields = structure.fields();
for (unsigned int i = 0; i < fields.size(); i++)
diff --git a/src/compiler/translator/StructureHLSL.h b/src/compiler/translator/StructureHLSL.h
index 068fa2e..ed002fe 100644
--- a/src/compiler/translator/StructureHLSL.h
+++ b/src/compiler/translator/StructureHLSL.h
@@ -26,7 +26,8 @@
class Std140PaddingHelper
{
public:
- explicit Std140PaddingHelper(const std::map<TString, int> &structElementIndexes);
+ explicit Std140PaddingHelper(const std::map<TString, int> &structElementIndexes,
+ unsigned *uniqueCounter);
int elementIndex() const { return mElementIndex; }
int prePadding(const TType &type);
@@ -34,7 +35,9 @@
TString postPaddingString(const TType &type, bool useHLSLRowMajorPacking);
private:
- int mPaddingCounter;
+ TString next();
+
+ unsigned *mPaddingCounter;
int mElementIndex;
const std::map<TString, int> &mStructElementIndexes;
};
@@ -50,9 +53,11 @@
TString defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
static TString defineNameless(const TStructure &structure);
- Std140PaddingHelper getPaddingHelper() const { return Std140PaddingHelper(mStd140StructElementIndexes); }
+ Std140PaddingHelper getPaddingHelper();
private:
+ unsigned mUniquePaddingCounter;
+
std::map<TString, int> mStd140StructElementIndexes;
typedef std::set<TString> StructNames;
diff --git a/src/compiler/translator/UniformHLSL.cpp b/src/compiler/translator/UniformHLSL.cpp
index 4b74566..e24da6a 100644
--- a/src/compiler/translator/UniformHLSL.cpp
+++ b/src/compiler/translator/UniformHLSL.cpp
@@ -269,7 +269,7 @@
if (blockStorage == EbsStd140)
{
// 2 and 3 component vector types in some cases need pre-padding
- hlsl += padHelper.prePadding(fieldType);
+ hlsl += padHelper.prePaddingString(fieldType);
}
hlsl += " " + InterfaceBlockFieldTypeString(field, blockStorage) +