From 6fc2c37d9a4c408331db1b33deb3b46e74d2a7d2 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 12 Aug 2019 15:41:41 -0400 Subject: Callable CPU code support (#1014) * First pass support for compiling to a loaded shared library. * Improve documentation for cpu target. * Removed the SLANG_COMPILE_FLAG_LOAD_SHARED_LIBRARY flag. Use the SLANG_HOST_CALLABLE code target Document mechanism. * Fix typo in cpp-resource.slang In test code if the target is 'callable' we don't need to compile (indeed there is no source file). * Small refactor using CommandLineCPPCompiler as base class to implement VisualStudioCPPCompiler and GCCCPPCompiler. * Improvements around CPPCompiler. Mechanism to know products produced. Cleaning up products after execution. * Fix multiple definition of 'SourceType' --- source/slang/slang.cpp | 61 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 14 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index cae9855e0..bb7e705e6 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1716,7 +1716,9 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getEntryPointCode( if(entryPointResult.format == ResultFormat::None ) return SLANG_FAIL; - *outCode = entryPointResult.getBlob().detach(); + ComPtr blob; + SLANG_RETURN_ON_FAIL(entryPointResult.getBlob(blob)); + *outCode = blob.detach(); return SLANG_OK; } @@ -3140,29 +3142,28 @@ SLANG_API void const* spGetEntryPointCode( return data; } -SLANG_API SlangResult spGetEntryPointCodeBlob( - SlangCompileRequest* request, - int entryPointIndex, - int targetIndex, - ISlangBlob** outBlob) +static SlangResult _getEntryPointResult( + SlangCompileRequest* request, + int entryPointIndex, + int targetIndex, + Slang::CompileResult** outCompileResult) { using namespace Slang; - if(!request) return SLANG_ERROR_INVALID_PARAMETER; - if(!outBlob) return SLANG_ERROR_INVALID_PARAMETER; - + if (!request) return SLANG_ERROR_INVALID_PARAMETER; + auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); Index targetCount = linkage->targets.getCount(); - if((targetIndex < 0) || (targetIndex >= targetCount)) + if ((targetIndex < 0) || (targetIndex >= targetCount)) { return SLANG_ERROR_INVALID_PARAMETER; } auto targetReq = linkage->targets[targetIndex]; Index entryPointCount = req->entryPoints.getCount(); - if((entryPointIndex < 0) || (entryPointIndex >= entryPointCount)) + if ((entryPointIndex < 0) || (entryPointIndex >= entryPointCount)) { return SLANG_ERROR_INVALID_PARAMETER; } @@ -3170,15 +3171,47 @@ SLANG_API SlangResult spGetEntryPointCodeBlob( auto targetProgram = program->getTargetProgram(targetReq); - if(!targetProgram) + if (!targetProgram) return SLANG_FAIL; - Slang::CompileResult& result = targetProgram->getExistingEntryPointResult(entryPointIndex); + *outCompileResult = &targetProgram->getExistingEntryPointResult(entryPointIndex); + return SLANG_OK; +} + +SLANG_API SlangResult spGetEntryPointCodeBlob( + SlangCompileRequest* request, + int entryPointIndex, + int targetIndex, + ISlangBlob** outBlob) +{ + using namespace Slang; + if(!outBlob) return SLANG_ERROR_INVALID_PARAMETER; + Slang::CompileResult* compileResult = nullptr; + SLANG_RETURN_ON_FAIL(_getEntryPointResult(request, entryPointIndex, targetIndex, &compileResult)); - auto blob = result.getBlob(); + ComPtr blob; + SLANG_RETURN_ON_FAIL(compileResult->getBlob(blob)); *outBlob = blob.detach(); return SLANG_OK; } +SLANG_API SlangResult spGetEntryPointHostCallable( + SlangCompileRequest* request, + int entryPointIndex, + int targetIndex, + ISlangSharedLibrary** outSharedLibrary) +{ + using namespace Slang; + if (!outSharedLibrary) return SLANG_ERROR_INVALID_PARAMETER; + + Slang::CompileResult* compileResult = nullptr; + SLANG_RETURN_ON_FAIL(_getEntryPointResult(request, entryPointIndex, targetIndex, &compileResult)); + + ComPtr sharedLibrary; + SLANG_RETURN_ON_FAIL(compileResult->getSharedLibrary(sharedLibrary)); + *outSharedLibrary = sharedLibrary.detach(); + return SLANG_OK; +} + SLANG_API char const* spGetEntryPointSource( SlangCompileRequest* request, int entryPointIndex) -- cgit v1.2.3