Line data Source code
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 :
13 : ////////////////////////////////////////////////////////////////////////////////////////////
14 :
15 0 : static const char* shader_type_to_string(GrShaderType type) {
16 0 : switch (type) {
17 : case kVertex_GrShaderType:
18 0 : return "vertex";
19 : case kGeometry_GrShaderType:
20 0 : return "geometry";
21 : case kFragment_GrShaderType:
22 0 : return "fragment";
23 : }
24 0 : return "";
25 : }
26 :
27 0 : static const char* precision_to_string(GrSLPrecision p) {
28 0 : switch (p) {
29 : case kLow_GrSLPrecision:
30 0 : return "low";
31 : case kMedium_GrSLPrecision:
32 0 : return "medium";
33 : case kHigh_GrSLPrecision:
34 0 : return "high";
35 : default:
36 0 : SkFAIL("Unexpected precision type.");
37 0 : return "";
38 : }
39 : }
40 :
41 0 : GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
42 0 : fGLSLGeneration = k330_GrGLSLGeneration;
43 0 : fShaderDerivativeSupport = false;
44 0 : fGeometryShaderSupport = false;
45 0 : fPathRenderingSupport = false;
46 0 : fDstReadInShaderSupport = false;
47 0 : fDualSourceBlendingSupport = false;
48 0 : fIntegerSupport = false;
49 0 : fTexelBufferSupport = false;
50 0 : fImageLoadStoreSupport = false;
51 0 : fShaderPrecisionVaries = false;
52 0 : fDropsTileOnZeroDivide = false;
53 0 : fFBFetchSupport = false;
54 0 : fFBFetchNeedsCustomOutput = false;
55 0 : fBindlessTextureSupport = false;
56 0 : fUsesPrecisionModifiers = false;
57 0 : fCanUseAnyFunctionInShader = true;
58 0 : fCanUseMinAndAbsTogether = true;
59 0 : fMustForceNegatedAtanParamToFloat = false;
60 0 : fAtan2ImplementedAsAtanYOverX = false;
61 0 : fRequiresLocalOutputColorForFBFetch = false;
62 0 : fMustImplementGSInvocationsWithLoop = false;
63 0 : fFlatInterpolationSupport = false;
64 0 : fNoPerspectiveInterpolationSupport = false;
65 0 : fMultisampleInterpolationSupport = false;
66 0 : fSampleVariablesSupport = false;
67 0 : fSampleMaskOverrideCoverageSupport = false;
68 0 : fExternalTextureSupport = false;
69 0 : fTexelFetchSupport = false;
70 :
71 0 : fVersionDeclString = nullptr;
72 0 : fShaderDerivativeExtensionString = nullptr;
73 0 : fFragCoordConventionsExtensionString = nullptr;
74 0 : fSecondaryOutputExtensionString = nullptr;
75 0 : fExternalTextureExtensionString = nullptr;
76 0 : fTexelBufferExtensionString = nullptr;
77 0 : fNoPerspectiveInterpolationExtensionString = nullptr;
78 0 : fMultisampleInterpolationExtensionString = nullptr;
79 0 : fSampleVariablesExtensionString = nullptr;
80 0 : fFBFetchColorName = nullptr;
81 0 : fFBFetchExtensionString = nullptr;
82 0 : fImageLoadStoreExtensionString = nullptr;
83 0 : fMaxVertexSamplers = 0;
84 0 : fMaxGeometrySamplers = 0;
85 0 : fMaxFragmentSamplers = 0;
86 0 : fMaxCombinedSamplers = 0;
87 0 : fMaxVertexImageStorages = 0;
88 0 : fMaxGeometryImageStorages = 0;
89 0 : fMaxFragmentImageStorages = 0;
90 0 : fMaxCombinedImageStorages = 0;
91 0 : fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
92 0 : }
93 :
94 0 : SkString GrShaderCaps::dump() const {
95 0 : SkString r;
96 : static const char* gNY[] = { "NO", "YES" };
97 0 : r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
98 0 : r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
99 0 : r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
100 0 : r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
101 0 : r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
102 0 : r.appendf("Integer Support : %s\n", gNY[fIntegerSupport]);
103 0 : r.appendf("Texel Buffer Support : %s\n", gNY[fTexelBufferSupport]);
104 0 : r.appendf("Image Load Store Support : %s\n", gNY[fImageLoadStoreSupport]);
105 :
106 0 : r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
107 :
108 0 : for (int s = 0; s < kGrShaderTypeCount; ++s) {
109 0 : GrShaderType shaderType = static_cast<GrShaderType>(s);
110 0 : r.appendf("\t%s:\n", shader_type_to_string(shaderType));
111 0 : for (int p = 0; p < kGrSLPrecisionCount; ++p) {
112 0 : if (fFloatPrecisions[s][p].supported()) {
113 0 : GrSLPrecision precision = static_cast<GrSLPrecision>(p);
114 0 : r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n",
115 : precision_to_string(precision),
116 0 : fFloatPrecisions[s][p].fLogRangeLow,
117 0 : fFloatPrecisions[s][p].fLogRangeHigh,
118 0 : fFloatPrecisions[s][p].fBits);
119 : }
120 : }
121 : }
122 :
123 : static const char* kAdvBlendEqInteractionStr[] = {
124 : "Not Supported",
125 : "Automatic",
126 : "General Enable",
127 : "Specific Enables",
128 : };
129 : GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
130 : GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
131 : GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
132 : GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
133 : GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
134 :
135 0 : r.appendf("--- GLSL-Specific ---\n");
136 :
137 0 : r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
138 0 : r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
139 0 : r.appendf("Bindless texture support: %s\n", (fBindlessTextureSupport ? "YES" : "NO"));
140 0 : r.appendf("Uses precision modifiers: %s\n", (fUsesPrecisionModifiers ? "YES" : "NO"));
141 0 : r.appendf("Can use any() function: %s\n", (fCanUseAnyFunctionInShader ? "YES" : "NO"));
142 0 : r.appendf("Can use min() and abs() together: %s\n", (fCanUseMinAndAbsTogether ? "YES" : "NO"));
143 0 : r.appendf("Must force negated atan param to float: %s\n", (fMustForceNegatedAtanParamToFloat ?
144 0 : "YES" : "NO"));
145 0 : r.appendf("Must use local out color for FBFetch: %s\n", (fRequiresLocalOutputColorForFBFetch ?
146 0 : "YES" : "NO"));
147 0 : r.appendf("Must implement geo shader invocations with loop : %s\n",
148 0 : (fMustImplementGSInvocationsWithLoop ? "YES" : "NO"));
149 0 : r.appendf("Flat interpolation support: %s\n", (fFlatInterpolationSupport ? "YES" : "NO"));
150 0 : r.appendf("No perspective interpolation support: %s\n", (fNoPerspectiveInterpolationSupport ?
151 0 : "YES" : "NO"));
152 0 : r.appendf("Multisample interpolation support: %s\n", (fMultisampleInterpolationSupport ?
153 0 : "YES" : "NO"));
154 0 : r.appendf("Sample variables support: %s\n", (fSampleVariablesSupport ? "YES" : "NO"));
155 0 : r.appendf("Sample mask override coverage support: %s\n", (fSampleMaskOverrideCoverageSupport ?
156 0 : "YES" : "NO"));
157 0 : r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
158 0 : r.appendf("texelFetch support: %s\n", (fTexelFetchSupport ? "YES" : "NO"));
159 0 : r.appendf("Max VS Samplers: %d\n", fMaxVertexSamplers);
160 0 : r.appendf("Max GS Samplers: %d\n", fMaxGeometrySamplers);
161 0 : r.appendf("Max FS Samplers: %d\n", fMaxFragmentSamplers);
162 0 : r.appendf("Max Combined Samplers: %d\n", fMaxFragmentSamplers);
163 0 : r.appendf("Max VS Image Storages: %d\n", fMaxVertexImageStorages);
164 0 : r.appendf("Max GS Image Storages: %d\n", fMaxGeometryImageStorages);
165 0 : r.appendf("Max FS Image Storages: %d\n", fMaxFragmentImageStorages);
166 0 : r.appendf("Max Combined Image Storages: %d\n", fMaxFragmentImageStorages);
167 0 : r.appendf("Advanced blend equation interaction: %s\n",
168 0 : kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
169 0 : return r;
170 : }
171 :
172 0 : void GrShaderCaps::initSamplerPrecisionTable() {
173 : // Determine the largest precision qualifiers that are effectively the same as lowp/mediump.
174 : // e.g. if lowp == mediump, then use mediump instead of lowp.
175 : GrSLPrecision effectiveMediumP[kGrShaderTypeCount];
176 : GrSLPrecision effectiveLowP[kGrShaderTypeCount];
177 0 : for (int s = 0; s < kGrShaderTypeCount; ++s) {
178 0 : const PrecisionInfo* info = fFloatPrecisions[s];
179 0 : effectiveMediumP[s] = info[kHigh_GrSLPrecision] == info[kMedium_GrSLPrecision] ?
180 : kHigh_GrSLPrecision : kMedium_GrSLPrecision;
181 0 : effectiveLowP[s] = info[kMedium_GrSLPrecision] == info[kLow_GrSLPrecision] ?
182 : effectiveMediumP[s] : kLow_GrSLPrecision;
183 : }
184 :
185 : // Determine which precision qualifiers should be used with samplers.
186 0 : for (int visibility = 0; visibility < (1 << kGrShaderTypeCount); ++visibility) {
187 0 : GrSLPrecision mediump = kHigh_GrSLPrecision;
188 0 : GrSLPrecision lowp = kHigh_GrSLPrecision;
189 0 : for (int s = 0; s < kGrShaderTypeCount; ++s) {
190 0 : if (visibility & (1 << s)) {
191 0 : mediump = SkTMin(mediump, effectiveMediumP[s]);
192 0 : lowp = SkTMin(lowp, effectiveLowP[s]);
193 : }
194 :
195 : GR_STATIC_ASSERT(0 == kLow_GrSLPrecision);
196 : GR_STATIC_ASSERT(1 == kMedium_GrSLPrecision);
197 : GR_STATIC_ASSERT(2 == kHigh_GrSLPrecision);
198 :
199 : GR_STATIC_ASSERT((1 << kVertex_GrShaderType) == kVertex_GrShaderFlag);
200 : GR_STATIC_ASSERT((1 << kGeometry_GrShaderType) == kGeometry_GrShaderFlag);
201 : GR_STATIC_ASSERT((1 << kFragment_GrShaderType) == kFragment_GrShaderFlag);
202 : GR_STATIC_ASSERT(3 == kGrShaderTypeCount);
203 : }
204 :
205 0 : uint8_t* table = fSamplerPrecisions[visibility];
206 0 : table[kUnknown_GrPixelConfig] = lowp;
207 0 : table[kAlpha_8_GrPixelConfig] = lowp;
208 0 : table[kGray_8_GrPixelConfig] = lowp;
209 0 : table[kRGB_565_GrPixelConfig] = lowp;
210 0 : table[kRGBA_4444_GrPixelConfig] = lowp;
211 0 : table[kRGBA_8888_GrPixelConfig] = lowp;
212 0 : table[kBGRA_8888_GrPixelConfig] = lowp;
213 0 : table[kSRGBA_8888_GrPixelConfig] = lowp;
214 0 : table[kSBGRA_8888_GrPixelConfig] = lowp;
215 0 : table[kRGBA_8888_sint_GrPixelConfig] = lowp;
216 0 : table[kETC1_GrPixelConfig] = lowp;
217 0 : table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
218 0 : table[kRG_float_GrPixelConfig] = kHigh_GrSLPrecision;
219 0 : table[kAlpha_half_GrPixelConfig] = mediump;
220 0 : table[kRGBA_half_GrPixelConfig] = mediump;
221 :
222 : GR_STATIC_ASSERT(15 == kGrPixelConfigCnt);
223 : }
224 0 : }
225 :
226 0 : void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
227 0 : fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
228 0 : }
|