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

Side by Side Diff: src/gpu/gl/GrGLProgram.h

Issue 611653002: Cleanup of shader building system (Closed) Base URL: https://skia.googlesource.com/skia.git@solo_gp
Patch Set: more cleanup 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 2011 Google Inc. 2 * Copyright 2011 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 8
9 #ifndef GrGLProgram_DEFINED 9 #ifndef GrGLProgram_DEFINED
10 #define GrGLProgram_DEFINED 10 #define GrGLProgram_DEFINED
11 11
12 #include "builders/GrGLProgramBuilder.h" 12 #include "builders/GrGLProgramBuilder.h"
13 #include "builders/GrGLESNvprProgramBuilder.h"
13 #include "GrDrawState.h" 14 #include "GrDrawState.h"
14 #include "GrGLContext.h" 15 #include "GrGLContext.h"
15 #include "GrGLProgramDesc.h" 16 #include "GrGLProgramDesc.h"
16 #include "GrGLSL.h" 17 #include "GrGLSL.h"
17 #include "GrGLTexture.h" 18 #include "GrGLTexture.h"
18 #include "GrGLProgramDataManager.h" 19 #include "GrGLProgramDataManager.h"
19 20
20 #include "SkString.h" 21 #include "SkString.h"
21 #include "SkXfermode.h" 22 #include "SkXfermode.h"
22 23
23 class GrGLProcessor; 24 class GrGLProcessor;
24 class GrGLProgramEffects; 25 class GrGLInstalledProcessors;
25 class GrGLProgramBuilder; 26 class GrGLProgramBuilder;
26 27
27 /** 28 /**
28 * This class manages a GPU program and records per-program information. 29 * This class manages a GPU program and records per-program information.
29 * We can specify the attribute locations so that they are constant 30 * We can specify the attribute locations so that they are constant
30 * across our shaders. But the driver determines the uniform locations 31 * across our shaders. But the driver determines the uniform locations
31 * at link time. We don't need to remember the sampler uniform location 32 * at link time. We don't need to remember the sampler uniform location
32 * because we will bind a texture slot to it and never change it 33 * because we will bind a texture slot to it and never change it
33 * Uniforms are program-local so we can't rely on fHWState to hold the 34 * Uniforms are program-local so we can't rely on fHWState to hold the
34 * previous uniform state after a program change. 35 * previous uniform state after a program change.
35 */ 36 */
36 class GrGLProgram : public SkRefCnt { 37 class GrGLProgram : public SkRefCnt {
37 public: 38 public:
38 SK_DECLARE_INST_COUNT(GrGLProgram) 39 SK_DECLARE_INST_COUNT(GrGLProgram)
39 40
40 typedef GrGLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles; 41 typedef GrGLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles;
41 42
42 static GrGLProgram* Create(GrGpuGL* gpu,
43 const GrGLProgramDesc& desc,
44 const GrGeometryStage* geometryProcessor,
45 const GrFragmentStage* colorStages[],
46 const GrFragmentStage* coverageStages[]);
47
48 virtual ~GrGLProgram(); 43 virtual ~GrGLProgram();
49 44
50 /** 45 /**
51 * Call to abandon GL objects owned by this program. 46 * Call to abandon GL objects owned by this program.
52 */ 47 */
53 void abandon(); 48 void abandon();
54 49
55 const GrGLProgramDesc& getDesc() { return fDesc; } 50 const GrGLProgramDesc& getDesc() { return fDesc; }
56 51
57 /** 52 /**
58 * Gets the GL program ID for this program. 53 * Gets the GL program ID for this program.
59 */ 54 */
60 GrGLuint programID() const { return fProgramID; } 55 GrGLuint programID() const { return fProgramID; }
61 56
62 bool hasVertexShader() const { return fHasVertexShader; } 57 virtual bool hasVertexShader() const = 0;
63 58
64 /** 59 /**
65 * Some GL state that is relevant to programs is not stored per-program. In particular color 60 * Some GL state that is relevant to programs is not stored per-program. In particular color
66 * and coverage attributes can be global state. This struct is read and upda ted by 61 * and coverage attributes can be global state. This struct is read and upda ted by
67 * GrGLProgram::setColor and GrGLProgram::setCoverage to allow us to avoid s etting this state 62 * GrGLProgram::setColor and GrGLProgram::setCoverage to allow us to avoid s etting this state
68 * redundantly. 63 * redundantly.
69 */ 64 */
70 struct SharedGLState { 65 struct SharedGLState {
71 GrColor fConstAttribColor; 66 GrColor fConstAttribColor;
72 int fConstAttribColorIndex; 67 int fConstAttribColorIndex;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 * stages come from GrGLProgramDesc::Build(). 148 * stages come from GrGLProgramDesc::Build().
154 */ 149 */
155 void setData(const GrOptDrawState&, 150 void setData(const GrOptDrawState&,
156 GrGpu::DrawType, 151 GrGpu::DrawType,
157 const GrGeometryStage* geometryProcessor, 152 const GrGeometryStage* geometryProcessor,
158 const GrFragmentStage* colorStages[], 153 const GrFragmentStage* colorStages[],
159 const GrFragmentStage* coverageStages[], 154 const GrFragmentStage* coverageStages[],
160 const GrDeviceCoordTexture* dstCopy, // can be NULL 155 const GrDeviceCoordTexture* dstCopy, // can be NULL
161 SharedGLState*); 156 SharedGLState*);
162 157
163 private: 158 protected:
164 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 159 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
160 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
165 161
166 GrGLProgram(GrGpuGL*, 162 GrGLProgram(GrGpuGL*,
167 const GrGLProgramDesc&, 163 const GrGLProgramDesc&,
168 const GrGLProgramBuilder&); 164 const BuiltinUniformHandles&,
165 GrGLuint programID,
166 const UniformInfoArray&,
167 GrGLInstalledProcessors* geometryProcessor,
168 GrGLInstalledProcessors* colorProcessors,
169 GrGLInstalledProcessors* coverageProcessors);
169 170
170 // Sets the texture units for samplers. 171 // Sets the texture units for samplers.
171 void initSamplerUniforms(); 172 void initSamplerUniforms();
173 void initSamplers(GrGLInstalledProcessors* processors, int* texUnitIdx);
172 174
173 // Helper for setData(). Makes GL calls to specify the initial color when th ere is not 175 // Helper for setData(). Makes GL calls to specify the initial color when th ere is not
174 // per-vertex colors. 176 // per-vertex colors.
175 void setColor(const GrOptDrawState&, GrColor color, SharedGLState*); 177 void setColor(const GrOptDrawState&, GrColor color, SharedGLState*);
176 178
177 // Helper for setData(). Makes GL calls to specify the initial coverage when there is not 179 // Helper for setData(). Makes GL calls to specify the initial coverage when there is not
178 // per-vertex coverages. 180 // per-vertex coverages.
179 void setCoverage(const GrOptDrawState&, GrColor coverage, SharedGLState*); 181 void setCoverage(const GrOptDrawState&, GrColor coverage, SharedGLState*);
180 182
183 virtual void postSetData(GrGpu::DrawType) = 0;
184
185 // A templated helper to loop over effects, set the transforms(via subclass) and bind textures
186 template <class ProcessorStage>
187 void setData(const ProcessorStage* effectStages[],
188 GrGLInstalledProcessors* installedProcessors) {
189 int numEffects = installedProcessors->fGLProcessors.count();
190 SkASSERT(numEffects == installedProcessors->fTransforms.count());
191 SkASSERT(numEffects == installedProcessors->fSamplers.count());
192 for (int e = 0; e < numEffects; ++e) {
193 const GrProcessor& effect = *effectStages[e]->getProcessor();
194 installedProcessors->fGLProcessors[e]->setData(fProgramDataManager, effect);
195 this->setTransformData(*effectStages[e], e, installedProcessors);
196 this->bindTextures(installedProcessors, effect, e);
197 }
198 }
199 virtual void setTransformData(const GrProcessorStage& effectStage,
200 int effectIdx,
201 GrGLInstalledProcessors* pe) = 0;
202 void bindTextures(const GrGLInstalledProcessors*, const GrProcessor&, int ef fectIdx);
203
181 // Helper for setData() that sets the view matrix and loads the render targe t height uniform 204 // Helper for setData() that sets the view matrix and loads the render targe t height uniform
182 void setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, const GrOptDra wState&); 205 void setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, const GrOptDra wState&);
206 virtual void setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
207 const GrOptDrawState& optState ,
208 const GrRenderTarget*,
209 const SkISize&) = 0;
183 210
184 // these reflect the current values of uniforms (GL uniform values travel wi th program) 211 // these reflect the current values of uniforms (GL uniform values travel wi th program)
185 MatrixState fMatrixState; 212 MatrixState fMatrixState;
186 GrColor fColor; 213 GrColor fColor;
187 GrColor fCoverage; 214 GrColor fCoverage;
188 int fDstCopyTexUnit; 215 int fDstCopyTexUnit;
216 BuiltinUniformHandles fBuiltinUniformHandles;
217 GrGLuint fProgramID;
189 218
190 BuiltinUniformHandles fBuiltinUniformHandles; 219 // the installed effects
191 SkAutoTUnref<GrGLProgramEffects> fGeometryProcessor; 220 SkAutoTUnref<GrGLInstalledProcessors> fGeometryProcessor;
bsalomon 2014/09/29 15:43:19 Let's either line up all the members or none of th
joshua.litt 2014/09/29 21:05:22 done
192 SkAutoTUnref<GrGLProgramEffects> fColorEffects; 221 SkAutoTUnref<GrGLInstalledProcessors> fColorEffects;
193 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; 222 SkAutoTUnref<GrGLInstalledProcessors> fCoverageEffects;
194 GrGLuint fProgramID;
195 bool fHasVertexShader;
196 int fTexCoordSetCnt;
197 223
198 GrGLProgramDesc fDesc; 224 GrGLProgramDesc fDesc;
199 GrGpuGL* fGpu; 225 GrGpuGL* fGpu;
200 226 GrGLProgramDataManager fProgramDataManager;
201 GrGLProgramDataManager fProgramDataManager;
202 227
203 typedef SkRefCnt INHERITED; 228 typedef SkRefCnt INHERITED;
204 }; 229 };
205 230
231 /*
232 * Below are slight specializations of the program object for the different type s of programs Skia
233 * supports. Skia programs consist of at the very least a vertex and fragment s hader. Old school
234 * Nvpr only has a fragment shader, NvprES ignores the vertex shader, but both r equire specialized
bsalomon 2014/09/29 15:43:19 Can we say NVPR 1.3+ rather than NvprES since the
joshua.litt 2014/09/29 21:05:22 done
235 * methods for setting transform data.
236 */
237 class GrGLSkiaProgram : public GrGLProgram {
238 public:
239 virtual bool hasVertexShader() const SK_OVERRIDE { return true; }
240
241 private:
242 GrGLSkiaProgram(GrGpuGL*,
243 const GrGLProgramDesc&,
244 const BuiltinUniformHandles&,
245 GrGLuint programID,
246 const UniformInfoArray&,
247 GrGLInstalledProcessors* geometryProcessor,
248 GrGLInstalledProcessors* colorProcessors,
249 GrGLInstalledProcessors* coverageProcessors);
250
251 virtual void postSetData(GrGpu::DrawType) SK_OVERRIDE;
252 virtual void setTransformData(const GrProcessorStage&,
253 int effectIdx,
254 GrGLInstalledProcessors*) SK_OVERRIDE;
255 virtual void setMatrixAndRenderTargetHeight(GrGpu::DrawType,
256 const GrOptDrawState&,
257 const GrRenderTarget*,
258 const SkISize&) SK_OVERRIDE;
259
260 friend class GrGLSkiaProgramBuilder;
261
262 typedef GrGLProgram INHERITED;
263 };
264
265 /*
266 * Both types of NVPR require setting the projection matrix through a special fu nction call
267 */
268 class GrGLNvprProgramBase : public GrGLProgram {
269 protected:
270 GrGLNvprProgramBase(GrGpuGL*,
271 const GrGLProgramDesc&,
272 const BuiltinUniformHandles&,
273 GrGLuint programID,
274 const UniformInfoArray&,
275 GrGLInstalledProcessors* colorProcessors,
276 GrGLInstalledProcessors* coverageProcessors);
277 virtual void setMatrixAndRenderTargetHeight(GrGpu::DrawType,
278 const GrOptDrawState&,
279 const GrRenderTarget*,
280 const SkISize&);
281
282 typedef GrGLProgram INHERITED;
283 };
284
285 class GrGLESNvprProgram : public GrGLNvprProgramBase {
286 public:
287 virtual bool hasVertexShader() const SK_OVERRIDE { return true; }
288
289 private:
290 typedef GrGLESNvprProgramBuilder::SeparableVaryingInfo SeparableVaryingInfo;
291 typedef GrGLESNvprProgramBuilder::SeparableVaryingInfoArray SeparableVarying InfoArray;
292 GrGLESNvprProgram(GrGpuGL*,
293 const GrGLProgramDesc&,
294 const BuiltinUniformHandles&,
295 GrGLuint programID,
296 const UniformInfoArray&,
297 GrGLInstalledProcessors* colorProcessors,
298 GrGLInstalledProcessors* coverageProcessors,
299 const SeparableVaryingInfoArray& separableVaryings);
300 virtual void postSetData(GrGpu::DrawType) SK_OVERRIDE;
301 virtual void setTransformData(const GrProcessorStage&,
302 int effectIdx,
303 GrGLInstalledProcessors*) SK_OVERRIDE;
304
305 struct Varying {
306 GrGLint fLocation;
307 SkDEBUGCODE(
308 GrSLType fType;
309 );
310 };
311 SkTArray<Varying, true> fVaryings;
312
313 friend class GrGLESNvprProgramBuilder;
314
315 typedef GrGLNvprProgramBase INHERITED;
316 };
317
318 class GrGLNvprProgram : public GrGLNvprProgramBase {
319 public:
320 virtual bool hasVertexShader() const SK_OVERRIDE { return false; }
321
322 private:
323 GrGLNvprProgram(GrGpuGL* gpu,
324 const GrGLProgramDesc& desc,
325 const BuiltinUniformHandles&,
326 GrGLuint programID,
327 const UniformInfoArray&,
328 GrGLInstalledProcessors* colorProcessors,
329 GrGLInstalledProcessors* coverageProcessors,
330 int texCoordSetCnt);
331 virtual void postSetData(GrGpu::DrawType) SK_OVERRIDE;
332 virtual void setTransformData(const GrProcessorStage&,
333 int effectIdx,
334 GrGLInstalledProcessors*) SK_OVERRIDE;
335
336 int fTexCoordSetCnt;
337
338 friend class GrGLNvprProgramBuilder;
339
340 typedef GrGLNvprProgramBase INHERITED;
341 };
342
206 #endif 343 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698