1 /* Copyright (c) 2015-2021 The Khronos Group Inc.
2  * Copyright (c) 2015-2021 Valve Corporation
3  * Copyright (c) 2015-2021 LunarG, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Author: Jon Ashburn <jon@lunarg.com>
18  * Author: Mark Lobodzinski <mark@lunarg.com>
19  **************************************************************************/
20 #pragma once
21 
22 #include <stdio.h>
23 #include <string>
24 
25 #include "vulkan/vk_layer.h"
26 #include "vulkan/vulkan.h"
27 #include "vk_layer_data.h"
28 
29 #if defined(WIN32)
30 #define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE
31 #define DEFAULT_VK_REGISTRY_HIVE_STR "HKEY_LOCAL_MACHINE"
32 #define SECONDARY_VK_REGISTRY_HIVE HKEY_CURRENT_USER
33 #define SECONDARY_VK_REGISTRY_HIVE_STR "HKEY_CURRENT_USER"
34 #endif
35 
36 std::string GetEnvironment(const char *variable);
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 typedef enum {
43     kVkConfig,
44     kEnvVar,
45     kLocal,
46 } SettingsFileSource;
47 
48 typedef struct SettingsFileInfo {
49     bool file_found = false;
50     std::string location{};
51     SettingsFileSource source = kLocal;
52 } SettingsFileInfo;
53 
54 typedef enum {
55     kInformationBit = 0x00000001,
56     kWarningBit = 0x00000002,
57     kPerformanceWarningBit = 0x00000004,
58     kErrorBit = 0x00000008,
59     kDebugBit = 0x00000010,
60 } LogMessageTypeBits;
61 typedef VkFlags LogMessageTypeFlags;
62 
63 // Definitions for Debug Actions
64 typedef enum VkLayerDbgActionBits {
65     VK_DBG_LAYER_ACTION_IGNORE = 0x00000000,
66     VK_DBG_LAYER_ACTION_CALLBACK = 0x00000001,
67     VK_DBG_LAYER_ACTION_LOG_MSG = 0x00000002,
68     VK_DBG_LAYER_ACTION_BREAK = 0x00000004,
69     VK_DBG_LAYER_ACTION_DEBUG_OUTPUT = 0x00000008,
70     VK_DBG_LAYER_ACTION_DEFAULT = 0x40000000,
71 } VkLayerDbgActionBits;
72 typedef VkFlags VkLayerDbgActionFlags;
73 
74 const layer_data::unordered_map<std::string, VkFlags> debug_actions_option_definitions = {
75     {std::string("VK_DBG_LAYER_ACTION_IGNORE"), VK_DBG_LAYER_ACTION_IGNORE},
76     {std::string("VK_DBG_LAYER_ACTION_CALLBACK"), VK_DBG_LAYER_ACTION_CALLBACK},
77     {std::string("VK_DBG_LAYER_ACTION_LOG_MSG"), VK_DBG_LAYER_ACTION_LOG_MSG},
78     {std::string("VK_DBG_LAYER_ACTION_BREAK"), VK_DBG_LAYER_ACTION_BREAK},
79 #if defined(WIN32)
80     {std::string("VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"), VK_DBG_LAYER_ACTION_DEBUG_OUTPUT},
81 #endif
82     {std::string("VK_DBG_LAYER_ACTION_DEFAULT"), VK_DBG_LAYER_ACTION_DEFAULT}};
83 
84 const layer_data::unordered_map<std::string, VkFlags> report_flags_option_definitions = {
85     {std::string("warn"), VK_DEBUG_REPORT_WARNING_BIT_EXT},
86     {std::string("info"), VK_DEBUG_REPORT_INFORMATION_BIT_EXT},
87     {std::string("perf"), VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT},
88     {std::string("error"), VK_DEBUG_REPORT_ERROR_BIT_EXT},
89     {std::string("debug"), VK_DEBUG_REPORT_DEBUG_BIT_EXT}};
90 
91 const layer_data::unordered_map<std::string, VkFlags> log_msg_type_option_definitions = {{std::string("warn"), kWarningBit},
92                                                                                   {std::string("info"), kInformationBit},
93                                                                                   {std::string("perf"), kPerformanceWarningBit},
94                                                                                   {std::string("error"), kErrorBit},
95                                                                                   {std::string("debug"), kDebugBit}};
96 
97 VK_LAYER_EXPORT const char *getLayerOption(const char *option);
98 VK_LAYER_EXPORT const char *GetLayerEnvVar(const char *option);
99 VK_LAYER_EXPORT const SettingsFileInfo *GetLayerSettingsFileInfo();
100 
101 VK_LAYER_EXPORT FILE *getLayerLogOutput(const char *option, const char *layer_name);
102 VK_LAYER_EXPORT VkFlags GetLayerOptionFlags(std::string option, layer_data::unordered_map<std::string, VkFlags> const &enum_data,
103                                             uint32_t option_default);
104 
105 VK_LAYER_EXPORT void setLayerOption(const char *option, const char *val);
106 VK_LAYER_EXPORT void PrintMessageFlags(VkFlags vk_flags, char *msg_flags);
107 VK_LAYER_EXPORT void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags);
108 VK_LAYER_EXPORT void PrintMessageType(VkFlags vk_flags, char *msg_flags);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113