mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-10 02:41:47 +00:00
Add vkb::destroy_surface
helper function
This commit is contained in:
parent
10d88ae840
commit
b3fdd554b4
@ -547,7 +547,7 @@ void cleanup (Init& init, RenderData& data) {
|
||||
|
||||
vkb::destroy_swapchain (init.swapchain);
|
||||
vkb::destroy_device (init.device);
|
||||
init->vkDestroySurfaceKHR (init.instance.instance, init.surface, nullptr);
|
||||
vkb::destroy_surface(init.instance, init.surface);
|
||||
vkb::destroy_instance (init.instance);
|
||||
destroy_window_glfw (init.window);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class VulkanFunctions {
|
||||
PFN_vkGetPhysicalDeviceFormatProperties2 fp_vkGetPhysicalDeviceFormatProperties2 = nullptr;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties2 fp_vkGetPhysicalDeviceMemoryProperties2 = nullptr;
|
||||
|
||||
PFN_vkGetDeviceProcAddr fp_vkGetDeviceProcAddr = nullptr;
|
||||
PFN_vkGetDeviceProcAddr fp_vkGetDeviceProcAddr = nullptr;
|
||||
PFN_vkCreateDevice fp_vkCreateDevice = nullptr;
|
||||
PFN_vkDestroyDevice fp_vkDestroyDevice = nullptr;
|
||||
PFN_vkEnumerateDeviceExtensionProperties fp_vkEnumerateDeviceExtensionProperties = nullptr;
|
||||
@ -190,7 +190,7 @@ class VulkanFunctions {
|
||||
get_proc_addr(fp_vkGetPhysicalDeviceFormatProperties2, "vkGetPhysicalDeviceFormatProperties2");
|
||||
get_proc_addr(fp_vkGetPhysicalDeviceMemoryProperties2, "vkGetPhysicalDeviceMemoryProperties2");
|
||||
|
||||
get_proc_addr(fp_vkGetDeviceProcAddr, "vkGetDeviceProcAddr");
|
||||
get_proc_addr(fp_vkGetDeviceProcAddr, "vkGetDeviceProcAddr");
|
||||
get_proc_addr(fp_vkCreateDevice, "vkCreateDevice");
|
||||
get_proc_addr(fp_vkDestroyDevice, "vkDestroyDevice");
|
||||
get_proc_addr(fp_vkEnumerateDeviceExtensionProperties, "vkEnumerateDeviceExtensionProperties");
|
||||
@ -558,7 +558,16 @@ bool SystemInfo::is_layer_available(const char* layer_name) const {
|
||||
if (!layer_name) return false;
|
||||
return detail::check_layer_supported(available_layers, layer_name);
|
||||
}
|
||||
|
||||
void destroy_surface(Instance instance, VkSurfaceKHR surface) {
|
||||
if (instance.instance != VK_NULL_HANDLE && surface != VK_NULL_HANDLE) {
|
||||
detail::vulkan_functions().fp_vkDestroySurfaceKHR(instance.instance, surface, instance.allocation_callbacks);
|
||||
}
|
||||
}
|
||||
void destroy_surface(VkInstance instance, VkSurfaceKHR surface, VkAllocationCallbacks* callbacks) {
|
||||
if (instance != VK_NULL_HANDLE && surface != VK_NULL_HANDLE) {
|
||||
detail::vulkan_functions().fp_vkDestroySurfaceKHR(instance, surface, callbacks);
|
||||
}
|
||||
}
|
||||
void destroy_instance(Instance instance) {
|
||||
if (instance.instance != VK_NULL_HANDLE) {
|
||||
if (instance.debug_messenger != VK_NULL_HANDLE)
|
||||
@ -945,7 +954,8 @@ uint32_t get_separate_queue_index(std::vector<VkQueueFamilyProperties> const& fa
|
||||
VkQueueFlags undesired_flags) {
|
||||
uint32_t index = QUEUE_INDEX_MAX_VALUE;
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(families.size()); i++) {
|
||||
if ((families[i].queueFlags & desired_flags) && ((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
|
||||
if ((families[i].queueFlags & desired_flags) &&
|
||||
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
|
||||
if ((families[i].queueFlags & undesired_flags) == 0) {
|
||||
return i;
|
||||
} else {
|
||||
@ -1376,9 +1386,7 @@ detail::Result<VkQueue> Device::get_dedicated_queue(QueueType type) const {
|
||||
|
||||
// ---- Dispatch ---- //
|
||||
|
||||
DispatchTable Device::make_table() const {
|
||||
return {device, fp_vkGetDeviceProcAddr};
|
||||
}
|
||||
DispatchTable Device::make_table() const { return { device, fp_vkGetDeviceProcAddr }; }
|
||||
|
||||
// ---- Device ---- //
|
||||
|
||||
|
@ -225,6 +225,8 @@ struct Instance {
|
||||
friend class PhysicalDeviceSelector;
|
||||
};
|
||||
|
||||
void destroy_surface(Instance instance, VkSurfaceKHR surface); // release surface handle
|
||||
void destroy_surface(VkInstance instance, VkSurfaceKHR surface, VkAllocationCallbacks* callbacks = nullptr); // release surface handle
|
||||
void destroy_instance(Instance instance); // release instance resources
|
||||
|
||||
class InstanceBuilder {
|
||||
@ -619,13 +621,13 @@ void destroy_swapchain(Swapchain const& swapchain);
|
||||
|
||||
class SwapchainBuilder {
|
||||
public:
|
||||
// Construct a SwapchainBuilder with a `vkb::Device`
|
||||
// Construct a SwapchainBuilder with a `vkb::Device`
|
||||
explicit SwapchainBuilder(Device const& device);
|
||||
// Construct a SwapchainBuilder with a specific VkSurfaceKHR handle and `vkb::Device`
|
||||
explicit SwapchainBuilder(Device const& device, VkSurfaceKHR const surface);
|
||||
// Construct a SwapchainBuilder with Vulkan handles for the physical device, device, and surface
|
||||
// Optionally can provide the uint32_t indices for the graphics and present queue
|
||||
// Note: The constructor will query the graphics & present queue if the indices are not provided
|
||||
explicit SwapchainBuilder(Device const& device, VkSurfaceKHR const surface);
|
||||
// Construct a SwapchainBuilder with Vulkan handles for the physical device, device, and surface
|
||||
// Optionally can provide the uint32_t indices for the graphics and present queue
|
||||
// Note: The constructor will query the graphics & present queue if the indices are not provided
|
||||
explicit SwapchainBuilder(VkPhysicalDevice const physical_device,
|
||||
VkDevice const device,
|
||||
VkSurfaceKHR const surface,
|
||||
|
@ -5,12 +5,6 @@
|
||||
// TODO
|
||||
// changing present modes and/or image formats
|
||||
|
||||
void destroy_surface(vkb::detail::Result<vkb::Instance> instance_ret, VkSurfaceKHR surface) {
|
||||
PFN_vkDestroySurfaceKHR fp_vkDestroySurfaceKHR = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
|
||||
instance_ret->fp_vkGetInstanceProcAddr(instance_ret->instance, "vkDestroySurfaceKHR"));
|
||||
fp_vkDestroySurfaceKHR(instance_ret->instance, surface, nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("Instance with surface", "[VkBootstrap.bootstrap]") {
|
||||
GIVEN("A window and a vulkan instance") {
|
||||
|
||||
@ -54,7 +48,7 @@ TEST_CASE("Instance with surface", "[VkBootstrap.bootstrap]") {
|
||||
REQUIRE(phys_dev_ret.has_value());
|
||||
}
|
||||
|
||||
destroy_surface(instance_ret, surface);
|
||||
vkb::destroy_surface(instance, surface);
|
||||
vkb::destroy_instance(instance);
|
||||
destroy_window_glfw(window);
|
||||
}
|
||||
@ -106,7 +100,8 @@ TEST_CASE("instance configuration", "[VkBootstrap.bootstrap]") {
|
||||
TEST_CASE("Headless Vulkan", "[VkBootstrap.bootstrap]") {
|
||||
vkb::InstanceBuilder builder;
|
||||
|
||||
auto instance_ret = builder.request_validation_layers().set_headless().use_default_debug_messenger().build();
|
||||
auto instance_ret =
|
||||
builder.request_validation_layers().set_headless().use_default_debug_messenger().build();
|
||||
REQUIRE(instance_ret.has_value());
|
||||
|
||||
vkb::PhysicalDeviceSelector phys_device_selector(instance_ret.value());
|
||||
@ -127,7 +122,8 @@ TEST_CASE("Device Configuration", "[VkBootstrap.bootstrap]") {
|
||||
auto window = create_window_glfw("Device Configuration");
|
||||
vkb::InstanceBuilder builder;
|
||||
|
||||
auto instance_ret = builder.request_validation_layers().require_api_version(1, 1).use_default_debug_messenger().build();
|
||||
auto instance_ret =
|
||||
builder.request_validation_layers().require_api_version(1, 1).use_default_debug_messenger().build();
|
||||
REQUIRE(instance_ret.has_value());
|
||||
auto surface = create_surface_glfw(instance_ret.value().instance, window);
|
||||
|
||||
@ -183,15 +179,18 @@ TEST_CASE("Device Configuration", "[VkBootstrap.bootstrap]") {
|
||||
vkb::destroy_device(device_ret.value());
|
||||
}
|
||||
|
||||
destroy_surface(instance_ret, surface);
|
||||
vkb::destroy_surface(instance_ret.value(), surface);
|
||||
vkb::destroy_instance(instance_ret.value());
|
||||
}
|
||||
|
||||
TEST_CASE("Loading Dispatch Table", "[VkBootstrap.bootstrap]") {
|
||||
vkb::InstanceBuilder builder;
|
||||
|
||||
auto instance_ret =
|
||||
builder.request_validation_layers().require_api_version(1, 0).set_headless().use_default_debug_messenger().build();
|
||||
auto instance_ret = builder.request_validation_layers()
|
||||
.require_api_version(1, 0)
|
||||
.set_headless()
|
||||
.use_default_debug_messenger()
|
||||
.build();
|
||||
REQUIRE(instance_ret.has_value());
|
||||
{
|
||||
|
||||
@ -209,10 +208,10 @@ TEST_CASE("Loading Dispatch Table", "[VkBootstrap.bootstrap]") {
|
||||
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
|
||||
VkFence fence = VK_NULL_HANDLE;
|
||||
dispatch_table.createFence(&info, nullptr, &fence);
|
||||
dispatch_table.createFence(&info, nullptr, &fence);
|
||||
REQUIRE(fence != VK_NULL_HANDLE);
|
||||
|
||||
dispatch_table.destroyFence(fence, nullptr);
|
||||
dispatch_table.destroyFence(fence, nullptr);
|
||||
vkb::destroy_device(device_ret.value());
|
||||
}
|
||||
vkb::destroy_instance(instance_ret.value());
|
||||
@ -325,7 +324,7 @@ TEST_CASE("Swapchain", "[VkBootstrap.bootstrap]") {
|
||||
}
|
||||
|
||||
vkb::destroy_device(device_ret.value());
|
||||
destroy_surface(instance_ret, surface);
|
||||
vkb::destroy_surface(instance_ret.value(), surface);
|
||||
vkb::destroy_instance(instance_ret.value());
|
||||
}
|
||||
}
|
||||
@ -350,10 +349,12 @@ TEST_CASE("Allocation Callbacks", "[VkBootstrap.bootstrap]") {
|
||||
auto window = create_window_glfw("Allocation Callbacks");
|
||||
vkb::InstanceBuilder builder;
|
||||
|
||||
auto instance_ret =
|
||||
builder.request_validation_layers().set_allocation_callbacks(&allocation_callbacks).use_default_debug_messenger().build();
|
||||
auto instance_ret = builder.request_validation_layers()
|
||||
.set_allocation_callbacks(&allocation_callbacks)
|
||||
.use_default_debug_messenger()
|
||||
.build();
|
||||
REQUIRE(instance_ret.has_value());
|
||||
auto surface = create_surface_glfw(instance_ret.value().instance, window);
|
||||
auto surface = create_surface_glfw(instance_ret.value().instance, window, &allocation_callbacks);
|
||||
|
||||
vkb::PhysicalDeviceSelector phys_device_selector(instance_ret.value());
|
||||
|
||||
@ -374,7 +375,7 @@ TEST_CASE("Allocation Callbacks", "[VkBootstrap.bootstrap]") {
|
||||
vkb::destroy_swapchain(swapchain_ret.value());
|
||||
vkb::destroy_device(device_ret.value());
|
||||
|
||||
destroy_surface(instance_ret, surface);
|
||||
vkb::destroy_surface(instance_ret.value(), surface);
|
||||
vkb::destroy_instance(instance_ret.value());
|
||||
}
|
||||
|
||||
@ -447,19 +448,23 @@ TEST_CASE("Querying Required Extension Features", "[VkBootstrap.version]") {
|
||||
GIVEN("A working instance") {
|
||||
vkb::InstanceBuilder builder;
|
||||
|
||||
auto instance_ret =
|
||||
builder.request_validation_layers().require_api_version(1, 2).set_headless().use_default_debug_messenger().build();
|
||||
auto instance_ret = builder.request_validation_layers()
|
||||
.require_api_version(1, 2)
|
||||
.set_headless()
|
||||
.use_default_debug_messenger()
|
||||
.build();
|
||||
REQUIRE(instance_ret.has_value());
|
||||
// Requires a device that supports runtime descriptor arrays via descriptor indexing extension.
|
||||
{
|
||||
VkPhysicalDeviceDescriptorIndexingFeaturesEXT descriptor_indexing_features{};
|
||||
descriptor_indexing_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
|
||||
descriptor_indexing_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
|
||||
descriptor_indexing_features.runtimeDescriptorArray = true;
|
||||
|
||||
vkb::PhysicalDeviceSelector selector(instance_ret.value());
|
||||
auto phys_dev_ret =
|
||||
selector.add_required_extension(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME).
|
||||
add_required_extension_features(descriptor_indexing_features).select();
|
||||
selector.add_required_extension(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME)
|
||||
.add_required_extension_features(descriptor_indexing_features)
|
||||
.select();
|
||||
// Ignore if hardware support isn't true
|
||||
REQUIRE(phys_dev_ret.has_value());
|
||||
|
||||
@ -479,8 +484,11 @@ TEST_CASE("Querying Vulkan 1.1 and 1.2 features", "[VkBootstrap.version]") {
|
||||
GIVEN("A working instance") {
|
||||
vkb::InstanceBuilder builder;
|
||||
|
||||
auto instance_ret =
|
||||
builder.request_validation_layers().require_api_version(1, 2).set_headless().use_default_debug_messenger().build();
|
||||
auto instance_ret = builder.request_validation_layers()
|
||||
.require_api_version(1, 2)
|
||||
.set_headless()
|
||||
.use_default_debug_messenger()
|
||||
.build();
|
||||
REQUIRE(instance_ret.has_value());
|
||||
// Requires a device that supports multiview and bufferDeviceAddress
|
||||
{
|
||||
|
@ -31,9 +31,10 @@ void destroy_window_glfw(GLFWwindow* window) {
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
}
|
||||
VkSurfaceKHR create_surface_glfw(VkInstance instance, GLFWwindow* window) {
|
||||
VkSurfaceKHR create_surface_glfw(
|
||||
VkInstance instance, GLFWwindow* window, VkAllocationCallbacks* allocator = nullptr) {
|
||||
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||
VkResult err = glfwCreateWindowSurface(instance, window, NULL, &surface);
|
||||
VkResult err = glfwCreateWindowSurface(instance, window, allocator, &surface);
|
||||
if (err) {
|
||||
const char* error_msg;
|
||||
int ret = glfwGetError(&error_msg);
|
||||
@ -126,8 +127,8 @@ struct VulkanLibrary {
|
||||
vkDestroyPipeline = (PFN_vkDestroyPipeline)vkGetDeviceProcAddr(device, "vkDestroyPipeline");
|
||||
vkDestroyPipelineLayout =
|
||||
(PFN_vkDestroyPipelineLayout)vkGetDeviceProcAddr(device, "vkDestroyPipelineLayout");
|
||||
vkDestroyRenderPass = (PFN_vkDestroyRenderPass)vkGetDeviceProcAddr(device, "vkDestroyRenderPass");
|
||||
}
|
||||
vkDestroyRenderPass = (PFN_vkDestroyRenderPass)vkGetDeviceProcAddr(device, "vkDestroyRenderPass");
|
||||
}
|
||||
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = VK_NULL_HANDLE;
|
||||
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr = VK_NULL_HANDLE;
|
||||
@ -163,5 +164,5 @@ struct VulkanLibrary {
|
||||
PFN_vkDestroyPipeline vkDestroyPipeline = VK_NULL_HANDLE;
|
||||
PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout = VK_NULL_HANDLE;
|
||||
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR = VK_NULL_HANDLE;
|
||||
PFN_vkDestroyRenderPass vkDestroyRenderPass = VK_NULL_HANDLE;
|
||||
PFN_vkDestroyRenderPass vkDestroyRenderPass = VK_NULL_HANDLE;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user