@@ -4,11 +4,11 @@ namespace inexor::vulkan_renderer::wrapper {
4
4
5
5
Swapchain::Swapchain (Swapchain &&other) noexcept
6
6
: device(other.device), graphics_card(std::exchange(other.graphics_card, nullptr )), surface(std::exchange(other.surface, nullptr )),
7
- swapchain (std::exchange(other.swapchain, nullptr )), old_swapchain(std::exchange( other.old_swapchain, nullptr )), surface_format (other.surface_format ),
8
- extent(other.extent), swapchain_images(std::move(other.swapchain_images)), swapchain_image_views(std::move(other.swapchain_image_views)),
9
- images_in_swapchain_count (other.images_in_swapchain_count ), vsync_enabled(other.vsync_enabled) {}
7
+ swapchain (std::exchange(other.swapchain, nullptr )), surface_format( other.surface_format), extent (other.extent ),
8
+ swapchain_images(std::move(other.swapchain_images)), swapchain_image_views(std::move(other.swapchain_image_views)),
9
+ swapchain_image_count (other.swapchain_image_count ), vsync_enabled(other.vsync_enabled) {}
10
10
11
- void Swapchain::setup_swapchain (std::uint32_t & window_width, std::uint32_t & window_height) {
11
+ void Swapchain::setup_swapchain (const VkSwapchainKHR old_swapchain, std::uint32_t window_width, std::uint32_t window_height) {
12
12
VulkanSettingsDecisionMaker settings_decision_maker;
13
13
14
14
settings_decision_maker.decide_width_and_height_of_swapchain_extent (graphics_card, surface, window_width, window_height, extent);
@@ -19,13 +19,7 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
19
19
throw std::runtime_error (" Error: Could not find a suitable present mode!" );
20
20
}
21
21
22
- images_in_swapchain_count = settings_decision_maker.decide_how_many_images_in_swapchain_to_use (graphics_card, surface);
23
-
24
- // Find the transformation of the surface.
25
- auto pre_transform = settings_decision_maker.decide_which_image_transformation_to_use (graphics_card, surface);
26
-
27
- // Find a supported composite alpha format (not all devices support alpha opaque).
28
- auto composite_alpha_format = settings_decision_maker.find_composite_alpha_format (graphics_card, surface);
22
+ swapchain_image_count = settings_decision_maker.decide_how_many_images_in_swapchain_to_use (graphics_card, surface);
29
23
30
24
auto surface_format_candidate = settings_decision_maker.decide_which_surface_color_format_in_swapchain_to_use (graphics_card, surface);
31
25
@@ -38,13 +32,14 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
38
32
VkSwapchainCreateInfoKHR swapchain_create_info = {};
39
33
swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
40
34
swapchain_create_info.surface = surface;
41
- swapchain_create_info.minImageCount = images_in_swapchain_count ;
35
+ swapchain_create_info.minImageCount = swapchain_image_count ;
42
36
swapchain_create_info.imageFormat = surface_format.format ;
43
37
swapchain_create_info.imageColorSpace = surface_format.colorSpace ;
44
38
swapchain_create_info.imageExtent .width = extent.width ;
45
39
swapchain_create_info.imageExtent .height = extent.height ;
46
40
swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
47
- swapchain_create_info.preTransform = (VkSurfaceTransformFlagBitsKHR)pre_transform;
41
+ swapchain_create_info.preTransform =
42
+ (VkSurfaceTransformFlagBitsKHR)settings_decision_maker.decide_which_image_transformation_to_use (graphics_card, surface);
48
43
swapchain_create_info.imageArrayLayers = 1 ;
49
44
swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
50
45
swapchain_create_info.queueFamilyIndexCount = 0 ;
@@ -57,7 +52,7 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
57
52
58
53
// Setting clipped to VK_TRUE allows the implementation to discard rendering outside of the surface area.
59
54
swapchain_create_info.clipped = VK_TRUE;
60
- swapchain_create_info.compositeAlpha = composite_alpha_format ;
55
+ swapchain_create_info.compositeAlpha = settings_decision_maker. find_composite_alpha_format (graphics_card, surface) ;
61
56
62
57
// Set additional usage flag for blitting from the swapchain images if supported.
63
58
VkFormatProperties formatProps;
@@ -72,21 +67,21 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
72
67
throw std::runtime_error (" Error: vkCreateSwapchainKHR failed!" );
73
68
}
74
69
75
- if (vkGetSwapchainImagesKHR (device, swapchain, &images_in_swapchain_count , nullptr ) != VK_SUCCESS) {
70
+ if (vkGetSwapchainImagesKHR (device, swapchain, &swapchain_image_count , nullptr ) != VK_SUCCESS) {
76
71
throw std::runtime_error (" Error: vkGetSwapchainImagesKHR failed!" );
77
72
}
78
73
79
- swapchain_images.resize (images_in_swapchain_count );
74
+ swapchain_images.resize (swapchain_image_count );
80
75
81
- if (vkGetSwapchainImagesKHR (device, swapchain, &images_in_swapchain_count , swapchain_images.data ())) {
76
+ if (vkGetSwapchainImagesKHR (device, swapchain, &swapchain_image_count , swapchain_images.data ())) {
82
77
throw std::runtime_error (" Error: vkGetSwapchainImagesKHR failed!" );
83
78
}
84
79
85
80
// TODO: Assign an appropriate debug marker name to the swapchain images.
86
81
87
- spdlog::debug (" Creating {} swapchain image views." , images_in_swapchain_count );
82
+ spdlog::debug (" Creating {} swapchain image views." , swapchain_image_count );
88
83
89
- swapchain_image_views.resize (images_in_swapchain_count );
84
+ swapchain_image_views.resize (swapchain_image_count );
90
85
91
86
VkImageViewCreateInfo image_view_create_info = {};
92
87
image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
@@ -102,7 +97,7 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
102
97
image_view_create_info.subresourceRange .baseArrayLayer = 0 ;
103
98
image_view_create_info.subresourceRange .layerCount = 1 ;
104
99
105
- for (std::size_t i = 0 ; i < images_in_swapchain_count ; i++) {
100
+ for (std::size_t i = 0 ; i < swapchain_image_count ; i++) {
106
101
spdlog::debug (" Creating swapchain image #{}." , i);
107
102
108
103
image_view_create_info.image = swapchain_images[i];
@@ -114,25 +109,23 @@ void Swapchain::setup_swapchain(std::uint32_t &window_width, std::uint32_t &wind
114
109
// TODO: Use Vulkan debug markers to assign an appropriate name to this swapchain image view.
115
110
}
116
111
117
- spdlog::debug (" Created {} swapchain image views successfully." , images_in_swapchain_count );
112
+ spdlog::debug (" Created {} swapchain image views successfully." , swapchain_image_count );
118
113
}
119
114
120
- Swapchain::Swapchain (const VkDevice device, const VkPhysicalDevice graphics_card, const VkSurfaceKHR surface, std::uint32_t & window_width,
121
- std::uint32_t & window_height, const bool enable_vsync)
115
+ Swapchain::Swapchain (const VkDevice device, const VkPhysicalDevice graphics_card, const VkSurfaceKHR surface, std::uint32_t window_width,
116
+ std::uint32_t window_height, const bool enable_vsync)
122
117
: device(device), graphics_card(graphics_card), surface(surface), vsync_enabled(enable_vsync) {
123
118
124
119
assert (device);
125
120
assert (graphics_card);
126
121
assert (surface);
127
122
128
- old_swapchain = VK_NULL_HANDLE;
129
-
130
- setup_swapchain (window_width, window_height);
123
+ setup_swapchain (VK_NULL_HANDLE, window_width, window_height);
131
124
}
132
125
133
- void Swapchain::recreate (std::uint32_t & window_width, std::uint32_t & window_height) {
126
+ void Swapchain::recreate (std::uint32_t window_width, std::uint32_t window_height) {
134
127
// Store the old swapchain. This allows us to pass it to VkSwapchainCreateInfoKHR::oldSwapchain to speed up swapchain recreation.
135
- old_swapchain = swapchain;
128
+ VkSwapchainKHR old_swapchain = swapchain;
136
129
137
130
// When swapchain needs to be recreated, all the old swapchain images need to be destroyed.
138
131
@@ -146,7 +139,7 @@ void Swapchain::recreate(std::uint32_t &window_width, std::uint32_t &window_heig
146
139
147
140
swapchain_images.clear ();
148
141
149
- setup_swapchain (window_width, window_height);
142
+ setup_swapchain (old_swapchain, window_width, window_height);
150
143
}
151
144
152
145
Swapchain::~Swapchain () {
0 commit comments