• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // VertexArrayMtl.h:
7 //    Defines the class interface for VertexArrayMtl, implementing VertexArrayImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_METAL_VERTEXARRAYMTL_H_
11 #define LIBANGLE_RENDERER_METAL_VERTEXARRAYMTL_H_
12 
13 #include "libANGLE/renderer/VertexArrayImpl.h"
14 #include "libANGLE/renderer/metal/BufferMtl.h"
15 #include "libANGLE/renderer/metal/mtl_buffer_pool.h"
16 #include "libANGLE/renderer/metal/mtl_command_buffer.h"
17 #include "libANGLE/renderer/metal/mtl_format_utils.h"
18 #include "libANGLE/renderer/metal/mtl_resources.h"
19 
20 namespace rx
21 {
22 class ContextMtl;
23 
24 class VertexArrayMtl : public VertexArrayImpl
25 {
26   public:
27     VertexArrayMtl(const gl::VertexArrayState &state, ContextMtl *context);
28     ~VertexArrayMtl() override;
29 
30     void destroy(const gl::Context *context) override;
31 
32     angle::Result syncState(const gl::Context *context,
33                             const gl::VertexArray::DirtyBits &dirtyBits,
34                             gl::VertexArray::DirtyAttribBitsArray *attribBits,
35                             gl::VertexArray::DirtyBindingBitsArray *bindingBits) override;
36 
37     // Feed client side's vertex/index data
38     angle::Result updateClientAttribs(const gl::Context *context,
39                                       GLint firstVertex,
40                                       GLsizei vertexOrIndexCount,
41                                       GLsizei instanceCount,
42                                       gl::DrawElementsType indexTypeOrInvalid,
43                                       const void *indices);
44 
45     // vertexDescChanged is both input and output, the input value if is true, will force new
46     // mtl::VertexDesc to be returned via vertexDescOut. Otherwise, it is only returned when the
47     // vertex array is dirty
48     angle::Result setupDraw(const gl::Context *glContext,
49                             mtl::RenderCommandEncoder *cmdEncoder,
50                             bool *vertexDescChanged,
51                             mtl::VertexDesc *vertexDescOut);
52 
53     angle::Result getIndexBuffer(const gl::Context *glContext,
54                                  gl::DrawElementsType indexType,
55                                  size_t indexCount,
56                                  const void *sourcePointer,
57                                  mtl::BufferRef *idxBufferOut,
58                                  size_t *idxBufferOffsetOut,
59                                  gl::DrawElementsType *indexTypeOut);
60 
61   private:
62     void reset(ContextMtl *context);
63 
64     angle::Result syncDirtyAttrib(const gl::Context *glContext,
65                                   const gl::VertexAttribute &attrib,
66                                   const gl::VertexBinding &binding,
67                                   size_t attribIndex);
68 
69     angle::Result convertIndexBuffer(const gl::Context *glContext,
70                                      gl::DrawElementsType indexType,
71                                      size_t offset,
72                                      mtl::BufferRef *idxBufferOut,
73                                      size_t *idxBufferOffsetOut);
74     angle::Result streamIndexBufferFromClient(const gl::Context *glContext,
75                                               gl::DrawElementsType indexType,
76                                               size_t indexCount,
77                                               const void *sourcePointer,
78                                               mtl::BufferRef *idxBufferOut,
79                                               size_t *idxBufferOffsetOut);
80 
81     angle::Result convertIndexBufferGPU(const gl::Context *glContext,
82                                         gl::DrawElementsType indexType,
83                                         BufferMtl *idxBuffer,
84                                         size_t offset,
85                                         size_t indexCount,
86                                         IndexConversionBufferMtl *conversion);
87 
88     angle::Result convertVertexBuffer(const gl::Context *glContext,
89                                       BufferMtl *srcBuffer,
90                                       const gl::VertexBinding &binding,
91                                       size_t attribIndex,
92                                       const mtl::VertexFormat &vertexFormat);
93 
94     angle::Result convertVertexBufferCPU(const gl::Context *glContext,
95                                          BufferMtl *srcBuffer,
96                                          const gl::VertexBinding &binding,
97                                          size_t attribIndex,
98                                          const mtl::VertexFormat &vertexFormat,
99                                          ConversionBufferMtl *conversion);
100 
101     // These can point to real BufferMtl or converted buffer in mConvertedArrayBufferHolders
102     gl::AttribArray<BufferHolderMtl *> mCurrentArrayBuffers;
103     gl::AttribArray<SimpleWeakBufferHolderMtl> mConvertedArrayBufferHolders;
104     gl::AttribArray<size_t> mCurrentArrayBufferOffsets;
105     gl::AttribArray<GLuint> mCurrentArrayBufferStrides;
106     gl::AttribArray<const mtl::VertexFormat *> mCurrentArrayBufferFormats;
107 
108     mtl::BufferPool mDynamicVertexData;
109     mtl::BufferPool mDynamicIndexData;
110 
111     bool mVertexArrayDirty = true;
112 };
113 }  // namespace rx
114 
115 #endif /* LIBANGLE_RENDERER_METAL_VERTEXARRAYMTL_H_ */
116