1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SKSL_PROGRAMSETTINGS 9 #define SKSL_PROGRAMSETTINGS 10 11 #include "include/private/SkSLDefines.h" 12 #include "include/private/SkSLProgramKind.h" 13 14 #include <vector> 15 16 namespace SkSL { 17 18 class ExternalFunction; 19 20 /** 21 * Holds the compiler settings for a program. 22 */ 23 struct ProgramSettings { 24 // If true the destination fragment color is read sk_FragColor. It must be declared inout. 25 bool fFragColorIsInOut = false; 26 // if true, Setting objects (e.g. sk_Caps.fbFetchSupport) should be replaced with their 27 // constant equivalents during compilation 28 bool fReplaceSettings = true; 29 // if true, all halfs are forced to be floats 30 bool fForceHighPrecision = false; 31 // if true, add -0.5 bias to LOD of all texture lookups 32 bool fSharpenTextures = false; 33 // if the program needs to create an RTFlip uniform, this is its offset in the uniform buffer 34 int fRTFlipOffset = -1; 35 // if the program needs to create an RTFlip uniform and is creating SPIR-V, this is the binding 36 // and set number of the uniform buffer. 37 int fRTFlipBinding = -1; 38 int fRTFlipSet = -1; 39 // If layout(set=S, binding=B) is not specified for a uniform, these values will be used. 40 // At present, zero is always used by our backends. 41 int fDefaultUniformSet = 0; 42 int fDefaultUniformBinding = 0; 43 // Enables the SkSL optimizer. Note that we never disable optimizations which are needed to 44 // fully evaluate constant-expressions, like constant folding or constant-intrinsic evaluation. 45 bool fOptimize = true; 46 // (Requires fOptimize = true) Removes any uncalled functions other than main(). Note that a 47 // function which starts out being used may end up being uncalled after optimization. 48 bool fRemoveDeadFunctions = true; 49 // (Requires fOptimize = true) Removes variables which are never used. 50 bool fRemoveDeadVariables = true; 51 // (Requires fOptimize = true) When greater than zero, enables the inliner. The threshold value 52 // sets an upper limit on the acceptable amount of code growth from inlining. 53 int fInlineThreshold = SkSL::kDefaultInlineThreshold; 54 // If true, every function in the generated program will be given the `noinline` modifier. 55 bool fForceNoInline = false; 56 // If true, implicit conversions to lower precision numeric types are allowed (e.g., float to 57 // half). These are always allowed when compiling Runtime Effects. 58 bool fAllowNarrowingConversions = false; 59 // If true, then Debug code will run SPIR-V output through the validator to ensure its 60 // correctness 61 bool fValidateSPIRV = true; 62 // If true, any synthetic uniforms must use push constant syntax 63 bool fUsePushConstants = false; 64 // Permits static if/switch statements to be used with non-constant tests. This is used when 65 // producing H and CPP code; the static tests don't have to have constant values *yet*, but 66 // the generated code will contain a static test which then does have to be a constant. 67 bool fPermitInvalidStaticTests = false; 68 // If true, configurations which demand strict ES2 conformance (runtime effects, generic 69 // programs, and SkVM rendering) will fail during compilation if ES2 restrictions are violated. 70 bool fEnforceES2Restrictions = true; 71 // If true, SkVM debug traces will contain the `trace_var` opcode. This opcode can cause the 72 // generated code to contain a lot of extra computations, because we need to explicitly compute 73 // every temporary value, even ones that would otherwise be optimized away entirely. The other 74 // debug opcodes are much less invasive on the generated code. 75 bool fAllowTraceVarInSkVMDebugTrace = true; 76 // If true, the DSL should automatically mangle symbol names. 77 bool fDSLMangling = true; 78 // If true, the DSL should automatically mark variables declared upon creation. 79 bool fDSLMarkVarsDeclared = false; 80 // If true, the DSL should install a memory pool when possible. 81 bool fDSLUseMemoryPool = true; 82 // If true, DSL objects assert that they were used prior to destruction 83 bool fAssertDSLObjectsReleased = true; 84 // If true, VarDeclaration can be cloned for testing purposes. See VarDeclaration::clone for 85 // more information. 86 bool fAllowVarDeclarationCloneForTesting = false; 87 // External functions available for use in runtime effects. These values are registered in the 88 // symbol table of the Program, but ownership is *not* transferred. It is up to the caller to 89 // keep them alive. 90 const std::vector<std::unique_ptr<ExternalFunction>>* fExternalFunctions = nullptr; 91 }; 92 93 /** 94 * All the configuration data for a given program. 95 */ 96 struct ProgramConfig { 97 /** True if we are currently processing one of the built-in SkSL include modules. */ 98 bool fIsBuiltinCode; 99 ProgramKind fKind; 100 ProgramSettings fSettings; 101 strictES2ModeProgramConfig102 bool strictES2Mode() const { 103 return fSettings.fEnforceES2Restrictions && 104 (IsRuntimeEffect(fKind) || fKind == ProgramKind::kGeneric); 105 } 106 IsRuntimeEffectProgramConfig107 static bool IsRuntimeEffect(ProgramKind kind) { 108 return (kind == ProgramKind::kRuntimeColorFilter || 109 kind == ProgramKind::kRuntimeShader || 110 kind == ProgramKind::kRuntimeBlender || 111 kind == ProgramKind::kCustomMeshVertex || 112 kind == ProgramKind::kCustomMeshFragment); 113 } 114 }; 115 116 } // namespace SkSL 117 118 #endif 119