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; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 25 | fImageLoadStoreSupport = false; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 26 | fDropsTileOnZeroDivide = false; |
| 27 | fFBFetchSupport = false; |
| 28 | fFBFetchNeedsCustomOutput = false; |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 29 | fUsesPrecisionModifiers = false; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 30 | fCanUseAnyFunctionInShader = true; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 31 | fCanUseMinAndAbsTogether = true; |
Florin Malita | 8a0044f | 2017-08-07 14:38:22 -0400 | [diff] [blame] | 32 | fCanUseFractForNegativeValues = true; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 33 | fMustForceNegatedAtanParamToFloat = false; |
Greg Daniel | 80a08dd | 2017-01-20 10:45:49 -0500 | [diff] [blame] | 34 | fAtan2ImplementedAsAtanYOverX = false; |
Greg Daniel | 10ed243 | 2017-12-01 16:19:43 -0500 | [diff] [blame] | 35 | fMustDoOpBetweenFloorAndAbs = false; |
egdaniel | 138c263 | 2016-08-17 10:59:00 -0700 | [diff] [blame] | 36 | fRequiresLocalOutputColorForFBFetch = false; |
Brian Osman | ac1e496 | 2017-05-25 11:34:38 -0400 | [diff] [blame] | 37 | fMustObfuscateUniformColor = false; |
Brian Osman | dff5d43 | 2017-08-01 14:46:18 -0400 | [diff] [blame] | 38 | fMustGuardDivisionEvenAfterExplicitZeroCheck = false; |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 39 | fCanUseFragCoord = true; |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 40 | fIncompleteShortIntPrecision = false; |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 41 | fAddAndTrueToLoopCondition = false; |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 42 | fUnfoldShortCircuitAsTernary = false; |
Adrienne Walker | 92b161f | 2018-08-22 10:41:52 -0700 | [diff] [blame] | 43 | fEmulateAbsIntFunction = false; |
Adrienne Walker | 8b23ca6 | 2018-08-22 10:45:41 -0700 | [diff] [blame] | 44 | fRewriteDoWhileLoops = false; |
Adrienne Walker | 2f4c09b | 2018-08-22 16:04:57 -0700 | [diff] [blame] | 45 | fRemovePowWithConstantExponent = false; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 46 | fFlatInterpolationSupport = false; |
Brian Salomon | 4127456 | 2017-09-15 09:40:03 -0700 | [diff] [blame] | 47 | fPreferFlatInterpolation = false; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 48 | fNoPerspectiveInterpolationSupport = false; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 49 | fExternalTextureSupport = false; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 50 | fVertexIDSupport = false; |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 51 | fFPManipulationSupport = false; |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 52 | fFloatIs32Bits = true; |
| 53 | fHalfIs32Bits = false; |
Chris Dalton | a708618 | 2018-11-16 09:33:43 -0500 | [diff] [blame] | 54 | fUnsignedSupport = false; |
| 55 | fBuiltinFMASupport = false; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 56 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 57 | fVersionDeclString = nullptr; |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 58 | fShaderDerivativeExtensionString = nullptr; |
Chris Dalton | 8fd7955 | 2018-01-11 00:46:14 -0500 | [diff] [blame] | 59 | fGeometryShaderExtensionString = nullptr; |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 60 | fGSInvocationsExtensionString = nullptr; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 61 | fFragCoordConventionsExtensionString = nullptr; |
| 62 | fSecondaryOutputExtensionString = nullptr; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 63 | fExternalTextureExtensionString = nullptr; |
Brian Osman | 061020e | 2018-04-17 14:22:15 -0400 | [diff] [blame] | 64 | fSecondExternalTextureExtensionString = nullptr; |
cdalton | c08f196 | 2016-02-12 12:14:06 -0800 | [diff] [blame] | 65 | fNoPerspectiveInterpolationExtensionString = 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 | fMaxFragmentSamplers = 0; |
jvanverth | 98a83a9 | 2015-06-24 11:07:07 -0700 | [diff] [blame] | 70 | fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 73 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 74 | void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { |
| 75 | writer->beginObject(); |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 76 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 77 | writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport); |
| 78 | writer->appendBool("Geometry Shader Support", fGeometryShaderSupport); |
Chris Dalton | f1b47bb | 2017-10-06 11:57:51 -0600 | [diff] [blame] | 79 | writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 80 | writer->appendBool("Path Rendering Support", fPathRenderingSupport); |
| 81 | writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport); |
| 82 | writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport); |
| 83 | writer->appendBool("Integer Support", fIntegerSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 84 | writer->appendBool("Image Load Store Support", fImageLoadStoreSupport); |
| 85 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 86 | static const char* kAdvBlendEqInteractionStr[] = { |
| 87 | "Not Supported", |
| 88 | "Automatic", |
| 89 | "General Enable", |
| 90 | "Specific Enables", |
| 91 | }; |
| 92 | GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction); |
| 93 | GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction); |
| 94 | GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction); |
| 95 | GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction); |
| 96 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1); |
| 97 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 98 | writer->appendBool("FB Fetch Support", fFBFetchSupport); |
| 99 | writer->appendBool("Drops tile on zero divide", fDropsTileOnZeroDivide); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 100 | writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers); |
| 101 | writer->appendBool("Can use any() function", fCanUseAnyFunctionInShader); |
| 102 | writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether); |
| 103 | writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues); |
| 104 | writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat); |
Greg Daniel | 10ed243 | 2017-12-01 16:19:43 -0500 | [diff] [blame] | 105 | writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 106 | writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 107 | writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor); |
| 108 | writer->appendBool("Must guard division even after explicit zero check", |
| 109 | fMustGuardDivisionEvenAfterExplicitZeroCheck); |
Brian Osman | cd3261a | 2018-01-16 13:52:29 +0000 | [diff] [blame] | 110 | writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord); |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 111 | writer->appendBool("Incomplete short int precision", fIncompleteShortIntPrecision); |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 112 | writer->appendBool("Add and true to loops workaround", fAddAndTrueToLoopCondition); |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 113 | writer->appendBool("Unfold short circuit as ternary", fUnfoldShortCircuitAsTernary); |
Adrienne Walker | 92b161f | 2018-08-22 10:41:52 -0700 | [diff] [blame] | 114 | writer->appendBool("Emulate abs(int) function", fEmulateAbsIntFunction); |
Adrienne Walker | 8b23ca6 | 2018-08-22 10:45:41 -0700 | [diff] [blame] | 115 | writer->appendBool("Rewrite do while loops", fRewriteDoWhileLoops); |
Adrienne Walker | 2f4c09b | 2018-08-22 16:04:57 -0700 | [diff] [blame] | 116 | writer->appendBool("Rewrite pow with constant exponent", fRemovePowWithConstantExponent); |
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); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 121 | writer->appendBool("sk_VertexID support", fVertexIDSupport); |
Chris Dalton | 7c7ff03 | 2018-03-28 20:09:58 -0600 | [diff] [blame] | 122 | writer->appendBool("Floating point manipulation support", fFPManipulationSupport); |
Chris Dalton | 47c8ed3 | 2017-11-15 18:27:09 -0700 | [diff] [blame] | 123 | writer->appendBool("float == fp32", fFloatIs32Bits); |
| 124 | writer->appendBool("half == fp32", fHalfIs32Bits); |
Chris Dalton | a708618 | 2018-11-16 09:33:43 -0500 | [diff] [blame] | 125 | writer->appendBool("Builtin fma() support", fBuiltinFMASupport); |
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 FS Samplers", fMaxFragmentSamplers); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 128 | writer->appendString("Advanced blend equation interaction", |
| 129 | kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); |
| 130 | |
| 131 | writer->endObject(); |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 132 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 133 | #else |
| 134 | void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { } |
| 135 | #endif |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 136 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 137 | void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) { |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 138 | if (options.fDisableDriverCorrectnessWorkarounds) { |
| 139 | SkASSERT(fCanUseAnyFunctionInShader); |
| 140 | SkASSERT(fCanUseMinAndAbsTogether); |
| 141 | SkASSERT(fCanUseFractForNegativeValues); |
| 142 | SkASSERT(!fMustForceNegatedAtanParamToFloat); |
| 143 | SkASSERT(!fAtan2ImplementedAsAtanYOverX); |
| 144 | SkASSERT(!fMustDoOpBetweenFloorAndAbs); |
| 145 | SkASSERT(!fRequiresLocalOutputColorForFBFetch); |
| 146 | SkASSERT(!fMustObfuscateUniformColor); |
| 147 | SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck); |
| 148 | SkASSERT(fCanUseFragCoord); |
Chris Dalton | c2d0dd6 | 2018-03-07 07:46:10 -0700 | [diff] [blame] | 149 | SkASSERT(!fIncompleteShortIntPrecision); |
Adrienne Walker | ee8295c | 2018-08-21 10:56:30 -0700 | [diff] [blame] | 150 | SkASSERT(!fAddAndTrueToLoopCondition); |
Adrienne Walker | c02165f | 2018-08-21 11:08:11 -0700 | [diff] [blame] | 151 | SkASSERT(!fUnfoldShortCircuitAsTernary); |
Adrienne Walker | 92b161f | 2018-08-22 10:41:52 -0700 | [diff] [blame] | 152 | SkASSERT(!fEmulateAbsIntFunction); |
Adrienne Walker | 8b23ca6 | 2018-08-22 10:45:41 -0700 | [diff] [blame] | 153 | SkASSERT(!fRewriteDoWhileLoops); |
Adrienne Walker | 2f4c09b | 2018-08-22 16:04:57 -0700 | [diff] [blame] | 154 | SkASSERT(!fRemovePowWithConstantExponent); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 155 | } |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 156 | #if GR_TEST_UTILS |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 157 | fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 158 | #endif |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 159 | } |