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

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

Issue 367643004: Implement NVPR on GLES (Closed) Base URL: https://skia.googlesource.com/skia.git@02-path-program-fragment
Patch Set: rebse Created 6 years, 3 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
« no previous file with comments | « src/gpu/gl/GrGpuGL_program.cpp ('k') | src/gpu/gl/builders/GrGLProgramBuilder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 GrGLProgramBuilder_DEFINED 8 #ifndef GrGLProgramBuilder_DEFINED
9 #define GrGLProgramBuilder_DEFINED 9 #define GrGLProgramBuilder_DEFINED
10 10
(...skipping 22 matching lines...) Expand all
33 */ 33 */
34 class GrGLProgramBuilder { 34 class GrGLProgramBuilder {
35 public: 35 public:
36 enum ShaderVisibility { 36 enum ShaderVisibility {
37 kVertex_Visibility = 0x1, 37 kVertex_Visibility = 0x1,
38 kGeometry_Visibility = 0x2, 38 kGeometry_Visibility = 0x2,
39 kFragment_Visibility = 0x4, 39 kFragment_Visibility = 0x4,
40 }; 40 };
41 41
42 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 42 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
43 typedef GrGLProgramDataManager::VaryingHandle VaryingHandle;
43 44
44 // Handles for program uniforms (other than per-effect uniforms) 45 // Handles for program uniforms (other than per-effect uniforms)
45 struct BuiltinUniformHandles { 46 struct BuiltinUniformHandles {
46 UniformHandle fViewMatrixUni; 47 UniformHandle fViewMatrixUni;
47 UniformHandle fRTAdjustmentUni; 48 UniformHandle fRTAdjustmentUni;
48 UniformHandle fColorUni; 49 UniformHandle fColorUni;
49 UniformHandle fCoverageUni; 50 UniformHandle fCoverageUni;
50 51
51 // We use the render target height to provide a y-down frag coord when s pecifying 52 // We use the render target height to provide a y-down frag coord when s pecifying
52 // origin_upper_left is not supported. 53 // origin_upper_left is not supported.
53 UniformHandle fRTHeightUni; 54 UniformHandle fRTHeightUni;
54 55
55 // Uniforms for computing texture coords to do the dst-copy lookup 56 // Uniforms for computing texture coords to do the dst-copy lookup
56 UniformHandle fDstCopyTopLeftUni; 57 UniformHandle fDstCopyTopLeftUni;
57 UniformHandle fDstCopyScaleUni; 58 UniformHandle fDstCopyScaleUni;
58 UniformHandle fDstCopySamplerUni; 59 UniformHandle fDstCopySamplerUni;
59 }; 60 };
60 61
61 struct UniformInfo { 62 struct UniformInfo {
62 GrGLShaderVar fVariable; 63 GrGLShaderVar fVariable;
63 uint32_t fVisibility; 64 uint32_t fVisibility;
64 GrGLint fLocation; 65 GrGLint fLocation;
65 }; 66 };
66 67
67 // This uses an allocator rather than array so that the GrGLShaderVars don't move in memory 68 // This uses an allocator rather than array so that the GrGLShaderVars don't move in memory
68 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their 69 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
69 // name strings. Otherwise, we'd have to hand out copies. 70 // name strings. Otherwise, we'd have to hand out copies.
70 typedef GrTAllocator<UniformInfo> UniformInfoArray; 71 typedef GrTAllocator<UniformInfo> UniformInfoArray;
71 72
73 struct SeparableVaryingInfo {
74 GrGLShaderVar fVariable;
75 GrGLint fLocation;
76 };
77
78 typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray;
79
72 /** Generates a shader program. 80 /** Generates a shader program.
73 * 81 *
74 * The program implements what is specified in the stages given as input. 82 * The program implements what is specified in the stages given as input.
75 * After successful generation, the builder result objects are available 83 * After successful generation, the builder result objects are available
76 * to be used. 84 * to be used.
77 * @return true if generation was successful. 85 * @return true if generation was successful.
78 */ 86 */
79 bool genProgram(const GrEffectStage* inColorStages[], 87 bool genProgram(const GrEffectStage* inColorStages[],
80 const GrEffectStage* inCoverageStages[]); 88 const GrEffectStage* inCoverageStages[]);
81 89
82 // Below are the results of the shader generation. 90 // Below are the results of the shader generation.
83 91
84 GrGLProgramEffects* getColorEffects() const { SkASSERT(fProgramID); return f ColorEffects.get(); } 92 GrGLProgramEffects* getColorEffects() const { SkASSERT(fProgramID); return f ColorEffects.get(); }
85 GrGLProgramEffects* getCoverageEffects() const { SkASSERT(fProgramID); retur n fCoverageEffects.get(); } 93 GrGLProgramEffects* getCoverageEffects() const { SkASSERT(fProgramID); retur n fCoverageEffects.get(); }
86 const BuiltinUniformHandles& getBuiltinUniformHandles() const { 94 const BuiltinUniformHandles& getBuiltinUniformHandles() const {
87 SkASSERT(fProgramID); 95 SkASSERT(fProgramID);
88 return fUniformHandles; 96 return fUniformHandles;
89 } 97 }
90 GrGLuint getProgramID() const { SkASSERT(fProgramID); return fProgramID; } 98 GrGLuint getProgramID() const { SkASSERT(fProgramID); return fProgramID; }
91 bool hasVertexShader() const { SkASSERT(fProgramID); return !fFragOnly; } 99 bool hasVertexShader() const { SkASSERT(fProgramID); return !fFragOnly; }
92 int getTexCoordSetCount() const { SkASSERT(fProgramID); return fTexCoordSetC nt; } 100 int getTexCoordSetCount() const { SkASSERT(fProgramID); return fTexCoordSetC nt; }
93 const UniformInfoArray& getUniformInfos() const { return fUniforms; } 101 const UniformInfoArray& getUniformInfos() const { return fUniforms; }
102 const SeparableVaryingInfoArray& getSeparableVaryingInfos() const {
103 return fSeparableVaryingInfos;
104 }
94 105
95 virtual ~GrGLProgramBuilder() {} 106 virtual ~GrGLProgramBuilder() {}
96 107
97 /** Add a uniform variable to the current program, that has visibility in on e or more shaders. 108 /** Add a uniform variable to the current program, that has visibility in on e or more shaders.
98 visibility is a bitfield of ShaderVisibility values indicating from whic h shaders the 109 visibility is a bitfield of ShaderVisibility values indicating from whic h shaders the
99 uniform should be accessible. At least one bit must be set. Geometry sha der uniforms are not 110 uniform should be accessible. At least one bit must be set. Geometry sha der uniforms are not
100 supported at this time. The actual uniform name will be mangled. If outN ame is not NULL then 111 supported at this time. The actual uniform name will be mangled. If outN ame is not NULL then
101 it will refer to the final uniform name after return. Use the addUniform Array variant to add 112 it will refer to the final uniform name after return. Use the addUniform Array variant to add
102 an array of uniforms. */ 113 an array of uniforms. */
103 GrGLProgramDataManager::UniformHandle addUniform(uint32_t visibility, 114 GrGLProgramDataManager::UniformHandle addUniform(uint32_t visibility,
(...skipping 15 matching lines...) Expand all
119 /** 130 /**
120 * Shortcut for getUniformVariable(u).c_str() 131 * Shortcut for getUniformVariable(u).c_str()
121 */ 132 */
122 const char* getUniformCStr(GrGLProgramDataManager::UniformHandle u) const { 133 const char* getUniformCStr(GrGLProgramDataManager::UniformHandle u) const {
123 return this->getUniformVariable(u).c_str(); 134 return this->getUniformVariable(u).c_str();
124 } 135 }
125 136
126 const GrGLContextInfo& ctxInfo() const; 137 const GrGLContextInfo& ctxInfo() const;
127 138
128 GrGLFragmentShaderBuilder* getFragmentShaderBuilder() { return &fFS; } 139 GrGLFragmentShaderBuilder* getFragmentShaderBuilder() { return &fFS; }
140 GrGpuGL* gpu() const { return fGpu; }
129 141
130 protected: 142 protected:
131 typedef GrTAllocator<GrGLShaderVar> VarArray; 143 typedef GrTAllocator<GrGLShaderVar> VarArray;
132 GrGLProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); 144 GrGLProgramBuilder(GrGpuGL*, const GrGLProgramDesc&);
133 145
134 GrGpuGL* gpu() const { return fGpu; }
135
136 const GrGLProgramDesc& desc() const { return fDesc; } 146 const GrGLProgramDesc& desc() const { return fDesc; }
137 147
138 // Helper for emitEffects(). 148 // Helper for emitEffects().
139 void createAndEmitEffects(GrGLProgramEffectsBuilder*, 149 void createAndEmitEffects(GrGLProgramEffectsBuilder*,
140 const GrEffectStage* effectStages[], 150 const GrEffectStage* effectStages[],
141 int effectCnt, 151 int effectCnt,
142 const GrGLProgramDesc::EffectKeyProvider&, 152 const GrGLProgramDesc::EffectKeyProvider&,
143 GrGLSLExpr4* inOutFSColor); 153 GrGLSLExpr4* inOutFSColor);
144 154
145 // Generates a name for a variable. The generated string will be name prefix ed by the prefix 155 // Generates a name for a variable. The generated string will be name prefix ed by the prefix
146 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp ecific if we're 156 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp ecific if we're
147 // generating stage code. 157 // generating stage code.
148 void nameVariable(SkString* out, char prefix, const char* name); 158 void nameVariable(SkString* out, char prefix, const char* name);
149 159
150 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint> * shaderIds) const; 160 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint> * shaderIds) const;
151 161
152 virtual void bindProgramLocations(GrGLuint programId); 162 virtual void bindProgramLocations(GrGLuint programId);
153 void resolveProgramLocations(GrGLuint programId); 163 void resolveProgramLocations(GrGLuint programId);
154 164
155 void appendDecls(const VarArray&, SkString*) const; 165 void appendDecls(const VarArray&, SkString*) const;
156 void appendUniformDecls(ShaderVisibility, SkString*) const; 166 void appendUniformDecls(ShaderVisibility, SkString*) const;
157 167
158 SkAutoTUnref<GrGLProgramEffects> fColorEffects; 168 SkAutoTUnref<GrGLProgramEffects> fColorEffects;
159 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; 169 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects;
160 BuiltinUniformHandles fUniformHandles; 170 BuiltinUniformHandles fUniformHandles;
161 bool fFragOnly; 171 bool fFragOnly;
162 int fTexCoordSetCnt; 172 int fTexCoordSetCnt;
163 GrGLuint fProgramID; 173 GrGLuint fProgramID;
164 GrGLFragmentShaderBuilder fFS; 174 GrGLFragmentShaderBuilder fFS;
175 SeparableVaryingInfoArray fSeparableVaryingInfos;
165 private: 176 private:
166 class CodeStage : SkNoncopyable { 177 class CodeStage : SkNoncopyable {
167 public: 178 public:
168 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} 179 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {}
169 180
170 bool inStageCode() const { 181 bool inStageCode() const {
171 this->validate(); 182 this->validate();
172 return NULL != fEffectStage; 183 return NULL != fEffectStage;
173 } 184 }
174 185
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 GrGLFullProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); 275 GrGLFullProgramBuilder(GrGpuGL*, const GrGLProgramDesc&);
265 276
266 /** Add a varying variable to the current program to pass values between vert ex and fragment 277 /** Add a varying variable to the current program to pass values between vert ex and fragment
267 shaders. If the last two parameters are non-NULL, they are filled in wit h the name 278 shaders. If the last two parameters are non-NULL, they are filled in wit h the name
268 generated. */ 279 generated. */
269 void addVarying(GrSLType type, 280 void addVarying(GrSLType type,
270 const char* name, 281 const char* name,
271 const char** vsOutName = NULL, 282 const char** vsOutName = NULL,
272 const char** fsInName = NULL); 283 const char** fsInName = NULL);
273 284
285 /** Add a separable varying input variable to the current program.
286 * A separable varying (fragment shader input) is a varying that can be used also when vertex
287 * shaders are not used. With a vertex shader, the operation is same as with other
288 * varyings. Without a vertex shader, such as with NV_path_rendering, GL API s are used to
289 * populate the variable. The APIs can refer to the variable through the ret urned handle.
290 */
291 VaryingHandle addSeparableVarying(GrSLType type,
292 const char* name,
293 const char** vsOutName,
294 const char** fsInName);
295
joshua.litt 2014/08/25 17:00:05 Since this only requires a fragment shader, does i
Chris Dalton 2014/08/25 18:04:50 It actually does require a vertex shader. Not for
274 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } 296 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; }
275 297
276 private: 298 private:
277 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage ) SK_OVERRIDE; 299 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage ) SK_OVERRIDE;
278 300
279 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect Stages[], 301 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect Stages[],
280 int effectCnt, 302 int effectCnt,
281 const GrGLProgramDesc::Effe ctKeyProvider&, 303 const GrGLProgramDesc::Effe ctKeyProvider&,
282 GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; 304 GrGLSLExpr4* inOutFSColor) SK_OVERRIDE;
283 305
(...skipping 25 matching lines...) Expand all
309 int effectCnt, 331 int effectCnt,
310 const GrGLProgramDesc::Effe ctKeyProvider&, 332 const GrGLProgramDesc::Effe ctKeyProvider&,
311 GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; 333 GrGLSLExpr4* inOutFSColor) SK_OVERRIDE;
312 334
313 virtual void emitCodeAfterEffects() SK_OVERRIDE {} 335 virtual void emitCodeAfterEffects() SK_OVERRIDE {}
314 336
315 typedef GrGLProgramBuilder INHERITED; 337 typedef GrGLProgramBuilder INHERITED;
316 }; 338 };
317 339
318 #endif 340 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL_program.cpp ('k') | src/gpu/gl/builders/GrGLProgramBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698