resolve merge conflicts of 59febde9 to deqp-dev
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / vktExternalMemoryUtil.hpp
1 #ifndef _VKTEXTERNALMEMORYUTIL_HPP
2 #define _VKTEXTERNALMEMORYUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 Google Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * \brief Vulkan external memory utilities
22  *//*--------------------------------------------------------------------*/
23
24 #include "tcuDefs.hpp"
25
26 #include "vkPlatform.hpp"
27 #include "vkRefUtil.hpp"
28
29 namespace vkt
30 {
31 namespace ExternalMemoryUtil
32 {
33
34 class NativeHandle
35 {
36 public:
37         enum Win32HandleType
38         {
39                 WIN32HANDLETYPE_NT = 0,
40                 WIN32HANDLETYPE_KMT,
41
42                 WIN32HANDLETYPE_LAST
43         };
44
45                                                 NativeHandle    (void);
46                                                 NativeHandle    (const NativeHandle& other);
47                                                 NativeHandle    (int fd);
48                                                 NativeHandle    (Win32HandleType type, vk::pt::Win32Handle handle);
49                                                 ~NativeHandle   (void);
50
51         NativeHandle&           operator=               (int fd);
52
53         void                            setWin32Handle  (Win32HandleType type, vk::pt::Win32Handle handle);
54
55         vk::pt::Win32Handle     getWin32Handle  (void) const;
56         int                                     getFd                   (void) const;
57         void                            disown                  (void);
58         void                            reset                   (void);
59
60 private:
61         int                                     m_fd;
62         Win32HandleType         m_win32HandleType;
63         vk::pt::Win32Handle     m_win32Handle;
64
65         // Disabled
66         NativeHandle&           operator=               (const NativeHandle&);
67 };
68
69 const char*                                             externalSemaphoreTypeToName     (vk::VkExternalSemaphoreHandleTypeFlagBitsKHR type);
70 const char*                                             externalFenceTypeToName         (vk::VkExternalFenceHandleTypeFlagBitsKHR type);
71 const char*                                             externalMemoryTypeToName        (vk::VkExternalMemoryHandleTypeFlagBitsKHR type);
72
73 enum Permanence
74 {
75         PERMANENCE_PERMANENT = 0,
76         PERMANENCE_TEMPORARY
77 };
78
79 enum Transference
80 {
81         TRANSFERENCE_COPY = 0,
82         TRANSFERENCE_REFERENCE
83 };
84
85 bool                                                    isSupportedPermanence                           (vk::VkExternalSemaphoreHandleTypeFlagBitsKHR   type,
86                                                                                                                                          Permanence                                                                             permanence);
87 Transference                                    getHandelTypeTransferences                      (vk::VkExternalSemaphoreHandleTypeFlagBitsKHR   type);
88
89 bool                                                    isSupportedPermanence                           (vk::VkExternalFenceHandleTypeFlagBitsKHR               type,
90                                                                                                                                          Permanence                                                                             permanence);
91 Transference                                    getHandelTypeTransferences                      (vk::VkExternalFenceHandleTypeFlagBitsKHR               type);
92
93 int                                                             getMemoryFd                                                     (const vk::DeviceInterface&                                     vkd,
94                                                                                                                                          vk::VkDevice                                                           device,
95                                                                                                                                          vk::VkDeviceMemory                                                     memory,
96                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType);
97
98 void                                                    getMemoryNative                                         (const vk::DeviceInterface&                                     vkd,
99                                                                                                                                          vk::VkDevice                                                           device,
100                                                                                                                                          vk::VkDeviceMemory                                                     memory,
101                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
102                                                                                                                                          NativeHandle&                                                          nativeHandle);
103
104 vk::Move<vk::VkSemaphore>               createExportableSemaphore                       (const vk::DeviceInterface&                                             vkd,
105                                                                                                                                          vk::VkDevice                                                                   device,
106                                                                                                                                          vk::VkExternalSemaphoreHandleTypeFlagBitsKHR   externalType);
107
108 int                                                             getSemaphoreFd                                          (const vk::DeviceInterface&                                             vkd,
109                                                                                                                                          vk::VkDevice                                                                   device,
110                                                                                                                                          vk::VkSemaphore                                                                semaphore,
111                                                                                                                                          vk::VkExternalSemaphoreHandleTypeFlagBitsKHR   externalType);
112
113 void                                                    getSemaphoreNative                                      (const vk::DeviceInterface&                                             vkd,
114                                                                                                                                          vk::VkDevice                                                                   device,
115                                                                                                                                          vk::VkSemaphore                                                                semaphore,
116                                                                                                                                          vk::VkExternalSemaphoreHandleTypeFlagBitsKHR   externalType,
117                                                                                                                                          NativeHandle&                                                                  nativeHandle);
118
119 void                                                    importSemaphore                                         (const vk::DeviceInterface&                                             vkd,
120                                                                                                                                          const vk::VkDevice                                                             device,
121                                                                                                                                          const vk::VkSemaphore                                                  semaphore,
122                                                                                                                                          vk::VkExternalSemaphoreHandleTypeFlagBitsKHR   externalType,
123                                                                                                                                          NativeHandle&                                                                  handle,
124                                                                                                                                          vk::VkSemaphoreImportFlagsKHR                                  flags);
125
126 vk::Move<vk::VkSemaphore>               createAndImportSemaphore                        (const vk::DeviceInterface&                                             vkd,
127                                                                                                                                          const vk::VkDevice                                                             device,
128                                                                                                                                          vk::VkExternalSemaphoreHandleTypeFlagBitsKHR   externalType,
129                                                                                                                                          NativeHandle&                                                                  handle,
130                                                                                                                                          vk::VkSemaphoreImportFlagsKHR                                  flags);
131
132 vk::Move<vk::VkFence>                   createExportableFence                           (const vk::DeviceInterface&                                             vkd,
133                                                                                                                                          vk::VkDevice                                                                   device,
134                                                                                                                                          vk::VkExternalFenceHandleTypeFlagBitsKHR               externalType);
135
136 int                                                             getFenceFd                                                      (const vk::DeviceInterface&                                             vkd,
137                                                                                                                                          vk::VkDevice                                                                   device,
138                                                                                                                                          vk::VkFence                                                                    fence,
139                                                                                                                                          vk::VkExternalFenceHandleTypeFlagBitsKHR               externalType);
140
141 void                                                    getFenceNative                                          (const vk::DeviceInterface&                                             vkd,
142                                                                                                                                          vk::VkDevice                                                                   device,
143                                                                                                                                          vk::VkFence                                                                    fence,
144                                                                                                                                          vk::VkExternalFenceHandleTypeFlagBitsKHR               externalType,
145                                                                                                                                          NativeHandle&                                                                  nativeHandle);
146
147 void                                                    importFence                                                     (const vk::DeviceInterface&                                             vkd,
148                                                                                                                                          const vk::VkDevice                                                             device,
149                                                                                                                                          const vk::VkFence                                                              fence,
150                                                                                                                                          vk::VkExternalFenceHandleTypeFlagBitsKHR               externalType,
151                                                                                                                                          NativeHandle&                                                                  handle,
152                                                                                                                                          vk::VkFenceImportFlagsKHR                                              flags);
153
154 vk::Move<vk::VkFence>                   createAndImportFence                            (const vk::DeviceInterface&                                             vkd,
155                                                                                                                                          const vk::VkDevice                                                             device,
156                                                                                                                                          vk::VkExternalFenceHandleTypeFlagBitsKHR               externalType,
157                                                                                                                                          NativeHandle&                                                                  handle,
158                                                                                                                                          vk::VkFenceImportFlagsKHR                                              flags);
159
160 vk::Move<vk::VkDeviceMemory>    allocateExportableMemory                        (const vk::DeviceInterface&                                     vkd,
161                                                                                                                                          vk::VkDevice                                                           device,
162                                                                                                                                          const vk::VkMemoryRequirements&                        requirements,
163                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType);
164
165 // If buffer is not null use dedicated allocation
166 vk::Move<vk::VkDeviceMemory>    allocateExportableMemory                        (const vk::DeviceInterface&                                     vkd,
167                                                                                                                                          vk::VkDevice                                                           device,
168                                                                                                                                          const vk::VkMemoryRequirements&                        requirements,
169                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
170                                                                                                                                          vk::VkBuffer                                                           buffer);
171
172 // If image is not null use dedicated allocation
173 vk::Move<vk::VkDeviceMemory>    allocateExportableMemory                        (const vk::DeviceInterface&                                     vkd,
174                                                                                                                                          vk::VkDevice                                                           device,
175                                                                                                                                          const vk::VkMemoryRequirements&                        requirements,
176                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
177                                                                                                                                          vk::VkImage                                                            image);
178
179 // \note hostVisible argument is strict. Setting it to false will cause NotSupportedError to be thrown if non-host visible memory doesn't exist.
180 // If buffer is not null use dedicated allocation
181 vk::Move<vk::VkDeviceMemory>    allocateExportableMemory                        (const vk::InstanceInterface&                           vki,
182                                                                                                                                          vk::VkPhysicalDevice                                           physicalDevice,
183                                                                                                                                          const vk::DeviceInterface&                                     vkd,
184                                                                                                                                          vk::VkDevice                                                           device,
185                                                                                                                                          const vk::VkMemoryRequirements&                        requirements,
186                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
187                                                                                                                                          bool                                                                           hostVisible,
188                                                                                                                                          vk::VkBuffer                                                           buffer);
189
190 vk::Move<vk::VkDeviceMemory>    importMemory                                            (const vk::DeviceInterface&                                     vkd,
191                                                                                                                                          vk::VkDevice                                                           device,
192                                                                                                                                          const vk::VkMemoryRequirements&                        requirements,
193                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
194                                                                                                                                          NativeHandle&                                                          handle);
195
196 vk::Move<vk::VkDeviceMemory>    importDedicatedMemory                           (const vk::DeviceInterface&                                     vkd,
197                                                                                                                                          vk::VkDevice                                                           device,
198                                                                                                                                          vk::VkBuffer                                                           buffer,
199                                                                                                                                          const vk::VkMemoryRequirements&                        requirements,
200                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
201                                                                                                                                          NativeHandle&                                                          handle);
202
203 vk::Move<vk::VkDeviceMemory>    importDedicatedMemory                           (const vk::DeviceInterface&                                     vkd,
204                                                                                                                                          vk::VkDevice                                                           device,
205                                                                                                                                          vk::VkImage                                                            image,
206                                                                                                                                          const vk::VkMemoryRequirements&                        requirements,
207                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
208                                                                                                                                          NativeHandle&                                                          handle);
209
210 vk::Move<vk::VkBuffer>                  createExternalBuffer                            (const vk::DeviceInterface&                                     vkd,
211                                                                                                                                          vk::VkDevice                                                           device,
212                                                                                                                                          deUint32                                                                       queueFamilyIndex,
213                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
214                                                                                                                                          vk::VkDeviceSize                                                       size,
215                                                                                                                                          vk::VkBufferCreateFlags                                        createFlags,
216                                                                                                                                          vk::VkBufferUsageFlags                                         usageFlags);
217
218 vk::Move<vk::VkImage>                   createExternalImage                                     (const vk::DeviceInterface&                                     vkd,
219                                                                                                                                          vk::VkDevice                                                           device,
220                                                                                                                                          deUint32                                                                       queueFamilyIndex,
221                                                                                                                                          vk::VkExternalMemoryHandleTypeFlagBitsKHR      externalType,
222                                                                                                                                          vk::VkFormat                                                           format,
223                                                                                                                                          deUint32                                                                       width,
224                                                                                                                                          deUint32                                                                       height,
225                                                                                                                                          vk::VkImageTiling                                                      tiling,
226                                                                                                                                          vk::VkImageCreateFlags                                         createFlags,
227                                                                                                                                          vk::VkImageUsageFlags                                          usageFlags);
228
229 } // ExternalMemoryUtil
230 } // vkt
231
232 #endif // _VKTEXTERNALMEMORYUTIL_HPP