From aca34e771d0ad76d396415e45c5f3cbf294709c9 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 12 Jul 2017 13:40:30 -0700 Subject: 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... --- source/slang/emit.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/slang/emit.cpp') 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(modifier)) + { + if (auto fieldDecl = dynamic_cast(decl)) + { + return true; + } + } + + } + break; + } + + + return false; + } + // Emit any modifiers that should go in front of a declaration void EmitModifiers(RefPtr 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) {} -- cgit v1.2.3