Fix : Added prerequisite checks for using VK_Layer_Validation #105922
|
@ -23,7 +23,8 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include "sys/stat.h"
|
||||
#include <sstream>
|
||||
vnapdv marked this conversation as resolved
Outdated
|
||||
#include <sys/stat.h>
|
||||
/* 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,21 +80,18 @@ static const char *vulkan_error_as_string(VkResult result)
|
|||
return "Unknown Error";
|
||||
}
|
||||
}
|
||||
vnapdv marked this conversation as resolved
Outdated
Jeroen Bakker
commented
`vklayer_config_exists` might be a better name.
|
||||
static bool is_vklayer_exist(const char* vk_extension_config)
|
||||
static bool vklayer_config_exist(const char* vk_extension_config)
|
||||
{
|
||||
const char *ev_val = getenv("VK_LAYER_PATH");
|
||||
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.
|
||||
return false;
|
||||
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 `_`.
|
||||
}
|
||||
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`.
|
||||
const size_t size_max = strlen(ev_val) + strlen(vk_extension_config) + 2;
|
||||
char *filename = (char *)malloc(size_max);
|
||||
memset(filename, 0, size_max);
|
||||
strcpy(filename, ev_val);
|
||||
strcat(filename, "/");
|
||||
strcat(filename, vk_extension_config);
|
||||
std::stringstream filename;
|
||||
filename << ev_val;
|
||||
filename << "/";
|
||||
filename << vk_extension_config;
|
||||
struct stat buffer;
|
||||
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
|
||||
bool exists = (stat(filename, &buffer) == 0);
|
||||
free(filename);
|
||||
bool exists = (stat(filename.str().c_str(), &buffer) == 0);
|
||||
return exists;
|
||||
}
|
||||
#define __STR(A) "" #A
|
||||
|
@ -118,6 +116,10 @@ static bool is_vklayer_exist(const char* vk_extension_config)
|
|||
|
||||
/* Triple buffering. */
|
||||
const int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
enum class VkDynamicLibraryType : std::uint8_t {
|
||||
vnapdv marked this conversation as resolved
Outdated
Jeroen Bakker
commented
Don't specify the size of the enumeration, Let the compiler chose the optimal one for you. Use a shorter name Don't specify the size of the enumeration, Let the compiler chose the optimal one for you.
Use a shorter name `DynamicLibrary` should be enough.
|
||||
VkValidationLayer = 0,
|
||||
VkDynamicLibraryAll
|
||||
vnapdv marked this conversation as resolved
Outdated
Jeroen Bakker
commented
We should remove this one, until it is actually needed. We should remove this one, until it is actually needed.
|
||||
};
|
||||
|
||||
GHOST_ContextVK::GHOST_ContextVK(bool stereoVisual,
|
||||
#ifdef _WIN32
|
||||
|
@ -417,16 +419,31 @@ static bool checkLayerSupport(vector<VkLayerProperties> &layers_available, const
|
|||
|
||||
static void enableLayer(vector<VkLayerProperties> &layers_available,
|
||||
vector<const char *> &layers_enabled,
|
||||
const char *layer_name,
|
||||
const bool debug)
|
||||
VkDynamicLibraryType library_type,
|
||||
const bool warning)
|
||||
{
|
||||
if (checkLayerSupport(layers_available, layer_name)) {
|
||||
layers_enabled.push_back(layer_name);
|
||||
std::string layer_name = "";
|
||||
std::string config_name = "";
|
||||
switch (library_type) {
|
||||
case VkDynamicLibraryType::VkValidationLayer:
|
||||
vnapdv marked this conversation as resolved
Outdated
Jeroen Bakker
commented
I think the pattern you're using here will be different when adding the second extension. You don't want to copy the warning for each extension. I think the pattern you're using here will be different when adding the second extension. You don't want to copy the warning for each extension.
|
||||
layer_name = "VK_LAYER_KHRONOS_validation";
|
||||
config_name = "VkLayer_khronos_validation.json";
|
||||
break;
|
||||
case VkDynamicLibraryType::VkDynamicLibraryAll:
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkLayerSupport(layers_available, "VK_LAYER_KHRONOS_validation") &&
|
||||
vnapdv marked this conversation as resolved
Outdated
Jeroen Bakker
commented
I think you wanted to refer to I think you wanted to refer to `layer_name` and `config_name` here.
|
||||
vklayer_config_exist("VkLayer_khronos_validation.json")) {
|
||||
layers_enabled.push_back("VK_LAYER_KHRONOS_validation");
|
||||
}
|
||||
else if (debug) {
|
||||
fprintf(
|
||||
stderr, "Warning: Layer requested, but not supported by the platform. [%s]\n", layer_name);
|
||||
else if (warning) {
|
||||
fprintf(stderr,
|
||||
"Warning: Layer requested, but not supported by the platform. [%s]\n",
|
||||
layer_name.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static bool device_extensions_support(VkPhysicalDevice device, vector<const char *> required_exts)
|
||||
|
@ -880,9 +897,7 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
|
|||
|
||||
vector<const char *> layers_enabled;
|
||||
if (m_debug) {
|
||||
if (is_vklayer_exist("VkLayer_khronos_validation.json")) {
|
||||
enableLayer(layers_available, layers_enabled, "VK_LAYER_KHRONOS_validation", m_debug);
|
||||
}
|
||||
enableLayer(layers_available, layers_enabled, VkDynamicLibraryType::VkValidationLayer,true);
|
||||
}
|
||||
|
||||
vector<const char *> extensions_device;
|
||||
|
|
System includes should use
<>