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; |
| 28 | } // anonymous namespace |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 29 | |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 30 | VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state, RendererVk *renderer) |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 31 | : VertexArrayImpl(state), |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 32 | mCurrentArrayBufferHandles{}, |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 33 | mCurrentArrayBufferOffsets{}, |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 34 | mCurrentArrayBufferResources{}, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 35 | mCurrentElementArrayBufferHandle(VK_NULL_HANDLE), |
| 36 | mCurrentElementArrayBufferOffset(0), |
| 37 | mCurrentElementArrayBufferResource(nullptr), |
| 38 | mDynamicVertexData(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, kDynamicVertexDataSize), |
| 39 | mDynamicIndexData(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, kDynamicIndexDataSize), |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 40 | mLineLoopHelper(renderer), |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 41 | mDirtyLineLoopTranslation(true), |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 42 | mVertexBuffersDirty(false), |
Luc Ferron | 49aacad | 2018-06-12 08:33:59 -0400 | [diff] [blame^] | 43 | mIndexBufferDirty(false), |
| 44 | mLastIndexBufferOffset(0) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 45 | { |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 46 | mCurrentArrayBufferHandles.fill(VK_NULL_HANDLE); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 47 | mCurrentArrayBufferOffsets.fill(0); |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 48 | mCurrentArrayBufferResources.fill(nullptr); |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 49 | |
| 50 | mPackedInputBindings.fill({0, 0}); |
| 51 | mPackedInputAttributes.fill({0, 0, 0}); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 52 | |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 53 | mDynamicVertexData.init(1, renderer); |
| 54 | mDynamicIndexData.init(1, renderer); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 55 | } |
| 56 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 57 | VertexArrayVk::~VertexArrayVk() |
| 58 | { |
| 59 | } |
| 60 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 61 | void VertexArrayVk::destroy(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 62 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 63 | VkDevice device = vk::GetImpl(context)->getRenderer()->getDevice(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 64 | mDynamicVertexData.destroy(device); |
| 65 | mDynamicIndexData.destroy(device); |
Jamie Madill | 22f12fe | 2018-04-08 14:23:40 -0400 | [diff] [blame] | 66 | mLineLoopHelper.destroy(device); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 69 | gl::Error VertexArrayVk::streamVertexData(RendererVk *renderer, |
| 70 | const gl::AttributesMask &attribsToStream, |
Jamie Madill | 32fd63b | 2018-03-31 11:20:35 -0400 | [diff] [blame] | 71 | const gl::DrawCallParams &drawCallParams) |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 72 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 73 | ASSERT(!attribsToStream.none()); |
| 74 | |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame] | 75 | const auto &attribs = mState.getVertexAttributes(); |
| 76 | const auto &bindings = mState.getVertexBindings(); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 77 | |
Jamie Madill | 32fd63b | 2018-03-31 11:20:35 -0400 | [diff] [blame] | 78 | const size_t lastVertex = drawCallParams.firstVertex() + drawCallParams.vertexCount(); |
| 79 | |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 80 | // TODO(fjhenigman): When we have a bunch of interleaved attributes, they end up |
| 81 | // un-interleaved, wasting space and copying time. Consider improving on that. |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 82 | for (size_t attribIndex : attribsToStream) |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 83 | { |
Frank Henigman | 6dd4a92 | 2018-03-02 16:35:13 -0500 | [diff] [blame] | 84 | const gl::VertexAttribute &attrib = attribs[attribIndex]; |
| 85 | const gl::VertexBinding &binding = bindings[attrib.bindingIndex]; |
| 86 | ASSERT(attrib.enabled && binding.getBuffer().get() == nullptr); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 87 | |
Frank Henigman | 6dd4a92 | 2018-03-02 16:35:13 -0500 | [diff] [blame] | 88 | // TODO(fjhenigman): Work with more formats than just GL_FLOAT. |
| 89 | if (attrib.type != GL_FLOAT) |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 90 | { |
Frank Henigman | 6dd4a92 | 2018-03-02 16:35:13 -0500 | [diff] [blame] | 91 | UNIMPLEMENTED(); |
| 92 | return gl::InternalError(); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 93 | } |
Frank Henigman | 6dd4a92 | 2018-03-02 16:35:13 -0500 | [diff] [blame] | 94 | |
| 95 | // Only [firstVertex, lastVertex] is needed by the upcoming draw so that |
| 96 | // is all we copy, but we allocate space for [0, lastVertex] so indexing |
| 97 | // will work. If we don't start at zero all the indices will be off. |
| 98 | // TODO(fjhenigman): See if we can account for indices being off by adjusting |
| 99 | // the offset, thus avoiding wasted memory. |
Jamie Madill | 32fd63b | 2018-03-31 11:20:35 -0400 | [diff] [blame] | 100 | const size_t firstByte = drawCallParams.firstVertex() * binding.getStride(); |
Frank Henigman | 6dd4a92 | 2018-03-02 16:35:13 -0500 | [diff] [blame] | 101 | const size_t lastByte = |
| 102 | lastVertex * binding.getStride() + gl::ComputeVertexAttributeTypeSize(attrib); |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 103 | uint8_t *dst = nullptr; |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 104 | uint32_t offset = 0; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 105 | ANGLE_TRY(mDynamicVertexData.allocate( |
| 106 | renderer, lastByte, &dst, &mCurrentArrayBufferHandles[attribIndex], &offset, nullptr)); |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 107 | mCurrentArrayBufferOffsets[attribIndex] = static_cast<VkDeviceSize>(offset); |
Frank Henigman | 6dd4a92 | 2018-03-02 16:35:13 -0500 | [diff] [blame] | 108 | memcpy(dst + firstByte, static_cast<const uint8_t *>(attrib.pointer) + firstByte, |
| 109 | lastByte - firstByte); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 110 | } |
| 111 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 112 | ANGLE_TRY(mDynamicVertexData.flush(renderer->getDevice())); |
Luc Ferron | 6185981 | 2018-05-09 14:17:39 -0400 | [diff] [blame] | 113 | mDynamicVertexData.releaseRetainedBuffers(renderer); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 114 | return gl::NoError(); |
| 115 | } |
| 116 | |
| 117 | gl::Error VertexArrayVk::streamIndexData(RendererVk *renderer, |
| 118 | const gl::DrawCallParams &drawCallParams) |
| 119 | { |
| 120 | ASSERT(!mState.getElementArrayBuffer().get()); |
| 121 | |
| 122 | uint32_t offset = 0; |
| 123 | |
| 124 | const GLsizei amount = sizeof(GLushort) * drawCallParams.indexCount(); |
| 125 | GLubyte *dst = nullptr; |
| 126 | |
| 127 | ANGLE_TRY(mDynamicIndexData.allocate(renderer, amount, &dst, &mCurrentElementArrayBufferHandle, |
| 128 | &offset, nullptr)); |
| 129 | if (drawCallParams.type() == GL_UNSIGNED_BYTE) |
| 130 | { |
| 131 | // Unsigned bytes don't have direct support in Vulkan so we have to expand the |
| 132 | // memory to a GLushort. |
| 133 | const GLubyte *in = static_cast<const GLubyte *>(drawCallParams.indices()); |
| 134 | GLushort *expandedDst = reinterpret_cast<GLushort *>(dst); |
| 135 | for (GLsizei index = 0; index < drawCallParams.indexCount(); index++) |
| 136 | { |
| 137 | expandedDst[index] = static_cast<GLushort>(in[index]); |
| 138 | } |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | memcpy(dst, drawCallParams.indices(), amount); |
| 143 | } |
| 144 | ANGLE_TRY(mDynamicIndexData.flush(renderer->getDevice())); |
Luc Ferron | 6185981 | 2018-05-09 14:17:39 -0400 | [diff] [blame] | 145 | mDynamicIndexData.releaseRetainedBuffers(renderer); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 146 | mCurrentElementArrayBufferOffset = offset; |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 147 | return gl::NoError(); |
| 148 | } |
| 149 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 150 | #define ANGLE_VERTEX_DIRTY_ATTRIB_FUNC(INDEX) \ |
| 151 | case gl::VertexArray::DIRTY_BIT_ATTRIB_0 + INDEX: \ |
| 152 | syncDirtyAttrib(attribs[INDEX], bindings[attribs[INDEX].bindingIndex], INDEX); \ |
| 153 | invalidatePipeline = true; \ |
| 154 | break; |
| 155 | |
| 156 | #define ANGLE_VERTEX_DIRTY_BINDING_FUNC(INDEX) \ |
| 157 | case gl::VertexArray::DIRTY_BIT_BINDING_0 + INDEX: \ |
| 158 | syncDirtyAttrib(attribs[INDEX], bindings[attribs[INDEX].bindingIndex], INDEX); \ |
| 159 | invalidatePipeline = true; \ |
| 160 | break; |
| 161 | |
| 162 | #define ANGLE_VERTEX_DIRTY_BUFFER_DATA_FUNC(INDEX) \ |
| 163 | case gl::VertexArray::DIRTY_BIT_BUFFER_DATA_0 + INDEX: \ |
| 164 | break; |
| 165 | |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 166 | gl::Error VertexArrayVk::syncState(const gl::Context *context, |
| 167 | const gl::VertexArray::DirtyBits &dirtyBits, |
| 168 | const gl::VertexArray::DirtyAttribBitsArray &attribBits, |
| 169 | const gl::VertexArray::DirtyBindingBitsArray &bindingBits) |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 170 | { |
| 171 | ASSERT(dirtyBits.any()); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 172 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 173 | bool invalidatePipeline = false; |
| 174 | |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 175 | // Invalidate current pipeline. |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 176 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 177 | |
| 178 | // Rebuild current attribute buffers cache. This will fail horribly if the buffer changes. |
| 179 | // TODO(jmadill): Handle buffer storage changes. |
| 180 | const auto &attribs = mState.getVertexAttributes(); |
| 181 | const auto &bindings = mState.getVertexBindings(); |
| 182 | |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 183 | for (size_t dirtyBit : dirtyBits) |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 184 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 185 | switch (dirtyBit) |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 186 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 187 | case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER: |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 188 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 189 | gl::Buffer *bufferGL = mState.getElementArrayBuffer().get(); |
| 190 | if (bufferGL) |
| 191 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 192 | BufferVk *bufferVk = vk::GetImpl(bufferGL); |
| 193 | mCurrentElementArrayBufferResource = bufferVk; |
| 194 | mCurrentElementArrayBufferHandle = bufferVk->getVkBuffer().getHandle(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 195 | } |
| 196 | else |
| 197 | { |
| 198 | mCurrentElementArrayBufferResource = nullptr; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 199 | mCurrentElementArrayBufferHandle = VK_NULL_HANDLE; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 200 | } |
Luc Ferron | 387b3b3 | 2018-05-28 10:11:57 -0400 | [diff] [blame] | 201 | |
| 202 | mCurrentElementArrayBufferOffset = 0; |
| 203 | mLineLoopBufferFirstIndex.reset(); |
| 204 | mLineLoopBufferLastIndex.reset(); |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 205 | mIndexBufferDirty = true; |
| 206 | mDirtyLineLoopTranslation = true; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 207 | break; |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 208 | } |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 209 | |
| 210 | case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA: |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 211 | mLineLoopBufferFirstIndex.reset(); |
| 212 | mLineLoopBufferLastIndex.reset(); |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 213 | mDirtyLineLoopTranslation = true; |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 214 | break; |
| 215 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 216 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_ATTRIB_FUNC); |
| 217 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BINDING_FUNC); |
| 218 | ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BUFFER_DATA_FUNC); |
| 219 | |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 220 | default: |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 221 | UNREACHABLE(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 222 | break; |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 223 | } |
| 224 | } |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 225 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 226 | if (invalidatePipeline) |
| 227 | { |
| 228 | mVertexBuffersDirty = true; |
| 229 | contextVk->invalidateCurrentPipeline(); |
| 230 | } |
| 231 | |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 232 | return gl::NoError(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 233 | } |
| 234 | |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 235 | void VertexArrayVk::syncDirtyAttrib(const gl::VertexAttribute &attrib, |
| 236 | const gl::VertexBinding &binding, |
| 237 | size_t attribIndex) |
| 238 | { |
| 239 | // Invalidate the input description for pipelines. |
| 240 | mDirtyPackedInputs.set(attribIndex); |
| 241 | |
| 242 | if (attrib.enabled) |
| 243 | { |
| 244 | gl::Buffer *bufferGL = binding.getBuffer().get(); |
| 245 | |
| 246 | if (bufferGL) |
| 247 | { |
| 248 | BufferVk *bufferVk = vk::GetImpl(bufferGL); |
| 249 | mCurrentArrayBufferResources[attribIndex] = bufferVk; |
| 250 | mCurrentArrayBufferHandles[attribIndex] = bufferVk->getVkBuffer().getHandle(); |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 251 | } |
| 252 | else |
| 253 | { |
| 254 | mCurrentArrayBufferResources[attribIndex] = nullptr; |
| 255 | mCurrentArrayBufferHandles[attribIndex] = VK_NULL_HANDLE; |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 256 | } |
| 257 | // TODO(jmadill): Offset handling. Assume zero for now. |
| 258 | mCurrentArrayBufferOffsets[attribIndex] = 0; |
| 259 | } |
| 260 | else |
| 261 | { |
Jamie Madill | a56467e | 2018-04-11 16:19:41 -0400 | [diff] [blame] | 262 | UNIMPLEMENTED(); |
| 263 | } |
| 264 | } |
| 265 | |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 266 | const gl::AttribArray<VkBuffer> &VertexArrayVk::getCurrentArrayBufferHandles() const |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 267 | { |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 268 | return mCurrentArrayBufferHandles; |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 269 | } |
| 270 | |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 271 | const gl::AttribArray<VkDeviceSize> &VertexArrayVk::getCurrentArrayBufferOffsets() const |
| 272 | { |
| 273 | return mCurrentArrayBufferOffsets; |
| 274 | } |
| 275 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 276 | void VertexArrayVk::updateArrayBufferReadDependencies(vk::CommandGraphResource *drawFramebuffer, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 277 | const gl::AttributesMask &activeAttribsMask, |
| 278 | Serial serial) |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 279 | { |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 280 | // Handle the bound array buffers. |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 281 | for (size_t attribIndex : activeAttribsMask) |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 282 | { |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 283 | if (mCurrentArrayBufferResources[attribIndex]) |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 284 | mCurrentArrayBufferResources[attribIndex]->addReadDependency(drawFramebuffer); |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 285 | } |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 286 | } |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 287 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 288 | void VertexArrayVk::updateElementArrayBufferReadDependency( |
| 289 | vk::CommandGraphResource *drawFramebuffer, |
| 290 | Serial serial) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 291 | { |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 292 | // Handle the bound element array buffer. |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 293 | if (mCurrentElementArrayBufferResource) |
Jamie Madill | da854a2 | 2017-11-30 17:24:21 -0500 | [diff] [blame] | 294 | { |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 295 | mCurrentElementArrayBufferResource->addReadDependency(drawFramebuffer); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 296 | } |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 299 | void VertexArrayVk::getPackedInputDescriptions(vk::PipelineDesc *pipelineDesc) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 300 | { |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 301 | updatePackedInputDescriptions(); |
| 302 | pipelineDesc->updateVertexInputInfo(mPackedInputBindings, mPackedInputAttributes); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 303 | } |
| 304 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 305 | void VertexArrayVk::updatePackedInputDescriptions() |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 306 | { |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 307 | if (!mDirtyPackedInputs.any()) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 308 | { |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | const auto &attribs = mState.getVertexAttributes(); |
| 313 | const auto &bindings = mState.getVertexBindings(); |
| 314 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 315 | for (auto attribIndex : mDirtyPackedInputs) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 316 | { |
| 317 | const auto &attrib = attribs[attribIndex]; |
| 318 | const auto &binding = bindings[attrib.bindingIndex]; |
| 319 | if (attrib.enabled) |
| 320 | { |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 321 | updatePackedInputInfo(static_cast<uint32_t>(attribIndex), binding, attrib); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 322 | } |
| 323 | else |
| 324 | { |
| 325 | UNIMPLEMENTED(); |
| 326 | } |
| 327 | } |
| 328 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 329 | mDirtyPackedInputs.reset(); |
| 330 | } |
| 331 | |
| 332 | void VertexArrayVk::updatePackedInputInfo(uint32_t attribIndex, |
| 333 | const gl::VertexBinding &binding, |
| 334 | const gl::VertexAttribute &attrib) |
| 335 | { |
| 336 | vk::PackedVertexInputBindingDesc &bindingDesc = mPackedInputBindings[attribIndex]; |
| 337 | |
| 338 | size_t attribSize = gl::ComputeVertexAttributeTypeSize(attrib); |
| 339 | ASSERT(attribSize <= std::numeric_limits<uint16_t>::max()); |
| 340 | |
Frank Henigman | a8e868f | 2018-01-28 23:32:25 -0500 | [diff] [blame] | 341 | bindingDesc.stride = static_cast<uint16_t>(binding.getStride()); |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 342 | bindingDesc.inputRate = static_cast<uint16_t>( |
| 343 | binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX); |
| 344 | |
| 345 | gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib); |
| 346 | VkFormat vkFormat = vk::GetNativeVertexFormat(vertexFormatType); |
| 347 | ASSERT(vkFormat <= std::numeric_limits<uint16_t>::max()); |
| 348 | |
| 349 | vk::PackedVertexInputAttributeDesc &attribDesc = mPackedInputAttributes[attribIndex]; |
| 350 | attribDesc.format = static_cast<uint16_t>(vkFormat); |
| 351 | attribDesc.location = static_cast<uint16_t>(attribIndex); |
| 352 | attribDesc.offset = static_cast<uint32_t>(ComputeVertexAttributeOffset(attrib, binding)); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 355 | gl::Error VertexArrayVk::drawArrays(const gl::Context *context, |
| 356 | RendererVk *renderer, |
| 357 | const gl::DrawCallParams &drawCallParams, |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 358 | vk::CommandBuffer *commandBuffer, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 359 | bool newCommandBuffer) |
| 360 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 361 | ASSERT(commandBuffer->valid()); |
| 362 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 363 | ANGLE_TRY(onDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 364 | |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 365 | // Note: Vertex indexes can be arbitrarily large. |
| 366 | uint32_t clampedVertexCount = drawCallParams.getClampedVertexCount<uint32_t>(); |
| 367 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 368 | if (drawCallParams.mode() != gl::PrimitiveMode::LineLoop) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 369 | { |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 370 | commandBuffer->draw(clampedVertexCount, 1, drawCallParams.firstVertex(), 0); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 371 | return gl::NoError(); |
| 372 | } |
| 373 | |
| 374 | // Handle GL_LINE_LOOP drawArrays. |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 375 | size_t lastVertex = static_cast<size_t>(drawCallParams.firstVertex() + clampedVertexCount); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 376 | if (!mLineLoopBufferFirstIndex.valid() || !mLineLoopBufferLastIndex.valid() || |
| 377 | mLineLoopBufferFirstIndex != drawCallParams.firstVertex() || |
| 378 | mLineLoopBufferLastIndex != lastVertex) |
| 379 | { |
Jamie Madill | 22f12fe | 2018-04-08 14:23:40 -0400 | [diff] [blame] | 380 | ANGLE_TRY(mLineLoopHelper.getIndexBufferForDrawArrays(renderer, drawCallParams, |
| 381 | &mCurrentElementArrayBufferHandle, |
| 382 | &mCurrentElementArrayBufferOffset)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 383 | |
| 384 | mLineLoopBufferFirstIndex = drawCallParams.firstVertex(); |
| 385 | mLineLoopBufferLastIndex = lastVertex; |
| 386 | } |
| 387 | |
| 388 | commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle, |
| 389 | mCurrentElementArrayBufferOffset, VK_INDEX_TYPE_UINT32); |
| 390 | |
Jamie Madill | 18e323a | 2018-05-11 16:54:17 -0400 | [diff] [blame] | 391 | vk::LineLoopHelper::Draw(clampedVertexCount, commandBuffer); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 392 | |
| 393 | return gl::NoError(); |
| 394 | } |
| 395 | |
| 396 | gl::Error VertexArrayVk::drawElements(const gl::Context *context, |
| 397 | RendererVk *renderer, |
| 398 | const gl::DrawCallParams &drawCallParams, |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 399 | vk::CommandBuffer *commandBuffer, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 400 | bool newCommandBuffer) |
| 401 | { |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 402 | ASSERT(commandBuffer->valid()); |
| 403 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 404 | if (drawCallParams.mode() != gl::PrimitiveMode::LineLoop) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 405 | { |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 406 | ANGLE_TRY( |
| 407 | onIndexedDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 408 | commandBuffer->drawIndexed(drawCallParams.indexCount(), 1, 0, 0, 0); |
| 409 | return gl::NoError(); |
| 410 | } |
| 411 | |
| 412 | // Handle GL_LINE_LOOP drawElements. |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 413 | if (mDirtyLineLoopTranslation) |
| 414 | { |
Luc Ferron | a912046 | 2018-04-12 13:11:03 -0400 | [diff] [blame] | 415 | gl::Buffer *elementArrayBuffer = mState.getElementArrayBuffer().get(); |
| 416 | VkIndexType indexType = gl_vk::GetIndexType(drawCallParams.type()); |
| 417 | |
| 418 | if (!elementArrayBuffer) |
| 419 | { |
| 420 | ANGLE_TRY(mLineLoopHelper.getIndexBufferForClientElementArray( |
Luc Ferron | 3e31380 | 2018-06-11 14:44:33 -0400 | [diff] [blame] | 421 | renderer, drawCallParams, &mCurrentElementArrayBufferHandle, |
| 422 | &mCurrentElementArrayBufferOffset)); |
Luc Ferron | a912046 | 2018-04-12 13:11:03 -0400 | [diff] [blame] | 423 | } |
| 424 | else |
| 425 | { |
Luc Ferron | a4fa9c2 | 2018-04-13 07:00:56 -0400 | [diff] [blame] | 426 | // When using an element array buffer, 'indices' is an offset to the first element. |
| 427 | intptr_t offset = reinterpret_cast<intptr_t>(drawCallParams.indices()); |
Luc Ferron | a912046 | 2018-04-12 13:11:03 -0400 | [diff] [blame] | 428 | BufferVk *elementArrayBufferVk = vk::GetImpl(elementArrayBuffer); |
| 429 | ANGLE_TRY(mLineLoopHelper.getIndexBufferForElementArrayBuffer( |
Luc Ferron | a4fa9c2 | 2018-04-13 07:00:56 -0400 | [diff] [blame] | 430 | renderer, elementArrayBufferVk, indexType, drawCallParams.indexCount(), offset, |
Luc Ferron | a912046 | 2018-04-12 13:11:03 -0400 | [diff] [blame] | 431 | &mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset)); |
| 432 | } |
Jamie Madill | b8e3966 | 2018-04-04 11:41:42 -0400 | [diff] [blame] | 433 | } |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 434 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 435 | ANGLE_TRY(onIndexedDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer)); |
Jamie Madill | 22f12fe | 2018-04-08 14:23:40 -0400 | [diff] [blame] | 436 | vk::LineLoopHelper::Draw(drawCallParams.indexCount(), commandBuffer); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 437 | |
| 438 | return gl::NoError(); |
| 439 | } |
| 440 | |
| 441 | gl::Error VertexArrayVk::onDraw(const gl::Context *context, |
| 442 | RendererVk *renderer, |
| 443 | const gl::DrawCallParams &drawCallParams, |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 444 | vk::CommandBuffer *commandBuffer, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 445 | bool newCommandBuffer) |
| 446 | { |
| 447 | const gl::State &state = context->getGLState(); |
| 448 | const gl::Program *programGL = state.getProgram(); |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame] | 449 | const gl::AttributesMask &clientAttribs = mState.getEnabledClientMemoryAttribsMask(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 450 | const gl::AttributesMask &activeAttribs = programGL->getActiveAttribLocationsMask(); |
| 451 | uint32_t maxAttrib = programGL->getState().getMaxActiveAttribLocation(); |
| 452 | |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame] | 453 | if (clientAttribs.any()) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 454 | { |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame] | 455 | const gl::AttributesMask &attribsToStream = (clientAttribs & activeAttribs); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 456 | if (attribsToStream.any()) |
| 457 | { |
| 458 | ANGLE_TRY(drawCallParams.ensureIndexRangeResolved(context)); |
| 459 | ANGLE_TRY(streamVertexData(renderer, attribsToStream, drawCallParams)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 460 | commandBuffer->bindVertexBuffers(0, maxAttrib, mCurrentArrayBufferHandles.data(), |
| 461 | mCurrentArrayBufferOffsets.data()); |
| 462 | } |
| 463 | } |
| 464 | else if (mVertexBuffersDirty || newCommandBuffer) |
| 465 | { |
Luc Ferron | 4416247 | 2018-04-06 13:20:45 -0400 | [diff] [blame] | 466 | if (maxAttrib > 0) |
| 467 | { |
Luc Ferron | 4416247 | 2018-04-06 13:20:45 -0400 | [diff] [blame] | 468 | commandBuffer->bindVertexBuffers(0, maxAttrib, mCurrentArrayBufferHandles.data(), |
| 469 | mCurrentArrayBufferOffsets.data()); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 470 | |
| 471 | vk::CommandGraphResource *drawFramebuffer = vk::GetImpl(state.getDrawFramebuffer()); |
| 472 | updateArrayBufferReadDependencies(drawFramebuffer, activeAttribs, |
Luc Ferron | 4416247 | 2018-04-06 13:20:45 -0400 | [diff] [blame] | 473 | renderer->getCurrentQueueSerial()); |
| 474 | } |
Luc Ferron | c1e0268 | 2018-04-11 11:02:55 -0400 | [diff] [blame] | 475 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 476 | mVertexBuffersDirty = false; |
Luc Ferron | c1e0268 | 2018-04-11 11:02:55 -0400 | [diff] [blame] | 477 | |
| 478 | // This forces the binding to happen if we follow a drawElement call from a drawArrays call. |
| 479 | mIndexBufferDirty = true; |
Luc Ferron | 983c429 | 2018-04-10 13:05:45 -0400 | [diff] [blame] | 480 | |
| 481 | // If we've had a drawElements call with a line loop before, we want to make sure this is |
| 482 | // invalidated the next time drawElements is called since we use the same index buffer for |
| 483 | // both calls. |
| 484 | mDirtyLineLoopTranslation = true; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | return gl::NoError(); |
| 488 | } |
| 489 | |
| 490 | gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context, |
| 491 | RendererVk *renderer, |
| 492 | const gl::DrawCallParams &drawCallParams, |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 493 | vk::CommandBuffer *commandBuffer, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 494 | bool newCommandBuffer) |
| 495 | { |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 496 | ANGLE_TRY(onDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer)); |
Luc Ferron | 49aacad | 2018-06-12 08:33:59 -0400 | [diff] [blame^] | 497 | bool isLineLoop = drawCallParams.mode() == gl::PrimitiveMode::LineLoop; |
| 498 | uintptr_t offset = mState.getElementArrayBuffer().get() && !isLineLoop |
| 499 | ? reinterpret_cast<uintptr_t>(drawCallParams.indices()) |
| 500 | : 0; |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 501 | |
Luc Ferron | 49aacad | 2018-06-12 08:33:59 -0400 | [diff] [blame^] | 502 | if (!mState.getElementArrayBuffer().get() && !isLineLoop) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 503 | { |
| 504 | ANGLE_TRY(drawCallParams.ensureIndexRangeResolved(context)); |
| 505 | ANGLE_TRY(streamIndexData(renderer, drawCallParams)); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 506 | commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle, |
| 507 | mCurrentElementArrayBufferOffset, |
| 508 | gl_vk::GetIndexType(drawCallParams.type())); |
| 509 | } |
Luc Ferron | 49aacad | 2018-06-12 08:33:59 -0400 | [diff] [blame^] | 510 | else if (mIndexBufferDirty || newCommandBuffer || offset != mLastIndexBufferOffset) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 511 | { |
Luc Ferron | 3e31380 | 2018-06-11 14:44:33 -0400 | [diff] [blame] | 512 | if (drawCallParams.type() == GL_UNSIGNED_BYTE && |
| 513 | drawCallParams.mode() != gl::PrimitiveMode::LineLoop) |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 514 | { |
Luc Ferron | 3e31380 | 2018-06-11 14:44:33 -0400 | [diff] [blame] | 515 | // TODO(fjhenigman): Index format translation for non line-loop calls. |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 516 | UNIMPLEMENTED(); |
| 517 | return gl::InternalError() |
| 518 | << "Unsigned byte translation is not implemented for indices in a buffer object"; |
| 519 | } |
| 520 | |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 521 | commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle, |
Luc Ferron | 49aacad | 2018-06-12 08:33:59 -0400 | [diff] [blame^] | 522 | mCurrentElementArrayBufferOffset + offset, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 523 | gl_vk::GetIndexType(drawCallParams.type())); |
Luc Ferron | 49aacad | 2018-06-12 08:33:59 -0400 | [diff] [blame^] | 524 | mLastIndexBufferOffset = offset; |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 525 | |
| 526 | const gl::State &glState = context->getGLState(); |
| 527 | vk::CommandGraphResource *drawFramebuffer = vk::GetImpl(glState.getDrawFramebuffer()); |
| 528 | updateElementArrayBufferReadDependency(drawFramebuffer, renderer->getCurrentQueueSerial()); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 529 | mIndexBufferDirty = false; |
Luc Ferron | 983c429 | 2018-04-10 13:05:45 -0400 | [diff] [blame] | 530 | |
| 531 | // If we've had a drawArrays call with a line loop before, we want to make sure this is |
| 532 | // invalidated the next time drawArrays is called since we use the same index buffer for |
| 533 | // both calls. |
| 534 | mLineLoopBufferFirstIndex.reset(); |
| 535 | mLineLoopBufferLastIndex.reset(); |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | return gl::NoError(); |
| 539 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 540 | } // namespace rx |