summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-12 13:40:30 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-12 13:40:30 -0700
commitaca34e771d0ad76d396415e45c5f3cbf294709c9 (patch)
tree07b4413d679e52cc56d48fb21b11d66b4e37b26b /source
parentb65861fc32a54d28b3fbbaf0d31bb1d71889f570 (diff)
Don't emit interpolation modifiers on struct fields when outputting GLSL
HLSL (and thus Slang) commonly puts interpolation modifiers like `sample` on the fields of `struct` types used as stage input/output, while GLSL only allows them on global-scope `in` and `out` variables (or ones in blocks). This change emits a really hacky filtering step to skip over certain modifiers when emitting a declaration. This lets us skip interpolation-mode modifiers when outputting a struct field to GLSL. Note: this probably gets the `in` or `out` block case wrong...
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp32
-rw-r--r--source/slang/modifier-defs.h11
2 files changed, 39 insertions, 4 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 3a5acd024..f5b4a8b56 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -2556,6 +2556,35 @@ struct EmitVisitor
Emit(";\n");
}
+ bool shouldSkipModifierForDecl(
+ Modifier* modifier,
+ Decl* decl)
+ {
+ switch(context->shared->target)
+ {
+ default:
+ break;
+
+ case CodeGenTarget::GLSL:
+ {
+ // Don't emit interpolation mode modifiers on `struct` fields
+ // (only allowed on global or block `in`/`out`)
+ if (auto interpolationMod = dynamic_cast<InterpolationModeModifier*>(modifier))
+ {
+ if (auto fieldDecl = dynamic_cast<StructField*>(decl))
+ {
+ return true;
+ }
+ }
+
+ }
+ break;
+ }
+
+
+ return false;
+ }
+
// Emit any modifiers that should go in front of a declaration
void EmitModifiers(RefPtr<Decl> decl)
{
@@ -2587,6 +2616,9 @@ struct EmitVisitor
for (auto mod = decl->modifiers.first; mod; mod = mod->next)
{
+ if (shouldSkipModifierForDecl(mod, decl))
+ continue;
+
advanceToSourceLocation(mod->Position);
if (0) {}
diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h
index c401b3353..2b5c77d86 100644
--- a/source/slang/modifier-defs.h
+++ b/source/slang/modifier-defs.h
@@ -208,17 +208,20 @@ SIMPLE_SYNTAX_CLASS(GLSLColumnMajorLayoutModifier, RowMajorLayoutModifier)
// More HLSL Keyword
+ABSTRACT_SYNTAX_CLASS(InterpolationModeModifier, Modifier)
+END_SYNTAX_CLASS()
+
// HLSL `nointerpolation` modifier
-SIMPLE_SYNTAX_CLASS(HLSLNoInterpolationModifier, Modifier)
+SIMPLE_SYNTAX_CLASS(HLSLNoInterpolationModifier, InterpolationModeModifier)
// HLSL `linear` modifier
-SIMPLE_SYNTAX_CLASS(HLSLLinearModifier, Modifier)
+SIMPLE_SYNTAX_CLASS(HLSLLinearModifier, InterpolationModeModifier)
// HLSL `sample` modifier
-SIMPLE_SYNTAX_CLASS(HLSLSampleModifier, Modifier)
+SIMPLE_SYNTAX_CLASS(HLSLSampleModifier, InterpolationModeModifier)
// HLSL `centroid` modifier
-SIMPLE_SYNTAX_CLASS(HLSLCentroidModifier, Modifier)
+SIMPLE_SYNTAX_CLASS(HLSLCentroidModifier, InterpolationModeModifier)
// HLSL `precise` modifier
SIMPLE_SYNTAX_CLASS(HLSLPreciseModifier, Modifier)