1 /*
2  *
3  * Copyright (c) 2014-2021 The Khronos Group Inc.
4  * Copyright (c) 2014-2021 Valve Corporation
5  * Copyright (c) 2014-2021 LunarG, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Author: Jon Ashburn <jon@lunarg.com>
20  * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
21  * Author: Chia-I Wu <olvaffe@gmail.com>
22  * Author: Chia-I Wu <olv@lunarg.com>
23  * Author: Mark Lobodzinski <mark@LunarG.com>
24  * Author: Lenny Komow <lenny@lunarg.com>
25  * Author: Charles Giessen <charles@lunarg.com>
26  *
27  */
28 
29 #pragma once
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 
34 #include "vulkan/vulkan_core.h"
35 
36 struct loader_instance;
37 
38 enum vulkan_loader_debug_flags {
39     VULKAN_LOADER_INFO_BIT = 0x01,
40     VULKAN_LOADER_WARN_BIT = 0x02,
41     VULKAN_LOADER_PERF_BIT = 0x04,
42     VULKAN_LOADER_ERROR_BIT = 0x08,
43     VULKAN_LOADER_DEBUG_BIT = 0x10,
44     VULKAN_LOADER_LAYER_BIT = 0x20,
45     VULKAN_LOADER_DRIVER_BIT = 0x40,
46     VULKAN_LOADER_VALIDATION_BIT = 0x80,
47     VULKAN_LOADER_FATAL_ERROR_BIT = 0x100,  // only forces the output to be printed to stderr, has no other effect
48 };
49 
50 // Checks for the environment variable VK_LOADER_DEBUG and sets up the current debug level accordingly
51 // This should be called before any Vulkan API calls, eg in the initialization of the .dll or .so
52 void loader_init_global_debug_level(void);
53 
54 // Sets the global debug level - used by global settings files
55 void loader_set_global_debug_level(uint32_t new_loader_debug);
56 
57 // The asm declaration prevents name mangling which is necessary for macOS
58 #if defined(MODIFY_UNKNOWN_FUNCTION_DECLS)
59 #define ASM_NAME(name) __asm(name)
60 #else
61 #define ASM_NAME(name)
62 #endif
63 
64 // Logs a message to stderr
65 // May output to DebugUtils if the instance isn't null and the extension is enabled.
66 void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...)
67     ASM_NAME("loader_log");
68 
69 // Used for the assembly code to emit an specific error message
70 // This is a work around for linux 32 bit error handling not passing relocatable strings correctly
71 void loader_log_asm_function_not_supported(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code,
72                                            const char *func_name) ASM_NAME("loader_log_asm_function_not_supported");
73 
74 #undef ASM_NAME
75