diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-08-12 15:41:41 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-12 15:41:41 -0400 |
| commit | 6fc2c37d9a4c408331db1b33deb3b46e74d2a7d2 (patch) | |
| tree | d763d0f85b61f853f5877ab9ee28d3edaeef302c /source/slang/slang.cpp | |
| parent | a0416216ffaf3bd3b0533d967a6d62c477b22d09 (diff) | |
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'
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 61 |
1 files changed, 47 insertions, 14 deletions
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<ISlangBlob> 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<ISlangBlob> 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<ISlangSharedLibrary> sharedLibrary; + SLANG_RETURN_ON_FAIL(compileResult->getSharedLibrary(sharedLibrary)); + *outSharedLibrary = sharedLibrary.detach(); + return SLANG_OK; +} + SLANG_API char const* spGetEntryPointSource( SlangCompileRequest* request, int entryPointIndex) |
