summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-04-04 07:18:33 -0700
committerGitHub <noreply@github.com>2018-04-04 07:18:33 -0700
commit7a8ed51873743e6497db28b5a756e080491d2fa3 (patch)
treeb4f2b7e96c5cb992308500a9ac769af0309402c7 /source
parent3115ba7a3640937df01ecf60f7ff55f71a3ab7c2 (diff)
Pass AST interpolation modifiers through to codegen. (#475)
This is a short-term fix, because we (1) don't have an IR-level representation of interpolation qualifiers, and (2) can't introduce one until *after* the IR-level type system is introduced (to be able to handle `struct` fields). The approach here is to find the AST-level declaration, either from layout information (in the case of an ordinary variable or function parameter), or from struct field information (because structs are being output from the AST form anyway). I've included a single end-to-end rendering test to confirm that we handle the `nointerpolation` modifier the same as HLSL. I also added the `noperspective` modifier, which seemed to be missing from our implementation.
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp52
-rw-r--r--source/slang/modifier-defs.h3
-rw-r--r--source/slang/parser.cpp1
3 files changed, 56 insertions, 0 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index f6a87fcfa..22b503b59 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -4574,6 +4574,57 @@ struct EmitVisitor
}
}
+ void emitInterpolationModifiers(
+ EmitContext* ctx,
+ VarDeclBase* decl,
+ Type* valueType)
+ {
+ bool isGLSL = (ctx->shared->target == CodeGenTarget::GLSL);
+ bool anyModifiers = false;
+
+ if(decl->FindModifier<HLSLNoInterpolationModifier>())
+ {
+ anyModifiers = true;
+ Emit(isGLSL ? "flat " : "nointerpolation ");
+ }
+ else if(decl->FindModifier<HLSLNoPerspectiveModifier>())
+ {
+ anyModifiers = true;
+ Emit("noperspective ");
+ }
+ else if(decl->FindModifier<HLSLLinearModifier>())
+ {
+ anyModifiers = true;
+ Emit(isGLSL ? "smooth " : "linear ");
+ }
+ else if(decl->FindModifier<HLSLSampleModifier>())
+ {
+ anyModifiers = true;
+ Emit("sample ");
+ }
+ else if(decl->FindModifier<HLSLCentroidModifier>())
+ {
+ anyModifiers = true;
+ Emit("centroid ");
+ }
+
+ // If the user didn't explicitly qualify a varying
+ // with integer type, then we need to explicitly
+ // add the `flat` modifier for GLSL.
+ if(!anyModifiers && isGLSL)
+ {
+ maybeEmitGLSLFlatModifier(ctx, valueType);
+ }
+ }
+
+ void emitInterpolationModifiers(
+ EmitContext* ctx,
+ VarLayout* layout,
+ Type* valueType)
+ {
+ emitInterpolationModifiers(ctx, layout->varDecl, valueType);
+ }
+
void emitIRVarModifiers(
EmitContext* ctx,
VarLayout* layout,
@@ -5280,6 +5331,7 @@ struct EmitVisitor
if(fieldType->Equals(getSession()->getVoidType()))
continue;
+ emitInterpolationModifiers(ctx, ff.getDecl(), fieldType);
emitIRType(ctx, fieldType, getIRName(ff));
EmitSemantics(ff.getDecl());
diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h
index fdbb05748..baa08a160 100644
--- a/source/slang/modifier-defs.h
+++ b/source/slang/modifier-defs.h
@@ -258,6 +258,9 @@ END_SYNTAX_CLASS()
// HLSL `nointerpolation` modifier
SIMPLE_SYNTAX_CLASS(HLSLNoInterpolationModifier, InterpolationModeModifier)
+// HLSL `noperspective` modifier
+SIMPLE_SYNTAX_CLASS(HLSLNoPerspectiveModifier, InterpolationModeModifier)
+
// HLSL `linear` modifier
SIMPLE_SYNTAX_CLASS(HLSLLinearModifier, InterpolationModeModifier)
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index a3afbe87a..ea8e567b4 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -4358,6 +4358,7 @@ namespace Slang
MODIFIER(column_major, HLSLColumnMajorLayoutModifier);
MODIFIER(nointerpolation, HLSLNoInterpolationModifier);
+ MODIFIER(noperspective, HLSLNoPerspectiveModifier);
MODIFIER(linear, HLSLLinearModifier);
MODIFIER(sample, HLSLSampleModifier);
MODIFIER(centroid, HLSLCentroidModifier);