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

Side by Side Diff: src/gpu/glsl/GrGLSLProgramBuilder.h

Issue 1535603006: Move some program building utils from GL to GLSL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebased Created 4 years, 11 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 2015 Google Inc. 2 * Copyright 2015 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 GrGLSLProgramBuilder_DEFINED 8 #ifndef GrGLSLProgramBuilder_DEFINED
9 #define GrGLSLProgramBuilder_DEFINED 9 #define GrGLSLProgramBuilder_DEFINED
10 10
11 #include "GrGeometryProcessor.h" 11 #include "GrGeometryProcessor.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "glsl/GrGLSLFragmentShaderBuilder.h" 13 #include "glsl/GrGLSLFragmentShaderBuilder.h"
14 #include "glsl/GrGLSLGeometryShaderBuilder.h" 14 #include "glsl/GrGLSLGeometryShaderBuilder.h"
15 #include "glsl/GrGLSLPrimitiveProcessor.h"
15 #include "glsl/GrGLSLProgramDataManager.h" 16 #include "glsl/GrGLSLProgramDataManager.h"
16 #include "glsl/GrGLSLUniformHandler.h" 17 #include "glsl/GrGLSLUniformHandler.h"
18 #include "glsl/GrGLSLTextureSampler.h"
17 #include "glsl/GrGLSLVertexShaderBuilder.h" 19 #include "glsl/GrGLSLVertexShaderBuilder.h"
20 #include "glsl/GrGLSLXferProcessor.h"
18 21
19 class GrGLSLCaps; 22 class GrGLSLCaps;
20 class GrGLSLShaderVar; 23 class GrGLSLShaderVar;
21 class GrGLSLVaryingHandler; 24 class GrGLSLVaryingHandler;
22 25
26 typedef SkSTArray<8, GrGLSLFragmentProcessor*, true> GrGLSLFragProcs;
27
23 class GrGLSLProgramBuilder { 28 class GrGLSLProgramBuilder {
24 public: 29 public:
25 typedef GrGpu::DrawArgs DrawArgs; 30 typedef GrGpu::DrawArgs DrawArgs;
26 typedef GrGLSLUniformHandler::ShaderVisibility ShaderVisibility; 31 typedef GrGLSLUniformHandler::ShaderVisibility ShaderVisibility;
27 typedef GrGLSLUniformHandler::UniformHandle UniformHandle; 32 typedef GrGLSLUniformHandler::UniformHandle UniformHandle;
28 33
29 virtual ~GrGLSLProgramBuilder() {} 34 virtual ~GrGLSLProgramBuilder() {}
30 35
36 virtual const GrCaps* caps() const = 0;
31 virtual const GrGLSLCaps* glslCaps() const = 0; 37 virtual const GrGLSLCaps* glslCaps() const = 0;
32 38
33 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim itiveProcessor; } 39 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim itiveProcessor; }
34 const GrPipeline& pipeline() const { return *fArgs.fPipeline; } 40 const GrPipeline& pipeline() const { return *fArgs.fPipeline; }
35 const GrProgramDesc& desc() const { return *fArgs.fDesc; } 41 const GrProgramDesc& desc() const { return *fArgs.fDesc; }
36 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header( ); } 42 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header( ); }
37 43
38 void appendUniformDecls(ShaderVisibility, SkString*) const; 44 void appendUniformDecls(ShaderVisibility, SkString*) const;
39 45
40 // Handles for program uniforms (other than per-effect uniforms) 46 // Handles for program uniforms (other than per-effect uniforms)
(...skipping 28 matching lines...) Expand all
69 GrGLSLVertexBuilder fVS; 75 GrGLSLVertexBuilder fVS;
70 GrGLSLGeometryBuilder fGS; 76 GrGLSLGeometryBuilder fGS;
71 GrGLSLFragmentShaderBuilder fFS; 77 GrGLSLFragmentShaderBuilder fFS;
72 78
73 int fStageIndex; 79 int fStageIndex;
74 80
75 const DrawArgs& fArgs; 81 const DrawArgs& fArgs;
76 82
77 BuiltinUniformHandles fUniformHandles; 83 BuiltinUniformHandles fUniformHandles;
78 84
85 GrGLSLPrimitiveProcessor* fGeometryProcessor;
86 GrGLSLXferProcessor* fXferProcessor;
87 GrGLSLFragProcs fFragmentProcessors;
88
79 protected: 89 protected:
80 explicit GrGLSLProgramBuilder(const DrawArgs& args); 90 explicit GrGLSLProgramBuilder(const DrawArgs& args);
91
92 bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage , int maxTextures);
93
94 private:
95 // reset is called by program creator between each processor's emit code. I t increments the
96 // stage offset for variable name mangling, and also ensures verfication var iables in the
97 // fragment shader are cleared.
98 void reset() {
99 this->addStage();
100 fFS.reset();
101 }
102 void addStage() { fStageIndex++; }
103
104 class AutoStageAdvance {
105 public:
106 AutoStageAdvance(GrGLSLProgramBuilder* pb)
107 : fPB(pb) {
108 fPB->reset();
109 // Each output to the fragment processor gets its own code section
110 fPB->fFS.nextStage();
111 }
112 ~AutoStageAdvance() {}
113 private:
114 GrGLSLProgramBuilder* fPB;
115 };
116
117 // Generates a possibly mangled name for a stage variable and writes it to t he fragment shader.
118 // If GrGLSLExpr4 has a valid name then it will use that instead
119 void nameExpression(GrGLSLExpr4*, const char* baseName);
120
121 void emitAndInstallPrimProc(const GrPrimitiveProcessor&,
122 GrGLSLExpr4* outputColor,
123 GrGLSLExpr4* outputCoverage);
124 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu t);
125 void emitAndInstallFragProc(const GrFragmentProcessor&,
126 int index,
127 const GrGLSLExpr4& input,
128 GrGLSLExpr4* output);
129 void emitAndInstallXferProc(const GrXferProcessor&,
130 const GrGLSLExpr4& colorIn,
131 const GrGLSLExpr4& coverageIn,
132 bool ignoresCoverage);
133 void emitFSOutputSwizzle(bool hasSecondaryOutput);
134
135 void verify(const GrPrimitiveProcessor&);
136 void verify(const GrXferProcessor&);
137 void verify(const GrFragmentProcessor&);
138
139 virtual void emitSamplers(const GrProcessor& processor,
140 GrGLSLTextureSampler::TextureSamplerArray* outSamp lers) = 0;
141
142 GrGLSLPrimitiveProcessor::TransformsIn fCoordTransforms;
143 GrGLSLPrimitiveProcessor::TransformsOut fOutCoords;
81 }; 144 };
82 145
83 #endif 146 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698