Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLUtil.h
Go to the documentation of this file.
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 */
7
8#ifndef SKSL_UTIL
9#define SKSL_UTIL
10
13#include "src/sksl/SkSLGLSL.h"
14
15#include <memory>
16
17enum class SkSLType : char;
18
19namespace SkSL {
20
21class Context;
22class OutputStream;
23class StringStream;
24class Type;
25
26struct ShaderCaps {
27 /**
28 * Indicates how GLSL must interact with advanced blend equations. The KHR extension requires
29 * special layout qualifiers in the fragment shader.
30 */
32 kNotSupported_AdvBlendEqInteraction, //<! No _blend_equation_advanced extension
33 kAutomatic_AdvBlendEqInteraction, //<! No interaction required
34 kGeneralEnable_AdvBlendEqInteraction, //<! layout(blend_support_all_equations) out
35
37 };
38
42
46
47 // Returns the string of an extension that must be enabled in the shader to support
48 // derivatives. If nullptr is returned then no extension needs to be enabled. Before calling
49 // this function, the caller should check that shaderDerivativeSupport exists.
54
55 // This returns the name of an extension that must be enabled in the shader to support external
56 // textures. In some cases, two extensions must be enabled - the second extension is returned
57 // by secondExternalTextureExtensionString(). If that function returns nullptr, then only one
58 // extension is required.
63
68
69 /**
70 * SkSL 300 requires support for derivatives, nonsquare matrices and bitwise integer operations.
71 */
79
81
83
86 /** Enables sampleGrad and sampleLod functions that don't rely on implicit derivatives */
88 /** Indicates true 32-bit integer support, with unsigned types and bitwise operations */
89 bool fIntegerSupport = false;
91 /** asinh(), acosh(), atanh() */
93 bool fFBFetchSupport = false;
98 bool fSampleMaskSupport = false;
100 bool fFloatIs32Bits = true;
101
102 // isinf() is defined, and floating point infinities are handled according to IEEE standards.
103 bool fInfinitySupport = false;
104
105 // Used by SkSL to know when to generate polyfills.
108
109 // Used for specific driver bug work arounds
114 bool fMustForceNegatedLdexpParamToMultiply = false; // http://skbug.com/12076
115 // Returns whether a device incorrectly implements atan(y,x) as atan(y/x)
117 // If this returns true some operation (could be a no op) must be called between floor and abs
118 // to make sure the driver compiler doesn't inline them together which can cause a driver bug in
119 // the shader.
121 // The D3D shader compiler, when targeting PS 3.0 (ie within ANGLE) fails to compile certain
122 // constructs. See detailed comments in GrGLCaps.cpp.
124 // If false, SkSL uses a workaround so that sk_FragCoord doesn't actually query gl_FragCoord
125 bool fCanUseFragCoord = true;
126 // If true, then conditions in for loops need "&& true" to work around driver bugs.
128 // If true, then expressions such as "x && y" or "x || y" are rewritten as ternary to work
129 // around driver bugs.
135 // The Android emulator claims samplerExternalOES is an unknown type if a default precision
136 // statement is made for the type.
138 // ARM GPUs calculate `matrix * vector` in SPIR-V at full precision, even when the inputs are
139 // RelaxedPrecision. Rewriting the multiply as a sum of vector*scalar fixes this. (skia:11769)
141 // Rewrites matrix equality comparisons to avoid an Adreno driver bug. (skia:11308)
143 // Strips const from function parameters in the GLSL code generator. (skia:13858)
145 // On some Android devices colors aren't accurate enough for the double lookup in the
146 // Perlin noise shader. This workaround aggressively snaps colors to multiples of 1/255.
148 // Vulkan requires certain builtin variables be present, even if they're unused. At one time,
149 // validation errors would result if sk_Clockwise was missing. Now, it's just (Adreno) driver
150 // bugs that drop or corrupt draws if they're missing.
152
153 const char* fVersionDeclString = "";
154
155 const char* fShaderDerivativeExtensionString = nullptr;
156 const char* fExternalTextureExtensionString = nullptr;
158 const char* fFBFetchColorName = nullptr;
159
161};
162
163// Various sets of caps for use in tests
165public:
166 static const ShaderCaps* Default() {
167 static const SkSL::ShaderCaps* sCaps = [] {
168 std::unique_ptr<ShaderCaps> caps = MakeShaderCaps();
169 caps->fVersionDeclString = "#version 400";
170 caps->fShaderDerivativeSupport = true;
171 return caps.release();
172 }();
173 return sCaps;
174 }
175
176 static const ShaderCaps* Standalone() {
177 static const SkSL::ShaderCaps* sCaps = MakeShaderCaps().release();
178 return sCaps;
179 }
180
181protected:
182 static std::unique_ptr<ShaderCaps> MakeShaderCaps();
183};
184
185bool type_to_sksltype(const Context& context, const Type& type, SkSLType* outType);
186
187void write_stringstream(const StringStream& d, OutputStream& out);
188
189} // namespace SkSL
190
191#endif // SKSL_UTIL
#define SkASSERT(cond)
Definition SkAssert.h:116
SkSLType
static const ShaderCaps * Standalone()
Definition SkSLUtil.h:176
static std::unique_ptr< ShaderCaps > MakeShaderCaps()
Definition SkSLUtil.cpp:25
static const ShaderCaps * Default()
Definition SkSLUtil.h:166
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
GLSLGeneration
Definition SkSLGLSL.h:15
void write_stringstream(const StringStream &s, OutputStream &out)
Definition SkSLUtil.cpp:41
bool type_to_sksltype(const Context &context, const Type &type, SkSLType *outType)
Definition SkSLUtil.cpp:45
const char * fExternalTextureExtensionString
Definition SkSLUtil.h:156
const char * secondExternalTextureExtensionString() const
Definition SkSLUtil.h:64
bool fMustGuardDivisionEvenAfterExplicitZeroCheck
Definition SkSLUtil.h:123
bool fSampleMaskSupport
Definition SkSLUtil.h:98
bool fRewriteMatrixComparisons
Definition SkSLUtil.h:142
bool fExternalTextureSupport
Definition SkSLUtil.h:99
bool fFBFetchNeedsCustomOutput
Definition SkSLUtil.h:94
bool fExplicitTextureLodSupport
Definition SkSLUtil.h:87
const char * shaderDerivativeExtensionString() const
Definition SkSLUtil.h:50
bool fMustForceNegatedAtanParamToFloat
Definition SkSLUtil.h:113
bool fPerlinNoiseRoundingFix
Definition SkSLUtil.h:147
bool fFBFetchSupport
Definition SkSLUtil.h:93
bool fDualSourceBlendingSupport
Definition SkSLUtil.h:84
bool fEmulateAbsIntFunction
Definition SkSLUtil.h:131
bool fMustDeclareFragmentFrontFacing
Definition SkSLUtil.h:151
bool fInfinitySupport
Definition SkSLUtil.h:103
bool fCanUseVoidInSequenceExpressions
Definition SkSLUtil.h:110
const char * fFBFetchColorName
Definition SkSLUtil.h:158
const char * externalTextureExtensionString() const
Definition SkSLUtil.h:59
@ kNotSupported_AdvBlendEqInteraction
Definition SkSLUtil.h:32
@ kAutomatic_AdvBlendEqInteraction
Definition SkSLUtil.h:33
@ kLast_AdvBlendEqInteraction
Definition SkSLUtil.h:36
@ kGeneralEnable_AdvBlendEqInteraction
Definition SkSLUtil.h:34
bool fUnfoldShortCircuitAsTernary
Definition SkSLUtil.h:130
bool fShaderDerivativeSupport
Definition SkSLUtil.h:85
bool fRemovePowWithConstantExponent
Definition SkSLUtil.h:134
bool fFlatInterpolationSupport
Definition SkSLUtil.h:96
bool fIntegerSupport
Definition SkSLUtil.h:89
bool fBuiltinFMASupport
Definition SkSLUtil.h:106
bool fRewriteMatrixVectorMultiply
Definition SkSLUtil.h:140
bool fRewriteDoWhileLoops
Definition SkSLUtil.h:132
const char * fShaderDerivativeExtensionString
Definition SkSLUtil.h:155
bool fRewriteSwitchStatements
Definition SkSLUtil.h:133
bool fInverseHyperbolicSupport
Definition SkSLUtil.h:92
const char * fVersionDeclString
Definition SkSLUtil.h:153
AdvBlendEqInteraction fAdvBlendEqInteraction
Definition SkSLUtil.h:160
bool fBuiltinDeterminantSupport
Definition SkSLUtil.h:107
SkSL::Version supportedSkSLVerion() const
Definition SkSLUtil.h:72
bool fNoPerspectiveInterpolationSupport
Definition SkSLUtil.h:97
bool fAddAndTrueToLoopCondition
Definition SkSLUtil.h:127
bool fNonsquareMatrixSupport
Definition SkSLUtil.h:90
bool fMustDoOpBetweenFloorAndAbs
Definition SkSLUtil.h:120
bool fMustForceNegatedLdexpParamToMultiply
Definition SkSLUtil.h:114
bool mustDeclareFragmentShaderOutput() const
Definition SkSLUtil.h:43
bool supportsDistanceFieldText() const
Definition SkSLUtil.h:80
bool fCanUseFractForNegativeValues
Definition SkSLUtil.h:112
bool mustEnableAdvBlendEqs() const
Definition SkSLUtil.h:39
bool fRemoveConstFromFunctionParameters
Definition SkSLUtil.h:144
bool fCanUseFragCoord
Definition SkSLUtil.h:125
const char * fSecondExternalTextureExtensionString
Definition SkSLUtil.h:157
bool fNoDefaultPrecisionForExternalSamplers
Definition SkSLUtil.h:137
bool fAtan2ImplementedAsAtanYOverX
Definition SkSLUtil.h:116
bool fUsesPrecisionModifiers
Definition SkSLUtil.h:95
bool fCanUseMinAndAbsTogether
Definition SkSLUtil.h:111
SkSL::GLSLGeneration fGLSLGeneration
Definition SkSLUtil.h:82