summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-check.cpp14
-rw-r--r--source/slang/slang-compiler.cpp111
-rw-r--r--source/slang/slang-compiler.h11
-rw-r--r--source/slang/slang-emit.cpp4
-rw-r--r--source/slang/slang-options.cpp9
-rw-r--r--source/slang/slang-profile.h1
-rw-r--r--source/slang/slang.cpp30
7 files changed, 114 insertions, 66 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index 3586fcf25..db69a3155 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -121,11 +121,11 @@ namespace Slang
return func;
}
- DownstreamCompilerSet* Session::requireCPPCompilerSet()
+ DownstreamCompilerSet* Session::requireDownstreamCompilerSet()
{
- if (cppCompilerSet == nullptr)
+ if (downstreamCompilerSet == nullptr)
{
- cppCompilerSet = new DownstreamCompilerSet;
+ downstreamCompilerSet = new DownstreamCompilerSet;
typedef DownstreamCompiler::CompilerType CompilerType;
DownstreamCompilerUtil::InitializeSetDesc desc;
@@ -134,10 +134,12 @@ namespace Slang
desc.paths[int(CompilerType::Clang)] = m_downstreamCompilerPaths[int(PassThroughMode::Clang)];
desc.paths[int(CompilerType::VisualStudio)] = m_downstreamCompilerPaths[int(PassThroughMode::VisualStudio)];
- DownstreamCompilerUtil::initializeSet(desc, cppCompilerSet);
+ desc.sharedLibraries[int(CompilerType::NVRTC)] = getOrLoadSharedLibrary(SharedLibraryType::NVRTC, nullptr);
+
+ DownstreamCompilerUtil::initializeSet(desc, downstreamCompilerSet);
}
- SLANG_ASSERT(cppCompilerSet);
- return cppCompilerSet;
+ SLANG_ASSERT(downstreamCompilerSet);
+ return downstreamCompilerSet;
}
TypeCheckingCache* Session::getTypeCheckingCache()
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 9ac49f60c..cba25d7df 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -76,6 +76,7 @@
namespace Slang
{
+// NOTE! These must be in the same order as the SlangCompileTarget enum
#define SLANG_CODE_GEN_TARGETS(x) \
x("unknown", Unknown) \
x("none", None) \
@@ -93,7 +94,9 @@ namespace Slang
x("cpp", CPPSource) \
x("exe,executable", Executable) \
x("sharedlib,sharedlibrary,dll", SharedLibrary) \
- x("callable,host-callable", HostCallable)
+ x("callable,host-callable", HostCallable) \
+ x("cu,cuda", CUDASource) \
+ x("ptx", PTX)
#define SLANG_CODE_GEN_INFO(names, e) \
{ CodeGenTarget::e, UnownedStringSlice::fromLiteral(names) },
@@ -115,6 +118,7 @@ namespace Slang
{
const auto& info = s_codeGenTargetInfos[i];
+ // If this assert fails, then the SLANG_CODE_GEN_TARGETS macro has the wrong order
SLANG_ASSERT(i == int(info.target));
if (StringUtil::indexOfInSplit(info.names, ',', name) >= 0)
@@ -472,23 +476,27 @@ namespace Slang
}
case PassThroughMode::Clang:
{
- return session->requireCPPCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::Clang) ? SLANG_OK: SLANG_E_NOT_FOUND;
+ return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::Clang) ? SLANG_OK: SLANG_E_NOT_FOUND;
}
case PassThroughMode::VisualStudio:
{
- return session->requireCPPCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::VisualStudio) ? SLANG_OK: SLANG_E_NOT_FOUND;
+ return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::VisualStudio) ? SLANG_OK: SLANG_E_NOT_FOUND;
}
case PassThroughMode::Gcc:
{
- return session->requireCPPCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::GCC) ? SLANG_OK: SLANG_E_NOT_FOUND;
+ return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::GCC) ? SLANG_OK: SLANG_E_NOT_FOUND;
}
case PassThroughMode::GenericCCpp:
{
List<DownstreamCompiler::Desc> descs;
- session->requireCPPCompilerSet()->getCompilerDescs(descs);
+ session->requireDownstreamCompilerSet()->getCompilerDescs(descs);
return descs.getCount() ? SLANG_OK: SLANG_E_NOT_FOUND;
}
+ case PassThroughMode::NVRTC:
+ {
+ return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::NVRTC) ? SLANG_OK: SLANG_E_NOT_FOUND;
+ }
}
return SLANG_E_NOT_IMPLEMENTED;
}
@@ -541,6 +549,10 @@ namespace Slang
// We need some C/C++ compiler
return PassThroughMode::GenericCCpp;
}
+ case CodeGenTarget::PTX:
+ {
+ return PassThroughMode::NVRTC;
+ }
default: break;
}
@@ -549,7 +561,7 @@ namespace Slang
return PassThroughMode::None;
}
- PassThroughMode getPassThroughModeForCPPCompiler(DownstreamCompiler::CompilerType type)
+ PassThroughMode getPassThroughModeForDownstreamCompiler(DownstreamCompiler::CompilerType type)
{
typedef DownstreamCompiler::CompilerType CompilerType;
@@ -558,6 +570,7 @@ namespace Slang
case CompilerType::VisualStudio: return PassThroughMode::VisualStudio;
case CompilerType::GCC: return PassThroughMode::Gcc;
case CompilerType::Clang: return PassThroughMode::Clang;
+ case CompilerType::NVRTC: return PassThroughMode::NVRTC;
default: return PassThroughMode::None;
}
}
@@ -1277,7 +1290,7 @@ SlangResult dissassembleDXILUsingDXC(
return SLANG_OK;
}
- SlangResult emitCPUBinaryForEntryPoint(
+ SlangResult emitDownstreamForEntryPoint(
BackEndCompileRequest* slangRequest,
Int entryPointIndex,
TargetRequest* targetReq,
@@ -1297,7 +1310,24 @@ SlangResult dissassembleDXILUsingDXC(
// If we are not in pass through, lookup the default compiler for the emitted source type
if (downstreamCompiler == PassThroughMode::None)
{
- downstreamCompiler = PassThroughMode(session->getDefaultDownstreamCompiler(SLANG_SOURCE_LANGUAGE_CPP));
+ auto target = targetReq->target;
+
+ switch (target)
+ {
+ case CodeGenTarget::PTX:
+ {
+ downstreamCompiler = PassThroughMode(session->getDefaultDownstreamCompiler(SLANG_SOURCE_LANGUAGE_CUDA));
+ break;
+ }
+ case CodeGenTarget::HostCallable:
+ case CodeGenTarget::SharedLibrary:
+ case CodeGenTarget::Executable:
+ {
+ downstreamCompiler = PassThroughMode(session->getDefaultDownstreamCompiler(SLANG_SOURCE_LANGUAGE_CPP));
+ break;
+ }
+ default: break;
+ }
}
// Get the required downstream CPP compiler
@@ -1382,39 +1412,13 @@ SlangResult dissassembleDXILUsingDXC(
const PathInfo& pathInfo = sourceFile->getPathInfo();
if (pathInfo.type == PathInfo::Type::FoundPath || pathInfo.type == PathInfo::Type::Normal)
{
- String compileSourcePath = pathInfo.foundPath;
- // We can see if we can load it
- if (File::exists(compileSourcePath))
- {
- // Here we look for the file on the regular file system (as opposed to using the
- // ISlangFileSystem. This is unfortunate but necessary - because when we call out
- // to the CPP compiler all it is able to (currently) see are files on the file system.
- //
- // Note that it could be coincidence that the filesystem has a file that's identical in
- // contents/name. That being the case though, any includes wouldn't work for a generated
- // file either from some specialized ISlangFileSystem, so this is probably as good as it gets
- // until we can integrate directly to a C/C++ compiler through say a shared library where we can control
- // file system access.
- try
- {
- String readContents = File::readAllText(compileSourcePath);
- // We should see if they are the same
- if ((sourceFile->getContent() == readContents.getUnownedSlice()))
- {
- // We just say use this file
- options.sourceFiles.add(compileSourcePath);
- }
- }
- catch (const Slang::IOException&)
- {
- }
- }
+ options.sourceContentsPath = pathInfo.foundPath;
}
+ options.sourceContents = sourceFile->getContent();
}
-
- // If can't just use file, concat together and make
- if (options.sourceFiles.getCount() == 0)
+ else
{
+ // If can't just use file, concat together and make
StringBuilder codeBuilder;
for (auto sourceFile : translationUnit->getSourceFiles())
{
@@ -1437,8 +1441,18 @@ SlangResult dissassembleDXILUsingDXC(
}
// Set the source type
- options.sourceType = (rawSourceLanguage == SourceLanguage::C) ? DownstreamCompiler::SourceType::C : DownstreamCompiler::SourceType::CPP;
-
+ 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;
+ }
+ }
+
// Disable exceptions and security checks
options.flags &= ~(CompileOptions::Flag::EnableExceptionHandling | CompileOptions::Flag::EnableSecurityChecks);
@@ -1456,6 +1470,13 @@ SlangResult dissassembleDXILUsingDXC(
options.targetType = DownstreamCompiler::TargetType::Executable;
break;
}
+ case CodeGenTarget::PTX:
+ {
+ // TODO(JS): Not clear what to do here.
+ // For example should 'Kernel' be distinct from 'Executable'. For now just use executable.
+ options.targetType = DownstreamCompiler::TargetType::Executable;
+ break;
+ }
default: break;
}
@@ -1488,7 +1509,7 @@ SlangResult dissassembleDXILUsingDXC(
case FloatingPointMode::Default: options.floatingPointMode = DownstreamCompiler::FloatingPointMode::Default; break;
case FloatingPointMode::Precise: options.floatingPointMode = DownstreamCompiler::FloatingPointMode::Precise; break;
case FloatingPointMode::Fast: options.floatingPointMode = DownstreamCompiler::FloatingPointMode::Fast; break;
- default: SLANG_ASSERT(!"Unhanlde floating point mode");
+ default: SLANG_ASSERT(!"Unhandled floating point mode");
}
// Add all the search paths (as calculated earlier - they will only be set if this is a pass through else will be empty)
@@ -1686,13 +1707,14 @@ SlangResult dissassembleDXILUsingDXC(
switch (target)
{
+ case CodeGenTarget::PTX:
case CodeGenTarget::HostCallable:
case CodeGenTarget::SharedLibrary:
case CodeGenTarget::Executable:
{
RefPtr<DownstreamCompileResult> downstreamResult;
- if (SLANG_SUCCEEDED(emitCPUBinaryForEntryPoint(
+ if (SLANG_SUCCEEDED(emitDownstreamForEntryPoint(
compileRequest,
entryPointIndex,
targetReq,
@@ -2012,7 +2034,6 @@ SlangResult dissassembleDXILUsingDXC(
const void* blobData = blob->getBufferPointer();
size_t blobSize = blob->getBufferSize();
-
if (writer->isConsole())
{
// Writing to console, so we need to generate text output.
@@ -2047,12 +2068,16 @@ SlangResult dissassembleDXILUsingDXC(
}
break;
+ case CodeGenTarget::PTX:
+ // For now we just dump PTX out as hex
+
case CodeGenTarget::HostCallable:
case CodeGenTarget::SharedLibrary:
case CodeGenTarget::Executable:
HexDumpUtil::dumpWithMarkers((const uint8_t*)blobData, blobSize, 24, writer);
break;
+
default:
SLANG_UNEXPECTED("unhandled output format");
return;
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index c33b2cf28..be5251d14 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -67,6 +67,8 @@ namespace Slang
Executable = SLANG_EXECUTABLE,
SharedLibrary = SLANG_SHARED_LIBRARY,
HostCallable = SLANG_HOST_CALLABLE,
+ CUDASource = SLANG_CUDA_SOURCE,
+ PTX = SLANG_PTX,
CountOf = SLANG_TARGET_COUNT_OF,
};
@@ -777,6 +779,7 @@ namespace Slang
VisualStudio = SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio compiler
Gcc = SLANG_PASS_THROUGH_GCC, ///< Gcc compiler
GenericCCpp = SLANG_PASS_THROUGH_GENERIC_C_CPP, ///< Generic C/C++ compiler
+ NVRTC = SLANG_PASS_THROUGH_NVRTC,
CountOf = SLANG_PASS_THROUGH_COUNT_OF,
};
@@ -1074,7 +1077,7 @@ namespace Slang
/// Given a target returns the required downstream compiler
PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target);
- PassThroughMode getPassThroughModeForCPPCompiler(DownstreamCompiler::CompilerType type);
+ PassThroughMode getPassThroughModeForDownstreamCompiler(DownstreamCompiler::CompilerType type);
/// A context for loading and re-using code modules.
@@ -1836,7 +1839,7 @@ namespace Slang
/// Get the specified compiler
DownstreamCompiler* getDownstreamCompiler(PassThroughMode downstreamCompiler);
/// Get the default cpp compiler for a language
- DownstreamCompiler* getDefaultCPPCompiler(SourceLanguage sourceLanguage);
+ DownstreamCompiler* getDefaultDownstreamCompiler(SourceLanguage sourceLanguage);
enum class SharedLibraryFuncType
{
@@ -1892,7 +1895,7 @@ namespace Slang
RefPtr<Type> stringType;
RefPtr<Type> enumTypeType;
- RefPtr<DownstreamCompilerSet> cppCompilerSet; ///< Information about available C/C++ compilers. null unless information is requested (because slow)
+ RefPtr<DownstreamCompilerSet> downstreamCompilerSet; ///< Information about available C/C++ compilers. null unless information is requested (because slow)
ComPtr<ISlangSharedLibraryLoader> sharedLibraryLoader; ///< The shared library loader (never null)
ComPtr<ISlangSharedLibrary> sharedLibraries[int(SharedLibraryType::CountOf)]; ///< The loaded shared libraries
@@ -1974,7 +1977,7 @@ namespace Slang
const String& getDownstreamCompilerPrelude(PassThroughMode mode) { return m_downstreamCompilerPreludes[int(mode)]; }
/// Finds out what compilers are present and caches the result
- DownstreamCompilerSet* requireCPPCompilerSet();
+ DownstreamCompilerSet* requireDownstreamCompilerSet();
Session();
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 755a005d1..45eef5148 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -583,10 +583,10 @@ String emitEntryPointSource(
{
const SourceLanguage sourceLanguage = (sourceStyle == SourceStyle::C) ? SourceLanguage::C : SourceLanguage::CPP;
// Get the compiler used for the language
- DownstreamCompiler* compiler = session->getDefaultCPPCompiler(sourceLanguage);
+ DownstreamCompiler* compiler = session->getDefaultDownstreamCompiler(sourceLanguage);
if (compiler)
{
- passThru = getPassThroughModeForCPPCompiler(compiler->getDesc().type);
+ passThru = getPassThroughModeForDownstreamCompiler(compiler->getDesc().type);
}
}
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index c7ede8d93..310042b8b 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -55,7 +55,8 @@ SlangResult tryReadCommandLineArgument(DiagnosticSink* sink, char const* option,
x(clang, CLANG) \
x(gcc, GCC) \
x(c, GENERIC_C_CPP) \
- x(cpp, GENERIC_C_CPP)
+ x(cpp, GENERIC_C_CPP) \
+ x(nvrtc, NVRTC)
static SlangResult _parsePassThrough(const UnownedStringSlice& name, SlangPassThrough& outPassThrough)
{
@@ -87,6 +88,10 @@ static SlangSourceLanguage _findSourceLanguage(const UnownedStringSlice& text)
{
return SLANG_SOURCE_LANGUAGE_HLSL;
}
+ else if (text == "cu" || text == "cuda")
+ {
+ return SLANG_SOURCE_LANGUAGE_CUDA;
+ }
return SLANG_SOURCE_LANGUAGE_UNKNOWN;
}
@@ -334,6 +339,8 @@ struct OptionsParser
{ ".c", SLANG_SOURCE_LANGUAGE_C, SLANG_STAGE_NONE },
{ ".cpp", SLANG_SOURCE_LANGUAGE_CPP, SLANG_STAGE_NONE },
+ { ".cu", SLANG_SOURCE_LANGUAGE_CUDA, SLANG_STAGE_NONE }
+
};
for (int i = 0; i < SLANG_COUNT_OF(entries); ++i)
diff --git a/source/slang/slang-profile.h b/source/slang/slang-profile.h
index b174245ba..2996c7040 100644
--- a/source/slang/slang-profile.h
+++ b/source/slang/slang-profile.h
@@ -15,6 +15,7 @@ namespace Slang
GLSL = SLANG_SOURCE_LANGUAGE_GLSL,
C = SLANG_SOURCE_LANGUAGE_C,
CPP = SLANG_SOURCE_LANGUAGE_CPP,
+ CUDA = SLANG_SOURCE_LANGUAGE_CUDA,
CountOf = SLANG_SOURCE_LANGUAGE_COUNT_OF,
};
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index faf748098..0319d1f7d 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -107,6 +107,7 @@ Session::Session()
}
m_defaultDownstreamCompilers[Index(SourceLanguage::C)] = PassThroughMode::GenericCCpp;
m_defaultDownstreamCompilers[Index(SourceLanguage::CPP)] = PassThroughMode::GenericCCpp;
+ m_defaultDownstreamCompilers[Index(SourceLanguage::CUDA)] = PassThroughMode::NVRTC;
}
}
@@ -193,7 +194,14 @@ SLANG_NO_THROW void SLANG_MCALL Session::setDownstreamCompilerPath(
case PassThroughMode::GenericCCpp:
{
// If any compiler path set changed, require all to be refreshed
- cppCompilerSet.setNull();
+ downstreamCompilerSet.setNull();
+ break;
+ }
+ case PassThroughMode::NVRTC:
+ {
+ // TODO(JS): We need a way to set the NVRTC path.
+ // We want to unload... and try again...
+ downstreamCompilerSet.setNull();
break;
}
default: break;
@@ -249,6 +257,10 @@ static bool _canCompile(PassThroughMode compiler, SourceLanguage sourceLanguage)
{
return sourceLanguage == SourceLanguage::C || sourceLanguage == SourceLanguage::CPP;
}
+ case PassThroughMode::NVRTC:
+ {
+ return sourceLanguage == SourceLanguage::CUDA;
+ }
default: break;
}
return false;
@@ -259,13 +271,10 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::setDefaultDownstreamCompiler(Sla
auto sourceLanguage = SourceLanguage(inSourceLanguage);
auto compiler = PassThroughMode(defaultCompiler);
- if (sourceLanguage == SourceLanguage::C || sourceLanguage == SourceLanguage::CPP)
+ if (_canCompile(compiler, sourceLanguage))
{
- if (_canCompile(compiler, sourceLanguage))
- {
- m_defaultDownstreamCompilers[int(sourceLanguage)] = compiler;
- return SLANG_OK;
- }
+ m_defaultDownstreamCompilers[int(sourceLanguage)] = compiler;
+ return SLANG_OK;
}
return SLANG_FAIL;
@@ -280,19 +289,20 @@ SlangPassThrough SLANG_MCALL Session::getDefaultDownstreamCompiler(SlangSourceLa
DownstreamCompiler* Session::getDownstreamCompiler(PassThroughMode compiler)
{
- DownstreamCompilerSet* compilerSet = requireCPPCompilerSet();
+ DownstreamCompilerSet* compilerSet = requireDownstreamCompilerSet();
switch (compiler)
{
- case PassThroughMode::GenericCCpp: return compilerSet->getDefaultCompiler();
+ case PassThroughMode::GenericCCpp: return compilerSet->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
case PassThroughMode::Clang: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::Clang));
case PassThroughMode::VisualStudio: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::VisualStudio));
case PassThroughMode::Gcc: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::GCC));
+ case PassThroughMode::NVRTC: return compilerSet->getDefaultCompiler(DownstreamCompiler::SourceType::CUDA);
default: break;
}
return nullptr;
}
-DownstreamCompiler* Session::getDefaultCPPCompiler(SourceLanguage sourceLanguage)
+DownstreamCompiler* Session::getDefaultDownstreamCompiler(SourceLanguage sourceLanguage)
{
return getDownstreamCompiler(m_defaultDownstreamCompilers[int(sourceLanguage)]);
}