Add Vulkan DrawContext utility class
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / framework / vulkan / vkImageWithMemory.hpp
1 #ifndef _VKIMAGEWITHMEMORY_HPP
2 #define _VKIMAGEWITHMEMORY_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2016 The Khronos Group Inc.
8  * Copyright (c) 2016 Google Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Image backed with memory
25  *//*--------------------------------------------------------------------*/
26
27 #include "vkDefs.hpp"
28 #include "vkMemUtil.hpp"
29 #include "vkQueryUtil.hpp"
30 #include "vkRef.hpp"
31 #include "vkRefUtil.hpp"
32
33 namespace vk
34 {
35 class ImageWithMemory
36 {
37 public:
38                                                                                 ImageWithMemory (const vk::DeviceInterface&             vk,
39                                                                                                                  const vk::VkDevice                             device,
40                                                                                                                  vk::Allocator&                                 allocator,
41                                                                                                                  const vk::VkImageCreateInfo&   imageCreateInfo,
42                                                                                                                  const vk::MemoryRequirement    memoryRequirement)
43
44                                                                                         : m_image               (createImage(vk, device, &imageCreateInfo))
45                                                                                         , m_allocation  (allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement))
46                                                                                 {
47                                                                                         VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
48                                                                                 }
49
50         const vk::VkImage&                                      get                             (void) const { return *m_image; }
51         const vk::VkImage&                                      operator*               (void) const { return get(); }
52         vk::Allocation&                                         getAllocation   (void) const { return *m_allocation; }
53
54 private:
55         const vk::Unique<vk::VkImage>           m_image;
56         const de::UniquePtr<vk::Allocation>     m_allocation;
57
58         // "deleted"
59                                                                                 ImageWithMemory (const ImageWithMemory&);
60         ImageWithMemory&                                        operator=               (const ImageWithMemory&);
61 };
62 } // vk
63
64 #endif // _VKIMAGEWITHMEMORY_HPP