xref: /aosp_15_r20/external/deqp/external/vulkancts/framework/vulkan/vkImageWithMemory.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 #include "vkImageWithMemory.hpp"
34 
35 namespace vk
36 {
37 class ImageWithMemory
38 {
39 public:
ImageWithMemory(const vk::DeviceInterface & vk,const vk::VkDevice device,vk::Allocator & allocator,const vk::VkImageCreateInfo & imageCreateInfo,const vk::MemoryRequirement memoryRequirement)40     ImageWithMemory(const vk::DeviceInterface &vk, const vk::VkDevice device, vk::Allocator &allocator,
41                     const vk::VkImageCreateInfo &imageCreateInfo, const vk::MemoryRequirement memoryRequirement)
42 
43         : m_image(createImage(vk, device, &imageCreateInfo))
44         , m_allocation(allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement))
45     {
46         VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
47     }
48 
get(void) const49     const vk::VkImage &get(void) const
50     {
51         return *m_image;
52     }
operator *(void) const53     const vk::VkImage &operator*(void) const
54     {
55         return get();
56     }
getAllocation(void) const57     vk::Allocation &getAllocation(void) const
58     {
59         return *m_allocation;
60     }
61 
62 private:
63     const vk::Unique<vk::VkImage> m_image;
64     const de::UniquePtr<vk::Allocation> m_allocation;
65 
66     // "deleted"
67     ImageWithMemory(const ImageWithMemory &);
68     ImageWithMemory &operator=(const ImageWithMemory &);
69 };
70 } // namespace vk
71 
72 #endif // _VKIMAGEWITHMEMORY_HPP
73