blob: f0854a5ea0a2a92993cd5d1b1e4945da50c08678 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/sksl/SkSLDefines.h"
16#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
John Stiles194b9b92020-09-15 15:37:24 -040073 bool fGeometryShaderSupport = true;
74 bool geometryShaderSupport() const {
75 return fGeometryShaderSupport;
76 }
77
78 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
John Stiles194b9b92020-09-15 15:37:24 -0400147 bool fMustEnableSpecificAdvBlendEqs = false;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400148 bool mustEnableSpecificAdvBlendEqs() const {
John Stiles194b9b92020-09-15 15:37:24 -0400149 return fMustEnableSpecificAdvBlendEqs;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400150 }
151
Brian Osmanb047b5d2020-11-03 11:56:42 -0500152 bool fCanUseAnyFunctionInShader = true;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400153 bool canUseAnyFunctionInShader() const {
John Stiles194b9b92020-09-15 15:37:24 -0400154 return fCanUseAnyFunctionInShader;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400155 }
156
John Stiles194b9b92020-09-15 15:37:24 -0400157 bool fNoDefaultPrecisionForExternalSamplers = false;
Brian Salomon5a5f3e82019-08-16 15:05:40 -0400158 bool noDefaultPrecisionForExternalSamplers() const {
John Stiles194b9b92020-09-15 15:37:24 -0400159 return fNoDefaultPrecisionForExternalSamplers;
Brian Salomon5a5f3e82019-08-16 15:05:40 -0400160 }
161
John Stiles194b9b92020-09-15 15:37:24 -0400162 bool fFloatIs32Bits = true;
Chris Dalton47c8ed32017-11-15 18:27:09 -0700163 bool floatIs32Bits() const {
John Stiles194b9b92020-09-15 15:37:24 -0400164 return fFloatIs32Bits;
Ethan Nicholas762466e2017-06-29 10:03:38 -0400165 }
166
John Stiles194b9b92020-09-15 15:37:24 -0400167 bool fIntegerSupport = false;
Ethan Nicholas07990de2017-07-18 09:47:43 -0400168 bool integerSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400169 return fIntegerSupport;
Ethan Nicholas07990de2017-07-18 09:47:43 -0400170 }
171
Brian Osmand8efe702020-09-22 09:49:04 -0400172 bool fBuiltinFMASupport = false;
Chris Dalton07ee63d2018-11-16 11:02:34 -0500173 bool builtinFMASupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400174 return fBuiltinFMASupport;
Chris Dalton07ee63d2018-11-16 11:02:34 -0500175 }
176
John Stiles6f3015a2020-10-08 14:55:36 -0400177 bool fBuiltinDeterminantSupport = false;
178 bool builtinDeterminantSupport() const {
179 return fBuiltinDeterminantSupport;
180 }
181
John Stiles194b9b92020-09-15 15:37:24 -0400182 bool fCanUseDoLoops = false;
Ethan Nicholas70728ef2020-05-28 07:09:00 -0400183 bool canUseDoLoops() const {
184 // we define this to false in standalone so we don't use do loops while inlining in FP files
185 // (which would then, being baked in, end up being used even in contexts where do loops are
186 // not allowed)
John Stiles194b9b92020-09-15 15:37:24 -0400187 return fCanUseDoLoops;
Ethan Nicholas70728ef2020-05-28 07:09:00 -0400188 }
189
John Stiles194b9b92020-09-15 15:37:24 -0400190 const char* fShaderDerivativeExtensionString = nullptr;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400191 const char* shaderDerivativeExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400192 return fShaderDerivativeExtensionString;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400193 }
194
John Stiles194b9b92020-09-15 15:37:24 -0400195 const char* fFragCoordConventionsExtensionString = nullptr;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400196 const char* fragCoordConventionsExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400197 return fFragCoordConventionsExtensionString;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400198 }
199
John Stiles194b9b92020-09-15 15:37:24 -0400200 const char* fGeometryShaderExtensionString = nullptr;
Chris Dalton8fd79552018-01-11 00:46:14 -0500201 const char* geometryShaderExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400202 return fGeometryShaderExtensionString;
Chris Dalton8fd79552018-01-11 00:46:14 -0500203 }
204
John Stiles194b9b92020-09-15 15:37:24 -0400205 const char* fGSInvocationsExtensionString = nullptr;
Chris Dalton567d6f42017-10-06 13:13:32 -0600206 const char* gsInvocationsExtensionString() const {
John Stiles194b9b92020-09-15 15:37:24 -0400207 return fGSInvocationsExtensionString;
Chris Dalton567d6f42017-10-06 13:13:32 -0600208 }
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 fGSInvocationsSupport = true;
Chris Dalton567d6f42017-10-06 13:13:32 -0600226 bool gsInvocationsSupport() const {
John Stiles194b9b92020-09-15 15:37:24 -0400227 return fGSInvocationsSupport;
Ethan Nicholas7da6dfa2017-06-21 11:25:18 -0400228 }
Ethan Nicholas1af6d682017-08-08 16:42:13 -0400229
John Stiles194b9b92020-09-15 15:37:24 -0400230 bool fCanUseFractForNegativeValues = true;
Ethan Nicholas1af6d682017-08-08 16:42:13 -0400231 bool canUseFractForNegativeValues() const {
John Stiles194b9b92020-09-15 15:37:24 -0400232 return fCanUseFractForNegativeValues;
Ethan Nicholas1af6d682017-08-08 16:42:13 -0400233 }
Brian Osmancd3261a2018-01-16 13:52:29 +0000234
John Stiles194b9b92020-09-15 15:37:24 -0400235 bool fCanUseFragCoord = true;
Brian Osmancd3261a2018-01-16 13:52:29 +0000236 bool canUseFragCoord() const {
John Stiles194b9b92020-09-15 15:37:24 -0400237 return fCanUseFragCoord;
Brian Osmancd3261a2018-01-16 13:52:29 +0000238 }
Chris Dalton85fcfc52018-03-14 11:15:27 -0600239
John Stiles194b9b92020-09-15 15:37:24 -0400240 bool fIncompleteShortIntPrecision = false;
Chris Dalton85fcfc52018-03-14 11:15:27 -0600241 bool incompleteShortIntPrecision() const {
John Stiles194b9b92020-09-15 15:37:24 -0400242 return fIncompleteShortIntPrecision;
Chris Dalton85fcfc52018-03-14 11:15:27 -0600243 }
Ethan Nicholas43f6d452018-04-13 16:53:07 -0400244
John Stiles194b9b92020-09-15 15:37:24 -0400245 bool fAddAndTrueToLoopCondition = false;
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700246 bool addAndTrueToLoopCondition() const {
John Stiles194b9b92020-09-15 15:37:24 -0400247 return fAddAndTrueToLoopCondition;
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700248 }
249
John Stiles194b9b92020-09-15 15:37:24 -0400250 bool fUnfoldShortCircuitAsTernary = false;
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700251 bool unfoldShortCircuitAsTernary() const {
John Stiles194b9b92020-09-15 15:37:24 -0400252 return fUnfoldShortCircuitAsTernary;
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700253 }
254
John Stiles194b9b92020-09-15 15:37:24 -0400255 bool fEmulateAbsIntFunction = false;
Adrienne Walker92b161f2018-08-22 10:41:52 -0700256 bool emulateAbsIntFunction() const {
John Stiles194b9b92020-09-15 15:37:24 -0400257 return fEmulateAbsIntFunction;
Adrienne Walker92b161f2018-08-22 10:41:52 -0700258 }
259
John Stiles194b9b92020-09-15 15:37:24 -0400260 bool fRewriteDoWhileLoops = false;
Adrienne Walker8b23ca62018-08-22 10:45:41 -0700261 bool rewriteDoWhileLoops() const {
John Stiles194b9b92020-09-15 15:37:24 -0400262 return fRewriteDoWhileLoops;
Adrienne Walker8b23ca62018-08-22 10:45:41 -0700263 }
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 }
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400274};
275
John Stiles194b9b92020-09-15 15:37:24 -0400276using ShaderCapsClass = StandaloneShaderCaps;
277using ShaderCapsPointer = std::shared_ptr<StandaloneShaderCaps>;
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400278extern StandaloneShaderCaps standaloneCaps;
279
280#else
281
John Stiles194b9b92020-09-15 15:37:24 -0400282using ShaderCapsClass = GrShaderCaps;
283using ShaderCapsPointer = sk_sp<GrShaderCaps>;
284
285#endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
286
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500287// Various sets of caps for use in tests
Brian Salomonf1dd6772016-11-29 15:27:52 -0500288class ShaderCapsFactory {
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500289public:
John Stiles194b9b92020-09-15 15:37:24 -0400290 static ShaderCapsPointer Default() {
291 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400292 result->fVersionDeclString = "#version 400";
293 result->fShaderDerivativeSupport = true;
John Stiles6f3015a2020-10-08 14:55:36 -0400294 result->fBuiltinDeterminantSupport = true;
John Stilesca4d0742020-09-18 15:41:31 -0400295 result->fCanUseDoLoops = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400296 return result;
297 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500298
John Stiles194b9b92020-09-15 15:37:24 -0400299 static ShaderCapsPointer Standalone() {
300 return MakeShaderCaps();
301 }
302
John Stiles8f84cee2020-10-08 18:39:08 -0400303 static ShaderCapsPointer AddAndTrueToLoopCondition() {
John Stiles194b9b92020-09-15 15:37:24 -0400304 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400305 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400306 result->fAddAndTrueToLoopCondition = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400307 return result;
308 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500309
John Stiles8f84cee2020-10-08 18:39:08 -0400310 static ShaderCapsPointer BlendModesFailRandomlyForAllZeroVec() {
John Stiles194b9b92020-09-15 15:37:24 -0400311 ShaderCapsPointer result = MakeShaderCaps();
John Stiles8f84cee2020-10-08 18:39:08 -0400312 result->fInBlendModesFailRandomlyForAllZeroVec = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400313 return result;
314 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500315
John Stiles194b9b92020-09-15 15:37:24 -0400316 static ShaderCapsPointer CannotUseFractForNegativeValues() {
317 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400318 result->fVersionDeclString = "#version 400";
319 result->fCanUseFractForNegativeValues = false;
320 return result;
321 }
Florin Malita3b30c4f2017-08-08 15:47:35 -0400322
John Stiles8f84cee2020-10-08 18:39:08 -0400323 static ShaderCapsPointer CannotUseFragCoord() {
John Stiles194b9b92020-09-15 15:37:24 -0400324 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400325 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400326 result->fCanUseFragCoord = false;
Brian Osmanb08cc022020-04-02 11:38:40 -0400327 return result;
328 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500329
John Stiles8f84cee2020-10-08 18:39:08 -0400330 static ShaderCapsPointer CannotUseMinAndAbsTogether() {
John Stiles194b9b92020-09-15 15:37:24 -0400331 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400332 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400333 result->fCanUseMinAndAbsTogether = false;
Brian Osmanb08cc022020-04-02 11:38:40 -0400334 return result;
335 }
Ethan Nicholas3605ace2016-11-21 15:59:48 -0500336
John Stiles8f84cee2020-10-08 18:39:08 -0400337 static ShaderCapsPointer EmulateAbsIntFunction() {
John Stiles194b9b92020-09-15 15:37:24 -0400338 ShaderCapsPointer result = MakeShaderCaps();
John Stiles8f84cee2020-10-08 18:39:08 -0400339 result->fVersionDeclString = "#version 400";
340 result->fEmulateAbsIntFunction = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400341 return result;
342 }
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500343
John Stiles194b9b92020-09-15 15:37:24 -0400344 static ShaderCapsPointer FragCoordsNew() {
345 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400346 result->fVersionDeclString = "#version 400";
347 result->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
348 return result;
349 }
John Stiles8f84cee2020-10-08 18:39:08 -0400350 static ShaderCapsPointer FragCoordsOld() {
John Stiles194b9b92020-09-15 15:37:24 -0400351 ShaderCapsPointer result = MakeShaderCaps();
John Stiles8f84cee2020-10-08 18:39:08 -0400352 result->fVersionDeclString = "#version 110";
353 result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
354 result->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
Brian Osmanb08cc022020-04-02 11:38:40 -0400355 return result;
356 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600357
John Stiles194b9b92020-09-15 15:37:24 -0400358 static ShaderCapsPointer GeometryShaderExtensionString() {
359 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400360 result->fVersionDeclString = "#version 310es";
361 result->fGeometryShaderSupport = true;
362 result->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
363 result->fGSInvocationsSupport = true;
364 return result;
365 }
Chris Dalton8fd79552018-01-11 00:46:14 -0500366
John Stiles8f84cee2020-10-08 18:39:08 -0400367 static ShaderCapsPointer GeometryShaderSupport() {
368 ShaderCapsPointer result = MakeShaderCaps();
369 result->fVersionDeclString = "#version 400";
370 result->fGeometryShaderSupport = true;
371 result->fGSInvocationsSupport = true;
372 return result;
373 }
374
John Stiles194b9b92020-09-15 15:37:24 -0400375 static ShaderCapsPointer GSInvocationsExtensionString() {
376 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400377 result->fVersionDeclString = "#version 400";
378 result->fGeometryShaderSupport = true;
379 result->fGSInvocationsSupport = true;
380 result->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
381 return result;
382 }
Ethan Nicholas7da6dfa2017-06-21 11:25:18 -0400383
John Stiles194b9b92020-09-15 15:37:24 -0400384 static ShaderCapsPointer IncompleteShortIntPrecision() {
385 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400386 result->fVersionDeclString = "#version 310es";
387 result->fUsesPrecisionModifiers = true;
388 result->fIncompleteShortIntPrecision = true;
389 return result;
390 }
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700391
John Stiles8f84cee2020-10-08 18:39:08 -0400392 static ShaderCapsPointer MustForceNegatedAtanParamToFloat() {
John Stiles194b9b92020-09-15 15:37:24 -0400393 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400394 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400395 result->fMustForceNegatedAtanParamToFloat = true;
Brian Osmanb08cc022020-04-02 11:38:40 -0400396 return result;
397 }
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700398
John Stileseaaa71b2020-10-08 22:18:10 -0400399 static ShaderCapsPointer MustGuardDivisionEvenAfterExplicitZeroCheck() {
400 ShaderCapsPointer result = MakeShaderCaps();
401 result->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
402 return result;
403 }
404
John Stiles8f84cee2020-10-08 18:39:08 -0400405 static ShaderCapsPointer NoGSInvocationsSupport() {
John Stiles194b9b92020-09-15 15:37:24 -0400406 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400407 result->fVersionDeclString = "#version 400";
John Stiles8f84cee2020-10-08 18:39:08 -0400408 result->fGeometryShaderSupport = true;
409 result->fGSInvocationsSupport = false;
Brian Osmanb08cc022020-04-02 11:38:40 -0400410 return result;
411 }
Adrienne Walker2f4c09b2018-08-22 16:04:57 -0700412
John Stiles194b9b92020-09-15 15:37:24 -0400413 static ShaderCapsPointer RemovePowWithConstantExponent() {
414 ShaderCapsPointer result = MakeShaderCaps();
Brian Osmanb08cc022020-04-02 11:38:40 -0400415 result->fVersionDeclString = "#version 400";
416 result->fRemovePowWithConstantExponent = true;
417 return result;
418 }
Chris Daltonb0fd4b12019-10-29 13:41:22 -0600419
John Stiles8f84cee2020-10-08 18:39:08 -0400420 static ShaderCapsPointer RewriteDoWhileLoops() {
421 ShaderCapsPointer result = MakeShaderCaps();
422 result->fVersionDeclString = "#version 400";
423 result->fRewriteDoWhileLoops = true;
424 return result;
425 }
426
John Stiles194b9b92020-09-15 15:37:24 -0400427 static ShaderCapsPointer SampleMaskSupport() {
428 ShaderCapsPointer result = Default();
Brian Osmanb08cc022020-04-02 11:38:40 -0400429 result->fSampleMaskSupport = true;
430 return result;
431 }
John Stiles194b9b92020-09-15 15:37:24 -0400432
John Stiles8f84cee2020-10-08 18:39:08 -0400433 static ShaderCapsPointer ShaderDerivativeExtensionString() {
434 ShaderCapsPointer result = MakeShaderCaps();
435 result->fVersionDeclString = "#version 400";
436 result->fShaderDerivativeSupport = true;
437 result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
438 result->fUsesPrecisionModifiers = true;
439 return result;
440 }
441
442 static ShaderCapsPointer UnfoldShortCircuitAsTernary() {
443 ShaderCapsPointer result = MakeShaderCaps();
444 result->fVersionDeclString = "#version 400";
445 result->fUnfoldShortCircuitAsTernary = true;
446 return result;
447 }
448
449 static ShaderCapsPointer UsesPrecisionModifiers() {
450 ShaderCapsPointer result = MakeShaderCaps();
451 result->fVersionDeclString = "#version 400";
452 result->fUsesPrecisionModifiers = true;
453 return result;
454 }
455
456 static ShaderCapsPointer Version110() {
457 ShaderCapsPointer result = MakeShaderCaps();
458 result->fVersionDeclString = "#version 110";
459 result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
460 return result;
461 }
462
463 static ShaderCapsPointer Version450Core() {
464 ShaderCapsPointer result = MakeShaderCaps();
465 result->fVersionDeclString = "#version 450 core";
466 return result;
467 }
468
John Stiles194b9b92020-09-15 15:37:24 -0400469private:
470 static ShaderCapsPointer MakeShaderCaps();
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500471};
472
Brian Osman3000d6b2020-07-31 15:57:28 -0400473#if !defined(SKSL_STANDALONE)
474bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType);
475#endif
476
Ethan Nicholas0df1b042017-03-31 13:56:23 -0400477void write_stringstream(const StringStream& d, OutputStream& out);
ethannicholasb3058bd2016-07-01 08:22:01 -0700478
ethannicholasb3058bd2016-07-01 08:22:01 -0700479NORETURN void sksl_abort();
480
John Stilesa6841be2020-08-06 14:11:56 -0400481} // namespace SkSL
ethannicholasb3058bd2016-07-01 08:22:01 -0700482
John Stiles194b9b92020-09-15 15:37:24 -0400483#endif // SKSL_UTIL