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