blob: ba56517b6ee1ff4784f7e0d2509b73c678ddcb8f [file] [log] [blame]
Jon Ashburn8d8dad02014-12-01 14:22:40 -07001/*
Jon Ashburn8d8dad02014-12-01 14:22:40 -07002 *
Courtney Goeltzenleuchter8a17da52015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentine92689442015-09-09 12:39:13 -07004 * Copyright (C) 2015 Google Inc.
Jon Ashburn8d8dad02014-12-01 14:22:40 -07005 *
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.
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060023 *
24 * Author: David Pinedo <david@lunarg.com>
25 * Author: Jon Ashburn <jon@lunarg.com>
Jon Ashburn8d8dad02014-12-01 14:22:40 -070026 */
Jon Ashburn227a9422014-11-26 11:10:26 -070027#include <string.h>
28#include <stdlib.h>
29#include <assert.h>
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060030#include "vk_dispatch_table_helper.h"
David Pinedo329ca9e2015-11-06 12:54:48 -070031#include "vulkan/vk_layer.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060032#include "vk_layer_table.h"
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060033#include "vk_layer_extension_utils.h"
Jon Ashburn227a9422014-11-26 11:10:26 -070034
David Pinedo07238d42015-07-09 16:23:44 -060035static const VkLayerProperties globalLayerProps[] = {
36 {
Mark Lobodzinski2e87e612015-12-30 08:16:12 -070037 "basic",
David Pinedo07238d42015-07-09 16:23:44 -060038 VK_API_VERSION, // specVersion
Chia-I Wu1f851912015-10-27 18:04:07 +080039 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
Mark Lobodzinski2e87e612015-12-30 08:16:12 -070040 "layer: basic",
David Pinedo07238d42015-07-09 16:23:44 -060041 }
42};
43
Jon Ashburn227a9422014-11-26 11:10:26 -070044
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +080045VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkLayerExtension1(VkDevice device)
Jon Ashburn227a9422014-11-26 11:10:26 -070046{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060047 printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device);
48 printf("vkLayerExtension1 returning SUCCESS\n");
49 return VK_SUCCESS;
Jon Ashburn227a9422014-11-26 11:10:26 -070050}
51
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060052static const VkLayerProperties basic_physicaldevice_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060053 {
Michael Lentine5d96e522015-12-11 10:49:51 -080054 "VK_LAYER_LUNARG_basic",
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060055 VK_API_VERSION,
56 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski2e87e612015-12-30 08:16:12 -070057 "Sample layer: basic, implements vkLayerExtension1",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060058 }
Jon Ashburneb2728b2015-04-10 14:33:07 -060059};
60
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060061/* Must use Vulkan name so that loader finds it */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +080062VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060063 VkPhysicalDevice physicalDevice,
64 uint32_t* pCount,
65 VkLayerProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -060066{
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060067 /* Mem tracker's physical device layers are the same as global */
68 return util_GetLayerProperties(ARRAY_SIZE(basic_physicaldevice_layers), basic_physicaldevice_layers,
69 pCount, pProperties);
Tony Barbour426b9052015-06-24 16:06:58 -060070}
Jon Ashburneb2728b2015-04-10 14:33:07 -060071
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060072static const VkExtensionProperties basic_physicaldevice_extensions[] = {
73 {
74 "vkLayerExtension1",
75 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060076 }
77};
78
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +080079VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060080 VkPhysicalDevice physicalDevice,
81 const char *pLayerName,
82 uint32_t *pCount,
83 VkExtensionProperties *pProperties)
Tony Barbour426b9052015-06-24 16:06:58 -060084{
Jon Ashburnaff81ff2015-11-02 17:37:20 -070085 if (pLayerName == NULL) {
86 return instance_dispatch_table(physicalDevice)->EnumerateDeviceExtensionProperties(
87 physicalDevice,
88 NULL,
89 pCount,
90 pProperties);
91 } else {
92 return util_GetExtensionProperties(ARRAY_SIZE(basic_physicaldevice_extensions),
93 basic_physicaldevice_extensions,
94 pCount, pProperties);
95 }
Jon Ashburneb2728b2015-04-10 14:33:07 -060096}
97
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +080098VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL basic_EnumeratePhysicalDevices(
Jon Ashburn2666e2f2015-05-15 15:09:35 -060099 VkInstance instance,
100 uint32_t* pPhysicalDeviceCount,
101 VkPhysicalDevice* pPhysicalDevices)
102{
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600103 printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance);
Jon Ashburn5a10d212015-06-01 10:02:09 -0600104 VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600105 printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount);
106 return result;
107}
108
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800109VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL basic_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Jon Ashburn227a9422014-11-26 11:10:26 -0700110{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600111 printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu);
Chia-I Wu69f40122015-10-26 21:10:41 +0800112 VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600113 printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice);
Jon Ashburn227a9422014-11-26 11:10:26 -0700114 return result;
115}
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600116
Jon Ashburn17f37372015-05-19 16:34:53 -0600117/* hook DestroyDevice to remove tableMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800118VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL basic_DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Jon Ashburn17f37372015-05-19 16:34:53 -0600119{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600120 dispatch_key key = get_dispatch_key(device);
Chia-I Wu69f40122015-10-26 21:10:41 +0800121 device_dispatch_table(device)->DestroyDevice(device, pAllocator);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600122 destroy_device_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600123}
124
125/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800126VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL basic_DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn17f37372015-05-19 16:34:53 -0600127{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600128 dispatch_key key = get_dispatch_key(instance);
Chia-I Wu69f40122015-10-26 21:10:41 +0800129 instance_dispatch_table(instance)->DestroyInstance(instance, pAllocator);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600130 destroy_instance_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600131}
132
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800133VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL basic_GetPhysicalDeviceFormatProperties(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo)
Jon Ashburn227a9422014-11-26 11:10:26 -0700134{
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600135 printf("At start of wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600136 instance_dispatch_table(gpu)->GetPhysicalDeviceFormatProperties(gpu, format, pFormatInfo);
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600137 printf("Completed wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
Jon Ashburn227a9422014-11-26 11:10:26 -0700138}
139
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800140VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700141{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600142 if (device == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700143 return NULL;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800144
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600145 /* loader uses this to force layer initialization; device object is wrapped */
146 if (!strcmp("vkGetDeviceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600147 initDeviceTable((const VkBaseLayerObject *) device);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600148 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600149 }
150
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600151 if (!strcmp("vkCreateDevice", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600152 return (PFN_vkVoidFunction) basic_CreateDevice;
Jon Ashburn17f37372015-05-19 16:34:53 -0600153 if (!strcmp("vkDestroyDevice", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600154 return (PFN_vkVoidFunction) basic_DestroyDevice;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600155 if (!strcmp("vkLayerExtension1", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600156 return (PFN_vkVoidFunction) vkLayerExtension1;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600157 else
158 {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600159 if (device_dispatch_table(device)->GetDeviceProcAddr == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700160 return NULL;
Jon Ashburn5a10d212015-06-01 10:02:09 -0600161 return device_dispatch_table(device)->GetDeviceProcAddr(device, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600162 }
163}
164
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800165VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600166{
167 if (instance == NULL)
168 return NULL;
169
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600170 /* loader uses this to force layer initialization; instance object is wrapped */
171 if (!strcmp("vkGetInstanceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600172 initInstanceTable((const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600173 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600174 }
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600175
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600176 if (!strcmp("vkEnumerateDeviceLayerProperties", pName))
177 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
178 if (!strcmp("vkEnumerateDeviceExtensionProperties", pName))
179 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600180 if (!strcmp("vkGetPhysicalDeviceFormatProperties", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600181 return (PFN_vkVoidFunction) basic_GetPhysicalDeviceFormatProperties;
Jon Ashburn17f37372015-05-19 16:34:53 -0600182 if (!strcmp("vkDestroyInstance", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600183 return (PFN_vkVoidFunction) basic_DestroyInstance;
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600184 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600185 return (PFN_vkVoidFunction) basic_EnumeratePhysicalDevices;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600186
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600187 if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL)
188 return NULL;
189 return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName);
Jon Ashburn227a9422014-11-26 11:10:26 -0700190}
David Pinedo07238d42015-07-09 16:23:44 -0600191
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800192VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)
David Pinedo07238d42015-07-09 16:23:44 -0600193{
194 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
195}
196
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800197VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)
David Pinedo07238d42015-07-09 16:23:44 -0600198{
199 return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);
200}