yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
c8ec3690
16.4.0
1// 2// Copyright (C) 2002-2005 3Dlabs Inc. Ltd. 3// Copyright (C) 2013-2016 LunarG, Inc. 4// Copyright (C) 2016-2020 Google, Inc. 5// Modifications Copyright(C) 2021 Advanced Micro Devices, Inc.All rights reserved. 6// 7// All rights reserved. 8// 9// Redistribution and use in source and binary forms, with or without 10// modification, are permitted provided that the following conditions 11// are met: 12// 13// Redistributions of source code must retain the above copyright 14// notice, this list of conditions and the following disclaimer. 15// 16// Redistributions in binary form must reproduce the above 17// copyright notice, this list of conditions and the following 18// disclaimer in the documentation and/or other materials provided 19// with the distribution. 20// 21// Neither the name of 3Dlabs Inc. Ltd. nor the names of its 22// contributors may be used to endorse or promote products derived 23// from this software without specific prior written permission. 24// 25// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36// POSSIBILITY OF SUCH DAMAGE. 37// 38 39// this only applies to the standalone wrapper, not the front end in general 40#ifndef _CRT_SECURE_NO_WARNINGS 41#define _CRT_SECURE_NO_WARNINGS 42#endif 43 44#include "glslang/Public/ResourceLimits.h" 45#include "Worklist.h" 46#include "DirStackFileIncluder.h" 47#include "./../glslang/Public/ShaderLang.h" 48#include "../glslang/MachineIndependent/localintermediate.h" 49#include "../SPIRV/GlslangToSpv.h" 50#include "../SPIRV/GLSL.std.450.h" 51#include "../SPIRV/disassemble.h" 52 53#include <array> 54#include <atomic> 55#include <cctype> 56#include <cmath> 57#include <cstdlib> 58#include <cstring> 59#include <iterator> 60#include <map> 61#include <memory> 62#include <set> 63#include <thread> 64#include <type_traits> 65 66#include "../glslang/OSDependent/osinclude.h" 67 68// Build-time generated includes 69#include "glslang/build_info.h" 70 71#include "glslang/glsl_intrinsic_header.h" 72 73extern "C" { 74GLSLANG_EXPORT void ShOutputHtml () ; 75} 76 77// Command-line options 78enum TOptions : uint64_t { 79EOptionNone = 0 , 80EOptionIntermediate = ( 1ull << 0 ) , 81EOptionSuppressInfolog = ( 1ull << 1 ) , 82EOptionMemoryLeakMode = ( 1ull << 2 ) , 83EOptionRelaxedErrors = ( 1ull << 3 ) , 84EOptionGiveWarnings = ( 1ull << 4 ) , 85EOptionLinkProgram = ( 1ull << 5 ) , 86EOptionMultiThreaded = ( 1ull << 6 ) , 87EOptionDumpConfig = ( 1ull << 7 ) , 88EOptionDumpReflection = ( 1ull << 8 ) , 89EOptionSuppressWarnings = ( 1ull << 9 ) , 90EOptionDumpVersions = ( 1ull << 10 ) , 91EOptionSpv = ( 1ull << 11 ) , 92EOptionHumanReadableSpv = ( 1ull << 12 ) , 93EOptionVulkanRules = ( 1ull << 13 ) , 94EOptionDefaultDesktop = ( 1ull << 14 ) , 95EOptionOutputPreprocessed = ( 1ull << 15 ) , 96EOptionOutputHexadecimal = ( 1ull << 16 ) , 97EOptionReadHlsl = ( 1ull << 17 ) , 98EOptionCascadingErrors = ( 1ull << 18 ) , 99EOptionAutoMapBindings = ( 1ull << 19 ) , 100EOptionFlattenUniformArrays = ( 1ull << 20 ) , 101EOptionNoStorageFormat = ( 1ull << 21 ) , 102EOptionKeepUncalled = ( 1ull << 22 ) , 103EOptionHlslOffsets = ( 1ull << 23 ) , 104EOptionHlslIoMapping = ( 1ull << 24 ) , 105EOptionAutoMapLocations = ( 1ull << 25 ) , 106EOptionDebug = ( 1ull << 26 ) , 107EOptionStdin = ( 1ull << 27 ) , 108EOptionOptimizeDisable = ( 1ull << 28 ) , 109EOptionOptimizeSize = ( 1ull << 29 ) , 110EOptionInvertY = ( 1ull << 30 ) , 111EOptionDumpBareVersion = ( 1ull << 31 ) , 112EOptionCompileOnly = ( 1ull << 32 ) , 113EOptionDisplayErrorColumn = ( 1ull << 33 ) , 114EOptionLinkTimeOptimization = ( 1ull << 34 ) , 115EOptionValidateCrossStageIO = ( 1ull << 35 ) , 116EOptionBindingsPerResourceType = ( 1ull << 36 ) , 117EOptionRelaxSetBindingLimits = ( 1ull << 37 ) , 118EOptionDiscardIsTerminate = ( 1ull << 38 ) , 119} ; 120bool targetHlslFunctionality1 = false ; 121bool SpvToolsDisassembler = false ; 122bool SpvToolsValidate = false ; 123bool NaNClamp = false ; 124bool stripDebugInfo = false ; 125bool emitNonSemanticShaderDebugInfo = false ; 126bool emitNonSemanticShaderDebugSource = false ; 127bool beQuiet = false ; 128bool VulkanRulesRelaxed = false ; 129bool autoSampledTextures = false ; 130 131// 132// Return codes from main/exit(). 133// 134enum TFailCode { 135ESuccess = 0 , 136EFailUsage , 137EFailCompile , 138EFailLink , 139EFailCompilerCreate , 140EFailThreadCreate , 141EFailLinkerCreate 142} ; 143 144// 145// Forward declarations. 146// 147EShLanguage FindLanguage ( const std :: string & name , bool parseSuffix = true ) ; 148void CompileFile ( const char * fileName , ShHandle ) ; 149void usage () ; 150char * ReadFileData ( const char * fileName ) ; 151void FreeFileData ( char * data ) ; 152void InfoLogMsg ( const char * msg , const char * name , const int num ) ; 153 154// Globally track if any compile or link failure. 155std :: atomic < int8_t > CompileFailed { 0 } ; 156std :: atomic < int8_t > LinkFailed { 0 } ; 157std :: atomic < int8_t > CompileOrLinkFailed { 0 } ; 158 159// array of unique places to leave the shader names and infologs for the asynchronous compiles 160std :: vector < std :: unique_ptr < glslang :: TWorkItem >> WorkItems ; 161 162std :: string ConfigFile ; 163 164// 165// Parse either a .conf file provided by the user or the default from glslang::DefaultTBuiltInResource 166// 167void ProcessConfigFile () 168{ 169if ( ConfigFile . size () == 0 ) 170* GetResources () = * GetDefaultResources () ; 171else { 172char * configString = ReadFileData ( ConfigFile . c_str ()) ; 173DecodeResourceLimits ( GetResources () , configString ) ; 174FreeFileData ( configString ) ; 175} 176} 177 178int ReflectOptions = EShReflectionDefault ; 179std :: underlying_type_t < TOptions > Options = EOptionNone ; 180const char * ExecutableName = nullptr ; 181const char * binaryFileName = nullptr ; 182const char * depencyFileName = nullptr ; 183const char * entryPointName = nullptr ; 184const char * sourceEntryPointName = nullptr ; 185const char * shaderStageName = nullptr ; 186const char * variableName = nullptr ; 187bool HlslEnable16BitTypes = false ; 188bool HlslDX9compatible = false ; 189bool HlslDxPositionW = false ; 190bool EnhancedMsgs = false ; 191bool AbsolutePath = false ; 192bool DumpBuiltinSymbols = false ; 193std :: vector < std :: string > IncludeDirectoryList ; 194 195// Source environment 196// (source 'Client' is currently the same as target 'Client') 197int ClientInputSemanticsVersion = 100 ; 198 199// Target environment 200glslang :: EShClient Client = glslang :: EShClientNone ; // will stay EShClientNone if only validating 201glslang :: EShTargetClientVersion ClientVersion ; // not valid until Client is set 202glslang :: EShTargetLanguage TargetLanguage = glslang :: EShTargetNone ; 203glslang :: EShTargetLanguageVersion TargetVersion ; // not valid until TargetLanguage is set 204 205// GLSL version 206int GlslVersion = 0 ; // GLSL version specified on CLI, overrides #version in shader source 207 208std :: vector < std :: string > Processes ; // what should be recorded by OpModuleProcessed, or equivalent 209 210// Per descriptor-set binding base data 211typedef std :: map < unsigned int , unsigned int > TPerSetBaseBinding ; 212 213std :: vector < std :: pair < std :: string , int >> uniformLocationOverrides ; 214int uniformBase = 0 ; 215 216std :: array < std :: array < unsigned int , EShLangCount > , glslang :: EResCount > baseBinding ; 217std :: array < std :: array < TPerSetBaseBinding , EShLangCount > , glslang :: EResCount > baseBindingForSet ; 218std :: array < std :: vector < std :: string > , EShLangCount > baseResourceSetBinding ; 219 220std :: vector < std :: pair < std :: string , glslang :: TBlockStorageClass >> blockStorageOverrides ; 221 222bool setGlobalUniformBlock = false ; 223std :: string globalUniformName ; 224unsigned int globalUniformBinding ; 225unsigned int globalUniformSet ; 226 227bool setGlobalBufferBlock = false ; 228std :: string atomicCounterBlockName ; 229unsigned int atomicCounterBlockSet ; 230 231// Add things like "#define ..." to a preamble to use in the beginning of the shader. 232class TPreamble { 233public : 234TPreamble () { } 235 236bool isSet () const { return text . size () > 0 ; } 237const char * get () const { return text . c_str () ; } 238 239// #define... 240void addDef ( std :: string def ) 241{ 242text . append ( "#define " ) ; 243fixLine ( def ) ; 244 245Processes . push_back ( "define-macro " ) ; 246Processes . back () . append ( def ) ; 247 248// The first "=" needs to turn into a space 249const size_t equal = def . find_first_of ( "=" ) ; 250if ( equal != def . npos ) 251def [ equal ] = ' ' ; 252 253text . append ( def ) ; 254text . append ( " \n " ) ; 255} 256 257// #undef... 258void addUndef ( std :: string undef ) 259{ 260text . append ( "#undef " ) ; 261fixLine ( undef ) ; 262 263Processes . push_back ( "undef-macro " ) ; 264Processes . back () . append ( undef ) ; 265 266text . append ( undef ) ; 267text . append ( " \n " ) ; 268} 269 270void addText ( std :: string preambleText ) 271{ 272fixLine ( preambleText ) ; 273 274Processes . push_back ( "preamble-text" ) ; 275Processes . back () . append ( preambleText ) ; 276 277text . append ( preambleText ) ; 278text . append ( " \n " ) ; 279} 280 281protected : 282void fixLine ( std :: string & line ) 283{ 284// Can't go past a newline in the line 285const size_t end = line . find_first_of ( " \n " ) ; 286if ( end != line . npos ) 287line = line . substr ( 0 , end ) ; 288} 289 290std :: string text ; // contents of preamble 291} ; 292 293// Track the user's #define and #undef from the command line. 294TPreamble UserPreamble ; 295std :: string PreambleString ; 296 297// 298// Create the default name for saving a binary if -o is not provided. 299// 300const char * GetBinaryName ( EShLanguage stage ) 301{ 302const char * name ; 303if ( binaryFileName == nullptr ) { 304switch ( stage ) { 305case EShLangVertex : name = "vert.spv" ; break ; 306case EShLangTessControl : name = "tesc.spv" ; break ; 307case EShLangTessEvaluation : name = "tese.spv" ; break ; 308case EShLangGeometry : name = "geom.spv" ; break ; 309case EShLangFragment : name = "frag.spv" ; break ; 310case EShLangCompute : name = "comp.spv" ; break ; 311case EShLangRayGen : name = "rgen.spv" ; break ; 312case EShLangIntersect : name = "rint.spv" ; break ; 313case EShLangAnyHit : name = "rahit.spv" ; break ; 314case EShLangClosestHit : name = "rchit.spv" ; break ; 315case EShLangMiss : name = "rmiss.spv" ; break ; 316case EShLangCallable : name = "rcall.spv" ; break ; 317case EShLangMesh : name = "mesh.spv" ; break ; 318case EShLangTask : name = "task.spv" ; break ; 319default : name = "unknown" ; break ; 320} 321} else 322name = binaryFileName ; 323 324return name ; 325} 326 327// 328// *.conf => this is a config file that can set limits/resources 329// 330bool SetConfigFile ( const std :: string & name ) 331{ 332if ( name . size () < 5 ) 333return false ; 334 335if ( name . compare ( name . size () - 5 , 5 , ".conf" ) == 0 ) { 336ConfigFile = name ; 337return true ; 338} 339 340return false ; 341} 342 343// 344// Give error and exit with failure code. 345// 346void Error ( const char * message , const char * detail = nullptr ) 347{ 348fprintf ( stderr , "%s: Error: " , ExecutableName ) ; 349if ( detail != nullptr ) 350fprintf ( stderr , "%s: " , detail ) ; 351fprintf ( stderr , "%s (use -h for usage) \n " , message ) ; 352exit ( EFailUsage ) ; 353} 354 355// 356// Process an optional binding base of one the forms: 357// --argname [stage] base // base for stage (if given) or all stages (if not) 358// --argname [stage] [base set]... // set/base pairs: set the base for given binding set. 359 360// Where stage is one of the forms accepted by FindLanguage, and base is an integer 361// 362void ProcessBindingBase ( int & argc , char **& argv , glslang :: TResourceType res ) 363{ 364if ( argc < 2 ) 365usage () ; 366 367EShLanguage lang = EShLangCount ; 368int singleBase = 0 ; 369TPerSetBaseBinding perSetBase ; 370int arg = 1 ; 371 372// Parse stage, if given 373if ( ! isdigit ( argv [ arg ][ 0 ])) { 374if ( argc < 3 ) // this form needs one more argument 375usage () ; 376 377lang = FindLanguage ( argv [ arg ++ ] , false ) ; 378} 379 380if (( argc - arg ) >= 2 && isdigit ( argv [ arg + 0 ][ 0 ]) && isdigit ( argv [ arg + 1 ][ 0 ])) { 381// Parse a per-set binding base 382do { 383const int baseNum = atoi ( argv [ arg ++ ]) ; 384const int setNum = atoi ( argv [ arg ++ ]) ; 385perSetBase [ setNum ] = baseNum ; 386} while (( argc - arg ) >= 2 && isdigit ( argv [ arg + 0 ][ 0 ]) && isdigit ( argv [ arg + 1 ][ 0 ])) ; 387} else { 388// Parse single binding base 389singleBase = atoi ( argv [ arg ++ ]) ; 390} 391 392argc -= ( arg - 1 ) ; 393argv += ( arg - 1 ) ; 394 395// Set one or all languages 396const int langMin = ( lang < EShLangCount ) ? lang + 0 : 0 ; 397const int langMax = ( lang < EShLangCount ) ? lang + 1 : EShLangCount ; 398 399for ( int lang = langMin ; lang < langMax ; ++ lang ) { 400if ( ! perSetBase . empty ()) 401baseBindingForSet [ res ][ lang ] . insert ( perSetBase . begin () , perSetBase . end ()) ; 402else 403baseBinding [ res ][ lang ] = singleBase ; 404} 405} 406 407void ProcessResourceSetBindingBase ( int & argc , char **& argv , std :: array < std :: vector < std :: string > , EShLangCount >& base ) 408{ 409if ( argc < 2 ) 410usage () ; 411 412if ( ! isdigit ( argv [ 1 ][ 0 ])) { 413if ( argc < 3 ) // this form needs one more argument 414usage () ; 415 416// Parse form: --argname stage [regname set base...], or: 417// --argname stage set 418const EShLanguage lang = FindLanguage ( argv [ 1 ] , false ) ; 419 420argc -- ; 421argv ++ ; 422 423while ( argc > 1 && argv [ 1 ] != nullptr && argv [ 1 ][ 0 ] != '-' ) { 424base [ lang ] . push_back ( argv [ 1 ]) ; 425 426argc -- ; 427argv ++ ; 428} 429 430// Must have one arg, or a multiple of three (for [regname set binding] triples) 431if ( base [ lang ] . size () != 1 && ( base [ lang ] . size () % 3 ) != 0 ) 432usage () ; 433 434} else { 435// Parse form: --argname set 436for ( int lang = 0 ; lang < EShLangCount ; ++ lang ) 437base [ lang ] . push_back ( argv [ 1 ]) ; 438 439argc -- ; 440argv ++ ; 441} 442} 443 444// 445// Process an optional binding base of one the forms: 446// --argname name {uniform|buffer|push_constant} 447void ProcessBlockStorage ( int & argc , char **& argv , std :: vector < std :: pair < std :: string , glslang :: TBlockStorageClass >>& storage ) 448{ 449if ( argc < 3 ) 450usage () ; 451 452glslang :: TBlockStorageClass blockStorage = glslang :: EbsNone ; 453 454std :: string strBacking ( argv [ 2 ]) ; 455if ( strBacking == "uniform" ) 456blockStorage = glslang :: EbsUniform ; 457else if ( strBacking == "buffer" ) 458blockStorage = glslang :: EbsStorageBuffer ; 459else if ( strBacking == "push_constant" ) 460blockStorage = glslang :: EbsPushConstant ; 461else { 462printf ( "%s: invalid block storage \n " , strBacking . c_str ()) ; 463usage () ; 464} 465 466storage . push_back ( std :: make_pair ( std :: string ( argv [ 1 ]) , blockStorage )) ; 467 468argc -= 2 ; 469argv += 2 ; 470} 471 472inline bool isNonDigit ( char c ) { 473// a non-digit character valid in a glsl identifier 474return ( c == '_' ) || ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) ; 475} 476 477// whether string isa valid identifier to be used in glsl 478bool isValidIdentifier ( const char * str ) { 479std :: string idn ( str ) ; 480 481if ( idn . length () == 0 ) { 482return false ; 483} 484 485if ( idn . length () >= 3 && idn . substr ( 0 , 3 ) == "gl_" ) { 486// identifiers startin with "gl_" are reserved 487return false ; 488} 489 490if ( ! isNonDigit ( idn [ 0 ])) { 491return false ; 492} 493 494for ( unsigned int i = 1 ; i < idn . length () ; ++ i ) { 495if ( ! ( isdigit ( idn [ i ]) || isNonDigit ( idn [ i ]))) { 496return false ; 497} 498} 499 500return true ; 501} 502 503// Process settings for either the global buffer block or global unfirom block 504// of the form: 505// --argname name set binding 506void ProcessGlobalBlockSettings ( int & argc , char **& argv , std :: string * name , unsigned int * set , unsigned int * binding ) 507{ 508if ( argc < 4 ) 509usage () ; 510 511unsigned int curArg = 1 ; 512 513assert ( name || set || binding ) ; 514 515if ( name ) { 516if ( ! isValidIdentifier ( argv [ curArg ])) { 517printf ( "%s: invalid identifier \n " , argv [ curArg ]) ; 518usage () ; 519} 520* name = argv [ curArg ] ; 521 522curArg ++ ; 523} 524 525if ( set ) { 526errno = 0 ; 527int setVal = static_cast < int > ( :: strtol ( argv [ curArg ] , nullptr , 10 )) ; 528if ( errno || setVal < 0 ) { 529printf ( "%s: invalid set \n " , argv [ curArg ]) ; 530usage () ; 531} 532* set = setVal ; 533 534curArg ++ ; 535} 536 537if ( binding ) { 538errno = 0 ; 539int bindingVal = static_cast < int > ( :: strtol ( argv [ curArg ] , nullptr , 10 )) ; 540if ( errno || bindingVal < 0 ) { 541printf ( "%s: invalid binding \n " , argv [ curArg ]) ; 542usage () ; 543} 544* binding = bindingVal ; 545 546curArg ++ ; 547} 548 549argc -= ( curArg - 1 ) ; 550argv += ( curArg - 1 ) ; 551} 552 553// 554// Do all command-line argument parsing. This includes building up the work-items 555// to be processed later, and saving all the command-line options. 556// 557// Does not return (it exits) if command-line is fatally flawed. 558// 559void ProcessArguments ( std :: vector < std :: unique_ptr < glslang :: TWorkItem >>& workItems , int argc , char * argv []) 560{ 561for ( int res = 0 ; res < glslang :: EResCount ; ++ res ) 562baseBinding [ res ] . fill ( 0 ) ; 563 564ExecutableName = argv [ 0 ] ; 565workItems . reserve ( argc ) ; 566 567const auto bumpArg = [ & ]() { 568if ( argc > 0 ) { 569argc -- ; 570argv ++ ; 571} 572} ; 573 574// read a string directly attached to a single-letter option 575const auto getStringOperand = [ & ]( const char * desc ) { 576if ( argv [ 0 ][ 2 ] == 0 ) { 577printf ( "%s must immediately follow option (no spaces) \n " , desc ) ; 578exit ( EFailUsage ) ; 579} 580return argv [ 0 ] + 2 ; 581} ; 582 583// read a number attached to a single-letter option 584const auto getAttachedNumber = [ & ]( const char * desc ) { 585int num = atoi ( argv [ 0 ] + 2 ) ; 586if ( num == 0 ) { 587printf ( "%s: expected attached non-0 number \n " , desc ) ; 588exit ( EFailUsage ) ; 589} 590return num ; 591} ; 592 593// minimum needed (without overriding something else) to target Vulkan SPIR-V 594const auto setVulkanSpv = []() { 595if ( Client == glslang :: EShClientNone ) 596ClientVersion = glslang :: EShTargetVulkan_1_0 ; 597Client = glslang :: EShClientVulkan ; 598Options |= EOptionSpv ; 599Options |= EOptionVulkanRules ; 600Options |= EOptionLinkProgram ; 601} ; 602 603// minimum needed (without overriding something else) to target OpenGL SPIR-V 604const auto setOpenGlSpv = []() { 605if ( Client == glslang :: EShClientNone ) 606ClientVersion = glslang :: EShTargetOpenGL_450 ; 607Client = glslang :: EShClientOpenGL ; 608Options |= EOptionSpv ; 609Options |= EOptionLinkProgram ; 610// undo a -H default to Vulkan 611Options &= ~ EOptionVulkanRules ; 612} ; 613 614const auto getUniformOverride = [ getStringOperand ]() { 615const char * arg = getStringOperand ( "-u<name>:<location>" ) ; 616const char * split = strchr ( arg , ':' ) ; 617if ( split == nullptr ) { 618printf ( "%s: missing location \n " , arg ) ; 619exit ( EFailUsage ) ; 620} 621errno = 0 ; 622int location = static_cast < int > ( :: strtol ( split + 1 , nullptr , 10 )) ; 623if ( errno ) { 624printf ( "%s: invalid location \n " , arg ) ; 625exit ( EFailUsage ) ; 626} 627return std :: make_pair ( std :: string ( arg , split - arg ) , location ) ; 628} ; 629 630for ( bumpArg () ; argc >= 1 ; bumpArg ()) { 631if ( argv [ 0 ][ 0 ] == '-' ) { 632switch ( argv [ 0 ][ 1 ]) { 633case '-' : 634{ 635std :: string lowerword ( argv [ 0 ] + 2 ) ; 636std :: transform ( lowerword . begin () , lowerword . end () , lowerword . begin () , :: tolower ) ; 637 638// handle --word style options 639if ( lowerword == "auto-map-bindings" || // synonyms 640lowerword == "auto-map-binding" || 641lowerword == "amb" ) { 642Options |= EOptionAutoMapBindings ; 643} else if ( lowerword == "relax-set-binding-limits" ) { 644Options |= EOptionRelaxSetBindingLimits ; 645} else if ( lowerword == "auto-map-locations" || // synonyms 646lowerword == "aml" ) { 647Options |= EOptionAutoMapLocations ; 648} else if ( lowerword == "uniform-base" ) { 649if ( argc <= 1 ) 650Error ( "no <base> provided" , lowerword . c_str ()) ; 651uniformBase = static_cast < int > ( :: strtol ( argv [ 1 ] , nullptr , 10 )) ; 652bumpArg () ; 653break ; 654} else if ( lowerword == "client" ) { 655if ( argc > 1 ) { 656if ( strcmp ( argv [ 1 ] , "vulkan100" ) == 0 ) 657setVulkanSpv () ; 658else if ( strcmp ( argv [ 1 ] , "opengl100" ) == 0 ) 659setOpenGlSpv () ; 660else 661Error ( "expects vulkan100 or opengl100" , lowerword . c_str ()) ; 662} else 663Error ( "expects vulkan100 or opengl100" , lowerword . c_str ()) ; 664bumpArg () ; 665} else if ( lowerword == "define-macro" || 666lowerword == "d" ) { 667if ( argc > 1 ) 668UserPreamble . addDef ( argv [ 1 ]) ; 669else 670Error ( "expects <name[=def]>" , argv [ 0 ]) ; 671bumpArg () ; 672} else if ( lowerword == "dump-builtin-symbols" ) { 673DumpBuiltinSymbols = true ; 674} else if ( lowerword == "entry-point" ) { 675entryPointName = argv [ 1 ] ; 676if ( argc <= 1 ) 677Error ( "no <name> provided" , lowerword . c_str ()) ; 678bumpArg () ; 679} else if ( lowerword == "flatten-uniform-arrays" || // synonyms 680lowerword == "flatten-uniform-array" || 681lowerword == "fua" ) { 682Options |= EOptionFlattenUniformArrays ; 683} else if ( lowerword == "glsl-version" ) { 684if ( argc > 1 ) { 685if ( strcmp ( argv [ 1 ] , "100" ) == 0 ) { 686GlslVersion = 100 ; 687} else if ( strcmp ( argv [ 1 ] , "110" ) == 0 ) { 688GlslVersion = 110 ; 689} else if ( strcmp ( argv [ 1 ] , "120" ) == 0 ) { 690GlslVersion = 120 ; 691} else if ( strcmp ( argv [ 1 ] , "130" ) == 0 ) { 692GlslVersion = 130 ; 693} else if ( strcmp ( argv [ 1 ] , "140" ) == 0 ) { 694GlslVersion = 140 ; 695} else if ( strcmp ( argv [ 1 ] , "150" ) == 0 ) { 696GlslVersion = 150 ; 697} else if ( strcmp ( argv [ 1 ] , "300es" ) == 0 ) { 698GlslVersion = 300 ; 699} else if ( strcmp ( argv [ 1 ] , "310es" ) == 0 ) { 700GlslVersion = 310 ; 701} else if ( strcmp ( argv [ 1 ] , "320es" ) == 0 ) { 702GlslVersion = 320 ; 703} else if ( strcmp ( argv [ 1 ] , "330" ) == 0 ) { 704GlslVersion = 330 ; 705} else if ( strcmp ( argv [ 1 ] , "400" ) == 0 ) { 706GlslVersion = 400 ; 707} else if ( strcmp ( argv [ 1 ] , "410" ) == 0 ) { 708GlslVersion = 410 ; 709} else if ( strcmp ( argv [ 1 ] , "420" ) == 0 ) { 710GlslVersion = 420 ; 711} else if ( strcmp ( argv [ 1 ] , "430" ) == 0 ) { 712GlslVersion = 430 ; 713} else if ( strcmp ( argv [ 1 ] , "440" ) == 0 ) { 714GlslVersion = 440 ; 715} else if ( strcmp ( argv [ 1 ] , "450" ) == 0 ) { 716GlslVersion = 450 ; 717} else if ( strcmp ( argv [ 1 ] , "460" ) == 0 ) { 718GlslVersion = 460 ; 719} else 720Error ( "--glsl-version expected one of: 100, 110, 120, 130, 140, 150, \n " 721"300es, 310es, 320es, 330 \n " 722"400, 410, 420, 430, 440, 450, 460" ) ; 723} 724bumpArg () ; 725} else if ( lowerword == "hlsl-offsets" ) { 726Options |= EOptionHlslOffsets ; 727} else if ( lowerword == "hlsl-iomap" || 728lowerword == "hlsl-iomapper" || 729lowerword == "hlsl-iomapping" ) { 730Options |= EOptionHlslIoMapping ; 731} else if ( lowerword == "hlsl-enable-16bit-types" ) { 732HlslEnable16BitTypes = true ; 733} else if ( lowerword == "hlsl-dx9-compatible" ) { 734HlslDX9compatible = true ; 735} else if ( lowerword == "hlsl-dx-position-w" ) { 736HlslDxPositionW = true ; 737} else if ( lowerword == "enhanced-msgs" ) { 738EnhancedMsgs = true ; 739} else if ( lowerword == "absolute-path" ) { 740AbsolutePath = true ; 741} else if ( lowerword == "auto-sampled-textures" ) { 742autoSampledTextures = true ; 743} else if ( lowerword == "discard-is-terminate" ) { 744Options |= EOptionDiscardIsTerminate ; 745} else if ( lowerword == "invert-y" || // synonyms 746lowerword == "iy" ) { 747Options |= EOptionInvertY ; 748} else if ( lowerword == "keep-uncalled" || // synonyms 749lowerword == "ku" ) { 750Options |= EOptionKeepUncalled ; 751} else if ( lowerword == "nan-clamp" ) { 752NaNClamp = true ; 753} else if ( lowerword == "no-storage-format" || // synonyms 754lowerword == "nsf" ) { 755Options |= EOptionNoStorageFormat ; 756} else if ( lowerword == "preamble-text" || 757lowerword == "p" ) { 758if ( argc > 1 ) 759UserPreamble . addText ( argv [ 1 ]) ; 760else 761Error ( "expects <text>" , argv [ 0 ]) ; 762bumpArg () ; 763} else if ( lowerword == "relaxed-errors" ) { 764Options |= EOptionRelaxedErrors ; 765} else if ( lowerword == "reflect-strict-array-suffix" ) { 766ReflectOptions |= EShReflectionStrictArraySuffix ; 767} else if ( lowerword == "reflect-basic-array-suffix" ) { 768ReflectOptions |= EShReflectionBasicArraySuffix ; 769} else if ( lowerword == "reflect-intermediate-io" ) { 770ReflectOptions |= EShReflectionIntermediateIO ; 771} else if ( lowerword == "reflect-separate-buffers" ) { 772ReflectOptions |= EShReflectionSeparateBuffers ; 773} else if ( lowerword == "reflect-all-block-variables" ) { 774ReflectOptions |= EShReflectionAllBlockVariables ; 775} else if ( lowerword == "reflect-unwrap-io-blocks" ) { 776ReflectOptions |= EShReflectionUnwrapIOBlocks ; 777} else if ( lowerword == "reflect-all-io-variables" ) { 778ReflectOptions |= EShReflectionAllIOVariables ; 779} else if ( lowerword == "reflect-shared-std140-ubo" ) { 780ReflectOptions |= EShReflectionSharedStd140UBO ; 781} else if ( lowerword == "reflect-shared-std140-ssbo" ) { 782ReflectOptions |= EShReflectionSharedStd140SSBO ; 783} else if ( lowerword == "resource-set-bindings" || // synonyms 784lowerword == "resource-set-binding" || 785lowerword == "rsb" ) { 786ProcessResourceSetBindingBase ( argc , argv , baseResourceSetBinding ) ; 787} else if ( lowerword == "set-block-storage" || 788lowerword == "sbs" ) { 789ProcessBlockStorage ( argc , argv , blockStorageOverrides ) ; 790} else if ( lowerword == "set-atomic-counter-block" || 791lowerword == "sacb" ) { 792ProcessGlobalBlockSettings ( argc , argv , & atomicCounterBlockName , & atomicCounterBlockSet , nullptr ) ; 793setGlobalBufferBlock = true ; 794} else if ( lowerword == "set-default-uniform-block" || 795lowerword == "sdub" ) { 796ProcessGlobalBlockSettings ( argc , argv , & globalUniformName , & globalUniformSet , & globalUniformBinding ) ; 797setGlobalUniformBlock = true ; 798} else if ( lowerword == "shift-image-bindings" || // synonyms 799lowerword == "shift-image-binding" || 800lowerword == "sib" ) { 801ProcessBindingBase ( argc , argv , glslang :: EResImage ) ; 802} else if ( lowerword == "shift-sampler-bindings" || // synonyms 803lowerword == "shift-sampler-binding" || 804lowerword == "ssb" ) { 805ProcessBindingBase ( argc , argv , glslang :: EResSampler ) ; 806} else if ( lowerword == "shift-uav-bindings" || // synonyms 807lowerword == "shift-uav-binding" || 808lowerword == "suavb" ) { 809ProcessBindingBase ( argc , argv , glslang :: EResUav ) ; 810} else if ( lowerword == "shift-texture-bindings" || // synonyms 811lowerword == "shift-texture-binding" || 812lowerword == "stb" ) { 813ProcessBindingBase ( argc , argv , glslang :: EResTexture ) ; 814} else if ( lowerword == "shift-ubo-bindings" || // synonyms 815lowerword == "shift-ubo-binding" || 816lowerword == "shift-cbuffer-bindings" || 817lowerword == "shift-cbuffer-binding" || 818lowerword == "sub" || 819lowerword == "scb" ) { 820ProcessBindingBase ( argc , argv , glslang :: EResUbo ) ; 821} else if ( lowerword == "shift-ssbo-bindings" || // synonyms 822lowerword == "shift-ssbo-binding" || 823lowerword == "sbb" ) { 824ProcessBindingBase ( argc , argv , glslang :: EResSsbo ) ; 825} else if ( lowerword == "shift-combined-sampler-bindings" || 826lowerword == "shift-combined-sampler-binding" || 827lowerword == "scsb" ) { 828ProcessBindingBase ( argc , argv , glslang :: EResCombinedSampler ) ; 829} else if ( lowerword == "shift-as-bindings" || 830lowerword == "shift-as-binding" || 831lowerword == "sab" ) { 832ProcessBindingBase ( argc , argv , glslang :: EResAs ) ; 833} else if ( lowerword == "source-entrypoint" || // synonyms 834lowerword == "sep" ) { 835if ( argc <= 1 ) 836Error ( "no <entry-point> provided" , lowerword . c_str ()) ; 837sourceEntryPointName = argv [ 1 ] ; 838bumpArg () ; 839break ; 840} else if ( lowerword == "spirv-dis" ) { 841SpvToolsDisassembler = true ; 842} else if ( lowerword == "spirv-val" ) { 843SpvToolsValidate = true ; 844} else if ( lowerword == "stdin" ) { 845Options |= EOptionStdin ; 846shaderStageName = argv [ 1 ] ; 847} else if ( lowerword == "suppress-warnings" ) { 848Options |= EOptionSuppressWarnings ; 849} else if ( lowerword == "target-env" ) { 850if ( argc > 1 ) { 851if ( strcmp ( argv [ 1 ] , "vulkan1.0" ) == 0 ) { 852setVulkanSpv () ; 853ClientVersion = glslang :: EShTargetVulkan_1_0 ; 854} else if ( strcmp ( argv [ 1 ] , "vulkan1.1" ) == 0 ) { 855setVulkanSpv () ; 856ClientVersion = glslang :: EShTargetVulkan_1_1 ; 857} else if ( strcmp ( argv [ 1 ] , "vulkan1.2" ) == 0 ) { 858setVulkanSpv () ; 859ClientVersion = glslang :: EShTargetVulkan_1_2 ; 860} else if ( strcmp ( argv [ 1 ] , "vulkan1.3" ) == 0 ) { 861setVulkanSpv () ; 862ClientVersion = glslang :: EShTargetVulkan_1_3 ; 863} else if ( strcmp ( argv [ 1 ] , "vulkan1.4" ) == 0 ) { 864setVulkanSpv () ; 865ClientVersion = glslang :: EShTargetVulkan_1_4 ; 866} else if ( strcmp ( argv [ 1 ] , "opengl" ) == 0 ) { 867setOpenGlSpv () ; 868ClientVersion = glslang :: EShTargetOpenGL_450 ; 869} else if ( strcmp ( argv [ 1 ] , "spirv1.0" ) == 0 ) { 870TargetLanguage = glslang :: EShTargetSpv ; 871TargetVersion = glslang :: EShTargetSpv_1_0 ; 872} else if ( strcmp ( argv [ 1 ] , "spirv1.1" ) == 0 ) { 873TargetLanguage = glslang :: EShTargetSpv ; 874TargetVersion = glslang :: EShTargetSpv_1_1 ; 875} else if ( strcmp ( argv [ 1 ] , "spirv1.2" ) == 0 ) { 876TargetLanguage = glslang :: EShTargetSpv ; 877TargetVersion = glslang :: EShTargetSpv_1_2 ; 878} else if ( strcmp ( argv [ 1 ] , "spirv1.3" ) == 0 ) { 879TargetLanguage = glslang :: EShTargetSpv ; 880TargetVersion = glslang :: EShTargetSpv_1_3 ; 881} else if ( strcmp ( argv [ 1 ] , "spirv1.4" ) == 0 ) { 882TargetLanguage = glslang :: EShTargetSpv ; 883TargetVersion = glslang :: EShTargetSpv_1_4 ; 884} else if ( strcmp ( argv [ 1 ] , "spirv1.5" ) == 0 ) { 885TargetLanguage = glslang :: EShTargetSpv ; 886TargetVersion = glslang :: EShTargetSpv_1_5 ; 887} else if ( strcmp ( argv [ 1 ] , "spirv1.6" ) == 0 ) { 888TargetLanguage = glslang :: EShTargetSpv ; 889TargetVersion = glslang :: EShTargetSpv_1_6 ; 890} else 891Error ( "--target-env expected one of: vulkan1.0, vulkan1.1, vulkan1.2, \n " 892"vulkan1.3, vulkan1.4, opengl, spirv1.0, spirv1.1, spirv1.2, spirv1.3, \n " 893"spirv1.4, spirv1.5 or spirv1.6" ) ; 894} 895bumpArg () ; 896} else if ( lowerword == "undef-macro" || 897lowerword == "u" ) { 898if ( argc > 1 ) 899UserPreamble . addUndef ( argv [ 1 ]) ; 900else 901Error ( "expects <name>" , argv [ 0 ]) ; 902bumpArg () ; 903} else if ( lowerword == "variable-name" || // synonyms 904lowerword == "vn" ) { 905Options |= EOptionOutputHexadecimal ; 906if ( argc <= 1 ) 907Error ( "no <C-variable-name> provided" , lowerword . c_str ()) ; 908variableName = argv [ 1 ] ; 909bumpArg () ; 910break ; 911} else if ( lowerword == "quiet" ) { 912beQuiet = true ; 913} else if ( lowerword == "depfile" ) { 914if ( argc <= 1 ) 915Error ( "no <depfile-name> provided" , lowerword . c_str ()) ; 916depencyFileName = argv [ 1 ] ; 917bumpArg () ; 918} else if ( lowerword == "version" ) { 919Options |= EOptionDumpVersions ; 920} else if ( lowerword == "no-link" ) { 921Options |= EOptionCompileOnly ; 922} else if ( lowerword == "error-column" ) { 923Options |= EOptionDisplayErrorColumn ; 924} else if ( lowerword == "lto" ) { 925Options |= EOptionLinkTimeOptimization ; 926} else if ( lowerword == "validate-io" ) { 927Options |= EOptionValidateCrossStageIO ; 928} else if ( lowerword == "bindings-per-resource-type" ) { 929Options |= EOptionBindingsPerResourceType ; 930} else if ( lowerword == "help" ) { 931usage () ; 932break ; 933} else { 934Error ( "unrecognized command-line option" , argv [ 0 ]) ; 935} 936} 937break ; 938case 'C' : 939Options |= EOptionCascadingErrors ; 940break ; 941case 'D' : 942if ( argv [ 0 ][ 2 ] == 0 ) 943Options |= EOptionReadHlsl ; 944else 945UserPreamble . addDef ( getStringOperand ( "-D<name[=def]>" )) ; 946break ; 947case 'u' : 948uniformLocationOverrides . push_back ( getUniformOverride ()) ; 949break ; 950case 'E' : 951Options |= EOptionOutputPreprocessed ; 952break ; 953case 'G' : 954// OpenGL client 955setOpenGlSpv () ; 956if ( argv [ 0 ][ 2 ] != 0 ) 957ClientInputSemanticsVersion = getAttachedNumber ( "-G<num> client input semantics" ) ; 958if ( ClientInputSemanticsVersion != 100 ) 959Error ( "unknown client version for -G, should be 100" ) ; 960break ; 961case 'H' : 962Options |= EOptionHumanReadableSpv ; 963if (( Options & EOptionSpv ) == 0 ) { 964// default to Vulkan 965setVulkanSpv () ; 966} 967break ; 968case 'I' : 969IncludeDirectoryList . push_back ( getStringOperand ( "-I<dir> include path" )) ; 970break ; 971case 'O' : 972if ( argv [ 0 ][ 2 ] == 'd' ) 973Options |= EOptionOptimizeDisable ; 974else if ( argv [ 0 ][ 2 ] == 's' ) 975#if ENABLE_OPT 976Options |= EOptionOptimizeSize ; 977#else 978Error ( "-Os not available; optimizer not linked" ) ; 979#endif 980else 981Error ( "unknown -O option" ) ; 982break ; 983case 'P' : 984UserPreamble . addText ( getStringOperand ( "-P<text>" )) ; 985break ; 986case 'R' : 987VulkanRulesRelaxed = true ; 988break ; 989case 'S' : 990if ( argc <= 1 ) 991Error ( "no <stage> specified for -S" ) ; 992shaderStageName = argv [ 1 ] ; 993bumpArg () ; 994break ; 995case 'U' : 996UserPreamble . addUndef ( getStringOperand ( "-U<name>" )) ; 997break ; 998case 'V' : 999setVulkanSpv () ; 1000if ( argv [ 0 ][ 2 ] != 0 ) 1001ClientInputSemanticsVersion = getAttachedNumber ( "-V<num> client input semantics" ) ; 1002if ( ClientInputSemanticsVersion != 100 ) 1003Error ( "unknown client version for -V, should be 100" ) ; 1004break ; 1005case 'c' : 1006Options |= EOptionDumpConfig ; 1007break ; 1008case 'd' : 1009if ( strncmp ( & argv [ 0 ][ 1 ] , "dumpversion" , strlen ( & argv [ 0 ][ 1 ]) + 1 ) == 0 || 1010strncmp ( & argv [ 0 ][ 1 ] , "dumpfullversion" , strlen ( & argv [ 0 ][ 1 ]) + 1 ) == 0 ) 1011Options |= EOptionDumpBareVersion ; 1012else 1013Options |= EOptionDefaultDesktop ; 1014break ; 1015case 'e' : 1016entryPointName = argv [ 1 ] ; 1017if ( argc <= 1 ) 1018Error ( "no <name> provided for -e" ) ; 1019bumpArg () ; 1020break ; 1021case 'f' : 1022if ( strcmp ( & argv [ 0 ][ 2 ] , "hlsl_functionality1" ) == 0 ) 1023targetHlslFunctionality1 = true ; 1024else 1025Error ( "-f: expected hlsl_functionality1" ) ; 1026break ; 1027case 'g' : 1028// Override previous -g or -g0 argument 1029stripDebugInfo = false ; 1030emitNonSemanticShaderDebugInfo = false ; 1031Options &= ~ EOptionDebug ; 1032if ( argv [ 0 ][ 2 ] == '0' ) 1033stripDebugInfo = true ; 1034else { 1035Options |= EOptionDebug ; 1036if ( argv [ 0 ][ 2 ] == 'V' ) { 1037emitNonSemanticShaderDebugInfo = true ; 1038if ( argv [ 0 ][ 3 ] == 'S' ) { 1039emitNonSemanticShaderDebugSource = true ; 1040} else { 1041emitNonSemanticShaderDebugSource = false ; 1042} 1043} 1044} 1045break ; 1046case 'h' : 1047usage () ; 1048break ; 1049case 'i' : 1050Options |= EOptionIntermediate ; 1051break ; 1052case 'l' : 1053Options |= EOptionLinkProgram ; 1054break ; 1055case 'm' : 1056Options |= EOptionMemoryLeakMode ; 1057break ; 1058case 'o' : 1059if ( argc <= 1 ) 1060Error ( "no <file> provided for -o" ) ; 1061binaryFileName = argv [ 1 ] ; 1062bumpArg () ; 1063break ; 1064case 'q' : 1065Options |= EOptionDumpReflection ; 1066break ; 1067case 'r' : 1068Options |= EOptionRelaxedErrors ; 1069break ; 1070case 's' : 1071Options |= EOptionSuppressInfolog ; 1072break ; 1073case 't' : 1074Options |= EOptionMultiThreaded ; 1075break ; 1076case 'v' : 1077Options |= EOptionDumpVersions ; 1078break ; 1079case 'w' : 1080Options |= EOptionSuppressWarnings ; 1081break ; 1082case 'x' : 1083Options |= EOptionOutputHexadecimal ; 1084break ; 1085default : 1086Error ( "unrecognized command-line option" , argv [ 0 ]) ; 1087break ; 1088} 1089} else { 1090std :: string name ( argv [ 0 ]) ; 1091if ( ! SetConfigFile ( name )) { 1092workItems . push_back ( std :: unique_ptr < glslang :: TWorkItem > ( new glslang :: TWorkItem ( name ))) ; 1093} 1094} 1095} 1096 1097// Make sure that -S is always specified if --stdin is specified 1098if (( Options & EOptionStdin ) && shaderStageName == nullptr ) 1099Error ( "must provide -S when --stdin is given" ) ; 1100 1101// Make sure that -E is not specified alongside linking (which includes SPV generation) 1102// Or things that require linking 1103if ( Options & EOptionOutputPreprocessed ) { 1104if ( Options & EOptionLinkProgram ) 1105Error ( "can't use -E when linking is selected" ) ; 1106if ( Options & EOptionDumpReflection ) 1107Error ( "reflection requires linking, which can't be used when -E when is selected" ) ; 1108} 1109 1110// reflection requires linking 1111if (( Options & EOptionDumpReflection ) && ! ( Options & EOptionLinkProgram )) 1112Error ( "reflection requires -l for linking" ) ; 1113 1114// link time optimization makes no sense unless linking 1115if (( Options & EOptionLinkTimeOptimization ) && ! ( Options & EOptionLinkProgram )) 1116Error ( "link time optimization requires -l for linking" ) ; 1117 1118// cross stage IO validation makes no sense unless linking 1119if (( Options & EOptionValidateCrossStageIO ) && ! ( Options & EOptionLinkProgram )) 1120Error ( "cross stage IO validation requires -l for linking" ) ; 1121 1122// -o or -x makes no sense if there is no target binary 1123if ( binaryFileName && ( Options & EOptionSpv ) == 0 ) 1124Error ( "no binary generation requested (e.g., -V)" ) ; 1125 1126if (( Options & EOptionFlattenUniformArrays ) != 0 && 1127( Options & EOptionReadHlsl ) == 0 ) 1128Error ( "uniform array flattening only valid when compiling HLSL source." ) ; 1129 1130if (( Options & EOptionReadHlsl ) && ( Client == glslang :: EShClientOpenGL )) { 1131Error ( "Using HLSL input under OpenGL semantics is not currently supported." ) ; 1132} 1133 1134// rationalize client and target language 1135if ( TargetLanguage == glslang :: EShTargetNone ) { 1136switch ( ClientVersion ) { 1137case glslang :: EShTargetVulkan_1_0 : 1138TargetLanguage = glslang :: EShTargetSpv ; 1139TargetVersion = glslang :: EShTargetSpv_1_0 ; 1140break ; 1141case glslang :: EShTargetVulkan_1_1 : 1142TargetLanguage = glslang :: EShTargetSpv ; 1143TargetVersion = glslang :: EShTargetSpv_1_3 ; 1144break ; 1145case glslang :: EShTargetVulkan_1_2 : 1146TargetLanguage = glslang :: EShTargetSpv ; 1147TargetVersion = glslang :: EShTargetSpv_1_5 ; 1148break ; 1149case glslang :: EShTargetVulkan_1_3 : 1150TargetLanguage = glslang :: EShTargetSpv ; 1151TargetVersion = glslang :: EShTargetSpv_1_6 ; 1152break ; 1153case glslang :: EShTargetVulkan_1_4 : 1154TargetLanguage = glslang :: EShTargetSpv ; 1155TargetVersion = glslang :: EShTargetSpv_1_6 ; 1156break ; 1157case glslang :: EShTargetOpenGL_450 : 1158TargetLanguage = glslang :: EShTargetSpv ; 1159TargetVersion = glslang :: EShTargetSpv_1_0 ; 1160break ; 1161default : 1162break ; 1163} 1164} 1165if ( TargetLanguage != glslang :: EShTargetNone && Client == glslang :: EShClientNone ) 1166Error ( "To generate SPIR-V, also specify client semantics. See -G and -V." ) ; 1167} 1168 1169// 1170// Translate the meaningful subset of command-line options to parser-behavior options. 1171// 1172void SetMessageOptions ( EShMessages & messages ) 1173{ 1174if ( Options & EOptionRelaxedErrors ) 1175messages = ( EShMessages )( messages | EShMsgRelaxedErrors ) ; 1176if ( Options & EOptionIntermediate ) 1177messages = ( EShMessages )( messages | EShMsgAST ) ; 1178if ( Options & EOptionSuppressWarnings ) 1179messages = ( EShMessages )( messages | EShMsgSuppressWarnings ) ; 1180if ( Options & EOptionSpv ) 1181messages = ( EShMessages )( messages | EShMsgSpvRules ) ; 1182if ( Options & EOptionVulkanRules ) 1183messages = ( EShMessages )( messages | EShMsgVulkanRules ) ; 1184if ( Options & EOptionOutputPreprocessed ) 1185messages = ( EShMessages )( messages | EShMsgOnlyPreprocessor ) ; 1186if ( Options & EOptionReadHlsl ) 1187messages = ( EShMessages )( messages | EShMsgReadHlsl ) ; 1188if ( Options & EOptionCascadingErrors ) 1189messages = ( EShMessages )( messages | EShMsgCascadingErrors ) ; 1190if ( Options & EOptionKeepUncalled ) 1191messages = ( EShMessages )( messages | EShMsgKeepUncalled ) ; 1192if ( Options & EOptionHlslOffsets ) 1193messages = ( EShMessages )( messages | EShMsgHlslOffsets ) ; 1194if ( Options & EOptionDebug ) 1195messages = ( EShMessages )( messages | EShMsgDebugInfo ) ; 1196if ( HlslEnable16BitTypes ) 1197messages = ( EShMessages )( messages | EShMsgHlslEnable16BitTypes ) ; 1198if (( Options & EOptionOptimizeDisable ) || ! ENABLE_OPT ) 1199messages = ( EShMessages )( messages | EShMsgHlslLegalization ) ; 1200if ( HlslDX9compatible ) 1201messages = ( EShMessages )( messages | EShMsgHlslDX9Compatible ) ; 1202if ( DumpBuiltinSymbols ) 1203messages = ( EShMessages )( messages | EShMsgBuiltinSymbolTable ) ; 1204if ( EnhancedMsgs ) 1205messages = ( EShMessages )( messages | EShMsgEnhanced ) ; 1206if ( AbsolutePath ) 1207messages = ( EShMessages )( messages | EShMsgAbsolutePath ) ; 1208if ( Options & EOptionDisplayErrorColumn ) 1209messages = ( EShMessages )( messages | EShMsgDisplayErrorColumn ) ; 1210if ( Options & EOptionLinkTimeOptimization ) 1211messages = ( EShMessages )( messages | EShMsgLinkTimeOptimization ) ; 1212if ( Options & EOptionValidateCrossStageIO ) 1213messages = ( EShMessages )( messages | EShMsgValidateCrossStageIO ) ; 1214if ( Options & EOptionRelaxSetBindingLimits ) 1215messages = ( EShMessages )( messages | EShMsgRelaxSetBindingLimits ) ; 1216} 1217 1218// 1219// Thread entry point, for non-linking asynchronous mode. 1220// 1221void CompileShaders ( glslang :: TWorklist & worklist ) 1222{ 1223if ( Options & EOptionDebug ) 1224Error ( "cannot generate debug information unless linking to generate code" ) ; 1225 1226// NOTE: TWorkList::remove is thread-safe 1227glslang :: TWorkItem * workItem ; 1228if ( Options & EOptionStdin ) { 1229if ( worklist . remove ( workItem )) { 1230ShHandle compiler = ShConstructCompiler ( FindLanguage ( "stdin" ) , 0 ) ; 1231if ( compiler == nullptr ) 1232return ; 1233 1234CompileFile ( "stdin" , compiler ) ; 1235 1236if ( ! ( Options & EOptionSuppressInfolog )) 1237workItem -> results = ShGetInfoLog ( compiler ) ; 1238 1239ShDestruct ( compiler ) ; 1240} 1241} else { 1242while ( worklist . remove ( workItem )) { 1243ShHandle compiler = ShConstructCompiler ( FindLanguage ( workItem -> name ) , 0 ) ; 1244if ( compiler == nullptr ) 1245return ; 1246 1247 1248CompileFile ( workItem -> name . c_str () , compiler ) ; 1249 1250if ( ! ( Options & EOptionSuppressInfolog )) 1251workItem -> results = ShGetInfoLog ( compiler ) ; 1252 1253ShDestruct ( compiler ) ; 1254} 1255} 1256} 1257 1258// Outputs the given string, but only if it is non-null and non-empty. 1259// This prevents erroneous newlines from appearing. 1260void PutsIfNonEmpty ( const char * str ) 1261{ 1262if ( str && str [ 0 ]) { 1263puts ( str ) ; 1264} 1265} 1266 1267// Outputs the given string to stderr, but only if it is non-null and non-empty. 1268// This prevents erroneous newlines from appearing. 1269void StderrIfNonEmpty ( const char * str ) 1270{ 1271if ( str && str [ 0 ]) 1272fprintf ( stderr , "%s \n " , str ) ; 1273} 1274 1275// Simple bundling of what makes a compilation unit for ease in passing around, 1276// and separation of handling file IO versus API (programmatic) compilation. 1277struct ShaderCompUnit { 1278EShLanguage stage ; 1279static const int maxCount = 1 ; 1280int count ; // live number of strings/names 1281const char * text [ maxCount ] ; // memory owned/managed externally 1282std :: string fileName [ maxCount ] ; // hold's the memory, but... 1283const char * fileNameList [ maxCount ] ; // downstream interface wants pointers 1284 1285ShaderCompUnit ( EShLanguage stage ) : stage ( stage ) , count ( 0 ) { } 1286 1287ShaderCompUnit ( const ShaderCompUnit & rhs ) 1288{ 1289stage = rhs . stage ; 1290count = rhs . count ; 1291for ( int i = 0 ; i < count ; ++ i ) { 1292fileName [ i ] = rhs . fileName [ i ] ; 1293text [ i ] = rhs . text [ i ] ; 1294fileNameList [ i ] = rhs . fileName [ i ] . c_str () ; 1295} 1296} 1297 1298void addString ( std :: string & ifileName , const char * itext ) 1299{ 1300assert ( count < maxCount ) ; 1301fileName [ count ] = ifileName ; 1302text [ count ] = itext ; 1303fileNameList [ count ] = fileName [ count ] . c_str () ; 1304++ count ; 1305} 1306} ; 1307 1308// Writes a string into a depfile, escaping some special characters following the Makefile rules. 1309static void writeEscapedDepString ( std :: ofstream & file , const std :: string & str ) 1310{ 1311for ( char c : str ) { 1312switch ( c ) { 1313case ' ' : 1314case ':' : 1315case '#' : 1316case '[' : 1317case ']' : 1318case ' \\ ' : 1319file << ' \\ ' ; 1320break ; 1321case '$' : 1322file << '$' ; 1323break ; 1324} 1325file << c ; 1326} 1327} 1328 1329// Writes a depfile similar to gcc -MMD foo.c 1330bool writeDepFile ( std :: string depfile , std :: vector < std :: string >& binaryFiles , const std :: vector < std :: string >& sources ) 1331{ 1332std :: ofstream file ( depfile ) ; 1333if ( file . fail ()) 1334return false ; 1335 1336for ( auto binaryFile = binaryFiles . begin () ; binaryFile != binaryFiles . end () ; binaryFile ++ ) { 1337writeEscapedDepString ( file , * binaryFile ) ; 1338file << ":" ; 1339for ( auto sourceFile = sources . begin () ; sourceFile != sources . end () ; sourceFile ++ ) { 1340file << " " ; 1341writeEscapedDepString ( file , * sourceFile ) ; 1342} 1343file << std :: endl ; 1344} 1345return true ; 1346} 1347 1348// 1349// For linking mode: Will independently parse each compilation unit, but then put them 1350// in the same program and link them together, making at most one linked module per 1351// pipeline stage. 1352// 1353// Uses the new C++ interface instead of the old handle-based interface. 1354// 1355 1356void CompileAndLinkShaderUnits ( std :: vector < ShaderCompUnit > compUnits ) 1357{ 1358// keep track of what to free 1359std :: list < glslang :: TShader *> shaders ; 1360 1361EShMessages messages = EShMsgDefault ; 1362SetMessageOptions ( messages ) ; 1363 1364DirStackFileIncluder includer ; 1365std :: for_each ( IncludeDirectoryList . begin () , IncludeDirectoryList . end () , [ & includer ]( const std :: string & dir ) { 1366includer . pushExternalDirectory ( dir ) ; }) ; 1367 1368std :: vector < std :: string > sources ; 1369 1370// 1371// Per-shader processing... 1372// 1373 1374glslang :: TProgram & program = * new glslang :: TProgram ; 1375const bool compileOnly = ( Options & EOptionCompileOnly ) != 0 ; 1376for ( auto it = compUnits . cbegin () ; it != compUnits . cend () ; ++ it ) { 1377const auto & compUnit = * it ; 1378for ( int i = 0 ; i < compUnit . count ; i ++ ) { 1379sources . push_back ( compUnit . fileNameList [ i ]) ; 1380} 1381glslang :: TShader * shader = new glslang :: TShader ( compUnit . stage ) ; 1382shader -> setStringsWithLengthsAndNames ( compUnit . text , nullptr , compUnit . fileNameList , compUnit . count ) ; 1383if ( entryPointName ) 1384shader -> setEntryPoint ( entryPointName ) ; 1385if ( sourceEntryPointName ) { 1386if ( entryPointName == nullptr ) 1387printf ( "Warning: Changing source entry point name without setting an entry-point name. \n " 1388"Use '-e <name>'. \n " ) ; 1389shader -> setSourceEntryPoint ( sourceEntryPointName ) ; 1390} 1391 1392if ( compileOnly ) 1393shader -> setCompileOnly () ; 1394 1395shader -> setOverrideVersion ( GlslVersion ) ; 1396 1397std :: string intrinsicString = getIntrinsic ( compUnit . text , compUnit . count ) ; 1398 1399PreambleString = "" ; 1400if ( UserPreamble . isSet ()) 1401PreambleString . append ( UserPreamble . get ()) ; 1402 1403if ( ! intrinsicString . empty ()) 1404PreambleString . append ( intrinsicString ) ; 1405 1406shader -> setPreamble ( PreambleString . c_str ()) ; 1407shader -> addProcesses ( Processes ) ; 1408 1409// Set IO mapper binding shift values 1410for ( int r = 0 ; r < glslang :: EResCount ; ++ r ) { 1411const glslang :: TResourceType res = glslang :: TResourceType ( r ) ; 1412 1413// Set base bindings 1414shader -> setShiftBinding ( res , baseBinding [ res ][ compUnit . stage ]) ; 1415 1416// Set bindings for particular resource sets 1417// TODO: use a range based for loop here, when available in all environments. 1418for ( auto i = baseBindingForSet [ res ][ compUnit . stage ] . begin () ; 1419i != baseBindingForSet [ res ][ compUnit . stage ] . end () ; ++ i ) 1420shader -> setShiftBindingForSet ( res , i -> second , i -> first ) ; 1421} 1422shader -> setNoStorageFormat (( Options & EOptionNoStorageFormat ) != 0 ) ; 1423shader -> setResourceSetBinding ( baseResourceSetBinding [ compUnit . stage ]) ; 1424 1425if ( autoSampledTextures ) 1426shader -> setTextureSamplerTransformMode ( EShTexSampTransUpgradeTextureRemoveSampler ) ; 1427 1428if ( Options & EOptionAutoMapBindings ) 1429shader -> setAutoMapBindings ( true ) ; 1430 1431if ( Options & EOptionAutoMapLocations ) 1432shader -> setAutoMapLocations ( true ) ; 1433 1434for ( auto & uniOverride : uniformLocationOverrides ) { 1435shader -> addUniformLocationOverride ( uniOverride . first . c_str () , 1436uniOverride . second ) ; 1437} 1438 1439shader -> setUniformLocationBase ( uniformBase ) ; 1440 1441if ( VulkanRulesRelaxed ) { 1442for ( auto & storageOverride : blockStorageOverrides ) { 1443shader -> addBlockStorageOverride ( storageOverride . first . c_str () , 1444storageOverride . second ) ; 1445} 1446 1447if ( setGlobalBufferBlock ) { 1448shader -> setAtomicCounterBlockName ( atomicCounterBlockName . c_str ()) ; 1449shader -> setAtomicCounterBlockSet ( atomicCounterBlockSet ) ; 1450} 1451 1452if ( setGlobalUniformBlock ) { 1453shader -> setGlobalUniformBlockName ( globalUniformName . c_str ()) ; 1454shader -> setGlobalUniformSet ( globalUniformSet ) ; 1455shader -> setGlobalUniformBinding ( globalUniformBinding ) ; 1456} 1457} 1458 1459shader -> setNanMinMaxClamp ( NaNClamp ) ; 1460 1461#ifdef ENABLE_HLSL 1462shader -> setFlattenUniformArrays (( Options & EOptionFlattenUniformArrays ) != 0 ) ; 1463if ( Options & EOptionHlslIoMapping ) 1464shader -> setHlslIoMapping ( true ) ; 1465#endif 1466 1467if ( Options & EOptionInvertY ) 1468shader -> setInvertY ( true ) ; 1469 1470if ( HlslDxPositionW ) 1471shader -> setDxPositionW ( true ) ; 1472 1473if ( EnhancedMsgs ) 1474shader -> setEnhancedMsgs () ; 1475 1476if ( emitNonSemanticShaderDebugInfo ) 1477shader -> setDebugInfo ( true ) ; 1478 1479if ( Options & EOptionBindingsPerResourceType ) 1480shader -> setBindingsPerResourceType () ; 1481 1482if ( Options & EOptionDiscardIsTerminate ) 1483shader -> setDiscardIsTerminate ( true ) ; 1484 1485// Set up the environment, some subsettings take precedence over earlier 1486// ways of setting things. 1487if ( Options & EOptionSpv ) { 1488shader -> setEnvInput (( Options & EOptionReadHlsl ) ? glslang :: EShSourceHlsl 1489: glslang :: EShSourceGlsl , 1490compUnit . stage , Client , ClientInputSemanticsVersion ) ; 1491shader -> setEnvClient ( Client , ClientVersion ) ; 1492shader -> setEnvTarget ( TargetLanguage , TargetVersion ) ; 1493#ifdef ENABLE_HLSL 1494if ( targetHlslFunctionality1 ) 1495shader -> setEnvTargetHlslFunctionality1 () ; 1496#endif 1497if ( VulkanRulesRelaxed ) 1498shader -> setEnvInputVulkanRulesRelaxed () ; 1499} 1500 1501shaders . push_back ( shader ) ; 1502 1503const int defaultVersion = Options & EOptionDefaultDesktop ? 110 : 100 ; 1504 1505if ( Options & EOptionOutputPreprocessed ) { 1506std :: string str ; 1507if ( shader -> preprocess ( GetResources () , defaultVersion , ENoProfile , false , false , messages , & str , includer )) { 1508PutsIfNonEmpty ( str . c_str ()) ; 1509} else { 1510CompileFailed = 1 ; 1511} 1512StderrIfNonEmpty ( shader -> getInfoLog ()) ; 1513StderrIfNonEmpty ( shader -> getInfoDebugLog ()) ; 1514continue ; 1515} 1516 1517if ( ! shader -> parse ( GetResources () , defaultVersion , false , messages , includer )) 1518CompileFailed = 1 ; 1519 1520if ( ! compileOnly ) 1521program . addShader ( shader ) ; 1522 1523if ( ! ( Options & EOptionSuppressInfolog ) && 1524! ( Options & EOptionMemoryLeakMode )) { 1525if ( ! beQuiet ) 1526PutsIfNonEmpty ( compUnit . fileName [ 0 ] . c_str ()) ; 1527PutsIfNonEmpty ( shader -> getInfoLog ()) ; 1528PutsIfNonEmpty ( shader -> getInfoDebugLog ()) ; 1529} 1530} 1531 1532// 1533// Program-level processing... 1534// 1535 1536if ( ! compileOnly ) { 1537// Link 1538if ( ! ( Options & EOptionOutputPreprocessed ) && ! program . link ( messages )) 1539LinkFailed = true ; 1540 1541// Map IO 1542if ( Options & EOptionSpv ) { 1543if ( ! program . mapIO ()) 1544LinkFailed = true ; 1545} 1546 1547// Report 1548if ( ! ( Options & EOptionSuppressInfolog ) && ! ( Options & EOptionMemoryLeakMode )) { 1549PutsIfNonEmpty ( program . getInfoLog ()) ; 1550PutsIfNonEmpty ( program . getInfoDebugLog ()) ; 1551} 1552 1553// Reflect 1554if ( Options & EOptionDumpReflection ) { 1555program . buildReflection ( ReflectOptions ) ; 1556program . dumpReflection () ; 1557} 1558} 1559 1560std :: vector < std :: string > outputFiles ; 1561 1562// Dump SPIR-V 1563if ( Options & EOptionSpv ) { 1564#ifdef ENABLE_SPIRV 1565CompileOrLinkFailed . fetch_or ( CompileFailed ) ; 1566CompileOrLinkFailed . fetch_or ( LinkFailed ) ; 1567if ( static_cast < bool > ( CompileOrLinkFailed . load ())) 1568printf ( "SPIR-V is not generated for failed compile or link \n " ) ; 1569else { 1570std :: vector < glslang :: TIntermediate *> intermediates ; 1571if ( ! compileOnly ) { 1572for ( int stage = 0 ; stage < EShLangCount ; ++ stage ) { 1573if ( auto * i = program . getIntermediate (( EShLanguage ) stage )) { 1574intermediates . emplace_back ( i ) ; 1575} 1576} 1577} else { 1578for ( const auto * shader : shaders ) { 1579if ( auto * i = shader -> getIntermediate ()) { 1580intermediates . emplace_back ( i ) ; 1581} 1582} 1583} 1584for ( auto * intermediate : intermediates ) { 1585std :: vector < unsigned int > spirv ; 1586spv :: SpvBuildLogger logger ; 1587glslang :: SpvOptions spvOptions ; 1588if ( Options & EOptionDebug ) { 1589spvOptions . generateDebugInfo = true ; 1590if ( emitNonSemanticShaderDebugInfo ) { 1591spvOptions . emitNonSemanticShaderDebugInfo = true ; 1592if ( emitNonSemanticShaderDebugSource ) { 1593spvOptions . emitNonSemanticShaderDebugSource = true ; 1594} 1595} 1596} else if ( stripDebugInfo ) 1597spvOptions . stripDebugInfo = true ; 1598spvOptions . disableOptimizer = ( Options & EOptionOptimizeDisable ) != 0 ; 1599spvOptions . optimizeSize = ( Options & EOptionOptimizeSize ) != 0 ; 1600spvOptions . disassemble = SpvToolsDisassembler ; 1601spvOptions . validate = SpvToolsValidate ; 1602spvOptions . compileOnly = compileOnly ; 1603glslang :: GlslangToSpv ( * intermediate , spirv , & logger , & spvOptions ) ; 1604 1605// Dump the spv to a file or stdout, etc., but only if not doing 1606// memory/perf testing, as it's not internal to programmatic use. 1607if ( ! ( Options & EOptionMemoryLeakMode )) { 1608printf ( "%s" , logger . getAllMessages () . c_str ()) ; 1609const auto filename = GetBinaryName ( intermediate -> getStage ()) ; 1610if ( Options & EOptionOutputHexadecimal ) { 1611if ( ! glslang :: OutputSpvHex ( spirv , filename , variableName )) 1612exit ( EFailUsage ) ; 1613} else { 1614if ( ! glslang :: OutputSpvBin ( spirv , filename )) 1615exit ( EFailUsage ) ; 1616} 1617 1618outputFiles . push_back ( filename ) ; 1619if ( ! SpvToolsDisassembler && ( Options & EOptionHumanReadableSpv )) 1620spv :: Disassemble ( std :: cout , spirv ) ; 1621} 1622} 1623} 1624#else 1625Error ( "This configuration of glslang does not have SPIR-V support" ) ; 1626#endif 1627} 1628 1629CompileOrLinkFailed . fetch_or ( CompileFailed ) ; 1630CompileOrLinkFailed . fetch_or ( LinkFailed ) ; 1631if ( depencyFileName && ! static_cast < bool > ( CompileOrLinkFailed . load ())) { 1632std :: set < std :: string > includedFiles = includer . getIncludedFiles () ; 1633sources . insert ( sources . end () , includedFiles . begin () , includedFiles . end ()) ; 1634 1635writeDepFile ( depencyFileName , outputFiles , sources ) ; 1636} 1637 1638// Free everything up, program has to go before the shaders 1639// because it might have merged stuff from the shaders, and 1640// the stuff from the shaders has to have its destructors called 1641// before the pools holding the memory in the shaders is freed. 1642delete & program ; 1643while ( shaders . size () > 0 ) { 1644delete shaders . back () ; 1645shaders . pop_back () ; 1646} 1647} 1648 1649// 1650// Do file IO part of compile and link, handing off the pure 1651// API/programmatic mode to CompileAndLinkShaderUnits(), which can 1652// be put in a loop for testing memory footprint and performance. 1653// 1654// This is just for linking mode: meaning all the shaders will be put into the 1655// the same program linked together. 1656// 1657// This means there are a limited number of work items (not multi-threading mode) 1658// and that the point is testing at the linking level. Hence, to enable 1659// performance and memory testing, the actual compile/link can be put in 1660// a loop, independent of processing the work items and file IO. 1661// 1662void CompileAndLinkShaderFiles ( glslang :: TWorklist & Worklist ) 1663{ 1664std :: vector < ShaderCompUnit > compUnits ; 1665 1666// If this is using stdin, we can't really detect multiple different file 1667// units by input type. We need to assume that we're just being given one 1668// file of a certain type. 1669if (( Options & EOptionStdin ) != 0 ) { 1670ShaderCompUnit compUnit ( FindLanguage ( "stdin" )) ; 1671std :: istreambuf_iterator < char > begin ( std :: cin ) , end ; 1672std :: string tempString ( begin , end ) ; 1673char * fileText = strdup ( tempString . c_str ()) ; 1674std :: string fileName = "stdin" ; 1675compUnit . addString ( fileName , fileText ) ; 1676compUnits . push_back ( compUnit ) ; 1677} else { 1678// Transfer all the work items from to a simple list of 1679// of compilation units. (We don't care about the thread 1680// work-item distribution properties in this path, which 1681// is okay due to the limited number of shaders, know since 1682// they are all getting linked together.) 1683glslang :: TWorkItem * workItem ; 1684while ( Worklist . remove ( workItem )) { 1685ShaderCompUnit compUnit ( FindLanguage ( workItem -> name )) ; 1686char * fileText = ReadFileData ( workItem -> name . c_str ()) ; 1687if ( fileText == nullptr ) 1688usage () ; 1689compUnit . addString ( workItem -> name , fileText ) ; 1690compUnits . push_back ( compUnit ) ; 1691} 1692} 1693 1694// Actual call to programmatic processing of compile and link, 1695// in a loop for testing memory and performance. This part contains 1696// all the perf/memory that a programmatic consumer will care about. 1697for ( int i = 0 ; i < (( Options & EOptionMemoryLeakMode ) ? 100 : 1 ) ; ++ i ) { 1698for ( int j = 0 ; j < (( Options & EOptionMemoryLeakMode ) ? 100 : 1 ) ; ++ j ) 1699CompileAndLinkShaderUnits ( compUnits ) ; 1700 1701if ( Options & EOptionMemoryLeakMode ) 1702glslang :: OS_DumpMemoryCounters () ; 1703} 1704 1705// free memory from ReadFileData, which got stored in a const char* 1706// as the first string above 1707for ( auto it = compUnits . begin () ; it != compUnits . end () ; ++ it ) 1708FreeFileData ( const_cast < char *> ( it -> text [ 0 ])) ; 1709} 1710 1711int singleMain () 1712{ 1713glslang :: TWorklist workList ; 1714std :: for_each ( WorkItems . begin () , WorkItems . end () , [ & workList ]( std :: unique_ptr < glslang :: TWorkItem >& item ) { 1715assert ( item ) ; 1716workList . add ( item . get ()) ; 1717}) ; 1718 1719if ( Options & EOptionDumpConfig ) { 1720printf ( "%s" , GetDefaultTBuiltInResourceString () . c_str ()) ; 1721if ( workList . empty ()) 1722return ESuccess ; 1723} 1724 1725if ( Options & EOptionDumpBareVersion ) { 1726int spirvGeneratorVersion = 0 ; 1727#ifdef ENABLE_SPIRV 1728spirvGeneratorVersion = glslang :: GetSpirvGeneratorVersion () ; 1729#endif 1730printf ( "%d:%d.%d.%d%s \n " , spirvGeneratorVersion , GLSLANG_VERSION_MAJOR , GLSLANG_VERSION_MINOR , 1731GLSLANG_VERSION_PATCH , GLSLANG_VERSION_FLAVOR ) ; 1732if ( workList . empty ()) 1733return ESuccess ; 1734} else if ( Options & EOptionDumpVersions ) { 1735int spirvGeneratorVersion = 0 ; 1736#ifdef ENABLE_SPIRV 1737spirvGeneratorVersion = glslang :: GetSpirvGeneratorVersion () ; 1738#endif 1739printf ( "Glslang Version: %d:%d.%d.%d%s \n " , spirvGeneratorVersion , GLSLANG_VERSION_MAJOR , 1740GLSLANG_VERSION_MINOR , GLSLANG_VERSION_PATCH , GLSLANG_VERSION_FLAVOR ) ; 1741printf ( "ESSL Version: %s \n " , glslang :: GetEsslVersionString ()) ; 1742printf ( "GLSL Version: %s \n " , glslang :: GetGlslVersionString ()) ; 1743std :: string spirvVersion ; 1744#if ENABLE_SPIRV 1745glslang :: GetSpirvVersion ( spirvVersion ) ; 1746#endif 1747printf ( "SPIR-V Version %s \n " , spirvVersion . c_str ()) ; 1748printf ( "GLSL.std.450 Version %d, Revision %d \n " , GLSLstd450Version , GLSLstd450Revision ) ; 1749printf ( "Khronos Tool ID %d \n " , glslang :: GetKhronosToolId ()) ; 1750printf ( "SPIR-V Generator Version %d \n " , spirvGeneratorVersion ) ; 1751printf ( "GL_KHR_vulkan_glsl version %d \n " , 100 ) ; 1752printf ( "ARB_GL_gl_spirv version %d \n " , 100 ) ; 1753if ( workList . empty ()) 1754return ESuccess ; 1755} 1756 1757if ( workList . empty () && (( Options & EOptionStdin ) == 0 )) { 1758usage () ; 1759} 1760 1761if ( Options & EOptionStdin ) { 1762WorkItems . push_back ( std :: unique_ptr < glslang :: TWorkItem > { new glslang :: TWorkItem ( "stdin" )}) ; 1763workList . add ( WorkItems . back () . get ()) ; 1764} 1765 1766ProcessConfigFile () ; 1767 1768if (( Options & EOptionReadHlsl ) && ! (( Options & EOptionOutputPreprocessed ) || ( Options & EOptionSpv ))) 1769Error ( "HLSL requires SPIR-V code generation (or preprocessing only)" ) ; 1770 1771// 1772// Two modes: 1773// 1) linking all arguments together, single-threaded, new C++ interface 1774// 2) independent arguments, can be tackled by multiple asynchronous threads, for testing thread safety, using the old handle interface 1775// 1776if ( Options & ( EOptionLinkProgram | EOptionOutputPreprocessed )) { 1777glslang :: InitializeProcess () ; 1778glslang :: InitializeProcess () ; // also test reference counting of users 1779glslang :: InitializeProcess () ; // also test reference counting of users 1780glslang :: FinalizeProcess () ; // also test reference counting of users 1781glslang :: FinalizeProcess () ; // also test reference counting of users 1782CompileAndLinkShaderFiles ( workList ) ; 1783glslang :: FinalizeProcess () ; 1784} else { 1785ShInitialize () ; 1786ShInitialize () ; // also test reference counting of users 1787ShFinalize () ; // also test reference counting of users 1788 1789bool printShaderNames = workList . size () > 1 ; 1790 1791if ( Options & EOptionMultiThreaded ) { 1792std :: array < std :: thread , 16 > threads ; 1793for ( unsigned int t = 0 ; t < threads . size () ; ++ t ) { 1794threads [ t ] = std :: thread ( CompileShaders , std :: ref ( workList )) ; 1795if ( threads [ t ] . get_id () == std :: thread :: id ()) { 1796fprintf ( stderr , "Failed to create thread \n " ) ; 1797return EFailThreadCreate ; 1798} 1799} 1800 1801std :: for_each ( threads . begin () , threads . end () , []( std :: thread & t ) { t . join () ; }) ; 1802} else 1803CompileShaders ( workList ) ; 1804 1805// Print out all the resulting infologs 1806for ( size_t w = 0 ; w < WorkItems . size () ; ++ w ) { 1807if ( WorkItems [ w ]) { 1808if ( printShaderNames || WorkItems [ w ] -> results . size () > 0 ) 1809PutsIfNonEmpty ( WorkItems [ w ] -> name . c_str ()) ; 1810PutsIfNonEmpty ( WorkItems [ w ] -> results . c_str ()) ; 1811} 1812} 1813 1814ShFinalize () ; 1815} 1816 1817if ( CompileFailed . load ()) 1818return EFailCompile ; 1819if ( LinkFailed . load ()) 1820return EFailLink ; 1821 1822return 0 ; 1823} 1824 1825int C_DECL main ( int argc , char * argv []) 1826{ 1827ProcessArguments ( WorkItems , argc , argv ) ; 1828 1829int ret = 0 ; 1830 1831// Loop over the entire init/finalize cycle to watch memory changes 1832const int iterations = 1 ; 1833if ( iterations > 1 ) 1834glslang :: OS_DumpMemoryCounters () ; 1835for ( int i = 0 ; i < iterations ; ++ i ) { 1836ret = singleMain () ; 1837if ( iterations > 1 ) 1838glslang :: OS_DumpMemoryCounters () ; 1839} 1840 1841return ret ; 1842} 1843 1844// 1845// Deduce the language from the filename. Files must end in one of the 1846// following extensions: 1847// 1848// .vert = vertex 1849// .tesc = tessellation control 1850// .tese = tessellation evaluation 1851// .geom = geometry 1852// .frag = fragment 1853// .comp = compute 1854// .rgen = ray generation 1855// .rint = ray intersection 1856// .rahit = ray any hit 1857// .rchit = ray closest hit 1858// .rmiss = ray miss 1859// .rcall = ray callable 1860// .mesh = mesh 1861// .task = task 1862// Additionally, the file names may end in .<stage>.glsl and .<stage>.hlsl 1863// where <stage> is one of the stages listed above. 1864// 1865EShLanguage FindLanguage ( const std :: string & name , bool parseStageName ) 1866{ 1867std :: string stageName ; 1868if ( shaderStageName ) 1869stageName = shaderStageName ; 1870else if ( parseStageName ) { 1871// Note: "first" extension means "first from the end", i.e. 1872// if the file is named foo.vert.glsl, then "glsl" is first, 1873// "vert" is second. 1874size_t firstExtStart = name . find_last_of ( "." ) ; 1875bool hasFirstExt = firstExtStart != std :: string :: npos ; 1876size_t secondExtStart = hasFirstExt ? name . find_last_of ( "." , firstExtStart - 1 ) : std :: string :: npos ; 1877bool hasSecondExt = secondExtStart != std :: string :: npos ; 1878std :: string firstExt = name . substr ( firstExtStart + 1 , std :: string :: npos ) ; 1879bool usesUnifiedExt = hasFirstExt && ( firstExt == "glsl" || firstExt == "hlsl" ) ; 1880if ( usesUnifiedExt && firstExt == "hlsl" ) 1881Options |= EOptionReadHlsl ; 1882if ( hasFirstExt && ! usesUnifiedExt ) 1883stageName = firstExt ; 1884else if ( usesUnifiedExt && hasSecondExt ) 1885stageName = name . substr ( secondExtStart + 1 , firstExtStart - secondExtStart - 1 ) ; 1886else { 1887usage () ; 1888return EShLangVertex ; 1889} 1890} else 1891stageName = name ; 1892 1893if ( stageName == "vert" ) 1894return EShLangVertex ; 1895else if ( stageName == "tesc" ) 1896return EShLangTessControl ; 1897else if ( stageName == "tese" ) 1898return EShLangTessEvaluation ; 1899else if ( stageName == "geom" ) 1900return EShLangGeometry ; 1901else if ( stageName == "frag" ) 1902return EShLangFragment ; 1903else if ( stageName == "comp" ) 1904return EShLangCompute ; 1905else if ( stageName == "rgen" ) 1906return EShLangRayGen ; 1907else if ( stageName == "rint" ) 1908return EShLangIntersect ; 1909else if ( stageName == "rahit" ) 1910return EShLangAnyHit ; 1911else if ( stageName == "rchit" ) 1912return EShLangClosestHit ; 1913else if ( stageName == "rmiss" ) 1914return EShLangMiss ; 1915else if ( stageName == "rcall" ) 1916return EShLangCallable ; 1917else if ( stageName == "mesh" ) 1918return EShLangMesh ; 1919else if ( stageName == "task" ) 1920return EShLangTask ; 1921 1922usage () ; 1923return EShLangVertex ; 1924} 1925 1926// 1927// Read a file's data into a string, and compile it using the old interface ShCompile, 1928// for non-linkable results. 1929// 1930void CompileFile ( const char * fileName , ShHandle compiler ) 1931{ 1932int ret = 0 ; 1933char * shaderString ; 1934if (( Options & EOptionStdin ) != 0 ) { 1935std :: istreambuf_iterator < char > begin ( std :: cin ) , end ; 1936std :: string tempString ( begin , end ) ; 1937shaderString = strdup ( tempString . c_str ()) ; 1938} else { 1939shaderString = ReadFileData ( fileName ) ; 1940} 1941 1942// move to length-based strings, rather than null-terminated strings 1943int * lengths = new int [ 1 ] ; 1944lengths [ 0 ] = ( int ) strlen ( shaderString ) ; 1945 1946EShMessages messages = EShMsgDefault ; 1947SetMessageOptions ( messages ) ; 1948 1949if ( UserPreamble . isSet ()) 1950Error ( "-D, -U and -P options require -l (linking) \n " ) ; 1951 1952for ( int i = 0 ; i < (( Options & EOptionMemoryLeakMode ) ? 100 : 1 ) ; ++ i ) { 1953for ( int j = 0 ; j < (( Options & EOptionMemoryLeakMode ) ? 100 : 1 ) ; ++ j ) { 1954// ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); 1955ret = ShCompile ( compiler , & shaderString , 1 , nullptr , EShOptNone , GetResources () , 0 , 1956( Options & EOptionDefaultDesktop ) ? 110 : 100 , false , messages , fileName ) ; 1957// const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err", 1958// "or should be l", "ine 1", "string 5\n", "float glo", "bal", 1959// ";\n#error should be line 2\n void main() {", "global = 2.3;}" }; 1960// const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" }; 1961// ret = ShCompile(compiler, multi, 7, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); 1962} 1963 1964if ( Options & EOptionMemoryLeakMode ) 1965glslang :: OS_DumpMemoryCounters () ; 1966} 1967 1968delete [] lengths ; 1969FreeFileData ( shaderString ) ; 1970 1971if ( ret == 0 ) 1972CompileFailed = true ; 1973} 1974 1975// 1976// print usage to stdout 1977// 1978void usage () 1979{ 1980printf ( "Usage: glslang [option]... [file]... \n " 1981" \n " 1982"'file' with one of the following three endings can be auto-classified: \n " 1983"1) .<stage>, where <stage> is one of: \n " 1984" vert for a vertex shader \n " 1985" tesc for a tessellation control shader \n " 1986" tese for a tessellation evaluation shader \n " 1987" geom for a geometry shader \n " 1988" frag for a fragment shader \n " 1989" comp for a compute shader \n " 1990" mesh for a mesh shader \n " 1991" task for a task shader \n " 1992" rgen for a ray generation shader \n " 1993" rint for a ray intersection shader \n " 1994" rahit for a ray any hit shader \n " 1995" rchit for a ray closest hit shader \n " 1996" rmiss for a ray miss shader \n " 1997" rcall for a ray callable shader \n " 1998"2) .<stage>.glsl or .<stage>.hlsl compound suffix, where stage options are \n " 1999" described above \n " 2000"3) .conf, to provide a config file that replaces the default configuration (see \n " 2001" -c option below for generating a template) \n " 2002" \n " 2003"Options: \n " 2004" -C cascading errors; risk crash from accumulation of error recoveries \n " 2005" -D input is HLSL (this is the default when any suffix is .hlsl) \n " 2006" -D<name[=def]> | --D <name[=def]> | --define-macro <name[=def]> \n " 2007" define a pre-processor macro \n " 2008" -E print pre-processed GLSL; cannot be used with -l; errors will \n " 2009" appear on stderr \n " 2010" -G[ver] create SPIR-V binary under OpenGL semantics; turns on -l; default \n " 2011" file name is <stage>.spv (-o overrides this); ver, when present, \n " 2012" is the version of the input semantics which will appear in \n " 2013" '#define GL_SPIRV ver'; --client opengl100 is the same as -G100; a \n " 2014" --target-env for OpenGL will also imply -G; currently only \n " 2015" supports GLSL \n " 2016" -H print human readable form of SPIR-V; turns on -V \n " 2017" -I<dir> add <dir> to the include search path; includer's directory is \n " 2018" searched first, followed by left-to-right order of -I \n " 2019" -Od disables optimization; may cause illegal SPIR-V for HLSL \n " 2020" -Os optimizes SPIR-V to minimize size \n " 2021" -P<text> | --P <text> | --preamble-text <text> \n " 2022" inject custom preamble text which is treated as if it appeared \n " 2023" immediately after the version declaration (if any) \n " 2024" -R use relaxed verification rules for generating Vulkan SPIR-V, \n " 2025" allowing the use of default uniforms, atomic_uints, and the \n " 2026" gl_VertexID and gl_InstanceID keywords \n " 2027" -S <stage> uses the specified <stage> rather than parsing the file extension; \n " 2028" choices for <stage> include vert, tesc, tese, geom, frag, and \n " 2029" comp; a full list of options is given above \n " 2030" -U<name> | --undef-macro <name> | --U <name> \n " 2031" undefine a pre-processor macro \n " 2032" -V[ver] create SPIR-V binary under Vulkan semantics; turns on -l; default \n " 2033" file name is <stage>.spv (-o overrides this); ver, when present, \n " 2034" is the version of the input semantics which will appear in \n " 2035" '#define VULKAN ver'; --client vulkan100 is the same as -V100; a \n " 2036" '--target-env' for Vulkan will also imply '-V' \n " 2037" -c configuration dump; creates the default configuration file \n " 2038" (redirect to a .conf file) \n " 2039" -d default to desktop (#version 110) when there is no shader #version \n " 2040" (default is ES version 100) \n " 2041" -e <name> | --entry-point <name> \n " 2042" specify <name> as the entry-point function name \n " 2043" -f{hlsl_functionality1} \n " 2044" 'hlsl_functionality1' enables use of the \n " 2045" SPV_GOOGLE_hlsl_functionality1 extension \n " 2046" -g generate debug information \n " 2047" -g0 strip debug information \n " 2048" -gV generate nonsemantic shader debug information \n " 2049" -gVS generate nonsemantic shader debug information with source \n " 2050" -h | --help print this usage message \n " 2051" -i intermediate tree (glslang AST) is printed out \n " 2052" -l link all input files together to form a single module \n " 2053" -m memory leak mode \n " 2054" -o <file> save binary to <file>; requires a binary option (e.g., -V) \n " 2055" -q dump reflection query database; requires -l for linking \n " 2056" -r | --relaxed-errors \n " 2057" relaxed GLSL semantic error-checking mode \n " 2058" -s silence syntax and semantic error reporting \n " 2059" -t multi-threaded mode \n " 2060" -u<name>:<loc> \n " 2061" specify a uniform location override for --aml \n " 2062" -v | --version \n " 2063" print version strings \n " 2064" -w | --suppress-warnings \n " 2065" suppress GLSL warnings, except as required by '#extension : warn' \n " 2066" -x save binary output as text-based 32-bit hexadecimal numbers \n " 2067" --absolute-path prints absolute path for messages \n " 2068" --relax-set-binding-limits allow larger layout(set) and \n " 2069" layout(binding) values \n " 2070" --auto-map-binding | --auto-map-bindings | --amb \n " 2071" automatically bind uniform variables without \n " 2072" explicit bindings \n " 2073" --auto-map-locations | --aml automatically locate input/output lacking \n " 2074" 'location' (fragile, not cross stage) \n " 2075" --auto-sampled-textures removes sampler variables and converts \n " 2076" existing textures to sampled textures \n " 2077" --client {vulkan<ver> | opengl<ver>} \n " 2078" see -V and -G \n " 2079" --depfile <file> writes depfile for build systems \n " 2080" --discard-is-terminate map GLSL discard to OpTerminateInvocation \n " 2081" instead of OpDemoteToHelperInvocation \n " 2082" --dump-builtin-symbols prints builtin symbol table prior each \n " 2083" compile \n " 2084" -dumpfullversion | -dumpversion print bare major.minor.patchlevel \n " 2085" --enhanced-msgs print more readable error messages (GLSL \n " 2086" only) \n " 2087" --error-column display the column of the error along the \n " 2088" line \n " 2089" --flatten-uniform-array | --flatten-uniform-arrays | --fua \n " 2090" flatten uniform texture/sampler arrays to \n " 2091" scalars \n " 2092" --glsl-version {100 | 110 | 120 | 130 | 140 | 150 | \n " 2093" 300es | 310es | 320es | 330 | \n " 2094" 400 | 410 | 420 | 430 | 440 | 450 | 460} \n " 2095" set GLSL version; overrides #version in \n " 2096" shader source \n " 2097" --hlsl-dx-position-w W component of SV_Position in HLSL fragment \n " 2098" shaders compatible with DirectX \n " 2099" --hlsl-dx9-compatible interprets sampler declarations as a \n " 2100" texture/sampler combo like DirectX9 would, \n " 2101" and recognizes DirectX9-specific semantics \n " 2102" --hlsl-enable-16bit-types allow 16-bit types in SPIR-V for HLSL \n " 2103" --hlsl-iomap | --hlsl-iomapper | --hlsl-iomapping \n " 2104" perform IO mapping in HLSL register space \n " 2105" --hlsl-offsets allow block offsets to follow HLSL rules; \n " 2106" works independently of source language \n " 2107" --invert-y | --iy invert position.Y output in vertex shader \n " 2108" --keep-uncalled | --ku don't eliminate uncalled functions \n " 2109" --lto perform link time optimization \n " 2110" --nan-clamp favor non-NaN operand in min, max, and clamp \n " 2111" --no-link only compile shader; do not link (GLSL only) \n " 2112" NOTE: this option will set the export \n " 2113" linkage attribute on all functions \n " 2114" --no-storage-format | --nsf use Unknown image format \n " 2115" --quiet do not print anything to stdout unless \n " 2116" requested by another option \n " 2117" --reflect-all-block-variables reflect all variables in blocks, whether \n " 2118" inactive or active \n " 2119" --reflect-basic-array-suffix arrays of basic types will have trailing [0] \n " 2120" --reflect-intermediate-io reflection includes inputs/outputs of linked \n " 2121" shaders rather than just vertex/fragment \n " 2122" --reflect-separate-buffers reflect buffer variables and blocks \n " 2123" separately to uniforms \n " 2124" --reflect-strict-array-suffix use strict array suffix rules when \n " 2125" reflecting \n " 2126" --reflect-unwrap-io-blocks unwrap input/output blocks the same as \n " 2127" uniform blocks \n " 2128" --resource-set-binding <stage> [name] <set> [binding]... \n " 2129" set descriptor set and binding for \n " 2130" individual resources \n " 2131" --resource-set-binding [stage] <set> \n " 2132" set descriptor set for all resources \n " 2133" --resource-set-bindings | --rsb synonyms for --resource-set-binding \n " 2134" --set-atomic-counter-block <name> <set> \n " 2135" set name and descriptor set for atomic \n " 2136" counter blocks with -R opt \n " 2137" --sacb synonym for set-atomic-counter-block \n " 2138" --set-block-backing name {uniform | buffer | push_constant} \n " 2139" changes the backing type of a uniform, \n " 2140" buffer, or push_constant block declared in \n " 2141" the program when using the -R option; this \n " 2142" can be used to change the backing for \n " 2143" existing blocks as well as implicit ones \n " 2144" such as 'gl_DefaultUniformBlock' \n " 2145" --set-default-uniform-block <name> <set> <binding> \n " 2146" set name, descriptor set, and binding for \n " 2147" global default-uniform-block with -R opt \n " 2148" --sdub synonym for set-default-uniform-block \n " 2149" --shift-image-binding [stage] <num> \n " 2150" base binding number for images (UAV) \n " 2151" --shift-image-binding [stage] <num> <set>... \n " 2152" per-descriptor-set shift values \n " 2153" --shift-image-bindings | --sib synonyms for --shift-image-binding \n " 2154" --shift-sampler-binding [stage] <num> \n " 2155" base binding number for samplers \n " 2156" --shift-sampler-binding [stage] <num> <set>... \n " 2157" per-descriptor-set shift values \n " 2158" --shift-sampler-bindings | --ssb synonyms for --shift-sampler-binding \n " 2159" --shift-ssbo-binding [stage] <num> \n " 2160" base binding number for SSBOs \n " 2161" --shift-ssbo-binding [stage] <num> <set>... \n " 2162" per-descriptor-set shift values \n " 2163" --shift-ssbo-bindings | --sbb synonyms for --shift-ssbo-binding \n " 2164" --shift-texture-binding [stage] <num> \n " 2165" base binding number for textures \n " 2166" --shift-texture-binding [stage] <num> <set>... \n " 2167" per-descriptor-set shift values \n " 2168" --shift-texture-bindings | --stb synonyms for --shift-texture-binding \n " 2169" --shift-uav-binding [stage] <num> base binding number for UAVs \n " 2170" --shift-uav-binding [stage] <num> <set>... \n " 2171" per-descriptor-set shift values \n " 2172" --shift-uav-bindings | --suavb synonyms for --shift-uav-binding \n " 2173" --shift-ubo-binding [stage] <num> base binding number for UBOs \n " 2174" --shift-ubo-binding [stage] <num> <set>... \n " 2175" per-descriptor-set shift values \n " 2176" --shift-ubo-bindings | --sub | \n " 2177" --shift-cbuffer-binding | --shift-cbuffer-bindings | --scb \n " 2178" synonyms for --shift-ubo-binding \n " 2179" --shift-combined-sampler-binding [stage] <num> \n " 2180" base binding number for combined samplers \n " 2181" --shift-combined-sampler-binding [stage] <num> <set>... \n " 2182" per-descriptor-set shift values \n " 2183" --shift-combined-sampler-bindings | --scsb \n " 2184" synonyms for --shift-combined-sampler-binding \n " 2185" --shift-as-binding [stage] <num> \n " 2186" base binding number for acceleration structures \n " 2187" --shift-as-binding [stage] <num> <set>... \n " 2188" per-descriptor-set shift values \n " 2189" --shift-as-bindings | --sab \n " 2190" synonyms for --shift-as-binding \n " 2191" --spirv-dis output standard-form disassembly; works only \n " 2192" when a SPIR-V generation option is also used \n " 2193" --spirv-val execute the SPIRV-Tools validator \n " 2194" --source-entrypoint <name> | --sep <name> \n " 2195" the given shader source function is renamed \n " 2196" to be the <name> given in -e \n " 2197" --stdin read from stdin instead of from a file; \n " 2198" requires providing the shader stage using -S \n " 2199" --target-env {vulkan1.0 | vulkan1.1 | vulkan1.2 | vulkan1.3 | vulkan1.4 | \n " 2200" opengl | spirv1.0 | spirv1.1 | spirv1.2 | spirv1.3 | \n " 2201" spirv1.4 | spirv1.5 | spirv1.6} \n " 2202" set the execution environment the generated \n " 2203" code will be executed in; defaults to: \n " 2204" * vulkan1.0 under --client vulkan<ver> \n " 2205" * opengl under --client opengl<ver> \n " 2206" * spirv1.0 under --target-env vulkan1.0 \n " 2207" * spirv1.3 under --target-env vulkan1.1 \n " 2208" * spirv1.5 under --target-env vulkan1.2 \n " 2209" * spirv1.6 under --target-env vulkan1.3 \n " 2210" * spirv1.6 under --target-env vulkan1.4 \n " 2211" multiple --target-env can be specified \n " 2212" --uniform-base <base> set a base to use for generated uniform \n " 2213" locations \n " 2214" --variable-name <name> | --vn <name> \n " 2215" creates a C header file that contains a \n " 2216" uint32_t array named <name> initialized with \n " 2217" the shader binary code \n " 2218" --validate-io validate cross stage IO \n " 2219" --bindings-per-resource-type \n " ) ; 2220 2221exit ( EFailUsage ) ; 2222} 2223 2224#if ! defined _MSC_VER && ! defined MINGW_HAS_SECURE_API 2225 2226#include <errno.h> 2227 2228int fopen_s ( 2229FILE ** pFile , 2230const char * filename , 2231const char * mode 2232) 2233{ 2234if ( ! pFile || ! filename || ! mode ) { 2235return EINVAL ; 2236} 2237 2238FILE * f = fopen ( filename , mode ) ; 2239if ( ! f ) { 2240if ( errno != 0 ) { 2241return errno ; 2242} else { 2243return ENOENT ; 2244} 2245} 2246* pFile = f ; 2247 2248return 0 ; 2249} 2250 2251#endif 2252 2253// 2254// Malloc a string of sufficient size and read a string into it. 2255// 2256char * ReadFileData ( const char * fileName ) 2257{ 2258FILE * in = nullptr ; 2259int errorCode = fopen_s ( & in , fileName , "r" ) ; 2260if ( errorCode || in == nullptr ) 2261Error ( "unable to open input file" ) ; 2262 2263int count = 0 ; 2264while ( fgetc ( in ) != EOF ) 2265count ++ ; 2266 2267fseek ( in , 0 , SEEK_SET ) ; 2268 2269if ( count > 3 ) { 2270unsigned char head [ 3 ] ; 2271if ( fread ( head , 1 , 3 , in ) == 3 ) { 2272if ( head [ 0 ] == 0xef && head [ 1 ] == 0xbb && head [ 2 ] == 0xbf ) { 2273// skip BOM 2274count -= 3 ; 2275} else { 2276fseek ( in , 0 , SEEK_SET ) ; 2277} 2278} else { 2279Error ( "can't read input file" ) ; 2280} 2281} 2282 2283char * return_data = ( char * ) malloc ( count + 1 ) ; // freed in FreeFileData() 2284if (( int ) fread ( return_data , 1 , count , in ) != count ) { 2285free ( return_data ) ; 2286Error ( "can't read input file" ) ; 2287} 2288 2289return_data [ count ] = ' \0 ' ; 2290fclose ( in ) ; 2291 2292return return_data ; 2293} 2294 2295void FreeFileData ( char * data ) 2296{ 2297free ( data ) ; 2298} 2299 2300void InfoLogMsg ( const char * msg , const char * name , const int num ) 2301{ 2302if ( num >= 0 ) 2303printf ( "#### %s %s %d INFO LOG #### \n " , msg , name , num ) ; 2304else 2305printf ( "#### %s %s INFO LOG #### \n " , msg , name ) ; 2306}