yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
de6cc94e3
master
1#include "slang-module.h" 2 3#include "../util/record-utility.h" 4#include "slang-session.h" 5 6namespace SlangRecord 7{ 8ModuleRecorder ::ModuleRecorder ( 9SessionRecorder * sessionRecorder , 10 slang::IModule * module , 11RecordManager * recordManager ) 12 :IComponentTypeRecorder (module ,recordManager ) 13 ,m_sessionRecorder (sessionRecorder ) 14 ,m_actualModule (module ) 15 ,m_recordManager (recordManager ) 16{ 17SLANG_RECORD_ASSERT (m_actualModule != nullptr ); 18SLANG_RECORD_ASSERT (m_recordManager != nullptr ); 19 20m_moduleHandle = reinterpret_cast < uint64_t > (m_actualModule .get ()); 21slangRecordLog (LogLevel ::Verbose ,"%s: %p\n" ,__PRETTY_FUNCTION__ ,module ); 22} 23 24ISlangUnknown * ModuleRecorder ::getInterface (const Guid & guid ) 25{ 26if (guid == IModuleRecorder ::getTypeGuid ()) 27return static_cast < IModuleRecorder *> (this ); 28else 29return nullptr ; 30} 31 32SLANG_NO_THROW slang::DeclReflection * ModuleRecorder ::getModuleReflection () 33{ 34// No need to record this call as it is just a query. 35slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 36 slang::DeclReflection * res = (slang::DeclReflection * )m_actualModule -> getModuleReflection (); 37return res ; 38} 39 40SLANG_NO_THROW SlangResult 41ModuleRecorder ::findEntryPointByName (char const * name , slang::IEntryPoint ** outEntryPoint ) 42{ 43slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 44 45ParameterRecorder * recorder {}; 46 { 47recorder = m_recordManager -> beginMethodRecord ( 48ApiCallId ::IModule_findEntryPointByName , 49m_moduleHandle ); 50recorder -> recordString (name ); 51recorder = m_recordManager -> endMethodRecord (); 52 } 53 54SlangResult res = m_actualModule -> findEntryPointByName (name ,outEntryPoint ); 55 56 { 57recorder -> recordAddress (* outEntryPoint ); 58m_recordManager -> apendOutput (); 59 } 60 61if (SLANG_OK == res ) 62 { 63IEntryPointRecorder * entryPointRecord = getEntryPointRecorder (* outEntryPoint ); 64* outEntryPoint = static_cast < slang::IEntryPoint *> (entryPointRecord ); 65 } 66return res ; 67} 68 69SLANG_NO_THROW SlangInt32 ModuleRecorder ::getDefinedEntryPointCount () 70{ 71// No need to record this call as it is just a query. 72slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 73SlangInt32 res = m_actualModule -> getDefinedEntryPointCount (); 74return res ; 75} 76 77SLANG_NO_THROW SlangResult 78ModuleRecorder ::getDefinedEntryPoint (SlangInt32 index , slang::IEntryPoint ** outEntryPoint ) 79{ 80// This call is to find the existing entry point, so it has been created already. Therefore, we 81// don't create a new one and assert the error if it is not found in our map. 82slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 83 84ParameterRecorder * recorder {}; 85 { 86recorder = m_recordManager -> beginMethodRecord ( 87ApiCallId ::IModule_getDefinedEntryPoint , 88m_moduleHandle ); 89recorder -> recordInt32 (index ); 90recorder = m_recordManager -> endMethodRecord (); 91 } 92 93SlangResult res = m_actualModule -> getDefinedEntryPoint (index ,outEntryPoint ); 94 95 { 96recorder -> recordAddress (* outEntryPoint ); 97m_recordManager -> apendOutput (); 98 } 99 100if (* outEntryPoint ) 101 { 102IEntryPointRecorder * entryPointRecord = nullptr ; 103bool ret = m_mapEntryPointToRecord .tryGetValue (* outEntryPoint ,entryPointRecord ); 104if (!ret ) 105 { 106SLANG_RECORD_ASSERT (!"Entrypoint not found in mapEntryPointToRecord" ); 107 } 108ComPtr < slang::IEntryPoint > result (static_cast < slang::IEntryPoint *> (entryPointRecord )); 109* outEntryPoint = result .detach (); 110 } 111else 112* outEntryPoint = nullptr ; 113 114return res ; 115} 116 117SLANG_NO_THROW SlangResult ModuleRecorder ::serialize (ISlangBlob ** outSerializedBlob ) 118{ 119slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 120 121ParameterRecorder * recorder {}; 122 { 123recorder = m_recordManager -> beginMethodRecord (ApiCallId ::IModule_serialize ,m_moduleHandle ); 124recorder = m_recordManager -> endMethodRecord (); 125 } 126 127SlangResult res = m_actualModule -> serialize (outSerializedBlob ); 128 129 { 130recorder -> recordAddress (* outSerializedBlob ); 131m_recordManager -> apendOutput (); 132 } 133 134return res ; 135} 136 137SLANG_NO_THROW SlangResult ModuleRecorder ::writeToFile (char const * fileName ) 138{ 139slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 140 141ParameterRecorder * recorder {}; 142 { 143recorder = 144m_recordManager -> beginMethodRecord (ApiCallId ::IModule_writeToFile ,m_moduleHandle ); 145recorder -> recordString (fileName ); 146recorder = m_recordManager -> endMethodRecord (); 147 } 148 149SlangResult res = m_actualModule -> writeToFile (fileName ); 150return res ; 151} 152 153SLANG_NO_THROW const char * ModuleRecorder ::getName () 154{ 155// No need to record this call as it is just a query. 156slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 157const char * res = m_actualModule -> getName (); 158return res ; 159} 160 161SLANG_NO_THROW const char * ModuleRecorder ::getFilePath () 162{ 163// No need to record this call as it is just a query. 164slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 165const char * res = m_actualModule -> getFilePath (); 166return res ; 167} 168 169SLANG_NO_THROW const char * ModuleRecorder ::getUniqueIdentity () 170{ 171// No need to record this call as it is just a query. 172slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 173const char * res = m_actualModule -> getUniqueIdentity (); 174return res ; 175} 176 177SLANG_NO_THROW SlangResult ModuleRecorder ::findAndCheckEntryPoint ( 178char const * name , 179SlangStage stage , 180 slang::IEntryPoint ** outEntryPoint , 181ISlangBlob ** outDiagnostics ) 182{ 183slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 184 185ParameterRecorder * recorder {}; 186 { 187recorder = m_recordManager -> beginMethodRecord ( 188ApiCallId ::IModule_findAndCheckEntryPoint , 189m_moduleHandle ); 190recorder -> recordString (name ); 191recorder -> recordEnumValue (stage ); 192recorder = m_recordManager -> endMethodRecord (); 193 } 194 195SlangResult res = 196m_actualModule -> findAndCheckEntryPoint (name ,stage ,outEntryPoint ,outDiagnostics ); 197 198 { 199recorder -> recordAddress (* outEntryPoint ); 200recorder -> recordAddress (outDiagnostics ?* outDiagnostics :nullptr ); 201m_recordManager -> apendOutput (); 202 } 203 204if (SLANG_OK == res ) 205 { 206IEntryPointRecorder * entryPointRecord = getEntryPointRecorder (* outEntryPoint ); 207* outEntryPoint = static_cast < slang::IEntryPoint *> (entryPointRecord ); 208 } 209return res ; 210} 211 212SLANG_NO_THROW SlangInt32 ModuleRecorder ::getDependencyFileCount () 213{ 214// No need to record this call as it is just a query. 215slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 216SlangInt32 res = m_actualModule -> getDependencyFileCount (); 217return res ; 218} 219 220SLANG_NO_THROW char const * ModuleRecorder ::getDependencyFilePath (SlangInt32 index ) 221{ 222// No need to record this call as it is just a query. 223slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 224const char * res = m_actualModule -> getDependencyFilePath (index ); 225return res ; 226} 227 228IEntryPointRecorder * ModuleRecorder ::getEntryPointRecorder (slang::IEntryPoint * entryPoint ) 229{ 230IEntryPointRecorder * entryPointRecord = nullptr ; 231bool ret = m_mapEntryPointToRecord .tryGetValue (entryPoint ,entryPointRecord ); 232if (!ret ) 233 { 234entryPointRecord = new EntryPointRecorder (m_sessionRecorder ,entryPoint ,m_recordManager ); 235Slang ::ComPtr < IEntryPointRecorder > result (entryPointRecord ); 236 237m_entryPointsRecordAllocation .add (result ); 238m_mapEntryPointToRecord .add (entryPoint ,result .detach ()); 239return entryPointRecord ; 240 } 241else 242 { 243Slang ::ComPtr < IEntryPointRecorder > result (entryPointRecord ); 244return result .detach (); 245 } 246} 247 248SlangResult ModuleRecorder ::disassemble (ISlangBlob ** outBlob ) 249{ 250// No need to record this call as it is just a query. 251slangRecordLog (LogLevel ::Verbose ,"%s\n" ,__PRETTY_FUNCTION__ ); 252auto res = m_actualModule -> disassemble (outBlob ); 253return res ; 254} 255}// namespace SlangRecord