• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 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 // VertexArrayVk.h:
7 //    Defines the class interface for VertexArrayVk, implementing VertexArrayImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_
11 #define LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_
12 
13 #include "libANGLE/renderer/VertexArrayImpl.h"
14 #include "libANGLE/renderer/vulkan/vk_cache_utils.h"
15 #include "libANGLE/renderer/vulkan/vk_helpers.h"
16 
17 namespace rx
18 {
19 class BufferVk;
20 struct ConversionBuffer;
21 
22 class VertexArrayVk : public VertexArrayImpl
23 {
24   public:
25     VertexArrayVk(ContextVk *contextVk, const gl::VertexArrayState &state);
26     ~VertexArrayVk() override;
27 
28     void destroy(const gl::Context *context) override;
29 
30     angle::Result syncState(const gl::Context *context,
31                             const gl::VertexArray::DirtyBits &dirtyBits,
32                             gl::VertexArray::DirtyAttribBitsArray *attribBits,
33                             gl::VertexArray::DirtyBindingBitsArray *bindingBits) override;
34 
35     void updateActiveAttribInfo(ContextVk *contextVk);
36 
37     void updateDefaultAttrib(ContextVk *contextVk,
38                              size_t attribIndex,
39                              VkBuffer bufferHandle,
40                              vk::BufferHelper *buffer,
41                              uint32_t offset);
42 
43     angle::Result updateStreamedAttribs(const gl::Context *context,
44                                         GLint firstVertex,
45                                         GLsizei vertexOrIndexCount,
46                                         GLsizei instanceCount,
47                                         gl::DrawElementsType indexTypeOrInvalid,
48                                         const void *indices);
49 
50     angle::Result handleLineLoop(ContextVk *contextVk,
51                                  GLint firstVertex,
52                                  GLsizei vertexOrIndexCount,
53                                  gl::DrawElementsType indexTypeOrInvalid,
54                                  const void *indices,
55                                  uint32_t *indexCountOut);
56 
57     angle::Result handleLineLoopIndexIndirect(ContextVk *contextVk,
58                                               gl::DrawElementsType glIndexType,
59                                               vk::BufferHelper *srcIndirectBuf,
60                                               VkDeviceSize indirectBufferOffset,
61                                               vk::BufferHelper **indirectBufferOut,
62                                               VkDeviceSize *indirectBufferOffsetOut);
63 
64     angle::Result handleLineLoopIndirectDraw(const gl::Context *context,
65                                              vk::BufferHelper *indirectBufferVk,
66                                              VkDeviceSize indirectBufferOffset,
67                                              vk::BufferHelper **indirectBufferOut,
68                                              VkDeviceSize *indirectBufferOffsetOut);
69 
getCurrentArrayBufferHandles()70     const gl::AttribArray<VkBuffer> &getCurrentArrayBufferHandles() const
71     {
72         return mCurrentArrayBufferHandles;
73     }
74 
getCurrentArrayBufferOffsets()75     const gl::AttribArray<VkDeviceSize> &getCurrentArrayBufferOffsets() const
76     {
77         return mCurrentArrayBufferOffsets;
78     }
79 
getCurrentArrayBuffers()80     const gl::AttribArray<vk::BufferHelper *> &getCurrentArrayBuffers() const
81     {
82         return mCurrentArrayBuffers;
83     }
84 
getCurrentElementArrayBufferOffset()85     VkDeviceSize getCurrentElementArrayBufferOffset() const
86     {
87         return mCurrentElementArrayBufferOffset;
88     }
89 
updateCurrentElementArrayBufferOffset(const GLvoid * offset)90     void updateCurrentElementArrayBufferOffset(const GLvoid *offset)
91     {
92         mCurrentElementArrayBufferOffset = reinterpret_cast<VkDeviceSize>(offset);
93     }
94 
getCurrentElementArrayBuffer()95     vk::BufferHelper *getCurrentElementArrayBuffer() const { return mCurrentElementArrayBuffer; }
96 
97     angle::Result convertIndexBufferGPU(ContextVk *contextVk,
98                                         BufferVk *bufferVk,
99                                         const void *indices);
100 
101     angle::Result convertIndexBufferIndirectGPU(ContextVk *contextVk,
102                                                 vk::BufferHelper *srcIndirectBuf,
103                                                 VkDeviceSize srcIndirectBufOffset,
104                                                 vk::BufferHelper **indirectBufferVkOut,
105                                                 VkDeviceSize *indirectBufferVkOffsetOut);
106 
107     angle::Result convertIndexBufferCPU(ContextVk *contextVk,
108                                         gl::DrawElementsType indexType,
109                                         size_t indexCount,
110                                         const void *sourcePointer);
111 
getStreamingVertexAttribsMask()112     const gl::AttributesMask &getStreamingVertexAttribsMask() const
113     {
114         return mStreamingVertexAttribsMask;
115     }
116 
117   private:
118     void setDefaultPackedInput(ContextVk *contextVk, size_t attribIndex);
119 
120     angle::Result convertVertexBufferGPU(ContextVk *contextVk,
121                                          BufferVk *srcBuffer,
122                                          const gl::VertexBinding &binding,
123                                          size_t attribIndex,
124                                          const vk::Format &vertexFormat,
125                                          ConversionBuffer *conversion,
126                                          GLuint relativeOffset);
127     angle::Result convertVertexBufferCPU(ContextVk *contextVk,
128                                          BufferVk *srcBuffer,
129                                          const gl::VertexBinding &binding,
130                                          size_t attribIndex,
131                                          const vk::Format &vertexFormat,
132                                          ConversionBuffer *conversion,
133                                          GLuint relativeOffset);
134 
135     angle::Result syncDirtyAttrib(ContextVk *contextVk,
136                                   const gl::VertexAttribute &attrib,
137                                   const gl::VertexBinding &binding,
138                                   size_t attribIndex,
139                                   bool bufferOnly);
140 
141     gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles;
142     gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets;
143     // The offset into the buffer to the first attrib
144     gl::AttribArray<GLuint> mCurrentArrayBufferRelativeOffsets;
145     gl::AttribArray<vk::BufferHelper *> mCurrentArrayBuffers;
146     // Cache strides of attributes for a fast pipeline cache update when VAOs are changed
147     gl::AttribArray<GLuint> mCurrentArrayBufferStrides;
148     VkDeviceSize mCurrentElementArrayBufferOffset;
149     vk::BufferHelper *mCurrentElementArrayBuffer;
150 
151     vk::DynamicBuffer mDynamicVertexData;
152     vk::DynamicBuffer mDynamicIndexData;
153     vk::DynamicBuffer mTranslatedByteIndexData;
154     vk::DynamicBuffer mTranslatedByteIndirectData;
155 
156     vk::LineLoopHelper mLineLoopHelper;
157     Optional<GLint> mLineLoopBufferFirstIndex;
158     Optional<size_t> mLineLoopBufferLastIndex;
159     bool mDirtyLineLoopTranslation;
160 
161     // Vulkan does not allow binding a null vertex buffer. We use a dummy as a placeholder.
162     vk::BufferHelper mTheNullBuffer;
163 
164     // Track client and/or emulated attribs that we have to stream their buffer contents
165     gl::AttributesMask mStreamingVertexAttribsMask;
166 };
167 }  // namespace rx
168 
169 #endif  // LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_
170