2020-02-03 23:23:47 +00:00
|
|
|
#include "common.h"
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-02-10 18:29:09 +00:00
|
|
|
int test_happy_path () {
|
2020-02-12 00:51:03 +00:00
|
|
|
printf ("happy path\n");
|
|
|
|
|
2020-01-30 08:15:10 +00:00
|
|
|
auto window = create_window_glfw ();
|
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::InstanceBuilder instance_builder;
|
2020-01-30 08:15:10 +00:00
|
|
|
auto instance_ret = instance_builder.set_default_debug_messenger ().build ();
|
2020-02-10 18:29:09 +00:00
|
|
|
if (!instance_ret) {
|
|
|
|
std::cout << static_cast<uint32_t> (instance_ret.error ().type) << "\n";
|
2020-01-31 22:23:22 +00:00
|
|
|
return -1; // couldn't make instance
|
|
|
|
}
|
|
|
|
vkb::Instance instance = instance_ret.value ();
|
|
|
|
printf ("made instance\n");
|
2020-01-30 08:15:10 +00:00
|
|
|
|
|
|
|
auto surface = create_surface_glfw (instance.instance, window);
|
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::PhysicalDeviceSelector phys_device_selector (instance);
|
2020-01-30 08:15:10 +00:00
|
|
|
auto phys_device_ret = phys_device_selector.set_surface (surface).select ();
|
2020-01-30 08:15:10 +00:00
|
|
|
if (!phys_device_ret) return -2; // couldn't select physical device
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::PhysicalDevice physical_device = phys_device_ret.value ();
|
|
|
|
printf ("made physical device\n");
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::DeviceBuilder device_builder (physical_device);
|
2020-01-30 08:15:10 +00:00
|
|
|
auto device_ret = device_builder.build ();
|
2020-01-31 22:23:22 +00:00
|
|
|
if (!device_ret) return -1; // couldn't create device
|
|
|
|
vkb::Device device = device_ret.value ();
|
|
|
|
printf ("made device\n");
|
2020-01-30 08:15:10 +00:00
|
|
|
|
|
|
|
// possible swapchain creation...
|
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::destroy_device (device);
|
2020-02-18 22:18:08 +00:00
|
|
|
destroy_surface (instance.instance, surface);
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::destroy_instance (instance);
|
2020-01-30 08:15:10 +00:00
|
|
|
destroy_window_glfw (window);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-10 18:29:09 +00:00
|
|
|
int test_instance_basic () {
|
2020-02-12 00:51:03 +00:00
|
|
|
printf ("\nbasic instance\n");
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::InstanceBuilder builder;
|
2020-01-30 08:15:10 +00:00
|
|
|
|
|
|
|
auto instance_ret =
|
2020-02-19 02:12:31 +00:00
|
|
|
builder.check_and_setup_validation_layers ()
|
2020-01-30 08:15:10 +00:00
|
|
|
.set_app_name ("test")
|
|
|
|
.set_debug_callback ([] (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
|
|
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
|
|
|
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
|
|
|
void* pUserData) -> VkBool32 {
|
2020-02-04 03:34:46 +00:00
|
|
|
auto ms = vkb::to_string_message_severity (messageSeverity);
|
|
|
|
auto mt = vkb::to_string_message_type (messageType);
|
2020-01-30 08:15:10 +00:00
|
|
|
printf ("[%s: %s](user defined)\n%s\n", ms, mt, pCallbackData->pMessage);
|
|
|
|
return VK_FALSE;
|
|
|
|
})
|
|
|
|
.set_api_version (1, 2, 111)
|
|
|
|
.build ();
|
2020-02-10 18:29:09 +00:00
|
|
|
if (!instance_ret.has_value ()) {
|
2020-01-30 08:15:10 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-02-12 00:51:03 +00:00
|
|
|
vkb::destroy_instance (instance_ret.value ());
|
|
|
|
|
2020-01-30 08:15:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 18:29:09 +00:00
|
|
|
int test_instance_headless () {
|
2020-02-12 00:51:03 +00:00
|
|
|
printf ("\nheadless instance\n");
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::InstanceBuilder builder;
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-02-17 21:09:40 +00:00
|
|
|
auto instance_ret =
|
2020-02-19 02:12:31 +00:00
|
|
|
builder.check_and_setup_validation_layers ()
|
2020-02-17 21:09:40 +00:00
|
|
|
.set_headless ()
|
|
|
|
.set_app_version (4, 5, 6)
|
|
|
|
.set_app_name ("headless")
|
|
|
|
.set_engine_name ("nick")
|
|
|
|
.set_api_version (1, 0, 34)
|
|
|
|
.set_default_debug_messenger ()
|
|
|
|
.add_validation_feature_enable (VkValidationFeatureEnableEXT::VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT)
|
|
|
|
.add_validation_feature_disable (VkValidationFeatureDisableEXT::VK_VALIDATION_FEATURE_DISABLE_OBJECT_LIFETIMES_EXT)
|
|
|
|
.add_validation_disable (VkValidationCheckEXT::VK_VALIDATION_CHECK_SHADERS_EXT)
|
|
|
|
.build ();
|
2020-02-10 18:29:09 +00:00
|
|
|
if (!instance_ret.has_value ()) {
|
2020-01-30 08:15:10 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-02-12 00:51:03 +00:00
|
|
|
vkb::destroy_instance (instance_ret.value ());
|
2020-01-30 08:15:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 18:29:09 +00:00
|
|
|
int test_physical_device_selection () {
|
2020-02-12 00:51:03 +00:00
|
|
|
printf ("\nphysical device selection\n");
|
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::InstanceBuilder instance_builder;
|
2020-01-30 08:15:10 +00:00
|
|
|
auto instance_ret = instance_builder.set_default_debug_messenger ().build ();
|
|
|
|
auto instance = instance_ret.value ();
|
|
|
|
auto window = create_window_glfw ();
|
|
|
|
auto surface = create_surface_glfw (instance.instance, window);
|
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::PhysicalDeviceSelector selector (instance);
|
2020-01-30 08:15:10 +00:00
|
|
|
auto phys_dev_ret = selector.set_surface (surface)
|
2020-01-30 08:15:10 +00:00
|
|
|
.add_desired_extension (VK_KHR_MULTIVIEW_EXTENSION_NAME)
|
|
|
|
.add_required_extension (VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME)
|
|
|
|
.set_minimum_version (1, 0)
|
|
|
|
.set_desired_version (1, 1)
|
|
|
|
.select ();
|
2020-02-10 18:29:09 +00:00
|
|
|
if (!phys_dev_ret.has_value ()) {
|
2020-01-30 08:15:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2020-02-18 22:18:08 +00:00
|
|
|
destroy_surface (instance.instance, surface);
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::destroy_instance (instance);
|
2020-01-30 08:15:10 +00:00
|
|
|
destroy_window_glfw (window);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 18:29:09 +00:00
|
|
|
int test_device_creation () {
|
2020-02-12 00:51:03 +00:00
|
|
|
printf ("\ndevice creation\n");
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::InstanceBuilder instance_builder;
|
2020-01-30 08:15:10 +00:00
|
|
|
auto instance_ret = instance_builder.set_default_debug_messenger ().build ();
|
2020-02-12 00:51:03 +00:00
|
|
|
if (!instance_ret.has_value ()) {
|
|
|
|
printf ("couldn't create instance %i\n", static_cast<uint32_t> (instance_ret.error ().type));
|
|
|
|
return -1;
|
|
|
|
}
|
2020-01-30 08:15:10 +00:00
|
|
|
auto instance = instance_ret.value ();
|
2020-02-12 00:51:03 +00:00
|
|
|
|
2020-01-30 08:15:10 +00:00
|
|
|
auto window = create_window_glfw ();
|
|
|
|
auto surface = create_surface_glfw (instance.instance, window);
|
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::PhysicalDeviceSelector selector (instance);
|
2020-01-30 08:15:10 +00:00
|
|
|
auto phys_dev_ret = selector.set_surface (surface).select ();
|
2020-01-30 08:15:10 +00:00
|
|
|
auto phys_dev = phys_dev_ret.value ();
|
2020-02-12 00:51:03 +00:00
|
|
|
if (!phys_dev_ret.has_value ()) {
|
|
|
|
printf ("couldn't select device %i\n", static_cast<uint32_t> (phys_dev_ret.error ().type));
|
|
|
|
return -1;
|
|
|
|
}
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::DeviceBuilder device_builder (phys_dev);
|
2020-01-30 08:15:10 +00:00
|
|
|
auto dev_ret = device_builder.build ();
|
2020-02-10 18:29:09 +00:00
|
|
|
if (!dev_ret.has_value ()) {
|
|
|
|
printf ("couldn't create device %i\n", static_cast<uint32_t> (dev_ret.error ().type));
|
2020-01-30 08:15:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::destroy_device (dev_ret.value ());
|
2020-02-18 22:18:08 +00:00
|
|
|
destroy_surface (instance.instance, surface);
|
2020-01-31 22:23:22 +00:00
|
|
|
vkb::destroy_instance (instance);
|
2020-01-30 08:15:10 +00:00
|
|
|
destroy_window_glfw (window);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 18:29:09 +00:00
|
|
|
int main () {
|
2020-01-30 08:15:10 +00:00
|
|
|
test_happy_path ();
|
2020-02-12 00:51:03 +00:00
|
|
|
test_instance_basic ();
|
|
|
|
test_instance_headless ();
|
|
|
|
test_physical_device_selection ();
|
|
|
|
test_device_creation ();
|
2020-01-30 08:15:10 +00:00
|
|
|
}
|