yum-mirror/slang

Making it easier to work with shaders

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

Ellie HermaszewskaStable names and backwards compat for serialized IR modules (#7644)00746bf09

master
5.1 KiB119 linesraw
1#ifndef SLANG_SESSION_H
2#define SLANG_SESSION_H
3
4#include "../../core/slang-dictionary.h"
5#include "../../core/slang-smart-pointer.h"
6#include "../../slang/slang-compiler.h"
7#include "record-manager.h"
8#include "slang-com-helper.h"
9#include "slang-com-ptr.h"
10#include "slang-module.h"
11#include "slang.h"
12
13namespace SlangRecord
14{
15using namespace Slang;
16class SessionRecorder : public RefObject, public slang::ISession
17{
18public:
19    SLANG_REF_OBJECT_IUNKNOWN_ALL
20    ISlangUnknown* getInterface(const Guid& guid);
21
22    explicit SessionRecorder(slang::ISession* session, RecordManager* recordManager);
23
24    SLANG_NO_THROW slang::IGlobalSession* SLANG_MCALL getGlobalSession() override;
25    SLANG_NO_THROW slang::IModule* SLANG_MCALL
26    loadModule(const char* moduleName, slang::IBlob** outDiagnostics = nullptr) override;
27    SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModuleFromIRBlob(
28        const char* moduleName,
29        const char* path,
30        slang::IBlob* source,
31        slang::IBlob** outDiagnostics = nullptr) override;
32    SLANG_NO_THROW SlangResult SLANG_MCALL loadModuleInfoFromIRBlob(
33        slang::IBlob* source,
34        SlangInt& outModuleVersion,
35        const char*& outModuleCompilerVersion,
36        const char*& outModuleName) override;
37    SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModuleFromSource(
38        const char* moduleName,
39        const char* path,
40        slang::IBlob* source,
41        slang::IBlob** outDiagnostics = nullptr) override;
42    SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModuleFromSourceString(
43        const char* moduleName,
44        const char* path,
45        const char* string,
46        slang::IBlob** outDiagnostics = nullptr) override;
47    SLANG_NO_THROW SlangResult SLANG_MCALL createCompositeComponentType(
48        slang::IComponentType* const* componentTypes,
49        SlangInt componentTypeCount,
50        slang::IComponentType** outCompositeComponentType,
51        ISlangBlob** outDiagnostics = nullptr) override;
52    SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL specializeType(
53        slang::TypeReflection* type,
54        slang::SpecializationArg const* specializationArgs,
55        SlangInt specializationArgCount,
56        ISlangBlob** outDiagnostics = nullptr) override;
57    SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL getTypeLayout(
58        slang::TypeReflection* type,
59        SlangInt targetIndex = 0,
60        slang::LayoutRules rules = slang::LayoutRules::Default,
61        ISlangBlob** outDiagnostics = nullptr) override;
62    SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL getContainerType(
63        slang::TypeReflection* elementType,
64        slang::ContainerType containerType,
65        ISlangBlob** outDiagnostics = nullptr) override;
66    SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL getDynamicType() override;
67    SLANG_NO_THROW SlangResult SLANG_MCALL
68    getTypeRTTIMangledName(slang::TypeReflection* type, ISlangBlob** outNameBlob) override;
69    SLANG_NO_THROW SlangResult SLANG_MCALL getTypeConformanceWitnessMangledName(
70        slang::TypeReflection* type,
71        slang::TypeReflection* interfaceType,
72        ISlangBlob** outNameBlob) override;
73    SLANG_NO_THROW SlangResult SLANG_MCALL getTypeConformanceWitnessSequentialID(
74        slang::TypeReflection* type,
75        slang::TypeReflection* interfaceType,
76        uint32_t* outId) override;
77    SLANG_NO_THROW SlangResult SLANG_MCALL getDynamicObjectRTTIBytes(
78        slang::TypeReflection* type,
79        slang::TypeReflection* interfaceType,
80        uint32_t* outRTTIDataBuffer,
81        uint32_t bufferSizeInBytes) override;
82    SLANG_NO_THROW SlangResult SLANG_MCALL createTypeConformanceComponentType(
83        slang::TypeReflection* type,
84        slang::TypeReflection* interfaceType,
85        slang::ITypeConformance** outConformance,
86        SlangInt conformanceIdOverride,
87        ISlangBlob** outDiagnostics) override;
88    SLANG_NO_THROW SlangResult SLANG_MCALL
89    createCompileRequest(SlangCompileRequest** outCompileRequest) override;
90    SLANG_NO_THROW SlangInt SLANG_MCALL getLoadedModuleCount() override;
91    SLANG_NO_THROW slang::IModule* SLANG_MCALL getLoadedModule(SlangInt index) override;
92    SLANG_NO_THROW bool SLANG_MCALL
93    isBinaryModuleUpToDate(const char* modulePath, slang::IBlob* binaryModuleBlob) override;
94
95private:
96    SLANG_FORCE_INLINE slang::ISession* asExternal(SessionRecorder* session)
97    {
98        return static_cast<slang::ISession*>(session);
99    }
100
101    // The IComponentType object is the record target, therefore `componentTypes` will not be
102    // the actual component types, we have to use the COM interface to get the actual objects.
103    SlangResult getActualComponentTypes(
104        slang::IComponentType* const* componentTypes,
105        SlangInt componentTypeCount,
106        List<slang::IComponentType*>& outActualComponentTypes);
107
108    IModuleRecorder* getModuleRecorder(slang::IModule* module);
109
110    Slang::ComPtr<slang::ISession> m_actualSession;
111    uint64_t m_sessionHandle = 0;
112
113    Dictionary<slang::IModule*, IModuleRecorder*> m_mapModuleToRecord;
114    List<ComPtr<IModuleRecorder>> m_moduleRecordersAlloation;
115    RecordManager* m_recordManager = nullptr;
116};
117} // namespace SlangRecord
118
119#endif // SLANG_SESSION_H