Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: src/gpu/gl/builders/GrGLFragmentShaderBuilder.h

Issue 611653002: Cleanup of shader building system (Closed) Base URL: https://skia.googlesource.com/skia.git@solo_gp
Patch Set: name changes Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGLFragmentShaderBuilder_DEFINED 8 #ifndef GrGLFragmentShaderBuilder_DEFINED
9 #define GrGLFragmentShaderBuilder_DEFINED 9 #define GrGLFragmentShaderBuilder_DEFINED
10
10 #include "GrGLShaderBuilder.h" 11 #include "GrGLShaderBuilder.h"
11 12
12 class GrGLProgramBuilder;
13
14 /* 13 /*
15 * This base class encapsulates the functionality which all GrProcessors are all owed to use in their 14 * This base class encapsulates the functionality which the GP uses to build fra gment shaders
16 * fragment shader
17 */ 15 */
18 class GrGLProcessorFragmentShaderBuilder : public GrGLShaderBuilder { 16 class GrGLGPFragmentShaderBuilder : public GrGLShaderBuilder {
19 public: 17 public:
20 GrGLProcessorFragmentShaderBuilder(GrGLProgramBuilder* program) : INHERITED( program) {} 18 GrGLGPFragmentShaderBuilder(GrGLProgramBuilder* program) : INHERITED(program ) {}
21 virtual ~GrGLProcessorFragmentShaderBuilder() {} 19 virtual ~GrGLGPFragmentShaderBuilder() {}
22 /** 20 /**
23 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile 21 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile
24 * if code is added that uses one of these features without calling enableFe ature() 22 * if code is added that uses one of these features without calling enableFe ature()
25 */ 23 */
26 enum GLSLFeature { 24 enum GLSLFeature {
27 kStandardDerivatives_GLSLFeature = 0, 25 kStandardDerivatives_GLSLFeature = 0,
28 kLastGLSLFeature = kStandardDerivatives_GLSLFeature 26 kLastGLSLFeature = kStandardDerivatives_GLSLFeature
29 }; 27 };
30 28
31 /** 29 /**
(...skipping 14 matching lines...) Expand all
46 /** Returns a variable name that represents the position of the fragment in the FS. The position 44 /** Returns a variable name that represents the position of the fragment in the FS. The position
47 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */ 45 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */
48 virtual const char* fragmentPosition() = 0; 46 virtual const char* fragmentPosition() = 0;
49 47
50 private: 48 private:
51 typedef GrGLShaderBuilder INHERITED; 49 typedef GrGLShaderBuilder INHERITED;
52 }; 50 };
53 51
54 /* 52 /*
55 * Fragment processor's, in addition to all of the above, may need to use dst co lor so they use 53 * Fragment processor's, in addition to all of the above, may need to use dst co lor so they use
56 * this builder to create their shader 54 * this builder to create their shader. Because this is the only shader builder the FP sees, we
55 * just call it FPShaderBuilder
57 */ 56 */
58 class GrGLFragmentProcessorShaderBuilder : public GrGLProcessorFragmentShaderBui lder { 57 class GrGLFPShaderBuilder : public GrGLGPFragmentShaderBuilder {
59 public: 58 public:
60 GrGLFragmentProcessorShaderBuilder(GrGLProgramBuilder* program) : INHERITED( program) {} 59 GrGLFPShaderBuilder(GrGLProgramBuilder* program) : INHERITED(program) {}
60
61 /** Returns the variable name that holds the color of the destination pixel. This may be NULL if 61 /** Returns the variable name that holds the color of the destination pixel. This may be NULL if
62 no effect advertised that it will read the destination. */ 62 no effect advertised that it will read the destination. */
63 virtual const char* dstColor() = 0; 63 virtual const char* dstColor() = 0;
64 64
65 private: 65 private:
66 typedef GrGLProcessorFragmentShaderBuilder INHERITED; 66 typedef GrGLGPFragmentShaderBuilder INHERITED;
67 }; 67 };
68 68
69 class GrGLFragmentShaderBuilder : public GrGLFragmentProcessorShaderBuilder { 69 class GrGLFragmentShaderBuilder : public GrGLFPShaderBuilder {
70 public: 70 public:
71 typedef uint8_t DstReadKey; 71 typedef uint8_t DstReadKey;
72 typedef uint8_t FragPosKey; 72 typedef uint8_t FragPosKey;
73 73
74 /** Returns a key for adding code to read the copy-of-dst color in service of effects that 74 /** Returns a key for adding code to read the copy-of-dst color in service of effects that
75 require reading the dst. It must not return 0 because 0 indicates that t here is no dst 75 require reading the dst. It must not return 0 because 0 indicates that t here is no dst
76 copy read at all (in which case this function should not be called). */ 76 copy read at all (in which case this function should not be called). */
77 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&); 77 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&);
78 78
79 /** Returns a key for reading the fragment location. This should only be cal led if there is an 79 /** Returns a key for reading the fragment location. This should only be cal led if there is an
80 effect that will requires the fragment position. If the fragment position is not required, 80 effect that will requires the fragment position. If the fragment position is not required,
81 the key is 0. */ 81 the key is 0. */
82 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst, const Gr GLCaps&); 82 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst, const Gr GLCaps&);
83 83
84 GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, const GrGLProgramDesc & desc); 84 GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, const GrGLProgramDesc & desc);
85 85
86 // true public interface, defined explicitly in the abstract interfaces abov e
87 virtual bool enableFeature(GLSLFeature) SK_OVERRIDE;
88 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra y& coords,
89 int index) SK_OVERRIDE;
90 virtual const char* fragmentPosition() SK_OVERRIDE;
86 virtual const char* dstColor() SK_OVERRIDE; 91 virtual const char* dstColor() SK_OVERRIDE;
87 92
88 virtual bool enableFeature(GLSLFeature) SK_OVERRIDE; 93 // Private public interface, used by GrGLProgramBuilder to build a fragment shader
94 void emitCodeToReadDstTexture();
95 void enableCustomOutput();
96 void enableSecondaryOutput();
97 const char* getPrimaryColorOutputName() const;
98 const char* getSecondaryColorOutputName() const;
99 void enableSecondaryOutput(const GrGLSLExpr4& inputColor, const GrGLSLExpr4& inputCoverage);
100 void combineColorAndCoverage(const GrGLSLExpr4& inputColor, const GrGLSLExpr 4& inputCoverage);
101 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader Ids) const;
102 void bindFragmentShaderLocations(GrGLuint programID);
89 103
90 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra y& coords,
91 int index) SK_OVERRIDE;
92
93 virtual const char* fragmentPosition() SK_OVERRIDE;
94
95 private:
96 /* 104 /*
97 * An internal call for GrGLFullProgramBuilder to use to add varyings to the vertex shader 105 * An internal call for GrGLProgramBuilder to use to add varyings to the ver tex shader
98 */ 106 */
99 void addVarying(GrSLType type, 107 void addVarying(GrSLType type,
100 const char* name, 108 const char* name,
101 const char** fsInName, 109 const char** fsInName,
102 GrGLShaderVar::Precision fsPrecision = GrGLShaderVar::kDefaul t_Precision); 110 GrGLShaderVar::Precision fsPrecision = GrGLShaderVar::kDefaul t_Precision);
103 111
104 /* 112 // As GLProcessors emit code, there are some conditions we need to verify. We use the below
105 * Private functions used by GrGLProgramBuilder for compilation 113 // state to track this. The reset call is called per processor emitted.
106 */ 114 bool hasReadDstColor() const { return fHasReadDstColor; }
107 void bindProgramLocations(GrGLuint programId); 115 bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; }
108 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader Ids) const; 116 void reset() {
109 void emitCodeBeforeEffects(); 117 fHasReadDstColor = false;
110 void emitCodeAfterEffects(const GrGLSLExpr4& inputColor, const GrGLSLExpr4& inputCoverage); 118 fHasReadFragmentPosition = false;
119 }
111 120
112 /** Enables using the secondary color output and returns the name of the var in which it is 121 private:
113 to be stored */
114 const char* enableSecondaryOutput();
115
116 /** Gets the name of the primary color output. */
117 const char* getColorOutputName() const;
118
119 /** 122 /**
120 * Features that should only be enabled by GrGLFragmentShaderBuilder itself. 123 * Features that should only be enabled by GrGLFragmentShaderBuilder itself.
121 */ 124 */
122 enum GLSLPrivateFeature { 125 enum GLSLPrivateFeature {
123 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, 126 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1,
124 kLastGLSLPrivateFeature = kFragCoordConventions_GLSLPrivateFeature 127 kLastGLSLPrivateFeature = kFragCoordConventions_GLSLPrivateFeature
125 }; 128 };
126 129
127 // Interpretation of DstReadKey when generating code 130 // Interpretation of DstReadKey when generating code
128 enum { 131 enum {
129 kNoDstRead_DstReadKey = 0, 132 kNoDstRead_DstReadKey = 0,
130 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. 133 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read.
131 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alph a only. 134 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alph a only.
132 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top- left. 135 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top- left.
133 }; 136 };
134 137
138 // Interpretation of FragPosKey when generating code
135 enum { 139 enum {
136 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil l not be needed. 140 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil l not be needed.
137 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t op-left. 141 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t op-left.
138 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b ottom-left. 142 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b ottom-left.
139 }; 143 };
140 144
145 static const char* kDstCopyColorName;
146
141 bool fHasCustomColorOutput; 147 bool fHasCustomColorOutput;
142 bool fHasSecondaryOutput; 148 bool fHasSecondaryOutput;
143 bool fSetupFragPosition; 149 bool fSetupFragPosition;
144 bool fTopLeftFragPosRead; 150 bool fTopLeftFragPosRead;
145 151
152 // some state to verify shaders and effects are consistent, this is reset be tween effects by
153 // the program creator
154 bool fHasReadDstColor;
155 bool fHasReadFragmentPosition;
156
157 friend class GrGLNvprProgramBuilder;
146 friend class GrGLProgramBuilder; 158 friend class GrGLProgramBuilder;
147 friend class GrGLFullProgramBuilder;
148 159
149 typedef GrGLFragmentProcessorShaderBuilder INHERITED; 160 typedef GrGLFPShaderBuilder INHERITED;
150 }; 161 };
151 162
152 #endif 163 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698