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 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 17 | * Holds the compiler settings for a program. |
| 18 | */ |
| 19 | struct ProgramSettings { |
| 20 | // if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate |
| 21 | // must be flipped. |
| 22 | bool fFlipY = false; |
| 23 | // If true the destination fragment color is read sk_FragColor. It must be declared inout. |
| 24 | bool fFragColorIsInOut = false; |
| 25 | // if true, Setting objects (e.g. sk_Caps.fbFetchSupport) should be replaced with their |
| 26 | // constant equivalents during compilation |
| 27 | bool fReplaceSettings = true; |
| 28 | // if true, all halfs are forced to be floats |
| 29 | bool fForceHighPrecision = false; |
| 30 | // if true, add -0.5 bias to LOD of all texture lookups |
| 31 | bool fSharpenTextures = false; |
| 32 | // if the program needs to create an RTHeight uniform, this is its offset in the uniform |
| 33 | // buffer |
| 34 | int fRTHeightOffset = -1; |
| 35 | // if the program needs to create an RTHeight uniform and is creating spriv, this is the |
| 36 | // binding and set number of the uniform buffer. |
| 37 | int fRTHeightBinding = -1; |
| 38 | int fRTHeightSet = -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; |
John Stiles | 66c53b9 | 2021-02-20 08:00:43 -0500 | [diff] [blame] | 43 | // Enables the SkSL optimizer. |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 44 | bool fOptimize = true; |
John Stiles | 0bfeae6 | 2021-03-11 09:09:42 -0500 | [diff] [blame] | 45 | // (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] | 46 | // function which starts out being used may end up being uncalled after optimization. |
| 47 | bool fRemoveDeadFunctions = true; |
John Stiles | 0bfeae6 | 2021-03-11 09:09:42 -0500 | [diff] [blame] | 48 | // (Requires fOptimize = true) Removes global variables which are never used. |
| 49 | bool fRemoveDeadVariables = true; |
John Stiles | 66c53b9 | 2021-02-20 08:00:43 -0500 | [diff] [blame] | 50 | // (Requires fOptimize = true) When greater than zero, enables the inliner. The threshold value |
| 51 | // sets an upper limit on the acceptable amount of code growth from inlining. |
| 52 | int fInlineThreshold = SkSL::kDefaultInlineThreshold; |
John Stiles | 9d26af9 | 2021-03-23 09:25:33 -0400 | [diff] [blame] | 53 | // If true, every function in the generated program will be given the `noinline` modifier. |
| 54 | bool fForceNoInline = false; |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 55 | // If true, implicit conversions to lower precision numeric types are allowed |
| 56 | // (eg, float to half) |
| 57 | bool fAllowNarrowingConversions = false; |
| 58 | // If true, then Debug code will run SPIR-V output through the validator to ensure its |
| 59 | // correctness |
| 60 | bool fValidateSPIRV = true; |
| 61 | // If true, any synthetic uniforms must use push constant syntax |
| 62 | bool fUsePushConstants = false; |
| 63 | // Permits static if/switch statements to be used with non-constant tests. This is used when |
| 64 | // producing H and CPP code; the static tests don't have to have constant values *yet*, but |
| 65 | // the generated code will contain a static test which then does have to be a constant. |
| 66 | bool fPermitInvalidStaticTests = false; |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * All the configuration data for a given program. |
| 71 | */ |
| 72 | struct ProgramConfig { |
| 73 | ProgramKind fKind; |
| 74 | ProgramSettings fSettings; |
John Stiles | ca107c9 | 2021-02-19 09:54:44 -0500 | [diff] [blame] | 75 | |
| 76 | bool strictES2Mode() const { |
| 77 | return fKind == ProgramKind::kRuntimeEffect || fKind == ProgramKind::kGeneric; |
| 78 | } |
John Stiles | 270cec2 | 2021-02-17 12:59:36 -0500 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace SkSL |
| 82 | |
| 83 | #endif |