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 "GrGLSLCaps.h"
10
11 #include "GrContextOptions.h"
12
13 ////////////////////////////////////////////////////////////////////////////////////////////
14
GrGLSLCaps(const GrContextOptions & options)15 GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options) {
16 fGLSLGeneration = k330_GrGLSLGeneration;
17
18 fDropsTileOnZeroDivide = false;
19 fFBFetchSupport = false;
20 fFBFetchNeedsCustomOutput = false;
21 fBindlessTextureSupport = false;
22 fUsesPrecisionModifiers = false;
23 fCanUseAnyFunctionInShader = true;
24 fCanUseMinAndAbsTogether = true;
25 fMustForceNegatedAtanParamToFloat = false;
26 fRequiresLocalOutputColorForFBFetch = false;
27 fFlatInterpolationSupport = false;
28 fNoPerspectiveInterpolationSupport = false;
29 fMultisampleInterpolationSupport = false;
30 fSampleVariablesSupport = false;
31 fSampleMaskOverrideCoverageSupport = false;
32 fExternalTextureSupport = false;
33 fTexelFetchSupport = false;
34 fVersionDeclString = nullptr;
35 fShaderDerivativeExtensionString = nullptr;
36 fFragCoordConventionsExtensionString = nullptr;
37 fSecondaryOutputExtensionString = nullptr;
38 fExternalTextureExtensionString = nullptr;
39 fTexelBufferExtensionString = nullptr;
40 fNoPerspectiveInterpolationExtensionString = nullptr;
41 fMultisampleInterpolationExtensionString = nullptr;
42 fSampleVariablesExtensionString = nullptr;
43 fFBFetchColorName = nullptr;
44 fFBFetchExtensionString = nullptr;
45 fMaxVertexSamplers = 0;
46 fMaxGeometrySamplers = 0;
47 fMaxFragmentSamplers = 0;
48 fMaxCombinedSamplers = 0;
49 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
50 }
51
dump() const52 SkString GrGLSLCaps::dump() const {
53 SkString r = INHERITED::dump();
54
55 static const char* kAdvBlendEqInteractionStr[] = {
56 "Not Supported",
57 "Automatic",
58 "General Enable",
59 "Specific Enables",
60 };
61 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
62 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
63 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
64 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
65 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
66
67 r.appendf("--- GLSL-Specific ---\n");
68
69 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
70 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
71 r.appendf("Bindless texture support: %s\n", (fBindlessTextureSupport ? "YES" : "NO"));
72 r.appendf("Uses precision modifiers: %s\n", (fUsesPrecisionModifiers ? "YES" : "NO"));
73 r.appendf("Can use any() function: %s\n", (fCanUseAnyFunctionInShader ? "YES" : "NO"));
74 r.appendf("Can use min() and abs() together: %s\n", (fCanUseMinAndAbsTogether ? "YES" : "NO"));
75 r.appendf("Must force negated atan param to float: %s\n", (fMustForceNegatedAtanParamToFloat ?
76 "YES" : "NO"));
77 r.appendf("Must use local out color for FBFetch: %s\n", (fRequiresLocalOutputColorForFBFetch ?
78 "YES" : "NO"));
79 r.appendf("Flat interpolation support: %s\n", (fFlatInterpolationSupport ? "YES" : "NO"));
80 r.appendf("No perspective interpolation support: %s\n", (fNoPerspectiveInterpolationSupport ?
81 "YES" : "NO"));
82 r.appendf("Multisample interpolation support: %s\n", (fMultisampleInterpolationSupport ?
83 "YES" : "NO"));
84 r.appendf("Sample variables support: %s\n", (fSampleVariablesSupport ? "YES" : "NO"));
85 r.appendf("Sample mask override coverage support: %s\n", (fSampleMaskOverrideCoverageSupport ?
86 "YES" : "NO"));
87 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
88 r.appendf("texelFetch support: %s\n", (fTexelFetchSupport ? "YES" : "NO"));
89 r.appendf("Max VS Samplers: %d\n", fMaxVertexSamplers);
90 r.appendf("Max GS Samplers: %d\n", fMaxGeometrySamplers);
91 r.appendf("Max FS Samplers: %d\n", fMaxFragmentSamplers);
92 r.appendf("Max Combined Samplers: %d\n", fMaxFragmentSamplers);
93 r.appendf("Advanced blend equation interaction: %s\n",
94 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
95 return r;
96 }
97
initSamplerPrecisionTable()98 void GrGLSLCaps::initSamplerPrecisionTable() {
99 // Determine the largest precision qualifiers that are effectively the same as lowp/mediump.
100 // e.g. if lowp == mediump, then use mediump instead of lowp.
101 GrSLPrecision effectiveMediumP[kGrShaderTypeCount];
102 GrSLPrecision effectiveLowP[kGrShaderTypeCount];
103 for (int s = 0; s < kGrShaderTypeCount; ++s) {
104 const PrecisionInfo* info = fFloatPrecisions[s];
105 effectiveMediumP[s] = info[kHigh_GrSLPrecision] == info[kMedium_GrSLPrecision] ?
106 kHigh_GrSLPrecision : kMedium_GrSLPrecision;
107 effectiveLowP[s] = info[kMedium_GrSLPrecision] == info[kLow_GrSLPrecision] ?
108 effectiveMediumP[s] : kLow_GrSLPrecision;
109 }
110
111 // Determine which precision qualifiers should be used with samplers.
112 for (int visibility = 0; visibility < (1 << kGrShaderTypeCount); ++visibility) {
113 GrSLPrecision mediump = kHigh_GrSLPrecision;
114 GrSLPrecision lowp = kHigh_GrSLPrecision;
115 for (int s = 0; s < kGrShaderTypeCount; ++s) {
116 if (visibility & (1 << s)) {
117 mediump = SkTMin(mediump, effectiveMediumP[s]);
118 lowp = SkTMin(lowp, effectiveLowP[s]);
119 }
120
121 GR_STATIC_ASSERT(0 == kLow_GrSLPrecision);
122 GR_STATIC_ASSERT(1 == kMedium_GrSLPrecision);
123 GR_STATIC_ASSERT(2 == kHigh_GrSLPrecision);
124
125 GR_STATIC_ASSERT((1 << kVertex_GrShaderType) == kVertex_GrShaderFlag);
126 GR_STATIC_ASSERT((1 << kGeometry_GrShaderType) == kGeometry_GrShaderFlag);
127 GR_STATIC_ASSERT((1 << kFragment_GrShaderType) == kFragment_GrShaderFlag);
128 GR_STATIC_ASSERT(3 == kGrShaderTypeCount);
129 }
130
131 uint8_t* table = fSamplerPrecisions[visibility];
132 table[kUnknown_GrPixelConfig] = kDefault_GrSLPrecision;
133 table[kAlpha_8_GrPixelConfig] = lowp;
134 table[kIndex_8_GrPixelConfig] = lowp;
135 table[kRGB_565_GrPixelConfig] = lowp;
136 table[kRGBA_4444_GrPixelConfig] = lowp;
137 table[kRGBA_8888_GrPixelConfig] = lowp;
138 table[kBGRA_8888_GrPixelConfig] = lowp;
139 table[kSRGBA_8888_GrPixelConfig] = lowp;
140 table[kSBGRA_8888_GrPixelConfig] = lowp;
141 table[kETC1_GrPixelConfig] = lowp;
142 table[kLATC_GrPixelConfig] = lowp;
143 table[kR11_EAC_GrPixelConfig] = lowp;
144 table[kASTC_12x12_GrPixelConfig] = lowp;
145 table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
146 table[kAlpha_half_GrPixelConfig] = mediump;
147 table[kRGBA_half_GrPixelConfig] = mediump;
148
149 GR_STATIC_ASSERT(16 == kGrPixelConfigCnt);
150 }
151 }
152
onApplyOptionsOverrides(const GrContextOptions & options)153 void GrGLSLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
154 }
155