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 // Writes a stringified version of enum vulkan_loader_debug_flags into a char array cmd_line_msg of length cmd_line_size 58 void generate_debug_flag_str(VkFlags msg_type, size_t cmd_line_size, char *cmd_line_msg); 59 60 // The asm declaration prevents name mangling which is necessary for macOS 61 #if defined(MODIFY_UNKNOWN_FUNCTION_DECLS) 62 #define ASM_NAME(name) __asm(name) 63 #else 64 #define ASM_NAME(name) 65 #endif 66 67 #if defined(__clang__) 68 #define DECORATE_PRINTF(_fmt_argnum, _first_param_num) __attribute__((format(printf, _fmt_argnum, _first_param_num))) 69 #elif defined(__GNUC__) 70 #define DECORATE_PRINTF(_fmt_argnum, _first_param_num) __attribute__((format(gnu_printf, _fmt_argnum, _first_param_num))) 71 #else 72 #define DECORATE_PRINTF(_fmt_num, _first_param_num) 73 #endif 74 75 // Logs a message to stderr 76 // May output to DebugUtils if the instance isn't null and the extension is enabled. 77 void DECORATE_PRINTF(4, 5) loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, 78 ...) ASM_NAME("loader_log"); 79 80 // Used for the assembly code to emit an specific error message 81 // This is a work around for linux 32 bit error handling not passing relocatable strings correctly 82 void loader_log_asm_function_not_supported(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, 83 const char *func_name) ASM_NAME("loader_log_asm_function_not_supported"); 84 85 #undef ASM_NAME 86