From 15335549340c54fd7b89b28104ddc907e9c64638 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 12 Dec 2019 14:53:44 -0500 Subject: Use DownstreamCompiler for all downstream compilers (#1152) * 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. * Fix compiling on gcc/clang for 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. --- source/slang/slang-compiler.cpp | 76 ++++++++--------------------------------- 1 file changed, 15 insertions(+), 61 deletions(-) (limited to 'source/slang/slang-compiler.cpp') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index cba25d7df..16d9a5546 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -427,6 +427,7 @@ namespace Slang { "glsl", SourceLanguage::GLSL }, { "c", SourceLanguage::C }, { "cxx", SourceLanguage::CPP }, + { "cuda", SourceLanguage::CUDA }, }; SourceLanguage findSourceLanguageByName(String const& name) @@ -444,6 +445,7 @@ namespace Slang SlangResult checkExternalCompilerSupport(Session* session, PassThroughMode passThrough) { + // Check if the type is supported on this compile switch (passThrough) { case PassThroughMode::None: @@ -451,54 +453,20 @@ namespace Slang // If no pass through -> that will always work! return SLANG_OK; } - case PassThroughMode::Dxc: - { -#if SLANG_ENABLE_DXIL_SUPPORT - // Must have dxc - return session->getOrLoadSharedLibrary(SharedLibraryType::Dxc, nullptr) ? SLANG_OK : SLANG_E_NOT_FOUND; +#if !SLANG_ENABLE_DXIL_SUPPORT + case PassThroughMode::Dxc: return SLANG_E_NOT_IMPLEMENTED; #endif - break; - } - case PassThroughMode::Fxc: - { -#if SLANG_ENABLE_DXBC_SUPPORT - // Must have fxc - return session->getOrLoadSharedLibrary(SharedLibraryType::Fxc, nullptr) ? SLANG_OK : SLANG_E_NOT_FOUND; +#if !SLANG_ENABLE_DXBC_SUPPORT + case PassThroughMode::Fxc: return SLANG_E_NOT_IMPLEMENTED; #endif - break; - } - case PassThroughMode::Glslang: - { -#if SLANG_ENABLE_GLSLANG_SUPPORT - return session->getOrLoadSharedLibrary(Slang::SharedLibraryType::Glslang, nullptr) ? SLANG_OK : SLANG_E_NOT_FOUND; +#if !SLANG_ENABLE_GLSLANG_SUPPORT + case PassThroughMode::Glslang: return SLANG_E_NOT_IMPLEMENTED; #endif - break; - } - case PassThroughMode::Clang: - { - return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::Clang) ? SLANG_OK: SLANG_E_NOT_FOUND; - } - case PassThroughMode::VisualStudio: - { - return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::VisualStudio) ? SLANG_OK: SLANG_E_NOT_FOUND; - } - case PassThroughMode::Gcc: - { - return session->requireDownstreamCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::GCC) ? SLANG_OK: SLANG_E_NOT_FOUND; - } - case PassThroughMode::GenericCCpp: - { - List 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; - } + default: break; } - return SLANG_E_NOT_IMPLEMENTED; + + return session->getOrLoadDownstreamCompiler(passThrough, nullptr) ? SLANG_OK: SLANG_E_NOT_FOUND; } PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target) @@ -561,20 +529,6 @@ namespace Slang return PassThroughMode::None; } - PassThroughMode getPassThroughModeForDownstreamCompiler(DownstreamCompiler::CompilerType type) - { - typedef DownstreamCompiler::CompilerType CompilerType; - - switch (type) - { - 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; - } - } - SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target) { const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target); @@ -1290,7 +1244,7 @@ SlangResult dissassembleDXILUsingDXC( return SLANG_OK; } - SlangResult emitDownstreamForEntryPoint( + SlangResult emitWithDownstreamForEntryPoint( BackEndCompileRequest* slangRequest, Int entryPointIndex, TargetRequest* targetReq, @@ -1330,8 +1284,8 @@ SlangResult dissassembleDXILUsingDXC( } } - // Get the required downstream CPP compiler - DownstreamCompiler* compiler = session->getDownstreamCompiler(downstreamCompiler); + // Get the required downstream compiler + DownstreamCompiler* compiler = session->getOrLoadDownstreamCompiler(downstreamCompiler, sink); if (!compiler) { @@ -1714,7 +1668,7 @@ SlangResult dissassembleDXILUsingDXC( { RefPtr downstreamResult; - if (SLANG_SUCCEEDED(emitDownstreamForEntryPoint( + if (SLANG_SUCCEEDED(emitWithDownstreamForEntryPoint( compileRequest, entryPointIndex, targetReq, -- cgit v1.2.3