Skip to content

Commit

Permalink
vkconfig3: Clean up Diagnostics tab
Browse files Browse the repository at this point in the history
Change-Id: Ibb1726b536edace67792b64bb9283f006073cc99
  • Loading branch information
christophe-lunarg committed Nov 11, 2024
1 parent 799a9eb commit 2eb0bc3
Show file tree
Hide file tree
Showing 22 changed files with 315 additions and 303 deletions.
170 changes: 2 additions & 168 deletions vkconfig_core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,174 +879,8 @@ std::string Configurator::GenerateVulkanStatus() const {
log += this->layers.Log();
log += this->configurations.Log();
log += this->executables.Log();
// log += "Vulkan Loader Log:\n";
// log += ::GenerateLoaderLog();

/*
Configurator& configurator = Configurator::Get();
// Layers override configuration
switch (configurator.environment.GetMode()) {
default:
case LAYERS_CONTROLLED_BY_APPLICATIONS:
log += "- Vulkan Layers Controlled by Vulkan Applications\n";
break;
case LAYERS_CONTROLLED_BY_CONFIGURATOR:
if (configurator.configurations.HasActiveConfiguration(configurator.layers.selected_layers)) {
log += format("- Vulkan Layers Controlled by \"%s\" configuration\n",
configurator.environment.GetSelectedConfiguration().c_str());
} else {
log += format("- Vulkan Layers Controlled by Vulkan Configurator but no configuration selected\n",
configurator.environment.GetSelectedConfiguration().c_str());
}
break;
case LAYERS_DISABLED_BY_CONFIGURATOR:
log += "- Vulkan Layers Disabled by Vulkan Configurator\n";
break;
}
log += "- Environment variables:\n";
LayersMode saved_mode = configurator.environment.GetMode();
configurator.environment.SetMode(LAYERS_CONTROLLED_BY_APPLICATIONS);
configurator.Configure(configurator.layers.selected_layers);
QLibrary library(GetVulkanLibrary());
PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties =
(PFN_vkEnumerateInstanceLayerProperties)library.resolve("vkEnumerateInstanceLayerProperties");
assert(vkEnumerateInstanceLayerProperties);
std::uint32_t instance_layer_count = 0;
VkResult err = vkEnumerateInstanceLayerProperties(&instance_layer_count, NULL);
assert(!err);
std::vector<VkLayerProperties> layers_properties;
layers_properties.resize(instance_layer_count);
err = vkEnumerateInstanceLayerProperties(&instance_layer_count, &layers_properties[0]);
assert(!err);
log += "- Available Layers:\n";
for (std::size_t i = 0, n = layers_properties.size(); i < n; ++i) {
const Layer* layer = FindByKey(configurator.layers.selected_layers, layers_properties[i].layerName);
std::string status;
if (layer != nullptr) {
if (layer->status != STATUS_STABLE) {
status = GetToken(layer->status);
}
}
if (status.empty()) {
log += format(" - %s\n", layers_properties[i].layerName);
} else {
log += format(" - %s (%s)\n", layers_properties[i].layerName, status.c_str());
}
}
VkInstance inst = VK_NULL_HANDLE;
err = CreateInstance(library, inst, false);
if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
// If no compatible driver were found, trying with portability enumeration
err = CreateInstance(library, inst, true);
if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
Alert::InstanceFailure();
log += "- Cannot find a compatible Vulkan installable client driver (ICD).\n";
return log;
}
}
assert(err == VK_SUCCESS);
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices =
(PFN_vkEnumeratePhysicalDevices)library.resolve("vkEnumeratePhysicalDevices");
assert(vkEnumeratePhysicalDevices);
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties =
(PFN_vkEnumerateInstanceExtensionProperties)library.resolve("vkEnumerateInstanceExtensionProperties");
assert(vkEnumerateInstanceExtensionProperties);
VkResult result = VK_SUCCESS;
uint32_t instance_extension_count = 0;
result = vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, nullptr);
std::vector<VkExtensionProperties> instance_extensions;
if (instance_extension_count > 0) {
instance_extensions.resize(instance_extension_count);
}
result = vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, instance_extensions.data());
bool has_device_id = false;
if (result == VK_SUCCESS) {
for (std::size_t i = 0, n = instance_extensions.size(); i < n; ++i) {
if (instance_extensions[i].extensionName == std::string(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME)) {
has_device_id = true;
break;
}
}
}
uint32_t gpu_count = 0;
err = vkEnumeratePhysicalDevices(inst, &gpu_count, NULL);
PFN_vkDestroyInstance vkDestroyInstance = (PFN_vkDestroyInstance)library.resolve("vkDestroyInstance");
assert(vkDestroyInstance);
// This can fail on a new Linux setup. Check and fail gracefully rather than crash.
if (err != VK_SUCCESS) {
Alert::PhysicalDeviceFailure();
vkDestroyInstance(inst, NULL);
log += "- Cannot find a compatible Vulkan installable client driver (ICD).\n";
return log;
}
std::vector<VkPhysicalDevice> devices;
devices.resize(gpu_count);
err = vkEnumeratePhysicalDevices(inst, &gpu_count, &devices[0]);
assert(!err);
PFN_vkGetPhysicalDeviceProperties pfnGetPhysicalDeviceProperties =
(PFN_vkGetPhysicalDeviceProperties)library.resolve("vkGetPhysicalDeviceProperties");
assert(pfnGetPhysicalDeviceProperties);
Configurator& configurator_edit = Configurator::Get();
configurator_edit.device_names.clear();
log += "- Physical Devices:\n";
for (std::size_t i = 0, n = devices.size(); i < n; ++i) {
VkPhysicalDeviceProperties properties;
pfnGetPhysicalDeviceProperties(devices[i], &properties);
const std::string vk_version = format("%d.%d.%d", VK_VERSION_MAJOR(properties.apiVersion),
VK_VERSION_MINOR(properties.apiVersion), VK_VERSION_PATCH(properties.apiVersion));
log += format(" - %s with Vulkan %s\n", properties.deviceName, vk_version.c_str());
if (has_device_id) {
PFN_vkGetPhysicalDeviceProperties2 pfnGetPhysicalDeviceProperties2 =
(PFN_vkGetPhysicalDeviceProperties2)library.resolve("vkGetPhysicalDeviceProperties2");
assert(pfnGetPhysicalDeviceProperties2);
VkPhysicalDeviceIDPropertiesKHR properties_deviceid{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR, nullptr};
VkPhysicalDeviceProperties2 properties2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &properties_deviceid};
pfnGetPhysicalDeviceProperties2(devices[i], &properties2);
const std::string deviceUUID = GetUUIDString(properties_deviceid.deviceUUID);
log += format(" - deviceUUID: %s\n", deviceUUID.c_str());
const std::string driverUUID = GetUUIDString(properties_deviceid.driverUUID);
log += format(" - driverUUID: %s\n", driverUUID.c_str());
}
configurator_edit.device_names.push_back(properties.deviceName);
}
vkDestroyInstance(inst, NULL);
configurator.environment.SetMode(saved_mode);
configurator.Configure(configurator.layers.selected_layers);
*/
return log;
}
1 change: 1 addition & 0 deletions vkconfig_core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Configurator : public Serialize {
bool has_crashed = false;
TabType active_tab = TAB_CONFIGURATIONS;
bool advanced = true;
Path last_path_status = ::Get(Path::HOME) + "/vkconfig.txt";

private:
Path home_sdk_path;
Expand Down
83 changes: 83 additions & 0 deletions vkconfig_core/vulkan_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <cassert>
#include <sstream>
#include <iostream>

// 261 for Unix in fact...
const Version REQUIRED_LOADER_VERSION(1, 3, 284);
Expand Down Expand Up @@ -102,6 +103,59 @@ bool VulkanFunctions::Validate() const {
this->CreateInstance != nullptr && this->DestroyInstance != nullptr && this->GetPhysicalDeviceProperties2 != nullptr;
}

static VkResult CreateInstance(const VulkanFunctions &vk, bool enumerate_portability, VkInstance &instance) {
uint32_t property_count = 0;
VkResult err = vk.EnumerateInstanceExtensionProperties(nullptr, &property_count, nullptr);
assert(err == VK_SUCCESS);

std::vector<VkExtensionProperties> instance_properties(property_count);
err = vk.EnumerateInstanceExtensionProperties(nullptr, &property_count, &instance_properties[0]);
assert(err == VK_SUCCESS);

// Handle Portability Enumeration requirements
std::vector<const char *> instance_extensions;

for (std::size_t i = 0, n = instance_properties.size(); i < n; ++i) {
if (instance_properties[i].extensionName == std::string(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME)) {
instance_extensions.push_back(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME);
}
#if VK_KHR_portability_enumeration
if (enumerate_portability) {
if (instance_properties[i].extensionName == std::string(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) {
instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
}
}
#endif
}

// Check Vulkan Devices

VkApplicationInfo app = {};
app.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app.pNext = nullptr;
app.pApplicationName = VKCONFIG_SHORT_NAME;
app.applicationVersion = 0;
app.pEngineName = VKCONFIG_SHORT_NAME;
app.engineVersion = 0;
app.apiVersion = VK_API_VERSION_1_1;

VkInstanceCreateInfo inst_info = {};
inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
#if VK_KHR_portability_enumeration
if (enumerate_portability) {
inst_info.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
#endif
inst_info.pNext = nullptr;
inst_info.pApplicationInfo = &app;
inst_info.enabledLayerCount = 0;
inst_info.ppEnabledLayerNames = nullptr;
inst_info.enabledExtensionCount = static_cast<uint32_t>(instance_extensions.size());
inst_info.ppEnabledExtensionNames = instance_extensions.empty() ? nullptr : &instance_extensions[0];

return vk.CreateInstance(&inst_info, nullptr, &instance);
}

VulkanSystemInfo BuildVulkanSystemInfo() {
VulkanSystemInfo vulkan_system_info;

Expand Down Expand Up @@ -341,3 +395,32 @@ std::string GetLabel(VendorID vendorID) {
return "Qualcomm";
}
}

std::string GenerateLoaderLog() {
std::stringstream buffer;
std::streambuf *old = std::cerr.rdbuf(buffer.rdbuf());

bool is_set = qEnvironmentVariableIsSet("VK_LOADER_DEBUG");
std::string saved_data = is_set ? qgetenv("VK_LOADER_DEBUG").toStdString() : "";

qputenv("VK_LOADER_DEBUG", "all");

std::cerr << "gni" << std::endl;

VulkanFunctions vk;

if (vk.Validate()) {
VkInstance instance = VK_NULL_HANDLE;

VkResult err = ::CreateInstance(vk, false, instance);
if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
err = ::CreateInstance(vk, true, instance);
if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
return "VK_ERROR_INCOMPATIBLE_DRIVER\n";
}
}
vk.DestroyInstance(instance, nullptr);
}

return buffer.str();
}
2 changes: 2 additions & 0 deletions vkconfig_core/vulkan_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ std::vector<std::string> BuildEnvVariablesList(const char *layer_key, const char
const char *GetLabel(VkPhysicalDeviceType deviceType);

std::string GetLabel(VendorID vendorID);

std::string GenerateLoaderLog();
Loading

0 comments on commit 2eb0bc3

Please sign in to comment.