Skip to content

Commit f474f04

Browse files
committed
Try to address resize issue in windows.
1 parent 58e0fe7 commit f474f04

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

attachments/17_swap_chain_recreation.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class HelloTriangleApplication {
8484
glfwInit();
8585

8686
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
87+
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
8788

8889
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
8990
glfwSetWindowUserPointer(window, this);
@@ -141,6 +142,7 @@ class HelloTriangleApplication {
141142
}
142143

143144
void recreateSwapChain() {
145+
framebufferResized = false;
144146
int width = 0, height = 0;
145147
glfwGetFramebufferSize(window, &width, &height);
146148
while (width == 0 || height == 0) {
@@ -153,6 +155,13 @@ class HelloTriangleApplication {
153155
cleanupSwapChain();
154156
createSwapChain();
155157
createImageViews();
158+
// Recreate dependent objects in case format or extent changed
159+
graphicsPipeline = nullptr;
160+
createGraphicsPipeline();
161+
createSyncObjects();
162+
// Reset indices to avoid out-of-range after swapchain resize
163+
semaphoreIndex = 0;
164+
currentFrame = 0;
156165
}
157166

158167
void createInstance() {
@@ -250,8 +259,9 @@ class HelloTriangleApplication {
250259
{ return strcmp( availableDeviceExtension.extensionName, requiredDeviceExtension ) == 0; } );
251260
} );
252261

253-
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
254-
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
262+
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
263+
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan11Features>().shaderDrawParameters &&
264+
features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
255265
features.template get<vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>().extendedDynamicState;
256266

257267
return supportsVulkan1_3 && supportsGraphics && supportsAllRequiredExtensions && supportsRequiredFeatures;
@@ -285,11 +295,12 @@ class HelloTriangleApplication {
285295
throw std::runtime_error("Could not find a queue for graphics and present -> terminating");
286296
}
287297

288-
// query for Vulkan 1.3 features
289-
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
298+
// query for required features (Vulkan 1.1 and 1.3)
299+
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
290300
{}, // vk::PhysicalDeviceFeatures2
291-
{.synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
292-
{.extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
301+
{ .shaderDrawParameters = true }, // vk::PhysicalDeviceVulkan11Features
302+
{ .synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
303+
{ .extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
293304
};
294305

295306
// create a Device

0 commit comments

Comments
 (0)