Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1 | /* |
| 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 Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 29 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 30 | #include "loader.h" |
| 31 | #include "vk_debug_report_lunarg.h" |
Jon Ashburn | c2a4d93 | 2015-08-03 17:34:47 -0600 | [diff] [blame] | 32 | /* |
| 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 Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 92 | |
| 93 | void debug_report_add_instance_extensions( |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 94 | const struct loader_instance *inst, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 95 | struct loader_extension_list *ext_list); |
| 96 | |
| 97 | void debug_report_create_instance( |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 98 | struct loader_instance *ptr_instance, |
| 99 | const VkInstanceCreateInfo *pCreateInfo); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 100 | |
Jon Ashburn | 05b4ec6 | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 101 | bool debug_report_instance_gpa( |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 102 | struct loader_instance *ptr_instance, |
Jon Ashburn | 05b4ec6 | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 103 | const char* name, |
| 104 | void **addr); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 105 | |
Dan Ginsburg | f99e410 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 106 | VkResult VKAPI loader_DbgCreateMsgCallback( |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 107 | VkInstance instance, |
| 108 | VkFlags msgFlags, |
| 109 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
Jon Ashburn | f9136f4 | 2015-08-06 13:56:43 -0600 | [diff] [blame] | 110 | void* pUserData, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 111 | VkDbgMsgCallback* pMsgCallback); |
| 112 | |
Dan Ginsburg | f99e410 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 113 | VkResult VKAPI loader_DbgDestroyMsgCallback( |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 114 | VkInstance instance, |
| 115 | VkDbgMsgCallback msgCallback); |