1 #ifndef _VKTEXTERNALMEMORYUTIL_HPP
2 #define _VKTEXTERNALMEMORYUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2016 Google Inc.
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Vulkan external memory utilities
22 *//*--------------------------------------------------------------------*/
24 #include "tcuDefs.hpp"
26 #include "vkPlatform.hpp"
27 #include "vkRefUtil.hpp"
31 namespace ExternalMemoryUtil
39 WIN32HANDLETYPE_NT = 0,
46 NativeHandle (const NativeHandle& other);
47 NativeHandle (int fd);
48 NativeHandle (Win32HandleType type, vk::pt::Win32Handle handle);
51 NativeHandle& operator= (int fd);
53 void setWin32Handle (Win32HandleType type, vk::pt::Win32Handle handle);
55 vk::pt::Win32Handle getWin32Handle (void) const;
56 int getFd (void) const;
62 Win32HandleType m_win32HandleType;
63 vk::pt::Win32Handle m_win32Handle;
66 NativeHandle& operator= (const NativeHandle&);
69 const char* externalSemaphoreTypeToName (vk::VkExternalSemaphoreHandleTypeFlagBitsKHR type);
70 const char* externalFenceTypeToName (vk::VkExternalFenceHandleTypeFlagBitsKHR type);
71 const char* externalMemoryTypeToName (vk::VkExternalMemoryHandleTypeFlagBitsKHR type);
75 PERMANENCE_PERMANENT = 0,
81 TRANSFERENCE_COPY = 0,
82 TRANSFERENCE_REFERENCE
85 bool isSupportedPermanence (vk::VkExternalSemaphoreHandleTypeFlagBitsKHR type,
86 Permanence permanence);
87 Transference getHandelTypeTransferences (vk::VkExternalSemaphoreHandleTypeFlagBitsKHR type);
89 bool isSupportedPermanence (vk::VkExternalFenceHandleTypeFlagBitsKHR type,
90 Permanence permanence);
91 Transference getHandelTypeTransferences (vk::VkExternalFenceHandleTypeFlagBitsKHR type);
93 int getMemoryFd (const vk::DeviceInterface& vkd,
95 vk::VkDeviceMemory memory,
96 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType);
98 void getMemoryNative (const vk::DeviceInterface& vkd,
100 vk::VkDeviceMemory memory,
101 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
102 NativeHandle& nativeHandle);
104 vk::Move<vk::VkSemaphore> createExportableSemaphore (const vk::DeviceInterface& vkd,
106 vk::VkExternalSemaphoreHandleTypeFlagBitsKHR externalType);
108 int getSemaphoreFd (const vk::DeviceInterface& vkd,
110 vk::VkSemaphore semaphore,
111 vk::VkExternalSemaphoreHandleTypeFlagBitsKHR externalType);
113 void getSemaphoreNative (const vk::DeviceInterface& vkd,
115 vk::VkSemaphore semaphore,
116 vk::VkExternalSemaphoreHandleTypeFlagBitsKHR externalType,
117 NativeHandle& nativeHandle);
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);
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);
132 vk::Move<vk::VkFence> createExportableFence (const vk::DeviceInterface& vkd,
134 vk::VkExternalFenceHandleTypeFlagBitsKHR externalType);
136 int getFenceFd (const vk::DeviceInterface& vkd,
139 vk::VkExternalFenceHandleTypeFlagBitsKHR externalType);
141 void getFenceNative (const vk::DeviceInterface& vkd,
144 vk::VkExternalFenceHandleTypeFlagBitsKHR externalType,
145 NativeHandle& nativeHandle);
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);
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);
160 vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
162 const vk::VkMemoryRequirements& requirements,
163 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType);
165 // If buffer is not null use dedicated allocation
166 vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
168 const vk::VkMemoryRequirements& requirements,
169 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
170 vk::VkBuffer buffer);
172 // If image is not null use dedicated allocation
173 vk::Move<vk::VkDeviceMemory> allocateExportableMemory (const vk::DeviceInterface& vkd,
175 const vk::VkMemoryRequirements& requirements,
176 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
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,
185 const vk::VkMemoryRequirements& requirements,
186 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
188 vk::VkBuffer buffer);
190 vk::Move<vk::VkDeviceMemory> importMemory (const vk::DeviceInterface& vkd,
192 const vk::VkMemoryRequirements& requirements,
193 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
194 NativeHandle& handle);
196 vk::Move<vk::VkDeviceMemory> importDedicatedMemory (const vk::DeviceInterface& vkd,
199 const vk::VkMemoryRequirements& requirements,
200 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
201 NativeHandle& handle);
203 vk::Move<vk::VkDeviceMemory> importDedicatedMemory (const vk::DeviceInterface& vkd,
206 const vk::VkMemoryRequirements& requirements,
207 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
208 NativeHandle& handle);
210 vk::Move<vk::VkBuffer> createExternalBuffer (const vk::DeviceInterface& vkd,
212 deUint32 queueFamilyIndex,
213 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
214 vk::VkDeviceSize size,
215 vk::VkBufferCreateFlags createFlags,
216 vk::VkBufferUsageFlags usageFlags);
218 vk::Move<vk::VkImage> createExternalImage (const vk::DeviceInterface& vkd,
220 deUint32 queueFamilyIndex,
221 vk::VkExternalMemoryHandleTypeFlagBitsKHR externalType,
225 vk::VkImageTiling tiling,
226 vk::VkImageCreateFlags createFlags,
227 vk::VkImageUsageFlags usageFlags);
229 } // ExternalMemoryUtil
232 #endif // _VKTEXTERNALMEMORYUTIL_HPP