From d86748d3e0767c01d9be6def86df63febb82c2eb Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 10 Jul 2017 11:31:16 -0700 Subject: Don't emitting an imported declaration unless it is used. This helps avoid the problem where we emit a function that does a `discard` and thus get a GLSL compilation failure in a vertex shader (that doesn't even call the function). --- source/slang/lower.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp index 9f117106b..fa38264d4 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -1299,17 +1299,20 @@ struct LoweringVisitor RefPtr visitImportDecl(ImportDecl* decl) { - // No need to translate things here if we are - // in "full" mode, because we will selectively - // translate the imported declarations at their - // use sites(s). - if (!shared->isRewrite) - return nullptr; - - for (auto dd : decl->importedModuleDecl->Members) - { - translateDeclRef(dd); - } + // We could unconditionally output the declarations in the + // imported code, but this could cause problems if any + // of those declarations used capabilities not allowed + // by the target pipeline stage (e.g., `discard` is + // an error in a GLSL vertex shader file, even if + // it is in a function that never gets called). + // + // As a result, we just ignore the `import` step, + // and allow declarations to be pulled in by + // their use sites. + // + // If this proves to be a problem, we will need + // a pass that resolves which declarations in imported + // modules are "valid" for the chosen target stage. // Don't actually include a representation of // the import declaration in the output -- cgit v1.2.3