diff --git a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp index c23d424b1a..082a4fcef3 100644 --- a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp +++ b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp @@ -306,6 +306,17 @@ size_t GetVertexCountForRange(GLint64 srcBufferBytes, size_t numVertices = static_cast(srcBufferBytes + srcVertexStride - 1) / srcVertexStride; + + // A vertex at stride-slot k occupies [k*stride, k*stride + formatSize). The ceil-division + // above can over-count by one when srcBufferBytes mod stride lies in [1, formatSize). Clamp + // so the last counted vertex's format-size read stays within srcBufferBytes. This mirrors + // the clamp already applied in CalculateMaxVertexCountForConversion. + size_t intendedSrcDataSize = + (numVertices - 1) * static_cast(srcVertexStride) + srcFormatSize; + if (intendedSrcDataSize > static_cast(srcBufferBytes)) + { + numVertices = static_cast(srcBufferBytes - srcFormatSize) / srcVertexStride + 1; + } return numVertices; }