From ddf4a323be5ae4e59dce742f618dbbdee4ed28d8 Mon Sep 17 00:00:00 2001 From: cheneym2 Date: Fri, 30 Aug 2024 02:23:26 -0400 Subject: Support mixture of precompiled and non-precompiled modules (#4860) * Support mixture of precompiled and non-precompiled modules This changes the implementation of precompile DXIL modules to accept combinations of modules with precompiled DXIL, ones without, and ones with a mixture of precompiled DXIL and Slang IR. During precompilation, module IR is analyzed to find public functions which appear to be capable of being compiled as HLSL, and those functions are given a HLSLExport decoration, ensuring they are emitted as HLSL and preserved in the precompiled DXIL blob. The IR for those functions is then tagged with a new decoration AvailableInDXIL, which marks that their implementation is present in the embedded DXIL blob. The DXIL blob is attached to the IR as before, inside a EmbeddedDXIL BlobLit instruction. The logic that determines whether or not functions should be precompiled to DXIL is a placeholder at this point, returning true always. A subsequent change will add selection criteria. During module linking, the full module IR is available, as well as the optional EmbeddedDXIL blob. The IR for functions implemented by the blob are tagged with AvailableInDXIL in the module IR. After linking the IR for all modules to program level IR, the IR for the functions marked AvailableInDXIL are deleted from the linked IR, prior to emitting HLSL and compiling linking the result. This change also changes the point of time when the module IR is checked for EmbeddedDXIL blobs. Instead of happening at load time as before, it happens during immediately before final linking, meaning that the blob does not need to be independently stored with the module separate from the IR as was done previously. Work on #4792 * Clean up debug prints * Call isSimpleHLSLDataType stub * Address feedback on precompiled dxil support Allow for IR filtering both before and after linking. Only mark AvailableInDXIL those functions which pass both filtering stages. Functions are corrlated using mangled function names. Rather than delete functions entirely when linking with libraries that include precompiled DXIL, instead convert the IR function definitions to declarations by gutting them, removing child blocks. * Use artifact metadata and name list instead of linkedir hack * Use String instead of UnownedStringSlice * Update tests * Renaming * Minor edits * Don't fully remove functions post-link * Unexport before collecting metadata --- source/slang/slang-module-library.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'source/slang/slang-module-library.cpp') diff --git a/source/slang/slang-module-library.cpp b/source/slang/slang-module-library.cpp index 42b9ff77a..02ace07d3 100644 --- a/source/slang/slang-module-library.cpp +++ b/source/slang/slang-module-library.cpp @@ -83,15 +83,6 @@ SlangResult loadModuleLibrary(const Byte* inBytes, size_t bytesCount, String pat module, &sink); if (!loadedModule) return SLANG_FAIL; - - for (auto inst : module.irModule->getModuleInst()->getChildren()) - { - if (inst->getOp() == kIROp_EmbeddedDXIL) - { - auto slice = static_cast(inst->getOperand(0))->getStringSlice(); - module.irModule->precompiledDXIL = StringBlob::create(slice); - } - } library->m_modules.add(loadedModule); } } -- cgit v1.2.3