blob: 835a8005918c8fa99deb3a9cf381c9fa912f020d [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"
Ian Elliott20f06872015-02-12 17:08:34 -070031// The following is #included again to catch certain OS-specific functions
32// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060033#include "vk_loader_platform.h"
Jon Ashburn227a9422014-11-26 11:10:26 -070034
Jon Ashburn227a9422014-11-26 11:10:26 -070035
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060036VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device)
Jon Ashburn227a9422014-11-26 11:10:26 -070037{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060038 printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device);
39 printf("vkLayerExtension1 returning SUCCESS\n");
40 return VK_SUCCESS;
Jon Ashburn227a9422014-11-26 11:10:26 -070041}
42
Jon Ashburneb2728b2015-04-10 14:33:07 -060043#define BASIC_LAYER_EXT_ARRAY_SIZE 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060044
45static const VkExtensionProperties basicExts[BASIC_LAYER_EXT_ARRAY_SIZE] = {
46 {
47 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
48 "Basic",
49 0x10,
50 "Sample layer: Basic ",
51// 0,
52// NULL,
53 },
54 {
55 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
56 "vkLayerExtension1",
57 0x10,
58 "Sample layer: Basic",
59// 0,
60// NULL,
61 }
Jon Ashburneb2728b2015-04-10 14:33:07 -060062};
63
Tony Barbour426b9052015-06-24 16:06:58 -060064VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Jon Ashburneb2728b2015-04-10 14:33:07 -060065 uint32_t extensionIndex,
Tony Barbour426b9052015-06-24 16:06:58 -060066 VkExtensionProperties* pData)
Jon Ashburneb2728b2015-04-10 14:33:07 -060067{
Jon Ashburneb2728b2015-04-10 14:33:07 -060068 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Jon Ashburneb2728b2015-04-10 14:33:07 -060069 uint32_t *count;
70
Tony Barbour426b9052015-06-24 16:06:58 -060071 if (extensionIndex >= BASIC_LAYER_EXT_ARRAY_SIZE)
72 return VK_ERROR_INVALID_VALUE;
73 memcpy((VkExtensionProperties *) pData, &basicExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburneb2728b2015-04-10 14:33:07 -060074
Tony Barbour426b9052015-06-24 16:06:58 -060075 return VK_SUCCESS;
76}
Jon Ashburneb2728b2015-04-10 14:33:07 -060077
Tony Barbour426b9052015-06-24 16:06:58 -060078VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionCount(uint32_t* pCount)
79{
80 *pCount = BASIC_LAYER_EXT_ARRAY_SIZE;
Jon Ashburneb2728b2015-04-10 14:33:07 -060081 return VK_SUCCESS;
82}
83
Jon Ashburn2666e2f2015-05-15 15:09:35 -060084VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(
85 VkInstance instance,
86 uint32_t* pPhysicalDeviceCount,
87 VkPhysicalDevice* pPhysicalDevices)
88{
Jon Ashburn2666e2f2015-05-15 15:09:35 -060089 printf("At start of wrapped vkEnumeratePhysicalDevices() call w/ inst: %p\n", (void*)instance);
Jon Ashburn5a10d212015-06-01 10:02:09 -060090 VkResult result = instance_dispatch_table(instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Jon Ashburn2666e2f2015-05-15 15:09:35 -060091 printf("Completed wrapped vkEnumeratePhysicalDevices() call w/ count %u\n", *pPhysicalDeviceCount);
92 return result;
93}
94
Tony Barbour8205d902015-04-16 15:59:00 -060095VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Jon Ashburn227a9422014-11-26 11:10:26 -070096{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060097 printf("At start of wrapped vkCreateDevice() call w/ gpu: %p\n", (void*)gpu);
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -060098 VkResult result = device_dispatch_table(*pDevice)->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060099 printf("Completed wrapped vkCreateDevice() call w/ pDevice, Device %p: %p\n", (void*)pDevice, (void *) *pDevice);
Jon Ashburn227a9422014-11-26 11:10:26 -0700100 return result;
101}
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600102
Jon Ashburn17f37372015-05-19 16:34:53 -0600103/* hook DestroyDevice to remove tableMap entry */
104VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
105{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600106 dispatch_key key = get_dispatch_key(device);
Jon Ashburn5a10d212015-06-01 10:02:09 -0600107 VkResult res = device_dispatch_table(device)->DestroyDevice(device);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600108 destroy_device_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600109 return res;
110}
111
112/* hook DestroyInstance to remove tableInstanceMap entry */
113VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
114{
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600115 dispatch_key key = get_dispatch_key(instance);
Jon Ashburn5a10d212015-06-01 10:02:09 -0600116 VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);
Courtney Goeltzenleuchter9f171942015-06-13 21:22:12 -0600117 destroy_instance_dispatch_table(key);
Jon Ashburn17f37372015-05-19 16:34:53 -0600118 return res;
119}
120
Chris Forbesd7576302015-06-21 22:55:02 +1200121VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatInfo(VkPhysicalDevice gpu, VkFormat format, VkFormatProperties *pFormatInfo)
Jon Ashburn227a9422014-11-26 11:10:26 -0700122{
Chris Forbesd7576302015-06-21 22:55:02 +1200123 printf("At start of wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu);
124 VkResult result = instance_dispatch_table(gpu)->GetPhysicalDeviceFormatInfo(gpu, format, pFormatInfo);
125 printf("Completed wrapped vkGetPhysicalDeviceFormatInfo() call w/ gpu: %p\n", (void*)gpu);
Jon Ashburn227a9422014-11-26 11:10:26 -0700126 return result;
127}
128
Jon Ashburn1245cec2015-05-18 13:20:15 -0600129VK_LAYER_EXPORT void * VKAPI vkGetDeviceProcAddr(VkDevice device, const char* pName)
Jon Ashburn8d8dad02014-12-01 14:22:40 -0700130{
Jon Ashburn1245cec2015-05-18 13:20:15 -0600131 if (device == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700132 return NULL;
Chia-I Wue9ae3882015-01-05 09:41:27 +0800133
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600134 /* loader uses this to force layer initialization; device object is wrapped */
135 if (!strcmp("vkGetDeviceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600136 initDeviceTable((const VkBaseLayerObject *) device);
Jon Ashburn1245cec2015-05-18 13:20:15 -0600137 return (void *) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600138 }
139
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -0600140 if (!strcmp("vkCreateDevice", pName))
141 return (void *) vkCreateDevice;
Jon Ashburn17f37372015-05-19 16:34:53 -0600142 if (!strcmp("vkDestroyDevice", pName))
143 return (void *) vkDestroyDevice;
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600144 if (!strcmp("vkLayerExtension1", pName))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145 return (void *) vkLayerExtension1;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600146 else
147 {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600148 if (device_dispatch_table(device)->GetDeviceProcAddr == NULL)
Jon Ashburn227a9422014-11-26 11:10:26 -0700149 return NULL;
Jon Ashburn5a10d212015-06-01 10:02:09 -0600150 return device_dispatch_table(device)->GetDeviceProcAddr(device, pName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600151 }
152}
153
154VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* pName)
155{
156 if (instance == NULL)
157 return NULL;
158
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600159 /* loader uses this to force layer initialization; instance object is wrapped */
160 if (!strcmp("vkGetInstanceProcAddr", pName)) {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600161 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600162 return (void *) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600163 }
Chris Forbesd7576302015-06-21 22:55:02 +1200164 if (!strcmp("vkGetPhysicalDeviceFormatInfo", pName))
165 return (void *) vkGetPhysicalDeviceFormatInfo;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600166
Jon Ashburn17f37372015-05-19 16:34:53 -0600167 if (!strcmp("vkDestroyInstance", pName))
168 return (void *) vkDestroyInstance;
Jon Ashburn2666e2f2015-05-15 15:09:35 -0600169 if (!strcmp("vkEnumeratePhysicalDevices", pName))
170 return (void*) vkEnumeratePhysicalDevices;
Tony Barbour426b9052015-06-24 16:06:58 -0600171 if (!strcmp("vkGetGlobalExtensionCount", pName))
172 return (void*) vkGetGlobalExtensionCount;
173 if (!strcmp("vkGetGlobalExtensionProperties", pName))
174 return (void*) vkGetGlobalExtensionProperties;
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600175 else
176 {
Jon Ashburn5a10d212015-06-01 10:02:09 -0600177 if (instance_dispatch_table(instance)->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -0600178 return NULL;
Jon Ashburn5a10d212015-06-01 10:02:09 -0600179 return instance_dispatch_table(instance)->GetInstanceProcAddr(instance, pName);
Jon Ashburn227a9422014-11-26 11:10:26 -0700180 }
Jon Ashburn4f2575f2015-05-28 16:25:02 -0600181
Jon Ashburn227a9422014-11-26 11:10:26 -0700182}