blob: 384ddaeacb23bc3092c2d041825a6bc4b4990fa9 [file] [log] [blame]
Brandon Jonesc9610c52014-08-25 17:02:59 -07001//
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 Lang0a73dd82014-11-19 16:18:08 -05009#ifndef LIBANGLE_RENDERER_PROGRAMIMPL_H_
10#define LIBANGLE_RENDERER_PROGRAMIMPL_H_
Brandon Jonesc9610c52014-08-25 17:02:59 -070011
12#include "common/angleutils.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050013#include "libANGLE/BinaryStream.h"
14#include "libANGLE/Constants.h"
Geoff Lang7dd2e102014-11-10 15:19:26 -050015#include "libANGLE/Program.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050016#include "libANGLE/Shader.h"
Brandon Jonesc9610c52014-08-25 17:02:59 -070017
Brandon Jones1a8a7e32014-10-01 12:49:30 -070018#include <map>
19
Jamie Madill192745a2016-12-22 15:58:21 -050020namespace gl
21{
Jamie Madillc564c072017-06-01 12:45:42 -040022class Context;
Jamie Madillc9727f32017-11-07 12:37:07 -050023struct ProgramLinkedResources;
Jamie Madillb980c562018-11-27 11:34:27 -050024} // namespace gl
Jamie Madill192745a2016-12-22 15:58:21 -050025
Jamie Madill53ea9cc2016-05-17 10:12:52 -040026namespace sh
27{
28struct BlockMemberInfo;
29}
30
Brandon Jonesc9610c52014-08-25 17:02:59 -070031namespace rx
32{
jchen107ae70d82018-07-06 13:47:01 +080033
34// Provides a mechanism to access the result of asynchronous linking.
35class 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 Madill785e8a02018-10-04 17:42:00 -040045 virtual angle::Result wait(const gl::Context *context) = 0;
jchen107ae70d82018-07-06 13:47:01 +080046 // Peeks whether the linking is still ongoing.
47 virtual bool isLinking() = 0;
48};
49
50// Wraps an already done linking.
51class LinkEventDone final : public LinkEvent
52{
53 public:
Jamie Madill785e8a02018-10-04 17:42:00 -040054 LinkEventDone(angle::Result result) : mResult(result) {}
Jamie Madillab2bfa82019-01-15 19:06:47 -050055 angle::Result wait(const gl::Context *context) override;
56 bool isLinking() override;
jchen107ae70d82018-07-06 13:47:01 +080057
58 private:
Jamie Madill785e8a02018-10-04 17:42:00 -040059 angle::Result mResult;
jchen107ae70d82018-07-06 13:47:01 +080060};
61
Jamie Madillab2bfa82019-01-15 19:06:47 -050062inline angle::Result LinkEventDone::wait(const gl::Context *context)
63{
64 return mResult;
65}
66inline bool LinkEventDone::isLinking()
67{
68 return false;
69}
70
Jamie Madillf0d10f82015-03-31 12:56:52 -040071class ProgramImpl : angle::NonCopyable
Brandon Jonesc9610c52014-08-25 17:02:59 -070072{
Brandon Jones1a8a7e32014-10-01 12:49:30 -070073 public:
Jamie Madill48ef11b2016-04-27 15:21:52 -040074 ProgramImpl(const gl::ProgramState &state) : mState(state) {}
Jamie Madill62d31cb2015-09-11 13:25:51 -040075 virtual ~ProgramImpl() {}
Jamie Madillf4a789f2018-10-18 16:56:20 -040076 virtual void destroy(const gl::Context *context) {}
Brandon Jones1a8a7e32014-10-01 12:49:30 -070077
Jamie Madill785e8a02018-10-04 17:42:00 -040078 virtual angle::Result load(const gl::Context *context,
79 gl::InfoLog &infoLog,
80 gl::BinaryInputStream *stream) = 0;
Jamie Madill27a60632017-06-30 15:12:01 -040081 virtual void save(const gl::Context *context, gl::BinaryOutputStream *stream) = 0;
Jamie Madillb980c562018-11-27 11:34:27 -050082 virtual void setBinaryRetrievableHint(bool retrievable) = 0;
83 virtual void setSeparable(bool separable) = 0;
Brandon Jones22502d52014-08-29 16:58:36 -070084
jchen107ae70d82018-07-06 13:47:01 +080085 virtual std::unique_ptr<LinkEvent> link(const gl::Context *context,
86 const gl::ProgramLinkedResources &resources,
87 gl::InfoLog &infoLog) = 0;
Jamie Madill36cfd6a2015-08-18 10:46:20 -040088 virtual GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) = 0;
89
Brandon Jones1a8a7e32014-10-01 12:49:30 -070090 virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0;
91 virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0;
92 virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0;
93 virtual void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) = 0;
Jamie Madillb980c562018-11-27 11:34:27 -050094 virtual void setUniform1iv(GLint location, GLsizei count, const GLint *v) = 0;
95 virtual void setUniform2iv(GLint location, GLsizei count, const GLint *v) = 0;
96 virtual void setUniform3iv(GLint location, GLsizei count, const GLint *v) = 0;
97 virtual void setUniform4iv(GLint location, GLsizei count, const GLint *v) = 0;
Brandon Jones1a8a7e32014-10-01 12:49:30 -070098 virtual void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) = 0;
99 virtual void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) = 0;
100 virtual void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) = 0;
101 virtual void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) = 0;
Jamie Madillb980c562018-11-27 11:34:27 -0500102 virtual void setUniformMatrix2fv(GLint location,
103 GLsizei count,
104 GLboolean transpose,
105 const GLfloat *value) = 0;
106 virtual void setUniformMatrix3fv(GLint location,
107 GLsizei count,
108 GLboolean transpose,
109 const GLfloat *value) = 0;
110 virtual void setUniformMatrix4fv(GLint location,
111 GLsizei count,
112 GLboolean transpose,
113 const GLfloat *value) = 0;
114 virtual void setUniformMatrix2x3fv(GLint location,
115 GLsizei count,
116 GLboolean transpose,
117 const GLfloat *value) = 0;
118 virtual void setUniformMatrix3x2fv(GLint location,
119 GLsizei count,
120 GLboolean transpose,
121 const GLfloat *value) = 0;
122 virtual void setUniformMatrix2x4fv(GLint location,
123 GLsizei count,
124 GLboolean transpose,
125 const GLfloat *value) = 0;
126 virtual void setUniformMatrix4x2fv(GLint location,
127 GLsizei count,
128 GLboolean transpose,
129 const GLfloat *value) = 0;
130 virtual void setUniformMatrix3x4fv(GLint location,
131 GLsizei count,
132 GLboolean transpose,
133 const GLfloat *value) = 0;
134 virtual void setUniformMatrix4x3fv(GLint location,
135 GLsizei count,
136 GLboolean transpose,
137 const GLfloat *value) = 0;
Brandon Jonesc9610c52014-08-25 17:02:59 -0700138
Jamie Madill54164b02017-08-28 15:17:37 -0400139 // Done in the back-end to avoid having to keep a system copy of uniform data.
140 virtual void getUniformfv(const gl::Context *context,
141 GLint location,
Jamie Madillb980c562018-11-27 11:34:27 -0500142 GLfloat *params) const = 0;
Jamie Madill54164b02017-08-28 15:17:37 -0400143 virtual void getUniformiv(const gl::Context *context, GLint location, GLint *params) const = 0;
144 virtual void getUniformuiv(const gl::Context *context,
145 GLint location,
Jamie Madillb980c562018-11-27 11:34:27 -0500146 GLuint *params) const = 0;
Jamie Madill54164b02017-08-28 15:17:37 -0400147
Sami Väisänen46eaa942016-06-29 10:26:37 +0300148 // CHROMIUM_path_rendering
149 // Set parameters to control fragment shader input variable interpolation
150 virtual void setPathFragmentInputGen(const std::string &inputName,
151 GLenum genMode,
152 GLint components,
153 const GLfloat *coeffs) = 0;
Jamie Madill811b6352015-02-09 10:17:09 -0500154
Jamie Madill54164b02017-08-28 15:17:37 -0400155 // Implementation-specific method for ignoring unreferenced uniforms. Some implementations may
156 // perform more extensive analysis and ignore some locations that ANGLE doesn't detect as
157 // unreferenced. This method is not required to be overriden by a back-end.
Jamie Madillfb997ec2017-09-20 15:44:27 -0400158 virtual void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
Qin Jiajia47f6dd02018-08-10 13:36:32 +0800159 std::vector<gl::SamplerBinding> *samplerBindings,
160 std::vector<gl::ImageBinding> *imageBindings)
Jamie Madillb980c562018-11-27 11:34:27 -0500161 {}
Jamie Madill54164b02017-08-28 15:17:37 -0400162
Jamie Madill2274b652018-05-31 10:56:08 -0400163 const gl::ProgramState &getState() const { return mState; }
164
Jamie Madill6f755b22018-10-09 12:48:54 -0400165 virtual angle::Result syncState(const gl::Context *context,
166 const gl::Program::DirtyBits &dirtyBits);
Jamie Madill70aeda42018-08-20 12:17:40 -0400167
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700168 protected:
Jamie Madill48ef11b2016-04-27 15:21:52 -0400169 const gl::ProgramState &mState;
Brandon Jonesc9610c52014-08-25 17:02:59 -0700170};
171
Jamie Madill6f755b22018-10-09 12:48:54 -0400172inline angle::Result ProgramImpl::syncState(const gl::Context *context,
173 const gl::Program::DirtyBits &dirtyBits)
Jamie Madill70aeda42018-08-20 12:17:40 -0400174{
Jamie Madill7c985f52018-11-29 18:16:17 -0500175 return angle::Result::Continue;
Jamie Madill70aeda42018-08-20 12:17:40 -0400176}
177
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500178} // namespace rx
Brandon Jonesc9610c52014-08-25 17:02:59 -0700179
Jamie Madillb980c562018-11-27 11:34:27 -0500180#endif // LIBANGLE_RENDERER_PROGRAMIMPL_H_