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 enum class BufferBindingDirty 23 { 24 No, 25 Yes, 26 }; 27 28 class VertexArrayVk : public VertexArrayImpl 29 { 30 public: 31 VertexArrayVk(ContextVk *contextVk, const gl::VertexArrayState &state); 32 ~VertexArrayVk() override; 33 34 void destroy(const gl::Context *context) override; 35 36 angle::Result syncState(const gl::Context *context, 37 const gl::VertexArray::DirtyBits &dirtyBits, 38 gl::VertexArray::DirtyAttribBitsArray *attribBits, 39 gl::VertexArray::DirtyBindingBitsArray *bindingBits) override; 40 41 angle::Result updateActiveAttribInfo(ContextVk *contextVk); 42 43 angle::Result updateDefaultAttrib(ContextVk *contextVk, size_t attribIndex); 44 45 angle::Result updateStreamedAttribs(const gl::Context *context, 46 GLint firstVertex, 47 GLsizei vertexOrIndexCount, 48 GLsizei instanceCount, 49 gl::DrawElementsType indexTypeOrInvalid, 50 const void *indices); 51 52 angle::Result handleLineLoop(ContextVk *contextVk, 53 GLint firstVertex, 54 GLsizei vertexOrIndexCount, 55 gl::DrawElementsType indexTypeOrInvalid, 56 const void *indices, 57 uint32_t *indexCountOut); 58 59 angle::Result handleLineLoopIndexIndirect(ContextVk *contextVk, 60 gl::DrawElementsType glIndexType, 61 vk::BufferHelper *srcIndirectBuf, 62 VkDeviceSize indirectBufferOffset, 63 vk::BufferHelper **indirectBufferOut); 64 65 angle::Result handleLineLoopIndirectDraw(const gl::Context *context, 66 vk::BufferHelper *indirectBufferVk, 67 VkDeviceSize indirectBufferOffset, 68 vk::BufferHelper **indirectBufferOut); 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 getCurrentArrayBufferFormats()85 const gl::AttribArray<angle::FormatID> &getCurrentArrayBufferFormats() const 86 { 87 return mCurrentArrayBufferFormats; 88 } 89 getCurrentArrayBufferStrides()90 const gl::AttribArray<GLuint> &getCurrentArrayBufferStrides() const 91 { 92 return mCurrentArrayBufferStrides; 93 } 94 95 // Update mCurrentElementArrayBuffer based on the vertex array state 96 void updateCurrentElementArrayBuffer(); 97 getCurrentElementArrayBuffer()98 vk::BufferHelper *getCurrentElementArrayBuffer() const { return mCurrentElementArrayBuffer; } 99 100 angle::Result convertIndexBufferGPU(ContextVk *contextVk, 101 BufferVk *bufferVk, 102 const void *indices); 103 104 angle::Result convertIndexBufferIndirectGPU(ContextVk *contextVk, 105 vk::BufferHelper *srcIndirectBuf, 106 VkDeviceSize srcIndirectBufOffset, 107 vk::BufferHelper **indirectBufferVkOut); 108 109 angle::Result convertIndexBufferCPU(ContextVk *contextVk, 110 gl::DrawElementsType indexType, 111 size_t indexCount, 112 const void *sourcePointer, 113 BufferBindingDirty *bufferBindingDirty); 114 getStreamingVertexAttribsMask()115 const gl::AttributesMask &getStreamingVertexAttribsMask() const 116 { 117 return mStreamingVertexAttribsMask; 118 } 119 120 private: 121 angle::Result setDefaultPackedInput(ContextVk *contextVk, 122 size_t attribIndex, 123 angle::FormatID *formatOut); 124 125 angle::Result convertVertexBufferGPU(ContextVk *contextVk, 126 BufferVk *srcBuffer, 127 const gl::VertexBinding &binding, 128 size_t attribIndex, 129 const vk::Format &vertexFormat, 130 ConversionBuffer *conversion, 131 GLuint relativeOffset, 132 bool compressed); 133 angle::Result convertVertexBufferCPU(ContextVk *contextVk, 134 BufferVk *srcBuffer, 135 const gl::VertexBinding &binding, 136 size_t attribIndex, 137 const vk::Format &vertexFormat, 138 ConversionBuffer *conversion, 139 GLuint relativeOffset, 140 bool compress); 141 142 angle::Result syncDirtyAttrib(ContextVk *contextVk, 143 const gl::VertexAttribute &attrib, 144 const gl::VertexBinding &binding, 145 size_t attribIndex, 146 bool bufferOnly); 147 148 gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles; 149 gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets; 150 // The offset into the buffer to the first attrib 151 gl::AttribArray<GLuint> mCurrentArrayBufferRelativeOffsets; 152 gl::AttribArray<vk::BufferHelper *> mCurrentArrayBuffers; 153 // Tracks BufferSerial of mCurrentArrayBuffers since they are always valid to access. 154 gl::AttribArray<vk::BufferSerial> mCurrentArrayBufferSerial; 155 // Cache strides of attributes for a fast pipeline cache update when VAOs are changed 156 gl::AttribArray<angle::FormatID> mCurrentArrayBufferFormats; 157 gl::AttribArray<GLuint> mCurrentArrayBufferStrides; 158 gl::AttributesMask mCurrentArrayBufferCompressed; 159 vk::BufferHelper *mCurrentElementArrayBuffer; 160 161 // Cached element array buffers for improving performance. 162 vk::BufferHelperPointerVector mCachedStreamIndexBuffers; 163 164 vk::BufferHelper mStreamedIndexData; 165 vk::BufferHelper mTranslatedByteIndexData; 166 vk::BufferHelper mTranslatedByteIndirectData; 167 168 vk::LineLoopHelper mLineLoopHelper; 169 Optional<GLint> mLineLoopBufferFirstIndex; 170 Optional<size_t> mLineLoopBufferLastIndex; 171 bool mDirtyLineLoopTranslation; 172 173 // Track client and/or emulated attribs that we have to stream their buffer contents 174 gl::AttributesMask mStreamingVertexAttribsMask; 175 176 // The attrib/binding dirty bits that requires graphics pipeline update 177 gl::VertexArray::DirtyBindingBits mBindingDirtyBitsRequiresPipelineUpdate; 178 gl::VertexArray::DirtyAttribBits mAttribDirtyBitsRequiresPipelineUpdate; 179 }; 180 } // namespace rx 181 182 #endif // LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_ 183