vulkan/vkinfo: enable layers when -validate is specified
Enable layers when -validate is given, instead of unconditionally. This
is a regression fix since vkinfo fails with
vkCreateInstance failed: VK_ERROR_LAYER_NOT_PRESENT (-6)
since commit b1e7d59.
Change-Id: I42bfc474239896416e26ebf1b18cc65c9c045610
diff --git a/vulkan/tools/vkinfo.cpp b/vulkan/tools/vkinfo.cpp
index b88c35d..3dc6653 100644
--- a/vulkan/tools/vkinfo.cpp
+++ b/vulkan/tools/vkinfo.cpp
@@ -29,6 +29,12 @@
namespace {
+struct Options {
+ bool layer_description;
+ bool layer_extensions;
+ bool validate;
+};
+
struct GpuInfo {
VkPhysicalDeviceProperties properties;
VkPhysicalDeviceMemoryProperties memory;
@@ -116,7 +122,9 @@
die("vkEnumerateDeviceExtensionProperties (data)", result);
}
-void GatherGpuInfo(VkPhysicalDevice gpu, GpuInfo& info) {
+void GatherGpuInfo(VkPhysicalDevice gpu,
+ const Options &options,
+ GpuInfo& info) {
VkResult result;
uint32_t count;
@@ -188,7 +196,7 @@
.pQueueCreateInfos = &queue_create_info,
.enabledExtensionCount = num_extensions,
.ppEnabledExtensionNames = extensions,
- .enabledLayerCount = num_layers,
+ .enabledLayerCount = (options.validate) ? num_layers : 0,
.ppEnabledLayerNames = kValidationLayers,
.pEnabledFeatures = &info.features,
};
@@ -198,7 +206,7 @@
vkDestroyDevice(device, nullptr);
}
-void GatherInfo(VulkanInfo* info) {
+void GatherInfo(VulkanInfo* info, const Options& options) {
VkResult result;
uint32_t count;
@@ -253,7 +261,7 @@
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.enabledExtensionCount = num_extensions,
.ppEnabledExtensionNames = extensions,
- .enabledLayerCount = num_layers,
+ .enabledLayerCount = (options.validate) ? num_layers : 0,
.ppEnabledLayerNames = kValidationLayers,
};
VkInstance instance;
@@ -275,18 +283,13 @@
info->gpus.resize(num_gpus);
for (size_t i = 0; i < gpus.size(); i++)
- GatherGpuInfo(gpus[i], info->gpus.at(i));
+ GatherGpuInfo(gpus[i], options, info->gpus.at(i));
vkDestroyInstance(instance, nullptr);
}
// ----------------------------------------------------------------------------
-struct Options {
- bool layer_description;
- bool layer_extensions;
-};
-
const size_t kMaxIndent = 8;
const size_t kIndentSize = 3;
std::array<char, kMaxIndent * kIndentSize + 1> kIndent;
@@ -513,6 +516,7 @@
static volatile bool startup_pause = false;
Options options = {
.layer_description = false, .layer_extensions = false,
+ .validate = false,
};
for (int argi = 1; argi < argc; argi++) {
if (strcmp(argv[argi], "-v") == 0) {
@@ -522,6 +526,8 @@
options.layer_description = true;
} else if (strcmp(argv[argi], "-layer_extensions") == 0) {
options.layer_extensions = true;
+ } else if (strcmp(argv[argi], "-validate") == 0) {
+ options.validate = true;
} else if (strcmp(argv[argi], "-debug_pause") == 0) {
startup_pause = true;
}
@@ -532,7 +538,7 @@
}
VulkanInfo info;
- GatherInfo(&info);
+ GatherInfo(&info, options);
PrintInfo(info, options);
return 0;
}