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" |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 12 | #include "SkJSONWriter.h" |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 13 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 14 | //////////////////////////////////////////////////////////////////////////////////////////// |
| 15 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 16 | GrShaderCaps::GrShaderCaps(const GrContextOptions& options) { |
| 17 | fGLSLGeneration = k330_GrGLSLGeneration; |
| 18 | fShaderDerivativeSupport = false; |
| 19 | fGeometryShaderSupport = false; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 20 | fGSInvocationsSupport = false; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 21 | fPathRenderingSupport = false; |
| 22 | fDstReadInShaderSupport = false; |
| 23 | fDualSourceBlendingSupport = false; |
| 24 | fIntegerSupport = false; |
| 25 | fTexelBufferSupport = false; |
| 26 | fImageLoadStoreSupport = false; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 27 | fDropsTileOnZeroDivide = false; |
| 28 | fFBFetchSupport = false; |
| 29 | fFBFetchNeedsCustomOutput = false; |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 30 | fUsesPrecisionModifiers = false; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 31 | fCanUseAnyFunctionInShader = true; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 32 | fCanUseMinAndAbsTogether = true; |
Florin Malita | 8a0044f | 2017-08-07 14:38:22 -0400 | [diff] [blame] | 33 | fCanUseFractForNegativeValues = true; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 34 | fMustForceNegatedAtanParamToFloat = false; |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 35 | fAtan2ImplementedAsAtanYOverX = false; |
Greg Daniel | 10ed243 | 2017-12-01 16:19:43 -0500 | [diff] [blame] | 36 | fMustDoOpBetweenFloorAndAbs = false; |
egdaniel | 138c263 | 2016-08-17 10:59:00 -0700 | [diff] [blame] | 37 | fRequiresLocalOutputColorForFBFetch = false; |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 38 | fMustObfuscateUniformColor = false; |
Brian Osman | dff5d43 | 2017-08-01 14:46:18 -0400 | [diff] [blame] | 39 | fMustGuardDivisionEvenAfterExplicitZeroCheck = false; |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 40 | fCanUseFragCoord = true; |
Brian Salomon | 1b112cc | 2018-07-10 20:34:16 +0000 | [diff] [blame] | 41 | fInterpolantsAreInaccurate = false; |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 42 | fIncompleteShortIntPrecision = false; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 43 | fFlatInterpolationSupport = false; |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 44 | fPreferFlatInterpolation = false; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 45 | fNoPerspectiveInterpolationSupport = false; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 46 | fExternalTextureSupport = false; |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 47 | fTexelFetchSupport = false; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 48 | fVertexIDSupport = false; |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 49 | fFPManipulationSupport = false; |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 50 | fFloatIs32Bits = true; |
| 51 | fHalfIs32Bits = false; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 52 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 53 | fVersionDeclString = nullptr; |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 54 | fShaderDerivativeExtensionString = nullptr; |
Chris Dalton | 8fd7955 | 2018-01-11 00:46:14 -0500 | [diff] [blame] | 55 | fGeometryShaderExtensionString = nullptr; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 56 | fGSInvocationsExtensionString = nullptr; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 57 | fFragCoordConventionsExtensionString = nullptr; |
| 58 | fSecondaryOutputExtensionString = nullptr; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 59 | fExternalTextureExtensionString = nullptr; |
Brian Osman | 061020e | 2018-04-17 14:22:15 -0400 | [diff] [blame] | 60 | fSecondExternalTextureExtensionString = nullptr; |
cdalton | f8a6ce8 | 2016-04-11 13:02:05 -0700 | [diff] [blame] | 61 | fTexelBufferExtensionString = nullptr; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 62 | fNoPerspectiveInterpolationExtensionString = nullptr; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 63 | fFBFetchColorName = nullptr; |
| 64 | fFBFetchExtensionString = nullptr; |
Brian Salomon | f26f7a0 | 2016-11-15 14:05:01 -0500 | [diff] [blame] | 65 | fImageLoadStoreExtensionString = nullptr; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 66 | fMaxVertexSamplers = 0; |
| 67 | fMaxGeometrySamplers = 0; |
| 68 | fMaxFragmentSamplers = 0; |
| 69 | fMaxCombinedSamplers = 0; |
jvanverth | 98a83a9 | 2015-06-24 11:07:07 -0700 | [diff] [blame] | 70 | fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 71 | |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 72 | // TODO: Default this to 0 and only enable image multitexturing when a "safe" threshold is |
| 73 | // known for a GPU class. |
| 74 | fDisableImageMultitexturingDstRectAreaThreshold = std::numeric_limits<size_t>::max(); |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 77 | void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { |
| 78 | writer->beginObject(); |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 79 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 80 | writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport); |
| 81 | writer->appendBool("Geometry Shader Support", fGeometryShaderSupport); |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 82 | writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 83 | writer->appendBool("Path Rendering Support", fPathRenderingSupport); |
| 84 | writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport); |
| 85 | writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport); |
| 86 | writer->appendBool("Integer Support", fIntegerSupport); |
| 87 | writer->appendBool("Texel Buffer Support", fTexelBufferSupport); |
| 88 | writer->appendBool("Image Load Store Support", fImageLoadStoreSupport); |
| 89 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 90 | static const char* kAdvBlendEqInteractionStr[] = { |
| 91 | "Not Supported", |
| 92 | "Automatic", |
| 93 | "General Enable", |
| 94 | "Specific Enables", |
| 95 | }; |
| 96 | GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction); |
| 97 | GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction); |
| 98 | GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction); |
| 99 | GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction); |
| 100 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1); |
| 101 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 102 | writer->appendBool("FB Fetch Support", fFBFetchSupport); |
| 103 | writer->appendBool("Drops tile on zero divide", fDropsTileOnZeroDivide); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 104 | writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers); |
| 105 | writer->appendBool("Can use any() function", fCanUseAnyFunctionInShader); |
| 106 | writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether); |
| 107 | writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues); |
| 108 | writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat); |
Greg Daniel | 10ed243 | 2017-12-01 16:19:43 -0500 | [diff] [blame] | 109 | writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 110 | writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 111 | writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor); |
| 112 | writer->appendBool("Must guard division even after explicit zero check", |
| 113 | fMustGuardDivisionEvenAfterExplicitZeroCheck); |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 114 | writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord); |
Brian Salomon | 1b112cc | 2018-07-10 20:34:16 +0000 | [diff] [blame] | 115 | writer->appendBool("Interpolants are inaccurate", fInterpolantsAreInaccurate); |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 116 | writer->appendBool("Incomplete short int precision", fIncompleteShortIntPrecision); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 117 | writer->appendBool("Flat interpolation support", fFlatInterpolationSupport); |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 118 | writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 119 | writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 120 | writer->appendBool("External texture support", fExternalTextureSupport); |
| 121 | writer->appendBool("texelFetch support", fTexelFetchSupport); |
| 122 | writer->appendBool("sk_VertexID support", fVertexIDSupport); |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 123 | writer->appendBool("Floating point manipulation support", fFPManipulationSupport); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 124 | writer->appendBool("float == fp32", fFloatIs32Bits); |
| 125 | writer->appendBool("half == fp32", fHalfIs32Bits); |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 126 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 127 | writer->appendS32("Max VS Samplers", fMaxVertexSamplers); |
| 128 | writer->appendS32("Max GS Samplers", fMaxGeometrySamplers); |
| 129 | writer->appendS32("Max FS Samplers", fMaxFragmentSamplers); |
| 130 | writer->appendS32("Max Combined Samplers", fMaxFragmentSamplers); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 131 | writer->appendString("Advanced blend equation interaction", |
| 132 | kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 133 | writer->appendU64("Disable image multitexturing dst area threshold", |
| 134 | fDisableImageMultitexturingDstRectAreaThreshold); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 135 | |
| 136 | writer->endObject(); |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 139 | void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 140 | if (options.fDisableDriverCorrectnessWorkarounds) { |
| 141 | SkASSERT(fCanUseAnyFunctionInShader); |
| 142 | SkASSERT(fCanUseMinAndAbsTogether); |
| 143 | SkASSERT(fCanUseFractForNegativeValues); |
| 144 | SkASSERT(!fMustForceNegatedAtanParamToFloat); |
| 145 | SkASSERT(!fAtan2ImplementedAsAtanYOverX); |
| 146 | SkASSERT(!fMustDoOpBetweenFloorAndAbs); |
| 147 | SkASSERT(!fRequiresLocalOutputColorForFBFetch); |
| 148 | SkASSERT(!fMustObfuscateUniformColor); |
| 149 | SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck); |
| 150 | SkASSERT(fCanUseFragCoord); |
Brian Salomon | 1b112cc | 2018-07-10 20:34:16 +0000 | [diff] [blame] | 151 | SkASSERT(!fInterpolantsAreInaccurate); |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 152 | SkASSERT(!fIncompleteShortIntPrecision); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 153 | } |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 154 | #if GR_TEST_UTILS |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 155 | fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending; |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 156 | if (options.fDisableImageMultitexturing) { |
| 157 | fDisableImageMultitexturingDstRectAreaThreshold = 0; |
| 158 | } |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 159 | #endif |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 160 | } |