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 9#include "GrShaderCaps.h" 10 11#include "GrContextOptions.h" 12#include "SkJSONWriter.h" 13 14//////////////////////////////////////////////////////////////////////////////////////////// 15 16GrShaderCaps::GrShaderCaps(const GrContextOptions& options) { 17 fGLSLGeneration = k330_GrGLSLGeneration; 18 fShaderDerivativeSupport = false; 19 fGeometryShaderSupport = false; 20 fGSInvocationsSupport = false; 21 fPathRenderingSupport = false; 22 fDstReadInShaderSupport = false; 23 fDualSourceBlendingSupport = false; 24 fIntegerSupport = false; 25 fTexelBufferSupport = false; 26 fImageLoadStoreSupport = false; 27 fDropsTileOnZeroDivide = false; 28 fFBFetchSupport = false; 29 fFBFetchNeedsCustomOutput = false; 30 fBindlessTextureSupport = false; 31 fUsesPrecisionModifiers = false; 32 fCanUseAnyFunctionInShader = true; 33 fCanUseMinAndAbsTogether = true; 34 fCanUseFractForNegativeValues = true; 35 fMustForceNegatedAtanParamToFloat = false; 36 fAtan2ImplementedAsAtanYOverX = false; 37 fMustDoOpBetweenFloorAndAbs = false; 38 fRequiresLocalOutputColorForFBFetch = false; 39 fMustObfuscateUniformColor = false; 40 fMustGuardDivisionEvenAfterExplicitZeroCheck = false; 41 fCanUseFragCoord = true; 42 fInterpolantsAreInaccurate = false; 43 fFlatInterpolationSupport = false; 44 fPreferFlatInterpolation = false; 45 fNoPerspectiveInterpolationSupport = false; 46 fMultisampleInterpolationSupport = false; 47 fSampleVariablesSupport = false; 48 fSampleMaskOverrideCoverageSupport = false; 49 fExternalTextureSupport = false; 50 fTexelFetchSupport = false; 51 fVertexIDSupport = false; 52 fFloatIs32Bits = true; 53 fHalfIs32Bits = false; 54 55 fVersionDeclString = nullptr; 56 fShaderDerivativeExtensionString = nullptr; 57 fGeometryShaderExtensionString = nullptr; 58 fGSInvocationsExtensionString = nullptr; 59 fFragCoordConventionsExtensionString = nullptr; 60 fSecondaryOutputExtensionString = nullptr; 61 fExternalTextureExtensionString = nullptr; 62 fTexelBufferExtensionString = nullptr; 63 fNoPerspectiveInterpolationExtensionString = nullptr; 64 fMultisampleInterpolationExtensionString = nullptr; 65 fSampleVariablesExtensionString = nullptr; 66 fFBFetchColorName = nullptr; 67 fFBFetchExtensionString = nullptr; 68 fImageLoadStoreExtensionString = nullptr; 69 fMaxVertexSamplers = 0; 70 fMaxGeometrySamplers = 0; 71 fMaxFragmentSamplers = 0; 72 fMaxCombinedSamplers = 0; 73 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; 74 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(); 78} 79 80void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { 81 writer->beginObject(); 82 83 writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport); 84 writer->appendBool("Geometry Shader Support", fGeometryShaderSupport); 85 writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport); 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 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 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); 113 writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs); 114 writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch); 115 writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor); 116 writer->appendBool("Must guard division even after explicit zero check", 117 fMustGuardDivisionEvenAfterExplicitZeroCheck); 118 writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord); 119 writer->appendBool("Interpolants are inaccurate", fInterpolantsAreInaccurate); 120 writer->appendBool("Flat interpolation support", fFlatInterpolationSupport); 121 writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation); 122 writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport); 123 writer->appendBool("Multisample interpolation support", fMultisampleInterpolationSupport); 124 writer->appendBool("Sample variables support", fSampleVariablesSupport); 125 writer->appendBool("Sample mask override coverage support", fSampleMaskOverrideCoverageSupport); 126 writer->appendBool("External texture support", fExternalTextureSupport); 127 writer->appendBool("texelFetch support", fTexelFetchSupport); 128 writer->appendBool("sk_VertexID support", fVertexIDSupport); 129 writer->appendBool("float == fp32", fFloatIs32Bits); 130 writer->appendBool("half == fp32", fHalfIs32Bits); 131 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); 136 writer->appendString("Advanced blend equation interaction", 137 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); 138 writer->appendU64("Disable image multitexturing dst area threshold", 139 fDisableImageMultitexturingDstRectAreaThreshold); 140 141 writer->endObject(); 142} 143 144void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) { 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 } 158#if GR_TEST_UTILS 159 fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending; 160 if (options.fDisableImageMultitexturing) { 161 fDisableImageMultitexturingDstRectAreaThreshold = 0; 162 } 163#endif 164} 165