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