xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/metal/ProgramExecutableMtl.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2023 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker // ProgramExecutableMtl.h: Implementation of ProgramExecutableImpl.
8*8975f5c5SAndroid Build Coastguard Worker 
9*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_RENDERER_MTL_PROGRAMEXECUTABLEMTL_H_
10*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_RENDERER_MTL_PROGRAMEXECUTABLEMTL_H_
11*8975f5c5SAndroid Build Coastguard Worker 
12*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/ProgramExecutable.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/ProgramExecutableImpl.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/metal/mtl_buffer_pool.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/metal/mtl_command_buffer.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/metal/mtl_common.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/metal/mtl_msl_utils.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/metal/mtl_resources.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/metal/mtl_state_cache.h"
20*8975f5c5SAndroid Build Coastguard Worker 
21*8975f5c5SAndroid Build Coastguard Worker namespace rx
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker class ContextMtl;
24*8975f5c5SAndroid Build Coastguard Worker 
25*8975f5c5SAndroid Build Coastguard Worker struct UBOConversionInfo
26*8975f5c5SAndroid Build Coastguard Worker {
27*8975f5c5SAndroid Build Coastguard Worker 
UBOConversionInfoUBOConversionInfo28*8975f5c5SAndroid Build Coastguard Worker     UBOConversionInfo(const std::vector<sh::BlockMemberInfo> &stdInfo,
29*8975f5c5SAndroid Build Coastguard Worker                       const std::vector<sh::BlockMemberInfo> &metalInfo,
30*8975f5c5SAndroid Build Coastguard Worker                       size_t stdSize,
31*8975f5c5SAndroid Build Coastguard Worker                       size_t metalSize)
32*8975f5c5SAndroid Build Coastguard Worker         : _stdInfo(stdInfo), _metalInfo(metalInfo), _stdSize(stdSize), _metalSize(metalSize)
33*8975f5c5SAndroid Build Coastguard Worker     {
34*8975f5c5SAndroid Build Coastguard Worker         _needsConversion = _calculateNeedsConversion();
35*8975f5c5SAndroid Build Coastguard Worker     }
stdInfoUBOConversionInfo36*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::BlockMemberInfo> &stdInfo() const { return _stdInfo; }
metalInfoUBOConversionInfo37*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::BlockMemberInfo> &metalInfo() const { return _metalInfo; }
stdSizeUBOConversionInfo38*8975f5c5SAndroid Build Coastguard Worker     size_t stdSize() const { return _stdSize; }
metalSizeUBOConversionInfo39*8975f5c5SAndroid Build Coastguard Worker     size_t metalSize() const { return _metalSize; }
40*8975f5c5SAndroid Build Coastguard Worker 
needsConversionUBOConversionInfo41*8975f5c5SAndroid Build Coastguard Worker     bool needsConversion() const { return _needsConversion; }
42*8975f5c5SAndroid Build Coastguard Worker 
43*8975f5c5SAndroid Build Coastguard Worker   private:
44*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::BlockMemberInfo> _stdInfo, _metalInfo;
45*8975f5c5SAndroid Build Coastguard Worker     size_t _stdSize, _metalSize;
46*8975f5c5SAndroid Build Coastguard Worker     bool _needsConversion;
47*8975f5c5SAndroid Build Coastguard Worker 
_calculateNeedsConversionUBOConversionInfo48*8975f5c5SAndroid Build Coastguard Worker     bool _calculateNeedsConversion()
49*8975f5c5SAndroid Build Coastguard Worker     {
50*8975f5c5SAndroid Build Coastguard Worker         // If we have a different number of fields then we need conversion
51*8975f5c5SAndroid Build Coastguard Worker         if (_stdInfo.size() != _metalInfo.size())
52*8975f5c5SAndroid Build Coastguard Worker         {
53*8975f5c5SAndroid Build Coastguard Worker             return true;
54*8975f5c5SAndroid Build Coastguard Worker         }
55*8975f5c5SAndroid Build Coastguard Worker         for (size_t i = 0; i < _stdInfo.size(); ++i)
56*8975f5c5SAndroid Build Coastguard Worker         {
57*8975f5c5SAndroid Build Coastguard Worker             // If the matrix is transposed
58*8975f5c5SAndroid Build Coastguard Worker             if (_stdInfo[i].isRowMajorMatrix)
59*8975f5c5SAndroid Build Coastguard Worker             {
60*8975f5c5SAndroid Build Coastguard Worker                 return true;
61*8975f5c5SAndroid Build Coastguard Worker             }
62*8975f5c5SAndroid Build Coastguard Worker             // If we have a bool
63*8975f5c5SAndroid Build Coastguard Worker             if (gl::VariableComponentType(_stdInfo[i].type) == GL_BOOL)
64*8975f5c5SAndroid Build Coastguard Worker             {
65*8975f5c5SAndroid Build Coastguard Worker                 return true;
66*8975f5c5SAndroid Build Coastguard Worker             }
67*8975f5c5SAndroid Build Coastguard Worker             // If any offset information is different
68*8975f5c5SAndroid Build Coastguard Worker             if (!(_stdInfo[i] == _metalInfo[i]))
69*8975f5c5SAndroid Build Coastguard Worker             {
70*8975f5c5SAndroid Build Coastguard Worker                 return true;
71*8975f5c5SAndroid Build Coastguard Worker             }
72*8975f5c5SAndroid Build Coastguard Worker         }
73*8975f5c5SAndroid Build Coastguard Worker         return false;
74*8975f5c5SAndroid Build Coastguard Worker     }
75*8975f5c5SAndroid Build Coastguard Worker };
76*8975f5c5SAndroid Build Coastguard Worker 
77*8975f5c5SAndroid Build Coastguard Worker struct ProgramArgumentBufferEncoderMtl
78*8975f5c5SAndroid Build Coastguard Worker {
79*8975f5c5SAndroid Build Coastguard Worker     void reset(ContextMtl *contextMtl);
80*8975f5c5SAndroid Build Coastguard Worker 
81*8975f5c5SAndroid Build Coastguard Worker     mtl::AutoObjCPtr<id<MTLArgumentEncoder>> metalArgBufferEncoder;
82*8975f5c5SAndroid Build Coastguard Worker     mtl::BufferPool bufferPool;
83*8975f5c5SAndroid Build Coastguard Worker };
84*8975f5c5SAndroid Build Coastguard Worker 
85*8975f5c5SAndroid Build Coastguard Worker constexpr size_t kFragmentShaderVariants = 4;
86*8975f5c5SAndroid Build Coastguard Worker 
87*8975f5c5SAndroid Build Coastguard Worker // Represents a specialized shader variant. For example, a shader variant with fragment coverage
88*8975f5c5SAndroid Build Coastguard Worker // mask enabled and a shader variant without.
89*8975f5c5SAndroid Build Coastguard Worker struct ProgramShaderObjVariantMtl
90*8975f5c5SAndroid Build Coastguard Worker {
91*8975f5c5SAndroid Build Coastguard Worker     void reset(ContextMtl *contextMtl);
92*8975f5c5SAndroid Build Coastguard Worker 
93*8975f5c5SAndroid Build Coastguard Worker     mtl::AutoObjCPtr<id<MTLFunction>> metalShader;
94*8975f5c5SAndroid Build Coastguard Worker     // UBO's argument buffer encoder. Used when number of UBOs used exceeds number of allowed
95*8975f5c5SAndroid Build Coastguard Worker     // discrete slots, and thus needs to encode all into one argument buffer.
96*8975f5c5SAndroid Build Coastguard Worker     ProgramArgumentBufferEncoderMtl uboArgBufferEncoder;
97*8975f5c5SAndroid Build Coastguard Worker 
98*8975f5c5SAndroid Build Coastguard Worker     // Store reference to the TranslatedShaderInfo to easy querying mapped textures/UBO/XFB
99*8975f5c5SAndroid Build Coastguard Worker     // bindings.
100*8975f5c5SAndroid Build Coastguard Worker     const mtl::TranslatedShaderInfo *translatedSrcInfo;
101*8975f5c5SAndroid Build Coastguard Worker };
102*8975f5c5SAndroid Build Coastguard Worker 
103*8975f5c5SAndroid Build Coastguard Worker // State for the default uniform blocks.
104*8975f5c5SAndroid Build Coastguard Worker struct DefaultUniformBlockMtl final : private angle::NonCopyable
105*8975f5c5SAndroid Build Coastguard Worker {
106*8975f5c5SAndroid Build Coastguard Worker     DefaultUniformBlockMtl();
107*8975f5c5SAndroid Build Coastguard Worker     ~DefaultUniformBlockMtl();
108*8975f5c5SAndroid Build Coastguard Worker 
109*8975f5c5SAndroid Build Coastguard Worker     // Shadow copies of the shader uniform data.
110*8975f5c5SAndroid Build Coastguard Worker     angle::MemoryBuffer uniformData;
111*8975f5c5SAndroid Build Coastguard Worker 
112*8975f5c5SAndroid Build Coastguard Worker     // Since the default blocks are laid out in std140, this tells us where to write on a call
113*8975f5c5SAndroid Build Coastguard Worker     // to a setUniform method. They are arranged in uniform location order.
114*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::BlockMemberInfo> uniformLayout;
115*8975f5c5SAndroid Build Coastguard Worker };
116*8975f5c5SAndroid Build Coastguard Worker 
117*8975f5c5SAndroid Build Coastguard Worker class ProgramExecutableMtl : public ProgramExecutableImpl
118*8975f5c5SAndroid Build Coastguard Worker {
119*8975f5c5SAndroid Build Coastguard Worker   public:
120*8975f5c5SAndroid Build Coastguard Worker     ProgramExecutableMtl(const gl::ProgramExecutable *executable);
121*8975f5c5SAndroid Build Coastguard Worker     ~ProgramExecutableMtl() override;
122*8975f5c5SAndroid Build Coastguard Worker 
123*8975f5c5SAndroid Build Coastguard Worker     void destroy(const gl::Context *context) override;
124*8975f5c5SAndroid Build Coastguard Worker 
125*8975f5c5SAndroid Build Coastguard Worker     angle::Result load(ContextMtl *contextMtl, gl::BinaryInputStream *stream);
126*8975f5c5SAndroid Build Coastguard Worker     void save(gl::BinaryOutputStream *stream);
127*8975f5c5SAndroid Build Coastguard Worker 
128*8975f5c5SAndroid Build Coastguard Worker     void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override;
129*8975f5c5SAndroid Build Coastguard Worker     void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override;
130*8975f5c5SAndroid Build Coastguard Worker     void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override;
131*8975f5c5SAndroid Build Coastguard Worker     void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override;
132*8975f5c5SAndroid Build Coastguard Worker     void setUniform1iv(GLint location, GLsizei count, const GLint *v) override;
133*8975f5c5SAndroid Build Coastguard Worker     void setUniform2iv(GLint location, GLsizei count, const GLint *v) override;
134*8975f5c5SAndroid Build Coastguard Worker     void setUniform3iv(GLint location, GLsizei count, const GLint *v) override;
135*8975f5c5SAndroid Build Coastguard Worker     void setUniform4iv(GLint location, GLsizei count, const GLint *v) override;
136*8975f5c5SAndroid Build Coastguard Worker     void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override;
137*8975f5c5SAndroid Build Coastguard Worker     void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override;
138*8975f5c5SAndroid Build Coastguard Worker     void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override;
139*8975f5c5SAndroid Build Coastguard Worker     void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override;
140*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix2fv(GLint location,
141*8975f5c5SAndroid Build Coastguard Worker                              GLsizei count,
142*8975f5c5SAndroid Build Coastguard Worker                              GLboolean transpose,
143*8975f5c5SAndroid Build Coastguard Worker                              const GLfloat *value) override;
144*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix3fv(GLint location,
145*8975f5c5SAndroid Build Coastguard Worker                              GLsizei count,
146*8975f5c5SAndroid Build Coastguard Worker                              GLboolean transpose,
147*8975f5c5SAndroid Build Coastguard Worker                              const GLfloat *value) override;
148*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix4fv(GLint location,
149*8975f5c5SAndroid Build Coastguard Worker                              GLsizei count,
150*8975f5c5SAndroid Build Coastguard Worker                              GLboolean transpose,
151*8975f5c5SAndroid Build Coastguard Worker                              const GLfloat *value) override;
152*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix2x3fv(GLint location,
153*8975f5c5SAndroid Build Coastguard Worker                                GLsizei count,
154*8975f5c5SAndroid Build Coastguard Worker                                GLboolean transpose,
155*8975f5c5SAndroid Build Coastguard Worker                                const GLfloat *value) override;
156*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix3x2fv(GLint location,
157*8975f5c5SAndroid Build Coastguard Worker                                GLsizei count,
158*8975f5c5SAndroid Build Coastguard Worker                                GLboolean transpose,
159*8975f5c5SAndroid Build Coastguard Worker                                const GLfloat *value) override;
160*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix2x4fv(GLint location,
161*8975f5c5SAndroid Build Coastguard Worker                                GLsizei count,
162*8975f5c5SAndroid Build Coastguard Worker                                GLboolean transpose,
163*8975f5c5SAndroid Build Coastguard Worker                                const GLfloat *value) override;
164*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix4x2fv(GLint location,
165*8975f5c5SAndroid Build Coastguard Worker                                GLsizei count,
166*8975f5c5SAndroid Build Coastguard Worker                                GLboolean transpose,
167*8975f5c5SAndroid Build Coastguard Worker                                const GLfloat *value) override;
168*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix3x4fv(GLint location,
169*8975f5c5SAndroid Build Coastguard Worker                                GLsizei count,
170*8975f5c5SAndroid Build Coastguard Worker                                GLboolean transpose,
171*8975f5c5SAndroid Build Coastguard Worker                                const GLfloat *value) override;
172*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrix4x3fv(GLint location,
173*8975f5c5SAndroid Build Coastguard Worker                                GLsizei count,
174*8975f5c5SAndroid Build Coastguard Worker                                GLboolean transpose,
175*8975f5c5SAndroid Build Coastguard Worker                                const GLfloat *value) override;
176*8975f5c5SAndroid Build Coastguard Worker 
177*8975f5c5SAndroid Build Coastguard Worker     void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override;
178*8975f5c5SAndroid Build Coastguard Worker     void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override;
179*8975f5c5SAndroid Build Coastguard Worker     void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override;
180*8975f5c5SAndroid Build Coastguard Worker 
hasFlatAttribute()181*8975f5c5SAndroid Build Coastguard Worker     bool hasFlatAttribute() const { return mProgramHasFlatAttributes; }
182*8975f5c5SAndroid Build Coastguard Worker 
183*8975f5c5SAndroid Build Coastguard Worker     // Calls this before drawing, changedPipelineDesc is passed when vertex attributes desc and/or
184*8975f5c5SAndroid Build Coastguard Worker     // shader program changed.
185*8975f5c5SAndroid Build Coastguard Worker     angle::Result setupDraw(const gl::Context *glContext,
186*8975f5c5SAndroid Build Coastguard Worker                             mtl::RenderCommandEncoder *cmdEncoder,
187*8975f5c5SAndroid Build Coastguard Worker                             const mtl::RenderPipelineDesc &pipelineDesc,
188*8975f5c5SAndroid Build Coastguard Worker                             bool pipelineDescChanged,
189*8975f5c5SAndroid Build Coastguard Worker                             bool forceTexturesSetting,
190*8975f5c5SAndroid Build Coastguard Worker                             bool uniformBuffersDirty);
191*8975f5c5SAndroid Build Coastguard Worker 
192*8975f5c5SAndroid Build Coastguard Worker   private:
193*8975f5c5SAndroid Build Coastguard Worker     friend class ProgramMtl;
194*8975f5c5SAndroid Build Coastguard Worker 
195*8975f5c5SAndroid Build Coastguard Worker     void reset(ContextMtl *context);
196*8975f5c5SAndroid Build Coastguard Worker 
197*8975f5c5SAndroid Build Coastguard Worker     template <int cols, int rows>
198*8975f5c5SAndroid Build Coastguard Worker     void setUniformMatrixfv(GLint location,
199*8975f5c5SAndroid Build Coastguard Worker                             GLsizei count,
200*8975f5c5SAndroid Build Coastguard Worker                             GLboolean transpose,
201*8975f5c5SAndroid Build Coastguard Worker                             const GLfloat *value);
202*8975f5c5SAndroid Build Coastguard Worker     template <class T>
203*8975f5c5SAndroid Build Coastguard Worker     void getUniformImpl(GLint location, T *v, GLenum entryPointType) const;
204*8975f5c5SAndroid Build Coastguard Worker 
205*8975f5c5SAndroid Build Coastguard Worker     template <typename T>
206*8975f5c5SAndroid Build Coastguard Worker     void setUniformImpl(GLint location, GLsizei count, const T *v, GLenum entryPointType);
207*8975f5c5SAndroid Build Coastguard Worker 
208*8975f5c5SAndroid Build Coastguard Worker     void saveTranslatedShaders(gl::BinaryOutputStream *stream);
209*8975f5c5SAndroid Build Coastguard Worker     void loadTranslatedShaders(gl::BinaryInputStream *stream);
210*8975f5c5SAndroid Build Coastguard Worker 
211*8975f5c5SAndroid Build Coastguard Worker     void saveShaderInternalInfo(gl::BinaryOutputStream *stream);
212*8975f5c5SAndroid Build Coastguard Worker     void loadShaderInternalInfo(gl::BinaryInputStream *stream);
213*8975f5c5SAndroid Build Coastguard Worker 
214*8975f5c5SAndroid Build Coastguard Worker     void saveInterfaceBlockInfo(gl::BinaryOutputStream *stream);
215*8975f5c5SAndroid Build Coastguard Worker     angle::Result loadInterfaceBlockInfo(gl::BinaryInputStream *stream);
216*8975f5c5SAndroid Build Coastguard Worker 
217*8975f5c5SAndroid Build Coastguard Worker     void saveDefaultUniformBlocksInfo(gl::BinaryOutputStream *stream);
218*8975f5c5SAndroid Build Coastguard Worker     angle::Result loadDefaultUniformBlocksInfo(mtl::Context *context,
219*8975f5c5SAndroid Build Coastguard Worker                                                gl::BinaryInputStream *stream);
220*8975f5c5SAndroid Build Coastguard Worker 
221*8975f5c5SAndroid Build Coastguard Worker     void linkUpdateHasFlatAttributes(const gl::SharedCompiledShaderState &vertexShader);
222*8975f5c5SAndroid Build Coastguard Worker 
223*8975f5c5SAndroid Build Coastguard Worker     angle::Result initDefaultUniformBlocks(
224*8975f5c5SAndroid Build Coastguard Worker         mtl::Context *context,
225*8975f5c5SAndroid Build Coastguard Worker         const gl::ShaderMap<gl::SharedCompiledShaderState> &shaders);
226*8975f5c5SAndroid Build Coastguard Worker     angle::Result resizeDefaultUniformBlocksMemory(mtl::Context *context,
227*8975f5c5SAndroid Build Coastguard Worker                                                    const gl::ShaderMap<size_t> &requiredBufferSize);
228*8975f5c5SAndroid Build Coastguard Worker     void initUniformBlocksRemapper(const gl::SharedCompiledShaderState &shader);
229*8975f5c5SAndroid Build Coastguard Worker 
230*8975f5c5SAndroid Build Coastguard Worker     mtl::BufferPool *getBufferPool(ContextMtl *context, gl::ShaderType shaderType);
231*8975f5c5SAndroid Build Coastguard Worker 
232*8975f5c5SAndroid Build Coastguard Worker     angle::Result getSpecializedShader(ContextMtl *context,
233*8975f5c5SAndroid Build Coastguard Worker                                        gl::ShaderType shaderType,
234*8975f5c5SAndroid Build Coastguard Worker                                        const mtl::RenderPipelineDesc &renderPipelineDesc,
235*8975f5c5SAndroid Build Coastguard Worker                                        id<MTLFunction> *shaderOut);
236*8975f5c5SAndroid Build Coastguard Worker 
237*8975f5c5SAndroid Build Coastguard Worker     angle::Result commitUniforms(ContextMtl *context, mtl::RenderCommandEncoder *cmdEncoder);
238*8975f5c5SAndroid Build Coastguard Worker     angle::Result updateTextures(const gl::Context *glContext,
239*8975f5c5SAndroid Build Coastguard Worker                                  mtl::RenderCommandEncoder *cmdEncoder,
240*8975f5c5SAndroid Build Coastguard Worker                                  bool forceUpdate);
241*8975f5c5SAndroid Build Coastguard Worker 
242*8975f5c5SAndroid Build Coastguard Worker     angle::Result updateUniformBuffers(ContextMtl *context,
243*8975f5c5SAndroid Build Coastguard Worker                                        mtl::RenderCommandEncoder *cmdEncoder,
244*8975f5c5SAndroid Build Coastguard Worker                                        const mtl::RenderPipelineDesc &pipelineDesc);
245*8975f5c5SAndroid Build Coastguard Worker     angle::Result updateXfbBuffers(ContextMtl *context,
246*8975f5c5SAndroid Build Coastguard Worker                                    mtl::RenderCommandEncoder *cmdEncoder,
247*8975f5c5SAndroid Build Coastguard Worker                                    const mtl::RenderPipelineDesc &pipelineDesc);
248*8975f5c5SAndroid Build Coastguard Worker     angle::Result legalizeUniformBufferOffsets(ContextMtl *context);
249*8975f5c5SAndroid Build Coastguard Worker     angle::Result bindUniformBuffersToDiscreteSlots(ContextMtl *context,
250*8975f5c5SAndroid Build Coastguard Worker                                                     mtl::RenderCommandEncoder *cmdEncoder,
251*8975f5c5SAndroid Build Coastguard Worker                                                     gl::ShaderType shaderType);
252*8975f5c5SAndroid Build Coastguard Worker 
253*8975f5c5SAndroid Build Coastguard Worker     angle::Result encodeUniformBuffersInfoArgumentBuffer(ContextMtl *context,
254*8975f5c5SAndroid Build Coastguard Worker                                                          mtl::RenderCommandEncoder *cmdEncoder,
255*8975f5c5SAndroid Build Coastguard Worker                                                          gl::ShaderType shaderType);
256*8975f5c5SAndroid Build Coastguard Worker 
257*8975f5c5SAndroid Build Coastguard Worker     bool mProgramHasFlatAttributes;
258*8975f5c5SAndroid Build Coastguard Worker 
259*8975f5c5SAndroid Build Coastguard Worker     gl::ShaderMap<DefaultUniformBlockMtl> mDefaultUniformBlocks;
260*8975f5c5SAndroid Build Coastguard Worker     std::unordered_map<std::string, UBOConversionInfo> mUniformBlockConversions;
261*8975f5c5SAndroid Build Coastguard Worker 
262*8975f5c5SAndroid Build Coastguard Worker     // Translated metal shaders:
263*8975f5c5SAndroid Build Coastguard Worker     gl::ShaderMap<mtl::TranslatedShaderInfo> mMslShaderTranslateInfo;
264*8975f5c5SAndroid Build Coastguard Worker 
265*8975f5c5SAndroid Build Coastguard Worker     // Translated metal version for transform feedback only vertex shader:
266*8975f5c5SAndroid Build Coastguard Worker     // - Metal doesn't allow vertex shader to write to both buffers and to stage output
267*8975f5c5SAndroid Build Coastguard Worker     // (gl_Position). Need a special version of vertex shader that only writes to transform feedback
268*8975f5c5SAndroid Build Coastguard Worker     // buffers.
269*8975f5c5SAndroid Build Coastguard Worker     mtl::TranslatedShaderInfo mMslXfbOnlyVertexShaderInfo;
270*8975f5c5SAndroid Build Coastguard Worker 
271*8975f5c5SAndroid Build Coastguard Worker     // Compiled native shader object variants:
272*8975f5c5SAndroid Build Coastguard Worker     // - Vertex shader: One with emulated rasterization discard, one with true rasterization
273*8975f5c5SAndroid Build Coastguard Worker     // discard, one without.
274*8975f5c5SAndroid Build Coastguard Worker     mtl::RenderPipelineRasterStateMap<ProgramShaderObjVariantMtl> mVertexShaderVariants;
275*8975f5c5SAndroid Build Coastguard Worker     // - Fragment shader: Combinations of sample coverage mask and depth write enabled states.
276*8975f5c5SAndroid Build Coastguard Worker     std::array<ProgramShaderObjVariantMtl, kFragmentShaderVariants> mFragmentShaderVariants;
277*8975f5c5SAndroid Build Coastguard Worker 
278*8975f5c5SAndroid Build Coastguard Worker     // Cached references of current shader variants.
279*8975f5c5SAndroid Build Coastguard Worker     gl::ShaderMap<ProgramShaderObjVariantMtl *> mCurrentShaderVariants;
280*8975f5c5SAndroid Build Coastguard Worker 
281*8975f5c5SAndroid Build Coastguard Worker     gl::ShaderBitSet mDefaultUniformBlocksDirty;
282*8975f5c5SAndroid Build Coastguard Worker     gl::ShaderBitSet mSamplerBindingsDirty;
283*8975f5c5SAndroid Build Coastguard Worker 
284*8975f5c5SAndroid Build Coastguard Worker     // Scratch data:
285*8975f5c5SAndroid Build Coastguard Worker     // Legalized buffers and their offsets. For example, uniform buffer's offset=1 is not a valid
286*8975f5c5SAndroid Build Coastguard Worker     // offset, it will be converted to legal offset and the result is stored in this array.
287*8975f5c5SAndroid Build Coastguard Worker     std::vector<std::pair<mtl::BufferRef, uint32_t>> mLegalizedOffsetedUniformBuffers;
288*8975f5c5SAndroid Build Coastguard Worker     // Stores the render stages usage of each uniform buffer. Only used if the buffers are encoded
289*8975f5c5SAndroid Build Coastguard Worker     // into an argument buffer.
290*8975f5c5SAndroid Build Coastguard Worker     std::vector<uint32_t> mArgumentBufferRenderStageUsages;
291*8975f5c5SAndroid Build Coastguard Worker 
292*8975f5c5SAndroid Build Coastguard Worker     uint32_t mShadowCompareModes[mtl::kMaxShaderSamplers];
293*8975f5c5SAndroid Build Coastguard Worker 
294*8975f5c5SAndroid Build Coastguard Worker     gl::ShaderMap<std::unique_ptr<mtl::BufferPool>> mDefaultUniformBufferPools;
295*8975f5c5SAndroid Build Coastguard Worker };
296*8975f5c5SAndroid Build Coastguard Worker 
297*8975f5c5SAndroid Build Coastguard Worker angle::Result CreateMslShaderLib(mtl::Context *context,
298*8975f5c5SAndroid Build Coastguard Worker                                  gl::InfoLog &infoLog,
299*8975f5c5SAndroid Build Coastguard Worker                                  mtl::TranslatedShaderInfo *translatedMslInfo,
300*8975f5c5SAndroid Build Coastguard Worker                                  const std::map<std::string, std::string> &substitutionMacros);
301*8975f5c5SAndroid Build Coastguard Worker }  // namespace rx
302*8975f5c5SAndroid Build Coastguard Worker 
303*8975f5c5SAndroid Build Coastguard Worker #endif  // LIBANGLE_RENDERER_MTL_PROGRAMEXECUTABLEMTL_H_
304