GrShaderCaps.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #include "src/gpu/GrShaderCaps.h"
  8. #include "include/gpu/GrContextOptions.h"
  9. #include "src/utils/SkJSONWriter.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////
  11. GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
  12. fGLSLGeneration = k330_GrGLSLGeneration;
  13. fShaderDerivativeSupport = false;
  14. fGeometryShaderSupport = false;
  15. fGSInvocationsSupport = false;
  16. fPathRenderingSupport = false;
  17. fDstReadInShaderSupport = false;
  18. fDualSourceBlendingSupport = false;
  19. fIntegerSupport = false;
  20. fFBFetchSupport = false;
  21. fFBFetchNeedsCustomOutput = false;
  22. fUsesPrecisionModifiers = false;
  23. fCanUseAnyFunctionInShader = true;
  24. fCanUseMinAndAbsTogether = true;
  25. fCanUseFractForNegativeValues = true;
  26. fMustForceNegatedAtanParamToFloat = false;
  27. fAtan2ImplementedAsAtanYOverX = false;
  28. fMustDoOpBetweenFloorAndAbs = false;
  29. fRequiresLocalOutputColorForFBFetch = false;
  30. fMustObfuscateUniformColor = false;
  31. fMustGuardDivisionEvenAfterExplicitZeroCheck = false;
  32. fCanUseFragCoord = true;
  33. fIncompleteShortIntPrecision = false;
  34. fAddAndTrueToLoopCondition = false;
  35. fUnfoldShortCircuitAsTernary = false;
  36. fEmulateAbsIntFunction = false;
  37. fRewriteDoWhileLoops = false;
  38. fRemovePowWithConstantExponent = false;
  39. fMustWriteToFragColor = false;
  40. fFlatInterpolationSupport = false;
  41. fPreferFlatInterpolation = false;
  42. fNoPerspectiveInterpolationSupport = false;
  43. fSampleVariablesSupport = false;
  44. fSampleVariablesStencilSupport = false;
  45. fExternalTextureSupport = false;
  46. fVertexIDSupport = false;
  47. fFPManipulationSupport = false;
  48. fFloatIs32Bits = true;
  49. fHalfIs32Bits = false;
  50. fHasLowFragmentPrecision = false;
  51. // Backed API support is required to be able to make swizzle-neutral shaders (e.g.
  52. // GL_ARB_texture_swizzle).
  53. fTextureSwizzleAppliedInShader = true;
  54. fBuiltinFMASupport = false;
  55. fVersionDeclString = nullptr;
  56. fShaderDerivativeExtensionString = nullptr;
  57. fGeometryShaderExtensionString = nullptr;
  58. fGSInvocationsExtensionString = nullptr;
  59. fFragCoordConventionsExtensionString = nullptr;
  60. fSecondaryOutputExtensionString = nullptr;
  61. fExternalTextureExtensionString = nullptr;
  62. fSecondExternalTextureExtensionString = nullptr;
  63. fNoPerspectiveInterpolationExtensionString = nullptr;
  64. fSampleVariablesExtensionString = nullptr;
  65. fFBFetchColorName = nullptr;
  66. fFBFetchExtensionString = nullptr;
  67. fMaxFragmentSamplers = 0;
  68. fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
  69. }
  70. #ifdef SK_ENABLE_DUMP_GPU
  71. void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
  72. writer->beginObject();
  73. writer->appendBool("Shader Derivative Support", fShaderDerivativeSupport);
  74. writer->appendBool("Geometry Shader Support", fGeometryShaderSupport);
  75. writer->appendBool("Geometry Shader Invocations Support", fGSInvocationsSupport);
  76. writer->appendBool("Path Rendering Support", fPathRenderingSupport);
  77. writer->appendBool("Dst Read In Shader Support", fDstReadInShaderSupport);
  78. writer->appendBool("Dual Source Blending Support", fDualSourceBlendingSupport);
  79. writer->appendBool("Integer Support", fIntegerSupport);
  80. static const char* kAdvBlendEqInteractionStr[] = {
  81. "Not Supported",
  82. "Automatic",
  83. "General Enable",
  84. "Specific Enables",
  85. };
  86. GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
  87. GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
  88. GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
  89. GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
  90. GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
  91. writer->appendBool("FB Fetch Support", fFBFetchSupport);
  92. writer->appendBool("Uses precision modifiers", fUsesPrecisionModifiers);
  93. writer->appendBool("Can use any() function", fCanUseAnyFunctionInShader);
  94. writer->appendBool("Can use min() and abs() together", fCanUseMinAndAbsTogether);
  95. writer->appendBool("Can use fract() for negative values", fCanUseFractForNegativeValues);
  96. writer->appendBool("Must force negated atan param to float", fMustForceNegatedAtanParamToFloat);
  97. writer->appendBool("Must do op between floor and abs", fMustDoOpBetweenFloorAndAbs);
  98. writer->appendBool("Must use local out color for FBFetch", fRequiresLocalOutputColorForFBFetch);
  99. writer->appendBool("Must obfuscate uniform color", fMustObfuscateUniformColor);
  100. writer->appendBool("Must guard division even after explicit zero check",
  101. fMustGuardDivisionEvenAfterExplicitZeroCheck);
  102. writer->appendBool("Can use gl_FragCoord", fCanUseFragCoord);
  103. writer->appendBool("Incomplete short int precision", fIncompleteShortIntPrecision);
  104. writer->appendBool("Add and true to loops workaround", fAddAndTrueToLoopCondition);
  105. writer->appendBool("Unfold short circuit as ternary", fUnfoldShortCircuitAsTernary);
  106. writer->appendBool("Emulate abs(int) function", fEmulateAbsIntFunction);
  107. writer->appendBool("Rewrite do while loops", fRewriteDoWhileLoops);
  108. writer->appendBool("Rewrite pow with constant exponent", fRemovePowWithConstantExponent);
  109. writer->appendBool("Must write to sk_FragColor [workaround]", fMustWriteToFragColor);
  110. writer->appendBool("Flat interpolation support", fFlatInterpolationSupport);
  111. writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
  112. writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
  113. writer->appendBool("Sample variables support", fSampleVariablesSupport);
  114. writer->appendBool("Sample variables stencil support [workaround]",
  115. fSampleVariablesStencilSupport);
  116. writer->appendBool("External texture support", fExternalTextureSupport);
  117. writer->appendBool("sk_VertexID support", fVertexIDSupport);
  118. writer->appendBool("Floating point manipulation support", fFPManipulationSupport);
  119. writer->appendBool("float == fp32", fFloatIs32Bits);
  120. writer->appendBool("half == fp32", fHalfIs32Bits);
  121. writer->appendBool("Has poor fragment precision", fHasLowFragmentPrecision);
  122. writer->appendBool("Texture swizzle applied in shader", fTextureSwizzleAppliedInShader);
  123. writer->appendBool("Builtin fma() support", fBuiltinFMASupport);
  124. writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
  125. writer->appendString("Advanced blend equation interaction",
  126. kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
  127. writer->endObject();
  128. }
  129. #else
  130. void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { }
  131. #endif
  132. void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
  133. if (options.fDisableDriverCorrectnessWorkarounds) {
  134. SkASSERT(fCanUseAnyFunctionInShader);
  135. SkASSERT(fCanUseMinAndAbsTogether);
  136. SkASSERT(fCanUseFractForNegativeValues);
  137. SkASSERT(!fMustForceNegatedAtanParamToFloat);
  138. SkASSERT(!fAtan2ImplementedAsAtanYOverX);
  139. SkASSERT(!fMustDoOpBetweenFloorAndAbs);
  140. SkASSERT(!fRequiresLocalOutputColorForFBFetch);
  141. SkASSERT(!fMustObfuscateUniformColor);
  142. SkASSERT(!fMustGuardDivisionEvenAfterExplicitZeroCheck);
  143. SkASSERT(fCanUseFragCoord);
  144. SkASSERT(!fIncompleteShortIntPrecision);
  145. SkASSERT(!fAddAndTrueToLoopCondition);
  146. SkASSERT(!fUnfoldShortCircuitAsTernary);
  147. SkASSERT(!fEmulateAbsIntFunction);
  148. SkASSERT(!fRewriteDoWhileLoops);
  149. SkASSERT(!fRemovePowWithConstantExponent);
  150. SkASSERT(!fMustWriteToFragColor);
  151. }
  152. #if GR_TEST_UTILS
  153. fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
  154. #endif
  155. }