Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 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" |
Jamie Madill | 7acae0a | 2014-09-24 17:10:51 -0400 | [diff] [blame] | 13 | #include "libGLESv2/renderer/Workarounds.h" |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 14 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 18 | namespace gl |
| 19 | { |
| 20 | struct LinkedUniform; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 21 | struct VariableLocation; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 22 | struct VertexFormat; |
| 23 | } |
| 24 | |
| 25 | namespace rx |
| 26 | { |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 27 | class RendererD3D; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 28 | class UniformStorage; |
| 29 | |
| 30 | class ProgramD3D : public ProgramImpl |
| 31 | { |
| 32 | public: |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 33 | ProgramD3D(rx::RendererD3D *renderer); |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 34 | virtual ~ProgramD3D(); |
| 35 | |
| 36 | static ProgramD3D *makeProgramD3D(ProgramImpl *impl); |
| 37 | static const ProgramD3D *makeProgramD3D(const ProgramImpl *impl); |
| 38 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 39 | const std::vector<rx::PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; } |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 40 | int getShaderVersion() const { return mShaderVersion; } |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 41 | GLenum getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; } |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 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); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 48 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 49 | bool usesPointSize() const { return mUsesPointSize; } |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 50 | bool usesPointSpriteEmulation() const; |
| 51 | bool usesGeometryShader() const; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 52 | |
| 53 | GLenum getBinaryFormat() { return GL_PROGRAM_BINARY_ANGLE; } |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 54 | gl::LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream); |
| 55 | gl::Error save(gl::BinaryOutputStream *stream); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 56 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 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); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 60 | ShaderExecutable *getGeometryExecutable() const { return mGeometryExecutable; } |
| 61 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 62 | gl::LinkResult compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader, |
| 63 | int registers); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 64 | |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame^] | 65 | gl::LinkResult link(const gl::Data &data, gl::InfoLog &infoLog, |
| 66 | gl::Shader *fragmentShader, gl::Shader *vertexShader, |
| 67 | const std::vector<std::string> &transformFeedbackVaryings, |
| 68 | GLenum transformFeedbackBufferMode, |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 69 | int *registers, std::vector<gl::LinkedVarying> *linkedVaryings, |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame^] | 70 | std::map<int, gl::VariableLocation> *outputVariables); |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 71 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 72 | void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const; |
| 73 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 74 | void initializeUniformStorage(); |
| 75 | gl::Error applyUniforms(); |
| 76 | gl::Error applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const gl::Caps &caps); |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 77 | bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader, |
| 78 | unsigned int registerIndex, const gl::Caps &caps); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 79 | void dirtyAllUniforms(); |
| 80 | |
| 81 | void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 82 | void setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 83 | void setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 84 | void setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 85 | void setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 86 | void setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 87 | void setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 88 | void setUniform4iv(GLint location, GLsizei count, const GLint *v); |
| 89 | void setUniform1uiv(GLint location, GLsizei count, const GLuint *v); |
| 90 | void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); |
| 91 | void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); |
| 92 | void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); |
| 93 | void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 94 | void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 95 | void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 96 | void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 97 | void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 98 | void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 99 | void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 100 | void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 101 | void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 102 | |
| 103 | void getUniformfv(GLint location, GLfloat *params); |
| 104 | void getUniformiv(GLint location, GLint *params); |
| 105 | void getUniformuiv(GLint location, GLuint *params); |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 106 | |
| 107 | const UniformStorage &getVertexUniformStorage() const { return *mVertexUniformStorage; } |
| 108 | const UniformStorage &getFragmentUniformStorage() const { return *mFragmentUniformStorage; } |
| 109 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 110 | bool linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader, |
| 111 | const gl::Caps &caps); |
| 112 | bool defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock, const gl::Caps &caps); |
| 113 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 114 | void reset(); |
| 115 | |
| 116 | private: |
| 117 | DISALLOW_COPY_AND_ASSIGN(ProgramD3D); |
| 118 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 119 | class VertexExecutable |
| 120 | { |
| 121 | public: |
| 122 | VertexExecutable(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS], |
| 123 | const GLenum signature[gl::MAX_VERTEX_ATTRIBS], |
| 124 | rx::ShaderExecutable *shaderExecutable); |
| 125 | ~VertexExecutable(); |
| 126 | |
| 127 | bool matchesSignature(const GLenum convertedLayout[gl::MAX_VERTEX_ATTRIBS]) const; |
| 128 | |
| 129 | const gl::VertexFormat *inputs() const { return mInputs; } |
| 130 | const GLenum *signature() const { return mSignature; } |
| 131 | rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; } |
| 132 | |
| 133 | private: |
| 134 | gl::VertexFormat mInputs[gl::MAX_VERTEX_ATTRIBS]; |
| 135 | GLenum mSignature[gl::MAX_VERTEX_ATTRIBS]; |
| 136 | rx::ShaderExecutable *mShaderExecutable; |
| 137 | }; |
| 138 | |
| 139 | class PixelExecutable |
| 140 | { |
| 141 | public: |
| 142 | PixelExecutable(const std::vector<GLenum> &outputSignature, rx::ShaderExecutable *shaderExecutable); |
| 143 | ~PixelExecutable(); |
| 144 | |
| 145 | bool matchesSignature(const std::vector<GLenum> &signature) const { return mOutputSignature == signature; } |
| 146 | |
| 147 | const std::vector<GLenum> &outputSignature() const { return mOutputSignature; } |
| 148 | rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; } |
| 149 | |
| 150 | private: |
| 151 | std::vector<GLenum> mOutputSignature; |
| 152 | rx::ShaderExecutable *mShaderExecutable; |
| 153 | }; |
| 154 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 155 | struct Sampler |
| 156 | { |
| 157 | Sampler(); |
| 158 | |
| 159 | bool active; |
| 160 | GLint logicalTextureUnit; |
| 161 | GLenum textureType; |
| 162 | }; |
| 163 | |
| 164 | void defineUniformBase(GLenum shader, const sh::Uniform &uniform, unsigned int uniformRegister); |
| 165 | void defineUniform(GLenum shader, const sh::ShaderVariable &uniform, const std::string &fullName, |
| 166 | sh::HLSLBlockEncoder *encoder); |
| 167 | bool indexSamplerUniform(const gl::LinkedUniform &uniform, gl::InfoLog &infoLog, const gl::Caps &caps); |
| 168 | bool indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps); |
| 169 | static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount, |
| 170 | std::vector<Sampler> &outSamplers, GLuint *outUsedRange); |
| 171 | |
| 172 | template <typename T> |
| 173 | void setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType); |
| 174 | |
| 175 | template <int cols, int rows> |
| 176 | void setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType); |
| 177 | |
| 178 | template <typename T> |
| 179 | void getUniformv(GLint location, T *params, GLenum uniformType); |
| 180 | |
| 181 | template <typename VarT> |
| 182 | void defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex, |
| 183 | sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes, |
| 184 | bool inRowMajorLayout); |
| 185 | |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 186 | RendererD3D *mRenderer; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 187 | DynamicHLSL *mDynamicHLSL; |
| 188 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 189 | std::vector<VertexExecutable *> mVertexExecutables; |
| 190 | std::vector<PixelExecutable *> mPixelExecutables; |
| 191 | rx::ShaderExecutable *mGeometryExecutable; |
| 192 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 193 | std::string mVertexHLSL; |
| 194 | rx::D3DWorkaroundType mVertexWorkarounds; |
| 195 | |
| 196 | std::string mPixelHLSL; |
| 197 | rx::D3DWorkaroundType mPixelWorkarounds; |
| 198 | bool mUsesFragDepth; |
| 199 | std::vector<rx::PixelShaderOutputVariable> mPixelShaderKey; |
| 200 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 201 | bool mUsesPointSize; |
| 202 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 203 | UniformStorage *mVertexUniformStorage; |
| 204 | UniformStorage *mFragmentUniformStorage; |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 205 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 206 | GLenum mTransformFeedbackBufferMode; |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 207 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 208 | std::vector<Sampler> mSamplersPS; |
| 209 | std::vector<Sampler> mSamplersVS; |
| 210 | GLuint mUsedVertexSamplerRange; |
| 211 | GLuint mUsedPixelSamplerRange; |
| 212 | bool mDirtySamplerMapping; |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 213 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 214 | int mShaderVersion; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | } |
| 218 | |
| 219 | #endif // LIBGLESV2_RENDERER_PROGRAMD3D_H_ |