1 /*---------------------------------------------------------------------------* 2 3 Copyright (C) Nintendo. All rights reserved. 4 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 11 *---------------------------------------------------------------------------*/ 12 13 // 14 // shaderUtils optimization defines 15 // 16 17 #ifndef OPTFLAGS_HEADER_ 18 #define OPTFLAGS_HEADER_ 19 20 #if defined(__cplusplus) 21 extern "C" { 22 #endif 23 24 /// \brief Optimization flag settings for optimizeFlags (only if options.optFlagsPresent is 1). 25 26 /// Note that optimization flags are bit numbers, and have to be converted to bit masks vish GSH2_OPTMASK(). 27 /// For example, to set optimizeFlags to do -Ofastmath and -Oloopvar, we would set: 28 /// optimizeFlags = GSH2_OPTMASK(GSH2_OPTFLAG_FASTMATH) | GSH2_OPTMASK(GSH2_OPTFLAG_LOOPVAR) 29 30 enum GSH2OptimizeFlags 31 { 32 GSH2_OPTFLAG_SC = 0, ///< enable AMD specific Shader Compiler optimizations 33 GSH2_OPTFLAG_FASTMATH = 1, ///< enable optimizations that may violate IEEE floating point guarantees 34 GSH2_OPTFLAG_LOOPVAR = 2, ///< enable optimizations to find loop initialization 35 GSH2_OPTFLAG_CONST = 3, ///< enable constant propagation 36 GSH2_OPTFLAG_LOOPEXPR = 4, ///< enable unrolling loops containing complex expressions 37 GSH2_OPTFLAG_UNUSEDVAR = 5, ///< enable removing unused variables 38 GSH2_OPTFLAG_LIMITARRAYSYMS = 6, ///< do not emit more than 2 symbols for array elements (size optimization) 39 GSH2_OPTFLAG_GLSL = 7, ///< run first glsl to glsl optimization pass 40 }; 41 42 /// \brief Convert a flag into a bit mask. 43 #define GSH2_OPTMASK(bit) (((uint64)1)<<bit) 44 45 /// \brief defines for manipulating optimization flag sets (which are 64 bits) 46 47 /// Check to see if a flag is set. 48 #define GSH2_OPTFLAG_ISSET(flags, bit) (0 != ((flags) & GSH2_OPTMASK(bit))) 49 /// Set a specific flag in a mask. 50 #define GSH2_OPTFLAG_SETBIT(flags, bit) (flags |= GSH2_OPTMASK(bit)) 51 /// Clear a specific flag in a mask. 52 #define GSH2_OPTFLAG_CLRBIT(flags, bit) (flags &= ~GSH2_OPTMASK(bit)) 53 54 /// Mask representing all (non-experimental) flags; what we get from -Oall 55 #define GSH2_OPTFLAGS_ALL ( ((uint64)-1) & ~(GSH2_OPTMASK(GSH2_OPTFLAG_LIMITARRAYSYMS)|GSH2_OPTMASK(GSH2_OPTFLAG_GLSL)) ) 56 /// Mask representing no flags. 57 #define GSH2_OPTFLAGS_NONE ((uint64)0) 58 59 /// structure giving standard names for the flags 60 #define OFLAGDEF_CONTENTS \ 61 { "1", NULL, GSH2_OPTFLAGS_ALL }, \ 62 { "0", NULL, 0 }, \ 63 { "const", "additional constant propagation optimizations", GSH2_OPTMASK(GSH2_OPTFLAG_CONST) }, \ 64 { "fastmath", "enable optimizations that may violate strict IEEE semantics", GSH2_OPTMASK(GSH2_OPTFLAG_FASTMATH) }, \ 65 { "loopexpr", "allow unrolling of loops with complex expressions", GSH2_OPTMASK(GSH2_OPTFLAG_LOOPEXPR) }, \ 66 { "loopvar", "analyze variables to find loop variable initialization", GSH2_OPTMASK(GSH2_OPTFLAG_LOOPVAR) }, \ 67 { "sc", "enable AMD shader compiler optimizations", GSH2_OPTMASK(GSH2_OPTFLAG_SC) }, \ 68 { "unusedvar", "remove assignments to variables that are never used", GSH2_OPTMASK(GSH2_OPTFLAG_UNUSEDVAR) }, \ 69 { "glsl", "run an initial glsl->glsl optimization pass to remove unused code and variables", GSH2_OPTMASK(GSH2_OPTFLAG_GLSL) }, \ 70 { "all", "enable all optimizations", GSH2_OPTFLAGS_ALL }, \ 71 { "none", NULL, 0 }, \ 72 { NULL, NULL, 0 } 73 74 75 // Some defines that are for optimizing the compiler itself, rather than the generated code, 76 // but it's convenient to put them in this header because the optimize passes include this. 77 78 /// \brief Shader compiler passes that we instrument for time taken 79 #define GSH2_BT_UNKNOWN 0 ///< Time in an unknown part of code 80 #define GSH2_BT_INIT 1 ///< General initialization time 81 #define GSH2_BT_GLSLOPT 2 ///< GLSL Optimizer 82 #define GSH2_BT_PARSER 3 ///< Construct parse tree 83 #define GSH2_BT_CONVERTIL 4 ///< Convert to IL 84 #define GSH2_BT_OPTIMIZEIL 5 ///< IL Optimization (-Oxxx flags) 85 #define GSH2_BT_LINKSYM 6 ///< Link symbols 86 #define GSH2_BT_PATCHIL 7 ///< IL patcher 87 #define GSH2_BT_AMDSC 8 ///< AMD Shader Compiler (IL to ISA) 88 #define GSH2_BT_FINALOUT 9 ///< Final GFD file output 89 90 #define GSH2_BT_MISC 10 ///< Everything else 91 #define GSH2_BT_SYMTABINIT 11 ///< Symbol table initialization 92 93 #define GSH2_BT_FUNCINIT 12 ///< Function initialization 94 95 #define GSH2_BT_USEDITEMS 13 ///< Number of build time options currently used 96 97 // reserve some space here for new items 98 #define GSH2_BT_NUMITEMS 24 ///< total size of build time statistics array 99 100 /// \brief Initialize build time tracking system 101 void InitBuildTimes(void); 102 103 /// \brief Set which build time item the current code should be charged against 104 void SetCurrentBuildTime(int gsh2_bt_index); 105 106 /// \brief Get values for build time items 107 /// Retrieve the time taken for the various compiler phases (as given by the GSH2_BT_XXX flags) 108 /// into the results array. The values returned are milliseconds. resultcount is the number 109 /// of elements in the results array. 110 void GetBuildTimes(double *results, int resultcount); 111 112 #if defined(__cplusplus) 113 } 114 #endif 115 116 #endif 117