summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-19 08:49:58 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-19 08:49:58 -0700
commitefedd5e6d0d935ed5baa8d9c6596465fc89ce13c (patch)
tree8c7e631bf126855cd217076eddeea04c44a8f3fb /source
parent4c3d56a304de60ce722bee8418da929ae8895adc (diff)
Fixes for how parameter block names are set up.
We generate implicit names for global-scope parameter blocks (including HLSL `cbuffer`s, since the "name" the user sees is really just for reflection purposes), but this had a few problems: - We used the generated names for parameter-binding purposes - Except for a GLSL block with an explicit name, in which case we'd use the internal name and not the reflection name for matching - The generated named didn't match between GLSL and HLSL/Slang declarations This change tries to fix both of these issues. I changed the name generation to try to make it identical between HLSL and GLSL (to the extent we can control it), just in case. But then I also went and changed the parameter-binding-generation logic to use the *reflection* name instead of the internal name when deciding if things are the "same" parameter.
Diffstat (limited to 'source')
-rw-r--r--source/slang/parameter-binding.cpp19
-rw-r--r--source/slang/parser.cpp18
2 files changed, 23 insertions, 14 deletions
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index 15025f1e4..a8e71b22a 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -379,9 +379,17 @@ static bool findLayoutArg(
//
+static String getReflectionName(VarDeclBase* varDecl)
+{
+ if (auto reflectionNameModifier = varDecl->FindModifier<ParameterBlockReflectionName>())
+ return reflectionNameModifier->nameToken.Content;
+
+ return varDecl->getName();
+}
+
static bool isGLSLBuiltinName(VarDeclBase* varDecl)
{
- return varDecl->getName().StartsWith("gl_");
+ return getReflectionName(varDecl).StartsWith("gl_");
}
RefPtr<ExpressionType> tryGetEffectiveTypeForGLSLVaryingInput(
@@ -614,7 +622,6 @@ static void collectGlobalScopeGLSLVaryingParameter(
// Now add it to our list of reflection parameters, so
// that it can get a location assigned later...
- auto parameterName = varDecl->Name.Content;
ParameterInfo* parameterInfo = new ParameterInfo();
parameterInfo->translationUnit = context->translationUnit;
context->shared->parameters.Add(parameterInfo);
@@ -670,7 +677,7 @@ static void collectGlobalScopeParameter(
//
// First we look for an existing entry matching the name
// of this parameter:
- auto parameterName = varDecl->Name.Content;
+ auto parameterName = getReflectionName(varDecl);
ParameterInfo* parameterInfo = nullptr;
if( context->mapNameToParameterInfo.TryGetValue(parameterName, parameterInfo) )
{
@@ -747,7 +754,7 @@ static void addExplicitParameterBinding(
|| bindingInfo.space != semanticInfo.space )
{
auto firstVarDecl = parameterInfo->varLayouts[0]->varDecl.getDecl();
- getSink(context)->diagnose(firstVarDecl, Diagnostics::conflictingExplicitBindingsForParameter, firstVarDecl->getName());
+ getSink(context)->diagnose(firstVarDecl, Diagnostics::conflictingExplicitBindingsForParameter, getReflectionName(firstVarDecl));
}
// TODO(tfoley): `register` semantics can technically be
@@ -773,7 +780,9 @@ static void addExplicitParameterBinding(
auto paramA = parameterInfo->varLayouts[0]->varDecl.getDecl();
auto paramB = overlappedParameterInfo->varLayouts[0]->varDecl.getDecl();
- getSink(context)->diagnose(paramA, Diagnostics::parameterBindingsOverlap, paramA->getName(), paramB->getName());
+ getSink(context)->diagnose(paramA, Diagnostics::parameterBindingsOverlap,
+ getReflectionName(paramA),
+ getReflectionName(paramB));
}
}
}
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index b821555a9..50205ff29 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -1126,15 +1126,15 @@ namespace Slang
}
- static String GenerateName(Parser* /*parser*/, String const& base)
+ static String generateName(Parser* /*parser*/, String const& base)
{
// TODO: somehow mangle the name to avoid clashes
- return base;
+ return "SLANG_" + base;
}
- static String GenerateName(Parser* parser)
+ static String generateName(Parser* parser)
{
- return GenerateName(parser, "_anonymous_" + String(parser->anonymousCounter++));
+ return generateName(parser, "anonymous_" + String(parser->anonymousCounter++));
}
@@ -1149,7 +1149,7 @@ namespace Slang
if( declaratorInfo.nameToken.Type == TokenType::Unknown )
{
// HACK(tfoley): we always give a name, even if the declarator didn't include one... :(
- decl->Name.Content = GenerateName(parser);
+ decl->Name.Content = generateName(parser);
}
else
{
@@ -1791,8 +1791,8 @@ namespace Slang
addModifier(bufferVarDecl, reflectionNameModifier);
// Both the buffer variable and its type need to have names generated
- bufferVarDecl->Name.Content = GenerateName(parser, "SLANG_constantBuffer_" + reflectionNameToken.Content);
- bufferDataTypeDecl->Name.Content = GenerateName(parser, "SLANG_ConstantBuffer_" + reflectionNameToken.Content);
+ bufferVarDecl->Name.Content = generateName(parser, "parameterBlock_" + reflectionNameToken.Content);
+ bufferDataTypeDecl->Name.Content = generateName(parser, "ParameterBlock_" + reflectionNameToken.Content);
addModifier(bufferDataTypeDecl, new ImplicitParameterBlockElementTypeModifier());
addModifier(bufferVarDecl, new ImplicitParameterBlockVariableModifier());
@@ -1948,7 +1948,7 @@ namespace Slang
parser->FillPosition(blockVarDecl.Ptr());
// Generate a unique name for the data type
- blockDataTypeDecl->Name.Content = GenerateName(parser, "SLANG_ParameterBlock_" + reflectionNameToken.Content);
+ blockDataTypeDecl->Name.Content = generateName(parser, "ParameterBlock_" + reflectionNameToken.Content);
// TODO(tfoley): We end up constructing unchecked syntax here that
// is expected to type check into the right form, but it might be
@@ -1993,7 +1993,7 @@ namespace Slang
else
{
// synthesize a dummy name
- blockVarDecl->Name.Content = GenerateName(parser, "SLANG_parameterBlock_" + reflectionNameToken.Content);
+ blockVarDecl->Name.Content = generateName(parser, "parameterBlock_" + reflectionNameToken.Content);
// Otherwise we have a transparent declaration, similar
// to an HLSL `cbuffer`