Hash :
62b00f86
Author :
Date :
2025-10-02T12:19:23
Vulkan: Further minimize VertexArrayVk::syncDirtyEnabledAttrib This CL splits the streaming handling into its own function: syncDirtyEnabledAttrib is now splitted into syncDirtyEnabledNonStreamingAttrib and syncDirtyEnabledStreamingAttrib. This minimize the condition check inside syncDirtyEnabledAttrib. VertexArrayVk::syncDirtyEnabledAttrib() function has a check of bufferGL->getSize() > 0 as well as hasAtLeastOneVertex. And if either of them are false, they simply point to empty buffer. This CL merges these this fallout case into hasAtLeastOneVertex and added ASSERT to ensure that if buffer size is 0, hasAtLeastOneVertex is false. Bug: b/439073246 Change-Id: I5e3592c31469d15f5321208eb0278b10e447118c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6987341 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
//
// 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/UtilsVk.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
namespace rx
{
enum class BufferBindingDirty
{
No,
Yes,
};
struct AttributeRange
{
// Stream vertex attribute start pointer address.
uintptr_t startAddr;
// Stream vertex attribute end pointer address.
uintptr_t endAddr;
// Stream vertex attribute first used pointer address.
// ie. startAddr + startVertex * stride.
uintptr_t copyStartAddr;
AttributeRange() : startAddr(0), endAddr(0), copyStartAddr(0) {}
AttributeRange(uintptr_t start, uintptr_t end, uintptr_t copyStart)
: startAddr(start), endAddr(end), copyStartAddr(copyStart)
{}
};
ANGLE_INLINE bool operator<(const AttributeRange &a, const AttributeRange &b)
{
return a.startAddr == b.startAddr ? a.endAddr < b.endAddr : a.startAddr < b.startAddr;
}
class VertexArrayVk : public VertexArrayImpl
{
public:
VertexArrayVk(ContextVk *contextVk,
const gl::VertexArrayState &state,
const gl::VertexArrayBuffers &vertexArrayBuffers);
~VertexArrayVk() override;
void destroy(const gl::Context *context) override;
gl::VertexArray::DirtyBits checkBufferForDirtyBits(
const gl::Context *context,
const gl::VertexArrayBufferBindingMask bufferBindingMask) override;
angle::Result syncState(const gl::Context *context,
const gl::VertexArray::DirtyBits &dirtyBits,
gl::VertexArray::DirtyAttribBitsArray *attribBits,
gl::VertexArray::DirtyBindingBitsArray *bindingBits) override;
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,
vk::BufferHelper **indexBufferOut,
uint32_t *indexCountOut);
angle::Result handleLineLoopIndexIndirect(ContextVk *contextVk,
gl::DrawElementsType glIndexType,
vk::BufferHelper *srcIndexBuffer,
vk::BufferHelper *srcIndirectBuffer,
VkDeviceSize indirectBufferOffset,
vk::BufferHelper **indexBufferOut,
vk::BufferHelper **indirectBufferOut);
angle::Result handleLineLoopIndirectDraw(const gl::Context *context,
vk::BufferHelper *indirectBufferVk,
VkDeviceSize indirectBufferOffset,
vk::BufferHelper **indexBufferOut,
vk::BufferHelper **indirectBufferOut);
const gl::AttribArray<VkBuffer> &getCurrentArrayBufferHandles() const
{
return mCurrentArrayBufferHandles;
}
const gl::AttribArray<VkDeviceSize> &getCurrentArrayBufferOffsets() const
{
return mCurrentArrayBufferOffsets;
}
const gl::AttribArray<VkDeviceSize> &getCurrentArrayBufferSizes() const
{
return mCurrentArrayBufferSizes;
}
const gl::AttribArray<VkVertexInputBindingDescription2EXT> &getVertexInputBindingDesc() const
{
return mVertexInputBindingDesc;
}
const gl::AttribArray<VkVertexInputAttributeDescription2EXT> &getVertexInputAttribDesc() const
{
return mVertexInputAttribDesc;
}
GLuint getCurrentArrayBufferRelativeOffset(size_t attribIndex) const
{
return mVertexInputAttribDesc[attribIndex].offset;
}
VkFormat getCurrentArrayBufferVkFormat(size_t attribIndex) const
{
return mVertexInputAttribDesc[attribIndex].format;
}
angle::FormatID getCurrentArrayBufferFormatID(size_t attribIndex) const
{
return mCurrentEnabledAttributesMask.test(attribIndex)
? mState.getVertexAttribute(attribIndex).format->id
: mDefaultAttribFormatIDs[attribIndex];
}
GLuint getCurrentArrayBufferStride(size_t attribIndex) const
{
return mVertexInputBindingDesc[attribIndex].stride;
}
GLuint getCurrentArrayBufferDivisor(size_t attribIndex) const
{
return mVertexInputBindingDesc[attribIndex].divisor;
}
// Update mCurrentElementArrayBuffer based on the vertex array state
void updateCurrentElementArrayBuffer();
vk::BufferHelper *getCurrentElementArrayBuffer() const { return mCurrentElementArrayBuffer; }
const gl::AttribArray<vk::BufferHelper *> &getCurrentArrayBuffers() const
{
return mCurrentArrayBuffers;
}
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);
gl::AttributesMask getStreamingVertexAttribsMask() const { return mStreamingVertexAttribsMask; }
gl::ComponentTypeMask getCurrentVertexAttributesTypeMask() const
{
return mCurrentVertexAttributesTypeMask;
}
gl::AttributesMask getCurrentEnabledAttributesMask() const
{
return mCurrentEnabledAttributesMask;
}
private:
gl::AttributesMask mergeClientAttribsRange(
vk::Renderer *renderer,
const gl::AttributesMask activeStreamedAttribs,
size_t startVertex,
size_t endVertex,
std::array<AttributeRange, gl::MAX_VERTEX_ATTRIBS> &mergeRangesOut,
std::array<size_t, gl::MAX_VERTEX_ATTRIBS> &mergedIndexesOut) const;
void setDefaultPackedInput(ContextVk *contextVk,
size_t attribIndex,
angle::FormatID *formatOut);
angle::Result convertVertexBufferGPU(ContextVk *contextVk,
BufferVk *srcBuffer,
VertexConversionBuffer *conversion,
const angle::Format &srcFormat,
const angle::Format &dstFormat);
angle::Result convertVertexBufferCPU(ContextVk *contextVk,
BufferVk *srcBuffer,
VertexConversionBuffer *conversion,
const angle::Format &srcFormat,
const angle::Format &dstFormat,
const VertexCopyFunction vertexLoadFunction);
angle::Result syncDirtyEnabledNonStreamingAttrib(ContextVk *contextVk,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t attribIndex,
bool bufferOnly);
angle::Result syncDirtyEnabledStreamingAttrib(ContextVk *contextVk,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t attribIndex,
bool bufferOnly);
angle::Result syncDirtyDisabledAttrib(ContextVk *contextVk,
const gl::VertexAttribute &attrib,
size_t attribIndex);
angle::Result syncNeedsConversionAttrib(ContextVk *contextVk,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t attribIndex);
void setVertexInputAttribDescFormat(vk::Renderer *renderer,
size_t attribIndex,
angle::FormatID formatID);
void setVertexInputBindingDescDivisor(vk::Renderer *renderer,
size_t attribIndex,
GLuint divisor);
gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles;
gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets;
gl::AttribArray<VkDeviceSize> mCurrentArrayBufferSizes;
gl::AttribArray<vk::BufferHelper *> mCurrentArrayBuffers;
// Tracks BufferSerial of mCurrentArrayBuffers since they are always valid to access.
gl::AttribArray<vk::BufferSerial> mCurrentArrayBufferSerial;
// Tracks the default attribute format ID
gl::AttribArray<angle::FormatID> mDefaultAttribFormatIDs;
// These struct are defined by VK_EXT_vertex_input_dynamic_state, for convenience, we these to
// store offset/divisor even when vertexInputDynamicState not supported.
gl::AttribArray<VkVertexInputBindingDescription2EXT> mVertexInputBindingDesc;
gl::AttribArray<VkVertexInputAttributeDescription2EXT> mVertexInputAttribDesc;
vk::BufferHelper *mCurrentElementArrayBuffer;
// Cached element array buffers for improving performance.
vk::BufferHelperQueue mCachedStreamIndexBuffers;
ConversionBuffer mStreamedIndexData;
ConversionBuffer mTranslatedByteIndexData;
ConversionBuffer mTranslatedByteIndirectData;
LineLoopHelper mLineLoopHelper;
Optional<GLint> mLineLoopBufferFirstIndex;
Optional<size_t> mLineLoopBufferLastIndex;
bool mDirtyLineLoopTranslation;
gl::BufferBindingMask mDivisorExceedMaxSupportedValueBindingMask;
gl::AttributesMask mCurrentEnabledAttributesMask;
// Track client and/or emulated attribs that we have to stream their buffer contents
gl::AttributesMask mStreamingVertexAttribsMask;
gl::AttributesMask mNeedsConversionAttribMask;
gl::ComponentTypeMask mCurrentVertexAttributesTypeMask;
// The attrib/binding dirty bits that requires graphics pipeline update
gl::VertexArray::DirtyBindingBits mBindingDirtyBitsRequiresPipelineUpdate;
gl::VertexArray::DirtyAttribBits mAttribDirtyBitsRequiresPipelineUpdate;
// This maybe 0 or 1 depends on feature bit
uint32_t mZeroDivisor;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_VERTEXARRAYVK_H_