blob: 5503df52feaaef00ae9c0c3632d85569dd2c8eab [file] [log] [blame]
Mark Lobodzinski317574e2016-08-29 14:21:14 -06001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@lunarg.com>
19 */
20
21#define _GNU_SOURCE
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include "vk_loader_platform.h"
26#include "loader.h"
27#include "extensions.h"
28#include <vulkan/vk_icd.h>
Mark Young65cb3662016-11-07 13:27:02 -070029#include "wsi.h"
30
31// Definitions for the VK_EXT_debug_marker extension commands which
32// need to have a terminator function
33
34VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectTagEXT(
35 VkDevice device, VkDebugMarkerObjectTagInfoEXT *pTagInfo) {
36 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
37 // If this is a physical device, we have to replace it with the proper one
38 // for the next call.
39 if (pTagInfo->objectType ==
40 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
41 struct loader_physical_device_tramp *phys_dev_tramp =
Karl Schultz94971292016-11-19 09:02:27 -070042 (struct loader_physical_device_tramp *)(uintptr_t)pTagInfo->object;
43 pTagInfo->object = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev;
Mark Young65cb3662016-11-07 13:27:02 -070044 }
45 return disp->DebugMarkerSetObjectTagEXT(device, pTagInfo);
46}
47
48VKAPI_ATTR VkResult VKAPI_CALL terminator_DebugMarkerSetObjectTagEXT(
49 VkDevice device, VkDebugMarkerObjectTagInfoEXT *pTagInfo) {
50 uint32_t icd_index = 0;
51 struct loader_device *dev;
52 struct loader_icd_term *icd_term =
53 loader_get_icd_and_device(device, &dev, &icd_index);
Mark Younga095cca2016-12-02 15:02:52 -070054 if (NULL != icd_term && NULL != icd_term->DebugMarkerSetObjectTagEXT) {
55 // If this is a physical device, we have to replace it with the proper
56 // one for the next call.
57 if (pTagInfo->objectType ==
58 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
59 struct loader_physical_device_term *phys_dev_term =
60 (struct loader_physical_device_term *)(uintptr_t)
61 pTagInfo->object;
62 pTagInfo->object = (uint64_t)(uintptr_t)phys_dev_term->phys_dev;
Mark Young65cb3662016-11-07 13:27:02 -070063
Mark Younga095cca2016-12-02 15:02:52 -070064 // If this is a KHR_surface, and the ICD has created its own, we
65 // have to replace it with the proper one for the next call.
66 } else if (pTagInfo->objectType ==
67 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) {
68 if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) {
69 VkIcdSurface *icd_surface =
70 (VkIcdSurface *)(uintptr_t)pTagInfo->object;
71 if (NULL != icd_surface->real_icd_surfaces) {
72 pTagInfo->object =
73 (uint64_t)icd_surface->real_icd_surfaces[icd_index];
74 }
Mark Young65cb3662016-11-07 13:27:02 -070075 }
76 }
Mark Younga095cca2016-12-02 15:02:52 -070077 return icd_term->DebugMarkerSetObjectTagEXT(device, pTagInfo);
78 } else {
79 return VK_SUCCESS;
Mark Young65cb3662016-11-07 13:27:02 -070080 }
Mark Young65cb3662016-11-07 13:27:02 -070081}
82
83VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectNameEXT(
84 VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
85 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
86 // If this is a physical device, we have to replace it with the proper one
87 // for the next call.
88 if (pNameInfo->objectType ==
89 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
90 struct loader_physical_device_tramp *phys_dev_tramp =
Karl Schultz94971292016-11-19 09:02:27 -070091 (struct loader_physical_device_tramp *)(uintptr_t)pNameInfo->object;
92 pNameInfo->object = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev;
Mark Young65cb3662016-11-07 13:27:02 -070093 }
94 return disp->DebugMarkerSetObjectNameEXT(device, pNameInfo);
95}
96
97VKAPI_ATTR VkResult VKAPI_CALL terminator_DebugMarkerSetObjectNameEXT(
98 VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
99 uint32_t icd_index = 0;
100 struct loader_device *dev;
101 struct loader_icd_term *icd_term =
102 loader_get_icd_and_device(device, &dev, &icd_index);
Mark Younga095cca2016-12-02 15:02:52 -0700103 if (NULL != icd_term && NULL != icd_term->DebugMarkerSetObjectNameEXT) {
104 // If this is a physical device, we have to replace it with the proper
105 // one for the next call.
106 if (pNameInfo->objectType ==
107 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
108 struct loader_physical_device_term *phys_dev_term =
109 (struct loader_physical_device_term *)(uintptr_t)
110 pNameInfo->object;
111 pNameInfo->object = (uint64_t)(uintptr_t)phys_dev_term->phys_dev;
Mark Young65cb3662016-11-07 13:27:02 -0700112
Mark Younga095cca2016-12-02 15:02:52 -0700113 // If this is a KHR_surface, and the ICD has created its own, we
114 // have to replace it with the proper one for the next call.
115 } else if (pNameInfo->objectType ==
116 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) {
117 if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) {
118 VkIcdSurface *icd_surface =
119 (VkIcdSurface *)(uintptr_t)pNameInfo->object;
120 if (NULL != icd_surface->real_icd_surfaces) {
121 pNameInfo->object =
122 (uint64_t)(
123 uintptr_t)icd_surface->real_icd_surfaces[icd_index];
124 }
Mark Young65cb3662016-11-07 13:27:02 -0700125 }
126 }
Mark Younga095cca2016-12-02 15:02:52 -0700127 return icd_term->DebugMarkerSetObjectNameEXT(device, pNameInfo);
128 } else {
129 return VK_SUCCESS;
Mark Young65cb3662016-11-07 13:27:02 -0700130 }
Mark Young65cb3662016-11-07 13:27:02 -0700131}
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600132
Mark Young35159af2016-09-07 08:50:32 -0600133// Definitions for the VK_NV_external_memory_capabilities extension
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600134
135LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
136vkGetPhysicalDeviceExternalImageFormatPropertiesNV(
137 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
138 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
139 VkExternalMemoryHandleTypeFlagsNV externalHandleType,
140 VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600141 const VkLayerInstanceDispatchTable *disp;
142 VkPhysicalDevice unwrapped_phys_dev =
143 loader_unwrap_physical_device(physicalDevice);
144 disp = loader_get_instance_dispatch(physicalDevice);
145
Mark Young5210abc2016-09-08 18:36:32 -0600146 return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV(
147 unwrapped_phys_dev, format, type, tiling, usage, flags,
148 externalHandleType, pExternalImageFormatProperties);
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600149}
150
151VKAPI_ATTR VkResult VKAPI_CALL
152terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV(
153 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
154 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
155 VkExternalMemoryHandleTypeFlagsNV externalHandleType,
156 VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
Mark Young0153e0b2016-11-03 14:27:13 -0600157 struct loader_physical_device_term *phys_dev_term =
158 (struct loader_physical_device_term *)physicalDevice;
159 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600160
Mark Young0153e0b2016-11-03 14:27:13 -0600161 if (!icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV) {
James Jones389dc0c2016-08-18 23:41:19 +0100162 if (externalHandleType) {
163 return VK_ERROR_FORMAT_NOT_SUPPORTED;
164 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600165
Mark Young0153e0b2016-11-03 14:27:13 -0600166 if (!icd_term->GetPhysicalDeviceImageFormatProperties) {
James Jones389dc0c2016-08-18 23:41:19 +0100167 return VK_ERROR_INITIALIZATION_FAILED;
168 }
169
170 pExternalImageFormatProperties->externalMemoryFeatures = 0;
171 pExternalImageFormatProperties->exportFromImportedHandleTypes = 0;
172 pExternalImageFormatProperties->compatibleHandleTypes = 0;
173
Mark Young0153e0b2016-11-03 14:27:13 -0600174 return icd_term->GetPhysicalDeviceImageFormatProperties(
175 phys_dev_term->phys_dev, format, type, tiling, usage, flags,
James Jones389dc0c2016-08-18 23:41:19 +0100176 &pExternalImageFormatProperties->imageFormatProperties);
177 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600178
Mark Young0153e0b2016-11-03 14:27:13 -0600179 return icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV(
180 phys_dev_term->phys_dev, format, type, tiling, usage, flags,
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600181 externalHandleType, pExternalImageFormatProperties);
182}
183
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600184// Definitions for the VK_AMD_draw_indirect_count extension
185
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600186VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD(
187 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
188 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
189 uint32_t stride) {
Mark Young5210abc2016-09-08 18:36:32 -0600190 const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
191 disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer,
192 countBufferOffset, maxDrawCount, stride);
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600193}
194
195VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD(
196 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
197 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
198 uint32_t stride) {
Mark Young5210abc2016-09-08 18:36:32 -0600199 const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
200 disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset,
201 countBuffer, countBufferOffset,
202 maxDrawCount, stride);
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600203}
204
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600205#ifdef VK_USE_PLATFORM_WIN32_KHR
206
207// Definitions for the VK_NV_external_memory_win32 extension
208
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600209VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV(
210 VkDevice device, VkDeviceMemory memory,
211 VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) {
Mark Young5210abc2016-09-08 18:36:32 -0600212 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
213 return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle);
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600214}
215
216#endif // VK_USE_PLATFORM_WIN32_KHR
217
218// GPA helpers for non-KHR extensions
219
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600220bool extension_instance_gpa(struct loader_instance *ptr_instance,
221 const char *name, void **addr) {
222 *addr = NULL;
223
Mark Young65cb3662016-11-07 13:27:02 -0700224 // Definitions for the VK_EXT_debug_marker extension commands which
225 // need to have a terminator function. Since these are device
226 // commands, we always need to return a valid value for them.
227
228 if (!strcmp("vkDebugMarkerSetObjectTagEXT", name)) {
229 *addr = (void *)vkDebugMarkerSetObjectTagEXT;
230 return true;
231 }
232 if (!strcmp("vkDebugMarkerSetObjectNameEXT", name)) {
233 *addr = (void *)vkDebugMarkerSetObjectNameEXT;
234 return true;
235 }
236
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600237 // Functions for the VK_NV_external_memory_capabilities extension
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600238
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600239 if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) {
Mark Young35159af2016-09-07 08:50:32 -0600240 *addr = (ptr_instance->enabled_known_extensions
241 .nv_external_memory_capabilities == 1)
242 ? (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV
243 : NULL;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600244 return true;
245 }
246
Mark Young3ea0ff52016-09-09 07:26:48 -0600247 // Functions for the VK_AMD_draw_indirect_count extension
248
249 if (!strcmp("vkCmdDrawIndirectCountAMD", name)) {
250 *addr = (void *)vkCmdDrawIndirectCountAMD;
251 return true;
252 }
253
254 if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) {
255 *addr = (void *)vkCmdDrawIndexedIndirectCountAMD;
256 return true;
257 }
258
259#ifdef VK_USE_PLATFORM_WIN32_KHR
260
261 // Functions for the VK_NV_external_memory_win32 extension
262
263 if (!strcmp("vkGetMemoryWin32HandleNV", name)) {
264 *addr = (void *)vkGetMemoryWin32HandleNV;
265 return true;
266 }
267
268#endif // VK_USE_PLATFORM_WIN32_KHR
269
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600270 return false;
271}
272
273void extensions_create_instance(struct loader_instance *ptr_instance,
274 const VkInstanceCreateInfo *pCreateInfo) {
Mark Young35159af2016-09-07 08:50:32 -0600275 ptr_instance->enabled_known_extensions.nv_external_memory_capabilities = 0;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600276
277 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
278 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
279 VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) {
Mark Young35159af2016-09-07 08:50:32 -0600280 ptr_instance->enabled_known_extensions
281 .nv_external_memory_capabilities = 1;
282 return;
283 }
284 }
285}