Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 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 | // ProgramImpl.h: Defines the abstract rx::ProgramImpl class. |
| 8 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 9 | #ifndef LIBANGLE_RENDERER_PROGRAMIMPL_H_ |
| 10 | #define LIBANGLE_RENDERER_PROGRAMIMPL_H_ |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 11 | |
| 12 | #include "common/angleutils.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 13 | #include "libANGLE/BinaryStream.h" |
| 14 | #include "libANGLE/Constants.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 15 | #include "libANGLE/Program.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/Shader.h" |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 17 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 18 | #include <map> |
| 19 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 20 | namespace gl |
| 21 | { |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 22 | class Context; |
Jamie Madill | c9727f3 | 2017-11-07 12:37:07 -0500 | [diff] [blame] | 23 | struct ProgramLinkedResources; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 24 | } // namespace gl |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 25 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 26 | namespace sh |
| 27 | { |
| 28 | struct BlockMemberInfo; |
| 29 | } |
| 30 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 31 | namespace rx |
| 32 | { |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 33 | |
| 34 | // Provides a mechanism to access the result of asynchronous linking. |
| 35 | class LinkEvent : angle::NonCopyable |
| 36 | { |
| 37 | public: |
| 38 | virtual ~LinkEvent(){}; |
| 39 | |
| 40 | // Please be aware that these methods may be called under a gl::Context other |
| 41 | // than the one where the LinkEvent was created. |
| 42 | // |
| 43 | // Waits until the linking is actually done. Returns true if the linking |
| 44 | // succeeded, false otherwise. |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 45 | virtual angle::Result wait(const gl::Context *context) = 0; |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 46 | // Peeks whether the linking is still ongoing. |
| 47 | virtual bool isLinking() = 0; |
| 48 | }; |
| 49 | |
| 50 | // Wraps an already done linking. |
| 51 | class LinkEventDone final : public LinkEvent |
| 52 | { |
| 53 | public: |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 54 | LinkEventDone(angle::Result result) : mResult(result) {} |
| 55 | angle::Result wait(const gl::Context *context) override { return mResult; } |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 56 | bool isLinking() override { return false; } |
| 57 | |
| 58 | private: |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 59 | angle::Result mResult; |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 60 | }; |
| 61 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 62 | class ProgramImpl : angle::NonCopyable |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 63 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 64 | public: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 65 | ProgramImpl(const gl::ProgramState &state) : mState(state) {} |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 66 | virtual ~ProgramImpl() {} |
Jamie Madill | f4a789f | 2018-10-18 16:56:20 -0400 | [diff] [blame] | 67 | virtual void destroy(const gl::Context *context) {} |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 68 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 69 | virtual angle::Result load(const gl::Context *context, |
| 70 | gl::InfoLog &infoLog, |
| 71 | gl::BinaryInputStream *stream) = 0; |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 72 | virtual void save(const gl::Context *context, gl::BinaryOutputStream *stream) = 0; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 73 | virtual void setBinaryRetrievableHint(bool retrievable) = 0; |
| 74 | virtual void setSeparable(bool separable) = 0; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 75 | |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 76 | virtual std::unique_ptr<LinkEvent> link(const gl::Context *context, |
| 77 | const gl::ProgramLinkedResources &resources, |
| 78 | gl::InfoLog &infoLog) = 0; |
Jamie Madill | 36cfd6a | 2015-08-18 10:46:20 -0400 | [diff] [blame] | 79 | virtual GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) = 0; |
| 80 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 81 | virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
| 82 | virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
| 83 | virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
| 84 | virtual void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 85 | virtual void setUniform1iv(GLint location, GLsizei count, const GLint *v) = 0; |
| 86 | virtual void setUniform2iv(GLint location, GLsizei count, const GLint *v) = 0; |
| 87 | virtual void setUniform3iv(GLint location, GLsizei count, const GLint *v) = 0; |
| 88 | virtual void setUniform4iv(GLint location, GLsizei count, const GLint *v) = 0; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 89 | virtual void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
| 90 | virtual void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
| 91 | virtual void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
| 92 | virtual void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 93 | virtual void setUniformMatrix2fv(GLint location, |
| 94 | GLsizei count, |
| 95 | GLboolean transpose, |
| 96 | const GLfloat *value) = 0; |
| 97 | virtual void setUniformMatrix3fv(GLint location, |
| 98 | GLsizei count, |
| 99 | GLboolean transpose, |
| 100 | const GLfloat *value) = 0; |
| 101 | virtual void setUniformMatrix4fv(GLint location, |
| 102 | GLsizei count, |
| 103 | GLboolean transpose, |
| 104 | const GLfloat *value) = 0; |
| 105 | virtual void setUniformMatrix2x3fv(GLint location, |
| 106 | GLsizei count, |
| 107 | GLboolean transpose, |
| 108 | const GLfloat *value) = 0; |
| 109 | virtual void setUniformMatrix3x2fv(GLint location, |
| 110 | GLsizei count, |
| 111 | GLboolean transpose, |
| 112 | const GLfloat *value) = 0; |
| 113 | virtual void setUniformMatrix2x4fv(GLint location, |
| 114 | GLsizei count, |
| 115 | GLboolean transpose, |
| 116 | const GLfloat *value) = 0; |
| 117 | virtual void setUniformMatrix4x2fv(GLint location, |
| 118 | GLsizei count, |
| 119 | GLboolean transpose, |
| 120 | const GLfloat *value) = 0; |
| 121 | virtual void setUniformMatrix3x4fv(GLint location, |
| 122 | GLsizei count, |
| 123 | GLboolean transpose, |
| 124 | const GLfloat *value) = 0; |
| 125 | virtual void setUniformMatrix4x3fv(GLint location, |
| 126 | GLsizei count, |
| 127 | GLboolean transpose, |
| 128 | const GLfloat *value) = 0; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 129 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 130 | // Done in the back-end to avoid having to keep a system copy of uniform data. |
| 131 | virtual void getUniformfv(const gl::Context *context, |
| 132 | GLint location, |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 133 | GLfloat *params) const = 0; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 134 | virtual void getUniformiv(const gl::Context *context, GLint location, GLint *params) const = 0; |
| 135 | virtual void getUniformuiv(const gl::Context *context, |
| 136 | GLint location, |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 137 | GLuint *params) const = 0; |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 138 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 139 | // CHROMIUM_path_rendering |
| 140 | // Set parameters to control fragment shader input variable interpolation |
| 141 | virtual void setPathFragmentInputGen(const std::string &inputName, |
| 142 | GLenum genMode, |
| 143 | GLint components, |
| 144 | const GLfloat *coeffs) = 0; |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 145 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 146 | // Implementation-specific method for ignoring unreferenced uniforms. Some implementations may |
| 147 | // perform more extensive analysis and ignore some locations that ANGLE doesn't detect as |
| 148 | // unreferenced. This method is not required to be overriden by a back-end. |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 149 | virtual void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations, |
Qin Jiajia | 47f6dd0 | 2018-08-10 13:36:32 +0800 | [diff] [blame] | 150 | std::vector<gl::SamplerBinding> *samplerBindings, |
| 151 | std::vector<gl::ImageBinding> *imageBindings) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 152 | {} |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 153 | |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 154 | const gl::ProgramState &getState() const { return mState; } |
| 155 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 156 | virtual angle::Result syncState(const gl::Context *context, |
| 157 | const gl::Program::DirtyBits &dirtyBits); |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 158 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 159 | protected: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 160 | const gl::ProgramState &mState; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 163 | inline angle::Result ProgramImpl::syncState(const gl::Context *context, |
| 164 | const gl::Program::DirtyBits &dirtyBits) |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 165 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 166 | return angle::Result::Continue; |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 167 | } |
| 168 | |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 169 | } // namespace rx |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 170 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 171 | #endif // LIBANGLE_RENDERER_PROGRAMIMPL_H_ |