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