blob: 300a6bbfb8dd88a53112731b0bae2ab6263f669b [file] [log] [blame]
Jon Ashburn8d8dad02014-12-01 14:22:40 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Jon Ashburn8d8dad02014-12-01 14:22:40 -07003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
Jon Ashburn227a9422014-11-26 11:10:26 -070024#include <string.h>
25#include <stdlib.h>
26#include <assert.h>
Tobin Ehlis7a51d902015-07-03 10:34:49 -060027#include "vk_loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060028#include "vk_dispatch_table_helper.h"
Tobin Ehlis2d1d9702015-07-03 09:42:57 -060029#include "vk_layer.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060030#include "vk_layer_table.h"
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060031#include "vk_layer_extension_utils.h"
Ian Elliott20f06872015-02-12 17:08:34 -070032// The following is #included again to catch certain OS-specific functions
33// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060034#include "vk_loader_platform.h"
Jon Ashburn227a9422014-11-26 11:10:26 -070035
David Pinedo07238d42015-07-09 16:23:44 -060036static const VkLayerProperties globalLayerProps[] = {
37 {
38 "Basic",
39 VK_API_VERSION, // specVersion
40 VK_MAKE_VERSION(0, 1, 0), // implVersion
41 "layer: Basic",
42 }
43};
44
Jon Ashburn227a9422014-11-26 11:10:26 -070045
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060046VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device)
Jon Ashburn227a9422014-11-26 11:10:26 -070047{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060048 printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device);
49 printf("vkLayerExtension1 returning SUCCESS\n");
50 return VK_SUCCESS;
Jon Ashburn227a9422014-11-26 11:10:26 -070051}
52
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060053static const VkLayerProperties basic_physicaldevice_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060054 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060055 "Basic",
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060056 VK_API_VERSION,
57 VK_MAKE_VERSION(0, 1, 0),
58 "Sample layer: Basic, implements vkLayerExtension1",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060059 }
Jon Ashburneb2728b2015-04-10 14:33:07 -060060};
61
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060062/* Must use Vulkan name so that loader finds it */
63VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
64 VkPhysicalDevice physicalDevice,
65 uint32_t* pCount,
66 VkLayerProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -060067{
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060068 /* Mem tracker's physical device layers are the same as global */
69 return util_GetLayerProperties(ARRAY_SIZE(basic_physicaldevice_layers), basic_physicaldevice_layers,
70 pCount, pProperties);
Tony Barbour426b9052015-06-24 16:06:58 -060071}
Jon Ashburneb2728b2015-04-10 14:33:07 -060072
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060073static const VkExtensionProperties basic_physicaldevice_extensions[] = {
74 {
75 "vkLayerExtension1",
76 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060077 }
78};
79
80VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
81 VkPhysicalDevice physicalDevice,
82 const char *pLayerName,
83 uint32_t *pCount,
84 VkExtensionProperties *pProperties)
Tony Barbour426b9052015-06-24 16:06:58 -060085{
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060086 return util_GetExtensionProperties(ARRAY_SIZE(basic_physicaldevice_extensions), basic_physicaldevice_extensions,
87 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -060088}
89
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060090VK_LAYER_EXPORT VkResult VKAPI basic_EnumeratePhysicalDevices(
Jon Ashburn2666e2f2015-05-15 15:09:35 -060091 VkInstance instance,
92 uint32_t* pPhysicalDeviceCount,
93 VkPhysicalDevice* pPhysicalDevices)
94{
Jon Ashburn2666e2f2015-05-15 15:09:35 -060095 printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance);
Jon Ashburn5a10d212015-06-01 10:02:09 -060096 VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn2666e2f2015-05-15 15:09:35 -060097 printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount);
98 return result;
99}
100
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600101VK_LAYER_EXPORT VkResult VKAPI basic_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Jon Ashburn227a9422014-11-26 11:10:26 -0700102{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600103 printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu);
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600104 VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600105 printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice);
Jon Ashburn227a9422014-11-26 11:10:26 -0700106 return result;
107}
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600108
Jon Ashburn17f37372015-05-19 16:34:53 -0600109/* hook DestroyDevice to remove tableMap entry */
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600110VK_LAYER_EXPORT VkResult VKAPI basic_DestroyDevice(VkDevice device)
Jon Ashburn17f37372015-05-19 16:34:53 -0600111{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600112 dispatch_key key = get_dispatch_key(device);
Jon Ashburn5a10d212015-06-01 10:02:09 -0600113 VkResult res = device_dispatch_table(device)->DestroyDevice(device);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600114 destroy_device_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600115 return res;
116}
117
118/* hook DestroyInstance to remove tableInstanceMap entry */
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600119VK_LAYER_EXPORT VkResult VKAPI basic_DestroyInstance(VkInstance instance)
Jon Ashburn17f37372015-05-19 16:34:53 -0600120{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600121 dispatch_key key = get_dispatch_key(instance);
Jon Ashburn5a10d212015-06-01 10:02:09 -0600122 VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600123 destroy_instance_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600124 return res;
125}
126
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600127VK_LAYER_EXPORT VkResult VKAPI basic_GetPhysicalDeviceFormatProperties(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo)
Jon Ashburn227a9422014-11-26 11:10:26 -0700128{
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600129 printf("At start of wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
130 VkResult result = instance_dispatch_table(gpu)->GetPhysicalDeviceFormatProperties(gpu, format, pFormatInfo);
131 printf("Completed wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
Jon Ashburn227a9422014-11-26 11:10:26 -0700132 return result;
133}
134
Jon Ashburn1245cec2015-05-18 13:20:15 -0600135VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700136{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600137 if (device == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700138 return NULL;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800139
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600140 /* loader uses this to force layer initialization; device object is wrapped */
141 if (!strcmp("vkGetDeviceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600142 initDeviceTable((const VkBaseLayerObject *) device);
Jon Ashburn1245cec2015-05-18 13:20:15 -0600143 return (void *) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600144 }
145
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600146 if (!strcmp("vkCreateDevice", pName))
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600147 return (void *) basic_CreateDevice;
Jon Ashburn17f37372015-05-19 16:34:53 -0600148 if (!strcmp("vkDestroyDevice", pName))
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600149 return (void *) basic_DestroyDevice;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600150 if (!strcmp("vkLayerExtension1", pName))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600151 return (void *) vkLayerExtension1;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600152 else
153 {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600154 if (device_dispatch_table(device)->GetDeviceProcAddr == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700155 return NULL;
Jon Ashburn5a10d212015-06-01 10:02:09 -0600156 return device_dispatch_table(device)->GetDeviceProcAddr(device, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600157 }
158}
159
160VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName)
161{
162 if (instance == NULL)
163 return NULL;
164
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600165 /* loader uses this to force layer initialization; instance object is wrapped */
166 if (!strcmp("vkGetInstanceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600167 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600168 return (void *) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600169 }
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600170
171 if (!strcmp("vkGetPhysicalDeviceLayerProperties", pName))
172 return (void *) vkGetPhysicalDeviceLayerProperties;
173 if (!strcmp("vkGetPhysicalDeviceExtensionProperties", pName))
174 return (void *) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600175 if (!strcmp("vkGetPhysicalDeviceFormatProperties", pName))
176 return (void *) basic_GetPhysicalDeviceFormatProperties;
Jon Ashburn17f37372015-05-19 16:34:53 -0600177 if (!strcmp("vkDestroyInstance", pName))
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600178 return (void *) basic_DestroyInstance;
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600179 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600180 return (void*) basic_EnumeratePhysicalDevices;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600181
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600182 if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL)
183 return NULL;
184 return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName);
Jon Ashburn227a9422014-11-26 11:10:26 -0700185}
David Pinedo07238d42015-07-09 16:23:44 -0600186
187VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)
188{
189 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
190}
191
192VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)
193{
194 return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);
195}