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