Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / renderer / d3d / ProgramD3D.h
1 //
2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // ProgramD3D.h: Defines the rx::ProgramD3D class which implements rx::ProgramImpl.
8
9 #ifndef LIBGLESV2_RENDERER_PROGRAMD3D_H_
10 #define LIBGLESV2_RENDERER_PROGRAMD3D_H_
11
12 #include "libGLESv2/renderer/ProgramImpl.h"
13 #include "libGLESv2/renderer/Workarounds.h"
14
15 #include <string>
16 #include <vector>
17
18 namespace gl
19 {
20 struct LinkedUniform;
21 struct VariableLocation;
22 struct VertexFormat;
23 }
24
25 namespace rx
26 {
27
28 class UniformStorage;
29
30 class ProgramD3D : public ProgramImpl
31 {
32   public:
33     ProgramD3D(rx::Renderer *renderer);
34     virtual ~ProgramD3D();
35
36     static ProgramD3D *makeProgramD3D(ProgramImpl *impl);
37     static const ProgramD3D *makeProgramD3D(const ProgramImpl *impl);
38
39     const std::vector<rx::PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
40     int getShaderVersion() const { return mShaderVersion; }
41     GLenum getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; }
42
43     GLint getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const;
44     GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const;
45     GLint getUsedSamplerRange(gl::SamplerType type) const;
46     void updateSamplerMapping();
47     bool validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps);
48
49     bool usesPointSize() const { return mUsesPointSize; }
50     bool usesPointSpriteEmulation() const;
51     bool usesGeometryShader() const;
52
53     GLenum getBinaryFormat() { return GL_PROGRAM_BINARY_ANGLE; }
54     gl::LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream);
55     gl::Error save(gl::BinaryOutputStream *stream);
56
57     gl::Error getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutable **outExectuable);
58     gl::Error getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputLayout, ShaderExecutable **outExectuable);
59     gl::Error getVertexExecutableForInputLayout(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS], ShaderExecutable **outExectuable);
60     ShaderExecutable *getGeometryExecutable() const { return mGeometryExecutable; }
61
62     gl::LinkResult compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
63                                              int registers);
64
65     gl::LinkResult link(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
66                         const std::vector<std::string> &transformFeedbackVaryings, GLenum transformFeedbackBufferMode,
67                         int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
68                         std::map<int, gl::VariableLocation> *outputVariables, const gl::Caps &caps);
69
70     void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const;
71
72     void initializeUniformStorage();
73     gl::Error applyUniforms();
74     gl::Error applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const gl::Caps &caps);
75     bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
76                                     unsigned int registerIndex, const gl::Caps &caps);
77     void dirtyAllUniforms();
78
79     void setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
80     void setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
81     void setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
82     void setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
83     void setUniform1iv(GLint location, GLsizei count, const GLint *v);
84     void setUniform2iv(GLint location, GLsizei count, const GLint *v);
85     void setUniform3iv(GLint location, GLsizei count, const GLint *v);
86     void setUniform4iv(GLint location, GLsizei count, const GLint *v);
87     void setUniform1uiv(GLint location, GLsizei count, const GLuint *v);
88     void setUniform2uiv(GLint location, GLsizei count, const GLuint *v);
89     void setUniform3uiv(GLint location, GLsizei count, const GLuint *v);
90     void setUniform4uiv(GLint location, GLsizei count, const GLuint *v);
91     void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
92     void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
93     void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
94     void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
95     void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
96     void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
97     void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
98     void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
99     void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
100
101     void getUniformfv(GLint location, GLfloat *params);
102     void getUniformiv(GLint location, GLint *params);
103     void getUniformuiv(GLint location, GLuint *params);
104
105     const UniformStorage &getVertexUniformStorage() const { return *mVertexUniformStorage; }
106     const UniformStorage &getFragmentUniformStorage() const { return *mFragmentUniformStorage; }
107
108     bool linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader,
109                       const gl::Caps &caps);
110     bool defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock, const gl::Caps &caps);
111
112     void reset();
113
114   private:
115     DISALLOW_COPY_AND_ASSIGN(ProgramD3D);
116
117     class VertexExecutable
118     {
119       public:
120         VertexExecutable(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
121                          const GLenum signature[gl::MAX_VERTEX_ATTRIBS],
122                          rx::ShaderExecutable *shaderExecutable);
123         ~VertexExecutable();
124
125         bool matchesSignature(const GLenum convertedLayout[gl::MAX_VERTEX_ATTRIBS]) const;
126
127         const gl::VertexFormat *inputs() const { return mInputs; }
128         const GLenum *signature() const { return mSignature; }
129         rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
130
131       private:
132         gl::VertexFormat mInputs[gl::MAX_VERTEX_ATTRIBS];
133         GLenum mSignature[gl::MAX_VERTEX_ATTRIBS];
134         rx::ShaderExecutable *mShaderExecutable;
135     };
136
137     class PixelExecutable
138     {
139       public:
140         PixelExecutable(const std::vector<GLenum> &outputSignature, rx::ShaderExecutable *shaderExecutable);
141         ~PixelExecutable();
142
143         bool matchesSignature(const std::vector<GLenum> &signature) const { return mOutputSignature == signature; }
144
145         const std::vector<GLenum> &outputSignature() const { return mOutputSignature; }
146         rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
147
148       private:
149         std::vector<GLenum> mOutputSignature;
150         rx::ShaderExecutable *mShaderExecutable;
151     };
152
153     struct Sampler
154     {
155         Sampler();
156
157         bool active;
158         GLint logicalTextureUnit;
159         GLenum textureType;
160     };
161
162     void defineUniformBase(GLenum shader, const sh::Uniform &uniform, unsigned int uniformRegister);
163     void defineUniform(GLenum shader, const sh::ShaderVariable &uniform, const std::string &fullName,
164                        sh::HLSLBlockEncoder *encoder);
165     bool indexSamplerUniform(const gl::LinkedUniform &uniform, gl::InfoLog &infoLog, const gl::Caps &caps);
166     bool indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps);
167     static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount,
168                                std::vector<Sampler> &outSamplers, GLuint *outUsedRange);
169
170     template <typename T>
171     void setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType);
172
173     template <int cols, int rows>
174     void setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType);
175
176     template <typename T>
177     void getUniformv(GLint location, T *params, GLenum uniformType);
178
179     template <typename VarT>
180     void defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex,
181                                    sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes,
182                                    bool inRowMajorLayout);
183
184     Renderer *mRenderer;
185     DynamicHLSL *mDynamicHLSL;
186
187     std::vector<VertexExecutable *> mVertexExecutables;
188     std::vector<PixelExecutable *> mPixelExecutables;
189     rx::ShaderExecutable *mGeometryExecutable;
190
191     std::string mVertexHLSL;
192     rx::D3DWorkaroundType mVertexWorkarounds;
193
194     std::string mPixelHLSL;
195     rx::D3DWorkaroundType mPixelWorkarounds;
196     bool mUsesFragDepth;
197     std::vector<rx::PixelShaderOutputVariable> mPixelShaderKey;
198
199     bool mUsesPointSize;
200
201     UniformStorage *mVertexUniformStorage;
202     UniformStorage *mFragmentUniformStorage;
203
204     GLenum mTransformFeedbackBufferMode;
205
206     std::vector<Sampler> mSamplersPS;
207     std::vector<Sampler> mSamplersVS;
208     GLuint mUsedVertexSamplerRange;
209     GLuint mUsedPixelSamplerRange;
210     bool mDirtySamplerMapping;
211
212     int mShaderVersion;
213 };
214
215 }
216
217 #endif // LIBGLESV2_RENDERER_PROGRAMD3D_H_