blob: 98039cfb1725ae7fdbb10d2aa8986458ef1b9dd8 [file] [log] [blame]
Jon Ashburn79113cc2014-12-01 14:22:40 -07001/*
Jon Ashburn79113cc2014-12-01 14:22:40 -07002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentine695f2c22015-09-09 12:39:13 -07004 * Copyright (C) 2015 Google Inc.
Jon Ashburn79113cc2014-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.
23 */
Jon Ashburn1fec4242014-11-26 11:10:26 -070024#include <string.h>
25#include <stdlib.h>
26#include <assert.h>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060027#include "vk_dispatch_table_helper.h"
Tobin Ehlis0c6f9ee2015-07-03 09:42:57 -060028#include "vk_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_table.h"
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060030#include "vk_layer_extension_utils.h"
Jon Ashburn1fec4242014-11-26 11:10:26 -070031
David Pinedo38310942015-07-09 16:23:44 -060032static const VkLayerProperties globalLayerProps[] = {
33 {
34 "Basic",
35 VK_API_VERSION, // specVersion
Chia-I Wu3432a0c2015-10-27 18:04:07 +080036 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
David Pinedo38310942015-07-09 16:23:44 -060037 "layer: Basic",
38 }
39};
40
Jon Ashburn1fec4242014-11-26 11:10:26 -070041
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060042VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device)
Jon Ashburn1fec4242014-11-26 11:10:26 -070043{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060044 printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device);
45 printf("vkLayerExtension1 returning SUCCESS\n");
46 return VK_SUCCESS;
Jon Ashburn1fec4242014-11-26 11:10:26 -070047}
48
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060049static const VkLayerProperties basic_physicaldevice_layers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060050 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060051 "Basic",
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060052 VK_API_VERSION,
53 VK_MAKE_VERSION(0, 1, 0),
54 "Sample layer: Basic, implements vkLayerExtension1",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060055 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -060056};
57
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060058/* Must use Vulkan name so that loader finds it */
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -060059VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060060 VkPhysicalDevice physicalDevice,
61 uint32_t* pCount,
62 VkLayerProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -060063{
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060064 /* Mem tracker's physical device layers are the same as global */
65 return util_GetLayerProperties(ARRAY_SIZE(basic_physicaldevice_layers), basic_physicaldevice_layers,
66 pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -060067}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -060068
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060069static const VkExtensionProperties basic_physicaldevice_extensions[] = {
70 {
71 "vkLayerExtension1",
72 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060073 }
74};
75
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -060076VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060077 VkPhysicalDevice physicalDevice,
78 const char *pLayerName,
79 uint32_t *pCount,
80 VkExtensionProperties *pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -060081{
Jon Ashburn751c4842015-11-02 17:37:20 -070082 if (pLayerName == NULL) {
83 return instance_dispatch_table(physicalDevice)->EnumerateDeviceExtensionProperties(
84 physicalDevice,
85 NULL,
86 pCount,
87 pProperties);
88 } else {
89 return util_GetExtensionProperties(ARRAY_SIZE(basic_physicaldevice_extensions),
90 basic_physicaldevice_extensions,
91 pCount, pProperties);
92 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -060093}
94
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -060095VK_LAYER_EXPORT VkResult VKAPI basic_EnumeratePhysicalDevices(
Jon Ashburn95a77ba2015-05-15 15:09:35 -060096 VkInstance instance,
97 uint32_t* pPhysicalDeviceCount,
98 VkPhysicalDevice* pPhysicalDevices)
99{
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600100 printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance);
Jon Ashburn9eed2892015-06-01 10:02:09 -0600101 VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600102 printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount);
103 return result;
104}
105
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800106VK_LAYER_EXPORT VkResult VKAPI basic_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700107{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600108 printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800109 VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600110 printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice);
Jon Ashburn1fec4242014-11-26 11:10:26 -0700111 return result;
112}
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600113
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600114/* hook DestroyDevice to remove tableMap entry */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800115VK_LAYER_EXPORT void VKAPI basic_DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600116{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600117 dispatch_key key = get_dispatch_key(device);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800118 device_dispatch_table(device)->DestroyDevice(device, pAllocator);
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600119 destroy_device_dispatch_table(key);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600120}
121
122/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800123VK_LAYER_EXPORT void VKAPI basic_DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600124{
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600125 dispatch_key key = get_dispatch_key(instance);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800126 instance_dispatch_table(instance)->DestroyInstance(instance, pAllocator);
Courtney Goeltzenleuchter0daf2282015-06-13 21:22:12 -0600127 destroy_instance_dispatch_table(key);
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600128}
129
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600130VK_LAYER_EXPORT void VKAPI basic_GetPhysicalDeviceFormatProperties(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700131{
Courtney Goeltzenleuchterc729b3a2015-07-12 12:40:29 -0600132 printf("At start of wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600133 instance_dispatch_table(gpu)->GetPhysicalDeviceFormatProperties(gpu, format, pFormatInfo);
Courtney Goeltzenleuchterc729b3a2015-07-12 12:40:29 -0600134 printf("Completed wrapped vkGetPhysicalDeviceFormatProperties() call w/ gpu: %p\n", (void*)gpu);
Jon Ashburn1fec4242014-11-26 11:10:26 -0700135}
136
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600137VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn79113cc2014-12-01 14:22:40 -0700138{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600139 if (device == NULL)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700140 return NULL;
Chia-I Wub665d942015-01-05 09:41:27 +0800141
Jon Ashburn8fd08252015-05-28 16:25:02 -0600142 /* loader uses this to force layer initialization; device object is wrapped */
143 if (!strcmp("vkGetDeviceProcAddr", pName)) {
Jon Ashburn9eed2892015-06-01 10:02:09 -0600144 initDeviceTable((const VkBaseLayerObject *) device);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600145 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600146 }
147
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600148 if (!strcmp("vkCreateDevice", pName))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600149 return (PFN_vkVoidFunction) basic_CreateDevice;
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600150 if (!strcmp("vkDestroyDevice", pName))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600151 return (PFN_vkVoidFunction) basic_DestroyDevice;
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600152 if (!strcmp("vkLayerExtension1", pName))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600153 return (PFN_vkVoidFunction) vkLayerExtension1;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600154 else
155 {
Jon Ashburn9eed2892015-06-01 10:02:09 -0600156 if (device_dispatch_table(device)->GetDeviceProcAddr == NULL)
Jon Ashburn1fec4242014-11-26 11:10:26 -0700157 return NULL;
Jon Ashburn9eed2892015-06-01 10:02:09 -0600158 return device_dispatch_table(device)->GetDeviceProcAddr(device, pName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600159 }
160}
161
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600162VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600163{
164 if (instance == NULL)
165 return NULL;
166
Jon Ashburn8fd08252015-05-28 16:25:02 -0600167 /* loader uses this to force layer initialization; instance object is wrapped */
168 if (!strcmp("vkGetInstanceProcAddr", pName)) {
Jon Ashburn9eed2892015-06-01 10:02:09 -0600169 initInstanceTable((const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600170 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600171 }
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600172
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600173 if (!strcmp("vkEnumerateDeviceLayerProperties", pName))
174 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
175 if (!strcmp("vkEnumerateDeviceExtensionProperties", pName))
176 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchterc729b3a2015-07-12 12:40:29 -0600177 if (!strcmp("vkGetPhysicalDeviceFormatProperties", pName))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600178 return (PFN_vkVoidFunction) basic_GetPhysicalDeviceFormatProperties;
Jon Ashburn9a8a2e22015-05-19 16:34:53 -0600179 if (!strcmp("vkDestroyInstance", pName))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600180 return (PFN_vkVoidFunction) basic_DestroyInstance;
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600181 if (!strcmp("vkEnumeratePhysicalDevices", pName))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600182 return (PFN_vkVoidFunction) basic_EnumeratePhysicalDevices;
Jon Ashburn8fd08252015-05-28 16:25:02 -0600183
Courtney Goeltzenleuchter842f8422015-07-05 11:10:06 -0600184 if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL)
185 return NULL;
186 return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName);
Jon Ashburn1fec4242014-11-26 11:10:26 -0700187}
David Pinedo38310942015-07-09 16:23:44 -0600188
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600189VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)
David Pinedo38310942015-07-09 16:23:44 -0600190{
191 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
192}
193
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600194VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)
David Pinedo38310942015-07-09 16:23:44 -0600195{
196 return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);
197}