blob: 060539645e23369d3e5e6aae2079b0f9702aa71e [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
9#ifndef GrGLSLCaps_DEFINED
10#define GrGLSLCaps_DEFINED
11
12#include "GrCaps.h"
13#include "GrGLSL.h"
bsalomoncdee0092016-01-08 13:20:12 -080014#include "GrSwizzle.h"
jvanverthcba99b82015-06-24 06:59:57 -070015
16class GrGLSLCaps : public GrShaderCaps {
17public:
mtklein2766c002015-06-26 11:45:03 -070018
jvanverthcba99b82015-06-24 06:59:57 -070019
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
egdaniel472d44e2015-10-22 08:20:00 -070049 const char* versionDeclString() const { return fVersionDeclString; }
50
jvanverthcba99b82015-06-24 06:59:57 -070051 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
egdanielf5294392015-10-21 07:14:17 -070071 bool usesPrecisionModifiers() const { return fUsesPrecisionModifiers; }
72
egdaniel472d44e2015-10-22 08:20:00 -070073 // Returns whether we can use the glsl funciton any() in our shader code.
74 bool canUseAnyFunctionInShader() const { return fCanUseAnyFunctionInShader; }
75
egdaniel8dcdedc2015-11-11 06:27:20 -080076 bool canUseMinAndAbsTogether() const { return fCanUseMinAndAbsTogether; }
77
78 bool mustForceNegatedAtanParamToFloat() const { return fMustForceNegatedAtanParamToFloat; }
79
egdaniel574a4c12015-11-02 06:22:44 -080080 // 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 }
egdaniel8dcdedc2015-11-11 06:27:20 -080087
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 }
egdaniel574a4c12015-11-02 06:22:44 -0800103
bsalomon7ea33f52015-11-22 14:51:00 -0800104 const char* externalTextureExtensionString() const {
105 return fExternalTextureExtensionString;
106 }
107
egdanielb7e7d572015-11-04 04:23:53 -0800108 /**
bsalomoncdee0092016-01-08 13:20:12 -0800109 * 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
bsalomon7f9b2e42016-01-12 13:29:26 -0800111 * sampler rather than in the shader. In this case the returned swizzle will always be "rgba".
egdanielb7e7d572015-11-04 04:23:53 -0800112 */
bsalomoncdee0092016-01-08 13:20:12 -0800113 const GrSwizzle& configTextureSwizzle(GrPixelConfig config) const {
114 return fConfigTextureSwizzle[config];
115 }
egdanielb7e7d572015-11-04 04:23:53 -0800116
bsalomon7f9b2e42016-01-12 13:29:26 -0800117 /** 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
jvanverthcba99b82015-06-24 06:59:57 -0700122 GrGLSLGeneration generation() const { return fGLSLGeneration; }
123
124 /**
125 * Returns a string containing the caps info.
126 */
127 SkString dump() const override;
128
129private:
egdanielb7e7d572015-11-04 04:23:53 -0800130 void onApplyOptionsOverrides(const GrContextOptions& options) override;
131
jvanverthcba99b82015-06-24 06:59:57 -0700132 GrGLSLGeneration fGLSLGeneration;
133
134 bool fDropsTileOnZeroDivide : 1;
135 bool fFBFetchSupport : 1;
136 bool fFBFetchNeedsCustomOutput : 1;
137 bool fBindlessTextureSupport : 1;
egdanielf5294392015-10-21 07:14:17 -0700138 bool fUsesPrecisionModifiers : 1;
egdaniel472d44e2015-10-22 08:20:00 -0700139 bool fCanUseAnyFunctionInShader : 1;
egdanielf5294392015-10-21 07:14:17 -0700140
egdaniel8dcdedc2015-11-11 06:27:20 -0800141 // Used for specific driver bug work arounds
142 bool fCanUseMinAndAbsTogether : 1;
143 bool fMustForceNegatedAtanParamToFloat : 1;
144
egdaniel472d44e2015-10-22 08:20:00 -0700145 const char* fVersionDeclString;
jvanverthcba99b82015-06-24 06:59:57 -0700146
egdaniel574a4c12015-11-02 06:22:44 -0800147 const char* fShaderDerivativeExtensionString;
egdaniel8dcdedc2015-11-11 06:27:20 -0800148 const char* fFragCoordConventionsExtensionString;
149 const char* fSecondaryOutputExtensionString;
bsalomon7ea33f52015-11-22 14:51:00 -0800150 const char* fExternalTextureExtensionString;
egdaniel574a4c12015-11-02 06:22:44 -0800151
jvanverthcba99b82015-06-24 06:59:57 -0700152 const char* fFBFetchColorName;
153 const char* fFBFetchExtensionString;
154
155 AdvBlendEqInteraction fAdvBlendEqInteraction;
156
bsalomoncdee0092016-01-08 13:20:12 -0800157 GrSwizzle fConfigTextureSwizzle[kGrPixelConfigCnt];
bsalomon7f9b2e42016-01-12 13:29:26 -0800158 GrSwizzle fConfigOutputSwizzle[kGrPixelConfigCnt];
egdanielb7e7d572015-11-04 04:23:53 -0800159
jvanverthcba99b82015-06-24 06:59:57 -0700160 friend class GrGLCaps; // For initialization.
egdanielfa896322016-01-13 12:19:30 -0800161 friend class GrVkCaps;
jvanverthcba99b82015-06-24 06:59:57 -0700162
163 typedef GrShaderCaps INHERITED;
164};
165
jvanverthcba99b82015-06-24 06:59:57 -0700166#endif