yum-mirror/slang

Making it easier to work with shaders

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

jarcherNVFix API changes from separate debugging support (#7397)9c8fab83a

master
7.3 KiB211 linesraw
1#ifndef SLANG_MODULE_H
2#define SLANG_MODULE_H
3
4#include "../../core/slang-smart-pointer.h"
5#include "../../slang/slang-compiler.h"
6#include "record-manager.h"
7#include "slang-com-helper.h"
8#include "slang-com-ptr.h"
9#include "slang-entrypoint.h"
10#include "slang.h"
11
12namespace SlangRecord
13{
14using namespace Slang;
15class SessionRecorder;
16
17class IModuleRecorder : public slang::IModule, public RefObject
18{
19public:
20    SLANG_COM_INTERFACE(
21        0xb1802991,
22        0x185a,
23        0x4a03,
24        {0xa7, 0x7e, 0x0c, 0x86, 0xe0, 0x68, 0x2a, 0xab})
25};
26
27class ModuleRecorder : public IModuleRecorder, public IComponentTypeRecorder
28{
29    typedef IComponentTypeRecorder Super;
30
31public:
32    SLANG_REF_OBJECT_IUNKNOWN_ALL
33    ISlangUnknown* getInterface(const Guid& guid);
34
35    explicit ModuleRecorder(
36        SessionRecorder* sessionRecorder,
37        slang::IModule* module,
38        RecordManager* recordManager);
39
40    // Interfaces for `IModule`
41    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
42    findEntryPointByName(char const* name, slang::IEntryPoint** outEntryPoint) override;
43    virtual SLANG_NO_THROW SlangInt32 SLANG_MCALL getDefinedEntryPointCount() override;
44    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
45    getDefinedEntryPoint(SlangInt32 index, slang::IEntryPoint** outEntryPoint) override;
46    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
47    serialize(ISlangBlob** outSerializedBlob) override;
48    virtual SLANG_NO_THROW SlangResult SLANG_MCALL writeToFile(char const* fileName) override;
49    virtual SLANG_NO_THROW const char* SLANG_MCALL getName() override;
50    virtual SLANG_NO_THROW const char* SLANG_MCALL getFilePath() override;
51    virtual SLANG_NO_THROW const char* SLANG_MCALL getUniqueIdentity() override;
52    virtual SLANG_NO_THROW SlangResult SLANG_MCALL findAndCheckEntryPoint(
53        char const* name,
54        SlangStage stage,
55        slang::IEntryPoint** outEntryPoint,
56        ISlangBlob** outDiagnostics) override;
57    virtual SLANG_NO_THROW SlangInt32 SLANG_MCALL getDependencyFileCount() override;
58    virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath(SlangInt32 index) override;
59    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
60    disassemble(slang::IBlob** outDisassembly) override;
61
62    // Interfaces for `IComponentType`
63    virtual SLANG_NO_THROW slang::ISession* SLANG_MCALL getSession() override
64    {
65        return Super::getSession();
66    }
67
68    virtual SLANG_NO_THROW slang::ProgramLayout* SLANG_MCALL
69    getLayout(SlangInt targetIndex = 0, slang::IBlob** outDiagnostics = nullptr) override
70    {
71        return Super::getLayout(targetIndex, outDiagnostics);
72    }
73
74    virtual SLANG_NO_THROW SlangInt SLANG_MCALL getSpecializationParamCount() override
75    {
76        return Super::getSpecializationParamCount();
77    }
78
79    virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCode(
80        SlangInt entryPointIndex,
81        SlangInt targetIndex,
82        slang::IBlob** outCode,
83        slang::IBlob** outDiagnostics = nullptr) override
84    {
85        return Super::getEntryPointCode(entryPointIndex, targetIndex, outCode, outDiagnostics);
86    }
87
88    virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCode(
89        SlangInt targetIndex,
90        slang::IBlob** outCode,
91        slang::IBlob** outDiagnostics = nullptr) override
92    {
93        return Super::getTargetCode(targetIndex, outCode, outDiagnostics);
94    }
95
96    SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointMetadata(
97        SlangInt entryPointIndex,
98        SlangInt targetIndex,
99        slang::IMetadata** outMetadata,
100        slang::IBlob** outDiagnostics) SLANG_OVERRIDE
101    {
102        return Super::getEntryPointMetadata(
103            entryPointIndex,
104            targetIndex,
105            outMetadata,
106            outDiagnostics);
107    }
108
109    SLANG_NO_THROW SlangResult SLANG_MCALL getTargetMetadata(
110        SlangInt targetIndex,
111        slang::IMetadata** outMetadata,
112        slang::IBlob** outDiagnostics) SLANG_OVERRIDE
113    {
114        return Super::getTargetMetadata(targetIndex, outMetadata, outDiagnostics);
115    }
116
117    virtual SLANG_NO_THROW SlangResult SLANG_MCALL getResultAsFileSystem(
118        SlangInt entryPointIndex,
119        SlangInt targetIndex,
120        ISlangMutableFileSystem** outFileSystem) override
121    {
122        return Super::getResultAsFileSystem(entryPointIndex, targetIndex, outFileSystem);
123    }
124
125    virtual SLANG_NO_THROW void SLANG_MCALL getEntryPointHash(
126        SlangInt entryPointIndex,
127        SlangInt targetIndex,
128        slang::IBlob** outHash) override
129    {
130        return Super::getEntryPointHash(entryPointIndex, targetIndex, outHash);
131    }
132
133    virtual SLANG_NO_THROW SlangResult SLANG_MCALL specialize(
134        slang::SpecializationArg const* specializationArgs,
135        SlangInt specializationArgCount,
136        slang::IComponentType** outSpecializedComponentType,
137        ISlangBlob** outDiagnostics = nullptr) override
138    {
139        return Super::specialize(
140            specializationArgs,
141            specializationArgCount,
142            outSpecializedComponentType,
143            outDiagnostics);
144    }
145
146    virtual SLANG_NO_THROW SlangResult SLANG_MCALL link(
147        slang::IComponentType** outLinkedComponentType,
148        ISlangBlob** outDiagnostics = nullptr) override
149    {
150        return Super::link(outLinkedComponentType, outDiagnostics);
151    }
152
153    virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointHostCallable(
154        int entryPointIndex,
155        int targetIndex,
156        ISlangSharedLibrary** outSharedLibrary,
157        slang::IBlob** outDiagnostics = 0) override
158    {
159        return Super::getEntryPointHostCallable(
160            entryPointIndex,
161            targetIndex,
162            outSharedLibrary,
163            outDiagnostics);
164    }
165
166    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
167    renameEntryPoint(const char* newName, IComponentType** outEntryPoint) override
168    {
169        return Super::renameEntryPoint(newName, outEntryPoint);
170    }
171
172    virtual SLANG_NO_THROW SlangResult SLANG_MCALL linkWithOptions(
173        IComponentType** outLinkedComponentType,
174        uint32_t compilerOptionEntryCount,
175        slang::CompilerOptionEntry* compilerOptionEntries,
176        ISlangBlob** outDiagnostics = nullptr) override
177    {
178        return Super::linkWithOptions(
179            outLinkedComponentType,
180            compilerOptionEntryCount,
181            compilerOptionEntries,
182            outDiagnostics);
183    }
184
185    virtual SLANG_NO_THROW slang::DeclReflection* SLANG_MCALL getModuleReflection() override;
186
187    slang::IModule* getActualModule() const { return m_actualModule; }
188
189protected:
190    // `IComponentTypeRecorder` interface
191    virtual ApiClassId getClassId() override { return ApiClassId::Class_IModule; }
192
193    virtual SessionRecorder* getSessionRecorder() override { return m_sessionRecorder; }
194
195private:
196    IEntryPointRecorder* getEntryPointRecorder(slang::IEntryPoint* entryPoint);
197
198    SessionRecorder* m_sessionRecorder;
199    Slang::ComPtr<slang::IModule> m_actualModule;
200    uint64_t m_moduleHandle = 0;
201    RecordManager* m_recordManager = nullptr;
202
203    // `IEntryPoint` can only be created from 'IModule', so we need to record it in
204    // this class, and create a map such that we don't create new `EntryPointRecorder`
205    // for the same `IEntryPoint`.
206    Dictionary<slang::IEntryPoint*, IEntryPointRecorder*> m_mapEntryPointToRecord;
207    List<ComPtr<IEntryPointRecorder>> m_entryPointsRecordAllocation;
208};
209} // namespace SlangRecord
210
211#endif // SLANG_MODULE_H