summaryrefslogtreecommitdiffstats
path: root/source/slang/lower.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/lower.cpp')
-rw-r--r--source/slang/lower.cpp93
1 files changed, 74 insertions, 19 deletions
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp
index 023c63591..165812fae 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/lower.cpp
@@ -1545,38 +1545,93 @@ struct LoweringVisitor
type = arrayType;
}
- // TODO: if we are declaring an SOA-ized array,
- // this is where those array dimensions would need
- // to be tacked on.
+ // We need to create a reference to the global-scope declaration
+ // of the proper GLSL input/output variable. This might
+ // be a user-defined input/output, or a system-defined `gl_` one.
+ RefPtr<ExpressionSyntaxNode> globalVarExpr;
+
+ // Handle system-value inputs/outputs
+ assert(varLayout);
+ auto systemValueSemantic = varLayout->systemValueSemantic;
+ if (systemValueSemantic.Length() != 0)
+ {
+ auto ns = systemValueSemantic.ToLower();
- RefPtr<Variable> globalVarDecl = new Variable();
- globalVarDecl->Name.Content = info.name;
- globalVarDecl->Type.type = type;
+ if (ns == "sv_target")
+ {
+ // Note: we do *not* need to generate some kind of `gl_`
+ // builtin for fragment-shader outputs: they are just
+ // ordinary `out` variables, with ordinary `location`s,
+ // as far as GLSL is concerned.
+ }
+ else if (ns == "sv_position")
+ {
+ RefPtr<VarExpressionSyntaxNode> globalVarRef = new VarExpressionSyntaxNode();
+ globalVarRef->name = "gl_Position";
+ globalVarExpr = globalVarRef;
+ }
+ else
+ {
+ assert(!"unhandled");
+ }
+ }
- ensureDeclHasAValidName(globalVarDecl);
+ // If we didn't match some kind of builtin input/output,
+ // then declare a user input/output variable instead
+ if (!globalVarExpr)
+ {
+ RefPtr<Variable> globalVarDecl = new Variable();
+ globalVarDecl->Name.Content = info.name;
+ globalVarDecl->Type.type = type;
- addMember(shared->loweredProgram, globalVarDecl);
+ ensureDeclHasAValidName(globalVarDecl);
- // Add the layout information
- RefPtr<ComputedLayoutModifier> modifier = new ComputedLayoutModifier();
- modifier->layout = varLayout;
- addModifier(globalVarDecl, modifier);
+ addMember(shared->loweredProgram, globalVarDecl);
- // Need to generate an assignment in the right direction.
+ // Add the layout information
+ RefPtr<ComputedLayoutModifier> modifier = new ComputedLayoutModifier();
+ modifier->layout = varLayout;
+ addModifier(globalVarDecl, modifier);
+
+ // Add appropriate in/out modifier
+ switch (info.direction)
+ {
+ case VaryingParameterDirection::Input:
+ addModifier(globalVarDecl, new InModifier());
+ break;
+
+ case VaryingParameterDirection::Output:
+ addModifier(globalVarDecl, new OutModifier());
+ break;
+ }
+
+
+ RefPtr<VarExpressionSyntaxNode> globalVarRef = new VarExpressionSyntaxNode();
+ globalVarRef->Position = globalVarDecl->Position;
+ globalVarRef->declRef = makeDeclRef(globalVarDecl.Ptr());
+ globalVarRef->name = globalVarDecl->getName();
+
+ globalVarExpr = globalVarRef;
+ }
+
+ // TODO: if we are declaring an SOA-ized array,
+ // this is where those array dimensions would need
+ // to be tacked on.
//
- // TODO: for now I am just dealing with input:
+ // That is, this logic should be getting collected into a loop,
+ // and so we need to have a loop variable we can use to
+ // index into the two different expressions.
+
+ // Need to generate an assignment in the right direction.
switch (info.direction)
{
case VaryingParameterDirection::Input:
- addModifier(globalVarDecl, new InModifier());
- assign(varExpr, globalVarDecl);
+ assign(varExpr, globalVarExpr);
break;
case VaryingParameterDirection::Output:
- addModifier(globalVarDecl, new OutModifier());
-
- assign(globalVarDecl, varExpr);
+ assign(globalVarExpr, varExpr);
break;
}
}