summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/slang/emit.cpp20
-rw-r--r--tests/bugs/cbuffer-member-init.hlsl13
2 files changed, 29 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");
}
diff --git a/tests/bugs/cbuffer-member-init.hlsl b/tests/bugs/cbuffer-member-init.hlsl
new file mode 100644
index 000000000..fe6db8af0
--- /dev/null
+++ b/tests/bugs/cbuffer-member-init.hlsl
@@ -0,0 +1,13 @@
+//TEST:COMPARE_HLSL: -profile vs_5_0 -target dxbc-assembly -no-checking
+
+// Allow (but ignore) initializer on `cbuffer` member
+
+cbuffer C : register(b0)
+{
+ int a = -1;
+};
+
+float4 main() : SV_Position
+{
+ return a;
+}