Fix ambiguous function call issues in HLSL output
D3D compiler can't resolve between these overloaded functions:
float4 vec4(float2x2 x0);
float4 vec4(float4 x0);
Include the parameter types in the function name to disambiguate
between overloaded user-defined functions and constructors, like this:
float4 vec4_float2x2(float2x2 x0);
float4 vec4_float4(float4 x0);
This is only done for float2x2 and float4 parameters, other parameter
types like float2x3 vs. float3x2 don't need this.
BUG=angleproject:1099
BUG=angleproject:1030
TEST=angle_end2end_tests,
dEQP-GLES3.functional.attribute_location.* (10 more tests pass),
dEQP-GLES2.functional.attribute_location.*
Change-Id: Ief047d41b0adbc238393c3c13cb29771cbb83d58
Reviewed-on: https://chromium-review.googlesource.com/329882
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/StructureHLSL.cpp b/src/compiler/translator/StructureHLSL.cpp
index fd1a29c..99b815f 100644
--- a/src/compiler/translator/StructureHLSL.cpp
+++ b/src/compiler/translator/StructureHLSL.cpp
@@ -211,16 +211,18 @@
return string;
}
-void StructureHLSL::addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters)
+TString StructureHLSL::addConstructor(const TType &type,
+ const TString &name,
+ const TIntermSequence *parameters)
{
if (name == "")
{
- return; // Nameless structures don't have constructors
+ return TString(); // Nameless structures don't have constructors
}
if (type.getStruct() && mStructNames.find(name) != mStructNames.end())
{
- return; // Already added
+ return TString(name); // Already added
}
TType ctorType = type;
@@ -231,6 +233,8 @@
typedef std::vector<TType> ParameterArray;
ParameterArray ctorParameters;
+ TString constructorFunctionName;
+
const TStructure* structure = type.getStruct();
if (structure)
{
@@ -265,13 +269,16 @@
{
ctorParameters.push_back(*fields[i]->type());
}
+ constructorFunctionName = TString(name);
}
else if (parameters)
{
- for (TIntermSequence::const_iterator parameter = parameters->begin(); parameter != parameters->end(); parameter++)
+ for (auto parameter : *parameters)
{
- ctorParameters.push_back((*parameter)->getAsTyped()->getType());
+ const TType ¶mType = parameter->getAsTyped()->getType();
+ ctorParameters.push_back(paramType);
}
+ constructorFunctionName = TString(name) + DisambiguateFunctionName(parameters);
}
else UNREACHABLE();
@@ -283,7 +290,7 @@
}
else // Built-in type
{
- constructor += TypeString(ctorType) + " " + name + "(";
+ constructor += TypeString(ctorType) + " " + constructorFunctionName + "(";
}
for (unsigned int parameter = 0; parameter < ctorParameters.size(); parameter++)
@@ -465,6 +472,8 @@
}
mConstructors.insert(constructor);
+
+ return constructorFunctionName;
}
std::string StructureHLSL::structsHeader() const