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 | |
Brian Osman | a81e7e2 | 2021-09-15 10:28:27 -0400 | [diff] [blame^] | 92 | bool fFBFetchSupport = false; |
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 | |
Brian Osman | a81e7e2 | 2021-09-15 10:28:27 -0400 | [diff] [blame^] | 349 | static ShaderCapsPointer FramebufferFetchSupport() { |
| 350 | ShaderCapsPointer result = MakeShaderCaps(); |
| 351 | result->fFBFetchSupport = true; |
| 352 | result->fFBFetchColorName = "gl_LastFragData[0]"; |
| 353 | return result; |
| 354 | } |
| 355 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 356 | static ShaderCapsPointer IncompleteShortIntPrecision() { |
| 357 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 358 | result->fVersionDeclString = "#version 310es"; |
| 359 | result->fUsesPrecisionModifiers = true; |
| 360 | result->fIncompleteShortIntPrecision = true; |
| 361 | return result; |
| 362 | } |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 363 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 364 | static ShaderCapsPointer MustForceNegatedAtanParamToFloat() { |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 365 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 366 | result->fVersionDeclString = "#version 400"; |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 367 | result->fMustForceNegatedAtanParamToFloat = true; |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 368 | return result; |
| 369 | } |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 370 | |
Chris Dalton | 155c33c | 2021-06-07 18:51:42 -0600 | [diff] [blame] | 371 | static ShaderCapsPointer MustForceNegatedLdexpParamToMultiply() { |
| 372 | ShaderCapsPointer result = MakeShaderCaps(); |
| 373 | result->fVersionDeclString = "#version 400"; |
| 374 | result->fMustForceNegatedLdexpParamToMultiply = true; |
| 375 | return result; |
| 376 | } |
| 377 | |
John Stiles | eaaa71b | 2020-10-08 22:18:10 -0400 | [diff] [blame] | 378 | static ShaderCapsPointer MustGuardDivisionEvenAfterExplicitZeroCheck() { |
| 379 | ShaderCapsPointer result = MakeShaderCaps(); |
| 380 | result->fMustGuardDivisionEvenAfterExplicitZeroCheck = true; |
| 381 | return result; |
| 382 | } |
| 383 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 384 | static ShaderCapsPointer RemovePowWithConstantExponent() { |
| 385 | ShaderCapsPointer result = MakeShaderCaps(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 386 | result->fVersionDeclString = "#version 400"; |
| 387 | result->fRemovePowWithConstantExponent = true; |
| 388 | return result; |
| 389 | } |
Chris Dalton | b0fd4b1 | 2019-10-29 13:41:22 -0600 | [diff] [blame] | 390 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 391 | static ShaderCapsPointer RewriteDoWhileLoops() { |
| 392 | ShaderCapsPointer result = MakeShaderCaps(); |
| 393 | result->fVersionDeclString = "#version 400"; |
| 394 | result->fRewriteDoWhileLoops = true; |
| 395 | return result; |
| 396 | } |
| 397 | |
John Stiles | 5ee369f | 2021-05-21 17:27:57 -0400 | [diff] [blame] | 398 | static ShaderCapsPointer RewriteMatrixComparisons() { |
John Stiles | 36c5796 | 2021-05-20 18:00:39 -0400 | [diff] [blame] | 399 | ShaderCapsPointer result = MakeShaderCaps(); |
John Stiles | 5ee369f | 2021-05-21 17:27:57 -0400 | [diff] [blame] | 400 | result->fRewriteMatrixComparisons = true; |
John Stiles | 36c5796 | 2021-05-20 18:00:39 -0400 | [diff] [blame] | 401 | result->fUsesPrecisionModifiers = true; |
| 402 | return result; |
| 403 | } |
| 404 | |
John Stiles | 85749c0 | 2021-03-23 17:12:03 -0400 | [diff] [blame] | 405 | static ShaderCapsPointer RewriteMatrixVectorMultiply() { |
| 406 | ShaderCapsPointer result = MakeShaderCaps(); |
| 407 | result->fVersionDeclString = "#version 400"; |
| 408 | result->fRewriteMatrixVectorMultiply = true; |
| 409 | return result; |
| 410 | } |
| 411 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 412 | static ShaderCapsPointer SampleMaskSupport() { |
| 413 | ShaderCapsPointer result = Default(); |
Brian Osman | b08cc02 | 2020-04-02 11:38:40 -0400 | [diff] [blame] | 414 | result->fSampleMaskSupport = true; |
| 415 | return result; |
| 416 | } |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 417 | |
John Stiles | 8f84cee | 2020-10-08 18:39:08 -0400 | [diff] [blame] | 418 | static ShaderCapsPointer ShaderDerivativeExtensionString() { |
| 419 | ShaderCapsPointer result = MakeShaderCaps(); |
| 420 | result->fVersionDeclString = "#version 400"; |
| 421 | result->fShaderDerivativeSupport = true; |
| 422 | result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives"; |
| 423 | result->fUsesPrecisionModifiers = true; |
| 424 | return result; |
| 425 | } |
| 426 | |
| 427 | static ShaderCapsPointer UnfoldShortCircuitAsTernary() { |
| 428 | ShaderCapsPointer result = MakeShaderCaps(); |
| 429 | result->fVersionDeclString = "#version 400"; |
| 430 | result->fUnfoldShortCircuitAsTernary = true; |
| 431 | return result; |
| 432 | } |
| 433 | |
| 434 | static ShaderCapsPointer UsesPrecisionModifiers() { |
| 435 | ShaderCapsPointer result = MakeShaderCaps(); |
| 436 | result->fVersionDeclString = "#version 400"; |
| 437 | result->fUsesPrecisionModifiers = true; |
| 438 | return result; |
| 439 | } |
| 440 | |
| 441 | static ShaderCapsPointer Version110() { |
| 442 | ShaderCapsPointer result = MakeShaderCaps(); |
| 443 | result->fVersionDeclString = "#version 110"; |
| 444 | result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration; |
| 445 | return result; |
| 446 | } |
| 447 | |
| 448 | static ShaderCapsPointer Version450Core() { |
| 449 | ShaderCapsPointer result = MakeShaderCaps(); |
| 450 | result->fVersionDeclString = "#version 450 core"; |
| 451 | return result; |
| 452 | } |
| 453 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 454 | private: |
| 455 | static ShaderCapsPointer MakeShaderCaps(); |
Ethan Nicholas | 7ef4b74 | 2016-11-11 15:16:46 -0500 | [diff] [blame] | 456 | }; |
| 457 | |
Brian Osman | 3000d6b | 2020-07-31 15:57:28 -0400 | [diff] [blame] | 458 | #if !defined(SKSL_STANDALONE) |
| 459 | bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType); |
| 460 | #endif |
| 461 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 462 | void write_stringstream(const StringStream& d, OutputStream& out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 463 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 464 | } // namespace SkSL |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 465 | |
John Stiles | 194b9b9 | 2020-09-15 15:37:24 -0400 | [diff] [blame] | 466 | #endif // SKSL_UTIL |