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 fExternalTextureSupport = false;
50 fVertexIDSupport = false;
51 fFPManipulationSupport = false;
52 fFloatIs32Bits = true;
53 fHalfIs32Bits = false;
54 fUnsignedSupport = false;
55 fBuiltinFMASupport = false;
56
57 fVersionDeclString = nullptr;
58 fShaderDerivativeExtensionString = nullptr;
59 fGeometryShaderExtensionString = nullptr;
60 fGSInvocationsExtensionString = nullptr;
61 fFragCoordConventionsExtensionString = nullptr;
62 fSecondaryOutputExtensionString = nullptr;
63 fExternalTextureExtensionString = nullptr;
64 fSecondExternalTextureExtensionString = nullptr;
65 fNoPerspectiveInterpolationExtensionString = nullptr;
66 fFBFetchColorName = nullptr;
67 fFBFetchExtensionString = nullptr;
68 fImageLoadStoreExtensionString = nullptr;
69 fMaxFragmentSamplers = 0;
70 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
71 }
72
73 #ifdef SK_ENABLE_DUMP_GPU
dumpJSON(SkJSONWriter * writer) const74 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
75 writer->beginObject();
76
77 writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport);
78 writer->appendBool("Geometry Shader Support", fGeometryShaderSupport);
79 writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport);
80 writer->appendBool("Path Rendering Support", fPathRenderingSupport);
81 writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport);
82 writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport);
83 writer->appendBool("Integer Support", fIntegerSupport);
84 writer->appendBool("Image Load Store Support", fImageLoadStoreSupport);
85
86 static const char* kAdvBlendEqInteractionStr[] = {
87 "Not Supported",
88 "Automatic",
89 "General Enable",
90 "Specific Enables",
91 };
92 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
93 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
94 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
95 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
96 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
97
98 writer->appendBool("FB Fetch Support", fFBFetchSupport);
99 writer->appendBool("Drops tile on zero divide", fDropsTileOnZeroDivide);
100 writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers);
101 writer->appendBool("Can use any() function", fCanUseAnyFunctionInShader);
102 writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether);
103 writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues);
104 writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat);
105 writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs);
106 writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch);
107 writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor);
108 writer->appendBool("Must guard division even after explicit zero check",
109 fMustGuardDivisionEvenAfterExplicitZeroCheck);
110 writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord);
111 writer->appendBool("Incomplete short int precision", fIncompleteShortIntPrecision);
112 writer->appendBool("Add and true to loops workaround", fAddAndTrueToLoopCondition);
113 writer->appendBool("Unfold short circuit as ternary", fUnfoldShortCircuitAsTernary);
114 writer->appendBool("Emulate abs(int) function", fEmulateAbsIntFunction);
115 writer->appendBool("Rewrite do while loops", fRewriteDoWhileLoops);
116 writer->appendBool("Rewrite pow with constant exponent", fRemovePowWithConstantExponent);
117 writer->appendBool("Flat interpolation support", fFlatInterpolationSupport);
118 writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
119 writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
120 writer->appendBool("External texture support", fExternalTextureSupport);
121 writer->appendBool("sk_VertexID support", fVertexIDSupport);
122 writer->appendBool("Floating point manipulation support", fFPManipulationSupport);
123 writer->appendBool("float == fp32", fFloatIs32Bits);
124 writer->appendBool("half == fp32", fHalfIs32Bits);
125 writer->appendBool("Builtin fma() support", fBuiltinFMASupport);
126
127 writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
128 writer->appendString("Advanced blend equation interaction",
129 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
130
131 writer->endObject();
132 }
133 #else
dumpJSON(SkJSONWriter * writer) const134 void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { }
135 #endif
136
applyOptionsOverrides(const GrContextOptions & options)137 void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
138 if (options.fDisableDriverCorrectnessWorkarounds) {
139 SkASSERT(fCanUseAnyFunctionInShader);
140 SkASSERT(fCanUseMinAndAbsTogether);
141 SkASSERT(fCanUseFractForNegativeValues);
142 SkASSERT(!fMustForceNegatedAtanParamToFloat);
143 SkASSERT(!fAtan2ImplementedAsAtanYOverX);
144 SkASSERT(!fMustDoOpBetweenFloorAndAbs);
145 SkASSERT(!fRequiresLocalOutputColorForFBFetch);
146 SkASSERT(!fMustObfuscateUniformColor);
147 SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck);
148 SkASSERT(fCanUseFragCoord);
149 SkASSERT(!fIncompleteShortIntPrecision);
150 SkASSERT(!fAddAndTrueToLoopCondition);
151 SkASSERT(!fUnfoldShortCircuitAsTernary);
152 SkASSERT(!fEmulateAbsIntFunction);
153 SkASSERT(!fRewriteDoWhileLoops);
154 SkASSERT(!fRemovePowWithConstantExponent);
155 }
156 #if GR_TEST_UTILS
157 fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
158 #endif
159 }
160