yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
9c8fab83a
master
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 : 20SLANG_COM_INTERFACE ( 210xb1802991 , 220x185a , 230x4a03 , 24 {0xa7 ,0x7e ,0x0c ,0x86 ,0xe0 ,0x68 ,0x2a ,0xab }) 25}; 26 27class ModuleRecorder :public IModuleRecorder ,public IComponentTypeRecorder 28{ 29typedef IComponentTypeRecorder Super ; 30 31public : 32SLANG_REF_OBJECT_IUNKNOWN_ALL 33ISlangUnknown * getInterface (const Guid & guid ); 34 35explicit ModuleRecorder ( 36SessionRecorder * sessionRecorder , 37slang ::IModule * module , 38RecordManager * recordManager ); 39 40// Interfaces for `IModule` 41virtual SLANG_NO_THROW SlangResult SLANG_MCALL 42findEntryPointByName (char const * name ,slang ::IEntryPoint ** outEntryPoint )override ; 43virtual SLANG_NO_THROW SlangInt32 SLANG_MCALL getDefinedEntryPointCount ()override ; 44virtual SLANG_NO_THROW SlangResult SLANG_MCALL 45getDefinedEntryPoint ( SlangInt32 index, slang ::IEntryPoint ** outEntryPoint) override; 46virtual SLANG_NO_THROW SlangResult SLANG_MCALL 47serialize ( ISlangBlob ** outSerializedBlob) override; 48virtual SLANG_NO_THROW SlangResult SLANG_MCALL writeToFile ( char const * fileName) override; 49virtual SLANG_NO_THROW const char * SLANG_MCALL getName () override; 50virtual SLANG_NO_THROW const char * SLANG_MCALL getFilePath () override; 51virtual SLANG_NO_THROW const char * SLANG_MCALL getUniqueIdentity () override; 52virtual SLANG_NO_THROW SlangResult SLANG_MCALL findAndCheckEntryPoint ( 53char const * name, 54SlangStage stage, 55slang ::IEntryPoint ** outEntryPoint, 56ISlangBlob ** outDiagnostics) override; 57virtual SLANG_NO_THROW SlangInt32 SLANG_MCALL getDependencyFileCount () override; 58virtual SLANG_NO_THROW char const * SLANG_MCALL getDependencyFilePath ( SlangInt32 index) override; 59virtual SLANG_NO_THROW SlangResult SLANG_MCALL 60disassemble( slang :: IBlob ** outDisassembly ) override; 61 62// Interfaces for `IComponentType` 63virtual SLANG_NO_THROW slang::ISession * SLANG_MCALL getSession () override 64{ 65return Super:: getSession (); 66} 67 68virtual SLANG_NO_THROW slang::ProgramLayout * SLANG_MCALL 69getLayout ( SlangInt targetIndex = 0 , slang::IBlob ** outDiagnostics = nullptr ) override 70{ 71return Super:: getLayout (targetIndex, outDiagnostics); 72} 73 74virtual SLANG_NO_THROW SlangInt SLANG_MCALL getSpecializationParamCount () override 75{ 76return Super:: getSpecializationParamCount (); 77} 78 79virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCode ( 80SlangInt entryPointIndex, 81SlangInt targetIndex, 82slang ::IBlob ** outCode, 83slang ::IBlob ** outDiagnostics = nullptr) override 84{ 85return Super:: getEntryPointCode (entryPointIndex, targetIndex, outCode, outDiagnostics); 86} 87 88virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCode ( 89SlangInt targetIndex, 90slang ::IBlob ** outCode, 91slang ::IBlob ** outDiagnostics = nullptr) override 92{ 93return Super:: getTargetCode (targetIndex, outCode, outDiagnostics); 94} 95 96SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointMetadata ( 97SlangInt entryPointIndex, 98SlangInt targetIndex, 99slang ::IMetadata ** outMetadata, 100slang ::IBlob ** outDiagnostics) SLANG_OVERRIDE 101{ 102return Super:: getEntryPointMetadata ( 103entryPointIndex, 104targetIndex, 105outMetadata, 106outDiagnostics); 107} 108 109SLANG_NO_THROW SlangResult SLANG_MCALL getTargetMetadata ( 110SlangInt targetIndex, 111slang ::IMetadata ** outMetadata, 112slang ::IBlob ** outDiagnostics) SLANG_OVERRIDE 113{ 114return Super:: getTargetMetadata (targetIndex, outMetadata, outDiagnostics); 115} 116 117virtual SLANG_NO_THROW SlangResult SLANG_MCALL getResultAsFileSystem ( 118SlangInt entryPointIndex, 119SlangInt targetIndex, 120ISlangMutableFileSystem ** outFileSystem) override 121{ 122return Super:: getResultAsFileSystem (entryPointIndex, targetIndex, outFileSystem); 123} 124 125virtual SLANG_NO_THROW void SLANG_MCALL getEntryPointHash ( 126SlangInt entryPointIndex, 127SlangInt targetIndex, 128slang ::IBlob ** outHash) override 129{ 130return Super:: getEntryPointHash (entryPointIndex, targetIndex, outHash); 131} 132 133virtual SLANG_NO_THROW SlangResult SLANG_MCALL specialize ( 134slang :: SpecializationArg const * specializationArgs, 135SlangInt specializationArgCount, 136slang::IComponentType ** outSpecializedComponentType, 137ISlangBlob ** outDiagnostics = nullptr ) override 138{ 139return Super:: specialize ( 140specializationArgs, 141specializationArgCount, 142outSpecializedComponentType, 143outDiagnostics); 144} 145 146virtual SLANG_NO_THROW SlangResult SLANG_MCALL link ( 147slang ::IComponentType ** outLinkedComponentType, 148ISlangBlob ** outDiagnostics = nullptr ) override 149{ 150return Super:: link (outLinkedComponentType, outDiagnostics); 151} 152 153virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointHostCallable ( 154int entryPointIndex, 155int targetIndex, 156ISlangSharedLibrary ** outSharedLibrary, 157slang ::IBlob ** outDiagnostics = 0 ) override 158{ 159return Super:: getEntryPointHostCallable ( 160entryPointIndex, 161targetIndex, 162outSharedLibrary, 163outDiagnostics); 164} 165 166virtual SLANG_NO_THROW SlangResult SLANG_MCALL 167renameEntryPoint ( const char * newName, IComponentType ** outEntryPoint) override 168{ 169return Super:: renameEntryPoint (newName, outEntryPoint); 170} 171 172virtual SLANG_NO_THROW SlangResult SLANG_MCALL linkWithOptions ( 173IComponentType ** outLinkedComponentType, 174uint32_t compilerOptionEntryCount, 175slang ::CompilerOptionEntry * compilerOptionEntries, 176ISlangBlob ** outDiagnostics = nullptr) override 177{ 178return Super:: linkWithOptions ( 179outLinkedComponentType, 180compilerOptionEntryCount, 181compilerOptionEntries, 182outDiagnostics); 183} 184 185virtual SLANG_NO_THROW slang ::DeclReflection * SLANG_MCALL getModuleReflection () override; 186 187slang :: IModule * getActualModule () const { return m_actualModule; } 188 189protected : 190// `IComponentTypeRecorder` interface 191virtual ApiClassId getClassId () override { return ApiClassId::Class_IModule; } 192 193virtual SessionRecorder * getSessionRecorder () override { return m_sessionRecorder; } 194 195private : 196IEntryPointRecorder * getEntryPointRecorder (slang::IEntryPoint * entryPoint); 197 198SessionRecorder * m_sessionRecorder; 199Slang ::ComPtr < slang::IModule > m_actualModule; 200uint64_t m_moduleHandle = 0 ; 201RecordManager * 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`. 206Dictionary < slang::IEntryPoint * , IEntryPointRecorder *> m_mapEntryPointToRecord; 207List < ComPtr < IEntryPointRecorder>> m_entryPointsRecordAllocation; 208}; 209} // namespace SlangRecord 210 211#endif // SLANG_MODULE_H