case OutputType::html: {
p.SetHeader();
ArrayWrapper arr(p, "Layers", layers.size());
- p.IndentDecrease();
+ IndentWrapper indent(p);
+
for (auto &layer : layers) {
auto v_str = VkVersionString(layer.layer_properties.specVersion);
auto props = layer.layer_properties;
p.AddNewline();
}
}
- p.IndentIncrease();
break;
}
const std::vector<std::unique_ptr<AppSurface>> &surfaces) {
p.SetHeader();
ObjectWrapper obj(p, "Presentable Surfaces");
- p.IndentDecrease();
+ IndentWrapper indent(p);
std::vector<SurfaceTypeGroup> surface_list;
for (auto &group : surface_list) {
DumpSurface(p, inst, *group.gpu, *group.surface, group.surface_types);
}
- p.IndentIncrease();
p.AddNewline();
}
p.SetHeader();
ObjectWrapper obj(p, "Device Groups");
- p.IndentDecrease();
+ IndentWrapper indent(p);
+
int group_id = 0;
for (auto &group : groups) {
ObjectWrapper obj(p, "Group " + std::to_string(group_id));
p.AddNewline();
group_id++;
}
- p.IndentIncrease();
p.AddNewline();
}
}
void GpuDumpMemoryProps(Printer &p, AppGpu &gpu) {
p.SetHeader();
ObjectWrapper obj(p, "VkPhysicalDeviceMemoryProperties");
- p.IndentDecrease();
+ IndentWrapper indent(p);
{
ObjectWrapper obj(p, "memoryHeaps", gpu.memory_props.memoryHeapCount);
}
}
}
-
- p.IndentIncrease();
p.AddNewline();
}
void GpuDevDump(Printer &p, AppGpu &gpu) {
p.SetHeader();
ObjectWrapper obj(p, "Format Properties");
- p.IndentDecrease();
+ IndentWrapper indent(p);
if (p.Type() == OutputType::text) {
auto fmtPropMap = FormatPropMap(gpu);
p.SetElementIndex(counter++);
ObjectWrapper obj(p, "Common Format Group");
- p.IndentDecrease();
-
+ IndentWrapper indent(p);
{
ArrayWrapper arr(p, "Formats", prop.second.size());
for (auto &fmt : prop.second) {
}
}
GpuDumpFormatProperty(p, VK_FORMAT_UNDEFINED, props);
-
- p.IndentIncrease();
p.AddNewline();
}
}
}
- p.IndentIncrease();
p.AddNewline();
}
// Uses a seperate function than schema-json for clarity
void DumpGpu(Printer &p, AppGpu &gpu, bool show_formats) {
ObjectWrapper obj(p, "GPU" + std::to_string(gpu.id));
- p.IndentDecrease();
+ IndentWrapper indent(p);
GpuDumpProps(p, gpu);
DumpExtensions(p, "Device", gpu.device_extensions);
GpuDevDump(p, gpu);
}
- p.IndentIncrease();
p.AddNewline();
}
return 1;
}
}
+ std::vector<std::unique_ptr<Printer>> printers;
+ std::ostream out(std::cout.rdbuf());
+ std::ofstream html_out;
+ std::ofstream vkconfig_out;
- AppInstance instance = {};
- SetupWindowExtensions(instance);
+ // if any essential vulkan call fails, it throws an exception
+ try {
+ AppInstance instance = {};
+ SetupWindowExtensions(instance);
- auto pNext_chains = get_chain_infos();
+ auto pNext_chains = get_chain_infos();
- auto phys_devices = instance.FindPhysicalDevices();
+ auto phys_devices = instance.FindPhysicalDevices();
- std::vector<std::unique_ptr<AppSurface>> surfaces;
+ std::vector<std::unique_ptr<AppSurface>> surfaces;
#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \
defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT) || defined(VK_USE_PLATFORM_WAYLAND_KHR)
- for (auto &surface_extension : instance.surface_extensions) {
- surface_extension.create_window(instance);
- surface_extension.surface = surface_extension.create_surface(instance);
- for (auto &phys_device : phys_devices) {
- surfaces.push_back(std::unique_ptr<AppSurface>(
- new AppSurface(instance, phys_device, surface_extension, pNext_chains.surface_capabilities2)));
+ for (auto &surface_extension : instance.surface_extensions) {
+ surface_extension.create_window(instance);
+ surface_extension.surface = surface_extension.create_surface(instance);
+ for (auto &phys_device : phys_devices) {
+ surfaces.push_back(std::unique_ptr<AppSurface>(
+ new AppSurface(instance, phys_device, surface_extension, pNext_chains.surface_capabilities2)));
+ }
}
- }
#endif
- std::vector<std::unique_ptr<AppGpu>> gpus;
+ std::vector<std::unique_ptr<AppGpu>> gpus;
- uint32_t gpu_counter = 0;
- for (auto &phys_device : phys_devices) {
- gpus.push_back(std::unique_ptr<AppGpu>(new AppGpu(instance, gpu_counter++, phys_device, pNext_chains)));
- }
-
- if (selected_gpu >= gpus.size()) {
- std::cout << "The selected gpu (" << selected_gpu << ") is not in the valid range of 0 to " << gpus.size() - 1 << ".\n";
- return 0;
- }
-
- std::vector<std::unique_ptr<Printer>> printers;
+ uint32_t gpu_counter = 0;
+ for (auto &phys_device : phys_devices) {
+ gpus.push_back(std::unique_ptr<AppGpu>(new AppGpu(instance, gpu_counter++, phys_device, pNext_chains)));
+ }
- std::streambuf *buf;
- buf = std::cout.rdbuf();
- std::ostream out(buf);
- std::ofstream html_out;
- std::ofstream vkconfig_out;
+ if (selected_gpu >= gpus.size()) {
+ std::cout << "The selected gpu (" << selected_gpu << ") is not in the valid range of 0 to " << gpus.size() - 1 << ".\n";
+ return 0;
+ }
- if (human_readable_output) {
- printers.push_back(std::unique_ptr<Printer>(new Printer(OutputType::text, out, selected_gpu, instance.vk_version)));
- }
- if (html_output) {
- html_out = std::ofstream("vulkaninfo.html");
- printers.push_back(std::unique_ptr<Printer>(new Printer(OutputType::html, html_out, selected_gpu, instance.vk_version)));
- }
- if (json_output) {
- printers.push_back(std::unique_ptr<Printer>(new Printer(OutputType::json, out, selected_gpu, instance.vk_version)));
- }
- if (vkconfig_output) {
+ if (human_readable_output) {
+ printers.push_back(std::unique_ptr<Printer>(new Printer(OutputType::text, out, selected_gpu, instance.vk_version)));
+ }
+ if (html_output) {
+ html_out = std::ofstream("vulkaninfo.html");
+ printers.push_back(
+ std::unique_ptr<Printer>(new Printer(OutputType::html, html_out, selected_gpu, instance.vk_version)));
+ }
+ if (json_output) {
+ printers.push_back(std::unique_ptr<Printer>(new Printer(OutputType::json, out, selected_gpu, instance.vk_version)));
+ }
+ if (vkconfig_output) {
#ifdef WIN32
- vkconfig_out = std::ofstream(std::string(output_path) + "\\vulkaninfo.json");
+ vkconfig_out = std::ofstream(std::string(output_path) + "\\vulkaninfo.json");
#else
- vkconfig_out = std::ofstream(std::string(output_path) + "/vulkaninfo.json");
+ vkconfig_out = std::ofstream(std::string(output_path) + "/vulkaninfo.json");
#endif
- printers.push_back(
- std::unique_ptr<Printer>(new Printer(OutputType::vkconfig_output, vkconfig_out, selected_gpu, instance.vk_version)));
- }
+ printers.push_back(std::unique_ptr<Printer>(
+ new Printer(OutputType::vkconfig_output, vkconfig_out, selected_gpu, instance.vk_version)));
+ }
- for (auto &p : printers) {
- if (p->Type() == OutputType::json) {
- DumpLayers(*p.get(), instance.global_layers, gpus);
- DumpGpuJson(*p.get(), *gpus.at(selected_gpu).get());
+ for (auto &p : printers) {
+ if (p->Type() == OutputType::json) {
+ DumpLayers(*p.get(), instance.global_layers, gpus);
+ DumpGpuJson(*p.get(), *gpus.at(selected_gpu).get());
- } else {
- p->SetHeader();
- DumpExtensions(*p.get(), "Instance", instance.global_extensions);
- p->AddNewline();
+ } else {
+ p->SetHeader();
+ DumpExtensions(*p.get(), "Instance", instance.global_extensions);
+ p->AddNewline();
- DumpLayers(*p.get(), instance.global_layers, gpus);
+ DumpLayers(*p.get(), instance.global_layers, gpus);
#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \
defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT) || defined(VK_USE_PLATFORM_WAYLAND_KHR)
- DumpPresentableSurfaces(*p.get(), instance, gpus, surfaces);
+ DumpPresentableSurfaces(*p.get(), instance, gpus, surfaces);
#endif
- DumpGroups(*p.get(), instance);
+ DumpGroups(*p.get(), instance);
- p->SetHeader();
- ObjectWrapper obj(*p, "Device Properties and Extensions");
- p->IndentDecrease();
+ p->SetHeader();
+ ObjectWrapper obj(*p, "Device Properties and Extensions");
+ IndentWrapper indent(*p);
- for (auto &gpu : gpus) {
- DumpGpu(*p.get(), *gpu.get(), show_formats);
+ for (auto &gpu : gpus) {
+ DumpGpu(*p.get(), *gpu.get(), show_formats);
+ }
}
-
- p->IndentIncrease();
}
- p.reset();
- }
#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \
defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT) || defined(VK_USE_PLATFORM_WAYLAND_KHR)
- for (auto &surface_extension : instance.surface_extensions) {
- AppDestroySurface(instance, surface_extension.surface);
- surface_extension.destroy_window(instance);
- }
+ for (auto &surface_extension : instance.surface_extensions) {
+ AppDestroySurface(instance, surface_extension.surface);
+ surface_extension.destroy_window(instance);
+ }
#endif
+ } catch (std::exception &e) {
+ // Print the error to stderr and leave all outputs in a valid state (mainly for json)
+ std::cerr << "ERROR at " << e.what() << "\n";
+ for (auto &p : printers) {
+ if (p) {
+ p->FinishOutput();
+ }
+ }
+ }
+ // Call the printer's descrtuctor before the file handle gets closed
+ for (auto &p : printers) {
+ p.reset(nullptr);
+ }
WAIT_FOR_CONSOLE_DESTROY;
#ifdef _WIN32
#include <algorithm>
#include <array>
+#include <exception>
#include <iostream>
#include <fstream>
#include <memory>
#include <vulkan/vulkan.h>
-#define ERR(err) std::cerr << __FILE__ << ":" << __LINE__ << ": failed with " << VkResultString(err) << "\n";
+static const char *VkResultString(VkResult err);
+
+// General error: Get file + line and a short message
+struct FileLineException : std::runtime_error {
+ FileLineException(const std::string &arg, const char *file, int line) : runtime_error(arg) {
+ msg = std::string(file) + ":" + std::to_string(line) + ": " + arg;
+ }
+ ~FileLineException() throw() {}
+ const char *what() const throw() { return msg.c_str(); }
+
+ private:
+ std::string msg;
+};
+#define THROW_ERR(arg) throw FileLineException(arg, __FILE__, __LINE__);
+
+// Vulkan function error: Get name of function, file, line, and the error code returned by the function
+struct VulkanException : std::runtime_error {
+ VulkanException(const std::string &function, const char *file, int line, VkResult err) : runtime_error(function) {
+ msg = std::string(file) + ":" + std::to_string(line) + ":" + function + " failed with " + VkResultString(err);
+ }
+ ~VulkanException() throw() {}
+ const char *what() const throw() { return msg.c_str(); }
+
+ private:
+ std::string msg;
+};
+#define THROW_VK_ERR(func_name, err) throw VulkanException(func_name, __FILE__, __LINE__, err);
// global configuration
bool human_readable_output = true;
#define WAIT_FOR_CONSOLE_DESTROY
#endif
-#define ERR_EXIT(err) \
- do { \
- ERR(err); \
- fflush(stdout); \
- fflush(stderr); \
- WAIT_FOR_CONSOLE_DESTROY; \
- exit(-1); \
- } while (0)
-
#ifdef _WIN32
#define _CALL_PFN(pfn, ...) (pfn)
}
#endif // _WIN32
-static const char *VkResultString(VkResult err);
-
const char *app_short_name = "vulkaninfo";
std::vector<const char *> get_c_str_array(std::vector<std::string> const &vec) {
const char *pMsg, void *pUserData) {
std::cerr << VkDebugReportFlagsEXTString(msgFlags) << ": [" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n";
- // True is reserved for layer developers, and MAY mean calls are not distributed down the layer chain after validation error.
- // False SHOULD always be returned by apps:
+ // True is reserved for layer developers, and MAY mean calls are not distributed down the layer chain after validation
+ // error. False SHOULD always be returned by apps:
return VK_FALSE;
}
// Helper for robustly executing the two-call pattern
template <typename T, typename F, typename... Ts>
-auto GetVectorInit(F &&f, T init, Ts &&... ts) -> std::vector<T> {
+auto GetVectorInit(const char *func_name, F &&f, T init, Ts &&... ts) -> std::vector<T> {
uint32_t count = 0;
std::vector<T> results;
VkResult err;
do {
err = f(ts..., &count, nullptr);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR(func_name, err);
results.resize(count, init);
err = f(ts..., &count, results.data());
} while (err == VK_INCOMPLETE);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR(func_name, err);
return results;
}
template <typename T, typename F, typename... Ts>
-auto GetVector(F &&f, Ts &&... ts) -> std::vector<T> {
- return GetVectorInit(f, T(), ts...);
+auto GetVector(const char *func_name, F &&f, Ts &&... ts) -> std::vector<T> {
+ return GetVectorInit(func_name, f, T(), ts...);
}
// ----------- Instance Setup ------- //
for (uint32_t i = 0; i < chain_info.size(); i++) {
place->pNext = static_cast<VkStructureHeader *>(malloc(chain_info[i].mem_size));
if (!place->pNext) {
- ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
+ THROW_ERR("buildpNextChain's malloc failed to allocate");
}
std::memset(place->pNext, 0, chain_info[i].mem_size);
place = place->pNext;
ANativeWindow *window;
#endif
AppInstance() {
- if (dll.Initialize() != VK_SUCCESS) {
- std::cerr << "Failed to initialize: Vulkan loader is not installed, not found, or failed to load.\n";
- WAIT_FOR_CONSOLE_DESTROY;
- exit(1);
+ VkResult dllErr = dll.Initialize();
+ if (dllErr != VK_SUCCESS) {
+ THROW_ERR("Failed to initialize: Vulkan loader is not installed, not found, or failed to load.");
}
dll.InitializeDispatchPointers();
instance_version = VK_API_VERSION_1_0;
} else {
const VkResult err = dll.vkEnumerateInstanceVersion(&instance_version);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkEnumerateInstanceVersion", err);
}
// fallback to baked header version if loader returns 0 for the patch version
std::cerr << "Cannot create Vulkan instance.\n";
std::cerr << "This problem is often caused by a faulty installation of the Vulkan driver or attempting to use a GPU "
"that does not support Vulkan.\n";
- ERR_EXIT(err);
+ THROW_VK_ERR("vkCreateInstance", err);
} else if (err) {
- ERR_EXIT(err);
+ THROW_VK_ERR("vkCreateInstance", err);
}
ext_funcs.LoadInstanceExtensionDispatchPointers(dll.vkGetInstanceProcAddr, instance);
}
/* Gets a list of layer and instance extensions */
void AppGetInstanceExtensions() {
/* Scan layers */
- auto global_layer_properties = GetVector<VkLayerProperties>(dll.vkEnumerateInstanceLayerProperties);
+ auto global_layer_properties =
+ GetVector<VkLayerProperties>("vkEnumerateInstanceLayerProperties", dll.vkEnumerateInstanceLayerProperties);
global_layers.resize(global_layer_properties.size());
for (size_t i = 0; i < global_layer_properties.size(); i++) {
void AddSurfaceExtension(SurfaceExtension ext) { surface_extensions.push_back(ext); }
std::vector<VkExtensionProperties> AppGetGlobalLayerExtensions(char *layer_name) {
- return GetVector<VkExtensionProperties>(dll.vkEnumerateInstanceExtensionProperties, layer_name);
+ return GetVector<VkExtensionProperties>("vkEnumerateInstanceExtensionProperties",
+ dll.vkEnumerateInstanceExtensionProperties, layer_name);
}
std::vector<VkPhysicalDevice> FindPhysicalDevices() {
- return GetVector<VkPhysicalDevice>(dll.vkEnumeratePhysicalDevices, instance);
+ return GetVector<VkPhysicalDevice>("vkEnumerateInstanceExtensionProperties", dll.vkEnumeratePhysicalDevices, instance);
}
};
// Register window class:
if (!CALL_PFN(RegisterClassExA)(&win_class)) {
// It didn't work, so try to give a useful error:
- fprintf(stderr, "Failed to register the window class!\n");
- exit(1);
+ THROW_ERR("Failed to register the window class!");
}
// Create window with the registered class:
RECT wr = {0, 0, inst.width, inst.height};
nullptr); // no extra parameters
if (!inst.h_wnd) {
// It didn't work, so try to give a useful error:
- fprintf(stderr, "Failed to create a window!\n");
- exit(1);
+ THROW_ERR("Failed to create a window!");
}
}
VkSurfaceKHR surface;
VkResult err = inst.dll.vkCreateWin32SurfaceKHR(inst.instance, &createInfo, nullptr, &surface);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateWin32SurfaceKHR", err);
return surface;
}
static VkSurfaceKHR AppCreateXcbSurface(AppInstance &inst) {
if (!inst.xcb_connection) {
- ERR_EXIT(VK_ERROR_INITIALIZATION_FAILED);
+ THROW_ERR("AppCreateXcbSurface failed to establish connection");
}
VkXcbSurfaceCreateInfoKHR xcb_createInfo;
VkSurfaceKHR surface;
VkResult err = inst.dll.vkCreateXcbSurfaceKHR(inst.instance, &xcb_createInfo, nullptr, &surface);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateXcbSurfaceKHR", err);
return surface;
}
inst.xlib_display = XOpenDisplay(nullptr);
if (inst.xlib_display == nullptr) {
- fprintf(stderr, "XLib failed to connect to the X server.\nExiting ...\n");
- exit(1);
+ THROW_ERR("XLib failed to connect to the X server.\nExiting...");
}
XVisualInfo vInfoTemplate = {};
VkSurfaceKHR surface;
VkResult err = inst.dll.vkCreateXlibSurfaceKHR(inst.instance, &createInfo, nullptr, &surface);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateXlibSurfaceKHR", err);
return surface;
}
static void AppCreateMacOSWindow(AppInstance &inst) {
inst.macos_window = CreateMetalView(inst.width, inst.height);
if (inst.macos_window == nullptr) {
- fprintf(stderr, "Could not create a native Metal view.\nExiting...\n");
- exit(1);
+ THROW_ERR("Could not create a native Metal view.\nExiting...");
}
}
VkSurfaceKHR surface;
VkResult err = inst.dll.vkCreateMacOSSurfaceMVK(inst.instance, &createInfo, nullptr, &surface);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateMacOSSurfaceMVK", err);
return surface;
}
static void AppCreateMetalWindow(AppInstance &inst) {
inst.metal_window = CreateMetalView(inst.width, inst.height);
if (inst.metal_window == nullptr) {
- fprintf(stderr, "Could not create a native Metal view.\nExiting...\n");
- exit(1);
+ THROW_ERR("Could not create a native Metal view.\nExiting...");
}
}
VkSurfaceKHR surface;
VkResult err = inst.dll.vkCreateMetalSurfaceEXT(inst.instance, &createInfo, nullptr, &surface);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateMetalSurfaceEXT", err);
return surface;
}
VkSurfaceKHR surface;
VkResult err = inst.dll.vkCreateWaylandSurfaceKHR(inst.instance, &createInfo, nullptr, &surface);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateWaylandSurfaceKHR", err);
return surface;
}
createInfo.window = (struct ANativeWindow *)(inst.window);
err = inst.dll.vkCreateAndroidSurfaceKHR(inst.inst, &createInfo, NULL, &inst.surface);
- EXIT_ERR(err);
+ THROW_VK_ERR("vkCreateAndroidSurfaceKHR", err);
}
static VkSurfaceKHR AppDestroyAndroidSurface(AppInstance &inst) {}
#endif
bool has_display = true;
const char *display_var = getenv("DISPLAY");
if (display_var == nullptr || strlen(display_var) == 0) {
- fprintf(stderr, "'DISPLAY' environment variable not set... skipping surface info\n");
- fflush(stderr);
has_display = false;
+ THROW_ERR("'DISPLAY' environment variable not set... skipping surface info");
}
#endif
: inst(inst),
phys_device(phys_device),
surface_extension(surface_extension),
- surf_present_modes(GetVector<VkPresentModeKHR>(inst.ext_funcs.vkGetPhysicalDeviceSurfacePresentModesKHR, phys_device,
+ surf_present_modes(GetVector<VkPresentModeKHR>("vkGetPhysicalDeviceSurfacePresentModesKHR",
+ inst.ext_funcs.vkGetPhysicalDeviceSurfacePresentModesKHR, phys_device,
surface_extension.surface)) {
const VkPhysicalDeviceSurfaceInfo2KHR surface_info2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, nullptr,
surface_extension.surface};
VkSurfaceFormat2KHR init;
init.sType = VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR;
init.pNext = nullptr;
- surf_formats2 = GetVectorInit<VkSurfaceFormat2KHR>(inst.ext_funcs.vkGetPhysicalDeviceSurfaceFormats2KHR, init,
+ surf_formats2 = GetVectorInit<VkSurfaceFormat2KHR>("vkGetPhysicalDeviceSurfaceFormats2KHR",
+ inst.ext_funcs.vkGetPhysicalDeviceSurfaceFormats2KHR, init,
phys_device, &surface_info2);
} else {
- surf_formats = GetVector<VkSurfaceFormatKHR>(inst.ext_funcs.vkGetPhysicalDeviceSurfaceFormatsKHR, phys_device,
+ surf_formats = GetVector<VkSurfaceFormatKHR>("vkGetPhysicalDeviceSurfaceFormatsKHR",
+ inst.ext_funcs.vkGetPhysicalDeviceSurfaceFormatsKHR, phys_device,
surface_extension.surface);
}
if (inst.CheckExtensionEnabled(VK_KHR_SURFACE_EXTENSION_NAME)) {
VkResult err = inst.ext_funcs.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(phys_device, surface_extension.surface,
&surface_capabilities);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", err);
}
if (inst.CheckExtensionEnabled(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME)) {
VkResult err =
inst.ext_funcs.vkGetPhysicalDeviceSurfaceCapabilities2KHR(phys_device, &surface_info, &surface_capabilities2_khr);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkGetPhysicalDeviceSurfaceCapabilities2KHR", err);
}
if (inst.CheckExtensionEnabled(VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME)) {
surface_capabilities2_ext.pNext = nullptr;
VkResult err = inst.ext_funcs.vkGetPhysicalDeviceSurfaceCapabilities2EXT(phys_device, surface_extension.surface,
&surface_capabilities2_ext);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkGetPhysicalDeviceSurfaceCapabilities2EXT", err);
}
}
std::vector<VkPhysicalDeviceGroupProperties> GetGroups(AppInstance &inst) {
if (inst.CheckExtensionEnabled(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME)) {
- return GetVector<VkPhysicalDeviceGroupProperties>(inst.ext_funcs.vkEnumeratePhysicalDeviceGroupsKHR, inst.instance);
+ return GetVector<VkPhysicalDeviceGroupProperties>("vkEnumeratePhysicalDeviceGroupsKHR",
+ inst.ext_funcs.vkEnumeratePhysicalDeviceGroupsKHR, inst.instance);
}
return {};
}
VkDevice logical_device = VK_NULL_HANDLE;
VkResult err = inst.dll.vkCreateDevice(group.physicalDevices[0], &device_ci, nullptr, &logical_device);
- if (err != VK_SUCCESS && err != VK_ERROR_EXTENSION_NOT_PRESENT) ERR_EXIT(err);
+ if (err != VK_SUCCESS && err != VK_ERROR_EXTENSION_NOT_PRESENT) THROW_VK_ERR("vkCreateDevice", err);
if (err == VK_ERROR_EXTENSION_NOT_PRESENT) {
VkDeviceGroupPresentCapabilitiesKHR group_capabilities = {VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHR, nullptr};
// If the KHR_device_group extension is present, write the capabilities of the logical device into a struct for later
// output to user.
err = inst.ext_funcs.vkGetDeviceGroupPresentCapabilitiesKHR(logical_device, &group_capabilities);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkGetDeviceGroupPresentCapabilitiesKHR", err);
inst.dll.vkDestroyDevice(logical_device, nullptr);
inst.ext_funcs.vkGetPhysicalDeviceProperties2KHR(phys_device, &props2);
}
-
/* get queue count */
inst.dll.vkGetPhysicalDeviceQueueFamilyProperties(phys_device, &queue_count, nullptr);
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, nullptr, 0, 1, &q_ci, 0, nullptr, 0, nullptr, &enabled_features};
VkResult err = inst.dll.vkCreateDevice(phys_device, &device_ci, nullptr, &dev);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateDevice", err);
const VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
const std::vector<VkFormat> formats = {
if (err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
*support = false;
} else {
- if (err) ERR_EXIT(err);
+ if (err != VK_SUCCESS) THROW_VK_ERR("vkGetPhysicalDeviceImageFormatProperties", err);
VkImage dummy_img;
err = inst.dll.vkCreateImage(dev, &image_ci, nullptr, &dummy_img);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkCreateImage", err);
VkMemoryRequirements mem_req;
inst.dll.vkGetImageMemoryRequirements(dev, dummy_img, &mem_req);
}
std::vector<VkExtensionProperties> AppGetPhysicalDeviceLayerExtensions(char *layer_name) {
- return GetVector<VkExtensionProperties>(inst.dll.vkEnumerateDeviceExtensionProperties, phys_device, layer_name);
+ return GetVector<VkExtensionProperties>("vkEnumerateDeviceExtensionProperties",
+ inst.dll.vkEnumerateDeviceExtensionProperties, phys_device, layer_name);
}
// Helper function to determine whether a format range is currently supported.
for (auto &surface_ext : gpu.inst.surface_extensions) {
VkResult err = gpu.inst.ext_funcs.vkGetPhysicalDeviceSurfaceSupportKHR(
gpu.phys_device, queue_index, surface_ext.surface, &surface_ext.supports_present);
- if (err) ERR_EXIT(err);
+ if (err) THROW_VK_ERR("vkGetPhysicalDeviceSurfaceSupportKHR", err);
const bool first = (surface_ext == gpu.inst.surface_extensions.at(0));
if (!first && platforms_support_present != surface_ext.supports_present) {
std::vector<VkPhysicalDeviceToolPropertiesEXT> GetToolingInfo(AppGpu &gpu) {
if (gpu.inst.ext_funcs.vkGetPhysicalDeviceToolPropertiesEXT == nullptr) return {};
- return GetVector<VkPhysicalDeviceToolPropertiesEXT>(gpu.inst.ext_funcs.vkGetPhysicalDeviceToolPropertiesEXT, gpu.phys_device);
+ return GetVector<VkPhysicalDeviceToolPropertiesEXT>("vkGetPhysicalDeviceToolPropertiesEXT",
+ gpu.inst.ext_funcs.vkGetPhysicalDeviceToolPropertiesEXT, gpu.phys_device);
}
// --------- Format Properties ----------//
VkFormatProperties2 props;
props.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2;
buildpNextChain((VkStructureHeader *)&props, chainInfos.format_properties2);
-
gpu.inst.ext_funcs.vkGetPhysicalDeviceFormatProperties2KHR(gpu.phys_device, format, &props);
return props;
}