Merge remote-tracking branch 'gitlab/master' into dynamic_state_tests
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / dynamic_state / vktDynamicStateBufferObjectUtil.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Intel Corporation
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and/or associated documentation files (the
10  * "Materials"), to deal in the Materials without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Materials, and to
13  * permit persons to whom the Materials are furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice(s) and this permission notice shall be included
17  * in all copies or substantial portions of the Materials.
18  *
19  * The Materials are Confidential Information as defined by the
20  * Khronos Membership Agreement until designated non-confidential by Khronos,
21  * at which point this condition clause shall be removed.
22  *
23  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
30  *
31  *//*!
32  * \file
33  * \brief Buffer Object Util
34  *//*--------------------------------------------------------------------*/
35
36 #include "vktDynamicStateBufferObjectUtil.hpp"
37
38
39 #include "vkQueryUtil.hpp"
40
41
42 namespace vkt
43 {
44 namespace DynamicState
45 {
46
47 Buffer::Buffer (const vk::DeviceInterface &vk, vk::VkDevice device, vk::Move<vk::VkBuffer> object)
48         : m_object              (object)
49         , m_allocation  (DE_NULL)
50         , m_vk                  (vk)
51         , m_device              (device)
52 {
53 }
54
55 void Buffer::bindMemory (de::MovePtr<vk::Allocation> allocation)
56 {
57         DE_ASSERT(allocation);
58         VK_CHECK(m_vk.bindBufferMemory(m_device, *m_object, allocation->getMemory(), allocation->getOffset()));
59
60         DE_ASSERT(!m_allocation);
61         m_allocation = allocation;
62 }
63
64 de::SharedPtr<Buffer> Buffer::createAndAlloc (const vk::DeviceInterface &vk,
65         vk::VkDevice device,
66         const vk::VkBufferCreateInfo &createInfo,
67         vk::Allocator &allocator,
68         vk::MemoryRequirement memoryRequirement)
69 {
70         de::SharedPtr<Buffer> ret = create(vk, device, createInfo);
71
72         vk::VkMemoryRequirements bufferRequirements = vk::getBufferMemoryRequirements(vk, device, ret->object());
73         ret->bindMemory(allocator.allocate(bufferRequirements, memoryRequirement));
74         return ret;
75 }
76
77 de::SharedPtr<Buffer> Buffer::create (const vk::DeviceInterface &vk,
78                                                                           vk::VkDevice device,
79                                                                           const vk::VkBufferCreateInfo &createInfo)
80 {
81         return de::SharedPtr<Buffer>(new Buffer(vk, device, vk::createBuffer(vk, device, &createInfo)));
82 }
83
84 } //DynamicState
85 } //vkt