ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [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 | */ |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_UTIL |
| 9 | #define SKSL_UTIL |
| 10 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 11 | #include <cstdarg> |
| 12 | #include <memory> |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 13 | #include "stdlib.h" |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 14 | #include "string.h" |
Ethan Nicholas | daed259 | 2021-03-04 14:30:25 -0500 | [diff] [blame] | 15 | #include "include/private/SkSLDefines.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/sksl/SkSLLexer.h" |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 17 | |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 18 | #ifndef SKSL_STANDALONE |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "include/core/SkTypes.h" |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 20 | #include "include/private/GrTypesPriv.h" |
Ethan Nicholas | 7ad3f22 | 2020-01-22 11:44:18 -0500 | [diff] [blame] | 21 | #if SK_SUPPORT_GPU |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 22 | #include "include/gpu/GrContextOptions.h" |
Ethan Nicholas | 7ad3f22 | 2020-01-22 11:44:18 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrShaderCaps.h" |
| 24 | #endif // SK_SUPPORT_GPU |
Ethan Nicholas | 682f299 | 2020-01-22 12:58:42 -0500 | [diff] [blame] | 25 | #endif // SKSL_STANDALONE |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 26 | |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 27 | class GrShaderCaps; |
| 28 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 29 | namespace SkSL { |
| 30 | |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 31 | class Context; |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 32 | class OutputStream; |
| 33 | class StringStream; |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 34 | class Type; |
Ethan Nicholas | 842d31b | 2019-01-22 10:59:11 -0500 | [diff] [blame] | 35 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 36 | #if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 37 | |
| 38 | // we're being compiled standalone, so we don't have access to caps... |
| 39 | enum GrGLSLGeneration { |
| 40 | k110_GrGLSLGeneration, |
| 41 | k130_GrGLSLGeneration, |
| 42 | k140_GrGLSLGeneration, |
| 43 | k150_GrGLSLGeneration, |
| 44 | k330_GrGLSLGeneration, |
| 45 | k400_GrGLSLGeneration, |
| 46 | k420_GrGLSLGeneration, |
| 47 | k310es_GrGLSLGeneration, |
| 48 | k320es_GrGLSLGeneration, |
| 49 | }; |
| 50 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 51 | class StandaloneShaderCaps { |
| 52 | public: |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 53 | GrGLSLGeneration fGLSLGeneration = k400_GrGLSLGeneration; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 54 | GrGLSLGeneration generation() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 55 | return fGLSLGeneration; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 56 | } |
| 57 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 58 | bool fAtan2ImplementedAsAtanYOverX = false; |
Michael Ludwig | 24d438b | 2018-09-12 15:22:50 -0400 | [diff] [blame] | 59 | bool atan2ImplementedAsAtanYOverX() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 60 | return fAtan2ImplementedAsAtanYOverX; |
Michael Ludwig | 24d438b | 2018-09-12 15:22:50 -0400 | [diff] [blame] | 61 | } |
| 62 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 63 | bool fCanUseMinAndAbsTogether = true; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 64 | bool canUseMinAndAbsTogether() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 65 | return fCanUseMinAndAbsTogether; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 66 | } |
| 67 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 68 | bool fMustForceNegatedAtanParamToFloat = false; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 69 | bool mustForceNegatedAtanParamToFloat() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 70 | return fMustForceNegatedAtanParamToFloat; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Chris Dalton | 155c33c | 2021-06-07 18:51:42 -0600 | [diff] [blame] | 73 | bool fMustForceNegatedLdexpParamToMultiply = false; |
| 74 | bool mustForceNegatedLdexpParamToMultiply() const { |
| 75 | return fMustForceNegatedLdexpParamToMultiply; |
| 76 | } |
| 77 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 78 | bool fShaderDerivativeSupport = true; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 79 | bool shaderDerivativeSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 80 | return fShaderDerivativeSupport; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 81 | } |
| 82 | |
John Stiles | db42bf2 | 2020-09-15 16:09:11 -0400 | [diff] [blame] | 83 | bool fUsesPrecisionModifiers = false; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 84 | bool usesPrecisionModifiers() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 85 | return fUsesPrecisionModifiers; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | bool mustDeclareFragmentShaderOutput() const { |
John Stiles | 72664be | 2020-09-16 17:43:11 -0400 | [diff] [blame] | 89 | return fGLSLGeneration > k110_GrGLSLGeneration; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 90 | } |
| 91 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 92 | bool fFBFetchSupport = true; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 93 | bool fbFetchSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 94 | return fFBFetchSupport; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 95 | } |
| 96 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 97 | bool fFBFetchNeedsCustomOutput = false; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 98 | bool fbFetchNeedsCustomOutput() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 99 | return fFBFetchNeedsCustomOutput; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 100 | } |
| 101 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 102 | bool fFlatInterpolationSupport = true; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 103 | bool flatInterpolationSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 104 | return fFlatInterpolationSupport; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 105 | } |
| 106 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 107 | bool fNoperspectiveInterpolationSupport = true; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 108 | bool noperspectiveInterpolationSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 109 | return fNoperspectiveInterpolationSupport; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 110 | } |
| 111 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 112 | bool fMultisampleInterpolationSupport = true; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 113 | bool multisampleInterpolationSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 114 | return fMultisampleInterpolationSupport; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 115 | } |
| 116 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 117 | bool fSampleMaskSupport = true; |
Chris Dalton | 8a64a44 | 2019-10-29 18:54:58 -0600 | [diff] [blame] | 118 | bool sampleMaskSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 119 | return fSampleMaskSupport; |
Chris Dalton | 1ae54bc | 2019-10-29 16:28:01 -0600 | [diff] [blame] | 120 | } |
| 121 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 122 | bool fExternalTextureSupport = true; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 123 | bool externalTextureSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 124 | return fExternalTextureSupport; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 125 | } |
| 126 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 127 | bool fMustDoOpBetweenFloorAndAbs = false; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 128 | bool mustDoOpBetweenFloorAndAbs() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 129 | return fMustDoOpBetweenFloorAndAbs; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 130 | } |
| 131 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 132 | bool fMustGuardDivisionEvenAfterExplicitZeroCheck = false; |
Brian Salomon | f8c187c | 2019-12-19 14:41:57 -0500 | [diff] [blame] | 133 | bool mustGuardDivisionEvenAfterExplicitZeroCheck() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 134 | return fMustGuardDivisionEvenAfterExplicitZeroCheck; |
Brian Salomon | f8c187c | 2019-12-19 14:41:57 -0500 | [diff] [blame] | 135 | } |
| 136 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 137 | bool fInBlendModesFailRandomlyForAllZeroVec = false; |
Brian Salomon | f8c187c | 2019-12-19 14:41:57 -0500 | [diff] [blame] | 138 | bool inBlendModesFailRandomlyForAllZeroVec() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 139 | return fInBlendModesFailRandomlyForAllZeroVec; |
Brian Salomon | f8c187c | 2019-12-19 14:41:57 -0500 | [diff] [blame] | 140 | } |
| 141 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 142 | bool fMustEnableAdvBlendEqs = false; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 143 | bool mustEnableAdvBlendEqs() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 144 | return fMustEnableAdvBlendEqs; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Brian Osman | b047b5d | 2020-11-03 11:56:42 -0500 | [diff] [blame] | 147 | bool fCanUseAnyFunctionInShader = true; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 148 | bool canUseAnyFunctionInShader() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 149 | return fCanUseAnyFunctionInShader; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 150 | } |
| 151 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 152 | bool fNoDefaultPrecisionForExternalSamplers = false; |
Brian Salomon | 5a5f3e8 | 2019-08-16 15:05:40 -0400 | [diff] [blame] | 153 | bool noDefaultPrecisionForExternalSamplers() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 154 | return fNoDefaultPrecisionForExternalSamplers; |
Brian Salomon | 5a5f3e8 | 2019-08-16 15:05:40 -0400 | [diff] [blame] | 155 | } |
| 156 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 157 | bool fFloatIs32Bits = true; |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 158 | bool floatIs32Bits() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 159 | return fFloatIs32Bits; |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 160 | } |
| 161 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 162 | bool fIntegerSupport = false; |
Ethan Nicholas | 07990de | 2017-07-18 09:47:43 -0400 | [diff] [blame] | 163 | bool integerSupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 164 | return fIntegerSupport; |
Ethan Nicholas | 07990de | 2017-07-18 09:47:43 -0400 | [diff] [blame] | 165 | } |
| 166 | |
John Stiles | ec79349 | 2021-05-03 09:21:12 -0400 | [diff] [blame] | 167 | bool fNonsquareMatrixSupport = false; |
| 168 | bool nonsquareMatrixSupport() const { |
| 169 | return fNonsquareMatrixSupport; |
| 170 | } |
| 171 | |
John Stiles | bc9222b | 2021-08-17 15:58:03 -0400 | [diff] [blame] | 172 | bool fInverseHyperbolicSupport = false; |
| 173 | bool inverseHyperbolicSupport() const { |
| 174 | return fInverseHyperbolicSupport; |
| 175 | } |
| 176 | |
Brian Osman | d8efe70 | 2020-09-22 09:49:04 -0400 | [diff] [blame] | 177 | bool fBuiltinFMASupport = false; |
Chris Dalton | 07ee63d | 2018-11-16 11:02:34 -0500 | [diff] [blame] | 178 | bool builtinFMASupport() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 179 | return fBuiltinFMASupport; |
Chris Dalton | 07ee63d | 2018-11-16 11:02:34 -0500 | [diff] [blame] | 180 | } |
| 181 | |
John Stiles | 6f3015a | 2020-10-08 14:55:36 -0400 | [diff] [blame] | 182 | bool fBuiltinDeterminantSupport = false; |
| 183 | bool builtinDeterminantSupport() const { |
| 184 | return fBuiltinDeterminantSupport; |
| 185 | } |
| 186 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 187 | bool fCanUseDoLoops = false; |
Ethan Nicholas | 70728ef | 2020-05-28 07:09:00 -0400 | [diff] [blame] | 188 | bool canUseDoLoops() const { |
| 189 | // we define this to false in standalone so we don't use do loops while inlining in FP files |
| 190 | // (which would then, being baked in, end up being used even in contexts where do loops are |
| 191 | // not allowed) |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 192 | return fCanUseDoLoops; |
Ethan Nicholas | 70728ef | 2020-05-28 07:09:00 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Brian Osman | 28f702c | 2021-02-02 11:52:07 -0500 | [diff] [blame] | 195 | bool fUseNodePools = true; |
| 196 | bool useNodePools() const { |
| 197 | return fUseNodePools; |
| 198 | } |
| 199 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 200 | const char* fShaderDerivativeExtensionString = nullptr; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 201 | const char* shaderDerivativeExtensionString() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 202 | return fShaderDerivativeExtensionString; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 203 | } |
| 204 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 205 | const char* fFragCoordConventionsExtensionString = nullptr; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 206 | const char* fragCoordConventionsExtensionString() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 207 | return fFragCoordConventionsExtensionString; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 208 | } |
| 209 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 210 | const char* fExternalTextureExtensionString = nullptr; |
Brian Osman | 4b2f915 | 2018-04-17 11:19:57 -0400 | [diff] [blame] | 211 | const char* externalTextureExtensionString() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 212 | return fExternalTextureExtensionString; |
Brian Osman | 4b2f915 | 2018-04-17 11:19:57 -0400 | [diff] [blame] | 213 | } |
| 214 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 215 | const char* fSecondExternalTextureExtensionString = nullptr; |
Brian Osman | 061020e | 2018-04-17 14:22:15 -0400 | [diff] [blame] | 216 | const char* secondExternalTextureExtensionString() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 217 | return fSecondExternalTextureExtensionString; |
Brian Osman | 061020e | 2018-04-17 14:22:15 -0400 | [diff] [blame] | 218 | } |
| 219 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 220 | const char* fVersionDeclString = ""; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 221 | const char* versionDeclString() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 222 | return fVersionDeclString; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 223 | } |
Ethan Nicholas | 7da6dfa | 2017-06-21 11:25:18 -0400 | [diff] [blame] | 224 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 225 | bool fCanUseFractForNegativeValues = true; |
Ethan Nicholas | 1af6d68 | 2017-08-08 16:42:13 -0400 | [diff] [blame] | 226 | bool canUseFractForNegativeValues() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 227 | return fCanUseFractForNegativeValues; |
Ethan Nicholas | 1af6d68 | 2017-08-08 16:42:13 -0400 | [diff] [blame] | 228 | } |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 229 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 230 | bool fCanUseFragCoord = true; |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 231 | bool canUseFragCoord() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 232 | return fCanUseFragCoord; |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 233 | } |
Chris Dalton | 85fcfc5 | 2018-03-14 11:15:27 -0600 | [diff] [blame] | 234 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 235 | bool fIncompleteShortIntPrecision = false; |
Chris Dalton | 85fcfc5 | 2018-03-14 11:15:27 -0600 | [diff] [blame] | 236 | bool incompleteShortIntPrecision() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 237 | return fIncompleteShortIntPrecision; |
Chris Dalton | 85fcfc5 | 2018-03-14 11:15:27 -0600 | [diff] [blame] | 238 | } |
Ethan Nicholas | 43f6d45 | 2018-04-13 16:53:07 -0400 | [diff] [blame] | 239 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 240 | bool fAddAndTrueToLoopCondition = false; |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 241 | bool addAndTrueToLoopCondition() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 242 | return fAddAndTrueToLoopCondition; |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 243 | } |
| 244 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 245 | bool fUnfoldShortCircuitAsTernary = false; |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 246 | bool unfoldShortCircuitAsTernary() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 247 | return fUnfoldShortCircuitAsTernary; |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 248 | } |
| 249 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 250 | bool fEmulateAbsIntFunction = false; |
Adrienne Walker | 92b161f | 2018-08-22 10:41:52 -0700 | [diff] [blame] | 251 | bool emulateAbsIntFunction() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 252 | return fEmulateAbsIntFunction; |
Adrienne Walker | 92b161f | 2018-08-22 10:41:52 -0700 | [diff] [blame] | 253 | } |
| 254 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 255 | bool fRewriteDoWhileLoops = false; |
Adrienne Walker | 8b23ca6 | 2018-08-22 10:45:41 -0700 | [diff] [blame] | 256 | bool rewriteDoWhileLoops() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 257 | return fRewriteDoWhileLoops; |
Adrienne Walker | 8b23ca6 | 2018-08-22 10:45:41 -0700 | [diff] [blame] | 258 | } |
| 259 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 260 | bool fRemovePowWithConstantExponent = false; |
Adrienne Walker | 2f4c09b | 2018-08-22 16:04:57 -0700 | [diff] [blame] | 261 | bool removePowWithConstantExponent() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 262 | return fRemovePowWithConstantExponent; |
Adrienne Walker | 2f4c09b | 2018-08-22 16:04:57 -0700 | [diff] [blame] | 263 | } |
| 264 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 265 | const char* fFBFetchColorName = nullptr; |
Ethan Nicholas | 43f6d45 | 2018-04-13 16:53:07 -0400 | [diff] [blame] | 266 | const char* fbFetchColorName() const { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 267 | return fFBFetchColorName; |
Ethan Nicholas | 43f6d45 | 2018-04-13 16:53:07 -0400 | [diff] [blame] | 268 | } |
John Stiles | 85749c0 | 2021-03-23 17:12:03 -0400 | [diff] [blame] | 269 | |
| 270 | bool fRewriteMatrixVectorMultiply = false; |
| 271 | bool rewriteMatrixVectorMultiply() const { |
| 272 | return fRewriteMatrixVectorMultiply; |
| 273 | } |
| 274 | |
John Stiles | 5ee369f | 2021-05-21 17:27:57 -0400 | [diff] [blame] | 275 | bool fRewriteMatrixComparisons = false; |
| 276 | bool rewriteMatrixComparisons() const { |
| 277 | return fRewriteMatrixComparisons; |
John Stiles | 36c5796 | 2021-05-20 18:00:39 -0400 | [diff] [blame] | 278 | } |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 279 | }; |
| 280 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 281 | using ShaderCapsClass = StandaloneShaderCaps; |
| 282 | using ShaderCapsPointer = std::shared_ptr<StandaloneShaderCaps>; |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 283 | extern StandaloneShaderCaps standaloneCaps; |
| 284 | |
| 285 | #else |
| 286 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 287 | using ShaderCapsClass = GrShaderCaps; |
| 288 | using ShaderCapsPointer = sk_sp<GrShaderCaps>; |
| 289 | |
| 290 | #endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU |
| 291 | |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 292 | // Various sets of caps for use in tests |
Brian Salomon | f1dd677 | 2016-11-29 15:27:52 -0500 | [diff] [blame] | 293 | class ShaderCapsFactory { |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 294 | public: |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 295 | static ShaderCapsPointer Default() { |
| 296 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 297 | result->fVersionDeclString = "#version 400"; |
| 298 | result->fShaderDerivativeSupport = true; |
John Stiles | 6f3015a | 2020-10-08 14:55:36 -0400 | [diff] [blame] | 299 | result->fBuiltinDeterminantSupport = true; |
John Stiles | ca4d074 | 2020-09-18 15:41:31 -0400 | [diff] [blame] | 300 | result->fCanUseDoLoops = true; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 301 | return result; |
| 302 | } |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 303 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 304 | static ShaderCapsPointer Standalone() { |
| 305 | return MakeShaderCaps(); |
| 306 | } |
| 307 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 308 | static ShaderCapsPointer AddAndTrueToLoopCondition() { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 309 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 310 | result->fVersionDeclString = "#version 400"; |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 311 | result->fAddAndTrueToLoopCondition = true; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 312 | return result; |
| 313 | } |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 314 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 315 | static ShaderCapsPointer BlendModesFailRandomlyForAllZeroVec() { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 316 | ShaderCapsPointer result = MakeShaderCaps(); |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 317 | result->fInBlendModesFailRandomlyForAllZeroVec = true; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 318 | return result; |
| 319 | } |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 320 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 321 | static ShaderCapsPointer CannotUseFractForNegativeValues() { |
| 322 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 323 | result->fVersionDeclString = "#version 400"; |
| 324 | result->fCanUseFractForNegativeValues = false; |
| 325 | return result; |
| 326 | } |
Florin Malita | 3b30c4f | 2017-08-08 15:47:35 -0400 | [diff] [blame] | 327 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 328 | static ShaderCapsPointer CannotUseFragCoord() { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 329 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 330 | result->fVersionDeclString = "#version 400"; |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 331 | result->fCanUseFragCoord = false; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 332 | return result; |
| 333 | } |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 334 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 335 | static ShaderCapsPointer CannotUseMinAndAbsTogether() { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 336 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 337 | result->fVersionDeclString = "#version 400"; |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 338 | result->fCanUseMinAndAbsTogether = false; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 339 | return result; |
| 340 | } |
Ethan Nicholas | 3605ace | 2016-11-21 15:59:48 -0500 | [diff] [blame] | 341 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 342 | static ShaderCapsPointer EmulateAbsIntFunction() { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 343 | ShaderCapsPointer result = MakeShaderCaps(); |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 344 | result->fVersionDeclString = "#version 400"; |
| 345 | result->fEmulateAbsIntFunction = true; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 346 | return result; |
| 347 | } |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 348 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 349 | static ShaderCapsPointer IncompleteShortIntPrecision() { |
| 350 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 351 | result->fVersionDeclString = "#version 310es"; |
| 352 | result->fUsesPrecisionModifiers = true; |
| 353 | result->fIncompleteShortIntPrecision = true; |
| 354 | return result; |
| 355 | } |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 356 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 357 | static ShaderCapsPointer MustForceNegatedAtanParamToFloat() { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 358 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 359 | result->fVersionDeclString = "#version 400"; |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 360 | result->fMustForceNegatedAtanParamToFloat = true; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 361 | return result; |
| 362 | } |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 363 | |
Chris Dalton | 155c33c | 2021-06-07 18:51:42 -0600 | [diff] [blame] | 364 | static ShaderCapsPointer MustForceNegatedLdexpParamToMultiply() { |
| 365 | ShaderCapsPointer result = MakeShaderCaps(); |
| 366 | result->fVersionDeclString = "#version 400"; |
| 367 | result->fMustForceNegatedLdexpParamToMultiply = true; |
| 368 | return result; |
| 369 | } |
| 370 | |
John Stiles | eaaa71b | 2020-10-08 22:18:10 -0400 | [diff] [blame] | 371 | static ShaderCapsPointer MustGuardDivisionEvenAfterExplicitZeroCheck() { |
| 372 | ShaderCapsPointer result = MakeShaderCaps(); |
| 373 | result->fMustGuardDivisionEvenAfterExplicitZeroCheck = true; |
| 374 | return result; |
| 375 | } |
| 376 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 377 | static ShaderCapsPointer RemovePowWithConstantExponent() { |
| 378 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 379 | result->fVersionDeclString = "#version 400"; |
| 380 | result->fRemovePowWithConstantExponent = true; |
| 381 | return result; |
| 382 | } |
Chris Dalton | b0fd4b1 | 2019-10-29 13:41:22 -0600 | [diff] [blame] | 383 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 384 | static ShaderCapsPointer RewriteDoWhileLoops() { |
| 385 | ShaderCapsPointer result = MakeShaderCaps(); |
| 386 | result->fVersionDeclString = "#version 400"; |
| 387 | result->fRewriteDoWhileLoops = true; |
| 388 | return result; |
| 389 | } |
| 390 | |
John Stiles | 5ee369f | 2021-05-21 17:27:57 -0400 | [diff] [blame] | 391 | static ShaderCapsPointer RewriteMatrixComparisons() { |
John Stiles | 36c5796 | 2021-05-20 18:00:39 -0400 | [diff] [blame] | 392 | ShaderCapsPointer result = MakeShaderCaps(); |
John Stiles | 5ee369f | 2021-05-21 17:27:57 -0400 | [diff] [blame] | 393 | result->fRewriteMatrixComparisons = true; |
John Stiles | 36c5796 | 2021-05-20 18:00:39 -0400 | [diff] [blame] | 394 | result->fUsesPrecisionModifiers = true; |
| 395 | return result; |
| 396 | } |
| 397 | |
John Stiles | 85749c0 | 2021-03-23 17:12:03 -0400 | [diff] [blame] | 398 | static ShaderCapsPointer RewriteMatrixVectorMultiply() { |
| 399 | ShaderCapsPointer result = MakeShaderCaps(); |
| 400 | result->fVersionDeclString = "#version 400"; |
| 401 | result->fRewriteMatrixVectorMultiply = true; |
| 402 | return result; |
| 403 | } |
| 404 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 405 | static ShaderCapsPointer SampleMaskSupport() { |
| 406 | ShaderCapsPointer result = Default(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 407 | result->fSampleMaskSupport = true; |
| 408 | return result; |
| 409 | } |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 410 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 411 | static ShaderCapsPointer ShaderDerivativeExtensionString() { |
| 412 | ShaderCapsPointer result = MakeShaderCaps(); |
| 413 | result->fVersionDeclString = "#version 400"; |
| 414 | result->fShaderDerivativeSupport = true; |
| 415 | result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives"; |
| 416 | result->fUsesPrecisionModifiers = true; |
| 417 | return result; |
| 418 | } |
| 419 | |
| 420 | static ShaderCapsPointer UnfoldShortCircuitAsTernary() { |
| 421 | ShaderCapsPointer result = MakeShaderCaps(); |
| 422 | result->fVersionDeclString = "#version 400"; |
| 423 | result->fUnfoldShortCircuitAsTernary = true; |
| 424 | return result; |
| 425 | } |
| 426 | |
| 427 | static ShaderCapsPointer UsesPrecisionModifiers() { |
| 428 | ShaderCapsPointer result = MakeShaderCaps(); |
| 429 | result->fVersionDeclString = "#version 400"; |
| 430 | result->fUsesPrecisionModifiers = true; |
| 431 | return result; |
| 432 | } |
| 433 | |
| 434 | static ShaderCapsPointer Version110() { |
| 435 | ShaderCapsPointer result = MakeShaderCaps(); |
| 436 | result->fVersionDeclString = "#version 110"; |
| 437 | result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration; |
| 438 | return result; |
| 439 | } |
| 440 | |
| 441 | static ShaderCapsPointer Version450Core() { |
| 442 | ShaderCapsPointer result = MakeShaderCaps(); |
| 443 | result->fVersionDeclString = "#version 450 core"; |
| 444 | return result; |
| 445 | } |
| 446 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 447 | private: |
| 448 | static ShaderCapsPointer MakeShaderCaps(); |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 449 | }; |
| 450 | |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 451 | #if !defined(SKSL_STANDALONE) |
| 452 | bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType); |
| 453 | #endif |
| 454 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 455 | void write_stringstream(const StringStream& d, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 456 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 457 | } // namespace SkSL |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 458 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 459 | #endif // SKSL_UTIL |