blob: 66e6c2852c8d035a7bc11fd2462c149a21c95bfb [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.
Michael Lentine92689442015-09-09 12:39:13 -07005 * Copyright (C) 2015 Google Inc.
Jon Ashburn8d8dad02014-12-01 14:22:40 -07006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
Jon Ashburn227a9422014-11-26 11:10:26 -070025#include <string.h>
26#include <stdlib.h>
27#include <assert.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"
Jon Ashburn227a9422014-11-26 11:10:26 -070032
David Pinedo07238d42015-07-09 16:23:44 -060033static const VkLayerProperties globalLayerProps[] = {
34 {
35 "Basic",
36 VK_API_VERSION, // specVersion
Chia-I Wu1f851912015-10-27 18:04:07 +080037 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
David Pinedo07238d42015-07-09 16:23:44 -060038 "layer: Basic",
39 }
40};
41
Jon Ashburn227a9422014-11-26 11:10:26 -070042
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060043VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device)
Jon Ashburn227a9422014-11-26 11:10:26 -070044{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060045 printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device);
46 printf("vkLayerExtension1 returning SUCCESS\n");
47 return VK_SUCCESS;
Jon Ashburn227a9422014-11-26 11:10:26 -070048}
49
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060050static const VkLayerProperties basic_physicaldevice_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060051 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060052 "Basic",
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060053 VK_API_VERSION,
54 VK_MAKE_VERSION(0, 1, 0),
55 "Sample layer: Basic, implements vkLayerExtension1",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060056 }
Jon Ashburneb2728b2015-04-10 14:33:07 -060057};
58
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060059/* Must use Vulkan name so that loader finds it */
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -060060VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060061 VkPhysicalDevice physicalDevice,
62 uint32_t* pCount,
63 VkLayerProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -060064{
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060065 /* Mem tracker's physical device layers are the same as global */
66 return util_GetLayerProperties(ARRAY_SIZE(basic_physicaldevice_layers), basic_physicaldevice_layers,
67 pCount, pProperties);
Tony Barbour426b9052015-06-24 16:06:58 -060068}
Jon Ashburneb2728b2015-04-10 14:33:07 -060069
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060070static const VkExtensionProperties basic_physicaldevice_extensions[] = {
71 {
72 "vkLayerExtension1",
73 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060074 }
75};
76
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -060077VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060078 VkPhysicalDevice physicalDevice,
79 const char *pLayerName,
80 uint32_t *pCount,
81 VkExtensionProperties *pProperties)
Tony Barbour426b9052015-06-24 16:06:58 -060082{
Jon Ashburnaff81ff2015-11-02 17:37:20 -070083 if (pLayerName == NULL) {
84 return instance_dispatch_table(physicalDevice)->EnumerateDeviceExtensionProperties(
85 physicalDevice,
86 NULL,
87 pCount,
88 pProperties);
89 } else {
90 return util_GetExtensionProperties(ARRAY_SIZE(basic_physicaldevice_extensions),
91 basic_physicaldevice_extensions,
92 pCount, pProperties);
93 }
Jon Ashburneb2728b2015-04-10 14:33:07 -060094}
95
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -060096VK_LAYER_EXPORT VkResult VKAPI basic_EnumeratePhysicalDevices(
Jon Ashburn2666e2f2015-05-15 15:09:35 -060097 VkInstance instance,
98 uint32_t* pPhysicalDeviceCount,
99 VkPhysicalDevice* pPhysicalDevices)
100{
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600101 printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance);
Jon Ashburn5a10d212015-06-01 10:02:09 -0600102 VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600103 printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount);
104 return result;
105}
106
Chia-I Wu1f851912015-10-27 18:04:07 +0800107VK_LAYER_EXPORT VkResult VKAPI basic_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Jon Ashburn227a9422014-11-26 11:10:26 -0700108{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600109 printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu);
Chia-I Wu69f40122015-10-26 21:10:41 +0800110 VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600111 printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice);
Jon Ashburn227a9422014-11-26 11:10:26 -0700112 return result;
113}
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600114
Jon Ashburn17f37372015-05-19 16:34:53 -0600115/* hook DestroyDevice to remove tableMap entry */
Chia-I Wu1f851912015-10-27 18:04:07 +0800116VK_LAYER_EXPORT void VKAPI basic_DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Jon Ashburn17f37372015-05-19 16:34:53 -0600117{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600118 dispatch_key key = get_dispatch_key(device);
Chia-I Wu69f40122015-10-26 21:10:41 +0800119 device_dispatch_table(device)->DestroyDevice(device, pAllocator);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600120 destroy_device_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600121}
122
123/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu1f851912015-10-27 18:04:07 +0800124VK_LAYER_EXPORT void VKAPI basic_DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn17f37372015-05-19 16:34:53 -0600125{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600126 dispatch_key key = get_dispatch_key(instance);
Chia-I Wu69f40122015-10-26 21:10:41 +0800127 instance_dispatch_table(instance)->DestroyInstance(instance, pAllocator);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600128 destroy_instance_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600129}
130
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600131VK_LAYER_EXPORT void VKAPI basic_GetPhysicalDeviceFormatProperties(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo)
Jon Ashburn227a9422014-11-26 11:10:26 -0700132{
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600133 printf("At start of wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600134 instance_dispatch_table(gpu)->GetPhysicalDeviceFormatProperties(gpu, format, pFormatInfo);
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600135 printf("Completed wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
Jon Ashburn227a9422014-11-26 11:10:26 -0700136}
137
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600138VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700139{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600140 if (device == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700141 return NULL;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800142
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600143 /* loader uses this to force layer initialization; device object is wrapped */
144 if (!strcmp("vkGetDeviceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600145 initDeviceTable((const VkBaseLayerObject *) device);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600146 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600147 }
148
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600149 if (!strcmp("vkCreateDevice", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600150 return (PFN_vkVoidFunction) basic_CreateDevice;
Jon Ashburn17f37372015-05-19 16:34:53 -0600151 if (!strcmp("vkDestroyDevice", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600152 return (PFN_vkVoidFunction) basic_DestroyDevice;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600153 if (!strcmp("vkLayerExtension1", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600154 return (PFN_vkVoidFunction) vkLayerExtension1;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600155 else
156 {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600157 if (device_dispatch_table(device)->GetDeviceProcAddr == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700158 return NULL;
Jon Ashburn5a10d212015-06-01 10:02:09 -0600159 return device_dispatch_table(device)->GetDeviceProcAddr(device, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600160 }
161}
162
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600163VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600164{
165 if (instance == NULL)
166 return NULL;
167
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600168 /* loader uses this to force layer initialization; instance object is wrapped */
169 if (!strcmp("vkGetInstanceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600170 initInstanceTable((const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600171 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600172 }
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600173
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600174 if (!strcmp("vkEnumerateDeviceLayerProperties", pName))
175 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
176 if (!strcmp("vkEnumerateDeviceExtensionProperties", pName))
177 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600178 if (!strcmp("vkGetPhysicalDeviceFormatProperties", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600179 return (PFN_vkVoidFunction) basic_GetPhysicalDeviceFormatProperties;
Jon Ashburn17f37372015-05-19 16:34:53 -0600180 if (!strcmp("vkDestroyInstance", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600181 return (PFN_vkVoidFunction) basic_DestroyInstance;
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600182 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -0600183 return (PFN_vkVoidFunction) basic_EnumeratePhysicalDevices;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600184
Courtney Goeltzenleuchter326075a2015-07-05 11:10:06 -0600185 if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL)
186 return NULL;
187 return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName);
Jon Ashburn227a9422014-11-26 11:10:26 -0700188}
David Pinedo07238d42015-07-09 16:23:44 -0600189
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600190VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)
David Pinedo07238d42015-07-09 16:23:44 -0600191{
192 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
193}
194
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600195VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)
David Pinedo07238d42015-07-09 16:23:44 -0600196{
197 return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);
198}