Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layers: Move all settings to VK_EXT_layer_settings #8549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ vvl_sources = [
"layers/error_message/logging.cpp",
"layers/error_message/logging.h",
"layers/error_message/record_object.h",
"layers/error_message/log_message_type.h",
"layers/external/inplace_function.h",
"layers/external/vma/vk_mem_alloc.h",
"layers/external/vma/vma.cpp",
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ For those who don't want to build from source, there are few ways to get working
- For Android, each SDK tag will have binaries to download (example: [vulkan-sdk-1.3.280.0 tag](https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/tag/vulkan-sdk-1.3.280.0))
- Every change applied to the main branch runs through GitHub action and will [produce artifacts](https://github.com/KhronosGroup/Vulkan-ValidationLayers/actions?query=branch%3Amain) of the latest commit.

## Adjusting settings

See [settings documentation](./docs/settings.md).

## Community Assistance

Before submitting an issue to the validation layers or reaching out to the developers it may be prudent to reach out to the community first.
Expand Down
78 changes: 78 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Settings

There are many settings that can be set for Validation layers. This is a brief overview of how to use them.

There are 4 ways to configure the settings: `vkconfig`, `application defined`, `vk_layer_settings.txt`, `environment variables`

## VkConfig

We suggest people to use [VkConfig](https://www.lunarg.com/introducing-the-new-vulkan-configurator-vkconfig/).
spencer-lunarg marked this conversation as resolved.
Show resolved Hide resolved

The GUI comes with the SDK, and takes the `VkLayer_khronos_validation.json` file and does **everything** for you!

## Application Defined

The application can now use the `VK_EXT_layer_settings` extension to do everything at `vkCreateInstance` time. (Don't worry, we implement the extension, so it will be supported 100% of the time!).

```c++
// Example how to turn on verbose mode for DebugPrintf
const VkBool32 verbose_value = true;
const VkLayerSettingEXT layer_setting = {"VK_LAYER_KHRONOS_validation", "printf_verbose", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &verbose_value};
VkLayerSettingsCreateInfoEXT layer_settings_create_info = {VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT, nullptr, 1, &layer_setting};

VkInstanceCreateInfo instance_ci = GetYourCreateInfo();
instance_ci.pNext = &layer_settings_create_info;
```

## vk_layer_settings.txt

There is info [elsewhere](https://vulkan.lunarg.com/doc/view/latest/windows/layer_configuration.html) to describe this file, but the short answer is to set the `VK_LAYER_SETTINGS_PATH` like the following:

```
# windows
set VK_LAYER_SETTINGS_PATH=C:\path\to\vk_layer_settings.txt

# linux
export VK_LAYER_SETTINGS_PATH=/path/to/vk_layer_settings.txt
```

and it will set things for you in that file. We have a [default example](../layers/vk_layer_settings.txt) file you can start with.

## Environment Variables

This is done for us via the `vkuCreateLayerSettingSet` call in the [Vulkan-Utility-Libraries](https://github.com/KhronosGroup/Vulkan-Utility-Libraries/).

As an example, in our `VkLayer_khronos_validation.json` file you will find something like `"key": "message_id_filter",`.

From here you just need to adjust it the naming and prefix depending on your platform:

```
# Windows
set VK_LAYER_MESSAGE_ID_FILTER=VUID-VkInstanceCreateInfo-pNext-pNext

# Linux
export VK_LAYER_MESSAGE_ID_FILTER=VUID-VkInstanceCreateInfo-pNext-pNext

# Android
adb setprop debug.vulkan.khronos_validation.message_id_filter=VUID-VkInstanceCreateInfo-pNext-pNext
```

## Finding available settings

How we suggest finding them:

1. Check VkConfig
2. View `VkLayer_khronos_validation.json` (it is where we define them all)
3. In [layer_options.cpp](../layers/layer_options.cpp) (it is where we parse and set the settings)

## Legacy

This is only here to document the legacy of how we got to this situation.

Long ago validation created its own system to parse environmental variables as well as the `vk_layer_settings.txt` flow.

Then we created `VK_EXT_validation_features` as way to set things at `vkCreateInstance` time. `VK_EXT_validation_flags` was also created after with the same goals in mind.

As more and more layers basically needed to do what Validation Layers were doing, we just ended up creating `VK_EXT_layer_settings` as a final solution. This extension has been the way forward to a better system of creating settings for layers.

Unfortunately, we still support some legacy names, so this prevents us from making everything consistent.
1 change: 1 addition & 0 deletions layers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_sources(VkLayer_utils PRIVATE
error_message/error_location.h
error_message/error_strings.h
error_message/record_object.h
error_message/log_message_type.h
external/xxhash.h
external/inplace_function.h
${API_TYPE}/generated/error_location_helper.cpp
Expand Down
32 changes: 32 additions & 0 deletions layers/error_message/log_message_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 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.
*/
#pragma once

#include <vulkan/vulkan_core.h>

// These aim to follow VkDebugReportFlagBitsEXT but were created prior
// Could replace with VkDebugReportFlagBitsEXT, but would be a LOT of churn and these
// names are less verbose and desired.
enum LogMessageTypeBits {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gets included from both layer and tests, decided to make a dedicated file as this should never be touched and I only want the minimal ./layer code in ./test as possible

kInformationBit = 0x00000001,
kWarningBit = 0x00000002,
kPerformanceWarningBit = 0x00000004,
kErrorBit = 0x00000008,
kVerboseBit = 0x00000010,
};
using LogMessageTypeFlags = VkFlags;
43 changes: 43 additions & 0 deletions layers/error_message/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,49 @@ VKAPI_ATTR VkBool32 VKAPI_CALL MessengerBreakCallback([[maybe_unused]] VkDebugUt
return false;
}

static void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moving here as only place it is used

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");
}
}

static 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");
}
}

VKAPI_ATTR VkBool32 VKAPI_CALL MessengerLogCallback(VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
VkDebugUtilsMessageTypeFlagsEXT message_type,
const VkDebugUtilsMessengerCallbackDataEXT *callback_data, void *user_data) {
Expand Down
2 changes: 1 addition & 1 deletion layers/error_message/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <vulkan/utility/vk_struct_helper.hpp>

#include "vk_layer_config.h"
#include "error_message/log_message_type.h"
#include "containers/custom_containers.h"
#include "generated/vk_layer_dispatch_table.h"
#include "generated/vk_object_types.h"
Expand Down
1 change: 1 addition & 0 deletions layers/gpu/debug_printf/debug_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "generated/layer_chassis_dispatch.h"
#include "chassis/chassis_modification_state.h"
#include "gpu/shaders/gpu_error_header.h"
#include "vk_layer_config.h"

#include <iostream>

Expand Down
Loading