blob: 40a54b08684fcb3328bbccb2f2815afbc719141b [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
Brian Osmana81e7e22021-09-15 10:28:27 -040092 bool fFBFetchSupport = false;
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 Stiles6b888392021-09-24 11:33:54 -0400260 bool fRewriteSwitchStatements = false;
261 bool rewriteSwitchStatements() const {
262 return fRewriteSwitchStatements;
263 }
264
John Stiles194b9b92020-09-15 15:37:24 -0400265 bool fRemovePowWithConstantExponent = false;
Adrienne Walker2f4c09b2018-08-22 16:04:57 -0700266 bool removePowWithConstantExponent() const {
John Stiles194b9b92020-09-15 15:37:24 -0400267 return fRemovePowWithConstantExponent;
Adrienne Walker2f4c09b2018-08-22 16:04:57 -0700268 }
269
John Stiles194b9b92020-09-15 15:37:24 -0400270 const char* fFBFetchColorName = nullptr;
Ethan Nicholas43f6d452018-04-13 16:53:07 -0400271 const char* fbFetchColorName() const {
John Stiles194b9b92020-09-15 15:37:24 -0400272 return fFBFetchColorName;
Ethan Nicholas43f6d452018-04-13 16:53:07 -0400273 }
John Stiles85749c02021-03-23 17:12:03 -0400274
275 bool fRewriteMatrixVectorMultiply = false;
276 bool rewriteMatrixVectorMultiply() const {
277 return fRewriteMatrixVectorMultiply;
278 }
279
John Stiles5ee369f2021-05-21 17:27:57 -0400280 bool fRewriteMatrixComparisons = false;
281 bool rewriteMatrixComparisons() const {
282 return fRewriteMatrixComparisons;
John Stiles36c57962021-05-20 18:00:39 -0400283 }
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400284};
285
John Stiles194b9b92020-09-15 15:37:24 -0400286using ShaderCapsClass = StandaloneShaderCaps;
287using ShaderCapsPointer = std::shared_ptr<StandaloneShaderCaps>;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400288extern StandaloneShaderCaps standaloneCaps;
289
290#else
291
John Stiles194b9b92020-09-15 15:37:24 -0400292using ShaderCapsClass = GrShaderCaps;
293using ShaderCapsPointer = sk_sp<GrShaderCaps>;
294
295#endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
296
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500297// Various sets of caps for use in tests
Brian Salomonf1dd6772016-11-29 15:27:52 -0500298class ShaderCapsFactory {
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500299public:
John Stiles194b9b92020-09-15 15:37:24 -0400300 static ShaderCapsPointer Default() {
301 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400302 result->fVersionDeclString = "#version 400";
303 result->fShaderDerivativeSupport = true;
John Stiles6f3015a2020-10-08 14:55:36 -0400304 result->fBuiltinDeterminantSupport = true;
John Stilesca4d0742020-09-18 15:41:31 -0400305 result->fCanUseDoLoops = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400306 return result;
307 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500308
John Stiles194b9b92020-09-15 15:37:24 -0400309 static ShaderCapsPointer Standalone() {
310 return MakeShaderCaps();
311 }
312
John Stiles8f84cee2020-10-08 18:39:08 -0400313 static ShaderCapsPointer AddAndTrueToLoopCondition() {
John Stiles194b9b92020-09-15 15:37:24 -0400314 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400315 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400316 result->fAddAndTrueToLoopCondition = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400317 return result;
318 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500319
John Stiles8f84cee2020-10-08 18:39:08 -0400320 static ShaderCapsPointer BlendModesFailRandomlyForAllZeroVec() {
John Stiles194b9b92020-09-15 15:37:24 -0400321 ShaderCapsPointer result = MakeShaderCaps();
John Stiles8f84cee2020-10-08 18:39:08 -0400322 result->fInBlendModesFailRandomlyForAllZeroVec = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400323 return result;
324 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500325
John Stiles194b9b92020-09-15 15:37:24 -0400326 static ShaderCapsPointer CannotUseFractForNegativeValues() {
327 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400328 result->fVersionDeclString = "#version 400";
329 result->fCanUseFractForNegativeValues = false;
330 return result;
331 }
Florin Malita3b30c4f2017-08-08 15:47:35 -0400332
John Stiles8f84cee2020-10-08 18:39:08 -0400333 static ShaderCapsPointer CannotUseFragCoord() {
John Stiles194b9b92020-09-15 15:37:24 -0400334 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400335 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400336 result->fCanUseFragCoord = false;
Brian Osmanb08cc022020-04-02 11:38:40 -0400337 return result;
338 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500339
John Stiles8f84cee2020-10-08 18:39:08 -0400340 static ShaderCapsPointer CannotUseMinAndAbsTogether() {
John Stiles194b9b92020-09-15 15:37:24 -0400341 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400342 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400343 result->fCanUseMinAndAbsTogether = false;
Brian Osmanb08cc022020-04-02 11:38:40 -0400344 return result;
345 }
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500346
John Stiles8f84cee2020-10-08 18:39:08 -0400347 static ShaderCapsPointer EmulateAbsIntFunction() {
John Stiles194b9b92020-09-15 15:37:24 -0400348 ShaderCapsPointer result = MakeShaderCaps();
John Stiles8f84cee2020-10-08 18:39:08 -0400349 result->fVersionDeclString = "#version 400";
350 result->fEmulateAbsIntFunction = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400351 return result;
352 }
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500353
Brian Osmana81e7e22021-09-15 10:28:27 -0400354 static ShaderCapsPointer FramebufferFetchSupport() {
355 ShaderCapsPointer result = MakeShaderCaps();
356 result->fFBFetchSupport = true;
357 result->fFBFetchColorName = "gl_LastFragData[0]";
358 return result;
359 }
360
John Stiles194b9b92020-09-15 15:37:24 -0400361 static ShaderCapsPointer IncompleteShortIntPrecision() {
362 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400363 result->fVersionDeclString = "#version 310es";
364 result->fUsesPrecisionModifiers = true;
365 result->fIncompleteShortIntPrecision = true;
366 return result;
367 }
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700368
John Stiles8f84cee2020-10-08 18:39:08 -0400369 static ShaderCapsPointer MustForceNegatedAtanParamToFloat() {
John Stiles194b9b92020-09-15 15:37:24 -0400370 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400371 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400372 result->fMustForceNegatedAtanParamToFloat = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400373 return result;
374 }
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700375
Chris Dalton155c33c2021-06-07 18:51:42 -0600376 static ShaderCapsPointer MustForceNegatedLdexpParamToMultiply() {
377 ShaderCapsPointer result = MakeShaderCaps();
378 result->fVersionDeclString = "#version 400";
379 result->fMustForceNegatedLdexpParamToMultiply = true;
380 return result;
381 }
382
John Stileseaaa71b2020-10-08 22:18:10 -0400383 static ShaderCapsPointer MustGuardDivisionEvenAfterExplicitZeroCheck() {
384 ShaderCapsPointer result = MakeShaderCaps();
385 result->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
386 return result;
387 }
388
John Stiles194b9b92020-09-15 15:37:24 -0400389 static ShaderCapsPointer RemovePowWithConstantExponent() {
390 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400391 result->fVersionDeclString = "#version 400";
392 result->fRemovePowWithConstantExponent = true;
393 return result;
394 }
Chris Daltonb0fd4b12019-10-29 13:41:22 -0600395
John Stiles8f84cee2020-10-08 18:39:08 -0400396 static ShaderCapsPointer RewriteDoWhileLoops() {
397 ShaderCapsPointer result = MakeShaderCaps();
398 result->fVersionDeclString = "#version 400";
399 result->fRewriteDoWhileLoops = true;
400 return result;
401 }
402
John Stiles5ee369f2021-05-21 17:27:57 -0400403 static ShaderCapsPointer RewriteMatrixComparisons() {
John Stiles36c57962021-05-20 18:00:39 -0400404 ShaderCapsPointer result = MakeShaderCaps();
John Stiles5ee369f2021-05-21 17:27:57 -0400405 result->fRewriteMatrixComparisons = true;
John Stiles36c57962021-05-20 18:00:39 -0400406 result->fUsesPrecisionModifiers = true;
407 return result;
408 }
409
John Stiles85749c02021-03-23 17:12:03 -0400410 static ShaderCapsPointer RewriteMatrixVectorMultiply() {
411 ShaderCapsPointer result = MakeShaderCaps();
412 result->fVersionDeclString = "#version 400";
413 result->fRewriteMatrixVectorMultiply = true;
414 return result;
415 }
416
John Stiles6b888392021-09-24 11:33:54 -0400417 static ShaderCapsPointer RewriteSwitchStatements() {
418 ShaderCapsPointer result = MakeShaderCaps();
419 result->fVersionDeclString = "#version 400";
420 result->fRewriteSwitchStatements = true;
421 return result;
422 }
423
John Stiles194b9b92020-09-15 15:37:24 -0400424 static ShaderCapsPointer SampleMaskSupport() {
425 ShaderCapsPointer result = Default();
Brian Osmanb08cc022020-04-02 11:38:40 -0400426 result->fSampleMaskSupport = true;
427 return result;
428 }
John Stiles194b9b92020-09-15 15:37:24 -0400429
John Stiles8f84cee2020-10-08 18:39:08 -0400430 static ShaderCapsPointer ShaderDerivativeExtensionString() {
431 ShaderCapsPointer result = MakeShaderCaps();
432 result->fVersionDeclString = "#version 400";
433 result->fShaderDerivativeSupport = true;
434 result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
435 result->fUsesPrecisionModifiers = true;
436 return result;
437 }
438
439 static ShaderCapsPointer UnfoldShortCircuitAsTernary() {
440 ShaderCapsPointer result = MakeShaderCaps();
441 result->fVersionDeclString = "#version 400";
442 result->fUnfoldShortCircuitAsTernary = true;
443 return result;
444 }
445
446 static ShaderCapsPointer UsesPrecisionModifiers() {
447 ShaderCapsPointer result = MakeShaderCaps();
448 result->fVersionDeclString = "#version 400";
449 result->fUsesPrecisionModifiers = true;
450 return result;
451 }
452
453 static ShaderCapsPointer Version110() {
454 ShaderCapsPointer result = MakeShaderCaps();
455 result->fVersionDeclString = "#version 110";
456 result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
457 return result;
458 }
459
460 static ShaderCapsPointer Version450Core() {
461 ShaderCapsPointer result = MakeShaderCaps();
462 result->fVersionDeclString = "#version 450 core";
463 return result;
464 }
465
John Stiles194b9b92020-09-15 15:37:24 -0400466private:
467 static ShaderCapsPointer MakeShaderCaps();
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500468};
469
Brian Osman3000d6b2020-07-31 15:57:28 -0400470#if !defined(SKSL_STANDALONE)
471bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType);
472#endif
473
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400474void write_stringstream(const StringStream& d, OutputStream& out);
ethannicholasb3058bd2016-07-01 08:22:01 -0700475
John Stilesa6841be2020-08-06 14:11:56 -0400476} // namespace SkSL
ethannicholasb3058bd2016-07-01 08:22:01 -0700477
John Stiles194b9b92020-09-15 15:37:24 -0400478#endif // SKSL_UTIL