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 angle::Result updateActiveAttribInfo(ContextVk *contextVk); 36 37 angle::Result 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 getCurrentElementArrayBuffer()90 vk::BufferHelper *getCurrentElementArrayBuffer() const { return mCurrentElementArrayBuffer; } 91 92 angle::Result convertIndexBufferGPU(ContextVk *contextVk, 93 BufferVk *bufferVk, 94 const void *indices); 95 96 angle::Result convertIndexBufferIndirectGPU(ContextVk *contextVk, 97 vk::BufferHelper *srcIndirectBuf, 98 VkDeviceSize srcIndirectBufOffset, 99 vk::BufferHelper **indirectBufferVkOut, 100 VkDeviceSize *indirectBufferVkOffsetOut); 101 102 angle::Result convertIndexBufferCPU(ContextVk *contextVk, 103 gl::DrawElementsType indexType, 104 size_t indexCount, 105 const void *sourcePointer); 106 getStreamingVertexAttribsMask()107 const gl::AttributesMask &getStreamingVertexAttribsMask() const 108 { 109 return mStreamingVertexAttribsMask; 110 } 111 112 private: 113 angle::Result setDefaultPackedInput(ContextVk *contextVk, size_t attribIndex); 114 115 angle::Result convertVertexBufferGPU(ContextVk *contextVk, 116 BufferVk *srcBuffer, 117 const gl::VertexBinding &binding, 118 size_t attribIndex, 119 const vk::Format &vertexFormat, 120 ConversionBuffer *conversion, 121 GLuint relativeOffset, 122 bool compressed); 123 angle::Result convertVertexBufferCPU(ContextVk *contextVk, 124 BufferVk *srcBuffer, 125 const gl::VertexBinding &binding, 126 size_t attribIndex, 127 const vk::Format &vertexFormat, 128 ConversionBuffer *conversion, 129 GLuint relativeOffset, 130 bool compress); 131 132 angle::Result syncDirtyAttrib(ContextVk *contextVk, 133 const gl::VertexAttribute &attrib, 134 const gl::VertexBinding &binding, 135 size_t attribIndex, 136 bool bufferOnly); 137 138 gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles; 139 gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets; 140 // The offset into the buffer to the first attrib 141 gl::AttribArray<GLuint> mCurrentArrayBufferRelativeOffsets; 142 gl::AttribArray<vk::BufferHelper *> mCurrentArrayBuffers; 143 // Cache strides of attributes for a fast pipeline cache update when VAOs are changed 144 gl::AttribArray<GLuint> mCurrentArrayBufferStrides; 145 gl::AttributesMask mCurrentArrayBufferCompressed; 146 VkDeviceSize mCurrentElementArrayBufferOffset; 147 vk::BufferHelper *mCurrentElementArrayBuffer; 148 149 vk::DynamicBuffer mDynamicVertexData; 150 vk::DynamicBuffer mDynamicIndexData; 151 vk::DynamicBuffer mTranslatedByteIndexData; 152 vk::DynamicBuffer mTranslatedByteIndirectData; 153 154 vk::LineLoopHelper mLineLoopHelper; 155 Optional<GLint> mLineLoopBufferFirstIndex; 156 Optional<size_t> mLineLoopBufferLastIndex; 157 bool mDirtyLineLoopTranslation; 158 159 // Track client and/or emulated attribs that we have to stream their buffer contents 160 gl::AttributesMask mStreamingVertexAttribsMask; 161 }; 162 } // namespace rx 163 164 #endif // LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_ 165