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

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

Issue 1490283004: Create GLSLUniformHandler class for gpu backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up public api of uniformhandler Created 5 years 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/glsl/GrGLSLPrimitiveProcessor.cpp ('k') | src/gpu/glsl/GrGLSLProgramBuilder.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 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/GrGLSLProgramDataManager.h" 15 #include "glsl/GrGLSLProgramDataManager.h"
16 #include "glsl/GrGLSLUniformHandler.h"
16 #include "glsl/GrGLSLVertexShaderBuilder.h" 17 #include "glsl/GrGLSLVertexShaderBuilder.h"
17 18
18 class GrGLSLCaps; 19 class GrGLSLCaps;
19 class GrGLSLShaderVar; 20 class GrGLSLShaderVar;
20 class GrGLSLVaryingHandler; 21 class GrGLSLVaryingHandler;
21 22
22 // Enough precision to represent 1 / 2048 accurately in printf 23 class GrGLSLProgramBuilder {
23 #define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11
24
25 class GrGLSLUniformBuilder {
26 public:
27 enum ShaderVisibility {
28 kVertex_Visibility = 1 << kVertex_GrShaderType,
29 kGeometry_Visibility = 1 << kGeometry_GrShaderType,
30 kFragment_Visibility = 1 << kFragment_GrShaderType,
31 };
32
33 virtual ~GrGLSLUniformBuilder() {}
34
35 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
36
37 /** Add a uniform variable to the current program, that has visibility in on e or more shaders.
38 visibility is a bitfield of ShaderVisibility values indicating from whic h shaders the
39 uniform should be accessible. At least one bit must be set. Geometry sha der uniforms are not
40 supported at this time. The actual uniform name will be mangled. If outN ame is not nullptr
41 then it will refer to the final uniform name after return. Use the addUn iformArray variant
42 to add an array of uniforms. */
43 UniformHandle addUniform(uint32_t visibility,
44 GrSLType type,
45 GrSLPrecision precision,
46 const char* name,
47 const char** outName = nullptr) {
48 return this->addUniformArray(visibility, type, precision, name, 0, outNa me);
49 }
50
51 UniformHandle addUniformArray(uint32_t visibility,
52 GrSLType type,
53 GrSLPrecision precision,
54 const char* name,
55 int arrayCount,
56 const char** outName = nullptr) {
57 return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
58 outName);
59 }
60
61 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0 ;
62
63 /**
64 * Shortcut for getUniformVariable(u).c_str()
65 */
66 virtual const char* getUniformCStr(UniformHandle u) const = 0;
67
68 /*
69 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
70 */
71 protected:
72 virtual UniformHandle internalAddUniformArray(
73 uint32_t visibility,
74 GrSLType type,
75 GrSLPrecision precision,
76 const char* name,
77 bool mangleName,
78 int arrayCount,
79 const char** outName) = 0;
80 };
81
82 /* a specialization of the above for GPs. Lets the user add uniforms, varyings, and VS / FS code */
83 class GrGLSLGPBuilder : public virtual GrGLSLUniformBuilder {
84 public:
85 /*
86 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
87 */
88 };
89
90
91 /* a specializations for FPs. Lets the user add uniforms and FS code */
92 class GrGLSLFPBuilder : public virtual GrGLSLUniformBuilder {
93 public:
94 /*
95 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
96 */
97 };
98
99 /* a specializations for XPs. Lets the user add uniforms and FS code */
100 class GrGLSLXPBuilder : public virtual GrGLSLUniformBuilder {
101 public:
102 /*
103 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
104 */
105 };
106
107 class GrGLSLProgramBuilder : public GrGLSLGPBuilder,
108 public GrGLSLFPBuilder,
109 public GrGLSLXPBuilder {
110 public: 24 public:
111 typedef GrGpu::DrawArgs DrawArgs; 25 typedef GrGpu::DrawArgs DrawArgs;
26 typedef GrGLSLUniformHandler::ShaderVisibility ShaderVisibility;
27 typedef GrGLSLUniformHandler::UniformHandle UniformHandle;
28
29 virtual ~GrGLSLProgramBuilder() {}
112 30
113 virtual const GrGLSLCaps* glslCaps() const = 0; 31 virtual const GrGLSLCaps* glslCaps() const = 0;
114 32
33 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim itiveProcessor; }
34 const GrPipeline& pipeline() const { return *fArgs.fPipeline; }
35 const GrProgramDesc& desc() const { return *fArgs.fDesc; }
36 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header( ); }
37
38 void appendUniformDecls(ShaderVisibility, SkString*) const;
39
115 // Handles for program uniforms (other than per-effect uniforms) 40 // Handles for program uniforms (other than per-effect uniforms)
116 struct BuiltinUniformHandles { 41 struct BuiltinUniformHandles {
117 UniformHandle fRTAdjustmentUni; 42 UniformHandle fRTAdjustmentUni;
118 43
119 // We use the render target height to provide a y-down frag coord when s pecifying 44 // We use the render target height to provide a y-down frag coord when s pecifying
120 // origin_upper_left is not supported. 45 // origin_upper_left is not supported.
121 UniformHandle fRTHeightUni; 46 UniformHandle fRTHeightUni;
122 }; 47 };
123 48
124 protected: 49 // Used to add a uniform in the vertex shader for transforming into normaliz ed device space.
125 explicit GrGLSLProgramBuilder(const DrawArgs& args); 50 void addRTAdjustmentUniform(GrSLPrecision precision, const char* name, const char** outName);
126
127 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim itiveProcessor; }
128 const GrPipeline& pipeline() const { return *fArgs.fPipeline; }
129 const GrProgramDesc& desc() const { return *fArgs.fDesc; }
130 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header( ); }
131
132 void appendUniformDecls(ShaderVisibility, SkString*) const;
133
134 // Used to add a uniform for frag position without mangling the name of the uniform inside of a
135 // stage.
136 UniformHandle addFragPosUniform(uint32_t visibility,
137 GrSLType type,
138 GrSLPrecision precision,
139 const char* name,
140 const char** outName) {
141 return this->internalAddUniformArray(visibility, type, precision, name, false, 0, outName);
142 }
143
144 const char* rtAdjustment() const { return "rtAdjustment"; } 51 const char* rtAdjustment() const { return "rtAdjustment"; }
52
53 // Used to add a uniform for the RenderTarget height (used for frag position ) without mangling
54 // the name of the uniform inside of a stage.
55 void addRTHeightUniform(const char* name, const char** outName);
145 56
146 // Generates a name for a variable. The generated string will be name prefix ed by the prefix 57 // Generates a name for a variable. The generated string will be name prefix ed by the prefix
147 // char (unless the prefix is '\0'). It also will mangle the name to be stag e-specific unless 58 // char (unless the prefix is '\0'). It also will mangle the name to be stag e-specific unless
148 // explicitly asked not to. 59 // explicitly asked not to.
149 void nameVariable(SkString* out, char prefix, const char* name, bool mangle = true); 60 void nameVariable(SkString* out, char prefix, const char* name, bool mangle = true);
150 61
62 virtual GrGLSLUniformHandler* uniformHandler() = 0;
63 virtual const GrGLSLUniformHandler* uniformHandler() const = 0;
151 virtual GrGLSLVaryingHandler* varyingHandler() = 0; 64 virtual GrGLSLVaryingHandler* varyingHandler() = 0;
152 65
153 // number of each input/output type in a single allocation block, used by ma ny builders 66 // number of each input/output type in a single allocation block, used by ma ny builders
154 static const int kVarsPerBlock; 67 static const int kVarsPerBlock;
155 68
156 GrGLSLVertexBuilder fVS; 69 GrGLSLVertexBuilder fVS;
157 GrGLSLGeometryBuilder fGS; 70 GrGLSLGeometryBuilder fGS;
158 GrGLSLFragmentShaderBuilder fFS; 71 GrGLSLFragmentShaderBuilder fFS;
159 72
160 int fStageIndex; 73 int fStageIndex;
161 74
75 const DrawArgs& fArgs;
76
162 BuiltinUniformHandles fUniformHandles; 77 BuiltinUniformHandles fUniformHandles;
163 78
164 const DrawArgs& fArgs; 79 protected:
165 80 explicit GrGLSLProgramBuilder(const DrawArgs& args);
166 private:
167 virtual void onAppendUniformDecls(ShaderVisibility visibility, SkString* out ) const = 0;
168
169 friend class GrGLSLShaderBuilder;
170 friend class GrGLSLVertexBuilder;
171 friend class GrGLSLFragmentShaderBuilder;
172 friend class GrGLSLGeometryBuilder;
173 friend class GrGLSLVaryingHandler;
174 }; 81 };
175 82
176 #endif 83 #endif
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp ('k') | src/gpu/glsl/GrGLSLProgramBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698