xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrShaderCaps.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2012 Google Inc.
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker 
9*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrShaderCaps.h"
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/GrContextOptions.h"
12*c8dee2aaSAndroid Build Coastguard Worker 
13*c8dee2aaSAndroid Build Coastguard Worker ////////////////////////////////////////////////////////////////////////////////////////////
14*c8dee2aaSAndroid Build Coastguard Worker 
15*c8dee2aaSAndroid Build Coastguard Worker #ifdef SK_ENABLE_DUMP_GPU
16*c8dee2aaSAndroid Build Coastguard Worker #include "src/utils/SkJSONWriter.h"
17*c8dee2aaSAndroid Build Coastguard Worker 
dumpJSON(SkJSONWriter * writer) const18*c8dee2aaSAndroid Build Coastguard Worker void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
19*c8dee2aaSAndroid Build Coastguard Worker     writer->beginObject();
20*c8dee2aaSAndroid Build Coastguard Worker 
21*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport);
22*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport);
23*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport);
24*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Integer Support", fIntegerSupport);
25*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Nonsquare Matrix Support", fNonsquareMatrixSupport);
26*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Inverse Hyperbolic Support", fInverseHyperbolicSupport);
27*c8dee2aaSAndroid Build Coastguard Worker 
28*c8dee2aaSAndroid Build Coastguard Worker     static const char* kAdvBlendEqInteractionStr[] = {
29*c8dee2aaSAndroid Build Coastguard Worker         "Not Supported",
30*c8dee2aaSAndroid Build Coastguard Worker         "Automatic",
31*c8dee2aaSAndroid Build Coastguard Worker         "General Enable",
32*c8dee2aaSAndroid Build Coastguard Worker     };
33*c8dee2aaSAndroid Build Coastguard Worker     static_assert(0 == kNotSupported_AdvBlendEqInteraction);
34*c8dee2aaSAndroid Build Coastguard Worker     static_assert(1 == kAutomatic_AdvBlendEqInteraction);
35*c8dee2aaSAndroid Build Coastguard Worker     static_assert(2 == kGeneralEnable_AdvBlendEqInteraction);
36*c8dee2aaSAndroid Build Coastguard Worker     static_assert(std::size(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
37*c8dee2aaSAndroid Build Coastguard Worker 
38*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("FB Fetch Support", fFBFetchSupport);
39*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers);
40*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Can use void-typed expressions in a sequence expression",
41*c8dee2aaSAndroid Build Coastguard Worker                        fCanUseVoidInSequenceExpressions);
42*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether);
43*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues);
44*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat);
45*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must force negated ldexp param to multiply",
46*c8dee2aaSAndroid Build Coastguard Worker                        fMustForceNegatedLdexpParamToMultiply);
47*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs);
48*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch);
49*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor);
50*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must guard division even after explicit zero check",
51*c8dee2aaSAndroid Build Coastguard Worker                        fMustGuardDivisionEvenAfterExplicitZeroCheck);
52*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord);
53*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Add and true to loops workaround", fAddAndTrueToLoopCondition);
54*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Unfold short circuit as ternary", fUnfoldShortCircuitAsTernary);
55*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Emulate abs(int) function", fEmulateAbsIntFunction);
56*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Rewrite do while loops", fRewriteDoWhileLoops);
57*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Rewrite switch statements", fRewriteSwitchStatements);
58*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Rewrite pow with constant exponent", fRemovePowWithConstantExponent);
59*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must write to sk_FragColor [workaround]", fMustWriteToFragColor);
60*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Don't add default precision statement for samplerExternalOES",
61*c8dee2aaSAndroid Build Coastguard Worker                        fNoDefaultPrecisionForExternalSamplers);
62*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Rewrite matrix-vector multiply", fRewriteMatrixVectorMultiply);
63*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Rewrite matrix equality comparisons", fRewriteMatrixComparisons);
64*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Rounding fix required for Perlin noise", fPerlinNoiseRoundingFix);
65*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Must declare fragment front-facing", fMustDeclareFragmentFrontFacing);
66*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Flat interpolation support", fFlatInterpolationSupport);
67*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
68*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
69*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Sample mask support", fSampleMaskSupport);
70*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("External texture support", fExternalTextureSupport);
71*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("sk_VertexID support", fVertexIDSupport);
72*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Infinity support", fInfinitySupport);
73*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Non-constant array index support", fNonconstantArrayIndexSupport);
74*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Bit manipulation support", fBitManipulationSupport);
75*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("float == fp32", fFloatIs32Bits);
76*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("half == fp32", fHalfIs32Bits);
77*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Has poor fragment precision", fHasLowFragmentPrecision);
78*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Builtin fma() support", fBuiltinFMASupport);
79*c8dee2aaSAndroid Build Coastguard Worker     writer->appendBool("Builtin determinant() support", fBuiltinDeterminantSupport);
80*c8dee2aaSAndroid Build Coastguard Worker 
81*c8dee2aaSAndroid Build Coastguard Worker     writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
82*c8dee2aaSAndroid Build Coastguard Worker     writer->appendCString("Advanced blend equation interaction",
83*c8dee2aaSAndroid Build Coastguard Worker                           kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
84*c8dee2aaSAndroid Build Coastguard Worker 
85*c8dee2aaSAndroid Build Coastguard Worker     writer->endObject();
86*c8dee2aaSAndroid Build Coastguard Worker }
87*c8dee2aaSAndroid Build Coastguard Worker #else
dumpJSON(SkJSONWriter * writer) const88*c8dee2aaSAndroid Build Coastguard Worker void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { }
89*c8dee2aaSAndroid Build Coastguard Worker #endif
90*c8dee2aaSAndroid Build Coastguard Worker 
applyOptionsOverrides(const GrContextOptions & options)91*c8dee2aaSAndroid Build Coastguard Worker void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
92*c8dee2aaSAndroid Build Coastguard Worker     if (options.fDisableDriverCorrectnessWorkarounds) {
93*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(fCanUseVoidInSequenceExpressions);
94*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(fCanUseMinAndAbsTogether);
95*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(fCanUseFractForNegativeValues);
96*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fMustForceNegatedAtanParamToFloat);
97*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fMustForceNegatedLdexpParamToMultiply);
98*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fAtan2ImplementedAsAtanYOverX);
99*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fMustDoOpBetweenFloorAndAbs);
100*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fRequiresLocalOutputColorForFBFetch);
101*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fMustObfuscateUniformColor);
102*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck);
103*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(fCanUseFragCoord);
104*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fAddAndTrueToLoopCondition);
105*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fUnfoldShortCircuitAsTernary);
106*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fEmulateAbsIntFunction);
107*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fRewriteDoWhileLoops);
108*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fRewriteSwitchStatements);
109*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fRemovePowWithConstantExponent);
110*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fMustWriteToFragColor);
111*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fNoDefaultPrecisionForExternalSamplers);
112*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fRewriteMatrixVectorMultiply);
113*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fRewriteMatrixComparisons);
114*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fPerlinNoiseRoundingFix);
115*c8dee2aaSAndroid Build Coastguard Worker         SkASSERT(!fMustDeclareFragmentFrontFacing);
116*c8dee2aaSAndroid Build Coastguard Worker     }
117*c8dee2aaSAndroid Build Coastguard Worker     if (options.fReducedShaderVariations) {
118*c8dee2aaSAndroid Build Coastguard Worker         fReducedShaderMode = true;
119*c8dee2aaSAndroid Build Coastguard Worker     }
120*c8dee2aaSAndroid Build Coastguard Worker #if defined(GPU_TEST_UTILS)
121*c8dee2aaSAndroid Build Coastguard Worker     if (options.fSuppressDualSourceBlending) {
122*c8dee2aaSAndroid Build Coastguard Worker         fDualSourceBlendingSupport = false;
123*c8dee2aaSAndroid Build Coastguard Worker     }
124*c8dee2aaSAndroid Build Coastguard Worker     if (options.fSuppressFramebufferFetch) {
125*c8dee2aaSAndroid Build Coastguard Worker         fFBFetchSupport = false;
126*c8dee2aaSAndroid Build Coastguard Worker     }
127*c8dee2aaSAndroid Build Coastguard Worker #endif
128*c8dee2aaSAndroid Build Coastguard Worker }
129