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 | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 16 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
| 17 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 18 | namespace rx |
| 19 | { |
| 20 | |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame^] | 21 | VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state) |
| 22 | : VertexArrayImpl(state), |
| 23 | mCurrentVertexBufferHandlesCache(state.getMaxAttribs(), VK_NULL_HANDLE), |
| 24 | mCurrentVkBuffersCache(state.getMaxAttribs(), nullptr) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 25 | { |
| 26 | } |
| 27 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 28 | void VertexArrayVk::destroy(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 32 | void VertexArrayVk::syncState(const gl::Context *context, |
| 33 | const gl::VertexArray::DirtyBits &dirtyBits) |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 34 | { |
| 35 | ASSERT(dirtyBits.any()); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 36 | |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame^] | 37 | // Invalidate current pipeline. |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 38 | // TODO(jmadill): Use pipeline cache. |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 39 | auto contextVk = GetImplAs<ContextVk>(context); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 40 | contextVk->invalidateCurrentPipeline(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame^] | 41 | |
| 42 | // Rebuild current attribute buffers cache. This will fail horribly if the buffer changes. |
| 43 | // TODO(jmadill): Handle buffer storage changes. |
| 44 | const auto &attribs = mState.getVertexAttributes(); |
| 45 | const auto &bindings = mState.getVertexBindings(); |
| 46 | |
| 47 | for (auto dirtyBit : dirtyBits) |
| 48 | { |
| 49 | if (dirtyBit == gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER) |
| 50 | continue; |
| 51 | |
| 52 | size_t attribIndex = gl::VertexArray::GetVertexIndexFromDirtyBit(dirtyBit); |
| 53 | |
| 54 | const auto &attrib = attribs[attribIndex]; |
| 55 | const auto &binding = bindings[attrib.bindingIndex]; |
| 56 | if (attrib.enabled) |
| 57 | { |
| 58 | gl::Buffer *bufferGL = binding.getBuffer().get(); |
| 59 | |
| 60 | if (bufferGL) |
| 61 | { |
| 62 | BufferVk *bufferVk = GetImplAs<BufferVk>(bufferGL); |
| 63 | mCurrentVkBuffersCache[attribIndex] = bufferVk; |
| 64 | mCurrentVertexBufferHandlesCache[attribIndex] = bufferVk->getVkBuffer().getHandle(); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | mCurrentVkBuffersCache[attribIndex] = nullptr; |
| 69 | mCurrentVertexBufferHandlesCache[attribIndex] = VK_NULL_HANDLE; |
| 70 | } |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | UNIMPLEMENTED(); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | const std::vector<VkBuffer> &VertexArrayVk::getCurrentVertexBufferHandlesCache() const |
| 80 | { |
| 81 | return mCurrentVertexBufferHandlesCache; |
| 82 | } |
| 83 | |
| 84 | void VertexArrayVk::updateCurrentBufferSerials(const gl::AttributesMask &activeAttribsMask, |
| 85 | Serial serial) |
| 86 | { |
| 87 | for (auto attribIndex : activeAttribsMask) |
| 88 | { |
| 89 | mCurrentVkBuffersCache[attribIndex]->setQueueSerial(serial); |
| 90 | } |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 93 | } // namespace rx |