blob: 896dd56e302aa90a52f5c34a5ba42d8d71ae4daf [file] [log] [blame]
Jamie Madill9e54b5a2016-05-25 12:57:39 -04001//
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 Madillc564c072017-06-01 12:45:42 -040014#include "libANGLE/Context.h"
Jamie Madillbd159f02017-10-09 19:39:06 -040015#include "libANGLE/renderer/vulkan/BufferVk.h"
Jamie Madilldd43e6c2017-03-24 14:18:49 -040016#include "libANGLE/renderer/vulkan/ContextVk.h"
17
Jamie Madill9e54b5a2016-05-25 12:57:39 -040018namespace rx
19{
20
Jamie Madillbd159f02017-10-09 19:39:06 -040021VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state)
22 : VertexArrayImpl(state),
23 mCurrentVertexBufferHandlesCache(state.getMaxAttribs(), VK_NULL_HANDLE),
24 mCurrentVkBuffersCache(state.getMaxAttribs(), nullptr)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040025{
26}
27
Jamie Madill4928b7c2017-06-20 12:57:39 -040028void VertexArrayVk::destroy(const gl::Context *context)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040029{
30}
31
Jamie Madillc564c072017-06-01 12:45:42 -040032void VertexArrayVk::syncState(const gl::Context *context,
33 const gl::VertexArray::DirtyBits &dirtyBits)
Jamie Madilldd43e6c2017-03-24 14:18:49 -040034{
35 ASSERT(dirtyBits.any());
Jamie Madill72106562017-03-24 14:18:50 -040036
Jamie Madillbd159f02017-10-09 19:39:06 -040037 // Invalidate current pipeline.
Jamie Madill72106562017-03-24 14:18:50 -040038 // TODO(jmadill): Use pipeline cache.
Jamie Madillc564c072017-06-01 12:45:42 -040039 auto contextVk = GetImplAs<ContextVk>(context);
Jamie Madill72106562017-03-24 14:18:50 -040040 contextVk->invalidateCurrentPipeline();
Jamie Madillbd159f02017-10-09 19:39:06 -040041
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
79const std::vector<VkBuffer> &VertexArrayVk::getCurrentVertexBufferHandlesCache() const
80{
81 return mCurrentVertexBufferHandlesCache;
82}
83
84void VertexArrayVk::updateCurrentBufferSerials(const gl::AttributesMask &activeAttribsMask,
85 Serial serial)
86{
87 for (auto attribIndex : activeAttribsMask)
88 {
89 mCurrentVkBuffersCache[attribIndex]->setQueueSerial(serial);
90 }
Jamie Madilldd43e6c2017-03-24 14:18:49 -040091}
92
Jamie Madill9e54b5a2016-05-25 12:57:39 -040093} // namespace rx