• 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 
9 #include "src/gpu/GrShaderCaps.h"
10 
11 #include "include/gpu/GrContextOptions.h"
12 
13 ////////////////////////////////////////////////////////////////////////////////////////////
14 
GrShaderCaps()15 GrShaderCaps::GrShaderCaps() {
16     fGLSLGeneration = k330_GrGLSLGeneration;
17     fShaderDerivativeSupport = false;
18     fDstReadInShaderSupport = false;
19     fDualSourceBlendingSupport = false;
20     fIntegerSupport = false;
21     fNonsquareMatrixSupport = false;
22     fInverseHyperbolicSupport = false;
23     fFBFetchSupport = false;
24     fFBFetchNeedsCustomOutput = false;
25     fUsesPrecisionModifiers = false;
26     fCanUseAnyFunctionInShader = true;
27     fCanUseMinAndAbsTogether = true;
28     fCanUseFractForNegativeValues = true;
29     fMustForceNegatedAtanParamToFloat = false;
30     fMustForceNegatedLdexpParamToMultiply = false;
31     fAtan2ImplementedAsAtanYOverX = false;
32     fMustDoOpBetweenFloorAndAbs = false;
33     fRequiresLocalOutputColorForFBFetch = false;
34     fMustObfuscateUniformColor = false;
35     fMustGuardDivisionEvenAfterExplicitZeroCheck = false;
36     fCanUseFragCoord = true;
37     fIncompleteShortIntPrecision = false;
38     fAddAndTrueToLoopCondition = false;
39     fUnfoldShortCircuitAsTernary = false;
40     fEmulateAbsIntFunction = false;
41     fRewriteDoWhileLoops = false;
42     fRewriteSwitchStatements = false;
43     fRemovePowWithConstantExponent = false;
44     fMustWriteToFragColor = false;
45     fNoDefaultPrecisionForExternalSamplers = false;
46     fRewriteMatrixVectorMultiply = false;
47     fRewriteMatrixComparisons = false;
48     fFlatInterpolationSupport = false;
49     fPreferFlatInterpolation = false;
50     fNoPerspectiveInterpolationSupport = false;
51     fSampleMaskSupport = false;
52     fExternalTextureSupport = false;
53     fVertexIDSupport = false;
54     fInfinitySupport = false;
55     fNonconstantArrayIndexSupport = false;
56     fBitManipulationSupport = false;
57     fFloatIs32Bits = true;
58     fHalfIs32Bits = false;
59     fHasLowFragmentPrecision = false;
60     fReducedShaderMode = false;
61     fColorSpaceMathNeedsFloat = false;
62     fBuiltinFMASupport = false;
63     fBuiltinDeterminantSupport = false;
64     fCanUseDoLoops = true;
65     fCanUseFastMath = false;
66     fUseNodePools = true;
67     fAvoidDfDxForGradientsWhenPossible = false;
68 
69     fVersionDeclString = nullptr;
70     fShaderDerivativeExtensionString = nullptr;
71     fSecondaryOutputExtensionString = nullptr;
72     fExternalTextureExtensionString = nullptr;
73     fSecondExternalTextureExtensionString = nullptr;
74     fNoPerspectiveInterpolationExtensionString = nullptr;
75     fSampleVariablesExtensionString = nullptr;
76     fTessellationExtensionString = nullptr;
77     fFBFetchColorName = nullptr;
78     fFBFetchExtensionString = nullptr;
79     fMaxFragmentSamplers = 0;
80     fMaxTessellationSegments = 0;
81     fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
82 }
83 
84 #ifdef SK_ENABLE_DUMP_GPU
85 #include "src/utils/SkJSONWriter.h"
86 
dumpJSON(SkJSONWriter * writer) const87 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
88     writer->beginObject();
89 
90     writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport);
91     writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport);
92     writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport);
93     writer->appendBool("Integer Support", fIntegerSupport);
94     writer->appendBool("Nonsquare Matrix Support", fNonsquareMatrixSupport);
95     writer->appendBool("Inverse Hyperbolic Support", fInverseHyperbolicSupport);
96 
97     static const char* kAdvBlendEqInteractionStr[] = {
98         "Not Supported",
99         "Automatic",
100         "General Enable",
101     };
102     static_assert(0 == kNotSupported_AdvBlendEqInteraction);
103     static_assert(1 == kAutomatic_AdvBlendEqInteraction);
104     static_assert(2 == kGeneralEnable_AdvBlendEqInteraction);
105     static_assert(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
106 
107     writer->appendBool("FB Fetch Support", fFBFetchSupport);
108     writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers);
109     writer->appendBool("Can use any() function", fCanUseAnyFunctionInShader);
110     writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether);
111     writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues);
112     writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat);
113     writer->appendBool("Must force negated ldexp param to multiply",
114                        fMustForceNegatedLdexpParamToMultiply);
115     writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs);
116     writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch);
117     writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor);
118     writer->appendBool("Must guard division even after explicit zero check",
119                        fMustGuardDivisionEvenAfterExplicitZeroCheck);
120     writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord);
121     writer->appendBool("Incomplete short int precision", fIncompleteShortIntPrecision);
122     writer->appendBool("Add and true to loops workaround", fAddAndTrueToLoopCondition);
123     writer->appendBool("Unfold short circuit as ternary", fUnfoldShortCircuitAsTernary);
124     writer->appendBool("Emulate abs(int) function", fEmulateAbsIntFunction);
125     writer->appendBool("Rewrite do while loops", fRewriteDoWhileLoops);
126     writer->appendBool("Rewrite switch statements", fRewriteSwitchStatements);
127     writer->appendBool("Rewrite pow with constant exponent", fRemovePowWithConstantExponent);
128     writer->appendBool("Must write to sk_FragColor [workaround]", fMustWriteToFragColor);
129     writer->appendBool("Don't add default precision statement for samplerExternalOES",
130                        fNoDefaultPrecisionForExternalSamplers);
131     writer->appendBool("Rewrite matrix-vector multiply", fRewriteMatrixVectorMultiply);
132     writer->appendBool("Rewrite matrix equality comparisons", fRewriteMatrixComparisons);
133     writer->appendBool("Flat interpolation support", fFlatInterpolationSupport);
134     writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
135     writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
136     writer->appendBool("Sample mask support", fSampleMaskSupport);
137     writer->appendBool("External texture support", fExternalTextureSupport);
138     writer->appendBool("sk_VertexID support", fVertexIDSupport);
139     writer->appendBool("Infinity support", fInfinitySupport);
140     writer->appendBool("Non-constant array index support", fNonconstantArrayIndexSupport);
141     writer->appendBool("Bit manipulation support", fBitManipulationSupport);
142     writer->appendBool("float == fp32", fFloatIs32Bits);
143     writer->appendBool("half == fp32", fHalfIs32Bits);
144     writer->appendBool("Has poor fragment precision", fHasLowFragmentPrecision);
145     writer->appendBool("Color space math needs float", fColorSpaceMathNeedsFloat);
146     writer->appendBool("Builtin fma() support", fBuiltinFMASupport);
147     writer->appendBool("Builtin determinant() support", fBuiltinDeterminantSupport);
148     writer->appendBool("Can use do-while loops", fCanUseDoLoops);
149     writer->appendBool("Use node pools", fUseNodePools);
150 
151     writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
152     writer->appendS32("Max Tessellation Segments", fMaxTessellationSegments);
153     writer->appendString("Advanced blend equation interaction",
154                          kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
155 
156     writer->endObject();
157 }
158 #else
dumpJSON(SkJSONWriter * writer) const159 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { }
160 #endif
161 
applyOptionsOverrides(const GrContextOptions & options)162 void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
163     if (options.fDisableDriverCorrectnessWorkarounds) {
164         SkASSERT(fCanUseAnyFunctionInShader);
165         SkASSERT(fCanUseMinAndAbsTogether);
166         SkASSERT(fCanUseFractForNegativeValues);
167         SkASSERT(!fMustForceNegatedAtanParamToFloat);
168         SkASSERT(!fMustForceNegatedLdexpParamToMultiply);
169         SkASSERT(!fAtan2ImplementedAsAtanYOverX);
170         SkASSERT(!fMustDoOpBetweenFloorAndAbs);
171         SkASSERT(!fRequiresLocalOutputColorForFBFetch);
172         SkASSERT(!fMustObfuscateUniformColor);
173         SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck);
174         SkASSERT(fCanUseFragCoord);
175         SkASSERT(!fIncompleteShortIntPrecision);
176         SkASSERT(!fAddAndTrueToLoopCondition);
177         SkASSERT(!fUnfoldShortCircuitAsTernary);
178         SkASSERT(!fEmulateAbsIntFunction);
179         SkASSERT(!fRewriteDoWhileLoops);
180         SkASSERT(!fRewriteSwitchStatements);
181         SkASSERT(!fRemovePowWithConstantExponent);
182         SkASSERT(!fMustWriteToFragColor);
183         SkASSERT(!fNoDefaultPrecisionForExternalSamplers);
184         SkASSERT(!fRewriteMatrixVectorMultiply);
185         SkASSERT(!fRewriteMatrixComparisons);
186     }
187     if (!options.fEnableExperimentalHardwareTessellation) {
188         fMaxTessellationSegments = 0;
189     }
190     if (options.fReducedShaderVariations) {
191         fReducedShaderMode = true;
192     }
193 #if GR_TEST_UTILS
194     if (options.fSuppressDualSourceBlending) {
195         fDualSourceBlendingSupport = false;
196     }
197     if (options.fSuppressFramebufferFetch) {
198         fFBFetchSupport = false;
199     }
200     if (options.fMaxTessellationSegmentsOverride > 0) {
201         fMaxTessellationSegments = std::min(options.fMaxTessellationSegmentsOverride,
202                                             fMaxTessellationSegments);
203     }
204 #endif
205 }
206