John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 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 | |
Ethan Nicholas | daed259 | 2021-03-04 14:30:25 -0500 | [diff] [blame] | 11 | #include "include/private/SkSLDefines.h" |
Ethan Nicholas | ee49efc | 2021-04-09 15:33:53 -0400 | [diff] [blame] | 12 | #include "include/private/SkSLProgramKind.h" |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 13 | |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 16 | namespace SkSL { |
| 17 | |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 18 | class ExternalFunction; |
| 19 | |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 20 | /** |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 21 | * Holds the compiler settings for a program. |
| 22 | */ |
| 23 | struct ProgramSettings { |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 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; |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 33 | // if the program needs to create an RTFlip uniform, this is its offset in the uniform |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 34 | // buffer |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 35 | int fRTFlipOffset = -1; |
| 36 | // if the program needs to create an RTFlip uniform and is creating spriv, this is the |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 37 | // binding and set number of the uniform buffer. |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 38 | int fRTFlipBinding = -1; |
| 39 | int fRTFlipSet = -1; |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 40 | // If layout(set=S, binding=B) is not specified for a uniform, these values will be used. |
| 41 | // At present, zero is always used by our backends. |
| 42 | int fDefaultUniformSet = 0; |
| 43 | int fDefaultUniformBinding = 0; |
John Stiles | 66c53b9 | 2021-02-20 08:00:43 -0500 | [diff] [blame] | 44 | // Enables the SkSL optimizer. |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 45 | bool fOptimize = true; |
John Stiles | 0bfeae6 | 2021-03-11 09:09:42 -0500 | [diff] [blame] | 46 | // (Requires fOptimize = true) Removes any uncalled functions other than main(). Note that a |
John Stiles | 66c53b9 | 2021-02-20 08:00:43 -0500 | [diff] [blame] | 47 | // function which starts out being used may end up being uncalled after optimization. |
| 48 | bool fRemoveDeadFunctions = true; |
John Stiles | 0bfeae6 | 2021-03-11 09:09:42 -0500 | [diff] [blame] | 49 | // (Requires fOptimize = true) Removes global variables which are never used. |
| 50 | bool fRemoveDeadVariables = true; |
John Stiles | 66c53b9 | 2021-02-20 08:00:43 -0500 | [diff] [blame] | 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; |
John Stiles | 9d26af9 | 2021-03-23 09:25:33 -0400 | [diff] [blame] | 54 | // If true, every function in the generated program will be given the `noinline` modifier. |
| 55 | bool fForceNoInline = false; |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 56 | // If true, implicit conversions to lower precision numeric types are allowed |
| 57 | // (eg, float to half) |
| 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; |
John Stiles | 65d7ab2 | 2021-04-28 15:14:09 -0400 | [diff] [blame] | 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; |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 71 | // If true, the DSL should automatically mangle symbol names. |
| 72 | bool fDSLMangling = true; |
| 73 | // If true, the DSL should automatically mark variables declared upon creation. |
| 74 | bool fDSLMarkVarsDeclared = false; |
Brian Salomon | d8d85b9 | 2021-07-07 09:41:17 -0400 | [diff] [blame] | 75 | // If true, the DSL should install a memory pool when possible. |
| 76 | bool fDSLUseMemoryPool = true; |
Ethan Nicholas | 459777a | 2021-07-16 11:16:27 -0400 | [diff] [blame] | 77 | // If true, DSL objects assert that they were used prior to destruction |
| 78 | bool fAssertDSLObjectsReleased = true; |
Ethan Nicholas | 55a63af | 2021-05-18 10:12:58 -0400 | [diff] [blame] | 79 | // External functions available for use in runtime effects. These values are registered in the |
| 80 | // symbol table of the Program, but ownership is *not* transferred. It is up to the caller to |
| 81 | // keep them alive. |
| 82 | const std::vector<std::unique_ptr<ExternalFunction>>* fExternalFunctions = nullptr; |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * All the configuration data for a given program. |
| 87 | */ |
| 88 | struct ProgramConfig { |
| 89 | ProgramKind fKind; |
| 90 | ProgramSettings fSettings; |
John Stiles | ca107c9 | 2021-02-19 09:54:44 -0500 | [diff] [blame] | 91 | |
| 92 | bool strictES2Mode() const { |
John Stiles | 65d7ab2 | 2021-04-28 15:14:09 -0400 | [diff] [blame] | 93 | return fSettings.fEnforceES2Restrictions && |
John Stiles | bb2ef92 | 2021-07-26 08:32:07 -0400 | [diff] [blame] | 94 | (this->isRuntimeEffect() || fKind == ProgramKind::kGeneric); |
| 95 | } |
| 96 | |
| 97 | bool isRuntimeEffect() const { |
| 98 | return (fKind == ProgramKind::kRuntimeColorFilter || |
John Stiles | 65d7ab2 | 2021-04-28 15:14:09 -0400 | [diff] [blame] | 99 | fKind == ProgramKind::kRuntimeShader || |
John Stiles | bb2ef92 | 2021-07-26 08:32:07 -0400 | [diff] [blame] | 100 | fKind == ProgramKind::kRuntimeBlender); |
John Stiles | ca107c9 | 2021-02-19 09:54:44 -0500 | [diff] [blame] | 101 | } |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace SkSL |
| 105 | |
| 106 | #endif |