summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-06-18 08:10:47 -0400
committerGitHub <noreply@github.com>2020-06-18 12:10:47 +0000
commit31ae3467242995ab822a29c4148c2e86df2f1eb8 (patch)
treec13e216921ff152c210947d84136ac5ef611f709
parentd1a8cd23d15d0001131b6f01b0c9bc461279f760 (diff)
Associate a downstream compiler for prelude lookup even if output is source. (#1395)
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
-rw-r--r--source/slang/slang-compiler.cpp47
-rw-r--r--source/slang/slang-compiler.h4
-rw-r--r--source/slang/slang-emit.cpp34
3 files changed, 66 insertions, 19 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index a15d7f945..729c0077a 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -408,7 +408,7 @@ namespace Slang
return session->getOrLoadDownstreamCompiler(passThrough, nullptr) ? SLANG_OK: SLANG_E_NOT_FOUND;
}
- PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target)
+ PassThroughMode getPreludeDownstreamCompilerForTarget(Session* session, CodeGenTarget target)
{
switch (target)
{
@@ -418,18 +418,26 @@ namespace Slang
}
case CodeGenTarget::GLSL:
{
- // Can always output GLSL
- return PassThroughMode::None;
+ // For the prelude we'll use Glslang
+ return PassThroughMode::Glslang;
}
case CodeGenTarget::HLSL:
{
- // Can always output HLSL
- return PassThroughMode::None;
+ // Use the default compiler for the source language if set,
+ DownstreamCompiler* downstreamCompiler = session->getDefaultDownstreamCompiler(SourceLanguage::HLSL);
+ if (downstreamCompiler)
+ {
+ return PassThroughMode(downstreamCompiler->getDesc().type);
+ }
+ else
+ {
+ // This is ambiguous, because we could use dxc or fxc. For now we'll go with Dxc.
+ return PassThroughMode::Dxc;
+ }
}
case CodeGenTarget::CUDASource:
{
- // Can always output CUDA
- return PassThroughMode::None;
+ return PassThroughMode::NVRTC;
}
case CodeGenTarget::SPIRVAssembly:
case CodeGenTarget::SPIRV:
@@ -454,8 +462,8 @@ namespace Slang
case CodeGenTarget::CPPSource:
case CodeGenTarget::CSource:
{
- // Don't need an external compiler to output C and C++ code
- return PassThroughMode::None;
+ // We'll just use the generic C/C++ compiler
+ return PassThroughMode::GenericCCpp;
}
case CodeGenTarget::HostCallable:
case CodeGenTarget::SharedLibrary:
@@ -476,9 +484,28 @@ namespace Slang
return PassThroughMode::None;
}
+ PassThroughMode getDownstreamCompilerRequiredForTarget(Session* session, CodeGenTarget target)
+ {
+ switch (target)
+ {
+ // Don't *require* a downstream compiler for source output
+ case CodeGenTarget::GLSL:
+ case CodeGenTarget::HLSL:
+ case CodeGenTarget::CUDASource:
+ case CodeGenTarget::CPPSource:
+ case CodeGenTarget::CSource:
+ {
+ return PassThroughMode::None;
+ }
+ default: break;
+ }
+
+ return getPreludeDownstreamCompilerForTarget(session, target);
+ }
+
SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target)
{
- const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target);
+ const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(session, target);
return (mode != PassThroughMode::None) ?
checkExternalCompilerSupport(session, mode) :
SLANG_OK;
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 26648ed48..b1edbe602 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1191,7 +1191,9 @@ namespace Slang
};
/// Given a target returns the required downstream compiler
- PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target);
+ PassThroughMode getDownstreamCompilerRequiredForTarget(Session* session, CodeGenTarget target);
+ /// Given a target returns a downstream compiler the prelude should be taken from.
+ PassThroughMode getPreludeDownstreamCompilerForTarget(Session* session, CodeGenTarget target);
struct TypeCheckingCache;
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 260a862ae..4af7b5989 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -731,17 +731,35 @@ SlangResult emitEntryPointSourceFromIR(
Session* session = compileRequest->getSession();
// Get the downstream compiler needed for final target
- PassThroughMode passThru = getDownstreamCompilerRequiredForTarget(targetRequest->target);
+ PassThroughMode passThru = getDownstreamCompilerRequiredForTarget(session, targetRequest->target);
- // If generic CPP work out what compiler will actually be used
- if (passThru == PassThroughMode::GenericCCpp)
+ // If nothing was *needed*, we still need some idea of which downstream compiler is going to be used for the
+ // prelude (the prelude is associated with each specific downstream compiler)
+ if (passThru == PassThroughMode::None)
{
- const SourceLanguage sourceLanguage = (sourceStyle == SourceStyle::C) ? SourceLanguage::C : SourceLanguage::CPP;
- // Get the compiler used for the language
- DownstreamCompiler* compiler = session->getDefaultDownstreamCompiler(sourceLanguage);
- if (compiler)
+ // TODO(JS):
+ // NOTE! This makes the *assumption* that if we are outputting source, we don't want the
+ // prelude for a specific compiler, we are happy to just use the GenericCCpp
+ // If we didn't do this, we would have to do the work out what's available etc.
+ //
+ // This is all a bit unfortunate. The decision to associate preludes on compilers seemed like a good idea, but was perhaps a mistake.
+ // That it would be simpler if prelude was based on output source type.
+ passThru = getPreludeDownstreamCompilerForTarget(session, targetRequest->target);
+ }
+ else
+ {
+ // If a compiler was required that means a downstream compiler *will* be used
+ // so lookup which specific compiler is used, and use it's prelude
+ // Currently this distinction is only applicable to C++
+ if (passThru == PassThroughMode::GenericCCpp)
{
- passThru = PassThroughMode(compiler->getDesc().type);
+ const SourceLanguage sourceLanguage = (sourceStyle == SourceStyle::C) ? SourceLanguage::C : SourceLanguage::CPP;
+ // Get the compiler used for the language
+ DownstreamCompiler* compiler = session->getDefaultDownstreamCompiler(sourceLanguage);
+ if (compiler)
+ {
+ passThru = PassThroughMode(compiler->getDesc().type);
+ }
}
}