diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-11-06 14:28:25 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-06 14:28:25 -0500 |
| commit | 1185bd464092f372430cbfaa15a7be4dcaa90752 (patch) | |
| tree | b3b68f2d9de00c0845f4912a797f10b27741031f /source/slang/dxc-support.cpp | |
| parent | 453331951b0df2a612f9bc0d68eab2ad786ec5bf (diff) | |
Feature/shared library refactor (#712)
* * Added ISlangSharedLibraryLoader and ISlangSharedLibrary
* Implemented default implementations
* Added slang API function to get/set the ISlangSharedLibraryLoader on the session
* Put function caching onto the Session - so that if the loader is chaged, its easy to reset the shared libraries, and functions
* Run premake.
* Fix problem with setting null, would cause an unnecessary function/shared lib flush.
* * Unload SharedLibrary when DefaultSharedLibrary is deleted.
* Make SharedLibrary handle unload safely if already unloaded.
* Refactor SharedLibrary, such that it becomes a utility class - simplifying it's semantics.
* Simplified ISlangSharedLibrary such that doesn't have unload and isLoaded so easier to implement.
Use updated SharedLibrary impl.
* Disable aarch64 on windows
* Premake windows files without aarch64 build.
* Moved slang-shared-library to core (so can be used in code outside of main slang)
Fixed problem in premake5 where on windows projects were incorrectly constructed
* Allowed RefObject to base class of com types
Added ConfigurableSharedLibraryLoader
Added -dxc-path -fxc-path -glslang-path
Fix problem with dxc-path not honoring it's path when loading dxil
* Added documentation for command line control of dll loading paths.
* Remove some tabbing issues.
* Change name of include guard.
Diffstat (limited to 'source/slang/dxc-support.cpp')
| -rw-r--r-- | source/slang/dxc-support.cpp | 98 |
1 files changed, 22 insertions, 76 deletions
diff --git a/source/slang/dxc-support.cpp b/source/slang/dxc-support.cpp index 0478eef25..152710534 100644 --- a/source/slang/dxc-support.cpp +++ b/source/slang/dxc-support.cpp @@ -33,47 +33,23 @@ namespace Slang EntryPointRequest* entryPoint, TargetRequest* targetReq); - SharedLibrary loadDXCSharedLibrary(CompileRequest* request) - { - // TODO(tfoley): Let user specify name/path of library to use. - char const* libraryName = "dxcompiler"; - - SharedLibrary library = SharedLibrary::load(libraryName); - if (!library) - { - request->mSink.diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, libraryName); - } - return library; - } - - SharedLibrary getDXCSharedLibrary(CompileRequest* request) - { - static SharedLibrary library = loadDXCSharedLibrary(request); - return library; - } - int emitDXILForEntryPointUsingDXC( EntryPointRequest* entryPoint, TargetRequest* targetReq, List<uint8_t>& outCode) { auto compileRequest = entryPoint->compileRequest; + auto session = compileRequest->mSession; // First deal with all the rigamarole of loading // the `dxcompiler` library, and creating the // top-level COM objects that will be used to // compile things. - static DxcCreateInstanceProc dxcCreateInstance = nullptr; + auto dxcCreateInstance = (DxcCreateInstanceProc)session->getSharedLibraryFunc(Session::SharedLibraryFuncType::Dxc_DxcCreateInstance, &compileRequest->mSink); if (!dxcCreateInstance) { - auto dxcSharedLibrary = getDXCSharedLibrary(compileRequest); - if (!dxcSharedLibrary) - return 1; - - dxcCreateInstance = (DxcCreateInstanceProc) dxcSharedLibrary.findFuncByName("DxcCreateInstance"); - if (!dxcCreateInstance) - return 1; + return 1; } IDxcCompiler* dxcCompiler = nullptr; @@ -262,75 +238,45 @@ namespace Slang return 0; } - String dissassembleDXILUsingDXC( + SlangResult dissassembleDXILUsingDXC( CompileRequest* compileRequest, void const* data, - size_t size) + size_t size, + String& stringOut) { + stringOut = String(); + auto session = compileRequest->mSession; + // First deal with all the rigamarole of loading // the `dxcompiler` library, and creating the // top-level COM objects that will be used to // compile things. - static DxcCreateInstanceProc dxcCreateInstance = nullptr; + auto dxcCreateInstance = (DxcCreateInstanceProc)session->getSharedLibraryFunc(Session::SharedLibraryFuncType::Dxc_DxcCreateInstance, &compileRequest->mSink); if (!dxcCreateInstance) { - auto dxcSharedLibrary = getDXCSharedLibrary(compileRequest); - if (!dxcSharedLibrary) - return 1; - - dxcCreateInstance = (DxcCreateInstanceProc) dxcSharedLibrary.findFuncByName("DxcCreateInstance"); - if (!dxcCreateInstance) - return 1; - } - - IDxcCompiler* dxcCompiler = nullptr; - if (FAILED(dxcCreateInstance( - CLSID_DxcCompiler, - __uuidof(dxcCompiler), - (LPVOID*) &dxcCompiler))) - { - return 1; - } - - IDxcLibrary* dxcLibrary = nullptr; - if (FAILED(dxcCreateInstance( - CLSID_DxcLibrary, - __uuidof(dxcLibrary), - (LPVOID*) &dxcLibrary))) - { - return 1; + return SLANG_FAIL; } + ComPtr<IDxcCompiler> dxcCompiler; + SLANG_RETURN_ON_FAIL(dxcCreateInstance(CLSID_DxcCompiler, __uuidof(dxcCompiler), (LPVOID*) dxcCompiler.writeRef())); + ComPtr<IDxcLibrary> dxcLibrary; + SLANG_RETURN_ON_FAIL(dxcCreateInstance(CLSID_DxcLibrary, __uuidof(dxcLibrary), (LPVOID*) dxcLibrary.writeRef())); + // Create blob from the input data - IDxcBlobEncoding* dxcSourceBlob = nullptr; - if (FAILED(dxcLibrary->CreateBlobWithEncodingFromPinned( - (LPBYTE) data, - (UINT32) size, - 0, - &dxcSourceBlob))) - { - return 1; - } + ComPtr<IDxcBlobEncoding> dxcSourceBlob; + SLANG_RETURN_ON_FAIL(dxcLibrary->CreateBlobWithEncodingFromPinned((LPBYTE) data, (UINT32) size, 0, dxcSourceBlob.writeRef())); - IDxcBlobEncoding* dxcResultBlob = nullptr; - if(FAILED(dxcCompiler->Disassemble( - dxcSourceBlob, - &dxcResultBlob))) - { - return 1; - } + ComPtr<IDxcBlobEncoding> dxcResultBlob; + SLANG_RETURN_ON_FAIL(dxcCompiler->Disassemble(dxcSourceBlob, dxcResultBlob.writeRef())); String result; char const* codeBegin = (char const*)dxcResultBlob->GetBufferPointer(); char const* codeEnd = codeBegin + dxcResultBlob->GetBufferSize() - 1; result.append(codeBegin, codeEnd); + stringOut = result; - if(dxcResultBlob) dxcResultBlob ->Release(); - if(dxcLibrary) dxcLibrary ->Release(); - if(dxcCompiler) dxcCompiler ->Release(); - - return result; + return SLANG_OK; } |
