summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-08-12 16:28:18 -0400
committerGitHub <noreply@github.com>2019-08-12 16:28:18 -0400
commitea200663ffe33d7b4c739c0d84e9c21a3ae2ffa6 (patch)
tree73fae6929c3114be15e84875e4e798ef5a3e563c /source/slang
parent6fc2c37d9a4c408331db1b33deb3b46e74d2a7d2 (diff)
Ability to set Paths on Pass Through/Back End Compilers (#1010)
* Expanded prelude for some other resource types. Disable C++ output for ParameterGroup. * WIP: Layout for CPU. * Fixes to CPU layout. * WIP: The uniform is output, but the variable definition is not. * WIP: Entry point parameters to global scope in C++. Handling of resource types (in so far as outputting) * Some discussion of ABI and different input types. * WIP: More C++ support around resource types. * WIP: Split up variables into different structures on emit. * WIP: Emitting C++ with wrapping up of 'Context' * WIP: C++ code has access to semantic values. Wrap in struct so can use method calls to pass shared state. Disable legalizeResourceTypes and legalizeExistentialTypeLayout * Fix structured buffer layout for CPU. * Remove testing/handling of global uniforms on CPU path. Typo fix. Changed CPU tests to use new CPU calling convention. * Check globals are working. Initalize context to zero globals. * Order the global parameters for C++ ouput by their layout. Note - that layout isn't quite working correctly because the StructuredBuffer<int> the int seems to be consuming uniform space. * Work around for reflection not having all data needed for layout ordering for C++ code. * Output constant buffers as pointers. * Entry point parameters accessed through pointer to struct. * WIP: Layout for CPU is reasonable for test case. * Only output 'f' after float literal if type marks as a float. * Cast construction works on C++. * Made IntrinsicOp::ConvertConstruct to make intent clearer. * C++ handling construction from scalar. Handle access of a scalar with .x. Check default initialization. * Comment about need for split of kIROp_construct. Release build works. * Added support from constructVectorFromScalar to C/C++ target. * Handling of in/out in C/C++. * First pass documentation CPU support. * Improvements to C++/C slang code generation documentation. * Small doc change to include need for mechansim to specify cpp compiler path. * WIP: Being able to set path for backends. * Better handling of swizzling - allow swizzling a scalar into a vector. * Fix missing/broken headers for path setting on session. * Fix for compiling using clang on Windows. * Remove Clang test code. * * Removed spSessionGetGlobalSession - no longer needed because SlangSession is slang::IGlobalSession alias. * Gave Session a ref count on spCreateSession, and have it checked on spDestroySession, so behaves correctly as ISlangUnknown Note that spDestroySession does a release (and checks the ref count on debug builds). It's behaviour could be the same as just release, but this seems closer to the original intention.
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-check.cpp44
-rw-r--r--source/slang/slang-compiler.h10
-rw-r--r--source/slang/slang.cpp61
3 files changed, 109 insertions, 6 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index b7c1ccdc2..9a4a01045 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -5,6 +5,9 @@
#include "slang-visitor.h"
#include "../core/slang-secure-crt.h"
+
+#include "../core/slang-io.h"
+
#include <assert.h>
namespace Slang
@@ -323,6 +326,28 @@ namespace Slang
}
}
+ static PassThroughMode _toPassThroughMode(SharedLibraryType type)
+ {
+ switch (type)
+ {
+ case SharedLibraryType::Dxil:
+ case SharedLibraryType::Dxc:
+ {
+ return PassThroughMode::Dxc;
+ }
+ case SharedLibraryType::Fxc: return PassThroughMode::Fxc;
+ case SharedLibraryType::Glslang: return PassThroughMode::Glslang;
+ default: break;
+ }
+
+ return PassThroughMode::None;
+ }
+
+ void Session::setSharedLibrary(SharedLibraryType type, ISlangSharedLibrary* library)
+ {
+ sharedLibraries[int(type)] = library;
+ }
+
ISlangSharedLibrary* Session::getOrLoadSharedLibrary(SharedLibraryType type, DiagnosticSink* sink)
{
// If not loaded, try loading it
@@ -336,6 +361,15 @@ namespace Slang
}
const char* libName = DefaultSharedLibraryLoader::getSharedLibraryNameFromType(type);
+
+ StringBuilder builder;
+ PassThroughMode passThrough = _toPassThroughMode(type);
+ if (passThrough != PassThroughMode::None && m_passThroughPaths[int(passThrough)].getLength() > 0)
+ {
+ Path::combineIntoBuilder(m_passThroughPaths[int(passThrough)].getUnownedSlice(), UnownedStringSlice(libName), builder);
+ libName = builder.getBuffer();
+ }
+
if (SLANG_FAILED(sharedLibraryLoader->loadSharedLibrary(libName, sharedLibraries[int(type)].writeRef())))
{
if (sink)
@@ -386,7 +420,15 @@ namespace Slang
if (cppCompilerSet == nullptr)
{
cppCompilerSet = new CPPCompilerSet;
- CPPCompilerUtil::initializeSet(cppCompilerSet);
+
+ typedef CPPCompiler::CompilerType CompilerType;
+ CPPCompilerUtil::InitializeSetDesc desc;
+
+ desc.paths[int(CompilerType::GCC)] = m_passThroughPaths[int(PassThroughMode::Gcc)];
+ desc.paths[int(CompilerType::Clang)] = m_passThroughPaths[int(PassThroughMode::Clang)];
+ desc.paths[int(CompilerType::VisualStudio)] = m_passThroughPaths[int(PassThroughMode::VisualStudio)];
+
+ CPPCompilerUtil::initializeSet(desc, cppCompilerSet);
}
SLANG_ASSERT(cppCompilerSet);
return cppCompilerSet;
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index bbc6505b0..ce01e5ea3 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -762,9 +762,10 @@ namespace Slang
Dxc = SLANG_PASS_THROUGH_DXC, ///< pass through HLSL to `IDxcCompiler` API
Glslang = SLANG_PASS_THROUGH_GLSLANG, ///< pass through GLSL to `glslang` library
Clang = SLANG_PASS_THROUGH_CLANG, ///< Pass through clang compiler
- Gcc = SLANG_PASS_THROUGH_GCC, ///< Gcc compiler
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
+ CountOf = SLANG_PASS_THROUGH_COUNT_OF,
};
class SourceFile;
@@ -1790,6 +1791,9 @@ namespace Slang
SLANG_NO_THROW SlangProfileID SLANG_MCALL findProfile(
char const* name) override;
+ SLANG_NO_THROW void SLANG_MCALL setPassThroughPath(
+ SlangPassThrough passThrough,
+ char const* path) override;
enum class SharedLibraryFuncType
@@ -1916,6 +1920,8 @@ namespace Slang
/// Will try to load the library by specified name (using the set loader), if not one already available.
ISlangSharedLibrary* getOrLoadSharedLibrary(SharedLibraryType type, DiagnosticSink* sink);
+ /// Will unload the specified shared library if it's currently loaded
+ void setSharedLibrary(SharedLibraryType type, ISlangSharedLibrary* library);
/// Gets a shared library by type, or null if not loaded
ISlangSharedLibrary* getSharedLibrary(SharedLibraryType type) const { return sharedLibraries[int(type)]; }
@@ -1936,6 +1942,8 @@ namespace Slang
private:
/// Linkage used for all built-in (stdlib) code.
RefPtr<Linkage> m_builtinLinkage;
+
+ String m_passThroughPaths[int(PassThroughMode::CountOf)]; ///< Paths for each pass through
};
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index bb7e705e6..f0570132f 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -146,6 +146,51 @@ SLANG_NO_THROW SlangProfileID SLANG_MCALL Session::findProfile(
return Slang::Profile::LookUp(name).raw;
}
+SLANG_NO_THROW void SLANG_MCALL Session::setPassThroughPath(
+ SlangPassThrough inPassThrough,
+ char const* path)
+{
+ PassThroughMode passThrough = PassThroughMode(inPassThrough);
+ SLANG_ASSERT(int(passThrough) > int(PassThroughMode::None) && int(passThrough) < int(PassThroughMode::CountOf));
+
+ if (m_passThroughPaths[int(passThrough)] != path)
+ {
+ // If it's changed we should unload any shared libraries that use it
+ switch (passThrough)
+ {
+ case PassThroughMode::Dxc:
+ {
+ setSharedLibrary(SharedLibraryType::Dxc, nullptr);
+ setSharedLibrary(SharedLibraryType::Dxil, nullptr);
+ break;
+ }
+ case PassThroughMode::Fxc:
+ {
+ setSharedLibrary(SharedLibraryType::Fxc, nullptr);
+ break;
+ }
+ case PassThroughMode::Glslang:
+ {
+ setSharedLibrary(SharedLibraryType::Glslang, nullptr);
+ break;
+ }
+ case PassThroughMode::VisualStudio:
+ case PassThroughMode::Gcc:
+ case PassThroughMode::Clang:
+ case PassThroughMode::GenericCCpp:
+ {
+ // If any compiler path set changed, require all to be refreshed
+ cppCompilerSet.setNull();
+ break;
+ }
+ default: break;
+ }
+
+ // Set the path
+ m_passThroughPaths[int(passThrough)] = path;
+ }
+}
+
struct IncludeHandlerImpl : IncludeHandler
{
Linkage* linkage;
@@ -2446,7 +2491,9 @@ Session::~Session()
SLANG_API SlangSession* spCreateSession(const char*)
{
- return asExternal(new Slang::Session());
+ Slang::RefPtr<Slang::Session> session(new Slang::Session());
+ // Will be returned with a refcount of 1
+ return asExternal(session.detach());
}
SLANG_API SlangResult slang_createGlobalSession(
@@ -2463,10 +2510,16 @@ SLANG_API SlangResult slang_createGlobalSession(
}
SLANG_API void spDestroySession(
- SlangSession* session)
+ SlangSession* inSession)
{
- if(!session) return;
- delete Slang::asInternal(session);
+ if(!inSession) return;
+
+ Slang::Session* session = Slang::asInternal(inSession);
+ // It is assumed there is only a single reference on the session (the one placed
+ // with spCreateSession) if this function is called
+ SLANG_ASSERT(session->debugGetReferenceCount() == 1);
+ // Release
+ session->release();
}
SLANG_API void spAddBuiltins(