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 27 additions and 8 deletions
Showing only changes of commit 69e981f1b1 - Show all commits

View File

@ -19,10 +19,12 @@
#include <vector>
#include <sys/stat.h>
vnapdv marked this conversation as resolved
Review

Please run make format when push and configure clang-format to your IDE. This file has several issues where it doesn't match our code style.

Please run make format when push and configure clang-format to your IDE. This file has several issues where it doesn't match our code style.
Review

Please run make format when push and configure clang-format to your IDE. This file has several issues where it doesn't match our code style.

I checked blender's clang-format. It seems that there was a slight conflict in the settings of visual studio. I will make sure to check again with visual code.

> Please run make format when push and configure clang-format to your IDE. This file has several issues where it doesn't match our code style. I checked blender's clang-format. It seems that there was a slight conflict in the settings of visual studio. I will make sure to check again with visual code.
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
vnapdv marked this conversation as resolved Outdated

System includes should use <>

System includes should use `<>`
#include <sstream>
/* Set to 0 to allow devices that do not have the required features.
* This allows development on OSX until we really needs these features. */
@ -80,6 +82,19 @@ static const char *vulkan_error_as_string(VkResult result)
}
vnapdv marked this conversation as resolved Outdated

vklayer_config_exists might be a better name.

`vklayer_config_exists` might be a better name.
}
static bool vklayer_config_exist(const char* vk_extension_config)
{
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.
const char *ev_val = getenv("VK_LAYER_PATH");
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 `_`.
if (ev_val == nullptr) {
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`.
return false;
}
std::stringstream filename;
filename << ev_val;
filename << "/" << vk_extension_config;
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
struct stat buffer;
return (stat(filename.str().c_str(), &buffer) == 0);
}
#define __STR(A) "" #A
vnapdv marked this conversation as resolved Outdated

Just use #else.

Just use #else.
#define VK_CHECK(__expression) \
do { \
@ -401,16 +416,20 @@ 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)
const char* layer_name,
const bool warning)
{
if (checkLayerSupport(layers_available, layer_name)) {
layers_enabled.push_back(layer_name);
}
else if (debug) {
fprintf(
stderr, "Warning: Layer requested, but not supported by the platform. [%s]\n", layer_name);
if (strcmp(layer_name, "VK_LAYER_KHRONOS_validation") == 0) {
if (checkLayerSupport(layers_available, layer_name) &&
vklayer_config_exist("VkLayer_khronos_validation.json")) {
layers_enabled.push_back(layer_name);
}
else if (warning) {
vnapdv marked this conversation as resolved Outdated

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.
fprintf(stderr,"Warning: Layer requested, but not supported by the platform. [%s]\n",layer_name);
}
}
}
static bool device_extensions_support(VkPhysicalDevice device, vector<const char *> required_exts)