Fix : Added prerequisite checks for using VK_Layer_Validation #105922

Merged
Jeroen Bakker merged 16 commits from :vk_debug_break_down into main 2023-03-28 10:45:56 +02:00
1 changed files with 29 additions and 3 deletions
Showing only changes of commit 7c86f188c9 - Show all commits

View File

@ -23,7 +23,7 @@
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
vnapdv marked this conversation as resolved Outdated

System includes should use <>

System includes should use `<>`
/* Set to 0 to allow devices that do not have the required features.
* This allows development on OSX until we really needs these features. */
#define STRICT_REQUIREMENTS 1
@ -79,7 +79,31 @@ static const char *vulkan_error_as_string(VkResult result)
return "Unknown Error";
}
}
static bool is_vklayer_exist()
vnapdv marked this conversation as resolved Outdated

vklayer_config_exists might be a better name.

`vklayer_config_exists` might be a better name.
{
const char *ev_val = getenv("VK_LAYER_PATH");
bool exists = false;
if (ev_val != nullptr) {
vnapdv marked this conversation as resolved Outdated

Best to change this to an early exit.

Best to change this to an early exit.

If you return when ev_val is nullptr, you can't print the warnings. It will check if there is no VK_LAYER_PATH and if there is no json file, so it will not return early.

If you return when ev_val is nullptr, you can't print the warnings. It will check if there is no VK_LAYER_PATH and if there is no json file, so it will not return early.
std::string _json = std::string(ev_val) + "/VkLayer_khronos_validation.json";
vnapdv marked this conversation as resolved Outdated

The filename should be a parameter. In the future we might want to enable other layers as well. This way it is clear to the developer where to change it.

Not sure concatinating strings is the best solution. would rather use a pathseq

Variables should not start with an _.

The filename should be a parameter. In the future we might want to enable other layers as well. This way it is clear to the developer where to change it. Not sure concatinating strings is the best solution. would rather use a pathseq Variables should not start with an `_`.
std::ifstream infile(_json.c_str());
vnapdv marked this conversation as resolved Outdated

Not sure we need to open the file. can we use file stats?

Not sure we need to open the file. can we use file stats?

This section is too C. I would use std::stringstream.

This section is too C. I would use `std::stringstream`.
exists = infile.good();
}
if (!exists) {
#if defined(_WIN32)
fprintf(stderr,
vnapdv marked this conversation as resolved Outdated

Not sure we should print any message to the user. --debug-gpu is also used by users when reporting bugs. This message will confuse them and ask questions. I rather see this fail silently.

So perhaps we just want to change the messahe in enableLayer (supporter=>available).

But then, what is the value of this PR?

Not sure we should print any message to the user. `--debug-gpu` is also used by users when reporting bugs. This message will confuse them and ask questions. I rather see this fail silently. So perhaps we just want to change the messahe in `enableLayer` (supporter=>available). But then, what is the value of this PR?

What we check with enableLayer is not whether it's actually ready for dynamic linking.
If the dll or so files are not properly configured, vkCreateInstance will fail.
This is a check to avoid that error.


Vulkan Error : GHOST_ContextVK.cpp:937 : vkCreateInstance(&create_info, 0, &m_instance) failled with VK_ERROR_LAYER_NOT_PRESENT

What we check with `enableLayer` is not whether it's actually ready for dynamic linking. If the dll or so files are not properly configured, vkCreateInstance will fail. This is a check to avoid that error. ----- Vulkan Error : GHOST_ContextVK.cpp:937 : vkCreateInstance(&create_info, 0, &m_instance) failled with VK_ERROR_LAYER_NOT_PRESENT
"Warning: Layer requested, we are trying to use the VulkanValidationLayer explicitly. "
"\n Set the path ..VulkanSDK\1.2.198.1\Bin of VulkanSDK (version1.2.198.1) to the "
"environment variable VK_LAYER_PATH.\nSee more details "
"https://vulkan.lunarg.com/doc/sdk/1.3.239.0/windows/layer_configuration.html.");
#elif !defined(__APPLE__)
vnapdv marked this conversation as resolved Outdated

Just use #else.

Just use #else.
fprintf(stderr,
"Warning: Layer requested, we are trying to use the VulkanValidationLayer explicitly. "
"\n Set the path ..vulkan/explicit_layer.d of VulkanSDK (version1.2.198.1) to the "
"environment variable VK_LAYER_PATH.\n"See more details https://vulkan.lunarg.com/doc/sdk/1.3.239.0/linux/layer_configuration.html.");
vnapdv marked this conversation as resolved Outdated

Seems to be an error.

Seems to be an error.
#endif
}
return exists;
}
#define __STR(A) "" #A
#define VK_CHECK(__expression) \
do { \
@ -864,7 +888,9 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
vector<const char *> layers_enabled;
if (m_debug) {
enableLayer(layers_available, layers_enabled, "VK_LAYER_KHRONOS_validation", m_debug);
if (is_vklayer_exist()) {
enableLayer(layers_available, layers_enabled, "VK_LAYER_KHRONOS_validation", m_debug);
}
}
vector<const char *> extensions_device;