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