Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 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.cpp: |
| 7 | // Implements the class methods for VertexArrayVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/VertexArrayVk.h" |
| 11 | |
| 12 | #include "common/debug.h" |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 13 | #include "common/utilities.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 14 | #include "libANGLE/Context.h" |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 15 | #include "libANGLE/renderer/vulkan/BufferVk.h" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 16 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 17 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 19 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 20 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 21 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 22 | namespace rx |
| 23 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 24 | namespace |
| 25 | { |
Jamie Madill | 77abad8 | 2018-10-25 17:03:48 -0400 | [diff] [blame] | 26 | constexpr size_t kDynamicVertexDataSize = 1024 * 1024; |
| 27 | constexpr size_t kDynamicIndexDataSize = 1024 * 8; |
jchen10 | 5dc0a6f | 2018-09-20 14:30:45 +0800 | [diff] [blame] | 28 | constexpr size_t kMaxVertexFormatAlignment = 4; |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 29 | |
| 30 | bool BindingIsAligned(const gl::VertexBinding &binding, unsigned componentSize) |
| 31 | { |
| 32 | return (binding.getOffset() % componentSize == 0) && (binding.getStride() % componentSize == 0); |
| 33 | } |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 34 | |
| 35 | angle::Result StreamVertexData(ContextVk *contextVk, |
| 36 | vk::DynamicBuffer *dynamicBuffer, |
| 37 | const uint8_t *sourceData, |
| 38 | size_t bytesToAllocate, |
| 39 | size_t destOffset, |
| 40 | size_t vertexCount, |
| 41 | size_t stride, |
| 42 | VertexCopyFunction vertexLoadFunction, |
| 43 | VkBuffer *bufferHandleOut, |
| 44 | VkDeviceSize *bufferOffsetOut) |
| 45 | { |
| 46 | uint8_t *dst = nullptr; |
| 47 | ANGLE_TRY(dynamicBuffer->allocate(contextVk, bytesToAllocate, &dst, bufferHandleOut, |
| 48 | bufferOffsetOut, nullptr)); |
| 49 | dst += destOffset; |
| 50 | vertexLoadFunction(sourceData, stride, vertexCount, dst); |
| 51 | |
| 52 | ANGLE_TRY(dynamicBuffer->flush(contextVk)); |
| 53 | return angle::Result::Continue(); |
| 54 | } |
jchen10 | 5dc0a6f | 2018-09-20 14:30:45 +0800 | [diff] [blame] | 55 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 56 | } // anonymous namespace |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 57 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 58 | #define INIT \ |
| 59 | { \ |
| 60 | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, 1024 * 8 \ |
| 61 | } |
| 62 | |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 63 | VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state, RendererVk *renderer) |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 64 | : VertexArrayImpl(state), |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 65 | mCurrentArrayBufferHandles{}, |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 66 | mCurrentArrayBufferOffsets{}, |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 67 | mCurrentArrayBufferResources{}, |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 68 | mCurrentArrayBufferFormats{}, |
| 69 | mCurrentArrayBufferStrides{}, |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 70 | mCurrentArrayBufferConversion{{ |
| 71 | INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, |
| 72 | INIT, |
| 73 | }}, |
| 74 | mCurrentArrayBufferConversionCanRelease{}, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 75 | mCurrentElementArrayBufferHandle(VK_NULL_HANDLE), |
| 76 | mCurrentElementArrayBufferOffset(0), |
| 77 | mCurrentElementArrayBufferResource(nullptr), |
Jamie Madill | 77b2436 | 2018-11-05 22:39:29 -0500 | [diff] [blame] | 78 | mPackedInputBindings{}, |
| 79 | mPackedInputAttributes{}, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 80 | mDynamicVertexData(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, kDynamicVertexDataSize), |
| 81 | mDynamicIndexData(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, kDynamicIndexDataSize), |
Luc Ferron | 6ed167a | 2018-06-13 13:45:55 -0400 | [diff] [blame] | 82 | mTranslatedByteIndexData(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, kDynamicIndexDataSize), |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 83 | mLineLoopHelper(renderer), |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 84 | mDirtyLineLoopTranslation(true) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 85 | { |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 86 | mCurrentArrayBufferHandles.fill(VK_NULL_HANDLE); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 87 | mCurrentArrayBufferOffsets.fill(0); |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 88 | mCurrentArrayBufferResources.fill(nullptr); |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 89 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 90 | for (vk::DynamicBuffer &buffer : mCurrentArrayBufferConversion) |
| 91 | { |
jchen10 | 5dc0a6f | 2018-09-20 14:30:45 +0800 | [diff] [blame] | 92 | buffer.init(kMaxVertexFormatAlignment, renderer); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 93 | } |
jchen10 | 5dc0a6f | 2018-09-20 14:30:45 +0800 | [diff] [blame] | 94 | mDynamicVertexData.init(kMaxVertexFormatAlignment, renderer); |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 95 | mDynamicIndexData.init(1, renderer); |
Luc Ferron | 6ed167a | 2018-06-13 13:45:55 -0400 | [diff] [blame] | 96 | mTranslatedByteIndexData.init(1, renderer); |
Jamie Madill | 0a17e48 | 2018-08-31 17:19:11 -0400 | [diff] [blame] | 97 | |
| 98 | // Initially consider all inputs dirty. |
| 99 | mDirtyPackedInputs.set(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 102 | VertexArrayVk::~VertexArrayVk() |
| 103 | { |
| 104 | } |
| 105 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 106 | void VertexArrayVk::destroy(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 107 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 108 | VkDevice device = vk::GetImpl(context)->getRenderer()->getDevice(); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 109 | for (vk::DynamicBuffer &buffer : mCurrentArrayBufferConversion) |
| 110 | { |
| 111 | buffer.destroy(device); |
| 112 | } |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 113 | mDynamicVertexData.destroy(device); |
| 114 | mDynamicIndexData.destroy(device); |
Luc Ferron | 6ed167a | 2018-06-13 13:45:55 -0400 | [diff] [blame] | 115 | mTranslatedByteIndexData.destroy(device); |
Jamie Madill | 22f12fe | 2018-04-08 14:23:40 -0400 | [diff] [blame] | 116 | mLineLoopHelper.destroy(device); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 119 | angle::Result VertexArrayVk::streamIndexData(ContextVk *contextVk, |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 120 | GLenum indexType, |
| 121 | size_t indexCount, |
| 122 | const void *sourcePointer, |
| 123 | vk::DynamicBuffer *dynamicBuffer) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 124 | { |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 125 | ASSERT(!mState.getElementArrayBuffer() || indexType == GL_UNSIGNED_BYTE); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 126 | |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 127 | dynamicBuffer->releaseRetainedBuffers(contextVk->getRenderer()); |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 128 | |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 129 | const size_t amount = sizeof(GLushort) * indexCount; |
| 130 | GLubyte *dst = nullptr; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 131 | |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 132 | ANGLE_TRY(dynamicBuffer->allocate(contextVk, amount, &dst, &mCurrentElementArrayBufferHandle, |
| 133 | &mCurrentElementArrayBufferOffset, nullptr)); |
| 134 | if (indexType == GL_UNSIGNED_BYTE) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 135 | { |
| 136 | // Unsigned bytes don't have direct support in Vulkan so we have to expand the |
| 137 | // memory to a GLushort. |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 138 | const GLubyte *in = static_cast<const GLubyte *>(sourcePointer); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 139 | GLushort *expandedDst = reinterpret_cast<GLushort *>(dst); |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 140 | for (size_t index = 0; index < indexCount; index++) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 141 | { |
| 142 | expandedDst[index] = static_cast<GLushort>(in[index]); |
| 143 | } |
| 144 | } |
| 145 | else |
| 146 | { |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 147 | memcpy(dst, sourcePointer, amount); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 148 | } |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 149 | ANGLE_TRY(dynamicBuffer->flush(contextVk)); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 150 | return angle::Result::Continue(); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 153 | // We assume the buffer is completely full of the same kind of data and convert |
| 154 | // and/or align it as we copy it to a DynamicBuffer. The assumption could be wrong |
| 155 | // but the alternative of copying it piecemeal on each draw would have a lot more |
| 156 | // overhead. |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 157 | angle::Result VertexArrayVk::convertVertexBuffer(ContextVk *contextVk, |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 158 | BufferVk *srcBuffer, |
| 159 | const gl::VertexBinding &binding, |
| 160 | size_t attribIndex) |
| 161 | { |
| 162 | |
Frank Henigman | 9d84ccb | 2018-09-12 18:09:02 -0400 | [diff] [blame] | 163 | // Needed before reading buffer or we could get stale data. |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 164 | ANGLE_TRY(contextVk->getRenderer()->finish(contextVk)); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 165 | |
| 166 | unsigned srcFormatSize = mCurrentArrayBufferFormats[attribIndex]->angleFormat().pixelBytes; |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 167 | unsigned dstFormatSize = mCurrentArrayBufferStrides[attribIndex]; |
| 168 | |
| 169 | mCurrentArrayBufferConversion[attribIndex].releaseRetainedBuffers(contextVk->getRenderer()); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 170 | |
| 171 | // Bytes usable for vertex data. |
| 172 | GLint64 bytes = srcBuffer->getSize() - binding.getOffset(); |
| 173 | if (bytes < srcFormatSize) |
| 174 | return angle::Result::Continue(); |
| 175 | |
| 176 | // Count the last vertex. It may occupy less than a full stride. |
| 177 | size_t numVertices = 1; |
| 178 | bytes -= srcFormatSize; |
| 179 | |
| 180 | // Count how many strides fit remaining space. |
| 181 | if (bytes > 0) |
| 182 | numVertices += static_cast<size_t>(bytes) / binding.getStride(); |
| 183 | |
Jamie Madill | 77abad8 | 2018-10-25 17:03:48 -0400 | [diff] [blame] | 184 | void *src = nullptr; |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 185 | ANGLE_TRY(srcBuffer->mapImpl(contextVk, &src)); |
| 186 | const uint8_t *srcBytes = reinterpret_cast<const uint8_t *>(src); |
| 187 | srcBytes += binding.getOffset(); |
jchen10 | 5dc0a6f | 2018-09-20 14:30:45 +0800 | [diff] [blame] | 188 | ASSERT(GetVertexInputAlignment(*mCurrentArrayBufferFormats[attribIndex]) <= |
| 189 | kMaxVertexFormatAlignment); |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 190 | ANGLE_TRY(StreamVertexData(contextVk, &mCurrentArrayBufferConversion[attribIndex], srcBytes, |
| 191 | numVertices * dstFormatSize, 0, numVertices, binding.getStride(), |
| 192 | mCurrentArrayBufferFormats[attribIndex]->vertexLoadFunction, |
| 193 | &mCurrentArrayBufferHandles[attribIndex], |
| 194 | &mCurrentArrayBufferOffsets[attribIndex])); |
| 195 | ANGLE_TRY(srcBuffer->unmapImpl(contextVk)); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 196 | |
| 197 | mCurrentArrayBufferConversionCanRelease[attribIndex] = true; |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 198 | |
| 199 | return angle::Result::Continue(); |
| 200 | } |
| 201 | |
| 202 | void VertexArrayVk::ensureConversionReleased(RendererVk *renderer, size_t attribIndex) |
| 203 | { |
| 204 | if (mCurrentArrayBufferConversionCanRelease[attribIndex]) |
| 205 | { |
| 206 | mCurrentArrayBufferConversion[attribIndex].release(renderer); |
| 207 | mCurrentArrayBufferConversionCanRelease[attribIndex] = false; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | #define ANGLE_VERTEX_DIRTY_ATTRIB_FUNC(INDEX) \ |
| 212 | case gl::VertexArray::DIRTY_BIT_ATTRIB_0 + INDEX: \ |
| 213 | ANGLE_TRY(syncDirtyAttrib(contextVk, attribs[INDEX], \ |
| 214 | bindings[attribs[INDEX].bindingIndex], INDEX)); \ |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 215 | invalidateContext = true; \ |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 216 | break; |
| 217 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 218 | #define ANGLE_VERTEX_DIRTY_BINDING_FUNC(INDEX) \ |
| 219 | case gl::VertexArray::DIRTY_BIT_BINDING_0 + INDEX: \ |
| 220 | ANGLE_TRY(syncDirtyAttrib(contextVk, attribs[INDEX], \ |
| 221 | bindings[attribs[INDEX].bindingIndex], INDEX)); \ |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 222 | invalidateContext = true; \ |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 223 | break; |
| 224 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 225 | #define ANGLE_VERTEX_DIRTY_BUFFER_DATA_FUNC(INDEX) \ |
| 226 | case gl::VertexArray::DIRTY_BIT_BUFFER_DATA_0 + INDEX: \ |
| 227 | ANGLE_TRY(syncDirtyAttrib(contextVk, attribs[INDEX], \ |
| 228 | bindings[attribs[INDEX].bindingIndex], INDEX)); \ |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 229 | break; |
| 230 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 231 | angle::Result VertexArrayVk::syncState(const gl::Context *context, |
| 232 | const gl::VertexArray::DirtyBits &dirtyBits, |
| 233 | const gl::VertexArray::DirtyAttribBitsArray &attribBits, |
| 234 | const gl::VertexArray::DirtyBindingBitsArray &bindingBits) |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 235 | { |
| 236 | ASSERT(dirtyBits.any()); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 237 | |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 238 | bool invalidateContext = false; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 239 | |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 240 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 241 | |
| 242 | // Rebuild current attribute buffers cache. This will fail horribly if the buffer changes. |
| 243 | // TODO(jmadill): Handle buffer storage changes. |
| 244 | const auto &attribs = mState.getVertexAttributes(); |
| 245 | const auto &bindings = mState.getVertexBindings(); |
| 246 | |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 247 | for (size_t dirtyBit : dirtyBits) |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 248 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 249 | switch (dirtyBit) |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 250 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 251 | case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER: |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 252 | { |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 253 | gl::Buffer *bufferGL = mState.getElementArrayBuffer(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 254 | if (bufferGL) |
| 255 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 256 | BufferVk *bufferVk = vk::GetImpl(bufferGL); |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 257 | mCurrentElementArrayBufferResource = &bufferVk->getBuffer(); |
| 258 | mCurrentElementArrayBufferHandle = |
| 259 | bufferVk->getBuffer().getBuffer().getHandle(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 260 | } |
| 261 | else |
| 262 | { |
| 263 | mCurrentElementArrayBufferResource = nullptr; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 264 | mCurrentElementArrayBufferHandle = VK_NULL_HANDLE; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 265 | } |
Luc Ferron | 387b3b3 | 2018-05-28 10:11:57 -0400 | [diff] [blame] | 266 | |
| 267 | mCurrentElementArrayBufferOffset = 0; |
| 268 | mLineLoopBufferFirstIndex.reset(); |
| 269 | mLineLoopBufferLastIndex.reset(); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 270 | contextVk->setIndexBufferDirty(); |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 271 | mDirtyLineLoopTranslation = true; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 272 | break; |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 273 | } |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 274 | |
| 275 | case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA: |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 276 | mLineLoopBufferFirstIndex.reset(); |
| 277 | mLineLoopBufferLastIndex.reset(); |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 278 | mDirtyLineLoopTranslation = true; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 279 | break; |
| 280 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 281 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_ATTRIB_FUNC); |
| 282 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BINDING_FUNC); |
| 283 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BUFFER_DATA_FUNC); |
| 284 | |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 285 | default: |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 286 | UNREACHABLE(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 287 | break; |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 288 | } |
| 289 | } |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 290 | |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 291 | if (invalidateContext) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 292 | { |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 293 | contextVk->invalidateVertexAndIndexBuffers(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 296 | return angle::Result::Continue(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 299 | angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk, |
| 300 | const gl::VertexAttribute &attrib, |
| 301 | const gl::VertexBinding &binding, |
| 302 | size_t attribIndex) |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 303 | { |
| 304 | // Invalidate the input description for pipelines. |
| 305 | mDirtyPackedInputs.set(attribIndex); |
| 306 | |
Frank Henigman | 67c388e | 2018-07-19 19:16:11 -0400 | [diff] [blame] | 307 | RendererVk *renderer = contextVk->getRenderer(); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 308 | bool releaseConversion = true; |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 309 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 310 | if (attrib.enabled) |
| 311 | { |
Frank Henigman | 67c388e | 2018-07-19 19:16:11 -0400 | [diff] [blame] | 312 | gl::Buffer *bufferGL = binding.getBuffer().get(); |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 313 | mCurrentArrayBufferFormats[attribIndex] = &renderer->getFormat(GetVertexFormatID(attrib)); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 314 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 315 | if (bufferGL) |
| 316 | { |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 317 | BufferVk *bufferVk = vk::GetImpl(bufferGL); |
| 318 | unsigned componentSize = |
| 319 | mCurrentArrayBufferFormats[attribIndex]->angleFormat().pixelBytes / attrib.size; |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 320 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 321 | if (mCurrentArrayBufferFormats[attribIndex]->vertexLoadRequiresConversion || |
| 322 | !BindingIsAligned(binding, componentSize)) |
| 323 | { |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 324 | mCurrentArrayBufferStrides[attribIndex] = |
| 325 | mCurrentArrayBufferFormats[attribIndex]->bufferFormat().pixelBytes; |
| 326 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 327 | ANGLE_TRY(convertVertexBuffer(contextVk, bufferVk, binding, attribIndex)); |
| 328 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 329 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 330 | releaseConversion = false; |
| 331 | } |
| 332 | else |
| 333 | { |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 334 | mCurrentArrayBufferResources[attribIndex] = &bufferVk->getBuffer(); |
| 335 | mCurrentArrayBufferHandles[attribIndex] = |
| 336 | bufferVk->getBuffer().getBuffer().getHandle(); |
Jamie Madill | 77abad8 | 2018-10-25 17:03:48 -0400 | [diff] [blame] | 337 | mCurrentArrayBufferOffsets[attribIndex] = binding.getOffset(); |
| 338 | mCurrentArrayBufferStrides[attribIndex] = binding.getStride(); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 339 | } |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 340 | } |
| 341 | else |
| 342 | { |
| 343 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 344 | mCurrentArrayBufferHandles[attribIndex] = VK_NULL_HANDLE; |
Luc Ferron | fa5d84b | 2018-06-28 10:40:04 -0400 | [diff] [blame] | 345 | mCurrentArrayBufferOffsets[attribIndex] = 0; |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 346 | mCurrentArrayBufferStrides[attribIndex] = |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 347 | mCurrentArrayBufferFormats[attribIndex]->bufferFormat().pixelBytes; |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 348 | } |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 349 | } |
| 350 | else |
| 351 | { |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 352 | contextVk->invalidateDefaultAttribute(attribIndex); |
| 353 | |
| 354 | // These will be filled out by the ContextVk. |
| 355 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 356 | mCurrentArrayBufferHandles[attribIndex] = VK_NULL_HANDLE; |
| 357 | mCurrentArrayBufferOffsets[attribIndex] = 0; |
| 358 | mCurrentArrayBufferStrides[attribIndex] = 0; |
| 359 | mCurrentArrayBufferFormats[attribIndex] = |
Jamie Madill | ba36593 | 2018-07-18 17:23:46 -0400 | [diff] [blame] | 360 | &renderer->getFormat(angle::FormatID::R32G32B32A32_FLOAT); |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 361 | } |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 362 | |
| 363 | if (releaseConversion) |
| 364 | ensureConversionReleased(renderer, attribIndex); |
| 365 | |
| 366 | return angle::Result::Continue(); |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 367 | } |
| 368 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 369 | void VertexArrayVk::getPackedInputDescriptions(vk::PipelineDesc *pipelineDesc) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 370 | { |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 371 | updatePackedInputDescriptions(); |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 372 | pipelineDesc->updateVertexInputInfo(mPackedInputBindings, mPackedInputAttributes); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 373 | } |
| 374 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 375 | void VertexArrayVk::updatePackedInputDescriptions() |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 376 | { |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 377 | if (!mDirtyPackedInputs.any()) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 378 | { |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | const auto &attribs = mState.getVertexAttributes(); |
| 383 | const auto &bindings = mState.getVertexBindings(); |
| 384 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 385 | for (auto attribIndex : mDirtyPackedInputs) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 386 | { |
| 387 | const auto &attrib = attribs[attribIndex]; |
| 388 | const auto &binding = bindings[attrib.bindingIndex]; |
| 389 | if (attrib.enabled) |
| 390 | { |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 391 | updatePackedInputInfo(static_cast<uint32_t>(attribIndex), binding, attrib); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 392 | } |
| 393 | else |
| 394 | { |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 395 | vk::PackedVertexInputBindingDesc &bindingDesc = mPackedInputBindings[attribIndex]; |
| 396 | bindingDesc.stride = 0; |
| 397 | bindingDesc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; |
| 398 | |
Jamie Madill | 77b2436 | 2018-11-05 22:39:29 -0500 | [diff] [blame] | 399 | mPackedInputAttributes.formats[attribIndex] = |
| 400 | static_cast<uint16_t>(VK_FORMAT_R32G32B32A32_SFLOAT); |
| 401 | mPackedInputAttributes.offsets[attribIndex] = 0; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 405 | mDirtyPackedInputs.reset(); |
| 406 | } |
| 407 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 408 | void VertexArrayVk::updatePackedInputInfo(uint32_t attribIndex, |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 409 | const gl::VertexBinding &binding, |
| 410 | const gl::VertexAttribute &attrib) |
| 411 | { |
| 412 | vk::PackedVertexInputBindingDesc &bindingDesc = mPackedInputBindings[attribIndex]; |
| 413 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 414 | bindingDesc.stride = static_cast<uint16_t>(mCurrentArrayBufferStrides[attribIndex]); |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 415 | bindingDesc.inputRate = static_cast<uint16_t>( |
| 416 | binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX); |
| 417 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 418 | VkFormat vkFormat = mCurrentArrayBufferFormats[attribIndex]->vkBufferFormat; |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 419 | ASSERT(vkFormat <= std::numeric_limits<uint16_t>::max()); |
Frank Henigman | 8c379f3 | 2018-06-21 19:55:05 -0400 | [diff] [blame] | 420 | if (vkFormat == VK_FORMAT_UNDEFINED) |
| 421 | { |
Frank Henigman | 8c379f3 | 2018-06-21 19:55:05 -0400 | [diff] [blame] | 422 | UNIMPLEMENTED(); |
| 423 | } |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 424 | |
Jamie Madill | 77b2436 | 2018-11-05 22:39:29 -0500 | [diff] [blame] | 425 | mPackedInputAttributes.formats[attribIndex] = static_cast<uint8_t>(vkFormat); |
| 426 | mPackedInputAttributes.offsets[attribIndex] = static_cast<uint16_t>(attrib.relativeOffset); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 429 | angle::Result VertexArrayVk::updateClientAttribs(const gl::Context *context, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 430 | GLint firstVertex, |
| 431 | GLsizei vertexOrIndexCount, |
| 432 | GLenum indexTypeOrNone, |
| 433 | const void *indices) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 434 | { |
Jamie Madill | 77abad8 | 2018-10-25 17:03:48 -0400 | [diff] [blame] | 435 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 436 | const gl::AttributesMask &clientAttribs = context->getStateCache().getActiveClientAttribsMask(); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 437 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 438 | ASSERT(clientAttribs.any()); |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 439 | |
| 440 | GLint startVertex; |
| 441 | size_t vertexCount; |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 442 | ANGLE_TRY(GetVertexRangeInfo(context, firstVertex, vertexOrIndexCount, indexTypeOrNone, indices, |
| 443 | 0, &startVertex, &vertexCount)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 444 | |
| 445 | mDynamicVertexData.releaseRetainedBuffers(contextVk->getRenderer()); |
| 446 | |
| 447 | const auto &attribs = mState.getVertexAttributes(); |
| 448 | const auto &bindings = mState.getVertexBindings(); |
| 449 | |
| 450 | // TODO(fjhenigman): When we have a bunch of interleaved attributes, they end up |
| 451 | // un-interleaved, wasting space and copying time. Consider improving on that. |
| 452 | for (size_t attribIndex : clientAttribs) |
| 453 | { |
| 454 | const gl::VertexAttribute &attrib = attribs[attribIndex]; |
| 455 | const gl::VertexBinding &binding = bindings[attrib.bindingIndex]; |
| 456 | ASSERT(attrib.enabled && binding.getBuffer().get() == nullptr); |
| 457 | |
| 458 | const size_t bytesToAllocate = |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 459 | (startVertex + vertexCount) * mCurrentArrayBufferStrides[attribIndex]; |
| 460 | const uint8_t *src = |
| 461 | static_cast<const uint8_t *>(attrib.pointer) + startVertex * binding.getStride(); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 462 | |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 463 | size_t destOffset = startVertex * mCurrentArrayBufferStrides[attribIndex]; |
jchen10 | 5dc0a6f | 2018-09-20 14:30:45 +0800 | [diff] [blame] | 464 | ASSERT(GetVertexInputAlignment(*mCurrentArrayBufferFormats[attribIndex]) <= |
| 465 | kMaxVertexFormatAlignment); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 466 | |
| 467 | // Only vertexCount() vertices will be used by the upcoming draw. so that is all we copy. |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 468 | // We allocate space for startVertex + vertexCount so indexing will work. If we |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 469 | // don't start at zero all the indices will be off. |
| 470 | // TODO(fjhenigman): See if we can account for indices being off by adjusting the |
| 471 | // offset, thus avoiding wasted memory. |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 472 | ANGLE_TRY(StreamVertexData( |
| 473 | contextVk, &mDynamicVertexData, src, bytesToAllocate, destOffset, vertexCount, |
| 474 | binding.getStride(), mCurrentArrayBufferFormats[attribIndex]->vertexLoadFunction, |
| 475 | &mCurrentArrayBufferHandles[attribIndex], &mCurrentArrayBufferOffsets[attribIndex])); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | return angle::Result::Continue(); |
| 479 | } |
| 480 | |
| 481 | angle::Result VertexArrayVk::handleLineLoop(ContextVk *contextVk, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 482 | GLint firstVertex, |
| 483 | GLsizei vertexOrIndexCount, |
| 484 | GLenum indexTypeOrNone, |
| 485 | const void *indices) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 486 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 487 | if (indexTypeOrNone != GL_NONE) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 488 | { |
| 489 | // Handle GL_LINE_LOOP drawElements. |
| 490 | if (mDirtyLineLoopTranslation) |
| 491 | { |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 492 | gl::Buffer *elementArrayBuffer = mState.getElementArrayBuffer(); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 493 | |
| 494 | if (!elementArrayBuffer) |
| 495 | { |
Frank Henigman | 85c4b43 | 2018-09-19 23:35:00 -0400 | [diff] [blame] | 496 | ANGLE_TRY(mLineLoopHelper.streamIndices( |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 497 | contextVk, indexTypeOrNone, vertexOrIndexCount, |
| 498 | reinterpret_cast<const uint8_t *>(indices), &mCurrentElementArrayBufferHandle, |
| 499 | &mCurrentElementArrayBufferOffset)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 500 | } |
| 501 | else |
| 502 | { |
| 503 | // When using an element array buffer, 'indices' is an offset to the first element. |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 504 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 505 | BufferVk *elementArrayBufferVk = vk::GetImpl(elementArrayBuffer); |
| 506 | ANGLE_TRY(mLineLoopHelper.getIndexBufferForElementArrayBuffer( |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 507 | contextVk, elementArrayBufferVk, indexTypeOrNone, vertexOrIndexCount, offset, |
| 508 | &mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | |
| 512 | // If we've had a drawArrays call with a line loop before, we want to make sure this is |
| 513 | // invalidated the next time drawArrays is called since we use the same index buffer for |
| 514 | // both calls. |
| 515 | mLineLoopBufferFirstIndex.reset(); |
| 516 | mLineLoopBufferLastIndex.reset(); |
| 517 | return angle::Result::Continue(); |
| 518 | } |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 519 | |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 520 | // Note: Vertex indexes can be arbitrarily large. |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 521 | uint32_t clampedVertexCount = gl::clampCast<uint32_t>(vertexOrIndexCount); |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 522 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 523 | // Handle GL_LINE_LOOP drawArrays. |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 524 | size_t lastVertex = static_cast<size_t>(firstVertex + clampedVertexCount); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 525 | if (!mLineLoopBufferFirstIndex.valid() || !mLineLoopBufferLastIndex.valid() || |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 526 | mLineLoopBufferFirstIndex != firstVertex || mLineLoopBufferLastIndex != lastVertex) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 527 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 528 | ANGLE_TRY(mLineLoopHelper.getIndexBufferForDrawArrays( |
| 529 | contextVk, clampedVertexCount, firstVertex, &mCurrentElementArrayBufferHandle, |
| 530 | &mCurrentElementArrayBufferOffset)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 531 | |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 532 | mLineLoopBufferFirstIndex = firstVertex; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 533 | mLineLoopBufferLastIndex = lastVertex; |
| 534 | } |
| 535 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 536 | return angle::Result::Continue(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 539 | angle::Result VertexArrayVk::updateIndexTranslation(ContextVk *contextVk, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 540 | GLsizei indexCount, |
| 541 | GLenum type, |
| 542 | const void *indices) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 543 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 544 | ASSERT(type != GL_NONE); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 545 | |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 546 | gl::Buffer *glBuffer = mState.getElementArrayBuffer(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 547 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 548 | if (!glBuffer) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 549 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 550 | ANGLE_TRY(streamIndexData(contextVk, type, indexCount, indices, &mDynamicIndexData)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 551 | } |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 552 | else |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 553 | { |
Frank Henigman | 9d84ccb | 2018-09-12 18:09:02 -0400 | [diff] [blame] | 554 | // Needed before reading buffer or we could get stale data. |
| 555 | ANGLE_TRY(contextVk->getRenderer()->finish(contextVk)); |
| 556 | |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 557 | ASSERT(type == GL_UNSIGNED_BYTE); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 558 | // Unsigned bytes don't have direct support in Vulkan so we have to expand the |
| 559 | // memory to a GLushort. |
| 560 | BufferVk *bufferVk = vk::GetImpl(glBuffer); |
| 561 | void *srcDataMapping = nullptr; |
| 562 | ASSERT(!glBuffer->isMapped()); |
| 563 | ANGLE_TRY(bufferVk->mapImpl(contextVk, &srcDataMapping)); |
| 564 | uint8_t *srcData = static_cast<uint8_t *>(srcDataMapping); |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 565 | intptr_t offsetIntoSrcData = reinterpret_cast<intptr_t>(indices); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 566 | srcData += offsetIntoSrcData; |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 567 | |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 568 | ANGLE_TRY(streamIndexData(contextVk, type, |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 569 | static_cast<size_t>(bufferVk->getSize()) - offsetIntoSrcData, |
| 570 | srcData, &mTranslatedByteIndexData)); |
Luc Ferron | 6ed167a | 2018-06-13 13:45:55 -0400 | [diff] [blame] | 571 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 572 | ANGLE_TRY(bufferVk->unmapImpl(contextVk)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 575 | return angle::Result::Continue(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 576 | } |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 577 | |
| 578 | void VertexArrayVk::updateDefaultAttrib(RendererVk *renderer, |
| 579 | size_t attribIndex, |
| 580 | VkBuffer bufferHandle, |
| 581 | uint32_t offset) |
| 582 | { |
| 583 | if (!mState.getEnabledAttributesMask().test(attribIndex)) |
| 584 | { |
| 585 | mCurrentArrayBufferHandles[attribIndex] = bufferHandle; |
| 586 | mCurrentArrayBufferOffsets[attribIndex] = offset; |
| 587 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 588 | mCurrentArrayBufferStrides[attribIndex] = 0; |
| 589 | mCurrentArrayBufferFormats[attribIndex] = |
Jamie Madill | ba36593 | 2018-07-18 17:23:46 -0400 | [diff] [blame] | 590 | &renderer->getFormat(angle::FormatID::R32G32B32A32_FIXED); |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 591 | mDirtyPackedInputs.set(attribIndex); |
| 592 | } |
| 593 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 594 | } // namespace rx |