Hash :
b97aab3f
Author :
Date :
2022-03-09T17:36:24
Vulkan: resync mCurrentElementArrayBuffer when out of lineloop When glDrawElements is called with GL_UNSIGNED_BYTE type or LineLoop mode, we will internally allocate an element buffer and copy data to it. But when we switch out of that mode, we must re-sync mCurrentElementArrayBuffer to what it should be based on VertexArray buffer binding. This CL fix the bug that we were previously not updating it and end up using the wrong element buffer. Also added three tests: DrawWithSameBufferButDifferentTypes: that uses GL_UNSIGNED_BYTE data and GL_UNSIGNED_SHORT data in the same buffer and switch between these two data types without incurring buffer change. DrawWithSameBufferButDifferentModes: draw line mode followed by triangle without the same element buffer. DrawArraysLineLoopFollowedByDrawElementsTriangle: draw line mode with glDrawArrays and then followed by DrawElements. Bug: chromium:1299261 Change-Id: I5c471117d300e9fac9127a9d8fa66d48ac312f03 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3513553 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Commit-Queue: Charlie Lao <cclao@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// VertexArrayVk.h:
// Defines the class interface for VertexArrayVk, implementing VertexArrayImpl.
//
#ifndef LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_
#define LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_
#include "libANGLE/renderer/VertexArrayImpl.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
namespace rx
{
class BufferVk;
struct ConversionBuffer;
enum class BufferBindingDirty
{
No,
Yes,
};
class VertexArrayVk : public VertexArrayImpl
{
public:
VertexArrayVk(ContextVk *contextVk, const gl::VertexArrayState &state);
~VertexArrayVk() override;
void destroy(const gl::Context *context) override;
angle::Result syncState(const gl::Context *context,
const gl::VertexArray::DirtyBits &dirtyBits,
gl::VertexArray::DirtyAttribBitsArray *attribBits,
gl::VertexArray::DirtyBindingBitsArray *bindingBits) override;
angle::Result updateActiveAttribInfo(ContextVk *contextVk);
angle::Result updateDefaultAttrib(ContextVk *contextVk, size_t attribIndex);
angle::Result updateStreamedAttribs(const gl::Context *context,
GLint firstVertex,
GLsizei vertexOrIndexCount,
GLsizei instanceCount,
gl::DrawElementsType indexTypeOrInvalid,
const void *indices);
angle::Result handleLineLoop(ContextVk *contextVk,
GLint firstVertex,
GLsizei vertexOrIndexCount,
gl::DrawElementsType indexTypeOrInvalid,
const void *indices,
uint32_t *indexCountOut);
angle::Result handleLineLoopIndexIndirect(ContextVk *contextVk,
gl::DrawElementsType glIndexType,
vk::BufferHelper *srcIndirectBuf,
VkDeviceSize indirectBufferOffset,
vk::BufferHelper **indirectBufferOut);
angle::Result handleLineLoopIndirectDraw(const gl::Context *context,
vk::BufferHelper *indirectBufferVk,
VkDeviceSize indirectBufferOffset,
vk::BufferHelper **indirectBufferOut);
const gl::AttribArray<VkBuffer> &getCurrentArrayBufferHandles() const
{
return mCurrentArrayBufferHandles;
}
const gl::AttribArray<VkDeviceSize> &getCurrentArrayBufferOffsets() const
{
return mCurrentArrayBufferOffsets;
}
const gl::AttribArray<vk::BufferHelper *> &getCurrentArrayBuffers() const
{
return mCurrentArrayBuffers;
}
// Update mCurrentElementArrayBuffer based on the vertex array state
void updateCurrentElementArrayBuffer();
vk::BufferHelper *getCurrentElementArrayBuffer() const { return mCurrentElementArrayBuffer; }
angle::Result convertIndexBufferGPU(ContextVk *contextVk,
BufferVk *bufferVk,
const void *indices);
angle::Result convertIndexBufferIndirectGPU(ContextVk *contextVk,
vk::BufferHelper *srcIndirectBuf,
VkDeviceSize srcIndirectBufOffset,
vk::BufferHelper **indirectBufferVkOut);
angle::Result convertIndexBufferCPU(ContextVk *contextVk,
gl::DrawElementsType indexType,
size_t indexCount,
const void *sourcePointer,
BufferBindingDirty *bufferBindingDirty);
const gl::AttributesMask &getStreamingVertexAttribsMask() const
{
return mStreamingVertexAttribsMask;
}
private:
angle::Result setDefaultPackedInput(ContextVk *contextVk, size_t attribIndex);
angle::Result convertVertexBufferGPU(ContextVk *contextVk,
BufferVk *srcBuffer,
const gl::VertexBinding &binding,
size_t attribIndex,
const vk::Format &vertexFormat,
ConversionBuffer *conversion,
GLuint relativeOffset,
bool compressed);
angle::Result convertVertexBufferCPU(ContextVk *contextVk,
BufferVk *srcBuffer,
const gl::VertexBinding &binding,
size_t attribIndex,
const vk::Format &vertexFormat,
ConversionBuffer *conversion,
GLuint relativeOffset,
bool compress);
angle::Result syncDirtyAttrib(ContextVk *contextVk,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t attribIndex,
bool bufferOnly);
gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles;
gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets;
// The offset into the buffer to the first attrib
gl::AttribArray<GLuint> mCurrentArrayBufferRelativeOffsets;
gl::AttribArray<vk::BufferHelper *> mCurrentArrayBuffers;
// Cache strides of attributes for a fast pipeline cache update when VAOs are changed
gl::AttribArray<GLuint> mCurrentArrayBufferStrides;
gl::AttributesMask mCurrentArrayBufferCompressed;
vk::BufferHelper *mCurrentElementArrayBuffer;
// Cached element array buffers for improving performance.
vk::BufferHelperPointerVector mCachedStreamIndexBuffers;
vk::BufferHelper mStreamedIndexData;
vk::BufferHelper mTranslatedByteIndexData;
vk::BufferHelper mTranslatedByteIndirectData;
vk::LineLoopHelper mLineLoopHelper;
Optional<GLint> mLineLoopBufferFirstIndex;
Optional<size_t> mLineLoopBufferLastIndex;
bool mDirtyLineLoopTranslation;
// Track client and/or emulated attribs that we have to stream their buffer contents
gl::AttributesMask mStreamingVertexAttribsMask;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_