~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ProgramMtl.h

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright 2019 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
// ProgramMtl.h:
 
7
//    Defines the class interface for ProgramMtl, implementing ProgramImpl.
 
8
//
 
9
 
 
10
#ifndef LIBANGLE_RENDERER_METAL_PROGRAMMTL_H_
 
11
#define LIBANGLE_RENDERER_METAL_PROGRAMMTL_H_
 
12
 
 
13
#import <Metal/Metal.h>
 
14
 
 
15
#include <array>
 
16
 
 
17
#include "common/Optional.h"
 
18
#include "common/utilities.h"
 
19
#include "libANGLE/renderer/ProgramImpl.h"
 
20
#include "libANGLE/renderer/glslang_wrapper_utils.h"
 
21
#include "libANGLE/renderer/metal/mtl_command_buffer.h"
 
22
#include "libANGLE/renderer/metal/mtl_resources.h"
 
23
#include "libANGLE/renderer/metal/mtl_state_cache.h"
 
24
 
 
25
namespace rx
 
26
{
 
27
class ContextMtl;
 
28
 
 
29
class ProgramMtl : public ProgramImpl
 
30
{
 
31
  public:
 
32
    ProgramMtl(const gl::ProgramState &state);
 
33
    ~ProgramMtl() override;
 
34
 
 
35
    void destroy(const gl::Context *context) override;
 
36
 
 
37
    std::unique_ptr<LinkEvent> load(const gl::Context *context,
 
38
                                    gl::BinaryInputStream *stream,
 
39
                                    gl::InfoLog &infoLog) override;
 
40
    void save(const gl::Context *context, gl::BinaryOutputStream *stream) override;
 
41
    void setBinaryRetrievableHint(bool retrievable) override;
 
42
    void setSeparable(bool separable) override;
 
43
 
 
44
    std::unique_ptr<LinkEvent> link(const gl::Context *context,
 
45
                                    const gl::ProgramLinkedResources &resources,
 
46
                                    gl::InfoLog &infoLog) override;
 
47
    GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override;
 
48
 
 
49
    void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override;
 
50
    void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override;
 
51
    void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override;
 
52
    void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override;
 
53
    void setUniform1iv(GLint location, GLsizei count, const GLint *v) override;
 
54
    void setUniform2iv(GLint location, GLsizei count, const GLint *v) override;
 
55
    void setUniform3iv(GLint location, GLsizei count, const GLint *v) override;
 
56
    void setUniform4iv(GLint location, GLsizei count, const GLint *v) override;
 
57
    void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override;
 
58
    void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override;
 
59
    void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override;
 
60
    void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override;
 
61
    void setUniformMatrix2fv(GLint location,
 
62
                             GLsizei count,
 
63
                             GLboolean transpose,
 
64
                             const GLfloat *value) override;
 
65
    void setUniformMatrix3fv(GLint location,
 
66
                             GLsizei count,
 
67
                             GLboolean transpose,
 
68
                             const GLfloat *value) override;
 
69
    void setUniformMatrix4fv(GLint location,
 
70
                             GLsizei count,
 
71
                             GLboolean transpose,
 
72
                             const GLfloat *value) override;
 
73
    void setUniformMatrix2x3fv(GLint location,
 
74
                               GLsizei count,
 
75
                               GLboolean transpose,
 
76
                               const GLfloat *value) override;
 
77
    void setUniformMatrix3x2fv(GLint location,
 
78
                               GLsizei count,
 
79
                               GLboolean transpose,
 
80
                               const GLfloat *value) override;
 
81
    void setUniformMatrix2x4fv(GLint location,
 
82
                               GLsizei count,
 
83
                               GLboolean transpose,
 
84
                               const GLfloat *value) override;
 
85
    void setUniformMatrix4x2fv(GLint location,
 
86
                               GLsizei count,
 
87
                               GLboolean transpose,
 
88
                               const GLfloat *value) override;
 
89
    void setUniformMatrix3x4fv(GLint location,
 
90
                               GLsizei count,
 
91
                               GLboolean transpose,
 
92
                               const GLfloat *value) override;
 
93
    void setUniformMatrix4x3fv(GLint location,
 
94
                               GLsizei count,
 
95
                               GLboolean transpose,
 
96
                               const GLfloat *value) override;
 
97
 
 
98
    void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override;
 
99
    void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override;
 
100
    void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override;
 
101
 
 
102
    void setPathFragmentInputGen(const std::string &inputName,
 
103
                                 GLenum genMode,
 
104
                                 GLint components,
 
105
                                 const GLfloat *coeffs) override;
 
106
 
 
107
    // Calls this before drawing, changedPipelineDesc is passed when vertex attributes desc and/or
 
108
    // shader program changed.
 
109
    angle::Result setupDraw(const gl::Context *glContext,
 
110
                            mtl::RenderCommandEncoder *cmdEncoder,
 
111
                            const Optional<mtl::RenderPipelineDesc> &changedPipelineDesc,
 
112
                            bool forceTexturesSetting);
 
113
 
 
114
  private:
 
115
    template <int cols, int rows>
 
116
    void setUniformMatrixfv(GLint location,
 
117
                            GLsizei count,
 
118
                            GLboolean transpose,
 
119
                            const GLfloat *value);
 
120
    template <class T>
 
121
    void getUniformImpl(GLint location, T *v, GLenum entryPointType) const;
 
122
 
 
123
    template <typename T>
 
124
    void setUniformImpl(GLint location, GLsizei count, const T *v, GLenum entryPointType);
 
125
 
 
126
    angle::Result initDefaultUniformBlocks(const gl::Context *glContext);
 
127
 
 
128
    angle::Result commitUniforms(ContextMtl *context, mtl::RenderCommandEncoder *cmdEncoder);
 
129
    angle::Result updateTextures(const gl::Context *glContext,
 
130
                                 mtl::RenderCommandEncoder *cmdEncoder,
 
131
                                 bool forceUpdate);
 
132
 
 
133
    void reset(ContextMtl *context);
 
134
    void linkResources(const gl::ProgramLinkedResources &resources);
 
135
    angle::Result linkImpl(const gl::Context *glContext, gl::InfoLog &infoLog);
 
136
    angle::Result convertToMsl(const gl::Context *glContext,
 
137
                               gl::ShaderType shaderType,
 
138
                               gl::InfoLog &infoLog,
 
139
                               std::vector<uint32_t> *sprivCode);
 
140
 
 
141
    angle::Result createMslShader(const gl::Context *glContext,
 
142
                                  gl::ShaderType shaderType,
 
143
                                  gl::InfoLog &infoLog,
 
144
                                  const std::string &translatedSource);
 
145
 
 
146
    // State for the default uniform blocks.
 
147
    struct DefaultUniformBlock final : private angle::NonCopyable
 
148
    {
 
149
        DefaultUniformBlock();
 
150
        ~DefaultUniformBlock();
 
151
 
 
152
        // Shadow copies of the shader uniform data.
 
153
        angle::MemoryBuffer uniformData;
 
154
 
 
155
        // Since the default blocks are laid out in std140, this tells us where to write on a call
 
156
        // to a setUniform method. They are arranged in uniform location order.
 
157
        std::vector<sh::BlockMemberInfo> uniformLayout;
 
158
    };
 
159
 
 
160
    gl::ShaderBitSet mDefaultUniformBlocksDirty;
 
161
    gl::ShaderBitSet mSamplerBindingsDirty;
 
162
    gl::ShaderMap<DefaultUniformBlock> mDefaultUniformBlocks;
 
163
 
 
164
    // We keep the translated linked shader sources to use with shader draw call patching.
 
165
    gl::ShaderMap<std::string> mShaderSource;
 
166
    ShaderInterfaceVariableInfoMap mVariableInfoMap;
 
167
 
 
168
    mtl::RenderPipelineCache mMetalRenderPipelineCache;
 
169
};
 
170
 
 
171
}  // namespace rx
 
172
 
 
173
#endif /* LIBANGLE_RENDERER_METAL_PROGRAMMTL_H_ */