blob: a6107a7fcef450d52cd9ee9d501c35aa5a79e000 [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 Goeltzenleuchterf579fa62015-06-10 17:39:03 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
24 * Author: Jon Ashburn <jon@lunarg.com>
25 *
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060026 */
27
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060028#include "vk_loader_platform.h"
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060029#include "loader.h"
David Pinedoabd07722015-11-24 09:00:24 -070030#include "vulkan/vk_lunarg_debug_report.h"
Jon Ashburn51379582015-08-03 17:34:47 -060031 /*
32 * CreateMsgCallback is global and needs to be
33 * applied to all layers and ICDs.
34 * What happens if a layer is enabled on both the instance chain
35 * as well as the device chain and a call to CreateMsgCallback is made?
36 * Do we need to make sure that each layer / driver only gets called once?
37 * Should a layer implementing support for CreateMsgCallback only be allowed (?)
38 * to live on one chain? Or maybe make it the application's responsibility.
39 * If the app enables DRAW_STATE on at both CreateInstance time and CreateDevice
40 * time, CreateMsgCallback will call the DRAW_STATE layer twice. Once via
41 * the instance chain and once via the device chain.
42 * The loader should only return the DEBUG_REPORT extension as supported
43 * for the GetGlobalExtensionSupport call. That should help eliminate one
44 * duplication.
45 * Since the instance chain requires us iterating over the available ICDs
46 * and each ICD will have it's own unique MsgCallback object we need to
47 * track those objects to give back the right one.
48 * This also implies that the loader has to intercept vkDestroyObject and
49 * if the extension is enabled and the object type is a MsgCallback then
50 * we must translate the object into the proper ICD specific ones.
51 * DestroyObject works on a device chain. Should not be what's destroying
52 * the MsgCallback object. That needs to be an instance thing. So, since
53 * we used an instance to create it, we need a custom Destroy that also
54 * takes an instance. That way we can iterate over the ICDs properly.
55 * Example use:
56 * CreateInstance: DEBUG_REPORT
57 * Loader will create instance chain with enabled extensions.
58 * TODO: Should validation layers be enabled here? If not, they will not be in the instance chain.
59 * fn = GetProcAddr(INSTANCE, "vkCreateMsgCallback") -> point to loader's vkCreateMsgCallback
60 * App creates a callback object: fn(..., &MsgCallbackObject1)
61 * Have only established the instance chain so far. Loader will call the instance chain.
62 * Each layer in the instance chain will call down to the next layer, terminating with
63 * the CreateMsgCallback loader terminator function that creates the actual MsgCallbackObject1 object.
64 * The loader CreateMsgCallback terminator will iterate over the ICDs.
65 * Calling each ICD that supports vkCreateMsgCallback and collect answers in icd_msg_callback_map here.
66 * As result is sent back up the chain each layer has opportunity to record the callback operation and
67 * appropriate MsgCallback object.
68 * ...
69 * Any reports matching the flags set in MsgCallbackObject1 will generate the defined callback behavior
70 * in the layer / ICD that initiated that report.
71 * ...
72 * CreateDevice: MemTracker:...
73 * App does not include DEBUG_REPORT as that is a global extension.
74 * TODO: GetExtensionSupport must not report DEBUG_REPORT when using instance.
75 * App MUST include any desired validation layers or they will not participate in the device call chain.
76 * App creates a callback object: fn(..., &MsgCallbackObject2)
77 * Loader's vkCreateMsgCallback is called.
78 * Loader sends call down instance chain - this is a global extension - any validation layer that was
79 * enabled at CreateInstance will be able to register the callback. Loader will iterate over the ICDs and
80 * will record the ICD's version of the MsgCallback2 object here.
81 * ...
82 * Any report will go to the layer's report function and it will check the flags for MsgCallbackObject1
83 * and MsgCallbackObject2 and take the appropriate action as indicated by the app.
84 * ...
85 * App calls vkDestroyMsgCallback( MsgCallbackObject1 )
86 * Loader's DestroyMsgCallback is where call starts. DestroyMsgCallback will be sent down instance chain
87 * ending in the loader's DestroyMsgCallback terminator which will iterate over the ICD's destroying each
88 * ICD version of that MsgCallback object and then destroy the loader's version of the object.
89 * Any reports generated after this will only have MsgCallbackObject2 available.
90 */
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060091
92void debug_report_add_instance_extensions(
Jon Ashburne39a4f82015-08-28 13:38:21 -060093 const struct loader_instance *inst,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060094 struct loader_extension_list *ext_list);
95
96void debug_report_create_instance(
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060097 struct loader_instance *ptr_instance,
98 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060099
Jon Ashburnf7a48db2015-10-01 12:03:17 -0600100bool debug_report_instance_gpa(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600101 struct loader_instance *ptr_instance,
Jon Ashburnf7a48db2015-10-01 12:03:17 -0600102 const char* name,
103 void **addr);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600104
Chia-I Wu9ab61502015-11-06 06:42:02 +0800105VKAPI_ATTR VkResult VKAPI_CALL loader_DbgCreateMsgCallback(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600106 VkInstance instance,
107 VkFlags msgFlags,
108 const PFN_vkDbgMsgCallback pfnMsgCallback,
Jon Ashburne67741a2015-08-06 13:56:43 -0600109 void* pUserData,
Courtney Goeltzenleuchter107a0d22015-11-25 14:07:05 -0700110 VkDebugReportCallbackLUNARG* pMsgCallback);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600111
Chia-I Wu9ab61502015-11-06 06:42:02 +0800112VKAPI_ATTR VkResult VKAPI_CALL loader_DbgDestroyMsgCallback(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600113 VkInstance instance,
Courtney Goeltzenleuchter107a0d22015-11-25 14:07:05 -0700114 VkDebugReportCallbackLUNARG msgCallback);