• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 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 GrShaderCaps_DEFINED
9 #define GrShaderCaps_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "src/gpu/glsl/GrGLSL.h"
13 #include "src/sksl/SkSLUtil.h"
14 
15 struct GrContextOptions;
16 class SkJSONWriter;
17 
18 struct GrShaderCaps : SkSL::ShaderCaps {
GrShaderCapsGrShaderCaps19     GrShaderCaps() {}
20 
21     //
22     // TODO: Remove these unnecessary accessors
23     //
24     void dumpJSON(SkJSONWriter*) const;
25 
supportsDistanceFieldTextGrShaderCaps26     bool supportsDistanceFieldText() const { return fShaderDerivativeSupport; }
27 
dstReadInShaderSupportGrShaderCaps28     bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
dualSourceBlendingSupportGrShaderCaps29     bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
30 
fbFetchExtensionStringGrShaderCaps31     const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
32 
preferFlatInterpolationGrShaderCaps33     bool preferFlatInterpolation() const { return fPreferFlatInterpolation; }
34 
vertexIDSupportGrShaderCaps35     bool vertexIDSupport() const { return fVertexIDSupport; }
36 
37     // isinf() is defined, and floating point infinities are handled according to IEEE standards.
infinitySupportGrShaderCaps38     bool infinitySupport() const { return fInfinitySupport; }
39 
40     // Returns true if `expr` in `myArray[expr]` can be any integer expression. If false, `expr`
41     // must be a constant-index-expression as defined in the OpenGL ES2 specification, Appendix A.5.
nonconstantArrayIndexSupportGrShaderCaps42     bool nonconstantArrayIndexSupport() const {
43         return fNonconstantArrayIndexSupport;
44     }
45 
46     // frexp(), ldexp(), findMSB(), findLSB().
bitManipulationSupportGrShaderCaps47     bool bitManipulationSupport() const { return fBitManipulationSupport; }
48 
halfIs32BitsGrShaderCaps49     bool halfIs32Bits() const { return fHalfIs32Bits; }
50 
hasLowFragmentPrecisionGrShaderCaps51     bool hasLowFragmentPrecision() const { return fHasLowFragmentPrecision; }
52 
53     // Use a reduced set of rendering algorithms or less optimal effects in order to
54     // reduce the number of unique shaders generated.
reducedShaderModeGrShaderCaps55     bool reducedShaderMode() const { return fReducedShaderMode; }
56 
57     /**
58      * SkSL ES3 requires support for derivatives, nonsquare matrices and bitwise integer operations.
59      */
supportsSkSLES3GrShaderCaps60     bool supportsSkSLES3() const {
61         return fShaderDerivativeSupport && fNonsquareMatrixSupport && fIntegerSupport &&
62                fGLSLGeneration >= SkSL::GLSLGeneration::k330;
63     }
64 
65     // SkSL only.
colorSpaceMathNeedsFloatGrShaderCaps66     bool colorSpaceMathNeedsFloat() const { return fColorSpaceMathNeedsFloat; }
67 
requiresLocalOutputColorForFBFetchGrShaderCaps68     bool requiresLocalOutputColorForFBFetch() const { return fRequiresLocalOutputColorForFBFetch; }
69 
mustObfuscateUniformColorGrShaderCaps70     bool mustObfuscateUniformColor() const { return fMustObfuscateUniformColor; }
71 
72     // On Nexus 6, the GL context can get lost if a shader does not write a value to gl_FragColor.
73     // https://bugs.chromium.org/p/chromium/issues/detail?id=445377
mustWriteToFragColorGrShaderCaps74     bool mustWriteToFragColor() const { return fMustWriteToFragColor; }
75 
76     // Some GPUs produce poor results when enabling Metal's fastmath option
canUseFastMathGrShaderCaps77     bool canUseFastMath() const { return fCanUseFastMath; }
78 
79     // When we have the option of using either dFdx or dfDy in a shader, this returns whether we
80     // should avoid using dFdx. We have found some drivers have bugs or lower precision when using
81     // dFdx.
avoidDfDxForGradientsWhenPossibleGrShaderCaps82     bool avoidDfDxForGradientsWhenPossible() const { return fAvoidDfDxForGradientsWhenPossible; }
83 
84     // This returns the name of an extension that must be enabled in the shader, if such a thing is
85     // required in order to use a secondary output in the shader. This returns a nullptr if no such
86     // extension is required. However, the return value of this function does not say whether dual
87     // source blending is supported.
secondaryOutputExtensionStringGrShaderCaps88     const char* secondaryOutputExtensionString() const { return fSecondaryOutputExtensionString; }
89 
noperspectiveInterpolationExtensionStringGrShaderCaps90     const char* noperspectiveInterpolationExtensionString() const {
91         SkASSERT(this->noperspectiveInterpolationSupport());
92         return fNoPerspectiveInterpolationExtensionString;
93     }
94 
sampleVariablesExtensionStringGrShaderCaps95     const char* sampleVariablesExtensionString() const {
96         SkASSERT(this->sampleMaskSupport());
97         return fSampleVariablesExtensionString;
98     }
99 
tessellationExtensionStringGrShaderCaps100     const char* tessellationExtensionString() const {
101         SkASSERT(this->tessellationSupport());
102         return fTessellationExtensionString;
103     }
104 
maxFragmentSamplersGrShaderCaps105     int maxFragmentSamplers() const { return fMaxFragmentSamplers; }
106 
107     // Maximum number of segments a tessellation edge can be divided into.
maxTessellationSegmentsGrShaderCaps108     int maxTessellationSegments() const { return fMaxTessellationSegments; }
109 
tessellationSupportGrShaderCaps110     bool tessellationSupport() const { return SkToBool(fMaxTessellationSegments);}
111 
112     void applyOptionsOverrides(const GrContextOptions& options);
113 
114     bool fDstReadInShaderSupport = false;
115     bool fDualSourceBlendingSupport = false;
116     bool fPreferFlatInterpolation = false;
117     bool fVertexIDSupport = false;
118     bool fInfinitySupport = false;
119     bool fNonconstantArrayIndexSupport = false;
120     bool fBitManipulationSupport = false;
121     bool fHalfIs32Bits = false;
122     bool fHasLowFragmentPrecision = false;
123     bool fReducedShaderMode = false;
124 
125     // Used for specific driver bug work arounds
126     bool fRequiresLocalOutputColorForFBFetch = false;
127     bool fMustObfuscateUniformColor = false;
128     bool fMustWriteToFragColor = false;
129     bool fColorSpaceMathNeedsFloat = false;
130     bool fCanUseFastMath = false;
131     bool fAvoidDfDxForGradientsWhenPossible = false;
132 
133     const char* fSecondaryOutputExtensionString = nullptr;
134     const char* fNoPerspectiveInterpolationExtensionString = nullptr;
135     const char* fSampleVariablesExtensionString = nullptr;
136     const char* fTessellationExtensionString = nullptr;
137 
138     const char* fFBFetchExtensionString = nullptr;
139 
140     int fMaxFragmentSamplers = 0;
141     int fMaxTessellationSegments = 0;
142 };
143 
144 #endif
145