blob: 5069f7d2521b31b501373e50a95c8e1d7e377b2b [file] [log] [blame]
Brandon Jonesc9610c52014-08-25 17:02:59 -07001//
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"
Jamie Madill7acae0a2014-09-24 17:10:51 -040013#include "libGLESv2/renderer/Workarounds.h"
Brandon Jonesc9610c52014-08-25 17:02:59 -070014
Brandon Jones22502d52014-08-29 16:58:36 -070015#include <string>
16#include <vector>
17
Brandon Jonesc9610c52014-08-25 17:02:59 -070018namespace gl
19{
20struct LinkedUniform;
Brandon Jones22502d52014-08-29 16:58:36 -070021struct VariableLocation;
Brandon Jonesc9610c52014-08-25 17:02:59 -070022struct VertexFormat;
23}
24
25namespace rx
26{
27
28class UniformStorage;
29
30class 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
Brandon Jones22502d52014-08-29 16:58:36 -070039 const std::vector<rx::PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
Brandon Jones44151a92014-09-10 11:32:25 -070040 int getShaderVersion() const { return mShaderVersion; }
Brandon Joneseb994362014-09-24 10:27:28 -070041 GLenum getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; }
Brandon Jones1a8a7e32014-10-01 12:49:30 -070042
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);
Brandon Jones44151a92014-09-10 11:32:25 -070048
Brandon Joneseb994362014-09-24 10:27:28 -070049 bool usesPointSize() const { return mUsesPointSize; }
Brandon Jones44151a92014-09-10 11:32:25 -070050 bool usesPointSpriteEmulation() const;
51 bool usesGeometryShader() const;
Brandon Jones22502d52014-08-29 16:58:36 -070052
53 GLenum getBinaryFormat() { return GL_PROGRAM_BINARY_ANGLE; }
Geoff Langb543aff2014-09-30 14:52:54 -040054 gl::LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream);
55 gl::Error save(gl::BinaryOutputStream *stream);
Brandon Jones22502d52014-08-29 16:58:36 -070056
Geoff Langb543aff2014-09-30 14:52:54 -040057 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);
Brandon Joneseb994362014-09-24 10:27:28 -070060 ShaderExecutable *getGeometryExecutable() const { return mGeometryExecutable; }
61
Geoff Langb543aff2014-09-30 14:52:54 -040062 gl::LinkResult compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
63 int registers);
Brandon Jones22502d52014-08-29 16:58:36 -070064
Geoff Langb543aff2014-09-30 14:52:54 -040065 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);
Brandon Jonesc9610c52014-08-25 17:02:59 -070069
Brandon Jones44151a92014-09-10 11:32:25 -070070 void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const;
71
Brandon Jones1a8a7e32014-10-01 12:49:30 -070072 void initializeUniformStorage();
73 gl::Error applyUniforms();
74 gl::Error applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const gl::Caps &caps);
Brandon Jones18bd4102014-09-22 14:21:44 -070075 bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
76 unsigned int registerIndex, const gl::Caps &caps);
Brandon Jones1a8a7e32014-10-01 12:49:30 -070077 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);
Brandon Jonesc9610c52014-08-25 17:02:59 -0700104
105 const UniformStorage &getVertexUniformStorage() const { return *mVertexUniformStorage; }
106 const UniformStorage &getFragmentUniformStorage() const { return *mFragmentUniformStorage; }
107
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700108 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
Brandon Jonesc9610c52014-08-25 17:02:59 -0700112 void reset();
113
114 private:
115 DISALLOW_COPY_AND_ASSIGN(ProgramD3D);
116
Brandon Joneseb994362014-09-24 10:27:28 -0700117 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
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700153 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
Brandon Jonesc9610c52014-08-25 17:02:59 -0700184 Renderer *mRenderer;
185 DynamicHLSL *mDynamicHLSL;
186
Brandon Joneseb994362014-09-24 10:27:28 -0700187 std::vector<VertexExecutable *> mVertexExecutables;
188 std::vector<PixelExecutable *> mPixelExecutables;
189 rx::ShaderExecutable *mGeometryExecutable;
190
Brandon Jones22502d52014-08-29 16:58:36 -0700191 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
Brandon Jones44151a92014-09-10 11:32:25 -0700199 bool mUsesPointSize;
200
Brandon Jonesc9610c52014-08-25 17:02:59 -0700201 UniformStorage *mVertexUniformStorage;
202 UniformStorage *mFragmentUniformStorage;
Brandon Jones44151a92014-09-10 11:32:25 -0700203
Brandon Joneseb994362014-09-24 10:27:28 -0700204 GLenum mTransformFeedbackBufferMode;
Brandon Joneseb994362014-09-24 10:27:28 -0700205
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700206 std::vector<Sampler> mSamplersPS;
207 std::vector<Sampler> mSamplersVS;
208 GLuint mUsedVertexSamplerRange;
209 GLuint mUsedPixelSamplerRange;
210 bool mDirtySamplerMapping;
Brandon Joneseb994362014-09-24 10:27:28 -0700211
Brandon Jones44151a92014-09-10 11:32:25 -0700212 int mShaderVersion;
Brandon Jonesc9610c52014-08-25 17:02:59 -0700213};
214
215}
216
217#endif // LIBGLESV2_RENDERER_PROGRAMD3D_H_