blob: 5a0608a753c8e4b49a9d8116de573022c8347b88 [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
Mark Young35159af2016-09-07 08:50:32 -060030// Definitions for the VK_NV_external_memory_capabilities extension
Mark Lobodzinski317574e2016-08-29 14:21:14 -060031
32LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
33vkGetPhysicalDeviceExternalImageFormatPropertiesNV(
34 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
35 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
36 VkExternalMemoryHandleTypeFlagsNV externalHandleType,
37 VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
Mark Lobodzinski317574e2016-08-29 14:21:14 -060038 const VkLayerInstanceDispatchTable *disp;
Mark Young35159af2016-09-07 08:50:32 -060039 struct loader_physical_device_tramp *phys_dev =
40 (struct loader_physical_device_tramp *)physicalDevice;
Mark Lobodzinski317574e2016-08-29 14:21:14 -060041 VkPhysicalDevice unwrapped_phys_dev =
42 loader_unwrap_physical_device(physicalDevice);
43 disp = loader_get_instance_dispatch(physicalDevice);
44
Mark Young5210abc2016-09-08 18:36:32 -060045 return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV(
46 unwrapped_phys_dev, format, type, tiling, usage, flags,
47 externalHandleType, pExternalImageFormatProperties);
Mark Lobodzinski317574e2016-08-29 14:21:14 -060048}
49
50VKAPI_ATTR VkResult VKAPI_CALL
51terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV(
52 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
53 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
54 VkExternalMemoryHandleTypeFlagsNV externalHandleType,
55 VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
Mark Lobodzinski317574e2016-08-29 14:21:14 -060056 struct loader_physical_device *phys_dev =
57 (struct loader_physical_device *)physicalDevice;
58 struct loader_icd *icd = phys_dev->this_icd;
59
James Jones389dc0c2016-08-18 23:41:19 +010060 if (!icd->GetPhysicalDeviceExternalImageFormatPropertiesNV) {
61 if (externalHandleType) {
62 return VK_ERROR_FORMAT_NOT_SUPPORTED;
63 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -060064
James Jones389dc0c2016-08-18 23:41:19 +010065 if (!icd->GetPhysicalDeviceImageFormatProperties) {
66 return VK_ERROR_INITIALIZATION_FAILED;
67 }
68
69 pExternalImageFormatProperties->externalMemoryFeatures = 0;
70 pExternalImageFormatProperties->exportFromImportedHandleTypes = 0;
71 pExternalImageFormatProperties->compatibleHandleTypes = 0;
72
73 return icd->GetPhysicalDeviceImageFormatProperties(
74 phys_dev->phys_dev, format, type, tiling, usage, flags,
75 &pExternalImageFormatProperties->imageFormatProperties);
76 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -060077
78 return icd->GetPhysicalDeviceExternalImageFormatPropertiesNV(
79 phys_dev->phys_dev, format, type, tiling, usage, flags,
80 externalHandleType, pExternalImageFormatProperties);
81}
82
Mark Lobodzinski0853ad52016-08-29 14:54:34 -060083// Definitions for the VK_AMD_draw_indirect_count extension
84
Mark Lobodzinski0853ad52016-08-29 14:54:34 -060085VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD(
86 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
87 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
88 uint32_t stride) {
Mark Young5210abc2016-09-08 18:36:32 -060089 const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
90 disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer,
91 countBufferOffset, maxDrawCount, stride);
Mark Lobodzinski0853ad52016-08-29 14:54:34 -060092}
93
94VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD(
95 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
96 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
97 uint32_t stride) {
Mark Young5210abc2016-09-08 18:36:32 -060098 const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
99 disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset,
100 countBuffer, countBufferOffset,
101 maxDrawCount, stride);
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600102}
103
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600104#ifdef VK_USE_PLATFORM_WIN32_KHR
105
106// Definitions for the VK_NV_external_memory_win32 extension
107
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600108VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV(
109 VkDevice device, VkDeviceMemory memory,
110 VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) {
Mark Young5210abc2016-09-08 18:36:32 -0600111 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
112 return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle);
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600113}
114
115#endif // VK_USE_PLATFORM_WIN32_KHR
116
117// GPA helpers for non-KHR extensions
118
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600119bool extension_instance_gpa(struct loader_instance *ptr_instance,
120 const char *name, void **addr) {
121 *addr = NULL;
122
123 // Functions for the VK_NV_external_memory_capabilities extension
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600124
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600125 if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) {
Mark Young35159af2016-09-07 08:50:32 -0600126 *addr = (ptr_instance->enabled_known_extensions
127 .nv_external_memory_capabilities == 1)
128 ? (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV
129 : NULL;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600130 return true;
131 }
132
Mark Young3ea0ff52016-09-09 07:26:48 -0600133 // Functions for the VK_AMD_draw_indirect_count extension
134
135 if (!strcmp("vkCmdDrawIndirectCountAMD", name)) {
136 *addr = (void *)vkCmdDrawIndirectCountAMD;
137 return true;
138 }
139
140 if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) {
141 *addr = (void *)vkCmdDrawIndexedIndirectCountAMD;
142 return true;
143 }
144
145#ifdef VK_USE_PLATFORM_WIN32_KHR
146
147 // Functions for the VK_NV_external_memory_win32 extension
148
149 if (!strcmp("vkGetMemoryWin32HandleNV", name)) {
150 *addr = (void *)vkGetMemoryWin32HandleNV;
151 return true;
152 }
153
154#endif // VK_USE_PLATFORM_WIN32_KHR
155
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600156 return false;
157}
158
159void extensions_create_instance(struct loader_instance *ptr_instance,
160 const VkInstanceCreateInfo *pCreateInfo) {
Mark Young35159af2016-09-07 08:50:32 -0600161 ptr_instance->enabled_known_extensions.nv_external_memory_capabilities = 0;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600162
163 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
164 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
165 VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) {
Mark Young35159af2016-09-07 08:50:32 -0600166 ptr_instance->enabled_known_extensions
167 .nv_external_memory_capabilities = 1;
168 return;
169 }
170 }
171}