HLSL: Disambiguate between struct function parameters
Structs with different names but identical members are treated as
ambiguous by the native HLSL compiler when looking up user-defined
functions. Add the struct name to the function name to work around
this limitation.
BUG=chromium:731324
TEST=angle_end2end_tests
Change-Id: Ie80ac0f1374bc5ac05dfebef3f94e2da7cdfc581
Reviewed-on: https://chromium-review.googlesource.com/558929
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/UtilsHLSL.cpp b/src/compiler/translator/UtilsHLSL.cpp
index 738a29c..150da5a 100644
--- a/src/compiler/translator/UtilsHLSL.cpp
+++ b/src/compiler/translator/UtilsHLSL.cpp
@@ -455,12 +455,21 @@
for (auto parameter : *parameters)
{
const TType ¶mType = parameter->getAsTyped()->getType();
- // Disambiguation is needed for float2x2 and float4 parameters. These are the only parameter
- // types that HLSL thinks are identical. float2x3 and float3x2 are different types, for
- // example. Other parameter types are not added to function names to avoid making function
- // names longer.
+ // Parameter types are only added to function names if they are ambiguous according to the
+ // native HLSL compiler. Other parameter types are not added to function names to avoid
+ // making function names longer.
if (paramType.getObjectSize() == 4 && paramType.getBasicType() == EbtFloat)
{
+ // Disambiguation is needed for float2x2 and float4 parameters. These are the only
+ // built-in types that HLSL thinks are identical. float2x3 and float3x2 are different
+ // types, for example.
+ disambiguatingString += "_" + TypeString(paramType);
+ }
+ else if (paramType.getBasicType() == EbtStruct)
+ {
+ // Disambiguation is needed for struct parameters, since HLSL thinks that structs with
+ // the same fields but a different name are identical.
+ ASSERT(paramType.getStruct()->name() != "");
disambiguatingString += "_" + TypeString(paramType);
}
}