blob: 6ad99994b3423fe6fc13f5dd09892e53d765950c [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 Madill192745a2016-12-22 15:58:21 -050024}
25
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) {}
55 angle::Result wait(const gl::Context *context) override { return mResult; }
jchen107ae70d82018-07-06 13:47:01 +080056 bool isLinking() override { return false; }
57
58 private:
Jamie Madill785e8a02018-10-04 17:42:00 -040059 angle::Result mResult;
jchen107ae70d82018-07-06 13:47:01 +080060};
61
Jamie Madillf0d10f82015-03-31 12:56:52 -040062class ProgramImpl : angle::NonCopyable
Brandon Jonesc9610c52014-08-25 17:02:59 -070063{
Brandon Jones1a8a7e32014-10-01 12:49:30 -070064 public:
Jamie Madill48ef11b2016-04-27 15:21:52 -040065 ProgramImpl(const gl::ProgramState &state) : mState(state) {}
Jamie Madill62d31cb2015-09-11 13:25:51 -040066 virtual ~ProgramImpl() {}
Jamie Madillf4a789f2018-10-18 16:56:20 -040067 virtual void destroy(const gl::Context *context) {}
Brandon Jones1a8a7e32014-10-01 12:49:30 -070068
Jamie Madill785e8a02018-10-04 17:42:00 -040069 virtual angle::Result load(const gl::Context *context,
70 gl::InfoLog &infoLog,
71 gl::BinaryInputStream *stream) = 0;
Jamie Madill27a60632017-06-30 15:12:01 -040072 virtual void save(const gl::Context *context, gl::BinaryOutputStream *stream) = 0;
Geoff Langc5629752015-12-07 16:29:04 -050073 virtual void setBinaryRetrievableHint(bool retrievable) = 0;
Yunchao He61afff12017-03-14 15:34:03 +080074 virtual void setSeparable(bool separable) = 0;
Brandon Jones22502d52014-08-29 16:58:36 -070075
jchen107ae70d82018-07-06 13:47:01 +080076 virtual std::unique_ptr<LinkEvent> link(const gl::Context *context,
77 const gl::ProgramLinkedResources &resources,
78 gl::InfoLog &infoLog) = 0;
Jamie Madill36cfd6a2015-08-18 10:46:20 -040079 virtual GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) = 0;
80
Brandon Jones1a8a7e32014-10-01 12:49:30 -070081 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;
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;
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;
93 virtual void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
94 virtual void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
95 virtual void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
96 virtual void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
97 virtual void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
98 virtual void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
99 virtual void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
100 virtual void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
101 virtual void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
Brandon Jonesc9610c52014-08-25 17:02:59 -0700102
Jamie Madill54164b02017-08-28 15:17:37 -0400103 // Done in the back-end to avoid having to keep a system copy of uniform data.
104 virtual void getUniformfv(const gl::Context *context,
105 GLint location,
106 GLfloat *params) const = 0;
107 virtual void getUniformiv(const gl::Context *context, GLint location, GLint *params) const = 0;
108 virtual void getUniformuiv(const gl::Context *context,
109 GLint location,
110 GLuint *params) const = 0;
111
Sami Väisänen46eaa942016-06-29 10:26:37 +0300112 // CHROMIUM_path_rendering
113 // Set parameters to control fragment shader input variable interpolation
114 virtual void setPathFragmentInputGen(const std::string &inputName,
115 GLenum genMode,
116 GLint components,
117 const GLfloat *coeffs) = 0;
Jamie Madill811b6352015-02-09 10:17:09 -0500118
Jamie Madill54164b02017-08-28 15:17:37 -0400119 // Implementation-specific method for ignoring unreferenced uniforms. Some implementations may
120 // perform more extensive analysis and ignore some locations that ANGLE doesn't detect as
121 // unreferenced. This method is not required to be overriden by a back-end.
Jamie Madillfb997ec2017-09-20 15:44:27 -0400122 virtual void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
Qin Jiajia47f6dd02018-08-10 13:36:32 +0800123 std::vector<gl::SamplerBinding> *samplerBindings,
124 std::vector<gl::ImageBinding> *imageBindings)
Jamie Madillfb997ec2017-09-20 15:44:27 -0400125 {
126 }
Jamie Madill54164b02017-08-28 15:17:37 -0400127
Jamie Madill2274b652018-05-31 10:56:08 -0400128 const gl::ProgramState &getState() const { return mState; }
129
Jamie Madill6f755b22018-10-09 12:48:54 -0400130 virtual angle::Result syncState(const gl::Context *context,
131 const gl::Program::DirtyBits &dirtyBits);
Jamie Madill70aeda42018-08-20 12:17:40 -0400132
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700133 protected:
Jamie Madill48ef11b2016-04-27 15:21:52 -0400134 const gl::ProgramState &mState;
Brandon Jonesc9610c52014-08-25 17:02:59 -0700135};
136
Jamie Madill6f755b22018-10-09 12:48:54 -0400137inline angle::Result ProgramImpl::syncState(const gl::Context *context,
138 const gl::Program::DirtyBits &dirtyBits)
Jamie Madill70aeda42018-08-20 12:17:40 -0400139{
Jamie Madill6f755b22018-10-09 12:48:54 -0400140 return angle::Result::Continue();
Jamie Madill70aeda42018-08-20 12:17:40 -0400141}
142
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500143} // namespace rx
Brandon Jonesc9610c52014-08-25 17:02:59 -0700144
Geoff Lang0a73dd82014-11-19 16:18:08 -0500145#endif // LIBANGLE_RENDERER_PROGRAMIMPL_H_