blob: d7d28ea95fe4ede7c139261f9baea8548bf15f0c [file] [log] [blame]
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001/*
Jon Ashburn44aed662016-02-02 17:47:28 -07002 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
5 * Copyright (C) 2015-2016 Google Inc.
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06006 *
Jon Ashburn44aed662016-02-02 17:47:28 -07007 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and/or associated documentation files (the "Materials"), to
9 * deal in the Materials without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Materials, and to permit persons to whom the Materials are
12 * furnished to do so, subject to the following conditions:
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060013 *
Jon Ashburn44aed662016-02-02 17:47:28 -070014 * The above copyright notice(s) and this permission notice shall be included in
15 * all copies or substantial portions of the Materials.
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060016 *
Jon Ashburn44aed662016-02-02 17:47:28 -070017 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Jon Ashburn44aed662016-02-02 17:47:28 -070019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 *
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
24 * USE OR OTHER DEALINGS IN THE MATERIALS.
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060025 *
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060026 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
27 * Author: Jon Ashburn <jon@lunarg.com>
28 *
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060029 */
30
Tobin Ehlis7a51d902015-07-03 10:34:49 -060031#include "vk_loader_platform.h"
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060032#include "loader.h"
Jon Ashburn44aed662016-02-02 17:47:28 -070033/*
34 * CreateMsgCallback is global and needs to be
35 * applied to all layers and ICDs.
36 * What happens if a layer is enabled on both the instance chain
37 * as well as the device chain and a call to CreateMsgCallback is made?
38 * Do we need to make sure that each layer / driver only gets called once?
39 * Should a layer implementing support for CreateMsgCallback only be allowed (?)
40 * to live on one chain? Or maybe make it the application's responsibility.
41 * If the app enables DRAW_STATE on at both CreateInstance time and CreateDevice
42 * time, CreateMsgCallback will call the DRAW_STATE layer twice. Once via
43 * the instance chain and once via the device chain.
44 * The loader should only return the DEBUG_REPORT extension as supported
45 * for the GetGlobalExtensionSupport call. That should help eliminate one
46 * duplication.
47 * Since the instance chain requires us iterating over the available ICDs
48 * and each ICD will have it's own unique MsgCallback object we need to
49 * track those objects to give back the right one.
50 * This also implies that the loader has to intercept vkDestroyObject and
51 * if the extension is enabled and the object type is a MsgCallback then
52 * we must translate the object into the proper ICD specific ones.
53 * DestroyObject works on a device chain. Should not be what's destroying
54 * the MsgCallback object. That needs to be an instance thing. So, since
55 * we used an instance to create it, we need a custom Destroy that also
56 * takes an instance. That way we can iterate over the ICDs properly.
57 * Example use:
58 * CreateInstance: DEBUG_REPORT
59 * Loader will create instance chain with enabled extensions.
60 * TODO: Should validation layers be enabled here? If not, they will not be in
61 * the instance chain.
62 * fn = GetProcAddr(INSTANCE, "vkCreateMsgCallback") -> point to loader's
63 * vkCreateMsgCallback
64 * App creates a callback object: fn(..., &MsgCallbackObject1)
65 * Have only established the instance chain so far. Loader will call the
66 * instance chain.
67 * Each layer in the instance chain will call down to the next layer,
68 * terminating with
69 * the CreateMsgCallback loader terminator function that creates the actual
70 * MsgCallbackObject1 object.
71 * The loader CreateMsgCallback terminator will iterate over the ICDs.
72 * Calling each ICD that supports vkCreateMsgCallback and collect answers in
73 * icd_msg_callback_map here.
74 * As result is sent back up the chain each layer has opportunity to record the
75 * callback operation and
76 * appropriate MsgCallback object.
77 * ...
78 * Any reports matching the flags set in MsgCallbackObject1 will generate the
79 * defined callback behavior
80 * in the layer / ICD that initiated that report.
81 * ...
82 * CreateDevice: MemTracker:...
83 * App does not include DEBUG_REPORT as that is a global extension.
84 * TODO: GetExtensionSupport must not report DEBUG_REPORT when using instance.
85 * App MUST include any desired validation layers or they will not participate
86 * in the device call chain.
87 * App creates a callback object: fn(..., &MsgCallbackObject2)
88 * Loader's vkCreateMsgCallback is called.
89 * Loader sends call down instance chain - this is a global extension - any
90 * validation layer that was
91 * enabled at CreateInstance will be able to register the callback. Loader will
92 * iterate over the ICDs and
93 * will record the ICD's version of the MsgCallback2 object here.
94 * ...
95 * Any report will go to the layer's report function and it will check the flags
96 * for MsgCallbackObject1
97 * and MsgCallbackObject2 and take the appropriate action as indicated by the
98 * app.
99 * ...
100 * App calls vkDestroyMsgCallback( MsgCallbackObject1 )
101 * Loader's DestroyMsgCallback is where call starts. DestroyMsgCallback will be
102 * sent down instance chain
103 * ending in the loader's DestroyMsgCallback terminator which will iterate over
104 * the ICD's destroying each
105 * ICD version of that MsgCallback object and then destroy the loader's version
106 * of the object.
107 * Any reports generated after this will only have MsgCallbackObject2 available.
108 */
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600109
110void debug_report_add_instance_extensions(
Jon Ashburn44aed662016-02-02 17:47:28 -0700111 const struct loader_instance *inst, struct loader_extension_list *ext_list);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600112
Jon Ashburn44aed662016-02-02 17:47:28 -0700113void debug_report_create_instance(struct loader_instance *ptr_instance,
114 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600115
Jon Ashburn44aed662016-02-02 17:47:28 -0700116bool debug_report_instance_gpa(struct loader_instance *ptr_instance,
117 const char *name, void **addr);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600118
Jon Ashburna9c4a572016-02-26 13:14:27 -0700119VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugReportCallback(
Jon Ashburn44aed662016-02-02 17:47:28 -0700120 VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
121 const VkAllocationCallbacks *pAllocator,
122 VkDebugReportCallbackEXT *pCallback);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600123
Jon Ashburn44aed662016-02-02 17:47:28 -0700124VKAPI_ATTR void VKAPI_CALL
Jon Ashburna9c4a572016-02-26 13:14:27 -0700125terminator_DestroyDebugReportCallback(VkInstance instance,
126 VkDebugReportCallbackEXT callback,
127 const VkAllocationCallbacks *pAllocator);
Courtney Goeltzenleuchter6175e4b2015-11-30 15:28:25 -0700128
Jon Ashburn44aed662016-02-02 17:47:28 -0700129VKAPI_ATTR void VKAPI_CALL
Jon Ashburna9c4a572016-02-26 13:14:27 -0700130terminator_DebugReportMessage(VkInstance instance, VkDebugReportFlagsEXT flags,
131 VkDebugReportObjectTypeEXT objType,
132 uint64_t object, size_t location, int32_t msgCode,
133 const char *pLayerPrefix, const char *pMsg);
Courtney Goeltzenleuchter15436c12015-12-02 15:29:33 -0700134
Jon Ashburn44aed662016-02-02 17:47:28 -0700135VkResult
136util_CreateDebugReportCallback(struct loader_instance *inst,
137 VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
138 const VkAllocationCallbacks *pAllocator,
139 VkDebugReportCallbackEXT callback);
Courtney Goeltzenleuchter15436c12015-12-02 15:29:33 -0700140
Jon Ashburn44aed662016-02-02 17:47:28 -0700141void util_DestroyDebugReportCallback(struct loader_instance *inst,
142 VkDebugReportCallbackEXT callback,
143 const VkAllocationCallbacks *pAllocator);
Courtney Goeltzenleuchter15436c12015-12-02 15:29:33 -0700144
Jon Ashburn9b2a8c92016-04-15 09:25:03 -0600145VkResult util_CopyDebugReportCreateInfos(
146 const void *pChain, const VkAllocationCallbacks *pAllocator,
147 uint32_t *num_callbacks, VkDebugReportCallbackCreateInfoEXT **infos,
148 VkDebugReportCallbackEXT **callbacks);
Ian Elliott01b78322016-03-31 10:48:19 -0600149void util_FreeDebugReportCreateInfos(const VkAllocationCallbacks *pAllocator,
150 VkDebugReportCallbackCreateInfoEXT *infos,
151 VkDebugReportCallbackEXT *callbacks);
Jon Ashburn9b2a8c92016-04-15 09:25:03 -0600152VkResult util_CreateDebugReportCallbacks(
153 struct loader_instance *inst, const VkAllocationCallbacks *pAllocator,
154 uint32_t num_callbacks, VkDebugReportCallbackCreateInfoEXT *infos,
155 VkDebugReportCallbackEXT *callbacks);
Ian Elliott01b78322016-03-31 10:48:19 -0600156
157void util_DestroyDebugReportCallbacks(struct loader_instance *inst,
158 const VkAllocationCallbacks *pAllocator,
159 uint32_t num_callbacks,
160 VkDebugReportCallbackEXT *callbacks);
161
Jon Ashburn44aed662016-02-02 17:47:28 -0700162VkBool32 util_DebugReportMessage(const struct loader_instance *inst,
163 VkFlags msgFlags,
164 VkDebugReportObjectTypeEXT objectType,
165 uint64_t srcObject, size_t location,
166 int32_t msgCode, const char *pLayerPrefix,
167 const char *pMsg);