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 #include "src/utils/SkJSONWriter.h"
13
14 ////////////////////////////////////////////////////////////////////////////////////////////
15
GrShaderCaps(const GrContextOptions & options)16 GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
17 fGLSLGeneration = k330_GrGLSLGeneration;
18 fShaderDerivativeSupport = false;
19 fGeometryShaderSupport = false;
20 fGSInvocationsSupport = false;
21 fPathRenderingSupport = false;
22 fDstReadInShaderSupport = false;
23 fDualSourceBlendingSupport = false;
24 fIntegerSupport = false;
25 fFBFetchSupport = false;
26 fFBFetchNeedsCustomOutput = false;
27 fUsesPrecisionModifiers = false;
28 fCanUseAnyFunctionInShader = true;
29 fCanUseMinAndAbsTogether = true;
30 fCanUseFractForNegativeValues = true;
31 fMustForceNegatedAtanParamToFloat = false;
32 fAtan2ImplementedAsAtanYOverX = false;
33 fMustDoOpBetweenFloorAndAbs = false;
34 fRequiresLocalOutputColorForFBFetch = false;
35 fMustObfuscateUniformColor = false;
36 fMustGuardDivisionEvenAfterExplicitZeroCheck = false;
37 fCanUseFragCoord = true;
38 fIncompleteShortIntPrecision = false;
39 fAddAndTrueToLoopCondition = false;
40 fUnfoldShortCircuitAsTernary = false;
41 fEmulateAbsIntFunction = false;
42 fRewriteDoWhileLoops = false;
43 fRemovePowWithConstantExponent = false;
44 fMustWriteToFragColor = false;
45 fNoDefaultPrecisionForExternalSamplers = false;
46 fFlatInterpolationSupport = false;
47 fPreferFlatInterpolation = false;
48 fNoPerspectiveInterpolationSupport = false;
49 fSampleVariablesSupport = false;
50 fSampleVariablesStencilSupport = false;
51 fExternalTextureSupport = false;
52 fVertexIDSupport = false;
53 fFPManipulationSupport = false;
54 fFloatIs32Bits = true;
55 fHalfIs32Bits = false;
56 fHasLowFragmentPrecision = false;
57 // Backed API support is required to be able to make swizzle-neutral shaders (e.g.
58 // GL_ARB_texture_swizzle).
59 fTextureSwizzleAppliedInShader = true;
60 fBuiltinFMASupport = false;
61
62 fVersionDeclString = nullptr;
63 fShaderDerivativeExtensionString = nullptr;
64 fGeometryShaderExtensionString = nullptr;
65 fGSInvocationsExtensionString = nullptr;
66 fFragCoordConventionsExtensionString = nullptr;
67 fSecondaryOutputExtensionString = nullptr;
68 fExternalTextureExtensionString = nullptr;
69 fSecondExternalTextureExtensionString = nullptr;
70 fNoPerspectiveInterpolationExtensionString = nullptr;
71 fSampleVariablesExtensionString = nullptr;
72 fFBFetchColorName = nullptr;
73 fFBFetchExtensionString = nullptr;
74 fMaxFragmentSamplers = 0;
75 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
76 }
77
78 #ifdef SK_ENABLE_DUMP_GPU
dumpJSON(SkJSONWriter * writer) const79 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
80 writer->beginObject();
81
82 writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport);
83 writer->appendBool("Geometry Shader Support", fGeometryShaderSupport);
84 writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport);
85 writer->appendBool("Path Rendering Support", fPathRenderingSupport);
86 writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport);
87 writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport);
88 writer->appendBool("Integer Support", fIntegerSupport);
89
90 static const char* kAdvBlendEqInteractionStr[] = {
91 "Not Supported",
92 "Automatic",
93 "General Enable",
94 "Specific Enables",
95 };
96 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
97 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
98 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
99 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
100 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
101
102 writer->appendBool("FB Fetch Support", fFBFetchSupport);
103 writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers);
104 writer->appendBool("Can use any() function", fCanUseAnyFunctionInShader);
105 writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether);
106 writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues);
107 writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat);
108 writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs);
109 writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch);
110 writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor);
111 writer->appendBool("Must guard division even after explicit zero check",
112 fMustGuardDivisionEvenAfterExplicitZeroCheck);
113 writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord);
114 writer->appendBool("Incomplete short int precision", fIncompleteShortIntPrecision);
115 writer->appendBool("Add and true to loops workaround", fAddAndTrueToLoopCondition);
116 writer->appendBool("Unfold short circuit as ternary", fUnfoldShortCircuitAsTernary);
117 writer->appendBool("Emulate abs(int) function", fEmulateAbsIntFunction);
118 writer->appendBool("Rewrite do while loops", fRewriteDoWhileLoops);
119 writer->appendBool("Rewrite pow with constant exponent", fRemovePowWithConstantExponent);
120 writer->appendBool("Must write to sk_FragColor [workaround]", fMustWriteToFragColor);
121 writer->appendBool("Don't add default precision statement for samplerExternalOES",
122 fNoDefaultPrecisionForExternalSamplers);
123 writer->appendBool("Flat interpolation support", fFlatInterpolationSupport);
124 writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
125 writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
126 writer->appendBool("Sample variables support", fSampleVariablesSupport);
127 writer->appendBool("Sample variables stencil support [workaround]",
128 fSampleVariablesStencilSupport);
129 writer->appendBool("External texture support", fExternalTextureSupport);
130 writer->appendBool("sk_VertexID support", fVertexIDSupport);
131 writer->appendBool("Floating point manipulation support", fFPManipulationSupport);
132 writer->appendBool("float == fp32", fFloatIs32Bits);
133 writer->appendBool("half == fp32", fHalfIs32Bits);
134 writer->appendBool("Has poor fragment precision", fHasLowFragmentPrecision);
135 writer->appendBool("Texture swizzle applied in shader", fTextureSwizzleAppliedInShader);
136 writer->appendBool("Builtin fma() support", fBuiltinFMASupport);
137
138 writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
139 writer->appendString("Advanced blend equation interaction",
140 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
141
142 writer->endObject();
143 }
144 #else
dumpJSON(SkJSONWriter * writer) const145 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { }
146 #endif
147
applyOptionsOverrides(const GrContextOptions & options)148 void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
149 if (options.fDisableDriverCorrectnessWorkarounds) {
150 SkASSERT(fCanUseAnyFunctionInShader);
151 SkASSERT(fCanUseMinAndAbsTogether);
152 SkASSERT(fCanUseFractForNegativeValues);
153 SkASSERT(!fMustForceNegatedAtanParamToFloat);
154 SkASSERT(!fAtan2ImplementedAsAtanYOverX);
155 SkASSERT(!fMustDoOpBetweenFloorAndAbs);
156 SkASSERT(!fRequiresLocalOutputColorForFBFetch);
157 SkASSERT(!fMustObfuscateUniformColor);
158 SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck);
159 SkASSERT(fCanUseFragCoord);
160 SkASSERT(!fIncompleteShortIntPrecision);
161 SkASSERT(!fAddAndTrueToLoopCondition);
162 SkASSERT(!fUnfoldShortCircuitAsTernary);
163 SkASSERT(!fEmulateAbsIntFunction);
164 SkASSERT(!fRewriteDoWhileLoops);
165 SkASSERT(!fRemovePowWithConstantExponent);
166 SkASSERT(!fMustWriteToFragColor);
167 SkASSERT(!fNoDefaultPrecisionForExternalSamplers);
168 }
169 #if GR_TEST_UTILS
170 fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
171 #endif
172 }
173