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.
7 // ProgramD3D.h: Defines the rx::ProgramD3D class which implements rx::ProgramImpl.
9 #ifndef LIBGLESV2_RENDERER_PROGRAMD3D_H_
10 #define LIBGLESV2_RENDERER_PROGRAMD3D_H_
12 #include "libGLESv2/renderer/ProgramImpl.h"
13 #include "libGLESv2/renderer/Workarounds.h"
21 struct VariableLocation;
30 class ProgramD3D : public ProgramImpl
33 ProgramD3D(rx::Renderer *renderer);
34 virtual ~ProgramD3D();
36 static ProgramD3D *makeProgramD3D(ProgramImpl *impl);
37 static const ProgramD3D *makeProgramD3D(const ProgramImpl *impl);
39 const std::vector<rx::PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
40 int getShaderVersion() const { return mShaderVersion; }
41 GLenum getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; }
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);
49 bool usesPointSize() const { return mUsesPointSize; }
50 bool usesPointSpriteEmulation() const;
51 bool usesGeometryShader() const;
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);
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; }
62 gl::LinkResult compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
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);
70 void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const;
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();
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);
101 void getUniformfv(GLint location, GLfloat *params);
102 void getUniformiv(GLint location, GLint *params);
103 void getUniformuiv(GLint location, GLuint *params);
105 const UniformStorage &getVertexUniformStorage() const { return *mVertexUniformStorage; }
106 const UniformStorage &getFragmentUniformStorage() const { return *mFragmentUniformStorage; }
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);
115 DISALLOW_COPY_AND_ASSIGN(ProgramD3D);
117 class VertexExecutable
120 VertexExecutable(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
121 const GLenum signature[gl::MAX_VERTEX_ATTRIBS],
122 rx::ShaderExecutable *shaderExecutable);
125 bool matchesSignature(const GLenum convertedLayout[gl::MAX_VERTEX_ATTRIBS]) const;
127 const gl::VertexFormat *inputs() const { return mInputs; }
128 const GLenum *signature() const { return mSignature; }
129 rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
132 gl::VertexFormat mInputs[gl::MAX_VERTEX_ATTRIBS];
133 GLenum mSignature[gl::MAX_VERTEX_ATTRIBS];
134 rx::ShaderExecutable *mShaderExecutable;
137 class PixelExecutable
140 PixelExecutable(const std::vector<GLenum> &outputSignature, rx::ShaderExecutable *shaderExecutable);
143 bool matchesSignature(const std::vector<GLenum> &signature) const { return mOutputSignature == signature; }
145 const std::vector<GLenum> &outputSignature() const { return mOutputSignature; }
146 rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
149 std::vector<GLenum> mOutputSignature;
150 rx::ShaderExecutable *mShaderExecutable;
158 GLint logicalTextureUnit;
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);
170 template <typename T>
171 void setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType);
173 template <int cols, int rows>
174 void setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType);
176 template <typename T>
177 void getUniformv(GLint location, T *params, GLenum uniformType);
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);
185 DynamicHLSL *mDynamicHLSL;
187 std::vector<VertexExecutable *> mVertexExecutables;
188 std::vector<PixelExecutable *> mPixelExecutables;
189 rx::ShaderExecutable *mGeometryExecutable;
191 std::string mVertexHLSL;
192 rx::D3DWorkaroundType mVertexWorkarounds;
194 std::string mPixelHLSL;
195 rx::D3DWorkaroundType mPixelWorkarounds;
197 std::vector<rx::PixelShaderOutputVariable> mPixelShaderKey;
201 UniformStorage *mVertexUniformStorage;
202 UniformStorage *mFragmentUniformStorage;
204 GLenum mTransformFeedbackBufferMode;
206 std::vector<Sampler> mSamplersPS;
207 std::vector<Sampler> mSamplersVS;
208 GLuint mUsedVertexSamplerRange;
209 GLuint mUsedPixelSamplerRange;
210 bool mDirtySamplerMapping;
217 #endif // LIBGLESV2_RENDERER_PROGRAMD3D_H_