yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeCache and reuse glsl module. (#6152)8000e0ede

master
5.6 KiB127 linesraw
1#ifndef SLANG_GLOBAL_SESSION_H
2#define SLANG_GLOBAL_SESSION_H
3
4#include "../../core/slang-smart-pointer.h"
5#include "record-manager.h"
6#include "slang-com-helper.h"
7#include "slang-com-ptr.h"
8#include "slang.h"
9
10namespace SlangRecord
11{
12using namespace Slang;
13
14class GlobalSessionRecorder : public RefObject, public slang::IGlobalSession
15{
16public:
17    explicit GlobalSessionRecorder(
18        const SlangGlobalSessionDesc* desc,
19        slang::IGlobalSession* session);
20
21    SLANG_REF_OBJECT_IUNKNOWN_ADD_REF
22    SLANG_REF_OBJECT_IUNKNOWN_RELEASE
23
24    SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject)
25        SLANG_OVERRIDE;
26
27    // slang::IGlobalSession
28    SLANG_NO_THROW SlangResult SLANG_MCALL
29    createSession(slang::SessionDesc const& desc, slang::ISession** outSession) override;
30    SLANG_NO_THROW SlangProfileID SLANG_MCALL findProfile(char const* name) override;
31    SLANG_NO_THROW void SLANG_MCALL
32    setDownstreamCompilerPath(SlangPassThrough passThrough, char const* path) override;
33    SLANG_NO_THROW void SLANG_MCALL
34    setDownstreamCompilerPrelude(SlangPassThrough inPassThrough, char const* prelude) override;
35    SLANG_NO_THROW void SLANG_MCALL
36    getDownstreamCompilerPrelude(SlangPassThrough inPassThrough, ISlangBlob** outPrelude) override;
37    SLANG_NO_THROW const char* SLANG_MCALL getBuildTagString() override;
38    SLANG_NO_THROW SlangResult SLANG_MCALL setDefaultDownstreamCompiler(
39        SlangSourceLanguage sourceLanguage,
40        SlangPassThrough defaultCompiler) override;
41    SLANG_NO_THROW SlangPassThrough SLANG_MCALL
42    getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage) override;
43
44    SLANG_NO_THROW void SLANG_MCALL
45    setLanguagePrelude(SlangSourceLanguage inSourceLanguage, char const* prelude) override;
46    SLANG_NO_THROW void SLANG_MCALL
47    getLanguagePrelude(SlangSourceLanguage inSourceLanguage, ISlangBlob** outPrelude) override;
48
49    SLANG_NO_THROW SlangResult SLANG_MCALL
50    createCompileRequest(slang::ICompileRequest** outCompileRequest) override;
51
52    SLANG_NO_THROW void SLANG_MCALL
53    addBuiltins(char const* sourcePath, char const* sourceString) override;
54    SLANG_NO_THROW void SLANG_MCALL
55    setSharedLibraryLoader(ISlangSharedLibraryLoader* loader) override;
56    SLANG_NO_THROW ISlangSharedLibraryLoader* SLANG_MCALL getSharedLibraryLoader() override;
57    SLANG_NO_THROW SlangResult SLANG_MCALL
58    checkCompileTargetSupport(SlangCompileTarget target) override;
59    SLANG_NO_THROW SlangResult SLANG_MCALL
60    checkPassThroughSupport(SlangPassThrough passThrough) override;
61
62    SLANG_NO_THROW SlangResult SLANG_MCALL
63    compileCoreModule(slang::CompileCoreModuleFlags flags) override;
64    SLANG_NO_THROW SlangResult SLANG_MCALL
65    loadCoreModule(const void* coreModule, size_t coreModuleSizeInBytes) override;
66    SLANG_NO_THROW SlangResult SLANG_MCALL
67    saveCoreModule(SlangArchiveType archiveType, ISlangBlob** outBlob) override;
68
69    virtual SLANG_NO_THROW SlangResult SLANG_MCALL compileBuiltinModule(
70        slang::BuiltinModuleName module,
71        slang::CompileCoreModuleFlags flags) override;
72    virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadBuiltinModule(
73        slang::BuiltinModuleName module,
74        const void* moduleData,
75        size_t sizeInBytes) override;
76    virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveBuiltinModule(
77        slang::BuiltinModuleName module,
78        SlangArchiveType archiveType,
79        ISlangBlob** outBlob) override;
80
81    SLANG_NO_THROW SlangCapabilityID SLANG_MCALL findCapability(char const* name) override;
82
83    SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerForTransition(
84        SlangCompileTarget source,
85        SlangCompileTarget target,
86        SlangPassThrough compiler) override;
87    SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDownstreamCompilerForTransition(
88        SlangCompileTarget source,
89        SlangCompileTarget target) override;
90    SLANG_NO_THROW void SLANG_MCALL
91    getCompilerElapsedTime(double* outTotalTime, double* outDownstreamTime) override;
92
93    SLANG_NO_THROW SlangResult SLANG_MCALL setSPIRVCoreGrammar(char const* jsonPath) override;
94
95    SLANG_NO_THROW SlangResult SLANG_MCALL parseCommandLineArguments(
96        int argc,
97        const char* const* argv,
98        slang::SessionDesc* outSessionDesc,
99        ISlangUnknown** outAllocation) override;
100
101    SLANG_NO_THROW SlangResult SLANG_MCALL
102    getSessionDescDigest(slang::SessionDesc* sessionDesc, ISlangBlob** outBlob) override;
103
104    RecordManager* getRecordManager() { return m_recordManager.get(); }
105
106private:
107    SLANG_FORCE_INLINE slang::IGlobalSession* asExternal(GlobalSessionRecorder* session)
108    {
109        return static_cast<slang::IGlobalSession*>(session);
110    }
111
112    Slang::ComPtr<slang::IGlobalSession> m_actualGlobalSession;
113
114    // we will create one record file per IGlobalSession.
115    // We don't try to reproduce the user application's threading model, because it requires lots of
116    // effort and it's not necessary. Instead, we record all the compilation jobs associated with
117    // the session in the same record file, so that during replay, those jobs will be executed
118    // sequentially. This might violate the user application's threading model, because those jobs
119    // might be executed in different threads. But it's not a big problem, because slang doesn't
120    // allow multiple threads to access the same session at the same time. So even if there is one
121    // session used by multiple threads, those threads will execute the compile jobs sequentially.
122    Slang::RefPtr<RecordManager> m_recordManager;
123    uint64_t m_globalSessionHandle = 0;
124};
125} // namespace SlangRecord
126
127#endif