summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-12-12 16:14:27 -0500
committerGitHub <noreply@github.com>2019-12-12 16:14:27 -0500
commita2d4d447639a1860f9de4ba9e2435f1d40ff3669 (patch)
tree028e8ddc77ccd08bcb189204de8a1469535d2507 /source/slang
parent15335549340c54fd7b89b28104ddc907e9c64638 (diff)
Feature/source downstream compiler (#1153)
* CPPCompiler -> DownstreamCompiler * Added DownstreamCompileResult to start abstraction such that we don't need files. * * Split out slang-blob.cpp * Made CompileResult hold a DownstreamCompileResult - for access to binary or ISlangSharedLibrary * Keep temporary files in scope. * Add a hash to the hex dump stream. * Move all file tracking into DownstreamCompiler. * WIP support for nvrtc. * WIP: Adding support for nvrtc compiler. Adding enum types, wiring up the nvrtc into slang. * Fix remaining CPPCompiler references. * Fix order issue on target string matching. * Use ISlangSharedLibrary for nvrtc. * Use DownstreamCompiler for nvrtc. * WIP first pass at compilation win nvrtc. * Added testing if file is on file system into CommandLineDownstreamCompiler. Added sourceContentsPath. * Make test cuda-compile.cu work by just compiling not comparing output. * Genearlize DownstreamCompiler usage. * Fix warning on clang. * Remove CompilerType from DownstreamCompiler. * Use DownstreamCompiler interface for all compilers. NOTE for FXC, DXC and GLSLANG this doesn't mean using 'compile' - it's still extracting functions from shared library. * Replace DownstreamCompiler::SourceType -> SlangSourceLanguage * Replace _canCompile with something data driven. * Fix compiling on gcc/clang for DownstreamCompiler. * Moved some text conversions into DownstreamCompiler. * Fix problem on non-vc builds with not having return on locateCompilers for VS. * Change so no warning for code not reachable on locateCompilers for vs.
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-check.cpp13
-rw-r--r--source/slang/slang-compiler.cpp14
-rw-r--r--source/slang/slang-compiler.h5
-rw-r--r--source/slang/slang-options.cpp68
-rw-r--r--source/slang/slang-options.h1
-rw-r--r--source/slang/slang-profile.h2
-rw-r--r--source/slang/slang-state-serialize.cpp2
-rw-r--r--source/slang/slang.cpp39
8 files changed, 21 insertions, 123 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index 50de73f07..b04b1c9f1 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -114,7 +114,7 @@ namespace Slang
if (type == PassThroughMode::GenericCCpp)
{
- // try loading all C/C++ compilers
+ // try testing for availablilty on all C/C++ compilers
getOrLoadDownstreamCompiler(PassThroughMode::Clang, sink);
getOrLoadDownstreamCompiler(PassThroughMode::Gcc, sink);
getOrLoadDownstreamCompiler(PassThroughMode::VisualStudio, sink);
@@ -138,19 +138,20 @@ namespace Slang
DownstreamCompilerUtil::updateDefaults(m_downstreamCompilerSet);
+ DownstreamCompiler* compiler = nullptr;
+
if (type == PassThroughMode::GenericCCpp)
{
- m_downstreamCompilers[int(type)] = m_downstreamCompilerSet->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
+ compiler = m_downstreamCompilerSet->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP);
}
else
{
DownstreamCompiler::Desc desc;
desc.type = SlangPassThrough(type);
-
- m_downstreamCompilers[int(type)] = DownstreamCompilerUtil::findCompiler(m_downstreamCompilerSet, DownstreamCompilerUtil::MatchType::Newest, desc);
+ compiler = DownstreamCompilerUtil::findCompiler(m_downstreamCompilerSet, DownstreamCompilerUtil::MatchType::Newest, desc);
}
-
- return m_downstreamCompilers[int(type)];
+ m_downstreamCompilers[int(type)] = compiler;
+ return compiler;
}
SlangFuncPtr Session::getSharedLibraryFunc(SharedLibraryFuncType type, DiagnosticSink* sink)
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 16d9a5546..07bfaacc9 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -1395,18 +1395,8 @@ SlangResult dissassembleDXILUsingDXC(
}
// Set the source type
- switch (rawSourceLanguage)
- {
- case SourceLanguage::C: options.sourceType = DownstreamCompiler::SourceType::C; break;
- case SourceLanguage::CPP: options.sourceType = DownstreamCompiler::SourceType::CPP; break;
- case SourceLanguage::CUDA: options.sourceType = DownstreamCompiler::SourceType::CUDA; break;
- default:
- {
- SLANG_ASSERT(!"Unhandled source language");
- return SLANG_FAIL;
- }
- }
-
+ options.sourceLanguage = SlangSourceLanguage(rawSourceLanguage);
+
// Disable exceptions and security checks
options.flags &= ~(CompileOptions::Flag::EnableExceptionHandling | CompileOptions::Flag::EnableSecurityChecks);
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 884c1acbc..1a385ab23 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1975,12 +1975,13 @@ namespace Slang
~Session();
ComPtr<ISlangSharedLibraryLoader> m_sharedLibraryLoader; ///< The shared library loader (never null)
+
SlangFuncPtr m_sharedLibraryFunctions[int(SharedLibraryFuncType::CountOf)]; ///< Functions from shared libraries
int m_downstreamCompilerInitialized = 0;
- RefPtr<DownstreamCompilerSet> m_downstreamCompilerSet; ///< Information about all available downstream compilers.
- RefPtr<DownstreamCompiler> m_downstreamCompilers[int(PassThroughMode::CountOf)]; ///< A downstream compiler for a pass through
+ RefPtr<DownstreamCompilerSet> m_downstreamCompilerSet; ///< Information about all available downstream compilers.
+ RefPtr<DownstreamCompiler> m_downstreamCompilers[int(PassThroughMode::CountOf)]; ///< A downstream compiler for a pass through
DownstreamCompilerLocatorFunc m_downstreamCompilerLocators[int(PassThroughMode::CountOf)];
private:
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 310042b8b..f9f8db0e2 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -45,66 +45,6 @@ SlangResult tryReadCommandLineArgument(DiagnosticSink* sink, char const* option,
return SLANG_OK;
}
-#define SLANG_PASS_THROUGH_TYPES(x) \
- x(none, NONE) \
- x(fxc, FXC) \
- x(dxc, DXC) \
- x(glslang, GLSLANG) \
- x(vs, VISUAL_STUDIO) \
- x(visualstudio, VISUAL_STUDIO) \
- x(clang, CLANG) \
- x(gcc, GCC) \
- x(c, GENERIC_C_CPP) \
- x(cpp, GENERIC_C_CPP) \
- x(nvrtc, NVRTC)
-
-static SlangResult _parsePassThrough(const UnownedStringSlice& name, SlangPassThrough& outPassThrough)
-{
-#define SLANG_PASS_THROUGH_TYPE_CHECK(x, y) \
- if (name == #x) { outPassThrough = SLANG_PASS_THROUGH_##y; return SLANG_OK; }
- SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_CHECK)
- return SLANG_FAIL;
-}
-
-static SlangSourceLanguage _findSourceLanguage(const UnownedStringSlice& text)
-{
- if (text == "c" || text == "C")
- {
- return SLANG_SOURCE_LANGUAGE_C;
- }
- else if (text == "cpp" || text == "c++" || text == "C++" || text == "cxx")
- {
- return SLANG_SOURCE_LANGUAGE_CPP;
- }
- else if (text == "slang")
- {
- return SLANG_SOURCE_LANGUAGE_SLANG;
- }
- else if (text == "glsl")
- {
- return SLANG_SOURCE_LANGUAGE_GLSL;
- }
- else if (text == "hlsl")
- {
- return SLANG_SOURCE_LANGUAGE_HLSL;
- }
- else if (text == "cu" || text == "cuda")
- {
- return SLANG_SOURCE_LANGUAGE_CUDA;
- }
- return SLANG_SOURCE_LANGUAGE_UNKNOWN;
-}
-
-UnownedStringSlice getPassThroughName(SlangPassThrough passThru)
-{
-#define SLANG_PASS_THROUGH_TYPE_TO_NAME(x, y) \
- if (passThru == SLANG_PASS_THROUGH_##y) return UnownedStringSlice::fromLiteral(#x);
-
- SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_TO_NAME)
-
- return UnownedStringSlice::fromLiteral("unknown");
-}
-
struct OptionsParser
{
SlangSession* session = nullptr;
@@ -768,7 +708,7 @@ struct OptionsParser
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_FAILED(_parsePassThrough(name.getUnownedSlice(), passThrough)))
+ if (SLANG_FAILED(DownstreamCompiler::getPassThroughFromName(name.getUnownedSlice(), passThrough)))
{
sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, name);
return SLANG_FAIL;
@@ -1003,7 +943,7 @@ struct OptionsParser
String compilerText;
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, compilerText));
- SlangSourceLanguage sourceLanguage = _findSourceLanguage(sourceLanguageText.getUnownedSlice());
+ SlangSourceLanguage sourceLanguage = DownstreamCompiler::getSourceLanguageFromName(sourceLanguageText.getUnownedSlice());
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
sink->diagnose(SourceLoc(), Diagnostics::unknownSourceLanguage, sourceLanguageText);
@@ -1011,7 +951,7 @@ struct OptionsParser
}
SlangPassThrough compiler;
- if (SLANG_FAILED(_parsePassThrough(compilerText.getUnownedSlice(), compiler)))
+ if (SLANG_FAILED(DownstreamCompiler::getPassThroughFromName(compilerText.getUnownedSlice(), compiler)))
{
sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, compilerText);
return SLANG_FAIL;
@@ -1045,7 +985,7 @@ struct OptionsParser
String slice = argStr.subString(1, index - 1);
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_SUCCEEDED(_parsePassThrough(slice.getUnownedSlice(), passThrough)))
+ if (SLANG_SUCCEEDED(DownstreamCompiler::getPassThroughFromName(slice.getUnownedSlice(), passThrough)))
{
session->setDownstreamCompilerPath(passThrough, name.getBuffer());
continue;
diff --git a/source/slang/slang-options.h b/source/slang/slang-options.h
index bb65c937b..517975d29 100644
--- a/source/slang/slang-options.h
+++ b/source/slang/slang-options.h
@@ -7,7 +7,6 @@
namespace Slang
{
-UnownedStringSlice getPassThroughName(SlangPassThrough passThru);
UnownedStringSlice getCodeGenTargetName(SlangCompileTarget target);
diff --git a/source/slang/slang-profile.h b/source/slang/slang-profile.h
index 2996c7040..9bc8197dc 100644
--- a/source/slang/slang-profile.h
+++ b/source/slang/slang-profile.h
@@ -7,7 +7,7 @@
namespace Slang
{
// Flavors of translation unit
- enum class SourceLanguage : SlangSourceLanguage
+ enum class SourceLanguage : SlangSourceLanguageIntegral
{
Unknown = SLANG_SOURCE_LANGUAGE_UNKNOWN, // should not occur
Slang = SLANG_SOURCE_LANGUAGE_SLANG,
diff --git a/source/slang/slang-state-serialize.cpp b/source/slang/slang-state-serialize.cpp
index 113a422fa..b97756965 100644
--- a/source/slang/slang-state-serialize.cpp
+++ b/source/slang/slang-state-serialize.cpp
@@ -1228,7 +1228,7 @@ static SlangResult _calcCommandLine(OffsetBase& base, StateSerializeUtil::Reques
default:
{
cmd.addArg("-pass-through");
- cmd.addArg(getPassThroughName(SlangPassThrough(requestState->passThroughMode)));
+ cmd.addArg(DownstreamCompiler::getPassThroughName(SlangPassThrough(requestState->passThroughMode)));
break;
}
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index de3c6b0a6..fce90d612 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -205,46 +205,13 @@ SLANG_NO_THROW const char* SLANG_MCALL Session::getBuildTagString()
return SLANG_TAG_VERSION;
}
-static bool _canCompile(PassThroughMode compiler, SourceLanguage sourceLanguage)
+SLANG_NO_THROW SlangResult SLANG_MCALL Session::setDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler)
{
- switch (compiler)
+ if (DownstreamCompiler::canCompile(defaultCompiler, sourceLanguage))
{
- case PassThroughMode::Fxc:
- case PassThroughMode::Dxc:
- {
- return sourceLanguage == SourceLanguage::HLSL;
- }
- case PassThroughMode::Glslang:
- {
- return sourceLanguage == SourceLanguage::GLSL;
- }
- case PassThroughMode::Clang:
- case PassThroughMode::VisualStudio:
- case PassThroughMode::Gcc:
- case PassThroughMode::GenericCCpp:
- {
- return sourceLanguage == SourceLanguage::C || sourceLanguage == SourceLanguage::CPP;
- }
- case PassThroughMode::NVRTC:
- {
- return sourceLanguage == SourceLanguage::CUDA;
- }
- default: break;
- }
- return false;
-}
-
-SLANG_NO_THROW SlangResult SLANG_MCALL Session::setDefaultDownstreamCompiler(SlangSourceLanguage inSourceLanguage, SlangPassThrough defaultCompiler)
-{
- auto sourceLanguage = SourceLanguage(inSourceLanguage);
- auto compiler = PassThroughMode(defaultCompiler);
-
- if (_canCompile(compiler, sourceLanguage))
- {
- m_defaultDownstreamCompilers[int(sourceLanguage)] = compiler;
+ m_defaultDownstreamCompilers[int(sourceLanguage)] = PassThroughMode(defaultCompiler);
return SLANG_OK;
}
-
return SLANG_FAIL;
}