From 1185bd464092f372430cbfaa15a7be4dcaa90752 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 6 Nov 2018 14:28:25 -0500 Subject: 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. --- source/slang/dxc-support.cpp | 98 ++++++++++---------------------------------- 1 file changed, 22 insertions(+), 76 deletions(-) (limited to 'source/slang/dxc-support.cpp') 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& 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 dxcCompiler; + SLANG_RETURN_ON_FAIL(dxcCreateInstance(CLSID_DxcCompiler, __uuidof(dxcCompiler), (LPVOID*) dxcCompiler.writeRef())); + ComPtr 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 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 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; } -- cgit v1.2.3