blob: baaae86fb9a8241221f5be2b6436458c81054d44 [file] [log] [blame]
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001/*
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchterf821dad2015-12-02 14:53:22 -07004 * Copyright (C) 2015 Google Inc.
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06005 *
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 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060024 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
25 * Author: Jon Ashburn <jon@lunarg.com>
26 *
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060027 */
28
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060029#include "vk_loader_platform.h"
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060030#include "loader.h"
David Pinedoabd07722015-11-24 09:00:24 -070031#include "vulkan/vk_lunarg_debug_report.h"
Jon Ashburn51379582015-08-03 17:34:47 -060032 /*
33 * CreateMsgCallback is global and needs to be
34 * applied to all layers and ICDs.
35 * What happens if a layer is enabled on both the instance chain
36 * as well as the device chain and a call to CreateMsgCallback is made?
37 * Do we need to make sure that each layer / driver only gets called once?
38 * Should a layer implementing support for CreateMsgCallback only be allowed (?)
39 * to live on one chain? Or maybe make it the application's responsibility.
40 * If the app enables DRAW_STATE on at both CreateInstance time and CreateDevice
41 * time, CreateMsgCallback will call the DRAW_STATE layer twice. Once via
42 * the instance chain and once via the device chain.
43 * The loader should only return the DEBUG_REPORT extension as supported
44 * for the GetGlobalExtensionSupport call. That should help eliminate one
45 * duplication.
46 * Since the instance chain requires us iterating over the available ICDs
47 * and each ICD will have it's own unique MsgCallback object we need to
48 * track those objects to give back the right one.
49 * This also implies that the loader has to intercept vkDestroyObject and
50 * if the extension is enabled and the object type is a MsgCallback then
51 * we must translate the object into the proper ICD specific ones.
52 * DestroyObject works on a device chain. Should not be what's destroying
53 * the MsgCallback object. That needs to be an instance thing. So, since
54 * we used an instance to create it, we need a custom Destroy that also
55 * takes an instance. That way we can iterate over the ICDs properly.
56 * Example use:
57 * CreateInstance: DEBUG_REPORT
58 * Loader will create instance chain with enabled extensions.
59 * TODO: Should validation layers be enabled here? If not, they will not be in the instance chain.
60 * fn = GetProcAddr(INSTANCE, "vkCreateMsgCallback") -> point to loader's vkCreateMsgCallback
61 * App creates a callback object: fn(..., &MsgCallbackObject1)
62 * Have only established the instance chain so far. Loader will call the instance chain.
63 * Each layer in the instance chain will call down to the next layer, terminating with
64 * the CreateMsgCallback loader terminator function that creates the actual MsgCallbackObject1 object.
65 * The loader CreateMsgCallback terminator will iterate over the ICDs.
66 * Calling each ICD that supports vkCreateMsgCallback and collect answers in icd_msg_callback_map here.
67 * As result is sent back up the chain each layer has opportunity to record the callback operation and
68 * appropriate MsgCallback object.
69 * ...
70 * Any reports matching the flags set in MsgCallbackObject1 will generate the defined callback behavior
71 * in the layer / ICD that initiated that report.
72 * ...
73 * CreateDevice: MemTracker:...
74 * App does not include DEBUG_REPORT as that is a global extension.
75 * TODO: GetExtensionSupport must not report DEBUG_REPORT when using instance.
76 * App MUST include any desired validation layers or they will not participate in the device call chain.
77 * App creates a callback object: fn(..., &MsgCallbackObject2)
78 * Loader's vkCreateMsgCallback is called.
79 * Loader sends call down instance chain - this is a global extension - any validation layer that was
80 * enabled at CreateInstance will be able to register the callback. Loader will iterate over the ICDs and
81 * will record the ICD's version of the MsgCallback2 object here.
82 * ...
83 * Any report will go to the layer's report function and it will check the flags for MsgCallbackObject1
84 * and MsgCallbackObject2 and take the appropriate action as indicated by the app.
85 * ...
86 * App calls vkDestroyMsgCallback( MsgCallbackObject1 )
87 * Loader's DestroyMsgCallback is where call starts. DestroyMsgCallback will be sent down instance chain
88 * ending in the loader's DestroyMsgCallback terminator which will iterate over the ICD's destroying each
89 * ICD version of that MsgCallback object and then destroy the loader's version of the object.
90 * Any reports generated after this will only have MsgCallbackObject2 available.
91 */
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060092
93void debug_report_add_instance_extensions(
Jon Ashburne39a4f82015-08-28 13:38:21 -060094 const struct loader_instance *inst,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060095 struct loader_extension_list *ext_list);
96
97void debug_report_create_instance(
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060098 struct loader_instance *ptr_instance,
99 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600100
Jon Ashburnf7a48db2015-10-01 12:03:17 -0600101bool debug_report_instance_gpa(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600102 struct loader_instance *ptr_instance,
Jon Ashburnf7a48db2015-10-01 12:03:17 -0600103 const char* name,
104 void **addr);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600105
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700106VKAPI_ATTR VkResult VKAPI_CALL loader_CreateDebugReportCallback(
107 VkInstance instance,
108 VkDebugReportCallbackCreateInfoLUNARG *pCreateInfo,
109 const VkAllocationCallbacks *pAllocator,
110 VkDebugReportCallbackLUNARG *pCallback);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600111
Courtney Goeltzenleuchter5ffb1d92015-11-30 15:22:41 -0700112VKAPI_ATTR void VKAPI_CALL loader_DestroyDebugReportCallback(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700113 VkInstance instance,
114 VkDebugReportCallbackLUNARG callback,
115 const VkAllocationCallbacks *pAllocator);
Courtney Goeltzenleuchter822e8d72015-11-30 15:28:25 -0700116
117VKAPI_ATTR void VKAPI_CALL loader_DebugReportMessage(
118 VkInstance instance,
119 VkDebugReportFlagsLUNARG flags,
120 VkDebugReportObjectTypeLUNARG objType,
121 uint64_t object,
122 size_t location,
123 int32_t msgCode,
124 const char* pLayerPrefix,
125 const char* pMsg);
Courtney Goeltzenleuchter82887272015-12-02 15:29:33 -0700126
127VkResult util_CreateDebugReportCallback(
128 struct loader_instance *inst,
129 VkDebugReportCallbackCreateInfoLUNARG *pCreateInfo,
130 const VkAllocationCallbacks *pAllocator,
131 VkDebugReportCallbackLUNARG callback);
132
133void util_DestroyDebugReportCallback(
134 struct loader_instance *inst,
135 VkDebugReportCallbackLUNARG callback,
136 const VkAllocationCallbacks *pAllocator);
137
138VkBool32 util_DebugReportMessage(
139 const struct loader_instance* inst,
140 VkFlags msgFlags,
141 VkDebugReportObjectTypeLUNARG objectType,
142 uint64_t srcObject,
143 size_t location,
144 int32_t msgCode,
145 const char* pLayerPrefix,
146 const char* pMsg);