jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 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 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 9 | #include "GrShaderCaps.h" |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 10 | |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
| 12 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 13 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 14 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 15 | static const char* shader_type_to_string(GrShaderType type) { |
| 16 | switch (type) { |
| 17 | case kVertex_GrShaderType: |
| 18 | return "vertex"; |
| 19 | case kGeometry_GrShaderType: |
| 20 | return "geometry"; |
| 21 | case kFragment_GrShaderType: |
| 22 | return "fragment"; |
| 23 | } |
| 24 | return ""; |
| 25 | } |
jvanverth | 98a83a9 | 2015-06-24 11:07:07 -0700 | [diff] [blame] | 26 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 27 | static const char* precision_to_string(GrSLPrecision p) { |
| 28 | switch (p) { |
| 29 | case kLow_GrSLPrecision: |
| 30 | return "low"; |
| 31 | case kMedium_GrSLPrecision: |
| 32 | return "medium"; |
| 33 | case kHigh_GrSLPrecision: |
| 34 | return "high"; |
| 35 | } |
| 36 | return ""; |
| 37 | } |
| 38 | |
| 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 | fPLSPathRenderingSupport = false; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 51 | fDropsTileOnZeroDivide = false; |
| 52 | fFBFetchSupport = false; |
| 53 | fFBFetchNeedsCustomOutput = false; |
| 54 | fBindlessTextureSupport = false; |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 55 | fUsesPrecisionModifiers = false; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 56 | fCanUseAnyFunctionInShader = true; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 57 | fCanUseMinAndAbsTogether = true; |
| 58 | fMustForceNegatedAtanParamToFloat = false; |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 59 | fAtan2ImplementedAsAtanYOverX = false; |
egdaniel | 138c263 | 2016-08-17 10:59:00 -0700 | [diff] [blame] | 60 | fRequiresLocalOutputColorForFBFetch = false; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 61 | fFlatInterpolationSupport = false; |
| 62 | fNoPerspectiveInterpolationSupport = false; |
cdalton | 4a98cdb | 2016-03-01 12:12:20 -0800 | [diff] [blame] | 63 | fMultisampleInterpolationSupport = false; |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 64 | fSampleVariablesSupport = false; |
| 65 | fSampleMaskOverrideCoverageSupport = false; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 66 | fExternalTextureSupport = false; |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 67 | fTexelFetchSupport = false; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 68 | |
| 69 | fPixelLocalStorageSize = 0; |
| 70 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 71 | fVersionDeclString = nullptr; |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 72 | fShaderDerivativeExtensionString = nullptr; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 73 | fFragCoordConventionsExtensionString = nullptr; |
| 74 | fSecondaryOutputExtensionString = nullptr; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 75 | fExternalTextureExtensionString = nullptr; |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 76 | fTexelBufferExtensionString = nullptr; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 77 | fNoPerspectiveInterpolationExtensionString = nullptr; |
cdalton | 4a98cdb | 2016-03-01 12:12:20 -0800 | [diff] [blame] | 78 | fMultisampleInterpolationExtensionString = nullptr; |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 79 | fSampleVariablesExtensionString = nullptr; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 80 | fFBFetchColorName = nullptr; |
| 81 | fFBFetchExtensionString = nullptr; |
Brian Salomon | f26f7a0 | 2016-11-15 14:05:01 -0500 | [diff] [blame] | 82 | fImageLoadStoreExtensionString = nullptr; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 83 | fMaxVertexSamplers = 0; |
| 84 | fMaxGeometrySamplers = 0; |
| 85 | fMaxFragmentSamplers = 0; |
| 86 | fMaxCombinedSamplers = 0; |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 87 | fMaxVertexImageStorages = 0; |
| 88 | fMaxGeometryImageStorages = 0; |
| 89 | fMaxFragmentImageStorages = 0; |
| 90 | fMaxCombinedImageStorages = 0; |
jvanverth | 98a83a9 | 2015-06-24 11:07:07 -0700 | [diff] [blame] | 91 | fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 94 | SkString GrShaderCaps::dump() const { |
| 95 | SkString r; |
| 96 | static const char* gNY[] = { "NO", "YES" }; |
| 97 | r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| 98 | r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 99 | r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); |
| 100 | r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]); |
| 101 | r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]); |
| 102 | r.appendf("Integer Support : %s\n", gNY[fIntegerSupport]); |
| 103 | r.appendf("Texel Buffer Support : %s\n", gNY[fTexelBufferSupport]); |
| 104 | r.appendf("Image Load Store Support : %s\n", gNY[fImageLoadStoreSupport]); |
| 105 | |
| 106 | r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]); |
| 107 | |
| 108 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 109 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 110 | r.appendf("\t%s:\n", shader_type_to_string(shaderType)); |
| 111 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 112 | if (fFloatPrecisions[s][p].supported()) { |
| 113 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
| 114 | r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n", |
| 115 | precision_to_string(precision), |
| 116 | fFloatPrecisions[s][p].fLogRangeLow, |
| 117 | fFloatPrecisions[s][p].fLogRangeHigh, |
| 118 | fFloatPrecisions[s][p].fBits); |
| 119 | } |
| 120 | } |
| 121 | } |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 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 | r.appendf("--- GLSL-Specific ---\n"); |
| 136 | |
| 137 | r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO")); |
| 138 | r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO")); |
| 139 | r.appendf("Bindless texture support: %s\n", (fBindlessTextureSupport ? "YES" : "NO")); |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 140 | r.appendf("Uses precision modifiers: %s\n", (fUsesPrecisionModifiers ? "YES" : "NO")); |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 141 | r.appendf("Can use any() function: %s\n", (fCanUseAnyFunctionInShader ? "YES" : "NO")); |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 142 | r.appendf("Can use min() and abs() together: %s\n", (fCanUseMinAndAbsTogether ? "YES" : "NO")); |
| 143 | r.appendf("Must force negated atan param to float: %s\n", (fMustForceNegatedAtanParamToFloat ? |
| 144 | "YES" : "NO")); |
egdaniel | 138c263 | 2016-08-17 10:59:00 -0700 | [diff] [blame] | 145 | r.appendf("Must use local out color for FBFetch: %s\n", (fRequiresLocalOutputColorForFBFetch ? |
| 146 | "YES" : "NO")); |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 147 | r.appendf("Flat interpolation support: %s\n", (fFlatInterpolationSupport ? "YES" : "NO")); |
| 148 | r.appendf("No perspective interpolation support: %s\n", (fNoPerspectiveInterpolationSupport ? |
| 149 | "YES" : "NO")); |
cdalton | 4a98cdb | 2016-03-01 12:12:20 -0800 | [diff] [blame] | 150 | r.appendf("Multisample interpolation support: %s\n", (fMultisampleInterpolationSupport ? |
| 151 | "YES" : "NO")); |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 152 | r.appendf("Sample variables support: %s\n", (fSampleVariablesSupport ? "YES" : "NO")); |
| 153 | r.appendf("Sample mask override coverage support: %s\n", (fSampleMaskOverrideCoverageSupport ? |
| 154 | "YES" : "NO")); |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 155 | r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO")); |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 156 | r.appendf("texelFetch support: %s\n", (fTexelFetchSupport ? "YES" : "NO")); |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 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); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 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); |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 165 | r.appendf("Advanced blend equation interaction: %s\n", |
| 166 | kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); |
| 167 | return r; |
| 168 | } |
| 169 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 170 | void GrShaderCaps::initSamplerPrecisionTable() { |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 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; |
| 181 | } |
| 182 | |
| 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]); |
| 191 | } |
| 192 | |
| 193 | GR_STATIC_ASSERT(0 == kLow_GrSLPrecision); |
| 194 | GR_STATIC_ASSERT(1 == kMedium_GrSLPrecision); |
| 195 | GR_STATIC_ASSERT(2 == kHigh_GrSLPrecision); |
| 196 | |
| 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); |
| 201 | } |
| 202 | |
| 203 | uint8_t* table = fSamplerPrecisions[visibility]; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 204 | table[kUnknown_GrPixelConfig] = kDefault_GrSLPrecision; |
| 205 | table[kAlpha_8_GrPixelConfig] = lowp; |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 206 | table[kGray_8_GrPixelConfig] = lowp; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 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[kLATC_GrPixelConfig] = lowp; |
| 216 | table[kR11_EAC_GrPixelConfig] = lowp; |
| 217 | table[kASTC_12x12_GrPixelConfig] = lowp; |
| 218 | table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision; |
| 219 | table[kAlpha_half_GrPixelConfig] = mediump; |
| 220 | table[kRGBA_half_GrPixelConfig] = mediump; |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 221 | |
Brian Osman | d0be1ef | 2017-01-11 16:57:15 -0500 | [diff] [blame] | 222 | GR_STATIC_ASSERT(17 == kGrPixelConfigCnt); |
cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 226 | void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) { |
| 227 | fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending; |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 228 | } |