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 | |
| 9 | #ifndef GrGLSLCaps_DEFINED |
| 10 | #define GrGLSLCaps_DEFINED |
| 11 | |
| 12 | #include "GrCaps.h" |
| 13 | #include "GrGLSL.h" |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 14 | #include "GrSwizzle.h" |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 15 | |
| 16 | class GrGLSLCaps : public GrShaderCaps { |
| 17 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 18 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Indicates how GLSL must interact with advanced blend equations. The KHR extension requires |
| 22 | * special layout qualifiers in the fragment shader. |
| 23 | */ |
| 24 | enum AdvBlendEqInteraction { |
| 25 | kNotSupported_AdvBlendEqInteraction, //<! No _blend_equation_advanced extension |
| 26 | kAutomatic_AdvBlendEqInteraction, //<! No interaction required |
| 27 | kGeneralEnable_AdvBlendEqInteraction, //<! layout(blend_support_all_equations) out |
| 28 | kSpecificEnables_AdvBlendEqInteraction, //<! Specific layout qualifiers per equation |
| 29 | |
| 30 | kLast_AdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction |
| 31 | }; |
| 32 | |
| 33 | /** |
| 34 | * Initializes the GrGLSLCaps to a default set of features |
| 35 | */ |
| 36 | GrGLSLCaps(const GrContextOptions&); |
| 37 | |
| 38 | /** |
| 39 | * Some helper functions for encapsulating various extensions to read FB Buffer on openglES |
| 40 | * |
| 41 | * TODO(joshualitt) On desktop opengl 4.2+ we can achieve something similar to this effect |
| 42 | */ |
| 43 | bool fbFetchSupport() const { return fFBFetchSupport; } |
| 44 | |
| 45 | bool fbFetchNeedsCustomOutput() const { return fFBFetchNeedsCustomOutput; } |
| 46 | |
| 47 | bool bindlessTextureSupport() const { return fBindlessTextureSupport; } |
| 48 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 49 | const char* versionDeclString() const { return fVersionDeclString; } |
| 50 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 51 | const char* fbFetchColorName() const { return fFBFetchColorName; } |
| 52 | |
| 53 | const char* fbFetchExtensionString() const { return fFBFetchExtensionString; } |
| 54 | |
| 55 | bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; } |
| 56 | |
| 57 | AdvBlendEqInteraction advBlendEqInteraction() const { return fAdvBlendEqInteraction; } |
| 58 | |
| 59 | bool mustEnableAdvBlendEqs() const { |
| 60 | return fAdvBlendEqInteraction >= kGeneralEnable_AdvBlendEqInteraction; |
| 61 | } |
| 62 | |
| 63 | bool mustEnableSpecificAdvBlendEqs() const { |
| 64 | return fAdvBlendEqInteraction == kSpecificEnables_AdvBlendEqInteraction; |
| 65 | } |
| 66 | |
| 67 | bool mustDeclareFragmentShaderOutput() const { |
| 68 | return fGLSLGeneration > k110_GrGLSLGeneration; |
| 69 | } |
| 70 | |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 71 | bool usesPrecisionModifiers() const { return fUsesPrecisionModifiers; } |
| 72 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 73 | // Returns whether we can use the glsl funciton any() in our shader code. |
| 74 | bool canUseAnyFunctionInShader() const { return fCanUseAnyFunctionInShader; } |
| 75 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 76 | bool canUseMinAndAbsTogether() const { return fCanUseMinAndAbsTogether; } |
| 77 | |
| 78 | bool mustForceNegatedAtanParamToFloat() const { return fMustForceNegatedAtanParamToFloat; } |
| 79 | |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 80 | // Returns the string of an extension that must be enabled in the shader to support |
| 81 | // derivatives. If nullptr is returned then no extension needs to be enabled. Before calling |
| 82 | // this function, the caller should check that shaderDerivativeSupport exists. |
| 83 | const char* shaderDerivativeExtensionString() const { |
| 84 | SkASSERT(this->shaderDerivativeSupport()); |
| 85 | return fShaderDerivativeExtensionString; |
| 86 | } |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 87 | |
| 88 | // Returns the string of an extension that will do all necessary coord transfomations needed |
| 89 | // when reading the fragment position. If such an extension does not exisits, this function |
| 90 | // returns a nullptr, and all transforms of the frag position must be done manually in the |
| 91 | // shader. |
| 92 | const char* fragCoordConventionsExtensionString() const { |
| 93 | return fFragCoordConventionsExtensionString; |
| 94 | } |
| 95 | |
| 96 | // This returns the name of an extension that must be enabled in the shader, if such a thing is |
| 97 | // required in order to use a secondary output in the shader. This returns a nullptr if no such |
| 98 | // extension is required. However, the return value of this function does not say whether dual |
| 99 | // source blending is supported. |
| 100 | const char* secondaryOutputExtensionString() const { |
| 101 | return fSecondaryOutputExtensionString; |
| 102 | } |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 103 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 104 | const char* externalTextureExtensionString() const { |
| 105 | return fExternalTextureExtensionString; |
| 106 | } |
| 107 | |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 108 | /** |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 109 | * Given a texture's config, this determines what swizzle must be appended to accesses to the |
| 110 | * texture in generated shader code. Swizzling may be implemented in texture parameters or a |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 111 | * sampler rather than in the shader. In this case the returned swizzle will always be "rgba". |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 112 | */ |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 113 | const GrSwizzle& configTextureSwizzle(GrPixelConfig config) const { |
| 114 | return fConfigTextureSwizzle[config]; |
| 115 | } |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 116 | |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 117 | /** Swizzle that should occur on the fragment shader outputs for a given config. */ |
| 118 | const GrSwizzle& configOutputSwizzle(GrPixelConfig config) const { |
| 119 | return fConfigOutputSwizzle[config]; |
| 120 | } |
| 121 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 122 | GrGLSLGeneration generation() const { return fGLSLGeneration; } |
| 123 | |
| 124 | /** |
| 125 | * Returns a string containing the caps info. |
| 126 | */ |
| 127 | SkString dump() const override; |
| 128 | |
| 129 | private: |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 130 | void onApplyOptionsOverrides(const GrContextOptions& options) override; |
| 131 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 132 | GrGLSLGeneration fGLSLGeneration; |
| 133 | |
| 134 | bool fDropsTileOnZeroDivide : 1; |
| 135 | bool fFBFetchSupport : 1; |
| 136 | bool fFBFetchNeedsCustomOutput : 1; |
| 137 | bool fBindlessTextureSupport : 1; |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 138 | bool fUsesPrecisionModifiers : 1; |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 139 | bool fCanUseAnyFunctionInShader : 1; |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 140 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 141 | // Used for specific driver bug work arounds |
| 142 | bool fCanUseMinAndAbsTogether : 1; |
| 143 | bool fMustForceNegatedAtanParamToFloat : 1; |
| 144 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 145 | const char* fVersionDeclString; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 146 | |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 147 | const char* fShaderDerivativeExtensionString; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 148 | const char* fFragCoordConventionsExtensionString; |
| 149 | const char* fSecondaryOutputExtensionString; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 150 | const char* fExternalTextureExtensionString; |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 151 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 152 | const char* fFBFetchColorName; |
| 153 | const char* fFBFetchExtensionString; |
| 154 | |
| 155 | AdvBlendEqInteraction fAdvBlendEqInteraction; |
| 156 | |
bsalomon | cdee009 | 2016-01-08 13:20:12 -0800 | [diff] [blame] | 157 | GrSwizzle fConfigTextureSwizzle[kGrPixelConfigCnt]; |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 158 | GrSwizzle fConfigOutputSwizzle[kGrPixelConfigCnt]; |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 159 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 160 | friend class GrGLCaps; // For initialization. |
egdaniel | fa89632 | 2016-01-13 12:19:30 -0800 | [diff] [blame^] | 161 | friend class GrVkCaps; |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 162 | |
| 163 | typedef GrShaderCaps INHERITED; |
| 164 | }; |
| 165 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 166 | #endif |