Re-added swapchain constructors from individual handles.

Allows people to use Swapchain Builder withtout holding onto the vkb::Device
handle. Also made patch levels optional since they generally don't matter.
This commit is contained in:
Charles Giessen 2020-10-21 13:25:48 -06:00
parent 6657593fa3
commit 6e50441f41
3 changed files with 50 additions and 18 deletions

View File

@ -1537,7 +1537,20 @@ SwapchainBuilder::SwapchainBuilder (Device const& device, VkSurfaceKHR const sur
info.graphics_queue_index = present.value ();
info.present_queue_index = graphics.value ();
}
SwapchainBuilder::SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface, uint32_t graphics_queue_index){
info.physical_device = physical_device;
info.device = device;
info.surface = surface;
info.graphics_queue_index = graphics_queue_index;
info.present_queue_index = graphics_queue_index;
}
SwapchainBuilder::SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface, uint32_t graphics_queue_index, uint32_t present_queue_index){
info.physical_device = physical_device;
info.device = device;
info.surface = surface;
info.graphics_queue_index = graphics_queue_index;
info.present_queue_index = present_queue_index;
}
detail::Result<Swapchain> SwapchainBuilder::build () const {
if (info.surface == VK_NULL_HANDLE) {
return detail::Error{ SwapchainError::surface_handle_not_provided };

View File

@ -224,13 +224,13 @@ class InstanceBuilder {
// Sets the name of the engine. Defaults to "" if none is provided.
InstanceBuilder& set_engine_name (const char* engine_name);
// Sets the (major, minor, patch) version of the application.
InstanceBuilder& set_app_version (uint32_t major, uint32_t minor, uint32_t patch);
InstanceBuilder& set_app_version (uint32_t major, uint32_t minor, uint32_t patch = 0);
// Sets the (major, minor, patch) version of the engine.
InstanceBuilder& set_engine_version (uint32_t major, uint32_t minor, uint32_t patch);
InstanceBuilder& set_engine_version (uint32_t major, uint32_t minor, uint32_t patch = 0);
// Require a vulkan instance API version. Will fail to create if this version isn't available.
InstanceBuilder& require_api_version (uint32_t major, uint32_t minor, uint32_t patch);
InstanceBuilder& require_api_version (uint32_t major, uint32_t minor, uint32_t patch = 0);
// Prefer a vulkan instance API version. If the desired version isn't available, it will use the highest version available.
InstanceBuilder& desire_api_version (uint32_t major, uint32_t minor, uint32_t patch);
InstanceBuilder& desire_api_version (uint32_t major, uint32_t minor, uint32_t patch = 0);
// Adds a layer to be enabled. Will fail to create an instance if the layer isn't available.
InstanceBuilder& enable_layer (const char* layer_name);
@ -404,8 +404,8 @@ class PhysicalDeviceSelector {
// Prefer a physical device that supports a (major, minor) version of vulkan.
PhysicalDeviceSelector& set_desired_version (uint32_t major, uint32_t minor);
// Require a physical device that supports a (major, minor) version of vulkan. Default is Vulkan 1.0.
PhysicalDeviceSelector& set_minimum_version (uint32_t major = 1, uint32_t minor = 0);
// Require a physical device that supports a (major, minor) version of vulkan.
PhysicalDeviceSelector& set_minimum_version (uint32_t major, uint32_t minor);
// Require a physical device which supports the features in VkPhysicalDeviceFeatures.
PhysicalDeviceSelector& set_required_features (VkPhysicalDeviceFeatures features);
@ -554,6 +554,8 @@ class SwapchainBuilder {
public:
explicit SwapchainBuilder (Device const& device);
explicit SwapchainBuilder (Device const& device, VkSurfaceKHR const surface);
explicit SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface, uint32_t graphics_queue_index);
explicit SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface, uint32_t graphics_queue_index, uint32_t present_queue_index);
detail::Result<Swapchain> build () const;

View File

@ -127,13 +127,13 @@ TEST_CASE ("Device Configuration", "[VkBootstrap.bootstrap]") {
auto window = create_window_glfw ("Device Configuration");
vkb::InstanceBuilder builder;
auto instance_ret = builder.request_validation_layers ().build ();
auto instance_ret = builder.request_validation_layers ().require_api_version(1,1).build ();
REQUIRE (instance_ret.has_value ());
auto surface = create_surface_glfw (instance_ret.value ().instance, window);
vkb::PhysicalDeviceSelector phys_device_selector (instance_ret.value ());
auto phys_device_ret = phys_device_selector.set_surface (surface).select ();
auto phys_device_ret = phys_device_selector.set_minimum_version (1, 1).set_surface (surface).select ();
REQUIRE (phys_device_ret.has_value ());
auto phys_device = phys_device_ret.value ();
@ -174,10 +174,11 @@ TEST_CASE ("Device Configuration", "[VkBootstrap.bootstrap]") {
}
SECTION ("VkPhysicalDeviceFeatures2 in pNext Chain") {
VkPhysicalDeviceFeatures2 phys_dev_feat_2{};
VkPhysicalDeviceShaderDrawParameterFeatures shader_draw_features{};
shader_draw_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES;
vkb::DeviceBuilder device_builder (phys_device);
auto device_ret = device_builder.add_pNext (&phys_dev_feat_2).build ();
vkb::DeviceBuilder device_builder (phys_device_ret.value ());
auto device_ret = device_builder.add_pNext (&shader_draw_features).build ();
REQUIRE (device_ret.has_value ());
vkb::destroy_device (device_ret.value ());
}
@ -205,6 +206,9 @@ TEST_CASE ("Swapchain", "[VkBootstrap.bootstrap]") {
REQUIRE (device_ret.has_value ());
vkb::Device device = device_ret.value ();
auto graphics_queue_index = device.get_queue_index (vkb::QueueType::graphics).value ();
auto present_queue_index = device.get_queue_index (vkb::QueueType::present).value ();
THEN ("Swapchain can be made") {
vkb::SwapchainBuilder swapchain_builder (device);
auto swapchain_ret = swapchain_builder.build ();
@ -262,6 +266,19 @@ TEST_CASE ("Swapchain", "[VkBootstrap.bootstrap]") {
vkb::destroy_swapchain (recreated_swapchain_ret.value ());
}
AND_THEN ("Swapchain can be created from individual handles") {
vkb::SwapchainBuilder swapchain_builder (
device.physical_device.physical_device, device.device, surface, graphics_queue_index, present_queue_index);
auto swapchain_ret = swapchain_builder.build ();
REQUIRE (swapchain_ret.has_value ());
auto swapchain = swapchain_ret.value ();
auto recreated_swapchain_ret = swapchain_builder.set_old_swapchain (swapchain).build ();
REQUIRE (recreated_swapchain_ret.has_value ());
vkb::destroy_swapchain (recreated_swapchain_ret.value ());
}
vkb::destroy_device (device_ret.value ());
destroy_surface (instance_ret, surface);
@ -353,12 +370,12 @@ TEST_CASE ("ReLoading Vulkan Automatically", "[VkBootstrap.loading]") {
{
vkb::InstanceBuilder builder;
auto ret = builder.build ();
REQUIRE(ret);
REQUIRE (ret);
}
{
{
vkb::InstanceBuilder builder;
auto ret = builder.build ();
REQUIRE(ret);
REQUIRE (ret);
}
}
@ -368,15 +385,15 @@ TEST_CASE ("ReLoading Vulkan Manually", "[VkBootstrap.loading]") {
REQUIRE (vk_lib.ptr_vkGetInstanceProcAddr != NULL);
vkb::InstanceBuilder builder{ vk_lib.ptr_vkGetInstanceProcAddr };
auto ret = builder.build ();
REQUIRE(ret);
REQUIRE (ret);
vk_lib.close ();
}
{
{
VulkanLibrary vk_lib;
REQUIRE (vk_lib.ptr_vkGetInstanceProcAddr != NULL);
vkb::InstanceBuilder builder{ vk_lib.ptr_vkGetInstanceProcAddr };
auto ret = builder.build ();
REQUIRE(ret);
REQUIRE (ret);
vk_lib.close ();
}
}