| 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 | |
| 9 | #include "GrGLSLCaps.h" |
| 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 | |
| 15 | GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options) { |
| jvanverth | 98a83a9 | 2015-06-24 11:07:07 -0700 | [diff] [blame] | 16 | fGLSLGeneration = k330_GrGLSLGeneration; |
| 17 | |
| jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 18 | fDropsTileOnZeroDivide = false; |
| 19 | fFBFetchSupport = false; |
| 20 | fFBFetchNeedsCustomOutput = false; |
| 21 | fBindlessTextureSupport = false; |
| egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 22 | fUsesPrecisionModifiers = false; |
| egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 23 | fCanUseAnyFunctionInShader = true; |
| egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 24 | fCanUseMinAndAbsTogether = true; |
| 25 | fMustForceNegatedAtanParamToFloat = false; |
| egdaniel | 138c263 | 2016-08-17 10:59:00 -0700 | [diff] [blame] | 26 | fRequiresLocalOutputColorForFBFetch = false; |
| cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 27 | fFlatInterpolationSupport = false; |
| 28 | fNoPerspectiveInterpolationSupport = false; |
| cdalton | 4a98cdb | 2016-03-01 12:12:20 -0800 | [diff] [blame] | 29 | fMultisampleInterpolationSupport = false; |
| cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 30 | fSampleVariablesSupport = false; |
| 31 | fSampleMaskOverrideCoverageSupport = false; |
| cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 32 | fExternalTextureSupport = false; |
| cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 33 | fTexelFetchSupport = false; |
| egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 34 | fVersionDeclString = nullptr; |
| egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 35 | fShaderDerivativeExtensionString = nullptr; |
| egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 36 | fFragCoordConventionsExtensionString = nullptr; |
| 37 | fSecondaryOutputExtensionString = nullptr; |
| bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 38 | fExternalTextureExtensionString = nullptr; |
| cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 39 | fTexelBufferExtensionString = nullptr; |
| cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 40 | fNoPerspectiveInterpolationExtensionString = nullptr; |
| cdalton | 4a98cdb | 2016-03-01 12:12:20 -0800 | [diff] [blame] | 41 | fMultisampleInterpolationExtensionString = nullptr; |
| cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 42 | fSampleVariablesExtensionString = nullptr; |
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 43 | fFBFetchColorName = nullptr; |
| 44 | fFBFetchExtensionString = nullptr; |
| cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 45 | fMaxVertexSamplers = 0; |
| 46 | fMaxGeometrySamplers = 0; |
| 47 | fMaxFragmentSamplers = 0; |
| 48 | fMaxCombinedSamplers = 0; |
| jvanverth | 98a83a9 | 2015-06-24 11:07:07 -0700 | [diff] [blame] | 49 | fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; |
| jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | 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")); |
| egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 72 | r.appendf("Uses precision modifiers: %s\n", (fUsesPrecisionModifiers ? "YES" : "NO")); |
| egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 73 | r.appendf("Can use any() function: %s\n", (fCanUseAnyFunctionInShader ? "YES" : "NO")); |
| egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 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")); |
| egdaniel | 138c263 | 2016-08-17 10:59:00 -0700 | [diff] [blame] | 77 | r.appendf("Must use local out color for FBFetch: %s\n", (fRequiresLocalOutputColorForFBFetch ? |
| 78 | "YES" : "NO")); |
| cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 79 | r.appendf("Flat interpolation support: %s\n", (fFlatInterpolationSupport ? "YES" : "NO")); |
| 80 | r.appendf("No perspective interpolation support: %s\n", (fNoPerspectiveInterpolationSupport ? |
| 81 | "YES" : "NO")); |
| cdalton | 4a98cdb | 2016-03-01 12:12:20 -0800 | [diff] [blame] | 82 | r.appendf("Multisample interpolation support: %s\n", (fMultisampleInterpolationSupport ? |
| 83 | "YES" : "NO")); |
| cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 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")); |
| cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 87 | r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO")); |
| cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 88 | r.appendf("texelFetch support: %s\n", (fTexelFetchSupport ? "YES" : "NO")); |
| cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 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); |
| jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 93 | r.appendf("Advanced blend equation interaction: %s\n", |
| 94 | kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); |
| 95 | return r; |
| 96 | } |
| 97 | |
| cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 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]; |
| Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 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[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; |
| cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 149 | |
| Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 150 | GR_STATIC_ASSERT(17 == kGrPixelConfigCnt); |
| cdalton | a6b92ad | 2016-04-11 12:03:08 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 154 | void GrGLSLCaps::onApplyOptionsOverrides(const GrContextOptions& options) { |
| egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 155 | } |