blob: 33d6e147d2e122990cfc387b8366e5e251756eab [file] [log] [blame]
jvanverthcba99b82015-06-24 06:59:57 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrShaderCaps.h"
jvanverthcba99b82015-06-24 06:59:57 -070010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrContextOptions.h"
12#include "src/utils/SkJSONWriter.h"
egdanielb7e7d572015-11-04 04:23:53 -080013
jvanverthcba99b82015-06-24 06:59:57 -070014////////////////////////////////////////////////////////////////////////////////////////////
15
Brian Salomon94efbf52016-11-29 13:43:05 -050016GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
17 fGLSLGeneration = k330_GrGLSLGeneration;
18 fShaderDerivativeSupport = false;
19 fGeometryShaderSupport = false;
Chris Daltonf1b47bb2017-10-06 11:57:51 -060020 fGSInvocationsSupport = false;
Brian Salomon94efbf52016-11-29 13:43:05 -050021 fDstReadInShaderSupport = false;
22 fDualSourceBlendingSupport = false;
23 fIntegerSupport = false;
jvanverthcba99b82015-06-24 06:59:57 -070024 fFBFetchSupport = false;
25 fFBFetchNeedsCustomOutput = false;
egdanielf5294392015-10-21 07:14:17 -070026 fUsesPrecisionModifiers = false;
egdaniel472d44e2015-10-22 08:20:00 -070027 fCanUseAnyFunctionInShader = true;
egdaniel8dcdedc2015-11-11 06:27:20 -080028 fCanUseMinAndAbsTogether = true;
Florin Malita8a0044f2017-08-07 14:38:22 -040029 fCanUseFractForNegativeValues = true;
egdaniel8dcdedc2015-11-11 06:27:20 -080030 fMustForceNegatedAtanParamToFloat = false;
Greg Daniel80a08dd2017-01-20 10:45:49 -050031 fAtan2ImplementedAsAtanYOverX = false;
Greg Daniel10ed2432017-12-01 16:19:43 -050032 fMustDoOpBetweenFloorAndAbs = false;
egdaniel138c2632016-08-17 10:59:00 -070033 fRequiresLocalOutputColorForFBFetch = false;
Brian Osmanac1e4962017-05-25 11:34:38 -040034 fMustObfuscateUniformColor = false;
Brian Osmandff5d432017-08-01 14:46:18 -040035 fMustGuardDivisionEvenAfterExplicitZeroCheck = false;
Brian Salomonf8c187c2019-12-19 14:41:57 -050036 fInBlendModesFailRandomlyForAllZeroVec = false;
Brian Osmancd3261a2018-01-16 13:52:29 +000037 fCanUseFragCoord = true;
Chris Daltonc2d0dd62018-03-07 07:46:10 -070038 fIncompleteShortIntPrecision = false;
Adrienne Walkeree8295c2018-08-21 10:56:30 -070039 fAddAndTrueToLoopCondition = false;
Adrienne Walkerc02165f2018-08-21 11:08:11 -070040 fUnfoldShortCircuitAsTernary = false;
Adrienne Walker92b161f2018-08-22 10:41:52 -070041 fEmulateAbsIntFunction = false;
Adrienne Walker8b23ca62018-08-22 10:45:41 -070042 fRewriteDoWhileLoops = false;
Adrienne Walker2f4c09b2018-08-22 16:04:57 -070043 fRemovePowWithConstantExponent = false;
Chris Dalton8e30ad42019-04-08 10:51:14 -060044 fMustWriteToFragColor = false;
Brian Salomon5a5f3e82019-08-16 15:05:40 -040045 fNoDefaultPrecisionForExternalSamplers = false;
John Stiles85749c02021-03-23 17:12:03 -040046 fRewriteMatrixVectorMultiply = false;
cdaltonc08f1962016-02-12 12:14:06 -080047 fFlatInterpolationSupport = false;
Brian Salomon41274562017-09-15 09:40:03 -070048 fPreferFlatInterpolation = false;
cdaltonc08f1962016-02-12 12:14:06 -080049 fNoPerspectiveInterpolationSupport = false;
Chris Dalton8a64a442019-10-29 18:54:58 -060050 fSampleMaskSupport = false;
cdalton9c3f1432016-03-11 10:07:37 -080051 fExternalTextureSupport = false;
Chris Dalton1d616352017-05-31 12:51:23 -060052 fVertexIDSupport = false;
Chris Dalton7c7ff032018-03-28 20:09:58 -060053 fFPManipulationSupport = false;
Chris Dalton47c8ed32017-11-15 18:27:09 -070054 fFloatIs32Bits = true;
55 fHalfIs32Bits = false;
Jim Van Verth20ae25c2019-03-29 08:50:41 -040056 fHasLowFragmentPrecision = false;
Brian Salomone9f22652021-04-12 11:18:32 -040057 fReducedShaderMode = false;
Brian Osman76f635c2020-03-25 16:23:11 -040058 fColorSpaceMathNeedsFloat = false;
Brian Osmand8efe702020-09-22 09:49:04 -040059 fBuiltinFMASupport = false;
John Stiles6f3015a2020-10-08 14:55:36 -040060 fBuiltinDeterminantSupport = false;
Ethan Nicholas70728ef2020-05-28 07:09:00 -040061 fCanUseDoLoops = true;
Jim Van Verthff98f282021-03-19 08:37:02 -040062 fCanUseFastMath = false;
Brian Osman28f702c2021-02-02 11:52:07 -050063 fUseNodePools = true;
Brian Salomon94efbf52016-11-29 13:43:05 -050064
egdaniel472d44e2015-10-22 08:20:00 -070065 fVersionDeclString = nullptr;
egdaniel574a4c12015-11-02 06:22:44 -080066 fShaderDerivativeExtensionString = nullptr;
Chris Dalton8fd79552018-01-11 00:46:14 -050067 fGeometryShaderExtensionString = nullptr;
Chris Daltonf1b47bb2017-10-06 11:57:51 -060068 fGSInvocationsExtensionString = nullptr;
egdaniel8dcdedc2015-11-11 06:27:20 -080069 fFragCoordConventionsExtensionString = nullptr;
70 fSecondaryOutputExtensionString = nullptr;
bsalomon7ea33f52015-11-22 14:51:00 -080071 fExternalTextureExtensionString = nullptr;
Brian Osman061020e2018-04-17 14:22:15 -040072 fSecondExternalTextureExtensionString = nullptr;
cdaltonc08f1962016-02-12 12:14:06 -080073 fNoPerspectiveInterpolationExtensionString = nullptr;
Chris Daltond31b5e72019-02-26 18:02:16 -070074 fSampleVariablesExtensionString = nullptr;
Chris Dalton5a2f9622019-12-27 14:56:38 -070075 fTessellationExtensionString = nullptr;
halcanary96fcdcc2015-08-27 07:41:13 -070076 fFBFetchColorName = nullptr;
77 fFBFetchExtensionString = nullptr;
cdalton9c3f1432016-03-11 10:07:37 -080078 fMaxFragmentSamplers = 0;
Chris Daltonb96995d2020-06-04 16:44:29 -060079 fMaxTessellationSegments = 0;
jvanverth98a83a92015-06-24 11:07:07 -070080 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
jvanverthcba99b82015-06-24 06:59:57 -070081}
82
Kevin Lubickf4def342018-10-04 12:52:50 -040083#ifdef SK_ENABLE_DUMP_GPU
Brian Osman71a18892017-08-10 10:23:25 -040084void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
85 writer->beginObject();
Brian Salomon94efbf52016-11-29 13:43:05 -050086
Brian Osman71a18892017-08-10 10:23:25 -040087 writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport);
88 writer->appendBool("Geometry Shader Support", fGeometryShaderSupport);
Chris Daltonf1b47bb2017-10-06 11:57:51 -060089 writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport);
Brian Osman71a18892017-08-10 10:23:25 -040090 writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport);
91 writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport);
92 writer->appendBool("Integer Support", fIntegerSupport);
Brian Osman71a18892017-08-10 10:23:25 -040093
jvanverthcba99b82015-06-24 06:59:57 -070094 static const char* kAdvBlendEqInteractionStr[] = {
95 "Not Supported",
96 "Automatic",
97 "General Enable",
jvanverthcba99b82015-06-24 06:59:57 -070098 };
Brian Salomon4dea72a2019-12-18 10:43:10 -050099 static_assert(0 == kNotSupported_AdvBlendEqInteraction);
100 static_assert(1 == kAutomatic_AdvBlendEqInteraction);
101 static_assert(2 == kGeneralEnable_AdvBlendEqInteraction);
Brian Salomon4dea72a2019-12-18 10:43:10 -0500102 static_assert(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
jvanverthcba99b82015-06-24 06:59:57 -0700103
Brian Osman71a18892017-08-10 10:23:25 -0400104 writer->appendBool("FB Fetch Support", fFBFetchSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400105 writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers);
106 writer->appendBool("Can use any() function", fCanUseAnyFunctionInShader);
107 writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether);
108 writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues);
109 writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat);
Greg Daniel10ed2432017-12-01 16:19:43 -0500110 writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs);
Brian Osman71a18892017-08-10 10:23:25 -0400111 writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch);
Brian Osman71a18892017-08-10 10:23:25 -0400112 writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor);
113 writer->appendBool("Must guard division even after explicit zero check",
114 fMustGuardDivisionEvenAfterExplicitZeroCheck);
Brian Salomonf8c187c2019-12-19 14:41:57 -0500115 writer->appendBool(
116 "src-in and dst-in blend modes may return (0,0,0,1) when dst/src is all zeros",
117 fInBlendModesFailRandomlyForAllZeroVec);
Brian Osmancd3261a2018-01-16 13:52:29 +0000118 writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord);
Chris Daltonc2d0dd62018-03-07 07:46:10 -0700119 writer->appendBool("Incomplete short int precision", fIncompleteShortIntPrecision);
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700120 writer->appendBool("Add and true to loops workaround", fAddAndTrueToLoopCondition);
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700121 writer->appendBool("Unfold short circuit as ternary", fUnfoldShortCircuitAsTernary);
Adrienne Walker92b161f2018-08-22 10:41:52 -0700122 writer->appendBool("Emulate abs(int) function", fEmulateAbsIntFunction);
Adrienne Walker8b23ca62018-08-22 10:45:41 -0700123 writer->appendBool("Rewrite do while loops", fRewriteDoWhileLoops);
Adrienne Walker2f4c09b2018-08-22 16:04:57 -0700124 writer->appendBool("Rewrite pow with constant exponent", fRemovePowWithConstantExponent);
Chris Dalton8e30ad42019-04-08 10:51:14 -0600125 writer->appendBool("Must write to sk_FragColor [workaround]", fMustWriteToFragColor);
Brian Salomon5a5f3e82019-08-16 15:05:40 -0400126 writer->appendBool("Don't add default precision statement for samplerExternalOES",
127 fNoDefaultPrecisionForExternalSamplers);
John Stiles85749c02021-03-23 17:12:03 -0400128 writer->appendBool("Rewrite matrix-vector multiply", fRewriteMatrixVectorMultiply);
Brian Osman71a18892017-08-10 10:23:25 -0400129 writer->appendBool("Flat interpolation support", fFlatInterpolationSupport);
Brian Salomon41274562017-09-15 09:40:03 -0700130 writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
Brian Osman71a18892017-08-10 10:23:25 -0400131 writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
Chris Dalton8a64a442019-10-29 18:54:58 -0600132 writer->appendBool("Sample mask support", fSampleMaskSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400133 writer->appendBool("External texture support", fExternalTextureSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400134 writer->appendBool("sk_VertexID support", fVertexIDSupport);
Chris Dalton7c7ff032018-03-28 20:09:58 -0600135 writer->appendBool("Floating point manipulation support", fFPManipulationSupport);
Chris Dalton47c8ed32017-11-15 18:27:09 -0700136 writer->appendBool("float == fp32", fFloatIs32Bits);
137 writer->appendBool("half == fp32", fHalfIs32Bits);
Jim Van Verth20ae25c2019-03-29 08:50:41 -0400138 writer->appendBool("Has poor fragment precision", fHasLowFragmentPrecision);
Brian Osman76f635c2020-03-25 16:23:11 -0400139 writer->appendBool("Color space math needs float", fColorSpaceMathNeedsFloat);
Chris Daltona7086182018-11-16 09:33:43 -0500140 writer->appendBool("Builtin fma() support", fBuiltinFMASupport);
John Stiles6f3015a2020-10-08 14:55:36 -0400141 writer->appendBool("Builtin determinant() support", fBuiltinDeterminantSupport);
Ethan Nicholas70728ef2020-05-28 07:09:00 -0400142 writer->appendBool("Can use do-while loops", fCanUseDoLoops);
Brian Osman28f702c2021-02-02 11:52:07 -0500143 writer->appendBool("Use node pools", fUseNodePools);
jvanverthcba99b82015-06-24 06:59:57 -0700144
Brian Osman71a18892017-08-10 10:23:25 -0400145 writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
Chris Daltonb96995d2020-06-04 16:44:29 -0600146 writer->appendS32("Max Tessellation Segments", fMaxTessellationSegments);
Brian Osman71a18892017-08-10 10:23:25 -0400147 writer->appendString("Advanced blend equation interaction",
148 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
149
150 writer->endObject();
jvanverthcba99b82015-06-24 06:59:57 -0700151}
Kevin Lubickf4def342018-10-04 12:52:50 -0400152#else
153void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { }
154#endif
jvanverthcba99b82015-06-24 06:59:57 -0700155
Brian Salomon94efbf52016-11-29 13:43:05 -0500156void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500157 if (options.fDisableDriverCorrectnessWorkarounds) {
158 SkASSERT(fCanUseAnyFunctionInShader);
159 SkASSERT(fCanUseMinAndAbsTogether);
160 SkASSERT(fCanUseFractForNegativeValues);
161 SkASSERT(!fMustForceNegatedAtanParamToFloat);
162 SkASSERT(!fAtan2ImplementedAsAtanYOverX);
163 SkASSERT(!fMustDoOpBetweenFloorAndAbs);
164 SkASSERT(!fRequiresLocalOutputColorForFBFetch);
165 SkASSERT(!fMustObfuscateUniformColor);
166 SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck);
Brian Salomonf8c187c2019-12-19 14:41:57 -0500167 SkASSERT(!fInBlendModesFailRandomlyForAllZeroVec);
Brian Salomon01b476a2018-01-23 11:06:41 -0500168 SkASSERT(fCanUseFragCoord);
Chris Daltonc2d0dd62018-03-07 07:46:10 -0700169 SkASSERT(!fIncompleteShortIntPrecision);
Adrienne Walkeree8295c2018-08-21 10:56:30 -0700170 SkASSERT(!fAddAndTrueToLoopCondition);
Adrienne Walkerc02165f2018-08-21 11:08:11 -0700171 SkASSERT(!fUnfoldShortCircuitAsTernary);
Adrienne Walker92b161f2018-08-22 10:41:52 -0700172 SkASSERT(!fEmulateAbsIntFunction);
Adrienne Walker8b23ca62018-08-22 10:45:41 -0700173 SkASSERT(!fRewriteDoWhileLoops);
Adrienne Walker2f4c09b2018-08-22 16:04:57 -0700174 SkASSERT(!fRemovePowWithConstantExponent);
Chris Dalton8e30ad42019-04-08 10:51:14 -0600175 SkASSERT(!fMustWriteToFragColor);
Brian Salomon5a5f3e82019-08-16 15:05:40 -0400176 SkASSERT(!fNoDefaultPrecisionForExternalSamplers);
John Stiles85749c02021-03-23 17:12:03 -0400177 SkASSERT(!fRewriteMatrixVectorMultiply);
Brian Salomon01b476a2018-01-23 11:06:41 -0500178 }
Chris Dalton4ac9aad2021-02-24 17:41:44 -0700179 if (!options.fEnableExperimentalHardwareTessellation) {
180 fMaxTessellationSegments = 0;
181 }
Brian Osman195c05b2017-08-30 15:14:04 -0400182#if GR_TEST_UTILS
Chris Dalton8367e112019-11-13 12:43:21 -0700183 if (options.fSuppressDualSourceBlending) {
184 fDualSourceBlendingSupport = false;
185 }
186 if (options.fSuppressGeometryShaders) {
187 fGeometryShaderSupport = false;
188 }
Chris Dalton31634282020-09-17 12:16:54 -0600189 if (options.fMaxTessellationSegmentsOverride > 0) {
190 fMaxTessellationSegments = std::min(options.fMaxTessellationSegmentsOverride,
191 fMaxTessellationSegments);
192 }
Brian Salomone9f22652021-04-12 11:18:32 -0400193 if (options.fReducedShaderVariations) {
194 fReducedShaderMode = true;
195 }
Brian Osman195c05b2017-08-30 15:14:04 -0400196#endif
egdanielb7e7d572015-11-04 04:23:53 -0800197}