blob: 8e464b07e45156d04b589455f50cf4d96281dc3d [file] [log] [blame]
jvanverthcba99b82015-06-24 06:59:57 -07001/*
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
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
12
jvanverthcba99b82015-06-24 06:59:57 -070013////////////////////////////////////////////////////////////////////////////////////////////
14
15GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options) {
jvanverth98a83a92015-06-24 11:07:07 -070016 fGLSLGeneration = k330_GrGLSLGeneration;
17
jvanverthcba99b82015-06-24 06:59:57 -070018 fDropsTileOnZeroDivide = false;
19 fFBFetchSupport = false;
20 fFBFetchNeedsCustomOutput = false;
21 fBindlessTextureSupport = false;
egdanielf5294392015-10-21 07:14:17 -070022 fUsesPrecisionModifiers = false;
egdaniel472d44e2015-10-22 08:20:00 -070023 fCanUseAnyFunctionInShader = true;
egdaniel8dcdedc2015-11-11 06:27:20 -080024 fCanUseMinAndAbsTogether = true;
25 fMustForceNegatedAtanParamToFloat = false;
egdaniel138c2632016-08-17 10:59:00 -070026 fRequiresLocalOutputColorForFBFetch = false;
cdaltonc08f1962016-02-12 12:14:06 -080027 fFlatInterpolationSupport = false;
28 fNoPerspectiveInterpolationSupport = false;
cdalton4a98cdb2016-03-01 12:12:20 -080029 fMultisampleInterpolationSupport = false;
cdalton33ad7012016-02-22 07:55:44 -080030 fSampleVariablesSupport = false;
31 fSampleMaskOverrideCoverageSupport = false;
cdalton9c3f1432016-03-11 10:07:37 -080032 fExternalTextureSupport = false;
cdaltonf8a6ce82016-04-11 13:02:05 -070033 fTexelFetchSupport = false;
egdaniel472d44e2015-10-22 08:20:00 -070034 fVersionDeclString = nullptr;
egdaniel574a4c12015-11-02 06:22:44 -080035 fShaderDerivativeExtensionString = nullptr;
egdaniel8dcdedc2015-11-11 06:27:20 -080036 fFragCoordConventionsExtensionString = nullptr;
37 fSecondaryOutputExtensionString = nullptr;
bsalomon7ea33f52015-11-22 14:51:00 -080038 fExternalTextureExtensionString = nullptr;
cdaltonf8a6ce82016-04-11 13:02:05 -070039 fTexelBufferExtensionString = nullptr;
cdaltonc08f1962016-02-12 12:14:06 -080040 fNoPerspectiveInterpolationExtensionString = nullptr;
cdalton4a98cdb2016-03-01 12:12:20 -080041 fMultisampleInterpolationExtensionString = nullptr;
cdalton33ad7012016-02-22 07:55:44 -080042 fSampleVariablesExtensionString = nullptr;
halcanary96fcdcc2015-08-27 07:41:13 -070043 fFBFetchColorName = nullptr;
44 fFBFetchExtensionString = nullptr;
cdalton9c3f1432016-03-11 10:07:37 -080045 fMaxVertexSamplers = 0;
46 fMaxGeometrySamplers = 0;
47 fMaxFragmentSamplers = 0;
48 fMaxCombinedSamplers = 0;
jvanverth98a83a92015-06-24 11:07:07 -070049 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
jvanverthcba99b82015-06-24 06:59:57 -070050}
51
52SkString 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"));
egdanielf5294392015-10-21 07:14:17 -070072 r.appendf("Uses precision modifiers: %s\n", (fUsesPrecisionModifiers ? "YES" : "NO"));
egdaniel8dcdedc2015-11-11 06:27:20 -080073 r.appendf("Can use any() function: %s\n", (fCanUseAnyFunctionInShader ? "YES" : "NO"));
egdaniel8dcdedc2015-11-11 06:27:20 -080074 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"));
egdaniel138c2632016-08-17 10:59:00 -070077 r.appendf("Must use local out color for FBFetch: %s\n", (fRequiresLocalOutputColorForFBFetch ?
78 "YES" : "NO"));
cdaltonc08f1962016-02-12 12:14:06 -080079 r.appendf("Flat interpolation support: %s\n", (fFlatInterpolationSupport ? "YES" : "NO"));
80 r.appendf("No perspective interpolation support: %s\n", (fNoPerspectiveInterpolationSupport ?
81 "YES" : "NO"));
cdalton4a98cdb2016-03-01 12:12:20 -080082 r.appendf("Multisample interpolation support: %s\n", (fMultisampleInterpolationSupport ?
83 "YES" : "NO"));
cdalton33ad7012016-02-22 07:55:44 -080084 r.appendf("Sample variables support: %s\n", (fSampleVariablesSupport ? "YES" : "NO"));
85 r.appendf("Sample mask override coverage support: %s\n", (fSampleMaskOverrideCoverageSupport ?
86 "YES" : "NO"));
cdalton9c3f1432016-03-11 10:07:37 -080087 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
cdaltonf8a6ce82016-04-11 13:02:05 -070088 r.appendf("texelFetch support: %s\n", (fTexelFetchSupport ? "YES" : "NO"));
cdalton9c3f1432016-03-11 10:07:37 -080089 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);
jvanverthcba99b82015-06-24 06:59:57 -070093 r.appendf("Advanced blend equation interaction: %s\n",
94 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
95 return r;
96}
97
cdaltona6b92ad2016-04-11 12:03:08 -070098void 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];
Brian Salomonbf7b6202016-11-11 16:08:03 -0500132 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[kRGBA_8888_sint_GrPixelConfig] = lowp;
142 table[kETC1_GrPixelConfig] = lowp;
143 table[kLATC_GrPixelConfig] = lowp;
144 table[kR11_EAC_GrPixelConfig] = lowp;
145 table[kASTC_12x12_GrPixelConfig] = lowp;
146 table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
147 table[kAlpha_half_GrPixelConfig] = mediump;
148 table[kRGBA_half_GrPixelConfig] = mediump;
cdaltona6b92ad2016-04-11 12:03:08 -0700149
Brian Salomonbf7b6202016-11-11 16:08:03 -0500150 GR_STATIC_ASSERT(17 == kGrPixelConfigCnt);
cdaltona6b92ad2016-04-11 12:03:08 -0700151 }
152}
153
egdanielb7e7d572015-11-04 04:23:53 -0800154void GrGLSLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
egdanielb7e7d572015-11-04 04:23:53 -0800155}