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 "GrShaderCaps.h"
10
11 #include "GrContextOptions.h"
12 #include "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 fImageLoadStoreSupport = false;
26 fDropsTileOnZeroDivide = false;
27 fFBFetchSupport = false;
28 fFBFetchNeedsCustomOutput = false;
29 fUsesPrecisionModifiers = false;
30 fCanUseAnyFunctionInShader = true;
31 fCanUseMinAndAbsTogether = true;
32 fCanUseFractForNegativeValues = true;
33 fMustForceNegatedAtanParamToFloat = false;
34 fAtan2ImplementedAsAtanYOverX = false;
35 fMustDoOpBetweenFloorAndAbs = false;
36 fRequiresLocalOutputColorForFBFetch = false;
37 fMustObfuscateUniformColor = false;
38 fMustGuardDivisionEvenAfterExplicitZeroCheck = false;
39 fCanUseFragCoord = true;
40 fIncompleteShortIntPrecision = false;
41 fAddAndTrueToLoopCondition = false;
42 fUnfoldShortCircuitAsTernary = false;
43 fEmulateAbsIntFunction = false;
44 fRewriteDoWhileLoops = false;
45 fRemovePowWithConstantExponent = false;
46 fFlatInterpolationSupport = false;
47 fPreferFlatInterpolation = false;
48 fNoPerspectiveInterpolationSupport = false;
49 fSampleVariablesSupport = false;
50 fExternalTextureSupport = false;
51 fVertexIDSupport = false;
52 fFPManipulationSupport = false;
53 fFloatIs32Bits = true;
54 fHalfIs32Bits = false;
55 fHasLowFragmentPrecision = false;
56 fUnsignedSupport = false;
57 fBuiltinFMASupport = false;
58
59 fVersionDeclString = nullptr;
60 fShaderDerivativeExtensionString = nullptr;
61 fGeometryShaderExtensionString = nullptr;
62 fGSInvocationsExtensionString = nullptr;
63 fFragCoordConventionsExtensionString = nullptr;
64 fSecondaryOutputExtensionString = nullptr;
65 fExternalTextureExtensionString = nullptr;
66 fSecondExternalTextureExtensionString = nullptr;
67 fNoPerspectiveInterpolationExtensionString = nullptr;
68 fSampleVariablesExtensionString = nullptr;
69 fFBFetchColorName = nullptr;
70 fFBFetchExtensionString = nullptr;
71 fImageLoadStoreExtensionString = nullptr;
72 fMaxFragmentSamplers = 0;
73 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
74 }
75
76 #ifdef SK_ENABLE_DUMP_GPU
dumpJSON(SkJSONWriter * writer) const77 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
78 writer->beginObject();
79
80 writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport);
81 writer->appendBool("Geometry Shader Support", fGeometryShaderSupport);
82 writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport);
83 writer->appendBool("Path Rendering Support", fPathRenderingSupport);
84 writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport);
85 writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport);
86 writer->appendBool("Integer Support", fIntegerSupport);
87 writer->appendBool("Image Load Store Support", fImageLoadStoreSupport);
88
89 static const char* kAdvBlendEqInteractionStr[] = {
90 "Not Supported",
91 "Automatic",
92 "General Enable",
93 "Specific Enables",
94 };
95 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
96 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
97 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
98 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
99 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
100
101 writer->appendBool("FB Fetch Support", fFBFetchSupport);
102 writer->appendBool("Drops tile on zero divide", fDropsTileOnZeroDivide);
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("Flat interpolation support", fFlatInterpolationSupport);
121 writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
122 writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
123 writer->appendBool("Sample variables support", fSampleVariablesSupport);
124 writer->appendBool("External texture support", fExternalTextureSupport);
125 writer->appendBool("sk_VertexID support", fVertexIDSupport);
126 writer->appendBool("Floating point manipulation support", fFPManipulationSupport);
127 writer->appendBool("float == fp32", fFloatIs32Bits);
128 writer->appendBool("half == fp32", fHalfIs32Bits);
129 writer->appendBool("Has poor fragment precision", fHasLowFragmentPrecision);
130 writer->appendBool("Builtin fma() support", fBuiltinFMASupport);
131
132 writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
133 writer->appendString("Advanced blend equation interaction",
134 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
135
136 writer->endObject();
137 }
138 #else
dumpJSON(SkJSONWriter * writer) const139 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { }
140 #endif
141
applyOptionsOverrides(const GrContextOptions & options)142 void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
143 if (options.fDisableDriverCorrectnessWorkarounds) {
144 SkASSERT(fCanUseAnyFunctionInShader);
145 SkASSERT(fCanUseMinAndAbsTogether);
146 SkASSERT(fCanUseFractForNegativeValues);
147 SkASSERT(!fMustForceNegatedAtanParamToFloat);
148 SkASSERT(!fAtan2ImplementedAsAtanYOverX);
149 SkASSERT(!fMustDoOpBetweenFloorAndAbs);
150 SkASSERT(!fRequiresLocalOutputColorForFBFetch);
151 SkASSERT(!fMustObfuscateUniformColor);
152 SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck);
153 SkASSERT(fCanUseFragCoord);
154 SkASSERT(!fIncompleteShortIntPrecision);
155 SkASSERT(!fAddAndTrueToLoopCondition);
156 SkASSERT(!fUnfoldShortCircuitAsTernary);
157 SkASSERT(!fEmulateAbsIntFunction);
158 SkASSERT(!fRewriteDoWhileLoops);
159 SkASSERT(!fRemovePowWithConstantExponent);
160 }
161 #if GR_TEST_UTILS
162 fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
163 #endif
164 }
165