blob: d1e780591f27473f3fcf4178741138a3efe7ba79 [file] [log] [blame]
Jon Ashburn79113cc2014-12-01 14:22:40 -07001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 * Vulkan
Jon Ashburn79113cc2014-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 Ashburn1fec4242014-11-26 11:10:26 -070024#include <string.h>
25#include <stdlib.h>
26#include <assert.h>
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060027#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vk_dispatch_table_helper.h"
Tobin Ehlis0c6f9ee2015-07-03 09:42:57 -060029#include "vk_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060030#include "vk_layer_table.h"
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060031#include "vk_layer_extension_utils.h"
Ian Elliott655cad72015-02-12 17:08:34 -070032// The following is #included again to catch certain OS-specific functions
33// being used:
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060034#include "vk_loader_platform.h"
Jon Ashburn1fec4242014-11-26 11:10:26 -070035
David Pinedo38310942015-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 Ashburn1fec4242014-11-26 11:10:26 -070045
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060046VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device)
Jon Ashburn1fec4242014-11-26 11:10:26 -070047{
Courtney Goeltzenleuchterd8e229c2015-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 Ashburn1fec4242014-11-26 11:10:26 -070051}
52
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060053static const VkLayerProperties basic_physicaldevice_layers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060054 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060055 "Basic",
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060056 VK_API_VERSION,
57 VK_MAKE_VERSION(0, 1, 0),
58 "Sample layer: Basic, implements vkLayerExtension1",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060059 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -060060};
61
Courtney Goeltzenleuchter842f8422015-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 Ashburn9fd4cc42015-04-10 14:33:07 -060067{
Courtney Goeltzenleuchter842f8422015-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 Barbour59a47322015-06-24 16:06:58 -060071}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -060072
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060073static const VkExtensionProperties basic_physicaldevice_extensions[] = {
74 {
75 "vkLayerExtension1",
76 VK_MAKE_VERSION(0, 1, 0),
77 VK_API_VERSION
78 }
79};
80
81VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
82 VkPhysicalDevice physicalDevice,
83 const char *pLayerName,
84 uint32_t *pCount,
85 VkExtensionProperties *pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -060086{
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060087 return util_GetExtensionProperties(ARRAY_SIZE(basic_physicaldevice_extensions), basic_physicaldevice_extensions,
88 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -060089}
90
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060091VK_LAYER_EXPORT VkResult VKAPI basic_EnumeratePhysicalDevices(
Jon Ashburn95a77ba2015-05-15 15:09:35 -060092 VkInstance instance,
93 uint32_t* pPhysicalDeviceCount,
94 VkPhysicalDevice* pPhysicalDevices)
95{
Jon Ashburn95a77ba2015-05-15 15:09:35 -060096 printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance);
Jon Ashburn9eed2892015-06-01 10:02:09 -060097 VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn95a77ba2015-05-15 15:09:35 -060098 printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount);
99 return result;
100}
101
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600102VK_LAYER_EXPORT VkResult VKAPI basic_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700103{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600104 printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu);
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600105 VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600106 printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice);
Jon Ashburn1fec4242014-11-26 11:10:26 -0700107 return result;
108}
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600109
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600110/* hook DestroyDevice to remove tableMap entry */
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600111VK_LAYER_EXPORT VkResult VKAPI basic_DestroyDevice(VkDevice device)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600112{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600113 dispatch_key key = get_dispatch_key(device);
Jon Ashburn9eed2892015-06-01 10:02:09 -0600114 VkResult res = device_dispatch_table(device)->DestroyDevice(device);
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600115 destroy_device_dispatch_table(key);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600116 return res;
117}
118
119/* hook DestroyInstance to remove tableInstanceMap entry */
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600120VK_LAYER_EXPORT VkResult VKAPI basic_DestroyInstance(VkInstance instance)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600121{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600122 dispatch_key key = get_dispatch_key(instance);
Jon Ashburn9eed2892015-06-01 10:02:09 -0600123 VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600124 destroy_instance_dispatch_table(key);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600125 return res;
126}
127
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600128VK_LAYER_EXPORT VkResult VKAPI basic_GetPhysicalDeviceFormatInfo(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700129{
Chris Forbesbc0bb772015-06-21 22:55:02 +1200130 printf("At start of wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu);
131 VkResult result = instance_dispatch_table(gpu)->GetPhysicalDeviceFormatInfo(gpu, format, pFormatInfo);
132 printf("Completed wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu);
Jon Ashburn1fec4242014-11-26 11:10:26 -0700133 return result;
134}
135
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600136VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700137{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600138 if (device == NULL)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700139 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800140
Jon Ashburn8fd08252015-05-28 16:25:02 -0600141 /* loader uses this to force layer initialization; device object is wrapped */
142 if (!strcmp("vkGetDeviceProcAddr", pName)) {
Jon Ashburn9eed2892015-06-01 10:02:09 -0600143 initDeviceTable((const VkBaseLayerObject *) device);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600144 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600145 }
146
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600147 if (!strcmp("vkCreateDevice", pName))
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600148 return (void *) basic_CreateDevice;
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600149 if (!strcmp("vkDestroyDevice", pName))
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600150 return (void *) basic_DestroyDevice;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600151 if (!strcmp("vkLayerExtension1", pName))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600152 return (void *) vkLayerExtension1;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600153 else
154 {
Jon Ashburn9eed2892015-06-01 10:02:09 -0600155 if (device_dispatch_table(device)->GetDeviceProcAddr == NULL)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700156 return NULL;
Jon Ashburn9eed2892015-06-01 10:02:09 -0600157 return device_dispatch_table(device)->GetDeviceProcAddr(device, pName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600158 }
159}
160
161VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName)
162{
163 if (instance == NULL)
164 return NULL;
165
Jon Ashburn8fd08252015-05-28 16:25:02 -0600166 /* loader uses this to force layer initialization; instance object is wrapped */
167 if (!strcmp("vkGetInstanceProcAddr", pName)) {
Jon Ashburn9eed2892015-06-01 10:02:09 -0600168 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600169 return (void *) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600170 }
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600171
172 if (!strcmp("vkGetPhysicalDeviceLayerProperties", pName))
173 return (void *) vkGetPhysicalDeviceLayerProperties;
174 if (!strcmp("vkGetPhysicalDeviceExtensionProperties", pName))
175 return (void *) vkGetPhysicalDeviceExtensionProperties;
Chris Forbesbc0bb772015-06-21 22:55:02 +1200176 if (!strcmp("vkGetPhysicalDeviceFormatInfo", pName))
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600177 return (void *) basic_GetPhysicalDeviceFormatInfo;
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600178 if (!strcmp("vkDestroyInstance", pName))
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600179 return (void *) basic_DestroyInstance;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600180 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600181 return (void*) basic_EnumeratePhysicalDevices;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600182
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600183 if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL)
184 return NULL;
185 return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName);
Jon Ashburn1fec4242014-11-26 11:10:26 -0700186}
David Pinedo38310942015-07-09 16:23:44 -0600187
188VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)
189{
190 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
191}
192
193VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)
194{
195 return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);
196}