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