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); |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame^] | 254 | mCurrentElementArrayBufferResource = &bufferVk->getBuffer(); |
| 255 | mCurrentElementArrayBufferHandle = |
| 256 | bufferVk->getBuffer().getBuffer().getHandle(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 257 | } |
| 258 | else |
| 259 | { |
| 260 | mCurrentElementArrayBufferResource = nullptr; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 261 | mCurrentElementArrayBufferHandle = VK_NULL_HANDLE; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 262 | } |
Luc Ferron | 387b3b3 | 2018-05-28 10:11:57 -0400 | [diff] [blame] | 263 | |
| 264 | mCurrentElementArrayBufferOffset = 0; |
| 265 | mLineLoopBufferFirstIndex.reset(); |
| 266 | mLineLoopBufferLastIndex.reset(); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 267 | contextVk->setIndexBufferDirty(); |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 268 | mDirtyLineLoopTranslation = true; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 269 | break; |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 270 | } |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 271 | |
| 272 | case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA: |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 273 | mLineLoopBufferFirstIndex.reset(); |
| 274 | mLineLoopBufferLastIndex.reset(); |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 275 | mDirtyLineLoopTranslation = true; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 276 | break; |
| 277 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 278 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_ATTRIB_FUNC); |
| 279 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BINDING_FUNC); |
| 280 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BUFFER_DATA_FUNC); |
| 281 | |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 282 | default: |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 283 | UNREACHABLE(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 284 | break; |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 285 | } |
| 286 | } |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 287 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 288 | if (invalidatePipeline) |
| 289 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 290 | contextVk->invalidateCurrentPipeline(); |
| 291 | } |
| 292 | |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 293 | return gl::NoError(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 296 | angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk, |
| 297 | const gl::VertexAttribute &attrib, |
| 298 | const gl::VertexBinding &binding, |
| 299 | size_t attribIndex) |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 300 | { |
| 301 | // Invalidate the input description for pipelines. |
| 302 | mDirtyPackedInputs.set(attribIndex); |
| 303 | |
Frank Henigman | 67c388e | 2018-07-19 19:16:11 -0400 | [diff] [blame] | 304 | RendererVk *renderer = contextVk->getRenderer(); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 305 | bool releaseConversion = true; |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 306 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 307 | if (attrib.enabled) |
| 308 | { |
Frank Henigman | 67c388e | 2018-07-19 19:16:11 -0400 | [diff] [blame] | 309 | gl::Buffer *bufferGL = binding.getBuffer().get(); |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 310 | mCurrentArrayBufferFormats[attribIndex] = &renderer->getFormat(GetVertexFormatID(attrib)); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 311 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 312 | if (bufferGL) |
| 313 | { |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 314 | BufferVk *bufferVk = vk::GetImpl(bufferGL); |
| 315 | unsigned componentSize = |
| 316 | mCurrentArrayBufferFormats[attribIndex]->angleFormat().pixelBytes / attrib.size; |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 317 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 318 | if (mCurrentArrayBufferFormats[attribIndex]->vertexLoadRequiresConversion || |
| 319 | !BindingIsAligned(binding, componentSize)) |
| 320 | { |
Jamie Madill | a064c27 | 2018-08-30 16:18:34 -0400 | [diff] [blame] | 321 | mCurrentArrayBufferStrides[attribIndex] = |
| 322 | mCurrentArrayBufferFormats[attribIndex]->bufferFormat().pixelBytes; |
| 323 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 324 | ANGLE_TRY(convertVertexBuffer(contextVk, bufferVk, binding, attribIndex)); |
| 325 | |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 326 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 327 | releaseConversion = false; |
| 328 | } |
| 329 | else |
| 330 | { |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame^] | 331 | mCurrentArrayBufferResources[attribIndex] = &bufferVk->getBuffer(); |
| 332 | mCurrentArrayBufferHandles[attribIndex] = |
| 333 | bufferVk->getBuffer().getBuffer().getHandle(); |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 334 | mCurrentArrayBufferOffsets[attribIndex] = binding.getOffset(); |
| 335 | mCurrentArrayBufferStrides[attribIndex] = binding.getStride(); |
| 336 | } |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 337 | } |
| 338 | else |
| 339 | { |
| 340 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 341 | mCurrentArrayBufferHandles[attribIndex] = VK_NULL_HANDLE; |
Luc Ferron | fa5d84b | 2018-06-28 10:40:04 -0400 | [diff] [blame] | 342 | mCurrentArrayBufferOffsets[attribIndex] = 0; |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 343 | mCurrentArrayBufferStrides[attribIndex] = |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 344 | mCurrentArrayBufferFormats[attribIndex]->bufferFormat().pixelBytes; |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 345 | } |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 346 | } |
| 347 | else |
| 348 | { |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 349 | contextVk->invalidateDefaultAttribute(attribIndex); |
| 350 | |
| 351 | // These will be filled out by the ContextVk. |
| 352 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 353 | mCurrentArrayBufferHandles[attribIndex] = VK_NULL_HANDLE; |
| 354 | mCurrentArrayBufferOffsets[attribIndex] = 0; |
| 355 | mCurrentArrayBufferStrides[attribIndex] = 0; |
| 356 | mCurrentArrayBufferFormats[attribIndex] = |
Jamie Madill | ba36593 | 2018-07-18 17:23:46 -0400 | [diff] [blame] | 357 | &renderer->getFormat(angle::FormatID::R32G32B32A32_FLOAT); |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 358 | } |
Frank Henigman | e452382 | 2018-07-19 16:10:53 -0400 | [diff] [blame] | 359 | |
| 360 | if (releaseConversion) |
| 361 | ensureConversionReleased(renderer, attribIndex); |
| 362 | |
| 363 | return angle::Result::Continue(); |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 364 | } |
| 365 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 366 | void VertexArrayVk::getPackedInputDescriptions(vk::PipelineDesc *pipelineDesc) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 367 | { |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 368 | updatePackedInputDescriptions(); |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 369 | pipelineDesc->updateVertexInputInfo(mPackedInputBindings, mPackedInputAttributes); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 370 | } |
| 371 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 372 | void VertexArrayVk::updatePackedInputDescriptions() |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 373 | { |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 374 | if (!mDirtyPackedInputs.any()) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 375 | { |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | const auto &attribs = mState.getVertexAttributes(); |
| 380 | const auto &bindings = mState.getVertexBindings(); |
| 381 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 382 | for (auto attribIndex : mDirtyPackedInputs) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 383 | { |
| 384 | const auto &attrib = attribs[attribIndex]; |
| 385 | const auto &binding = bindings[attrib.bindingIndex]; |
| 386 | if (attrib.enabled) |
| 387 | { |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 388 | updatePackedInputInfo(static_cast<uint32_t>(attribIndex), binding, attrib); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 389 | } |
| 390 | else |
| 391 | { |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 392 | vk::PackedVertexInputBindingDesc &bindingDesc = mPackedInputBindings[attribIndex]; |
| 393 | bindingDesc.stride = 0; |
| 394 | bindingDesc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; |
| 395 | |
| 396 | vk::PackedVertexInputAttributeDesc &attribDesc = mPackedInputAttributes[attribIndex]; |
| 397 | attribDesc.format = static_cast<uint16_t>(VK_FORMAT_R32G32B32A32_SFLOAT); |
| 398 | attribDesc.location = static_cast<uint16_t>(attribIndex); |
| 399 | attribDesc.offset = 0; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 403 | mDirtyPackedInputs.reset(); |
| 404 | } |
| 405 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 406 | void VertexArrayVk::updatePackedInputInfo(uint32_t attribIndex, |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 407 | const gl::VertexBinding &binding, |
| 408 | const gl::VertexAttribute &attrib) |
| 409 | { |
| 410 | vk::PackedVertexInputBindingDesc &bindingDesc = mPackedInputBindings[attribIndex]; |
| 411 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 412 | bindingDesc.stride = static_cast<uint16_t>(mCurrentArrayBufferStrides[attribIndex]); |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 413 | bindingDesc.inputRate = static_cast<uint16_t>( |
| 414 | binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX); |
| 415 | |
Frank Henigman | 419acc8 | 2018-06-24 19:57:31 -0400 | [diff] [blame] | 416 | VkFormat vkFormat = mCurrentArrayBufferFormats[attribIndex]->vkBufferFormat; |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 417 | ASSERT(vkFormat <= std::numeric_limits<uint16_t>::max()); |
Frank Henigman | 8c379f3 | 2018-06-21 19:55:05 -0400 | [diff] [blame] | 418 | if (vkFormat == VK_FORMAT_UNDEFINED) |
| 419 | { |
Frank Henigman | 8c379f3 | 2018-06-21 19:55:05 -0400 | [diff] [blame] | 420 | UNIMPLEMENTED(); |
| 421 | } |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 422 | |
| 423 | vk::PackedVertexInputAttributeDesc &attribDesc = mPackedInputAttributes[attribIndex]; |
| 424 | attribDesc.format = static_cast<uint16_t>(vkFormat); |
| 425 | attribDesc.location = static_cast<uint16_t>(attribIndex); |
Luc Ferron | fa5d84b | 2018-06-28 10:40:04 -0400 | [diff] [blame] | 426 | attribDesc.offset = static_cast<uint32_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, |
| 430 | const gl::DrawCallParams &drawCallParams) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 431 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 432 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 433 | const gl::AttributesMask &clientAttribs = context->getStateCache().getActiveClientAttribsMask(); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 434 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 435 | ASSERT(clientAttribs.any()); |
| 436 | ANGLE_TRY_HANDLE(context, drawCallParams.ensureIndexRangeResolved(context)); |
| 437 | |
| 438 | mDynamicVertexData.releaseRetainedBuffers(contextVk->getRenderer()); |
| 439 | |
| 440 | const auto &attribs = mState.getVertexAttributes(); |
| 441 | const auto &bindings = mState.getVertexBindings(); |
| 442 | |
| 443 | // TODO(fjhenigman): When we have a bunch of interleaved attributes, they end up |
| 444 | // un-interleaved, wasting space and copying time. Consider improving on that. |
| 445 | for (size_t attribIndex : clientAttribs) |
| 446 | { |
| 447 | const gl::VertexAttribute &attrib = attribs[attribIndex]; |
| 448 | const gl::VertexBinding &binding = bindings[attrib.bindingIndex]; |
| 449 | ASSERT(attrib.enabled && binding.getBuffer().get() == nullptr); |
| 450 | |
| 451 | const size_t bytesToAllocate = |
| 452 | (drawCallParams.firstVertex() + drawCallParams.vertexCount()) * |
| 453 | mCurrentArrayBufferStrides[attribIndex]; |
| 454 | const uint8_t *src = static_cast<const uint8_t *>(attrib.pointer) + |
| 455 | drawCallParams.firstVertex() * binding.getStride(); |
| 456 | |
| 457 | size_t destOffset = drawCallParams.firstVertex() * mCurrentArrayBufferStrides[attribIndex]; |
| 458 | |
| 459 | // Only vertexCount() vertices will be used by the upcoming draw. so that is all we copy. |
| 460 | // We allocate space for firstVertex() + vertexCount() so indexing will work. If we |
| 461 | // don't start at zero all the indices will be off. |
| 462 | // TODO(fjhenigman): See if we can account for indices being off by adjusting the |
| 463 | // offset, thus avoiding wasted memory. |
| 464 | ANGLE_TRY(StreamVertexData(contextVk, &mDynamicVertexData, src, bytesToAllocate, destOffset, |
| 465 | drawCallParams.vertexCount(), binding.getStride(), |
| 466 | mCurrentArrayBufferFormats[attribIndex]->vertexLoadFunction, |
| 467 | &mCurrentArrayBufferHandles[attribIndex], |
| 468 | &mCurrentArrayBufferOffsets[attribIndex])); |
| 469 | } |
| 470 | |
| 471 | return angle::Result::Continue(); |
| 472 | } |
| 473 | |
| 474 | angle::Result VertexArrayVk::handleLineLoop(ContextVk *contextVk, |
| 475 | const gl::DrawCallParams &drawCallParams) |
| 476 | { |
| 477 | if (drawCallParams.isDrawElements()) |
| 478 | { |
| 479 | // Handle GL_LINE_LOOP drawElements. |
| 480 | if (mDirtyLineLoopTranslation) |
| 481 | { |
| 482 | gl::Buffer *elementArrayBuffer = mState.getElementArrayBuffer().get(); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 483 | |
| 484 | if (!elementArrayBuffer) |
| 485 | { |
Frank Henigman | 85c4b43 | 2018-09-19 23:35:00 -0400 | [diff] [blame] | 486 | ANGLE_TRY(mLineLoopHelper.streamIndices( |
| 487 | contextVk, drawCallParams.type(), drawCallParams.indexCount(), |
| 488 | reinterpret_cast<const uint8_t *>(drawCallParams.indices()), |
| 489 | &mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 490 | } |
| 491 | else |
| 492 | { |
| 493 | // When using an element array buffer, 'indices' is an offset to the first element. |
| 494 | intptr_t offset = reinterpret_cast<intptr_t>(drawCallParams.indices()); |
| 495 | BufferVk *elementArrayBufferVk = vk::GetImpl(elementArrayBuffer); |
| 496 | ANGLE_TRY(mLineLoopHelper.getIndexBufferForElementArrayBuffer( |
Frank Henigman | 85c4b43 | 2018-09-19 23:35:00 -0400 | [diff] [blame] | 497 | contextVk, elementArrayBufferVk, drawCallParams.type(), |
| 498 | drawCallParams.indexCount(), offset, &mCurrentElementArrayBufferHandle, |
| 499 | &mCurrentElementArrayBufferOffset)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | // If we've had a drawArrays call with a line loop before, we want to make sure this is |
| 504 | // invalidated the next time drawArrays is called since we use the same index buffer for |
| 505 | // both calls. |
| 506 | mLineLoopBufferFirstIndex.reset(); |
| 507 | mLineLoopBufferLastIndex.reset(); |
| 508 | return angle::Result::Continue(); |
| 509 | } |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 510 | |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 511 | // Note: Vertex indexes can be arbitrarily large. |
| 512 | uint32_t clampedVertexCount = drawCallParams.getClampedVertexCount<uint32_t>(); |
| 513 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 514 | // Handle GL_LINE_LOOP drawArrays. |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 515 | size_t lastVertex = static_cast<size_t>(drawCallParams.firstVertex() + clampedVertexCount); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 516 | if (!mLineLoopBufferFirstIndex.valid() || !mLineLoopBufferLastIndex.valid() || |
| 517 | mLineLoopBufferFirstIndex != drawCallParams.firstVertex() || |
| 518 | mLineLoopBufferLastIndex != lastVertex) |
| 519 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 520 | ANGLE_TRY(mLineLoopHelper.getIndexBufferForDrawArrays(contextVk, drawCallParams, |
Jamie Madill | 22f12fe | 2018-04-08 14:23:40 -0400 | [diff] [blame] | 521 | &mCurrentElementArrayBufferHandle, |
| 522 | &mCurrentElementArrayBufferOffset)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 523 | |
| 524 | mLineLoopBufferFirstIndex = drawCallParams.firstVertex(); |
| 525 | mLineLoopBufferLastIndex = lastVertex; |
| 526 | } |
| 527 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 528 | return angle::Result::Continue(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 529 | } |
| 530 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 531 | angle::Result VertexArrayVk::updateIndexTranslation(ContextVk *contextVk, |
| 532 | const gl::DrawCallParams &drawCallParams) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 533 | { |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 534 | ASSERT(drawCallParams.isDrawElements()); |
| 535 | ASSERT(drawCallParams.mode() != gl::PrimitiveMode::LineLoop); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 536 | |
Luc Ferron | 6ed167a | 2018-06-13 13:45:55 -0400 | [diff] [blame] | 537 | gl::Buffer *glBuffer = mState.getElementArrayBuffer().get(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 538 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 539 | if (!glBuffer) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 540 | { |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 541 | ANGLE_TRY(streamIndexData(contextVk, drawCallParams.type(), drawCallParams.indexCount(), |
| 542 | drawCallParams.indices(), &mDynamicIndexData)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 543 | } |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 544 | else |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 545 | { |
Frank Henigman | 9d84ccb | 2018-09-12 18:09:02 -0400 | [diff] [blame] | 546 | // Needed before reading buffer or we could get stale data. |
| 547 | ANGLE_TRY(contextVk->getRenderer()->finish(contextVk)); |
| 548 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 549 | ASSERT(drawCallParams.type() == GL_UNSIGNED_BYTE); |
| 550 | // Unsigned bytes don't have direct support in Vulkan so we have to expand the |
| 551 | // memory to a GLushort. |
| 552 | BufferVk *bufferVk = vk::GetImpl(glBuffer); |
| 553 | void *srcDataMapping = nullptr; |
| 554 | ASSERT(!glBuffer->isMapped()); |
| 555 | ANGLE_TRY(bufferVk->mapImpl(contextVk, &srcDataMapping)); |
| 556 | uint8_t *srcData = static_cast<uint8_t *>(srcDataMapping); |
| 557 | intptr_t offsetIntoSrcData = reinterpret_cast<intptr_t>(drawCallParams.indices()); |
| 558 | srcData += offsetIntoSrcData; |
Jamie Madill | 253038d | 2018-08-30 16:18:35 -0400 | [diff] [blame] | 559 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 560 | ANGLE_TRY(streamIndexData(contextVk, drawCallParams.type(), |
| 561 | static_cast<size_t>(bufferVk->getSize()) - offsetIntoSrcData, |
| 562 | srcData, &mTranslatedByteIndexData)); |
Luc Ferron | 6ed167a | 2018-06-13 13:45:55 -0400 | [diff] [blame] | 563 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 564 | ANGLE_TRY(bufferVk->unmapImpl(contextVk)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 567 | return angle::Result::Continue(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 568 | } |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 569 | |
| 570 | void VertexArrayVk::updateDefaultAttrib(RendererVk *renderer, |
| 571 | size_t attribIndex, |
| 572 | VkBuffer bufferHandle, |
| 573 | uint32_t offset) |
| 574 | { |
| 575 | if (!mState.getEnabledAttributesMask().test(attribIndex)) |
| 576 | { |
| 577 | mCurrentArrayBufferHandles[attribIndex] = bufferHandle; |
| 578 | mCurrentArrayBufferOffsets[attribIndex] = offset; |
| 579 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 580 | mCurrentArrayBufferStrides[attribIndex] = 0; |
| 581 | mCurrentArrayBufferFormats[attribIndex] = |
Jamie Madill | ba36593 | 2018-07-18 17:23:46 -0400 | [diff] [blame] | 582 | &renderer->getFormat(angle::FormatID::R32G32B32A32_FIXED); |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 583 | mDirtyPackedInputs.set(attribIndex); |
| 584 | } |
| 585 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 586 | } // namespace rx |