blob: 52cd17026b6b51d88218037b8fb4f2bf47475849 [file] [log] [blame]
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 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 *
24 * Authors:
25 * Jon Ashburn <jon@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
27 */
28
Tobin Ehlis7a51d902015-07-03 10:34:49 -060029#include "vk_loader_platform.h"
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060030#include "loader.h"
31#include "vk_debug_report_lunarg.h"
Jon Ashburnc2a4d932015-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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060092
93void debug_report_add_instance_extensions(
94 struct loader_extension_list *ext_list);
95
96void debug_report_create_instance(
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060097 struct loader_instance *ptr_instance,
98 const VkInstanceCreateInfo *pCreateInfo);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060099
100void *debug_report_instance_gpa(
101 struct loader_instance *ptr_instance,
102 const char* name);
103
Dan Ginsburgf99e4102015-07-23 13:15:00 -0400104VkResult VKAPI loader_DbgCreateMsgCallback(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600105 VkInstance instance,
106 VkFlags msgFlags,
107 const PFN_vkDbgMsgCallback pfnMsgCallback,
Jon Ashburnf9136f42015-08-06 13:56:43 -0600108 void* pUserData,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600109 VkDbgMsgCallback* pMsgCallback);
110
Dan Ginsburgf99e4102015-07-23 13:15:00 -0400111VkResult VKAPI loader_DbgDestroyMsgCallback(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600112 VkInstance instance,
113 VkDbgMsgCallback msgCallback);