diff options
| author | Yong He <yonghe@outlook.com> | 2024-05-03 18:02:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-03 18:02:31 -0700 |
| commit | 59903ef7e4ddd8885f71567bf0fc85527a88fffc (patch) | |
| tree | 700a177860d24610780390b35277aa8ff5c47947 | |
| parent | 54153a3681c7c6ef86c6f7a864719d32a1934240 (diff) | |
Add host shared library target. (#4098)
* Add host shared library target.
* Attempt fix.
* Fix warnings.
* try fix.
* Fix test.
* Fix.
23 files changed, 45 insertions, 12 deletions
@@ -612,6 +612,7 @@ extern "C" SLANG_METAL, ///< Metal shading language SLANG_METAL_LIB, ///< Metal library SLANG_METAL_LIB_ASM, ///< Metal library assembly + SLANG_HOST_SHARED_LIBRARY, ///< A shared library/Dll for host code (for hosting CPU/OS) SLANG_TARGET_COUNT_OF, }; diff --git a/source/compiler-core/slang-artifact-desc-util.cpp b/source/compiler-core/slang-artifact-desc-util.cpp index 7e3f61915..783833902 100644 --- a/source/compiler-core/slang-artifact-desc-util.cpp +++ b/source/compiler-core/slang-artifact-desc-util.cpp @@ -276,6 +276,7 @@ SLANG_HIERARCHICAL_ENUM(ArtifactStyle, SLANG_ARTIFACT_STYLE, SLANG_ARTIFACT_STYL case SLANG_HOST_CPP_SOURCE: return Desc::make(Kind::Source, Payload::Cpp, Style::Host, 0); case SLANG_CPP_PYTORCH_BINDING: return Desc::make(Kind::Source, Payload::Cpp, Style::Host, 0); case SLANG_HOST_EXECUTABLE: return Desc::make(Kind::Executable, Payload::HostCPU, Style::Host, 0); + case SLANG_HOST_SHARED_LIBRARY: return Desc::make(Kind::SharedLibrary, Payload::HostCPU, Style::Host, 0); case SLANG_SHADER_SHARED_LIBRARY: return Desc::make(Kind::SharedLibrary, Payload::HostCPU, Style::Kernel, 0); case SLANG_SHADER_HOST_CALLABLE: return Desc::make(Kind::HostCallable, Payload::HostCPU, Style::Kernel, 0); case SLANG_CUDA_SOURCE: return Desc::make(Kind::Source, Payload::CUDA, Style::Kernel, 0); @@ -357,7 +358,7 @@ SLANG_HIERARCHICAL_ENUM(ArtifactStyle, SLANG_ARTIFACT_STYLE, SLANG_ARTIFACT_STYL switch (desc.kind) { case Kind::Executable: return SLANG_HOST_EXECUTABLE; - case Kind::SharedLibrary: return SLANG_SHADER_SHARED_LIBRARY; + case Kind::SharedLibrary: return desc.style == ArtifactStyle::Host ? SLANG_HOST_SHARED_LIBRARY : SLANG_SHADER_SHARED_LIBRARY; case Kind::HostCallable: return desc.style == ArtifactStyle::Host ? SLANG_HOST_HOST_CALLABLE : SLANG_SHADER_HOST_CALLABLE; case Kind::ObjectCode: return SLANG_OBJECT_CODE; default: break; diff --git a/source/compiler-core/slang-gcc-compiler-util.cpp b/source/compiler-core/slang-gcc-compiler-util.cpp index 2bcdfcbfa..52d4a0c29 100644 --- a/source/compiler-core/slang-gcc-compiler-util.cpp +++ b/source/compiler-core/slang-gcc-compiler-util.cpp @@ -560,6 +560,7 @@ static SlangResult _parseGCCFamilyLine(SliceAllocator& allocator, const UnownedS switch (options.targetType) { case SLANG_SHADER_SHARED_LIBRARY: + case SLANG_HOST_SHARED_LIBRARY: { // Shared library cmdLine.addArg("-shared"); @@ -639,7 +640,8 @@ static SlangResult _parseGCCFamilyLine(SliceAllocator& allocator, const UnownedS // Add the library paths - if (options.libraryPaths.count && options.targetType == SLANG_HOST_EXECUTABLE) + if (options.libraryPaths.count && + (options.targetType == SLANG_HOST_EXECUTABLE)) { if(PlatformUtil::isFamily(PlatformFamily::Apple, platformKind)) cmdLine.addArg("-Wl,-rpath,@loader_path,-rpath,@loader_path/../lib"); diff --git a/source/compiler-core/slang-visual-studio-compiler-util.cpp b/source/compiler-core/slang-visual-studio-compiler-util.cpp index 14fad0aec..753d256a6 100644 --- a/source/compiler-core/slang-visual-studio-compiler-util.cpp +++ b/source/compiler-core/slang-visual-studio-compiler-util.cpp @@ -189,6 +189,7 @@ static void _addFile(const String& path, const ArtifactDesc& desc, IOSFileArtifa switch (options.targetType) { case SLANG_SHADER_SHARED_LIBRARY: + case SLANG_HOST_SHARED_LIBRARY: { // Create dynamic link library if (options.debugInfoType == DebugInfoType::None) diff --git a/source/core/slang-type-text-util.cpp b/source/core/slang-type-text-util.cpp index f2f408b28..d18f10a5e 100644 --- a/source/core/slang-type-text-util.cpp +++ b/source/core/slang-type-text-util.cpp @@ -54,7 +54,8 @@ static const TypeTextUtil::CompileTargetInfo s_compileTargetInfos[] = { SLANG_CPP_PYTORCH_BINDING, "cpp,c++,cxx", "torch,torch-binding,torch-cpp,torch-cpp-binding", "C++ for pytorch binding" }, { SLANG_HOST_CPP_SOURCE, "cpp,c++,cxx", "host-cpp,host-c++,host-cxx", "C++ source for host execution"}, { SLANG_HOST_EXECUTABLE,"exe", "exe,executable", "Executable binary" }, - { SLANG_SHADER_SHARED_LIBRARY, "dll,so", "sharedlib,sharedlibrary,dll", "Shared library/Dll" }, + { SLANG_SHADER_SHARED_LIBRARY, "shader-dll,shader-so", "shader-sharedlib,sahder-sharedlibrary,shader-dll", "Shared library/Dll for shader kernel" }, + { SLANG_HOST_SHARED_LIBRARY, "dll,so", "sharedlib,sharedlibrary,dll", "Shared library/Dll for host execution" }, { SLANG_CUDA_SOURCE, "cu", "cuda,cu", "CUDA source code" }, { SLANG_PTX, "ptx", "ptx", "PTX assembly" }, { SLANG_CUDA_OBJECT_CODE, "obj,o", "cuobj,cubin", "CUDA binary" }, diff --git a/source/slang/slang-ast-dump.cpp b/source/slang/slang-ast-dump.cpp index 0019b2130..0986d7284 100644 --- a/source/slang/slang-ast-dump.cpp +++ b/source/slang/slang-ast-dump.cpp @@ -677,6 +677,7 @@ struct ASTDumpContext break; case SPIRVAsmOperand::RayCallableFromLocation: m_writer->emit("__rayCallableFromLocation"); + break; case SPIRVAsmOperand::BuiltinVar: m_writer->emit("builtin"); break; diff --git a/source/slang/slang-check-stmt.cpp b/source/slang/slang-check-stmt.cpp index f7b085579..2af8f7d08 100644 --- a/source/slang/slang-check-stmt.cpp +++ b/source/slang/slang-check-stmt.cpp @@ -267,7 +267,7 @@ namespace Slang } } } - else if (auto defaultStmt = as<DefaultStmt>(sStmt)) + else if (as<DefaultStmt>(sStmt)) { // check that there is at most one `default` clause if (hasDefaultStmt) diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 1f1bed902..b2b765c0e 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -539,6 +539,7 @@ namespace Slang case CodeGenTarget::ShaderSharedLibrary: case CodeGenTarget::HostExecutable: case CodeGenTarget::HostHostCallable: + case CodeGenTarget::HostSharedLibrary: { // We need some C/C++ compiler return PassThroughMode::GenericCCpp; @@ -955,6 +956,7 @@ namespace Slang } case CodeGenTarget::HostHostCallable: case CodeGenTarget::HostExecutable: + case CodeGenTarget::HostSharedLibrary: { return CodeGenTarget::HostCPPSource; } @@ -1279,8 +1281,14 @@ namespace Slang // Set the source type options.sourceLanguage = SlangSourceLanguage(sourceLanguage); - // Disable exceptions and security checks - options.flags &= ~(CompileOptions::Flag::EnableExceptionHandling | CompileOptions::Flag::EnableSecurityChecks); + switch (target) + { + case CodeGenTarget::ShaderHostCallable: + case CodeGenTarget::ShaderSharedLibrary: + // Disable exceptions and security checks + options.flags &= ~(CompileOptions::Flag::EnableExceptionHandling | CompileOptions::Flag::EnableSecurityChecks); + break; + } Profile profile; @@ -1586,6 +1594,7 @@ namespace Slang case CodeGenTarget::ShaderSharedLibrary: case CodeGenTarget::HostExecutable: case CodeGenTarget::HostHostCallable: + case CodeGenTarget::HostSharedLibrary: SLANG_RETURN_ON_FAIL(emitWithDownstreamForEntryPoints(outArtifact)); return SLANG_OK; @@ -1617,6 +1626,7 @@ namespace Slang case CodeGenTarget::ShaderHostCallable: case CodeGenTarget::ShaderSharedLibrary: case CodeGenTarget::HostExecutable: + case CodeGenTarget::HostSharedLibrary: { SLANG_RETURN_ON_FAIL(_emitEntryPoints(outArtifact)); diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 2711da3c9..fc97a2f47 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -85,6 +85,7 @@ namespace Slang PyTorchCppBinding = SLANG_CPP_PYTORCH_BINDING, HostCPPSource = SLANG_HOST_CPP_SOURCE, HostExecutable = SLANG_HOST_EXECUTABLE, + HostSharedLibrary = SLANG_HOST_SHARED_LIBRARY, ShaderSharedLibrary = SLANG_SHADER_SHARED_LIBRARY, ShaderHostCallable = SLANG_SHADER_HOST_CALLABLE, CUDASource = SLANG_CUDA_SOURCE, diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index 2b1f6ad81..7e327cab4 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -329,6 +329,7 @@ SlangResult CPPSourceEmitter::calcTypeName(IRType* type, CodeGenTarget target, S out << ">"; return SLANG_OK; } + return SLANG_FAIL; } case kIROp_IntLit: { @@ -1728,6 +1729,10 @@ void CPPSourceEmitter::emitPreModuleImpl() m_writer->emit("using namespace SLANG_PRELUDE_NAMESPACE;\n"); m_writer->emit("#endif\n\n"); } + else if (m_target == CodeGenTarget::HostCPPSource) + { + m_writer->emit("namespace Slang{ inline void handleSignal(SignalType, char const*) {} }\n"); + } Super::emitPreModuleImpl(); } diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index d768cff97..f9fa90d2f 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -2190,7 +2190,7 @@ void GLSLSourceEmitter::handleRequiredCapabilitiesImpl(IRInst* inst) { _requireGLSLExtension(requireGLSLExt->getExtensionName()); } - else if (auto requireComputeDerivative = as<IRRequireComputeDerivative>(childInst)) + else if (const auto requireComputeDerivative = as<IRRequireComputeDerivative>(childInst)) { // only allowed 1 of derivative_group_quadsNV or derivative_group_linearNV if (m_entryPointStage != Stage::Compute diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 106248ef8..a7cdfc8a3 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1957,6 +1957,7 @@ struct SPIRVEmitContext format = SpvImageFormatRgba8; break; } + break; case kIROp_SNormAttr: switch (vectorSize) { @@ -1973,6 +1974,7 @@ struct SPIRVEmitContext format = SpvImageFormatRgba8Snorm; break; } + break; } } } diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp index 3ac022f68..f35fa6750 100644 --- a/source/slang/slang-ir-layout.cpp +++ b/source/slang/slang-ir-layout.cpp @@ -96,6 +96,7 @@ static Result _calcSizeAndAlignment( case CodeGenTarget::HostCPPSource: case CodeGenTarget::HostHostCallable: case CodeGenTarget::HostExecutable: + case CodeGenTarget::HostSharedLibrary: kPointerSize = (int)sizeof(void*); break; } diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index 1fccf3e27..51b8344f6 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -537,6 +537,7 @@ void getTypeNameHint(StringBuilder& sb, IRInst* type) break; case kIROp_GLSLAtomicUintType: sb << "AtomicCounter"; + break; case kIROp_RaytracingAccelerationStructureType: sb << "RayTracingAccelerationStructure"; break; diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 805ea0fff..b6fcafb61 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -2824,6 +2824,7 @@ SlangResult OptionsParser::_parse( case CodeGenTarget::ShaderHostCallable: case CodeGenTarget::HostExecutable: case CodeGenTarget::ShaderSharedLibrary: + case CodeGenTarget::HostSharedLibrary: case CodeGenTarget::PyTorchCppBinding: case CodeGenTarget::DXIL: case CodeGenTarget::MetalLib: diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index d81cc92cd..83901ecc4 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -1756,6 +1756,7 @@ LayoutRulesFamilyImpl* getDefaultLayoutRulesFamilyForTarget(TargetRequest* targe case CodeGenTarget::HostHostCallable: case CodeGenTarget::ShaderHostCallable: case CodeGenTarget::HostExecutable: + case CodeGenTarget::HostSharedLibrary: case CodeGenTarget::ShaderSharedLibrary: case CodeGenTarget::CPPSource: case CodeGenTarget::CSource: @@ -2057,6 +2058,7 @@ SourceLanguage getIntermediateSourceLanguageForTarget(TargetProgram* targetProgr return SourceLanguage::C; } case CodeGenTarget::ShaderSharedLibrary: + case CodeGenTarget::HostSharedLibrary: case CodeGenTarget::ObjectCode: case CodeGenTarget::HostExecutable: case CodeGenTarget::HostHostCallable: diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 9b612b340..45a6933de 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -246,6 +246,7 @@ void Session::_initCodeGenTransitionMap() // is available. We prefer LLVM if that's available. If it's not we can use generic C/C++ compiler map.addTransition(source, CodeGenTarget::ShaderSharedLibrary, PassThroughMode::GenericCCpp); + map.addTransition(source, CodeGenTarget::HostSharedLibrary, PassThroughMode::GenericCCpp); map.addTransition(source, CodeGenTarget::HostExecutable, PassThroughMode::GenericCCpp); map.addTransition(source, CodeGenTarget::ObjectCode, PassThroughMode::GenericCCpp); } @@ -1709,6 +1710,7 @@ CapabilitySet TargetRequest::getTargetCaps() case CodeGenTarget::PyTorchCppBinding: case CodeGenTarget::HostExecutable: case CodeGenTarget::ShaderSharedLibrary: + case CodeGenTarget::HostSharedLibrary: case CodeGenTarget::HostHostCallable: case CodeGenTarget::ShaderHostCallable: atoms.add(CapabilityName::cpp); diff --git a/tests/diagnostics/local-line.slang b/tests/diagnostics/local-line.slang index ecf6a70bf..07b139516 100644 --- a/tests/diagnostics/local-line.slang +++ b/tests/diagnostics/local-line.slang @@ -1,7 +1,7 @@ //TEST:SIMPLE_LINE:-entry computeMain -target spirv -stage compute -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc -stage compute -//TEST:SIMPLE_LINE:-entry computeMain -target dll -stage compute +//TEST:SIMPLE_LINE:-entry computeMain -target shader-dll -stage compute //TEST:SIMPLE_LINE:-entry computeMain -target ptx -stage compute //TEST:SIMPLE_LINE(filecheck=CHECK):-entry computeMain -target spirv -stage compute -emit-spirv-via-glsl diff --git a/tests/diagnostics/syntax-error-intrinsic.slang b/tests/diagnostics/syntax-error-intrinsic.slang index d6867dd07..f369c22d5 100644 --- a/tests/diagnostics/syntax-error-intrinsic.slang +++ b/tests/diagnostics/syntax-error-intrinsic.slang @@ -7,7 +7,7 @@ //TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc -//TEST:SIMPLE_LINE:-entry computeMain -target dll +//TEST:SIMPLE_LINE:-entry computeMain -target shader-dll //TEST:SIMPLE_LINE:-entry computeMain -target ptx [shader("compute")] diff --git a/tests/diagnostics/syntax-error-op-line-2.slang b/tests/diagnostics/syntax-error-op-line-2.slang index 5e13399d7..097349424 100644 --- a/tests/diagnostics/syntax-error-op-line-2.slang +++ b/tests/diagnostics/syntax-error-op-line-2.slang @@ -7,7 +7,7 @@ //TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc -//TEST:SIMPLE_LINE:-entry computeMain -target dll +//TEST:SIMPLE_LINE:-entry computeMain -target shader-dll //TEST:SIMPLE_LINE:-entry computeMain -target ptx // Here the thing being checked is error reporting around return, and += diff --git a/tests/diagnostics/syntax-error-op-line-3.slang b/tests/diagnostics/syntax-error-op-line-3.slang index 5486b8603..51b2bded7 100644 --- a/tests/diagnostics/syntax-error-op-line-3.slang +++ b/tests/diagnostics/syntax-error-op-line-3.slang @@ -7,7 +7,7 @@ //TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc -//TEST:SIMPLE_LINE:-entry computeMain -target dll +//TEST:SIMPLE_LINE:-entry computeMain -target shader-dll //TEST:SIMPLE_LINE:-entry computeMain -target ptx //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer diff --git a/tests/diagnostics/syntax-error-op-line.slang b/tests/diagnostics/syntax-error-op-line.slang index 24ebaccd7..5459575c9 100644 --- a/tests/diagnostics/syntax-error-op-line.slang +++ b/tests/diagnostics/syntax-error-op-line.slang @@ -7,7 +7,7 @@ //TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc -//TEST:SIMPLE_LINE:-entry computeMain -target dll +//TEST:SIMPLE_LINE:-entry computeMain -target shader-dll //TEST:SIMPLE_LINE:-entry computeMain -target ptx [shader("compute")] diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 28e9e6e2e..ec306e849 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -998,6 +998,7 @@ static PassThroughFlags _getPassThroughFlagsForTarget(SlangCompileTarget target) case SLANG_HOST_EXECUTABLE: case SLANG_SHADER_SHARED_LIBRARY: + case SLANG_HOST_SHARED_LIBRARY: { return PassThroughFlag::Generic_C_CPP; } |
