summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-10-09 14:44:40 -0700
committerGitHub <noreply@github.com>2017-10-09 14:44:40 -0700
commit676560b05f945335ff9e091934f1aea3ff373ced (patch)
tree780f943bbcb9c09852c3c7542ad8d8a63302839d /source
parent06b2192aa2bb6698c863388c5d085ba5b1f28374 (diff)
Fix emit logic for `cbuffer` member with initializer (#205)
Given an input declaration like: cbuffer C { int a = -1; } Slang was automatically generating a `packoffset` semantic to place the member manually, but was emitting it *after* the initializer of the original declaration: cbuffer C : register(b) { int a = -1 : packoffset(c0); } That syntax is invalid, of course, and we actually want: cbuffer C : register(b) { int a : packoffset(c0) = -1; } This wasn't spotted earlier because putting initializers on a `cbuffer` member is not commonly done, since it requires reading those values via the reflection API. Slang's reflection API currently provides no way to access default values like this, so they aren't of much use yet. Still, it is better to emit correct syntax even in cases like this one.
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 938d54d36..8483caefc 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -3291,7 +3291,8 @@ struct EmitVisitor
}
// Shared emit logic for variable declarations (used for parameters, locals, globals, fields)
- void EmitVarDeclCommon(DeclRef<VarDeclBase> declRef)
+
+ void emitVarDeclHead(DeclRef<VarDeclBase> declRef)
{
EmitModifiers(declRef.getDecl());
@@ -3306,7 +3307,10 @@ struct EmitVisitor
}
EmitSemantics(declRef.getDecl());
+ }
+ void emitVarDeclInit(DeclRef<VarDeclBase> declRef)
+ {
// TODO(tfoley): technically have to apply substitution here too...
if (auto initExpr = declRef.getDecl()->initExpr)
{
@@ -3323,6 +3327,12 @@ struct EmitVisitor
}
}
+ void EmitVarDeclCommon(DeclRef<VarDeclBase> declRef)
+ {
+ emitVarDeclHead(declRef);
+ emitVarDeclInit(declRef);
+ }
+
// Shared emit logic for variable declarations (used for parameters, locals, globals, fields)
void EmitVarDeclCommon(RefPtr<VarDeclBase> decl)
{
@@ -3532,7 +3542,7 @@ struct EmitVisitor
{
int fieldIndex = fieldCounter++;
- EmitVarDeclCommon(field);
+ emitVarDeclHead(field);
RefPtr<VarLayout> fieldLayout = structTypeLayout->fields[fieldIndex];
SLANG_RELEASE_ASSERT(fieldLayout->varDecl.GetName() == field.GetName());
@@ -3540,6 +3550,8 @@ struct EmitVisitor
// Emit explicit layout annotations for every field
emitHLSLParameterBlockFieldLayoutSemantics(layout, fieldLayout);
+ emitVarDeclInit(field);
+
Emit(";\n");
}
}
@@ -3809,9 +3821,9 @@ struct EmitVisitor
}
}
- EmitVarDeclCommon(decl);
-
+ emitVarDeclHead(makeDeclRef(decl.Ptr()));
emitHLSLRegisterSemantics(layout);
+ emitVarDeclInit(makeDeclRef(decl.Ptr()));
Emit(";\n");
}