yum-mirror/slang

Making it easier to work with shaders

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

jarcherNVAdd record and replay support for IComponentType2 (#8215)a5e6ddd00

master
22.2 KiB619 linesraw
1#ifndef JSON_CONSUMER_H
2#define JSON_CONSUMER_H
3
4#include "../../core/slang-stream.h"
5#include "../util/record-format.h"
6#include "../util/record-utility.h"
7#include "decoder-consumer.h"
8
9namespace SlangRecord
10{
11class CommonInterfaceWriter
12{
13public:
14    CommonInterfaceWriter(ApiClassId classId, Slang::FileStream& fileStream)
15        : m_fileStream(fileStream)
16    {
17        switch (classId)
18        {
19        case ApiClassId::Class_IModule:
20            m_className = "IModule";
21            break;
22        case ApiClassId::Class_IEntryPoint:
23            m_className = "IEntryPoint";
24            break;
25        case ApiClassId::Class_ICompositeComponentType:
26            m_className = "ICompositeComponentType";
27            break;
28        case ApiClassId::Class_ITypeConformance:
29            m_className = "ITypeConformance";
30            break;
31        case ApiClassId::Class_IComponentType2:
32            m_className = "IComponentType2";
33            break;
34        default:
35            slangRecordLog(LogLevel::Error, "Invalid classNo %u\n", classId);
36            break;
37        }
38    }
39    CommonInterfaceWriter() = delete;
40    void getSession(ObjectID objectId, ObjectID outSessionId);
41    void getLayout(
42        ObjectID objectId,
43        SlangInt targetIndex,
44        ObjectID outDiagnosticsId,
45        ObjectID retProgramLayoutId);
46    void getEntryPointCode(
47        ObjectID objectId,
48        SlangInt entryPointIndex,
49        SlangInt targetIndex,
50        ObjectID outCodeId,
51        ObjectID outDiagnosticsId);
52    void getTargetCode(
53        ObjectID objectId,
54        SlangInt targetIndex,
55        ObjectID outCodeId,
56        ObjectID outDiagnosticsId);
57    void getResultAsFileSystem(
58        ObjectID objectId,
59        SlangInt entryPointIndex,
60        SlangInt targetIndex,
61        ObjectID outFileSystemId);
62    void getEntryPointHash(
63        ObjectID objectId,
64        SlangInt entryPointIndex,
65        SlangInt targetIndex,
66        ObjectID outHashId);
67    void specialize(
68        ObjectID objectId,
69        slang::SpecializationArg const* specializationArgs,
70        SlangInt specializationArgCount,
71        ObjectID outSpecializedComponentTypeId,
72        ObjectID outDiagnosticsId);
73    void link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId);
74    void getEntryPointHostCallable(
75        ObjectID objectId,
76        int entryPointIndex,
77        int targetIndex,
78        ObjectID outSharedLibraryId,
79        ObjectID outDiagnosticsId);
80    void renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId);
81    void linkWithOptions(
82        ObjectID objectId,
83        ObjectID outLinkedComponentTypeId,
84        uint32_t compilerOptionEntryCount,
85        slang::CompilerOptionEntry* compilerOptionEntries,
86        ObjectID outDiagnosticsId);
87
88    void queryInterface(ObjectID objectId, const SlangUUID& guid, ObjectID outInterfaceId);
89
90    // IComponentType2 methods.
91    void getTargetCompileResult(
92        ObjectID objectId,
93        SlangInt targetIndex,
94        ObjectID outCompileResultId,
95        ObjectID outDiagnosticsId);
96    void getEntryPointCompileResult(
97        ObjectID objectId,
98        SlangInt entryPointIndex,
99        SlangInt targetIndex,
100        ObjectID outCompileResultId,
101        ObjectID outDiagnosticsId);
102
103protected:
104    Slang::String m_className;
105    Slang::FileStream& m_fileStream;
106};
107
108class JsonConsumer : public IDecoderConsumer, public Slang::RefObject
109{
110public:
111    JsonConsumer(const Slang::String& filePath);
112    virtual ~JsonConsumer() = default;
113    virtual void CreateGlobalSession(
114        SlangGlobalSessionDesc const& desc,
115        ObjectID outGlobalSessionId) override;
116    virtual void IGlobalSession_createSession(
117        ObjectID objectId,
118        slang::SessionDesc const& desc,
119        ObjectID outSessionId) override;
120    virtual void IGlobalSession_findProfile(ObjectID objectId, char const* name) override;
121    virtual void IGlobalSession_setDownstreamCompilerPath(
122        ObjectID objectId,
123        SlangPassThrough passThrough,
124        char const* path) override;
125    virtual void IGlobalSession_setDownstreamCompilerPrelude(
126        ObjectID objectId,
127        SlangPassThrough inPassThrough,
128        char const* prelude) override;
129    virtual void IGlobalSession_getDownstreamCompilerPrelude(
130        ObjectID objectId,
131        SlangPassThrough inPassThrough,
132        ObjectID outPreludeId) override;
133
134    virtual void IGlobalSession_getBuildTagString(ObjectID objectId) override { (void)objectId; }
135
136    virtual void IGlobalSession_setDefaultDownstreamCompiler(
137        ObjectID objectId,
138        SlangSourceLanguage sourceLanguage,
139        SlangPassThrough defaultCompiler) override;
140    virtual void IGlobalSession_getDefaultDownstreamCompiler(
141        ObjectID objectId,
142        SlangSourceLanguage sourceLanguage) override;
143    virtual void IGlobalSession_setLanguagePrelude(
144        ObjectID objectId,
145        SlangSourceLanguage inSourceLanguage,
146        char const* prelude) override;
147    virtual void IGlobalSession_getLanguagePrelude(
148        ObjectID objectId,
149        SlangSourceLanguage inSourceLanguage,
150        ObjectID outPreludeId) override;
151    virtual void IGlobalSession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequest)
152        override;
153    virtual void IGlobalSession_addBuiltins(
154        ObjectID objectId,
155        char const* sourcePath,
156        char const* sourceString) override;
157    virtual void IGlobalSession_setSharedLibraryLoader(ObjectID objectId, ObjectID loaderId)
158        override;
159    virtual void IGlobalSession_getSharedLibraryLoader(ObjectID objectId, ObjectID outLoaderId)
160        override;
161    virtual void IGlobalSession_checkCompileTargetSupport(
162        ObjectID objectId,
163        SlangCompileTarget target) override;
164    virtual void IGlobalSession_checkPassThroughSupport(
165        ObjectID objectId,
166        SlangPassThrough passThrough) override;
167    virtual void IGlobalSession_compileCoreModule(
168        ObjectID objectId,
169        slang::CompileCoreModuleFlags flags) override;
170    virtual void IGlobalSession_loadCoreModule(
171        ObjectID objectId,
172        const void* coreModule,
173        size_t coreModuleSizeInBytes) override;
174    virtual void IGlobalSession_saveCoreModule(
175        ObjectID objectId,
176        SlangArchiveType archiveType,
177        ObjectID outBlobId) override;
178    virtual void IGlobalSession_findCapability(ObjectID objectId, char const* name) override;
179    virtual void IGlobalSession_setDownstreamCompilerForTransition(
180        ObjectID objectId,
181        SlangCompileTarget source,
182        SlangCompileTarget target,
183        SlangPassThrough compiler) override;
184    virtual void IGlobalSession_getDownstreamCompilerForTransition(
185        ObjectID objectId,
186        SlangCompileTarget source,
187        SlangCompileTarget target) override;
188
189    virtual void IGlobalSession_getCompilerElapsedTime(ObjectID objectId) override
190    {
191        (void)objectId;
192    }
193
194    virtual void IGlobalSession_setSPIRVCoreGrammar(ObjectID objectId, char const* jsonPath)
195        override;
196    virtual void IGlobalSession_parseCommandLineArguments(
197        ObjectID objectId,
198        int argc,
199        const char* const* argv,
200        ObjectID outSessionDescId,
201        ObjectID outAllocationId) override;
202    virtual void IGlobalSession_getSessionDescDigest(
203        ObjectID objectId,
204        slang::SessionDesc* sessionDesc,
205        ObjectID outBlobId) override;
206
207    // ISession
208    virtual void ISession_getGlobalSession(ObjectID objectId, ObjectID outGlobalSessionId) override;
209    virtual void ISession_loadModule(
210        ObjectID objectId,
211        const char* moduleName,
212        ObjectID outDiagnostics,
213        ObjectID outModuleId) override;
214
215    virtual void ISession_loadModuleFromIRBlob(
216        ObjectID objectId,
217        const char* moduleName,
218        const char* path,
219        slang::IBlob* source,
220        ObjectID outDiagnosticsId,
221        ObjectID outModuleId) override;
222    virtual void ISession_loadModuleFromSource(
223        ObjectID objectId,
224        const char* moduleName,
225        const char* path,
226        slang::IBlob* source,
227        ObjectID outDiagnosticsId,
228        ObjectID outModuleId) override;
229    virtual void ISession_loadModuleFromSourceString(
230        ObjectID objectId,
231        const char* moduleName,
232        const char* path,
233        const char* string,
234        ObjectID outDiagnosticsId,
235        ObjectID outModuleId) override;
236    virtual void ISession_createCompositeComponentType(
237        ObjectID objectId,
238        ObjectID* componentTypeIds,
239        SlangInt componentTypeCount,
240        ObjectID outCompositeComponentTypeIds,
241        ObjectID outDiagnosticsId) override;
242
243    virtual void ISession_specializeType(
244        ObjectID objectId,
245        ObjectID typeId,
246        slang::SpecializationArg const* specializationArgs,
247        SlangInt specializationArgCount,
248        ObjectID outDiagnosticsId,
249        ObjectID outTypeReflectionId) override;
250
251    virtual void ISession_getTypeLayout(
252        ObjectID objectId,
253        ObjectID typeId,
254        SlangInt targetIndex,
255        slang::LayoutRules rules,
256        ObjectID outDiagnosticsId,
257        ObjectID outTypeLayoutReflection) override;
258
259    virtual void ISession_getContainerType(
260        ObjectID objectId,
261        ObjectID elementType,
262        slang::ContainerType containerType,
263        ObjectID outDiagnosticsId,
264        ObjectID outTypeReflectionId) override;
265
266    virtual void ISession_getDynamicType(ObjectID objectId, ObjectID outTypeReflectionId) override;
267
268    virtual void ISession_getTypeRTTIMangledName(
269        ObjectID objectId,
270        ObjectID typeId,
271        ObjectID outNameBlobId) override;
272
273    virtual void ISession_getTypeConformanceWitnessMangledName(
274        ObjectID objectId,
275        ObjectID typeId,
276        ObjectID interfaceTypeId,
277        ObjectID outNameBlobId) override;
278
279    virtual void ISession_getTypeConformanceWitnessSequentialID(
280        ObjectID objectId,
281        ObjectID typeId,
282        ObjectID interfaceTypeId,
283        uint32_t outId) override;
284
285    virtual void ISession_createTypeConformanceComponentType(
286        ObjectID objectId,
287        ObjectID typeId,
288        ObjectID interfaceTypeId,
289        ObjectID outConformanceId,
290        SlangInt conformanceIdOverride,
291        ObjectID outDiagnosticsId) override;
292
293    virtual void ISession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequestId)
294        override;
295
296    virtual void ISession_getLoadedModuleCount(ObjectID objectId) override { (void)objectId; }
297
298    virtual void ISession_getLoadedModule(ObjectID objectId, SlangInt index, ObjectID outModuleId)
299        override;
300
301    virtual void ISession_isBinaryModuleUpToDate(ObjectID objectId) override { (void)objectId; }
302
303    // IModule
304    virtual void IModule_findEntryPointByName(
305        ObjectID objectId,
306        char const* name,
307        ObjectID outEntryPointId) override;
308
309    virtual void IModule_getDefinedEntryPointCount(ObjectID objectId) override { (void)objectId; }
310
311    virtual void IModule_getDefinedEntryPoint(
312        ObjectID objectId,
313        SlangInt32 index,
314        ObjectID outEntryPointId) override;
315    virtual void IModule_serialize(ObjectID objectId, ObjectID outSerializedBlobId) override;
316    virtual void IModule_writeToFile(ObjectID objectId, char const* fileName) override;
317
318    virtual void IModule_getName(ObjectID objectId) override { (void)objectId; }
319    virtual void IModule_getFilePath(ObjectID objectId) override { (void)objectId; }
320    virtual void IModule_getUniqueIdentity(ObjectID objectId) override { (void)objectId; }
321
322    virtual void IModule_findAndCheckEntryPoint(
323        ObjectID objectId,
324        char const* name,
325        SlangStage stage,
326        ObjectID outEntryPointId,
327        ObjectID outDiagnostics) override;
328
329    virtual void IModule_getSession(ObjectID objectId, ObjectID outSessionId) override;
330    virtual void IModule_getLayout(
331        ObjectID objectId,
332        SlangInt targetIndex,
333        ObjectID outDiagnosticsId,
334        ObjectID retProgramLayoutId) override;
335
336    virtual void IModule_getSpecializationParamCount(ObjectID objectId) override { (void)objectId; }
337
338    virtual void IModule_getEntryPointCode(
339        ObjectID objectId,
340        SlangInt entryPointIndex,
341        SlangInt targetIndex,
342        ObjectID outCodeId,
343        ObjectID outDiagnosticsId) override;
344    virtual void IModule_getTargetCode(
345        ObjectID objectId,
346        SlangInt targetIndex,
347        ObjectID outCodeId,
348        ObjectID outDiagnosticsId) override;
349    virtual void IModule_getResultAsFileSystem(
350        ObjectID objectId,
351        SlangInt entryPointIndex,
352        SlangInt targetIndex,
353        ObjectID outFileSystem) override;
354    virtual void IModule_getEntryPointHash(
355        ObjectID objectId,
356        SlangInt entryPointIndex,
357        SlangInt targetIndex,
358        ObjectID outHashId) override;
359    virtual void IModule_specialize(
360        ObjectID objectId,
361        slang::SpecializationArg const* specializationArgs,
362        SlangInt specializationArgCount,
363        ObjectID outSpecializedComponentTypeId,
364        ObjectID outDiagnosticsId) override;
365    virtual void IModule_link(
366        ObjectID objectId,
367        ObjectID outLinkedComponentTypeId,
368        ObjectID outDiagnosticsId) override;
369    virtual void IModule_getEntryPointHostCallable(
370        ObjectID objectId,
371        int entryPointIndex,
372        int targetIndex,
373        ObjectID outSharedLibrary,
374        ObjectID outDiagnostics) override;
375    virtual void IModule_renameEntryPoint(
376        ObjectID objectId,
377        const char* newName,
378        ObjectID outEntryPointId) override;
379    virtual void IModule_linkWithOptions(
380        ObjectID objectId,
381        ObjectID outLinkedComponentTypeId,
382        uint32_t compilerOptionEntryCount,
383        slang::CompilerOptionEntry* compilerOptionEntries,
384        ObjectID outDiagnosticsId) override;
385
386    // IEntryPoint
387    virtual void IEntryPoint_getSession(ObjectID objectId, ObjectID outSessionId) override;
388    virtual void IEntryPoint_getLayout(
389        ObjectID objectId,
390        SlangInt targetIndex,
391        ObjectID outDiagnosticsId,
392        ObjectID retProgramLayoutId) override;
393
394    virtual void IEntryPoint_getSpecializationParamCount(ObjectID objectId) override
395    {
396        (void)objectId;
397    }
398
399    virtual void IEntryPoint_getEntryPointCode(
400        ObjectID objectId,
401        SlangInt entryPointIndex,
402        SlangInt targetIndex,
403        ObjectID outCodeId,
404        ObjectID outDiagnosticsId) override;
405    virtual void IEntryPoint_getTargetCode(
406        ObjectID objectId,
407        SlangInt targetIndex,
408        ObjectID outCodeId,
409        ObjectID outDiagnosticsId) override;
410    virtual void IEntryPoint_getResultAsFileSystem(
411        ObjectID objectId,
412        SlangInt entryPointIndex,
413        SlangInt targetIndex,
414        ObjectID outFileSystem) override;
415    virtual void IEntryPoint_getEntryPointHash(
416        ObjectID objectId,
417        SlangInt entryPointIndex,
418        SlangInt targetIndex,
419        ObjectID outHashId) override;
420    virtual void IEntryPoint_specialize(
421        ObjectID objectId,
422        slang::SpecializationArg const* specializationArgs,
423        SlangInt specializationArgCount,
424        ObjectID outSpecializedComponentTypeId,
425        ObjectID outDiagnosticsId) override;
426    virtual void IEntryPoint_link(
427        ObjectID objectId,
428        ObjectID outLinkedComponentTypeId,
429        ObjectID outDiagnosticsId) override;
430    virtual void IEntryPoint_getEntryPointHostCallable(
431        ObjectID objectId,
432        int entryPointIndex,
433        int targetIndex,
434        ObjectID outSharedLibrary,
435        ObjectID outDiagnostics) override;
436    virtual void IEntryPoint_renameEntryPoint(
437        ObjectID objectId,
438        const char* newName,
439        ObjectID outEntryPointId) override;
440    virtual void IEntryPoint_linkWithOptions(
441        ObjectID objectId,
442        ObjectID outLinkedComponentTypeId,
443        uint32_t compilerOptionEntryCount,
444        slang::CompilerOptionEntry* compilerOptionEntries,
445        ObjectID outDiagnosticsId) override;
446
447    // ICompositeComponentType
448    virtual void ICompositeComponentType_getSession(ObjectID objectId, ObjectID outSessionId)
449        override;
450    virtual void ICompositeComponentType_getLayout(
451        ObjectID objectId,
452        SlangInt targetIndex,
453        ObjectID outDiagnosticsId,
454        ObjectID retProgramLayoutId) override;
455
456    virtual void ICompositeComponentType_getSpecializationParamCount(ObjectID objectId) override
457    {
458        (void)objectId;
459    }
460
461    virtual void ICompositeComponentType_getEntryPointCode(
462        ObjectID objectId,
463        SlangInt entryPointIndex,
464        SlangInt targetIndex,
465        ObjectID outCodeId,
466        ObjectID outDiagnostics) override;
467    virtual void ICompositeComponentType_getTargetCode(
468        ObjectID objectId,
469        SlangInt targetIndex,
470        ObjectID outCodeId,
471        ObjectID outDiagnostics) override;
472    virtual void ICompositeComponentType_getResultAsFileSystem(
473        ObjectID objectId,
474        SlangInt entryPointIndex,
475        SlangInt targetIndex,
476        ObjectID outFileSystem) override;
477    virtual void ICompositeComponentType_getEntryPointHash(
478        ObjectID objectId,
479        SlangInt entryPointIndex,
480        SlangInt targetIndex,
481        ObjectID outHashId) override;
482    virtual void ICompositeComponentType_specialize(
483        ObjectID objectId,
484        slang::SpecializationArg const* specializationArgs,
485        SlangInt specializationArgCount,
486        ObjectID outSpecializedComponentTypeId,
487        ObjectID outDiagnosticsId) override;
488    virtual void ICompositeComponentType_link(
489        ObjectID objectId,
490        ObjectID outLinkedComponentTypeId,
491        ObjectID outDiagnosticsId) override;
492    virtual void ICompositeComponentType_getEntryPointHostCallable(
493        ObjectID objectId,
494        int entryPointIndex,
495        int targetIndex,
496        ObjectID outSharedLibrary,
497        ObjectID outDiagnostics) override;
498    virtual void ICompositeComponentType_renameEntryPoint(
499        ObjectID objectId,
500        const char* newName,
501        ObjectID outEntryPointId) override;
502    virtual void ICompositeComponentType_linkWithOptions(
503        ObjectID objectId,
504        ObjectID outLinkedComponentTypeId,
505        uint32_t compilerOptionEntryCount,
506        slang::CompilerOptionEntry* compilerOptionEntries,
507        ObjectID outDiagnosticsId) override;
508
509    virtual void ICompositeComponentType_queryInterface(
510        ObjectID objectId,
511        const SlangUUID& guid,
512        ObjectID outInterfaceId) override;
513
514    // ITypeConformance
515    virtual void ITypeConformance_getSession(ObjectID objectId, ObjectID outSessionId) override;
516    virtual void ITypeConformance_getLayout(
517        ObjectID objectId,
518        SlangInt targetIndex,
519        ObjectID outDiagnosticsId,
520        ObjectID retProgramLayoutId) override;
521
522    virtual void ITypeConformance_getSpecializationParamCount(ObjectID objectId) override
523    {
524        (void)objectId;
525    }
526
527    virtual void ITypeConformance_getEntryPointCode(
528        ObjectID objectId,
529        SlangInt entryPointIndex,
530        SlangInt targetIndex,
531        ObjectID outCodeId,
532        ObjectID outDiagnosticsId) override;
533    virtual void ITypeConformance_getTargetCode(
534        ObjectID objectId,
535        SlangInt targetIndex,
536        ObjectID outCodeId,
537        ObjectID outDiagnosticsId) override;
538    virtual void ITypeConformance_getResultAsFileSystem(
539        ObjectID objectId,
540        SlangInt entryPointIndex,
541        SlangInt targetIndex,
542        ObjectID outFileSystem) override;
543    virtual void ITypeConformance_getEntryPointHash(
544        ObjectID objectId,
545        SlangInt entryPointIndex,
546        SlangInt targetIndex,
547        ObjectID outHashId) override;
548    virtual void ITypeConformance_specialize(
549        ObjectID objectId,
550        slang::SpecializationArg const* specializationArgs,
551        SlangInt specializationArgCount,
552        ObjectID outSpecializedComponentTypeId,
553        ObjectID outDiagnosticsId) override;
554    virtual void ITypeConformance_link(
555        ObjectID objectId,
556        ObjectID outLinkedComponentTypeId,
557        ObjectID outDiagnosticsId) override;
558    virtual void ITypeConformance_getEntryPointHostCallable(
559        ObjectID objectId,
560        int entryPointIndex,
561        int targetIndex,
562        ObjectID outSharedLibrary,
563        ObjectID outDiagnostics) override;
564    virtual void ITypeConformance_renameEntryPoint(
565        ObjectID objectId,
566        const char* newName,
567        ObjectID outEntryPointId) override;
568    virtual void ITypeConformance_linkWithOptions(
569        ObjectID objectId,
570        ObjectID outLinkedComponentTypeId,
571        uint32_t compilerOptionEntryCount,
572        slang::CompilerOptionEntry* compilerOptionEntries,
573        ObjectID outDiagnosticsId) override;
574
575    // IComponentType2 methods.
576    virtual void IComponentType2_getTargetCompileResult(
577        ObjectID objectId,
578        SlangInt targetIndex,
579        ObjectID outCompileResultId,
580        ObjectID outDiagnosticsId) override;
581    virtual void IComponentType2_getEntryPointCompileResult(
582        ObjectID objectId,
583        SlangInt entryPointIndex,
584        SlangInt targetIndex,
585        ObjectID outCompileResultId,
586        ObjectID outDiagnosticsId) override;
587
588    static void _writeCompilerOptionEntryHelper(
589        Slang::StringBuilder& builder,
590        int indent,
591        slang::CompilerOptionEntry* compilerOptionEntries,
592        uint32_t compilerOptionEntryCount,
593        bool isLast = false);
594    static void _writeGlobalSessionDescHelper(
595        Slang::StringBuilder& builder,
596        int indent,
597        SlangGlobalSessionDesc const& globalSessionDesc,
598        Slang::String keyName,
599        bool isLast = false);
600    static void _writeSessionDescHelper(
601        Slang::StringBuilder& builder,
602        int indent,
603        slang::SessionDesc const& sessionDesc,
604        Slang::String keyName,
605        bool isLast = false);
606
607private:
608    Slang::FileStream m_fileStream;
609    bool m_isFileValid = false;
610    CommonInterfaceWriter m_moduleHelper{ApiClassId::Class_IModule, m_fileStream};
611    CommonInterfaceWriter m_entryPointHelper{ApiClassId::Class_IEntryPoint, m_fileStream};
612    CommonInterfaceWriter m_compositeComponentTypeHelper{
613        ApiClassId::Class_ICompositeComponentType,
614        m_fileStream};
615    CommonInterfaceWriter m_typeConformanceHelper{ApiClassId::Class_ITypeConformance, m_fileStream};
616    CommonInterfaceWriter m_componentType2Helper{ApiClassId::Class_IComponentType2, m_fileStream};
617};
618} // namespace SlangRecord
619#endif // JSON_CONSUMER_H