diff --git a/CMakeLists.txt b/CMakeLists.txt index 47aa6b9a..91af0d88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,8 @@ else() endif() endif() +find_package(VulkanUtilityLibraries CONFIG REQUIRED) + option(BUILD_WERROR "Treat compiler warnings as errors") if (BUILD_WERROR) add_compile_options("$,/WX,-Werror>") diff --git a/layers/CMakeLists.txt b/layers/CMakeLists.txt index e28198d0..4f2c202c 100644 --- a/layers/CMakeLists.txt +++ b/layers/CMakeLists.txt @@ -47,7 +47,7 @@ endif() foreach(extension_layer ${EXTENSION_LAYERS}) target_include_directories(${extension_layer} PRIVATE .) - target_link_libraries(${extension_layer} PRIVATE VkExtLayer_utils) + target_link_libraries(${extension_layer} PRIVATE VkExtLayer_utils Vulkan::LayerSettings) if(MSVC) target_link_options(${extension_layer} PRIVATE /DEF:${CMAKE_CURRENT_SOURCE_DIR}/${extension_layer}.def) diff --git a/layers/VkLayer_khronos_synchronization2.def b/layers/VkLayer_khronos_synchronization2.def index 5359f0a8..895cccc6 100644 --- a/layers/VkLayer_khronos_synchronization2.def +++ b/layers/VkLayer_khronos_synchronization2.def @@ -1,9 +1,9 @@ ;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; -; Copyright (c) 2015-2021 The Khronos Group Inc. -; Copyright (c) 2015-2021 Valve Corporation -; Copyright (c) 2015-2021 LunarG, Inc. +; Copyright (c) 2015-2023 The Khronos Group Inc. +; Copyright (c) 2015-2023 Valve Corporation +; Copyright (c) 2015-2023 LunarG, Inc. ; Copyright (c) 2020 Intel Corporation ; ; Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/layers/VkLayer_khronos_timeline_semaphore.def b/layers/VkLayer_khronos_timeline_semaphore.def index fa861e82..5296405c 100644 --- a/layers/VkLayer_khronos_timeline_semaphore.def +++ b/layers/VkLayer_khronos_timeline_semaphore.def @@ -1,9 +1,9 @@ ;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; -; Copyright (c) 2015-2019, 2021 The Khronos Group Inc. -; Copyright (c) 2015-2019, 2021 Valve Corporation -; Copyright (c) 2015-2019, 2021 LunarG, Inc. +; Copyright (c) 2015-2023 The Khronos Group Inc. +; Copyright (c) 2015-2023 Valve Corporation +; Copyright (c) 2015-2023 LunarG, Inc. ; Copyright (c) 2020 Intel Corporation ; ; Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/layers/decompression/decompression.cpp b/layers/decompression/decompression.cpp index 8822df75..b58cdcd6 100755 --- a/layers/decompression/decompression.cpp +++ b/layers/decompression/decompression.cpp @@ -28,9 +28,9 @@ static bool logging_enabled = false; } #include +#include #include "allocator.h" #include "log.h" -#include "vk_layer_config.h" #include "vk_safe_struct.h" #include "vk_util.h" #include "decompression.h" @@ -115,6 +115,10 @@ static const ByteCode kIndirectGInflateBytecode[] = { {(const uint8_t*)kIndirectGInflate64_HAVE_INT16_HAVE_INT64, sizeof(kIndirectGInflate64_HAVE_INT16_HAVE_INT64)}, }; +#define kLayerSettingsForceEnable "force_device" +#define kLayerSettingsCustomSTypeInfo "custom_stype_list" +#define kLayerSettingsLogging "logging" + // required by vk_safe_struct std::vector> custom_stype_info{}; @@ -130,65 +134,9 @@ static const VkLayerProperties kGlobalLayer = { static const VkExtensionProperties kDeviceExtension = {VK_NV_MEMORY_DECOMPRESSION_EXTENSION_NAME, VK_NV_MEMORY_DECOMPRESSION_SPEC_VERSION}; -static const char* const kEnvarForceEnable = -#if defined(__ANDROID__) - "debug.vulkan.memory_decompression.force_enable"; -#else - "VK_MEMORY_DECOMPRESSION_FORCE_ENABLE"; -#endif -static const char* const kLayerSettingsForceEnable = "khronos_memory_decompression.force_enable"; - -static const char* const kEnvarLogging = -#if defined(__ANDROID__) - "debug.vulkan.memory_decompression.logging"; -#else - "VK_MEMORY_DECOMPRESSION_LOGGING"; -#endif -static const char* const kLayerSettingsLogging = "khronos_memory_decompression.logging"; - static vl_concurrent_unordered_map> instance_data_map; static vl_concurrent_unordered_map> device_data_map; -static void string_tolower(std::string& s) { - for (auto& c : s) { - c = tolower(c); - } -} - -static bool GetForceEnable() { - bool result = false; - std::string setting = GetEnvironment(kEnvarForceEnable); - if (setting.empty()) { - setting = GetLayerOption(kLayerSettingsForceEnable); - } - if (!setting.empty()) { - string_tolower(setting); - if (setting == "true") { - result = true; - } else { - result = std::atoi(setting.c_str()) != 0; - } - } - return result; -} - -static bool GetLoggingEnabled() { - bool result = false; - std::string setting = GetEnvironment(kEnvarLogging); - if (setting.empty()) { - setting = GetLayerOption(kLayerSettingsLogging); - } - if (!setting.empty()) { - string_tolower(setting); - if (setting == "true") { - result = true; - } else { - result = std::atoi(setting.c_str()) != 0; - } - } - return result; -} - uintptr_t DispatchKey(const void* object) { auto tmp = reinterpret_cast(object); return reinterpret_cast(*tmp); @@ -274,7 +222,7 @@ VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalD #define INIT_HOOK(_vt, _inst, fn) _vt.fn = reinterpret_cast(vtable.GetInstanceProcAddr(_inst, "vk" #fn)) InstanceData::InstanceData(VkInstance inst, PFN_vkGetInstanceProcAddr gpa, const VkAllocationCallbacks* alloc) - : instance(inst), api_version(0), force_enable(false), allocator(alloc) { + : instance(inst), api_version(0), allocator(alloc) { vtable.GetInstanceProcAddr = gpa; INIT_HOOK(vtable, instance, CreateInstance); INIT_HOOK(vtable, instance, DestroyInstance); @@ -297,18 +245,25 @@ static VkLayerInstanceCreateInfo* GetChainInfo(const VkInstanceCreateInfo* pCrea return chain_info; } -// Get all elements from a vkEnumerate*() lambda into a std::vector. -template -VkResult EnumerateAll(std::vector* vect, std::function func) { - VkResult result = VK_INCOMPLETE; - do { - uint32_t count = 0; - result = func(&count, nullptr); - ASSERT(result == VK_SUCCESS); - vect->resize(count); - result = func(&count, vect->data()); - } while (result == VK_INCOMPLETE); - return result; +void InitLayerSettings(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, LayerSettings* layer_settings) { + assert(layer_settings != nullptr); + + VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE; + vlCreateLayerSettingSet(kGlobalLayer.layerName, vlFindLayerSettingsCreateInfo(pCreateInfo), pAllocator, nullptr, &layerSettingSet); + + if (vlHasLayerSetting(layerSettingSet, kLayerSettingsForceEnable)) { + vlGetLayerSettingValue(layerSettingSet, kLayerSettingsForceEnable, layer_settings->force_enable); + } + + if (vlHasLayerSetting(layerSettingSet, kLayerSettingsLogging)) { + vlGetLayerSettingValue(layerSettingSet, kLayerSettingsLogging, layer_settings->logging); + } + + if (vlHasLayerSetting(layerSettingSet, kLayerSettingsCustomSTypeInfo)) { + vlGetLayerSettingValues(layerSettingSet, kLayerSettingsCustomSTypeInfo, custom_stype_info); + } + + vlDestroyLayerSettingSet(layerSettingSet, pAllocator); } VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, @@ -322,8 +277,6 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreat return VK_ERROR_INITIALIZATION_FAILED; } - logging_enabled = GetLoggingEnabled(); - // Advance the link info for the next element on the chain chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; @@ -337,8 +290,10 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreat instance_data_map.insert(DispatchKey(*pInstance), instance_data); - instance_data->force_enable = GetForceEnable(); instance_data->api_version = pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : 0; + + InitLayerSettings(pCreateInfo, pAllocator, &instance_data->layer_settings); + logging_enabled = instance_data->layer_settings.logging; } catch (const std::bad_alloc&) { auto destroy_instance = reinterpret_cast(gpa(NULL, "vkDestroyInstance")); destroy_instance(*pInstance, pAllocator); @@ -749,7 +704,7 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, con PRINT("Memory decompression feature not available in the driver, enabling decompression layer.\n"); enable_layer = true; } else { - if (instance_data->force_enable) { + if (instance_data->layer_settings.force_enable) { PRINT("Memory decompression feature available in the driver, but force enabling decompression layer.\n"); enable_layer = true; } else { diff --git a/layers/decompression/decompression.h b/layers/decompression/decompression.h index 9947c174..4fd02c3e 100755 --- a/layers/decompression/decompression.h +++ b/layers/decompression/decompression.h @@ -36,6 +36,11 @@ enum class SynchronizationScope { kFirst, kSecond }; struct DeviceData; struct DeviceFeatures; +struct LayerSettings { + bool force_enable{false}; + bool logging{false}; +}; + template using CmdVector = std::vector>; @@ -74,7 +79,7 @@ struct InstanceData { VkInstance instance; uint32_t api_version; - bool force_enable; + LayerSettings layer_settings; const VkAllocationCallbacks* allocator; struct InstanceDispatchTable { DECLARE_HOOK(GetInstanceProcAddr); diff --git a/layers/shader_object.cpp b/layers/shader_object.cpp index a916a41a..a75eb16c 100644 --- a/layers/shader_object.cpp +++ b/layers/shader_object.cpp @@ -32,11 +32,14 @@ #include #include +#include #include "log.h" #include "vk_safe_struct.h" #include "vk_api_hash.h" -#include "vk_layer_config.h" + +#define kLayerSettingsForceEnable "force_enable" +#define kLayerSettingsCustomSTypeInfo "custom_stype_list" // Required by vk_safe_struct std::vector> custom_stype_info{}; @@ -80,37 +83,6 @@ namespace shader_object { static const char* kLayerName = "VK_LAYER_KHRONOS_shader_object"; static const VkExtensionProperties kExtensionProperties = {VK_EXT_SHADER_OBJECT_EXTENSION_NAME, VK_EXT_SHADER_OBJECT_SPEC_VERSION}; -static const char* const kEnvarForceEnable = -#if defined(__ANDROID__) - "debug.vulkan.shader_object.force_enable"; -#else - "VK_SHADER_OBJECT_FORCE_ENABLE"; -#endif -static const char* const kLayerSettingsForceEnable = "khronos_shader_object.force_enable"; - -static void string_tolower(std::string &s) { - for (auto& c: s) { - c = tolower(c); - } -} - -static bool GetForceEnable() { - bool result = false; - std::string setting = GetEnvironment(kEnvarForceEnable); - if (setting.empty()) { - setting = GetLayerOption(kLayerSettingsForceEnable); - } - if (!setting.empty()) { - string_tolower(setting); - if (setting == "true") { - result = true; - } else { - result = std::atoi(setting.c_str()) != 0; - } - } - return result; -} - class AlignedMemory { public: AlignedMemory() : size_(0), max_alignment_(1), memory_write_ptr_(nullptr) {} @@ -1219,11 +1191,16 @@ class CommandBufferData { FullDrawStateData* draw_state_data_; }; +struct LayerSettings { + bool force_enable{false}; +}; + struct InstanceData { LayerDispatchInstance vtable; VkInstance instance; VkPhysicalDevice* physical_devices; uint32_t physical_device_count; + LayerSettings layer_settings; }; struct PhysicalDeviceData { @@ -2610,6 +2587,24 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance i static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char* pName); +void InitLayerSettings(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, LayerSettings* layer_settings) { + assert(layer_settings != nullptr); + + VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE; + const VkLayerSettingsCreateInfoEXT *pLayerSettingsCreateInfo = vlFindLayerSettingsCreateInfo(pCreateInfo); + vlCreateLayerSettingSet(kLayerName, pLayerSettingsCreateInfo, pAllocator, nullptr, &layerSettingSet); + + if (vlHasLayerSetting(layerSettingSet, kLayerSettingsForceEnable)) { + vlGetLayerSettingValue(layerSettingSet, kLayerSettingsForceEnable, layer_settings->force_enable); + } + + if (vlHasLayerSetting(layerSettingSet, kLayerSettingsCustomSTypeInfo)) { + vlGetLayerSettingValues(layerSettingSet, kLayerSettingsCustomSTypeInfo, custom_stype_info); + } + + vlDestroyLayerSettingSet(layerSettingSet, pAllocator); +} + static VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) { auto allocator = pAllocator ? *pAllocator : kDefaultAllocator; @@ -2653,6 +2648,8 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* instance_data->physical_device_count = physical_device_count; instance_data->vtable.Initialize(*pInstance, fpGetInstanceProcAddr); + InitLayerSettings(pCreateInfo, pAllocator, &instance_data->layer_settings); + result = fpEnumeratePhysicalDevices(*pInstance, &instance_data->physical_device_count, instance_data->physical_devices); ASSERT(result == VK_SUCCESS); @@ -2917,7 +2914,7 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevi // only enable the layer if the application asked for the extension and feature AND the driver does not have a native // implementation (unless if the user specified to ignore the native implementation via environment variable) bool enable_layer = shader_object_feature_requested && shader_object_extension_requested; - bool ignore_native_implementation = GetForceEnable(); + bool ignore_native_implementation = instance_data->layer_settings.force_enable; if (ignore_native_implementation) { DEBUG_LOG("ignoring native driver implementation of shader object\n"); } diff --git a/layers/synchronization2.cpp b/layers/synchronization2.cpp index a58a42a3..682ada4f 100644 --- a/layers/synchronization2.cpp +++ b/layers/synchronization2.cpp @@ -18,6 +18,7 @@ * Author: Jeremy Gebben */ #include +#include #include #include #include @@ -29,10 +30,12 @@ #include "allocator.h" #include "log.h" #include "vk_format_utils.h" -#include "vk_layer_config.h" #include "vk_safe_struct.h" #include "vk_util.h" +#define kLayerSettingsForceEnable "force_device" +#define kLayerSettingsCustomSTypeInfo "custom_stype_list" + // required by vk_safe_struct std::vector> custom_stype_info{}; @@ -48,138 +51,9 @@ static const VkLayerProperties kGlobalLayer = { static const VkExtensionProperties kDeviceExtension = {VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, VK_KHR_SYNCHRONIZATION_2_SPEC_VERSION}; -static const char* const kEnvarForceEnableRemoved = -#if defined(__ANDROID__) - "debug.vulkan.sync2.force_enable"; -#else - "VK_SYNC2_FORCE_ENABLE"; -#endif -static const char* const kEnvarForceEnable = -#if defined(__ANDROID__) - "debug.vulkan.synchronization2.force_enable"; -#else - "VK_SYNCHRONIZATION2_FORCE_ENABLE"; -#endif -static const char* const kLayerSettingsForceEnable = "khronos_synchronization2.force_enable"; - -// TODO: should we try to use the same fields as ValidationLayers, so that list only needs -// to be defined once? -static const char* const kEnvarCustomStypeListRemoved = -#if defined(__ANDROID__) - "debug.vulkan.sync2.custom_stype_list"; -#else - "VK_LAYER_SYNC2_CUSTOM_STYPE_LIST"; -#endif -static const char* const kEnvarCustomStypeList = -#if defined(__ANDROID__) - "debug.vulkan.synchronization2.custom_stype_list"; -#else - "VK_SYNCHRONIZATION2_CUSTOM_STYPE_LIST"; -#endif -static const char* const kLayerSettingsCustomStypeList = "khronos_synchronization2.custom_stype_list"; - static vl_concurrent_unordered_map> instance_data_map; static vl_concurrent_unordered_map> device_data_map; -static void string_tolower(std::string &s) { - for (auto& c: s) { - c = tolower(c); - } -} - -static bool GetForceEnable() { - bool result = false; - std::string setting_removed = GetEnvironment(kEnvarForceEnableRemoved); - if (!setting_removed.empty()) { - LOG("%s was renamed into %s, please update your developer environment.\n", kEnvarForceEnableRemoved, kEnvarForceEnable); - } - - std::string setting = GetEnvironment(kEnvarForceEnable); - if (setting.empty()) { - setting = GetLayerOption(kLayerSettingsForceEnable); - } - if (!setting.empty()) { - string_tolower(setting); - if (setting == "true") { - result = true; - } else { - result = std::atoi(setting.c_str()) != 0; - } - } - return result; -} - -static std::string GetNextToken(std::string *token_list, const std::string &delimiter, size_t *pos) { - std::string token; - *pos = token_list->find(delimiter); - if (*pos != std::string::npos) { - token = token_list->substr(0, *pos); - } else { - *pos = token_list->length() - delimiter.length(); - token = *token_list; - } - token_list->erase(0, *pos + delimiter.length()); - - // Remove quotes from quoted strings - if ((token.length() > 0) && (token[0] == '\"')) { - token.erase(token.begin()); - if ((token.length() > 0) && (token[token.length() - 1] == '\"')) { - token.erase(--token.end()); - } - } - return token; -} - -static uint32_t TokenToUint(const std::string &token) { - uint32_t int_id = 0; - if ((token.find("0x") == 0) || token.find("0X") == 0) { // Handle hex format - int_id = static_cast(std::strtoul(token.c_str(), nullptr, 16)); - } else { - int_id = static_cast(std::strtoul(token.c_str(), nullptr, 10)); // Decimal format - } - return int_id; -} - -static void SetCustomStypeInfo(std::string raw_id_list, const std::string &delimiter) { - size_t pos = 0; - std::string token; - // List format is a list of integer pairs - while (raw_id_list.length() != 0) { - token = GetNextToken(&raw_id_list, delimiter, &pos); - uint32_t stype_id = TokenToUint(token); - token = GetNextToken(&raw_id_list, delimiter, &pos); - uint32_t struct_size_in_bytes = TokenToUint(token); - if ((stype_id != 0) && (struct_size_in_bytes != 0)) { - bool found = false; - // Prevent duplicate entries - for (auto item : custom_stype_info) { - if (item.first == stype_id) { - found = true; - break; - } - } - if (!found) custom_stype_info.push_back(std::make_pair(stype_id, struct_size_in_bytes)); - } - } -} - -static void SetupCustomStypes() { - std::string setting_removed = GetEnvironment(kEnvarCustomStypeListRemoved); - if (!setting_removed.empty()) { - LOG("%s was renamed into %s, please update your developer environment.\n", kEnvarCustomStypeListRemoved, - kEnvarCustomStypeList); - } - - const std::string kEnvDelim = -#if defined(_WIN32) - ";"; -#else - ":"; -#endif - SetCustomStypeInfo(GetLayerOption(kLayerSettingsCustomStypeList), ","); - SetCustomStypeInfo(GetEnvironment(kEnvarCustomStypeList), kEnvDelim); -} - uintptr_t DispatchKey(const void* object) { auto tmp = reinterpret_cast(object); return reinterpret_cast(*tmp); @@ -303,18 +177,21 @@ static VkLayerInstanceCreateInfo* GetChainInfo(const VkInstanceCreateInfo* pCrea return chain_info; } -// Get all elements from a vkEnumerate*() lambda into a std::vector. -template -VkResult EnumerateAll(std::vector* vect, std::function func) { - VkResult result = VK_INCOMPLETE; - do { - uint32_t count = 0; - result = func(&count, nullptr); - ASSERT(result == VK_SUCCESS); - vect->resize(count); - result = func(&count, vect->data()); - } while (result == VK_INCOMPLETE); - return result; +void InitLayerSettings(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, LayerSettings* layer_settings) { + assert(layer_settings != nullptr); + + VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE; + vlCreateLayerSettingSet(kGlobalLayer.layerName, vlFindLayerSettingsCreateInfo(pCreateInfo), pAllocator, nullptr, &layerSettingSet); + + if (vlHasLayerSetting(layerSettingSet, kLayerSettingsForceEnable)) { + vlGetLayerSettingValue(layerSettingSet, kLayerSettingsForceEnable, layer_settings->force_enable); + } + + if (vlHasLayerSetting(layerSettingSet, kLayerSettingsCustomSTypeInfo)) { + vlGetLayerSettingValues(layerSettingSet, kLayerSettingsCustomSTypeInfo, custom_stype_info); + } + + vlDestroyLayerSettingSet(layerSettingSet, pAllocator); } VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) { @@ -339,10 +216,10 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreat pAllocator ? pAllocator : &extension_layer::kDefaultAllocator); instance_data_map.insert(DispatchKey(*pInstance), instance_data); - - instance_data->force_enable = GetForceEnable(); + instance_data->api_version = pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : 0; - SetupCustomStypes(); + + InitLayerSettings(pCreateInfo, pAllocator, &instance_data->layer_settings); } catch (const std::bad_alloc&) { auto destroy_instance = reinterpret_cast(gpa(NULL, "vkDestroyInstance")); destroy_instance(*pInstance, pAllocator); @@ -543,7 +420,7 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, con chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; try { - bool enable_layer = (features.sync2 && (!pdd->lower_has_sync2 || instance_data->force_enable)); + bool enable_layer = (features.sync2 && (!pdd->lower_has_sync2 || instance_data->layer_settings.force_enable)); // Filter out our extension name and feature struct, in a copy of the create info. // Only enable device hooks if synchronization2 extension is enabled AND // the physical device doesn't support it already or we are force enabled. diff --git a/layers/synchronization2.h b/layers/synchronization2.h index e5cf304b..2a95a60a 100644 --- a/layers/synchronization2.h +++ b/layers/synchronization2.h @@ -36,6 +36,10 @@ enum ImageAspect { kColorOnly, kDepthAndStencil, kDepthOnly, kStencilOnly }; struct DeviceData; struct DeviceFeatures; +struct LayerSettings { + bool force_enable{false}; +}; + // helper struct definitions to convert synchronization2 barriers struct BufferMemoryBarrier : public VkBufferMemoryBarrier { @@ -156,7 +160,7 @@ struct InstanceData { VkInstance instance; uint32_t api_version; - bool force_enable; + LayerSettings layer_settings; const VkAllocationCallbacks* allocator; struct InstanceDispatchTable { DECLARE_HOOK(GetInstanceProcAddr); diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index fc23f4e7..519b4e89 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -119,6 +119,9 @@ endif() if (GLSLANG_INSTALL_DIR) list(APPEND CMAKE_PREFIX_PATH ${GLSLANG_INSTALL_DIR}) endif() +if (VULKAN_UTILITY_LIBRARIES_INSTALL_DIR) + list(APPEND CMAKE_PREFIX_PATH ${VULKAN_UTILITY_LIBRARIES_INSTALL_DIR}) +endif() if (CMAKE_CROSSCOMPILING) set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH} PARENT_SCOPE) diff --git a/scripts/known_good.json b/scripts/known_good.json index dd6e9f7f..56d8d5d7 100755 --- a/scripts/known_good.json +++ b/scripts/known_good.json @@ -8,6 +8,20 @@ "install_dir": "Vulkan-Headers/build/install", "commit": "v1.3.262" }, + { + "name": "Vulkan-Utility-Libraries", + "url": "https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git", + "sub_dir": "Vulkan-Utility-Libraries", + "build_dir": "Vulkan-Utility-Libraries/build", + "install_dir": "Vulkan-Utility-Libraries/build/install", + "commit": "v1.3.262", + "deps": [ + { + "var_name": "VULKAN_HEADERS_INSTALL_DIR", + "repo_name": "Vulkan-Headers" + } + ] + }, { "name": "glslang", "url": "https://github.com/KhronosGroup/glslang.git", @@ -66,6 +80,7 @@ ], "install_names": { "Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR", + "Vulkan-Utility-Libraries": "VULKAN_UTILITY_LIBRARIES_INSTALL_DIR", "glslang": "GLSLANG_INSTALL_DIR", "SPIRV-Headers": "SPIRV_HEADERS_INSTALL_DIR", "SPIRV-Tools": "SPIRV_TOOLS_INSTALL_DIR", diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 416426d3..9323cb5c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -59,7 +59,7 @@ target_sources(vk_extension_layer_tests PRIVATE set_target_properties(vk_extension_layer_tests PROPERTIES VS_DEBUGGER_ENVIRONMENT "VK_LAYER_PATH=$") -add_dependencies(vk_extension_layer_tests VkLayer_khronos_synchronization2 VkLayer_khronos_memory_decompression) +add_dependencies(vk_extension_layer_tests VkLayer_khronos_synchronization2 VkLayer_khronos_shader_object VkLayer_khronos_memory_decompression) target_include_directories(vk_extension_layer_tests PRIVATE .) @@ -90,6 +90,7 @@ find_package(glslang REQUIRED CONFIG QUIET) target_link_libraries(vk_extension_layer_tests PRIVATE VkExtLayer_utils + Vulkan::LayerSettings Vulkan::Headers GTest::gtest GTest::gtest_main diff --git a/tests/decompression_tests.cpp b/tests/decompression_tests.cpp index fd66da6e..1df02b3d 100644 --- a/tests/decompression_tests.cpp +++ b/tests/decompression_tests.cpp @@ -24,12 +24,20 @@ #include "decompression_data.h" void DecompressionTest::SetUp() { - SetEnvironment("VK_MEMORY_DECOMPRESSION_FORCE_ENABLE", "1"); + VkBool32 force_enable = VK_TRUE; + + VkLayerSettingEXT settings[] = { + {"VK_LAYER_KHRONOS_memory_decompression", "force_enable", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &force_enable}}; + + VkLayerSettingsCreateInfoEXT layer_settings_create_info{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT, nullptr, + static_cast(std::size(settings)), &settings[0]}; + VkExtensionLayerTest::SetUp(); SetTargetApiVersion(VK_API_VERSION_1_2); VkExtensionLayerTest::AddSurfaceInstanceExtension(); instance_layers_.push_back("VK_LAYER_KHRONOS_memory_decompression"); - ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor, &layer_settings_create_info)); VkExtensionLayerTest::AddSwapchainDeviceExtension(); } diff --git a/tests/extension_layer_tests.cpp b/tests/extension_layer_tests.cpp index b6d2209f..5b9666da 100755 --- a/tests/extension_layer_tests.cpp +++ b/tests/extension_layer_tests.cpp @@ -675,7 +675,7 @@ int main(int argc, char **argv) { #endif // Set VK_LAYER_PATH so that the loader can find the layers - SetEnvironment("VK_LAYER_PATH", LAYER_BUILD_LOCATION); + VkTestFramework::setEnvironmentSetting("VK_LAYER_PATH", LAYER_BUILD_LOCATION); ::testing::InitGoogleTest(&argc, argv); VkTestFramework::InitArgs(&argc, argv); diff --git a/tests/extension_layer_tests.h b/tests/extension_layer_tests.h index 8e95f684..e5b0099b 100755 --- a/tests/extension_layer_tests.h +++ b/tests/extension_layer_tests.h @@ -28,6 +28,7 @@ #define VKLAYERTEST_H #include +#include #if defined(ANDROID) #include diff --git a/tests/shader_object_tests.cpp b/tests/shader_object_tests.cpp index 695c663b..33c9e56d 100644 --- a/tests/shader_object_tests.cpp +++ b/tests/shader_object_tests.cpp @@ -20,17 +20,23 @@ #include "extension_layer_tests.h" #include "shader_object_tests.h" -#include "vk_layer_config.h" void ShaderObjectTest::SetUp() { - SetEnvironment("VK_SHADER_OBJECT_FORCE_ENABLE", "1"); - const std::string layer_path = std::string(SHADER_OBJECT_BINARY_PATH); - SetEnvironment("VK_LAYER_PATH", layer_path.c_str()); + VkBool32 force_enable = VK_TRUE; + + VkLayerSettingEXT settings[] = { + {"VK_LAYER_KHRONOS_shader_object", "force_enable", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &force_enable} + }; + + VkLayerSettingsCreateInfoEXT layer_settings_create_info{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT, nullptr, + static_cast(std::size(settings)), &settings[0]}; + VkExtensionLayerTest::SetUp(); SetTargetApiVersion(VK_API_VERSION_1_1); VkExtensionLayerTest::AddSurfaceInstanceExtension(); instance_layers_.push_back("VK_LAYER_KHRONOS_shader_object"); - ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor, &layer_settings_create_info)); VkExtensionLayerTest::AddSwapchainDeviceExtension(); } diff --git a/tests/synchronization2_tests.cpp b/tests/synchronization2_tests.cpp index fafc5a56..10f1c624 100644 --- a/tests/synchronization2_tests.cpp +++ b/tests/synchronization2_tests.cpp @@ -28,15 +28,23 @@ #include "extension_layer_tests.h" #include "synchronization2_tests.h" -#include "vk_layer_config.h" void Sync2Test::SetUp() { - SetEnvironment("VK_SYNCHRONIZATION2_FORCE_ENABLE", "1"); + VkBool32 force_enable = VK_TRUE; + + VkLayerSettingEXT settings[] = { + {"VK_LAYER_KHRONOS_synchronization2", "force_enable", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &force_enable} + }; + + VkLayerSettingsCreateInfoEXT layer_settings_create_info{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT, nullptr, + static_cast(std::size(settings)), &settings[0]}; + VkExtensionLayerTest::SetUp(); SetTargetApiVersion(VK_API_VERSION_1_2); VkExtensionLayerTest::AddSurfaceInstanceExtension(); instance_layers_.push_back("VK_LAYER_KHRONOS_synchronization2"); - ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor, &layer_settings_create_info)); VkExtensionLayerTest::AddSwapchainDeviceExtension(); } diff --git a/tests/vkrenderframework.h b/tests/vkrenderframework.h index 2ba878e7..90a14d3a 100644 --- a/tests/vkrenderframework.h +++ b/tests/vkrenderframework.h @@ -39,8 +39,6 @@ #include #include -#include "vk_layer_config.h" - using vk_testing::MakeVkHandles; template @@ -124,7 +122,7 @@ class ErrorMonitor { // Helpers // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags - void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = kErrorBit); + void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT); void VerifyFound(); void VerifyNotFound(); diff --git a/tests/vktestframework.cpp b/tests/vktestframework.cpp index a9a65f6d..d61ffcef 100644 --- a/tests/vktestframework.cpp +++ b/tests/vktestframework.cpp @@ -114,6 +114,15 @@ VkTestFramework::VkTestFramework() : m_compile_options(0), m_num_shader_strings( VkTestFramework::~VkTestFramework() {} +// TODO: When the layer path issue is resolved with CI (set outside of the tests) remove this function +void VkTestFramework::setEnvironmentSetting(std::string setting, const char *val) { +#ifdef _WIN32 + _putenv_s(setting.c_str(), val); +#else + setenv(setting.c_str(), val, 1); +#endif +} + // Define all the static elements bool VkTestFramework::m_canonicalize_spv = false; bool VkTestFramework::m_strip_spv = false; diff --git a/tests/vktestframework.h b/tests/vktestframework.h index 5027dd22..d121690c 100644 --- a/tests/vktestframework.h +++ b/tests/vktestframework.h @@ -71,6 +71,8 @@ class VkTestFramework : public ::testing::Test { char **ReadFileData(const char *fileName); void FreeFileData(char **data); + static void setEnvironmentSetting(std::string setting, const char *val); + protected: VkTestFramework(); virtual ~VkTestFramework() = 0; diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 88cd44ef..2d251243 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -20,7 +20,6 @@ add_library(VkExtLayer_utils STATIC) target_sources(VkExtLayer_utils PRIVATE allocator.cpp vk_format_utils.cpp - vk_layer_config.cpp generated/vk_safe_struct.cpp generated/lvt_function_pointers.cpp ) diff --git a/utils/vk_layer_config.cpp b/utils/vk_layer_config.cpp deleted file mode 100644 index fbcde344..00000000 --- a/utils/vk_layer_config.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/************************************************************************** - * - * Copyright 2014-2020, 2022-2023 Valve Software - * Copyright 2015-2020, 2022-2023 Google Inc. - * Copyright 2019-2020, 2022-2023 LunarG, Inc. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Author: Jon Ashburn - * Author: Courtney Goeltzenleuchter - * Author: Tobin Ehlis - * Author: Mark Lobodzinski - **************************************************************************/ -#include "vk_layer_config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "vk_string_utils.h" - -#if defined(_WIN32) -#include -#include -#define GetCurrentDir _getcwd -#else -#include -#define GetCurrentDir getcwd -#endif - -class ConfigFile { - public: - ConfigFile(); - ~ConfigFile(){}; - - const char *GetOption(const std::string &option); - void SetOption(const std::string &option, const std::string &value); - std::string vk_layer_disables_env_var; - SettingsFileInfo settings_info{}; - - private: - bool file_is_parsed_; - std::map value_map_; - - std::string FindSettings(); - void ParseFile(const char *filename); -}; - -static ConfigFile layer_config; - -// On at least some platforms, environment functions are not reentrant. -// It is possible to run test cases concurrently in multiple threads, -// so guard the calls to these functions. -static std::mutex layer_env_mutex; - -std::string GetEnvironment(const char *variable) { - const std::lock_guard guard(layer_env_mutex); -#if !defined(__ANDROID__) && !defined(_WIN32) - const char *output = getenv(variable); - return output == NULL ? "" : output; -#elif defined(_WIN32) - int size = GetEnvironmentVariable(variable, NULL, 0); - if (size == 0) { - return ""; - } - char *buffer = new char[size]; - GetEnvironmentVariable(variable, buffer, size); - std::string output = buffer; - delete[] buffer; - return output; -#elif defined(__ANDROID__) - std::string command = "getprop " + std::string(variable); - FILE *pPipe = popen(command.c_str(), "r"); - if (pPipe != nullptr) { - char value[256]; - fgets(value, 256, pPipe); - pclose(pPipe); - - // Make sure its not an empty line - if (strcspn(value, "\r\n") == 0) { - return ""; - } else { - return std::string(value); - } - } else { - return ""; - } -#else - return ""; -#endif -} - -bool SetEnvironment(const char *name, const char *value) { - const std::lock_guard guard(layer_env_mutex); -#if !defined(__ANDROID__) && !defined(_WIN32) - // don't overwrite if the variable is already set. - return (setenv(name, value, 0) == 0) ? true : false; -#elif defined(_WIN32) - int size = GetEnvironmentVariable(name, NULL, 0); - // only overwrite if the variable isn't already set. - if (size == 0) { - return static_cast(SetEnvironmentVariable(name, value)); - } - return true; -#elif defined(__ANDROID__) - // TODO: unclear if this is possible on android - return false; -#else - return false; -#endif -} - -const char *GetLayerOption(const char *option) { return layer_config.GetOption(option); } - -const SettingsFileInfo *GetLayerSettingsFileInfo() { return &layer_config.settings_info; } - -// If option is NULL or stdout, return stdout, otherwise try to open option -// as a filename. If successful, return file handle, otherwise stdout -FILE *GetLayerLogOutput(const char *option, const char *layer_name) { - FILE *log_output = NULL; - if (!option || !strcmp("stdout", option)) { - log_output = stdout; - } else { - log_output = fopen(option, "w"); - if (log_output == NULL) { - if (option) { - std::cout << std::endl - << layer_name << " ERROR: Bad output filename specified: " << option << ". Writing to STDOUT instead" - << std::endl - << std::endl; - } - log_output = stdout; - } - } - return log_output; -} - -// Map option strings to flag enum values -VkFlags GetLayerOptionFlags(std::string option, std::unordered_map const &enum_data, - uint32_t option_default) { - VkDebugReportFlagsEXT flags = option_default; - std::string option_list = layer_config.GetOption(option.c_str()); - - while (option_list.length() != 0) { - // Find length of option string - std::size_t option_length = option_list.find(","); - if (option_length == option_list.npos) { - option_length = option_list.size(); - } - - // Get first option item in list - const std::string option_item = option_list.substr(0, option_length); - - auto enum_value = enum_data.find(option_item); - if (enum_value != enum_data.end()) { - flags |= enum_value->second; - } - - // Remove first option from option_list - option_list.erase(0, option_length); - // Remove possible comma separator - std::size_t char_position = option_list.find(","); - if (char_position == 0) { - option_list.erase(char_position, 1); - } - // Remove possible space - char_position = option_list.find(" "); - if (char_position == 0) { - option_list.erase(char_position, 1); - } - } - return flags; -} - -void SetLayerOption(const char *option, const char *value) { layer_config.SetOption(option, value); } - -// Constructor for ConfigFile. Initialize layers to log error messages to stdout by default. If a vk_layer_settings file is present, -// its settings will override the defaults. -ConfigFile::ConfigFile() : file_is_parsed_(false) { -} - -const char *ConfigFile::GetOption(const std::string &option) { - std::map::const_iterator it; - if (!file_is_parsed_) { - std::string settings_file = FindSettings(); - ParseFile(settings_file.c_str()); - } - - if ((it = value_map_.find(option)) == value_map_.end()) { - return ""; - } else { - return it->second.c_str(); - } -} - -void ConfigFile::SetOption(const std::string &option, const std::string &val) { - if (!file_is_parsed_) { - std::string settings_file = FindSettings(); - ParseFile(settings_file.c_str()); - } - - value_map_[option] = val; -} - -#if defined(WIN32) -// Check for admin rights -static inline bool IsHighIntegrity() { - HANDLE process_token; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_QUERY_SOURCE, &process_token)) { - // Maximum possible size of SID_AND_ATTRIBUTES is maximum size of a SID + size of attributes DWORD. - uint8_t mandatory_label_buffer[SECURITY_MAX_SID_SIZE + sizeof(DWORD)]; - DWORD buffer_size; - if (GetTokenInformation(process_token, TokenIntegrityLevel, mandatory_label_buffer, sizeof(mandatory_label_buffer), - &buffer_size) != 0) { - const TOKEN_MANDATORY_LABEL *mandatory_label = (const TOKEN_MANDATORY_LABEL *)mandatory_label_buffer; - const DWORD sub_authority_count = *GetSidSubAuthorityCount(mandatory_label->Label.Sid); - const DWORD integrity_level = *GetSidSubAuthority(mandatory_label->Label.Sid, sub_authority_count - 1); - - CloseHandle(process_token); - return integrity_level > SECURITY_MANDATORY_MEDIUM_RID; - } - - CloseHandle(process_token); - } - - return false; -} -#endif - -std::string ConfigFile::FindSettings() { - struct stat info; - -#if defined(WIN32) - // Look for VkConfig-specific settings location specified in the windows registry - HKEY key; - - const std::array hives = {DEFAULT_VK_REGISTRY_HIVE, SECONDARY_VK_REGISTRY_HIVE}; - const size_t hives_to_check_count = IsHighIntegrity() ? 1 : hives.size(); // Admin checks only the default hive - - for (size_t hive_index = 0; hive_index < hives_to_check_count; ++hive_index) { - LSTATUS err = RegOpenKeyEx(hives[hive_index], "Software\\Khronos\\Vulkan\\Settings", 0, KEY_READ, &key); - if (err == ERROR_SUCCESS) { - char name[2048]; - DWORD i = 0, name_size, type, value, value_size; - while (ERROR_SUCCESS == RegEnumValue(key, i++, name, &(name_size = sizeof(name)), nullptr, &type, - reinterpret_cast(&value), &(value_size = sizeof(value)))) { - // Check if the registry entry is a dword with a value of zero - if (type != REG_DWORD || value != 0) { - continue; - } - - // Check if this actually points to a file - if ((stat(name, &info) != 0) || !(info.st_mode & S_IFREG)) { - continue; - } - - // Use this file - RegCloseKey(key); - settings_info.source = kVkConfig; - settings_info.location = name; - return name; - } - - RegCloseKey(key); - } - } - -#else - // Look for VkConfig-specific settings location specified in a specific spot in the linux settings store - std::string search_path = GetEnvironment("XDG_DATA_HOME"); - if (search_path == "") { - search_path = GetEnvironment("HOME"); - if (search_path != "") { - search_path += "/.local/share"; - } - } - // Use the vk_layer_settings.txt file from here, if it is present - if (search_path != "") { - std::string home_file = search_path + "/vulkan/settings.d/vk_layer_settings.txt"; - if (stat(home_file.c_str(), &info) == 0) { - if (info.st_mode & S_IFREG) { - settings_info.source = kVkConfig; - settings_info.location = home_file; - return home_file; - } - } - } - -#endif - // Look for an enviornment variable override for the settings file location - std::string env_path = GetEnvironment("VK_LAYER_SETTINGS_PATH"); - - // If the path exists use it, else use vk_layer_settings - if (stat(env_path.c_str(), &info) == 0) { - // If this is a directory, append settings file name - if (info.st_mode & S_IFDIR) { - env_path.append("/vk_layer_settings.txt"); - } - settings_info.source = kEnvVar; - settings_info.location = env_path; - return env_path; - } - - // Default -- use the current working directory for the settings file location - settings_info.source = kLocal; - char buff[512]; - auto buf_ptr = GetCurrentDir(buff, 512); - if (buf_ptr) { - settings_info.location = buf_ptr; - settings_info.location.append("\\vk_layer_settings.txt"); - } - return "vk_layer_settings.txt"; -} - -void ConfigFile::ParseFile(const char *filename) { - file_is_parsed_ = true; - - // Extract option = value pairs from a file - std::ifstream file(filename); - if (file.good()) { - settings_info.file_found = true; - for (std::string line; std::getline(file, line);) { - // discard comments, which start with '#' - const auto comments_pos = line.find_first_of('#'); - if (comments_pos != std::string::npos) line.erase(comments_pos); - - const auto value_pos = line.find_first_of('='); - if (value_pos != std::string::npos) { - const std::string option = string_trim(line.substr(0, value_pos)); - const std::string value = string_trim(line.substr(value_pos + 1)); - value_map_[option] = value; - } - } - } -} - -void PrintMessageFlags(VkFlags vk_flags, char *msg_flags) { - bool separator = false; - - msg_flags[0] = 0; - if (vk_flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) { - strcat(msg_flags, "DEBUG"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "INFO"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "WARN"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "PERF"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "ERROR"); - } -} - -void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags) { - bool separator = false; - - msg_flags[0] = 0; - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) { - strcat(msg_flags, "VERBOSE"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "INFO"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "WARN"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "ERROR"); - } -} - -void PrintMessageType(VkFlags vk_flags, char *msg_flags) { - bool separator = false; - - msg_flags[0] = 0; - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) { - strcat(msg_flags, "GEN"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "SPEC"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "PERF"); - } -} diff --git a/utils/vk_layer_config.h b/utils/vk_layer_config.h deleted file mode 100644 index 4fc99c81..00000000 --- a/utils/vk_layer_config.h +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright (c) 2015-2020,2023 The Khronos Group Inc. - * Copyright (c) 2015-2020,2023 Valve Corporation - * Copyright (c) 2015-2020,2023 LunarG, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Author: Jon Ashburn - * Author: Mark Lobodzinski - **************************************************************************/ -#pragma once - -#include -#include -#include - -#include "vulkan/vk_layer.h" -#include "vulkan/vulkan.h" - -#if defined(WIN32) -#define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE -#define DEFAULT_VK_REGISTRY_HIVE_STR "HKEY_LOCAL_MACHINE" -#define SECONDARY_VK_REGISTRY_HIVE HKEY_CURRENT_USER -#define SECONDARY_VK_REGISTRY_HIVE_STR "HKEY_CURRENT_USER" -#endif - -typedef enum { - kVkConfig, - kEnvVar, - kLocal, -} SettingsFileSource; - -typedef struct SettingsFileInfo { - bool file_found = false; - std::string location{}; - SettingsFileSource source = kLocal; -} SettingsFileInfo; - -typedef enum { - kInformationBit = 0x00000001, - kWarningBit = 0x00000002, - kPerformanceWarningBit = 0x00000004, - kErrorBit = 0x00000008, - kDebugBit = 0x00000010, -} LogMessageTypeBits; -typedef VkFlags LogMessageTypeFlags; - -// Definitions for Debug Actions -typedef enum VkLayerDbgActionBits { - VK_DBG_LAYER_ACTION_IGNORE = 0x00000000, - VK_DBG_LAYER_ACTION_CALLBACK = 0x00000001, - VK_DBG_LAYER_ACTION_LOG_MSG = 0x00000002, - VK_DBG_LAYER_ACTION_BREAK = 0x00000004, - VK_DBG_LAYER_ACTION_DEBUG_OUTPUT = 0x00000008, - VK_DBG_LAYER_ACTION_DEFAULT = 0x40000000, -} VkLayerDbgActionBits; -typedef VkFlags VkLayerDbgActionFlags; - -const std::unordered_map debug_actions_option_definitions = { - {std::string("VK_DBG_LAYER_ACTION_IGNORE"), VK_DBG_LAYER_ACTION_IGNORE}, - {std::string("VK_DBG_LAYER_ACTION_CALLBACK"), VK_DBG_LAYER_ACTION_CALLBACK}, - {std::string("VK_DBG_LAYER_ACTION_LOG_MSG"), VK_DBG_LAYER_ACTION_LOG_MSG}, - {std::string("VK_DBG_LAYER_ACTION_BREAK"), VK_DBG_LAYER_ACTION_BREAK}, -#if defined(WIN32) - {std::string("VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"), VK_DBG_LAYER_ACTION_DEBUG_OUTPUT}, -#endif - {std::string("VK_DBG_LAYER_ACTION_DEFAULT"), VK_DBG_LAYER_ACTION_DEFAULT}}; - -const std::unordered_map report_flags_option_definitions = { - {std::string("warn"), VK_DEBUG_REPORT_WARNING_BIT_EXT}, - {std::string("info"), VK_DEBUG_REPORT_INFORMATION_BIT_EXT}, - {std::string("perf"), VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT}, - {std::string("error"), VK_DEBUG_REPORT_ERROR_BIT_EXT}, - {std::string("debug"), VK_DEBUG_REPORT_DEBUG_BIT_EXT}}; - -const std::unordered_map log_msg_type_option_definitions = {{std::string("warn"), kWarningBit}, - {std::string("info"), kInformationBit}, - {std::string("perf"), kPerformanceWarningBit}, - {std::string("error"), kErrorBit}, - {std::string("debug"), kDebugBit}}; - -const char *GetLayerOption(const char *option); -void SetLayerOption(const char *option, const char *val); - -// Get an environment variable, returns "" if the variable is unset. -std::string GetEnvironment(const char *name); - -// Set an environment variable, if it is not already set -bool SetEnvironment(const char *name, const char *value); - -const SettingsFileInfo *GetLayerSettingsFileInfo(); - -FILE *GetLayerLogOutput(const char *option, const char *layer_name); -VkFlags GetLayerOptionFlags(std::string option, std::unordered_map const &enum_data, uint32_t option_default); - -void PrintMessageFlags(VkFlags vk_flags, char *msg_flags); -void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags); -void PrintMessageType(VkFlags vk_flags, char *msg_flags);