blob: e14ceb19462be95217146318c7a46cb60dafd819 [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>
29
30 // Definitions for the VK_NV_external_memory_capabilities extension
31
32static const VkExtensionProperties
33 nv_external_memory_capabilities_extension_info = {
34 .extensionName = VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME,
35 .specVersion = VK_NV_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION,
36};
37
38LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
39vkGetPhysicalDeviceExternalImageFormatPropertiesNV(
40 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
41 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
42 VkExternalMemoryHandleTypeFlagsNV externalHandleType,
43 VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
44
45 const VkLayerInstanceDispatchTable *disp;
46 VkPhysicalDevice unwrapped_phys_dev =
47 loader_unwrap_physical_device(physicalDevice);
48 disp = loader_get_instance_dispatch(physicalDevice);
49
50 return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV(
51 unwrapped_phys_dev, format, type, tiling, usage, flags,
52 externalHandleType, pExternalImageFormatProperties);
53}
54
55VKAPI_ATTR VkResult VKAPI_CALL
56terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV(
57 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
58 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
59 VkExternalMemoryHandleTypeFlagsNV externalHandleType,
60 VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
Mark Lobodzinski317574e2016-08-29 14:21:14 -060061 struct loader_physical_device *phys_dev =
62 (struct loader_physical_device *)physicalDevice;
63 struct loader_icd *icd = phys_dev->this_icd;
64
James Jones389dc0c2016-08-18 23:41:19 +010065 if (!icd->GetPhysicalDeviceExternalImageFormatPropertiesNV) {
66 if (externalHandleType) {
67 return VK_ERROR_FORMAT_NOT_SUPPORTED;
68 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -060069
James Jones389dc0c2016-08-18 23:41:19 +010070 if (!icd->GetPhysicalDeviceImageFormatProperties) {
71 return VK_ERROR_INITIALIZATION_FAILED;
72 }
73
74 pExternalImageFormatProperties->externalMemoryFeatures = 0;
75 pExternalImageFormatProperties->exportFromImportedHandleTypes = 0;
76 pExternalImageFormatProperties->compatibleHandleTypes = 0;
77
78 return icd->GetPhysicalDeviceImageFormatProperties(
79 phys_dev->phys_dev, format, type, tiling, usage, flags,
80 &pExternalImageFormatProperties->imageFormatProperties);
81 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -060082
83 return icd->GetPhysicalDeviceExternalImageFormatPropertiesNV(
84 phys_dev->phys_dev, format, type, tiling, usage, flags,
85 externalHandleType, pExternalImageFormatProperties);
86}
87
Mark Lobodzinski0853ad52016-08-29 14:54:34 -060088// Definitions for the VK_AMD_draw_indirect_count extension
89
90static const VkExtensionProperties amd_draw_indirect_count_extension_info = {
91 .extensionName = VK_AMD_EXTENSION_DRAW_INDIRECT_COUNT_EXTENSION_NAME,
92 .specVersion = VK_AMD_EXTENSION_DRAW_INDIRECT_COUNT_SPEC_VERSION,
93};
94
95VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD(
96 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
97 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
98 uint32_t stride) {
99 const VkLayerDispatchTable *disp;
100
101 disp = loader_get_dispatch(commandBuffer);
102 disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer,
103 countBufferOffset, maxDrawCount, stride);
104}
105
106VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD(
107 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
108 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
109 uint32_t stride) {
110 const VkLayerDispatchTable *disp;
111
112 disp = loader_get_dispatch(commandBuffer);
113 disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset,
114 countBuffer, countBufferOffset,
115 maxDrawCount, stride);
116}
117
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600118#ifdef VK_USE_PLATFORM_WIN32_KHR
119
120// Definitions for the VK_NV_external_memory_win32 extension
121
122static const VkExtensionProperties nv_external_memory_win32_extension_info = {
123 .extensionName = VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME,
124 .specVersion = VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION,
125};
126
127VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV(
128 VkDevice device, VkDeviceMemory memory,
129 VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) {
130 const VkLayerDispatchTable *disp;
131
132 disp = loader_get_dispatch(device);
133 return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle);
134}
135
136#endif // VK_USE_PLATFORM_WIN32_KHR
137
138// GPA helpers for non-KHR extensions
139
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600140bool extension_instance_gpa(struct loader_instance *ptr_instance,
141 const char *name, void **addr) {
142 *addr = NULL;
143
144 // Functions for the VK_NV_external_memory_capabilities extension
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600145
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600146 if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) {
147 *addr = (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV;
148 return true;
149 }
150
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600151 // Functions for the VK_AMD_draw_indirect_count extension
152
153 if (!strcmp("vkCmdDrawIndirectCountAMD", name)) {
154 *addr = (void *)vkCmdDrawIndirectCountAMD;
155 return true;
156 }
157
158 if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) {
159 *addr = (void *)vkCmdDrawIndexedIndirectCountAMD;
160 return true;
161 }
162
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600163#ifdef VK_USE_PLATFORM_WIN32_KHR
164
165 // Functions for the VK_NV_external_memory_win32 extension
166
167 if (!strcmp("vkGetMemoryWin32HandleNV", name)) {
168 *addr = (void *)vkGetMemoryWin32HandleNV;
169 return true;
170 }
171
172#endif // VK_USE_PLATFORM_WIN32_KHR
173
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600174 return false;
175}
176
177void extensions_create_instance(struct loader_instance *ptr_instance,
178 const VkInstanceCreateInfo *pCreateInfo) {
179
180 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
181 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
182 VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) {
183 // Nothing to do;
184 return;
185 }
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600186
187 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
188 VK_AMD_EXTENSION_DRAW_INDIRECT_COUNT_EXTENSION_NAME) == 0) {
189 // Nothing to do;
190 return;
191 }
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600192
193#ifdef VK_USE_PLATFORM_WIN32_KHR
194 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
195 VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME) == 0) {
196 // Nothing to do;
197 return;
198 }
199#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600200 }
201}