blob: 9b59eb5fea97c6596e8f325a33be336e68c3bf27 [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;
39 VkPhysicalDevice unwrapped_phys_dev =
40 loader_unwrap_physical_device(physicalDevice);
41 disp = loader_get_instance_dispatch(physicalDevice);
42
Mark Young5210abc2016-09-08 18:36:32 -060043 return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV(
44 unwrapped_phys_dev, format, type, tiling, usage, flags,
45 externalHandleType, pExternalImageFormatProperties);
Mark Lobodzinski317574e2016-08-29 14:21:14 -060046}
47
48VKAPI_ATTR VkResult VKAPI_CALL
49terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV(
50 VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
51 VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
52 VkExternalMemoryHandleTypeFlagsNV externalHandleType,
53 VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
Mark Young0153e0b2016-11-03 14:27:13 -060054 struct loader_physical_device_term *phys_dev_term =
55 (struct loader_physical_device_term *)physicalDevice;
56 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski317574e2016-08-29 14:21:14 -060057
Mark Young0153e0b2016-11-03 14:27:13 -060058 if (!icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV) {
James Jones389dc0c2016-08-18 23:41:19 +010059 if (externalHandleType) {
60 return VK_ERROR_FORMAT_NOT_SUPPORTED;
61 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -060062
Mark Young0153e0b2016-11-03 14:27:13 -060063 if (!icd_term->GetPhysicalDeviceImageFormatProperties) {
James Jones389dc0c2016-08-18 23:41:19 +010064 return VK_ERROR_INITIALIZATION_FAILED;
65 }
66
67 pExternalImageFormatProperties->externalMemoryFeatures = 0;
68 pExternalImageFormatProperties->exportFromImportedHandleTypes = 0;
69 pExternalImageFormatProperties->compatibleHandleTypes = 0;
70
Mark Young0153e0b2016-11-03 14:27:13 -060071 return icd_term->GetPhysicalDeviceImageFormatProperties(
72 phys_dev_term->phys_dev, format, type, tiling, usage, flags,
James Jones389dc0c2016-08-18 23:41:19 +010073 &pExternalImageFormatProperties->imageFormatProperties);
74 }
Mark Lobodzinski317574e2016-08-29 14:21:14 -060075
Mark Young0153e0b2016-11-03 14:27:13 -060076 return icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV(
77 phys_dev_term->phys_dev, format, type, tiling, usage, flags,
Mark Lobodzinski317574e2016-08-29 14:21:14 -060078 externalHandleType, pExternalImageFormatProperties);
79}
80
Mark Lobodzinski0853ad52016-08-29 14:54:34 -060081// Definitions for the VK_AMD_draw_indirect_count extension
82
Mark Lobodzinski0853ad52016-08-29 14:54:34 -060083VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD(
84 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
85 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
86 uint32_t stride) {
Mark Young5210abc2016-09-08 18:36:32 -060087 const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
88 disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer,
89 countBufferOffset, maxDrawCount, stride);
Mark Lobodzinski0853ad52016-08-29 14:54:34 -060090}
91
92VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD(
93 VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
94 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
95 uint32_t stride) {
Mark Young5210abc2016-09-08 18:36:32 -060096 const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
97 disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset,
98 countBuffer, countBufferOffset,
99 maxDrawCount, stride);
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600100}
101
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600102#ifdef VK_USE_PLATFORM_WIN32_KHR
103
104// Definitions for the VK_NV_external_memory_win32 extension
105
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600106VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV(
107 VkDevice device, VkDeviceMemory memory,
108 VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) {
Mark Young5210abc2016-09-08 18:36:32 -0600109 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
110 return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle);
Mark Lobodzinski5f208522016-08-29 15:36:23 -0600111}
112
113#endif // VK_USE_PLATFORM_WIN32_KHR
114
115// GPA helpers for non-KHR extensions
116
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600117bool extension_instance_gpa(struct loader_instance *ptr_instance,
118 const char *name, void **addr) {
119 *addr = NULL;
120
121 // Functions for the VK_NV_external_memory_capabilities extension
Mark Lobodzinski0853ad52016-08-29 14:54:34 -0600122
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600123 if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) {
Mark Young35159af2016-09-07 08:50:32 -0600124 *addr = (ptr_instance->enabled_known_extensions
125 .nv_external_memory_capabilities == 1)
126 ? (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV
127 : NULL;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600128 return true;
129 }
130
Mark Young3ea0ff52016-09-09 07:26:48 -0600131 // Functions for the VK_AMD_draw_indirect_count extension
132
133 if (!strcmp("vkCmdDrawIndirectCountAMD", name)) {
134 *addr = (void *)vkCmdDrawIndirectCountAMD;
135 return true;
136 }
137
138 if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) {
139 *addr = (void *)vkCmdDrawIndexedIndirectCountAMD;
140 return true;
141 }
142
143#ifdef VK_USE_PLATFORM_WIN32_KHR
144
145 // Functions for the VK_NV_external_memory_win32 extension
146
147 if (!strcmp("vkGetMemoryWin32HandleNV", name)) {
148 *addr = (void *)vkGetMemoryWin32HandleNV;
149 return true;
150 }
151
152#endif // VK_USE_PLATFORM_WIN32_KHR
153
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600154 return false;
155}
156
157void extensions_create_instance(struct loader_instance *ptr_instance,
158 const VkInstanceCreateInfo *pCreateInfo) {
Mark Young35159af2016-09-07 08:50:32 -0600159 ptr_instance->enabled_known_extensions.nv_external_memory_capabilities = 0;
Mark Lobodzinski317574e2016-08-29 14:21:14 -0600160
161 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
162 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
163 VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) {
Mark Young35159af2016-09-07 08:50:32 -0600164 ptr_instance->enabled_known_extensions
165 .nv_external_memory_capabilities = 1;
166 return;
167 }
168 }
169}