blob: aab1444a0520c4420e464c0aae776f2706de1760 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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 Nicholas0df1b042017-03-31 13:56:23 -04007
ethannicholasb3058bd2016-07-01 08:22:01 -07008#ifndef SKSL_UTIL
9#define SKSL_UTIL
10
Ethan Nicholas0df1b042017-03-31 13:56:23 -040011#include <cstdarg>
12#include <memory>
ethannicholasb3058bd2016-07-01 08:22:01 -070013#include "stdlib.h"
Ethan Nicholas0df1b042017-03-31 13:56:23 -040014#include "string.h"
Ethan Nicholasdaed2592021-03-04 14:30:25 -050015#include "include/private/SkSLDefines.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/sksl/SkSLLexer.h"
Ethan Nicholas0df1b042017-03-31 13:56:23 -040017
Ethan Nicholas842d31b2019-01-22 10:59:11 -050018#ifndef SKSL_STANDALONE
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "include/core/SkTypes.h"
Brian Osman3000d6b2020-07-31 15:57:28 -040020#include "include/private/GrTypesPriv.h"
Ethan Nicholas7ad3f222020-01-22 11:44:18 -050021#if SK_SUPPORT_GPU
Brian Osmanb08cc022020-04-02 11:38:40 -040022#include "include/gpu/GrContextOptions.h"
Ethan Nicholas7ad3f222020-01-22 11:44:18 -050023#include "src/gpu/GrShaderCaps.h"
24#endif // SK_SUPPORT_GPU
Ethan Nicholas682f2992020-01-22 12:58:42 -050025#endif // SKSL_STANDALONE
Brian Salomonc7fe0f72018-05-11 10:14:21 -040026
Brian Osmanb08cc022020-04-02 11:38:40 -040027class GrShaderCaps;
28
ethannicholasb3058bd2016-07-01 08:22:01 -070029namespace SkSL {
30
Brian Osman3000d6b2020-07-31 15:57:28 -040031class Context;
Ethan Nicholas842d31b2019-01-22 10:59:11 -050032class OutputStream;
33class StringStream;
Brian Osman3000d6b2020-07-31 15:57:28 -040034class Type;
Ethan Nicholas842d31b2019-01-22 10:59:11 -050035
Brian Salomonc7fe0f72018-05-11 10:14:21 -040036#if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
Ethan Nicholas0df1b042017-03-31 13:56:23 -040037
38// we're being compiled standalone, so we don't have access to caps...
39enum 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 Nicholas0df1b042017-03-31 13:56:23 -040051class StandaloneShaderCaps {
52public:
John Stiles194b9b92020-09-15 15:37:24 -040053 GrGLSLGeneration fGLSLGeneration = k400_GrGLSLGeneration;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040054 GrGLSLGeneration generation() const {
John Stiles194b9b92020-09-15 15:37:24 -040055 return fGLSLGeneration;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040056 }
57
John Stiles194b9b92020-09-15 15:37:24 -040058 bool fAtan2ImplementedAsAtanYOverX = false;
Michael Ludwig24d438b2018-09-12 15:22:50 -040059 bool atan2ImplementedAsAtanYOverX() const {
John Stiles194b9b92020-09-15 15:37:24 -040060 return fAtan2ImplementedAsAtanYOverX;
Michael Ludwig24d438b2018-09-12 15:22:50 -040061 }
62
John Stiles194b9b92020-09-15 15:37:24 -040063 bool fCanUseMinAndAbsTogether = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040064 bool canUseMinAndAbsTogether() const {
John Stiles194b9b92020-09-15 15:37:24 -040065 return fCanUseMinAndAbsTogether;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040066 }
67
John Stiles194b9b92020-09-15 15:37:24 -040068 bool fMustForceNegatedAtanParamToFloat = false;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040069 bool mustForceNegatedAtanParamToFloat() const {
John Stiles194b9b92020-09-15 15:37:24 -040070 return fMustForceNegatedAtanParamToFloat;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040071 }
72
Chris Dalton155c33c2021-06-07 18:51:42 -060073 bool fMustForceNegatedLdexpParamToMultiply = false;
74 bool mustForceNegatedLdexpParamToMultiply() const {
75 return fMustForceNegatedLdexpParamToMultiply;
76 }
77
John Stiles194b9b92020-09-15 15:37:24 -040078 bool fShaderDerivativeSupport = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040079 bool shaderDerivativeSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -040080 return fShaderDerivativeSupport;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040081 }
82
John Stilesdb42bf22020-09-15 16:09:11 -040083 bool fUsesPrecisionModifiers = false;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040084 bool usesPrecisionModifiers() const {
John Stiles194b9b92020-09-15 15:37:24 -040085 return fUsesPrecisionModifiers;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040086 }
87
88 bool mustDeclareFragmentShaderOutput() const {
John Stiles72664be2020-09-16 17:43:11 -040089 return fGLSLGeneration > k110_GrGLSLGeneration;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040090 }
91
John Stiles194b9b92020-09-15 15:37:24 -040092 bool fFBFetchSupport = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040093 bool fbFetchSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -040094 return fFBFetchSupport;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040095 }
96
John Stiles194b9b92020-09-15 15:37:24 -040097 bool fFBFetchNeedsCustomOutput = false;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040098 bool fbFetchNeedsCustomOutput() const {
John Stiles194b9b92020-09-15 15:37:24 -040099 return fFBFetchNeedsCustomOutput;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400100 }
101
John Stiles194b9b92020-09-15 15:37:24 -0400102 bool fFlatInterpolationSupport = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400103 bool flatInterpolationSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400104 return fFlatInterpolationSupport;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400105 }
106
John Stiles194b9b92020-09-15 15:37:24 -0400107 bool fNoperspectiveInterpolationSupport = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400108 bool noperspectiveInterpolationSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400109 return fNoperspectiveInterpolationSupport;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400110 }
111
John Stiles194b9b92020-09-15 15:37:24 -0400112 bool fMultisampleInterpolationSupport = true;
Robert Phillips7f861922018-01-30 13:13:42 +0000113 bool multisampleInterpolationSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400114 return fMultisampleInterpolationSupport;
Robert Phillips7f861922018-01-30 13:13:42 +0000115 }
116
John Stiles194b9b92020-09-15 15:37:24 -0400117 bool fSampleMaskSupport = true;
Chris Dalton8a64a442019-10-29 18:54:58 -0600118 bool sampleMaskSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400119 return fSampleMaskSupport;
Chris Dalton1ae54bc2019-10-29 16:28:01 -0600120 }
121
John Stiles194b9b92020-09-15 15:37:24 -0400122 bool fExternalTextureSupport = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400123 bool externalTextureSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400124 return fExternalTextureSupport;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400125 }
126
John Stiles194b9b92020-09-15 15:37:24 -0400127 bool fMustDoOpBetweenFloorAndAbs = false;
Michael Ludwig4f94ef62018-09-12 15:22:16 -0400128 bool mustDoOpBetweenFloorAndAbs() const {
John Stiles194b9b92020-09-15 15:37:24 -0400129 return fMustDoOpBetweenFloorAndAbs;
Michael Ludwig4f94ef62018-09-12 15:22:16 -0400130 }
131
John Stiles194b9b92020-09-15 15:37:24 -0400132 bool fMustGuardDivisionEvenAfterExplicitZeroCheck = false;
Brian Salomonf8c187c2019-12-19 14:41:57 -0500133 bool mustGuardDivisionEvenAfterExplicitZeroCheck() const {
John Stiles194b9b92020-09-15 15:37:24 -0400134 return fMustGuardDivisionEvenAfterExplicitZeroCheck;
Brian Salomonf8c187c2019-12-19 14:41:57 -0500135 }
136
John Stiles194b9b92020-09-15 15:37:24 -0400137 bool fInBlendModesFailRandomlyForAllZeroVec = false;
Brian Salomonf8c187c2019-12-19 14:41:57 -0500138 bool inBlendModesFailRandomlyForAllZeroVec() const {
John Stiles194b9b92020-09-15 15:37:24 -0400139 return fInBlendModesFailRandomlyForAllZeroVec;
Brian Salomonf8c187c2019-12-19 14:41:57 -0500140 }
141
John Stiles194b9b92020-09-15 15:37:24 -0400142 bool fMustEnableAdvBlendEqs = false;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400143 bool mustEnableAdvBlendEqs() const {
John Stiles194b9b92020-09-15 15:37:24 -0400144 return fMustEnableAdvBlendEqs;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400145 }
146
Brian Osmanb047b5d2020-11-03 11:56:42 -0500147 bool fCanUseAnyFunctionInShader = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400148 bool canUseAnyFunctionInShader() const {
John Stiles194b9b92020-09-15 15:37:24 -0400149 return fCanUseAnyFunctionInShader;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400150 }
151
John Stiles194b9b92020-09-15 15:37:24 -0400152 bool fNoDefaultPrecisionForExternalSamplers = false;
Brian Salomon5a5f3e82019-08-16 15:05:40 -0400153 bool noDefaultPrecisionForExternalSamplers() const {
John Stiles194b9b92020-09-15 15:37:24 -0400154 return fNoDefaultPrecisionForExternalSamplers;
Brian Salomon5a5f3e82019-08-16 15:05:40 -0400155 }
156
John Stiles194b9b92020-09-15 15:37:24 -0400157 bool fFloatIs32Bits = true;
Chris Dalton47c8ed32017-11-15 18:27:09 -0700158 bool floatIs32Bits() const {
John Stiles194b9b92020-09-15 15:37:24 -0400159 return fFloatIs32Bits;
Ethan Nicholas762466e2017-06-29 10:03:38 -0400160 }
161
John Stiles194b9b92020-09-15 15:37:24 -0400162 bool fIntegerSupport = false;
Ethan Nicholas07990de2017-07-18 09:47:43 -0400163 bool integerSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400164 return fIntegerSupport;
Ethan Nicholas07990de2017-07-18 09:47:43 -0400165 }
166
John Stilesec793492021-05-03 09:21:12 -0400167 bool fNonsquareMatrixSupport = false;
168 bool nonsquareMatrixSupport() const {
169 return fNonsquareMatrixSupport;
170 }
171
John Stilesbc9222b2021-08-17 15:58:03 -0400172 bool fInverseHyperbolicSupport = false;
173 bool inverseHyperbolicSupport() const {
174 return fInverseHyperbolicSupport;
175 }
176
Brian Osmand8efe702020-09-22 09:49:04 -0400177 bool fBuiltinFMASupport = false;
Chris Dalton07ee63d2018-11-16 11:02:34 -0500178 bool builtinFMASupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400179 return fBuiltinFMASupport;
Chris Dalton07ee63d2018-11-16 11:02:34 -0500180 }
181
John Stiles6f3015a2020-10-08 14:55:36 -0400182 bool fBuiltinDeterminantSupport = false;
183 bool builtinDeterminantSupport() const {
184 return fBuiltinDeterminantSupport;
185 }
186
John Stiles194b9b92020-09-15 15:37:24 -0400187 bool fCanUseDoLoops = false;
Ethan Nicholas70728ef2020-05-28 07:09:00 -0400188 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 Stiles194b9b92020-09-15 15:37:24 -0400192 return fCanUseDoLoops;
Ethan Nicholas70728ef2020-05-28 07:09:00 -0400193 }
194
Brian Osman28f702c2021-02-02 11:52:07 -0500195 bool fUseNodePools = true;
196 bool useNodePools() const {
197 return fUseNodePools;
198 }
199
John Stiles194b9b92020-09-15 15:37:24 -0400200 const char* fShaderDerivativeExtensionString = nullptr;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400201 const char* shaderDerivativeExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400202 return fShaderDerivativeExtensionString;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400203 }
204
John Stiles194b9b92020-09-15 15:37:24 -0400205 const char* fFragCoordConventionsExtensionString = nullptr;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400206 const char* fragCoordConventionsExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400207 return fFragCoordConventionsExtensionString;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400208 }
209
John Stiles194b9b92020-09-15 15:37:24 -0400210 const char* fExternalTextureExtensionString = nullptr;
Brian Osman4b2f9152018-04-17 11:19:57 -0400211 const char* externalTextureExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400212 return fExternalTextureExtensionString;
Brian Osman4b2f9152018-04-17 11:19:57 -0400213 }
214
John Stiles194b9b92020-09-15 15:37:24 -0400215 const char* fSecondExternalTextureExtensionString = nullptr;
Brian Osman061020e2018-04-17 14:22:15 -0400216 const char* secondExternalTextureExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400217 return fSecondExternalTextureExtensionString;
Brian Osman061020e2018-04-17 14:22:15 -0400218 }
219
John Stiles194b9b92020-09-15 15:37:24 -0400220 const char* fVersionDeclString = "";
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400221 const char* versionDeclString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400222 return fVersionDeclString;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400223 }
Ethan Nicholas7da6dfa2017-06-21 11:25:18 -0400224
John Stiles194b9b92020-09-15 15:37:24 -0400225 bool fCanUseFractForNegativeValues = true;
Ethan Nicholas1af6d682017-08-08 16:42:13 -0400226 bool canUseFractForNegativeValues() const {
John Stiles194b9b92020-09-15 15:37:24 -0400227 return fCanUseFractForNegativeValues;
Ethan Nicholas1af6d682017-08-08 16:42:13 -0400228 }
Brian Osmancd3261a2018-01-16 13:52:29 +0000229
John Stiles194b9b92020-09-15 15:37:24 -0400230 bool fCanUseFragCoord = true;
Brian Osmancd3261a2018-01-16 13:52:29 +0000231 bool canUseFragCoord() const {
John Stiles194b9b92020-09-15 15:37:24 -0400232 return fCanUseFragCoord;
Brian Osmancd3261a2018-01-16 13:52:29 +0000233 }
Chris Dalton85fcfc52018-03-14 11:15:27 -0600234
John Stiles194b9b92020-09-15 15:37:24 -0400235 bool fIncompleteShortIntPrecision = false;
Chris Dalton85fcfc52018-03-14 11:15:27 -0600236 bool incompleteShortIntPrecision() const {
John Stiles194b9b92020-09-15 15:37:24 -0400237 return fIncompleteShortIntPrecision;
Chris Dalton85fcfc52018-03-14 11:15:27 -0600238 }
Ethan Nicholas43f6d452018-04-13 16:53:07 -0400239
John Stiles194b9b92020-09-15 15:37:24 -0400240 bool fAddAndTrueToLoopCondition = false;
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700241 bool addAndTrueToLoopCondition() const {
John Stiles194b9b92020-09-15 15:37:24 -0400242 return fAddAndTrueToLoopCondition;
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700243 }
244
John Stiles194b9b92020-09-15 15:37:24 -0400245 bool fUnfoldShortCircuitAsTernary = false;
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700246 bool unfoldShortCircuitAsTernary() const {
John Stiles194b9b92020-09-15 15:37:24 -0400247 return fUnfoldShortCircuitAsTernary;
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700248 }
249
John Stiles194b9b92020-09-15 15:37:24 -0400250 bool fEmulateAbsIntFunction = false;
Adrienne Walker92b161f2018-08-22 10:41:52 -0700251 bool emulateAbsIntFunction() const {
John Stiles194b9b92020-09-15 15:37:24 -0400252 return fEmulateAbsIntFunction;
Adrienne Walker92b161f2018-08-22 10:41:52 -0700253 }
254
John Stiles194b9b92020-09-15 15:37:24 -0400255 bool fRewriteDoWhileLoops = false;
Adrienne Walker8b23ca62018-08-22 10:45:41 -0700256 bool rewriteDoWhileLoops() const {
John Stiles194b9b92020-09-15 15:37:24 -0400257 return fRewriteDoWhileLoops;
Adrienne Walker8b23ca62018-08-22 10:45:41 -0700258 }
259
John Stiles194b9b92020-09-15 15:37:24 -0400260 bool fRemovePowWithConstantExponent = false;
Adrienne Walker2f4c09b2018-08-22 16:04:57 -0700261 bool removePowWithConstantExponent() const {
John Stiles194b9b92020-09-15 15:37:24 -0400262 return fRemovePowWithConstantExponent;
Adrienne Walker2f4c09b2018-08-22 16:04:57 -0700263 }
264
John Stiles194b9b92020-09-15 15:37:24 -0400265 const char* fFBFetchColorName = nullptr;
Ethan Nicholas43f6d452018-04-13 16:53:07 -0400266 const char* fbFetchColorName() const {
John Stiles194b9b92020-09-15 15:37:24 -0400267 return fFBFetchColorName;
Ethan Nicholas43f6d452018-04-13 16:53:07 -0400268 }
John Stiles85749c02021-03-23 17:12:03 -0400269
270 bool fRewriteMatrixVectorMultiply = false;
271 bool rewriteMatrixVectorMultiply() const {
272 return fRewriteMatrixVectorMultiply;
273 }
274
John Stiles5ee369f2021-05-21 17:27:57 -0400275 bool fRewriteMatrixComparisons = false;
276 bool rewriteMatrixComparisons() const {
277 return fRewriteMatrixComparisons;
John Stiles36c57962021-05-20 18:00:39 -0400278 }
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400279};
280
John Stiles194b9b92020-09-15 15:37:24 -0400281using ShaderCapsClass = StandaloneShaderCaps;
282using ShaderCapsPointer = std::shared_ptr<StandaloneShaderCaps>;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400283extern StandaloneShaderCaps standaloneCaps;
284
285#else
286
John Stiles194b9b92020-09-15 15:37:24 -0400287using ShaderCapsClass = GrShaderCaps;
288using ShaderCapsPointer = sk_sp<GrShaderCaps>;
289
290#endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
291
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500292// Various sets of caps for use in tests
Brian Salomonf1dd6772016-11-29 15:27:52 -0500293class ShaderCapsFactory {
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500294public:
John Stiles194b9b92020-09-15 15:37:24 -0400295 static ShaderCapsPointer Default() {
296 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400297 result->fVersionDeclString = "#version 400";
298 result->fShaderDerivativeSupport = true;
John Stiles6f3015a2020-10-08 14:55:36 -0400299 result->fBuiltinDeterminantSupport = true;
John Stilesca4d0742020-09-18 15:41:31 -0400300 result->fCanUseDoLoops = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400301 return result;
302 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500303
John Stiles194b9b92020-09-15 15:37:24 -0400304 static ShaderCapsPointer Standalone() {
305 return MakeShaderCaps();
306 }
307
John Stiles8f84cee2020-10-08 18:39:08 -0400308 static ShaderCapsPointer AddAndTrueToLoopCondition() {
John Stiles194b9b92020-09-15 15:37:24 -0400309 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400310 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400311 result->fAddAndTrueToLoopCondition = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400312 return result;
313 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500314
John Stiles8f84cee2020-10-08 18:39:08 -0400315 static ShaderCapsPointer BlendModesFailRandomlyForAllZeroVec() {
John Stiles194b9b92020-09-15 15:37:24 -0400316 ShaderCapsPointer result = MakeShaderCaps();
John Stiles8f84cee2020-10-08 18:39:08 -0400317 result->fInBlendModesFailRandomlyForAllZeroVec = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400318 return result;
319 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500320
John Stiles194b9b92020-09-15 15:37:24 -0400321 static ShaderCapsPointer CannotUseFractForNegativeValues() {
322 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400323 result->fVersionDeclString = "#version 400";
324 result->fCanUseFractForNegativeValues = false;
325 return result;
326 }
Florin Malita3b30c4f2017-08-08 15:47:35 -0400327
John Stiles8f84cee2020-10-08 18:39:08 -0400328 static ShaderCapsPointer CannotUseFragCoord() {
John Stiles194b9b92020-09-15 15:37:24 -0400329 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400330 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400331 result->fCanUseFragCoord = false;
Brian Osmanb08cc022020-04-02 11:38:40 -0400332 return result;
333 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500334
John Stiles8f84cee2020-10-08 18:39:08 -0400335 static ShaderCapsPointer CannotUseMinAndAbsTogether() {
John Stiles194b9b92020-09-15 15:37:24 -0400336 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400337 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400338 result->fCanUseMinAndAbsTogether = false;
Brian Osmanb08cc022020-04-02 11:38:40 -0400339 return result;
340 }
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500341
John Stiles8f84cee2020-10-08 18:39:08 -0400342 static ShaderCapsPointer EmulateAbsIntFunction() {
John Stiles194b9b92020-09-15 15:37:24 -0400343 ShaderCapsPointer result = MakeShaderCaps();
John Stiles8f84cee2020-10-08 18:39:08 -0400344 result->fVersionDeclString = "#version 400";
345 result->fEmulateAbsIntFunction = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400346 return result;
347 }
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500348
John Stiles194b9b92020-09-15 15:37:24 -0400349 static ShaderCapsPointer IncompleteShortIntPrecision() {
350 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400351 result->fVersionDeclString = "#version 310es";
352 result->fUsesPrecisionModifiers = true;
353 result->fIncompleteShortIntPrecision = true;
354 return result;
355 }
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700356
John Stiles8f84cee2020-10-08 18:39:08 -0400357 static ShaderCapsPointer MustForceNegatedAtanParamToFloat() {
John Stiles194b9b92020-09-15 15:37:24 -0400358 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400359 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400360 result->fMustForceNegatedAtanParamToFloat = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400361 return result;
362 }
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700363
Chris Dalton155c33c2021-06-07 18:51:42 -0600364 static ShaderCapsPointer MustForceNegatedLdexpParamToMultiply() {
365 ShaderCapsPointer result = MakeShaderCaps();
366 result->fVersionDeclString = "#version 400";
367 result->fMustForceNegatedLdexpParamToMultiply = true;
368 return result;
369 }
370
John Stileseaaa71b2020-10-08 22:18:10 -0400371 static ShaderCapsPointer MustGuardDivisionEvenAfterExplicitZeroCheck() {
372 ShaderCapsPointer result = MakeShaderCaps();
373 result->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
374 return result;
375 }
376
John Stiles194b9b92020-09-15 15:37:24 -0400377 static ShaderCapsPointer RemovePowWithConstantExponent() {
378 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400379 result->fVersionDeclString = "#version 400";
380 result->fRemovePowWithConstantExponent = true;
381 return result;
382 }
Chris Daltonb0fd4b12019-10-29 13:41:22 -0600383
John Stiles8f84cee2020-10-08 18:39:08 -0400384 static ShaderCapsPointer RewriteDoWhileLoops() {
385 ShaderCapsPointer result = MakeShaderCaps();
386 result->fVersionDeclString = "#version 400";
387 result->fRewriteDoWhileLoops = true;
388 return result;
389 }
390
John Stiles5ee369f2021-05-21 17:27:57 -0400391 static ShaderCapsPointer RewriteMatrixComparisons() {
John Stiles36c57962021-05-20 18:00:39 -0400392 ShaderCapsPointer result = MakeShaderCaps();
John Stiles5ee369f2021-05-21 17:27:57 -0400393 result->fRewriteMatrixComparisons = true;
John Stiles36c57962021-05-20 18:00:39 -0400394 result->fUsesPrecisionModifiers = true;
395 return result;
396 }
397
John Stiles85749c02021-03-23 17:12:03 -0400398 static ShaderCapsPointer RewriteMatrixVectorMultiply() {
399 ShaderCapsPointer result = MakeShaderCaps();
400 result->fVersionDeclString = "#version 400";
401 result->fRewriteMatrixVectorMultiply = true;
402 return result;
403 }
404
John Stiles194b9b92020-09-15 15:37:24 -0400405 static ShaderCapsPointer SampleMaskSupport() {
406 ShaderCapsPointer result = Default();
Brian Osmanb08cc022020-04-02 11:38:40 -0400407 result->fSampleMaskSupport = true;
408 return result;
409 }
John Stiles194b9b92020-09-15 15:37:24 -0400410
John Stiles8f84cee2020-10-08 18:39:08 -0400411 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 Stiles194b9b92020-09-15 15:37:24 -0400447private:
448 static ShaderCapsPointer MakeShaderCaps();
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500449};
450
Brian Osman3000d6b2020-07-31 15:57:28 -0400451#if !defined(SKSL_STANDALONE)
452bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType);
453#endif
454
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400455void write_stringstream(const StringStream& d, OutputStream& out);
ethannicholasb3058bd2016-07-01 08:22:01 -0700456
John Stilesa6841be2020-08-06 14:11:56 -0400457} // namespace SkSL
ethannicholasb3058bd2016-07-01 08:22:01 -0700458
John Stiles194b9b92020-09-15 15:37:24 -0400459#endif // SKSL_UTIL