Merge "Don't require supported binary formats in negative tests." into marshmallow...
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / draw / vktDrawBufferObjectUtil.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Intel Corporation
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Buffer Object Util
23  *//*--------------------------------------------------------------------*/
24
25 #include "vktDrawBufferObjectUtil.hpp"
26
27 #include "vkQueryUtil.hpp"
28
29 namespace vkt
30 {
31 namespace Draw
32 {
33
34 Buffer::Buffer (const vk::DeviceInterface& vk, vk::VkDevice device, vk::Move<vk::VkBuffer> object_)
35         : m_allocation  (DE_NULL)
36         , m_object              (object_)
37         , m_vk                  (vk)
38         , m_device              (device)
39 {
40 }
41
42 void Buffer::bindMemory (de::MovePtr<vk::Allocation> allocation)
43 {
44         DE_ASSERT(allocation);
45         VK_CHECK(m_vk.bindBufferMemory(m_device, *m_object, allocation->getMemory(), allocation->getOffset()));
46
47         DE_ASSERT(!m_allocation);
48         m_allocation = allocation;
49 }
50
51 de::SharedPtr<Buffer> Buffer::createAndAlloc (const vk::DeviceInterface& vk,
52                                                                                           vk::VkDevice device,
53                                                                                           const vk::VkBufferCreateInfo &createInfo,
54                                                                                           vk::Allocator &allocator,
55                                                                                           vk::MemoryRequirement memoryRequirement)
56 {
57         de::SharedPtr<Buffer> ret = create(vk, device, createInfo);
58
59         vk::VkMemoryRequirements bufferRequirements = vk::getBufferMemoryRequirements(vk, device, ret->object());
60         ret->bindMemory(allocator.allocate(bufferRequirements, memoryRequirement));
61         return ret;
62 }
63
64 de::SharedPtr<Buffer> Buffer::create (const vk::DeviceInterface& vk,
65                                                                           vk::VkDevice device,
66                                                                           const vk::VkBufferCreateInfo& createInfo)
67 {
68         return de::SharedPtr<Buffer>(new Buffer(vk, device, vk::createBuffer(vk, device, &createInfo)));
69 }
70
71 } // Draw
72 } // vkt