mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 07:24:34 +00:00
Removed allocators and added new swapchainbuilder constructor
Allocators only complicated the interface and likely aren't needed. They are useful on other function calls, but none of the ones here mattered. A constructor was added to swapchain that has all the handles it needs. This way users don't have to pass in the vkb::Device struct to use the swapchain builder
This commit is contained in:
parent
4851a5bec9
commit
c30782a106
@ -44,7 +44,6 @@ VkResult create_debug_utils_messenger (VkInstance instance,
|
|||||||
PFN_vkDebugUtilsMessengerCallbackEXT debug_callback,
|
PFN_vkDebugUtilsMessengerCallbackEXT debug_callback,
|
||||||
VkDebugUtilsMessageSeverityFlagsEXT severity,
|
VkDebugUtilsMessageSeverityFlagsEXT severity,
|
||||||
VkDebugUtilsMessageTypeFlagsEXT type,
|
VkDebugUtilsMessageTypeFlagsEXT type,
|
||||||
const VkAllocationCallbacks* pAllocator,
|
|
||||||
VkDebugUtilsMessengerEXT* pDebugMessenger)
|
VkDebugUtilsMessengerEXT* pDebugMessenger)
|
||||||
{
|
{
|
||||||
if (debug_callback == nullptr) debug_callback = default_debug_callback;
|
if (debug_callback == nullptr) debug_callback = default_debug_callback;
|
||||||
@ -60,7 +59,7 @@ VkResult create_debug_utils_messenger (VkInstance instance,
|
|||||||
instance, "vkCreateDebugUtilsMessengerEXT");
|
instance, "vkCreateDebugUtilsMessengerEXT");
|
||||||
if (vkCreateDebugUtilsMessengerEXT_func != nullptr)
|
if (vkCreateDebugUtilsMessengerEXT_func != nullptr)
|
||||||
{
|
{
|
||||||
return vkCreateDebugUtilsMessengerEXT_func (instance, &messengerCreateInfo, pAllocator, pDebugMessenger);
|
return vkCreateDebugUtilsMessengerEXT_func (instance, &messengerCreateInfo, nullptr, pDebugMessenger);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -68,14 +67,13 @@ VkResult create_debug_utils_messenger (VkInstance instance,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_debug_utils_messenger (
|
void destroy_debug_utils_messenger (VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger)
|
||||||
VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator)
|
|
||||||
{
|
{
|
||||||
auto vkDestroyDebugUtilsMessengerEXT_func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr (
|
auto vkDestroyDebugUtilsMessengerEXT_func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr (
|
||||||
instance, "vkDestroyDebugUtilsMessengerEXT");
|
instance, "vkDestroyDebugUtilsMessengerEXT");
|
||||||
if (vkDestroyDebugUtilsMessengerEXT_func != nullptr)
|
if (vkDestroyDebugUtilsMessengerEXT_func != nullptr)
|
||||||
{
|
{
|
||||||
vkDestroyDebugUtilsMessengerEXT_func (instance, debugMessenger, pAllocator);
|
vkDestroyDebugUtilsMessengerEXT_func (instance, debugMessenger, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,9 +131,8 @@ void destroy_instance (Instance instance)
|
|||||||
if (instance.instance != VK_NULL_HANDLE)
|
if (instance.instance != VK_NULL_HANDLE)
|
||||||
{
|
{
|
||||||
if (instance.debug_messenger != nullptr)
|
if (instance.debug_messenger != nullptr)
|
||||||
detail::destroy_debug_utils_messenger (
|
detail::destroy_debug_utils_messenger (instance.instance, instance.debug_messenger);
|
||||||
instance.instance, instance.debug_messenger, instance.allocator);
|
vkDestroyInstance (instance.instance, nullptr);
|
||||||
vkDestroyInstance (instance.instance, instance.allocator);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +240,6 @@ detail::Expected<Instance, VkResult> InstanceBuilder::build ()
|
|||||||
info.debug_callback,
|
info.debug_callback,
|
||||||
info.debug_message_severity,
|
info.debug_message_severity,
|
||||||
info.debug_message_type,
|
info.debug_message_type,
|
||||||
info.allocator,
|
|
||||||
&instance.debug_messenger);
|
&instance.debug_messenger);
|
||||||
if (res != VK_SUCCESS)
|
if (res != VK_SUCCESS)
|
||||||
{
|
{
|
||||||
@ -357,12 +353,6 @@ InstanceBuilder& InstanceBuilder::add_validation_feature_disable (VkValidationFe
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstanceBuilder& InstanceBuilder::set_allocator_callback (VkAllocationCallbacks* allocator)
|
|
||||||
{
|
|
||||||
info.allocator = allocator;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
Expected<SurfaceSupportDetails, VkResult> query_surface_support_details (
|
Expected<SurfaceSupportDetails, VkResult> query_surface_support_details (
|
||||||
@ -762,7 +752,7 @@ PhysicalDeviceSelector& PhysicalDeviceSelector::set_required_features (VkPhysica
|
|||||||
|
|
||||||
// ---- Device ---- //
|
// ---- Device ---- //
|
||||||
|
|
||||||
void destroy_device (Device device) { vkDestroyDevice (device.device, device.allocator); }
|
void destroy_device (Device device) { vkDestroyDevice (device.device, nullptr); }
|
||||||
|
|
||||||
struct QueueFamily
|
struct QueueFamily
|
||||||
{
|
{
|
||||||
@ -824,7 +814,6 @@ detail::Expected<Device, VkResult> DeviceBuilder::build ()
|
|||||||
{
|
{
|
||||||
return detail::Error{ res, "Couldn't create device" };
|
return detail::Error{ res, "Couldn't create device" };
|
||||||
}
|
}
|
||||||
device.allocator = info.allocator;
|
|
||||||
device.physical_device = info.physical_device;
|
device.physical_device = info.physical_device;
|
||||||
device.surface = info.physical_device.surface;
|
device.surface = info.physical_device.surface;
|
||||||
return device;
|
return device;
|
||||||
@ -960,17 +949,24 @@ VkExtent2D find_extent (VkSurfaceCapabilitiesKHR const& capabilities, uint32_t d
|
|||||||
SwapchainBuilder::SwapchainBuilder (Device const& device)
|
SwapchainBuilder::SwapchainBuilder (Device const& device)
|
||||||
{
|
{
|
||||||
info.device = device.device;
|
info.device = device.device;
|
||||||
info.physical_device = device.physical_device;
|
info.physical_device = device.physical_device.phys_device;
|
||||||
info.surface = device.surface;
|
info.surface = device.surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwapchainBuilder::SwapchainBuilder (
|
||||||
|
VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface)
|
||||||
|
{
|
||||||
|
info.physical_device = physical_device;
|
||||||
|
info.device = device;
|
||||||
|
info.surface = surface;
|
||||||
|
}
|
||||||
|
|
||||||
detail::Expected<Swapchain, VkResult> SwapchainBuilder::build ()
|
detail::Expected<Swapchain, VkResult> SwapchainBuilder::build ()
|
||||||
{
|
{
|
||||||
if (info.desired_formats.size () == 0) use_default_format_selection ();
|
if (info.desired_formats.size () == 0) use_default_format_selection ();
|
||||||
if (info.desired_present_modes.size () == 0) use_default_present_mode_selection ();
|
if (info.desired_present_modes.size () == 0) use_default_present_mode_selection ();
|
||||||
|
|
||||||
auto surface_support =
|
auto surface_support = detail::query_surface_support_details (info.physical_device, info.surface);
|
||||||
detail::query_surface_support_details (info.physical_device.phys_device, info.surface);
|
|
||||||
if (!surface_support.has_value ()) return surface_support.error ();
|
if (!surface_support.has_value ()) return surface_support.error ();
|
||||||
VkSurfaceFormatKHR surface_format =
|
VkSurfaceFormatKHR surface_format =
|
||||||
detail::find_surface_format (surface_support.value ().formats, info.desired_formats);
|
detail::find_surface_format (surface_support.value ().formats, info.desired_formats);
|
||||||
@ -997,8 +993,7 @@ detail::Expected<Swapchain, VkResult> SwapchainBuilder::build ()
|
|||||||
swapchain_create_info.imageArrayLayers = 1;
|
swapchain_create_info.imageArrayLayers = 1;
|
||||||
swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
|
|
||||||
detail::QueueFamilies indices =
|
detail::QueueFamilies indices = detail::find_queue_families (info.physical_device, info.surface);
|
||||||
detail::find_queue_families (info.physical_device.phys_device, info.surface);
|
|
||||||
uint32_t queueFamilyIndices[] = { static_cast<uint32_t> (indices.graphics),
|
uint32_t queueFamilyIndices[] = { static_cast<uint32_t> (indices.graphics),
|
||||||
static_cast<uint32_t> (indices.present) };
|
static_cast<uint32_t> (indices.present) };
|
||||||
|
|
||||||
@ -1083,7 +1078,7 @@ detail::Expected<std::vector<VkImageView>, VkResult> get_swapchain_image_views (
|
|||||||
void destroy_swapchain (Swapchain const& swapchain)
|
void destroy_swapchain (Swapchain const& swapchain)
|
||||||
{
|
{
|
||||||
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE)
|
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE)
|
||||||
vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, swapchain.allocator);
|
vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapchainBuilder& SwapchainBuilder::set_desired_format (VkSurfaceFormatKHR format)
|
SwapchainBuilder& SwapchainBuilder::set_desired_format (VkSurfaceFormatKHR format)
|
||||||
|
@ -102,8 +102,7 @@ template <typename E, typename U> class Expected
|
|||||||
else
|
else
|
||||||
m_error.~Error ();
|
m_error.~Error ();
|
||||||
}
|
}
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
E m_expect;
|
E m_expect;
|
||||||
Error m_error;
|
Error m_error;
|
||||||
};
|
};
|
||||||
@ -163,11 +162,9 @@ VkResult create_debug_utils_messenger (VkInstance instance,
|
|||||||
PFN_vkDebugUtilsMessengerCallbackEXT debug_callback,
|
PFN_vkDebugUtilsMessengerCallbackEXT debug_callback,
|
||||||
VkDebugUtilsMessageSeverityFlagsEXT severity,
|
VkDebugUtilsMessageSeverityFlagsEXT severity,
|
||||||
VkDebugUtilsMessageTypeFlagsEXT type,
|
VkDebugUtilsMessageTypeFlagsEXT type,
|
||||||
const VkAllocationCallbacks* pAllocator,
|
|
||||||
VkDebugUtilsMessengerEXT* pDebugMessenger);
|
VkDebugUtilsMessengerEXT* pDebugMessenger);
|
||||||
|
|
||||||
void destroy_debug_utils_messenger (
|
void destroy_debug_utils_messenger (VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger);
|
||||||
VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator);
|
|
||||||
|
|
||||||
static VKAPI_ATTR VkBool32 VKAPI_CALL default_debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
static VKAPI_ATTR VkBool32 VKAPI_CALL default_debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||||
@ -184,7 +181,6 @@ const char* to_string_message_type (VkDebugUtilsMessageTypeFlagsEXT s);
|
|||||||
struct Instance
|
struct Instance
|
||||||
{
|
{
|
||||||
VkInstance instance = VK_NULL_HANDLE;
|
VkInstance instance = VK_NULL_HANDLE;
|
||||||
VkAllocationCallbacks* allocator = VK_NULL_HANDLE;
|
|
||||||
VkDebugUtilsMessengerEXT debug_messenger = VK_NULL_HANDLE;
|
VkDebugUtilsMessengerEXT debug_messenger = VK_NULL_HANDLE;
|
||||||
bool headless = false;
|
bool headless = false;
|
||||||
bool validation_enabled = false;
|
bool validation_enabled = false;
|
||||||
@ -222,8 +218,6 @@ class InstanceBuilder
|
|||||||
InstanceBuilder& add_validation_feature_enable (VkValidationFeatureEnableEXT enable);
|
InstanceBuilder& add_validation_feature_enable (VkValidationFeatureEnableEXT enable);
|
||||||
InstanceBuilder& add_validation_feature_disable (VkValidationFeatureDisableEXT disable);
|
InstanceBuilder& add_validation_feature_disable (VkValidationFeatureDisableEXT disable);
|
||||||
|
|
||||||
InstanceBuilder& set_allocator_callback (VkAllocationCallbacks* allocator);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct InstanceInfo
|
struct InstanceInfo
|
||||||
{
|
{
|
||||||
@ -239,7 +233,6 @@ class InstanceBuilder
|
|||||||
std::vector<std::string> extensions;
|
std::vector<std::string> extensions;
|
||||||
VkInstanceCreateFlags flags = 0;
|
VkInstanceCreateFlags flags = 0;
|
||||||
std::vector<VkBaseOutStructure*> pNext_elements;
|
std::vector<VkBaseOutStructure*> pNext_elements;
|
||||||
VkAllocationCallbacks* allocator = nullptr;
|
|
||||||
|
|
||||||
// debug callback
|
// debug callback
|
||||||
PFN_vkDebugUtilsMessengerCallbackEXT debug_callback = nullptr;
|
PFN_vkDebugUtilsMessengerCallbackEXT debug_callback = nullptr;
|
||||||
@ -394,7 +387,6 @@ struct PhysicalDeviceSelector
|
|||||||
struct Device
|
struct Device
|
||||||
{
|
{
|
||||||
VkDevice device = VK_NULL_HANDLE;
|
VkDevice device = VK_NULL_HANDLE;
|
||||||
VkAllocationCallbacks* allocator = VK_NULL_HANDLE;
|
|
||||||
PhysicalDevice physical_device;
|
PhysicalDevice physical_device;
|
||||||
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||||
};
|
};
|
||||||
@ -414,7 +406,6 @@ class DeviceBuilder
|
|||||||
{
|
{
|
||||||
VkDeviceCreateFlags flags;
|
VkDeviceCreateFlags flags;
|
||||||
std::vector<VkBaseOutStructure*> pNext_chain;
|
std::vector<VkBaseOutStructure*> pNext_chain;
|
||||||
VkAllocationCallbacks* allocator = VK_NULL_HANDLE;
|
|
||||||
PhysicalDevice physical_device;
|
PhysicalDevice physical_device;
|
||||||
std::vector<std::string> extensions;
|
std::vector<std::string> extensions;
|
||||||
} info;
|
} info;
|
||||||
@ -453,7 +444,6 @@ struct Swapchain
|
|||||||
{
|
{
|
||||||
VkDevice device = VK_NULL_HANDLE;
|
VkDevice device = VK_NULL_HANDLE;
|
||||||
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
|
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
|
||||||
VkAllocationCallbacks* allocator = VK_NULL_HANDLE;
|
|
||||||
uint32_t image_count = 0;
|
uint32_t image_count = 0;
|
||||||
VkFormat image_format = VK_FORMAT_UNDEFINED;
|
VkFormat image_format = VK_FORMAT_UNDEFINED;
|
||||||
VkExtent2D extent = { 0, 0 };
|
VkExtent2D extent = { 0, 0 };
|
||||||
@ -468,6 +458,7 @@ class SwapchainBuilder
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SwapchainBuilder (Device const& device);
|
SwapchainBuilder (Device const& device);
|
||||||
|
SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface);
|
||||||
|
|
||||||
detail::Expected<Swapchain, VkResult> build ();
|
detail::Expected<Swapchain, VkResult> build ();
|
||||||
detail::Expected<Swapchain, VkResult> recreate (Swapchain const& swapchain);
|
detail::Expected<Swapchain, VkResult> recreate (Swapchain const& swapchain);
|
||||||
@ -486,8 +477,8 @@ class SwapchainBuilder
|
|||||||
private:
|
private:
|
||||||
struct SwapchainInfo
|
struct SwapchainInfo
|
||||||
{
|
{
|
||||||
|
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
|
||||||
VkDevice device = VK_NULL_HANDLE;
|
VkDevice device = VK_NULL_HANDLE;
|
||||||
PhysicalDevice physical_device;
|
|
||||||
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||||
VkSwapchainKHR old_swapchain = VK_NULL_HANDLE;
|
VkSwapchainKHR old_swapchain = VK_NULL_HANDLE;
|
||||||
std::vector<VkSurfaceFormatKHR> desired_formats;
|
std::vector<VkSurfaceFormatKHR> desired_formats;
|
||||||
|
Loading…
Reference in New Issue
Block a user