Fix : Added prerequisite checks for using VK_Layer_Validation #105922
|
@ -23,7 +23,7 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include <fstream>
|
||||
vnapdv marked this conversation as resolved
Outdated
|
||||
/* 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
Jeroen Bakker
commented
`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
Jeroen Bakker
commented
Best to change this to an early exit. Best to change this to an early exit.
Kazashi Yoshioka
commented
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
Jeroen Bakker
commented
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
Jeroen Bakker
commented
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?
Jeroen Bakker
commented
This section is too C. I would use 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
Jeroen Bakker
commented
Not sure we should print any message to the user. So perhaps we just want to change the messahe in 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?
Kazashi Yoshioka
commented
What we check with 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
Jeroen Bakker
commented
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
Jeroen Bakker
commented
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;
|
||||
|
|
System includes should use
<>