Skip to content

Commit e37bb22

Browse files
committed
Bring changes forward for resize.
1 parent fb7a5c2 commit e37bb22

18 files changed

+276
-335
lines changed

attachments/15_hello_triangle.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,7 @@ class HelloTriangleApplication {
101101
void mainLoop() {
102102
while (!glfwWindowShouldClose(window)) {
103103
glfwPollEvents();
104-
try {
105-
drawFrame();
106-
} catch (const vk::SystemError& e) {
107-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
108-
// Swapchain is out of date, this can happen during window close
109-
// Just ignore and continue to close
110-
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
111-
} else {
112-
// Rethrow other errors
113-
throw;
114-
}
115-
}
104+
drawFrame();
116105
}
117106

118107
device.waitIdle();

attachments/16_frames_in_flight.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,7 @@ class HelloTriangleApplication {
105105
void mainLoop() {
106106
while (!glfwWindowShouldClose(window)) {
107107
glfwPollEvents();
108-
try {
109-
drawFrame();
110-
} catch (const vk::SystemError& e) {
111-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
112-
// Swapchain is out of date, this can happen during window close
113-
// Just ignore and continue to close
114-
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
115-
} else {
116-
// Rethrow other errors
117-
throw;
118-
}
119-
}
108+
drawFrame();
120109
}
121110

122111
device.waitIdle();

attachments/17_swap_chain_recreation.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class HelloTriangleApplication {
131131
}
132132

133133
void recreateSwapChain() {
134-
framebufferResized = false;
135134
int width = 0, height = 0;
136135
glfwGetFramebufferSize(window, &width, &height);
137136
while (width == 0 || height == 0) {
@@ -144,13 +143,6 @@ class HelloTriangleApplication {
144143
cleanupSwapChain();
145144
createSwapChain();
146145
createImageViews();
147-
// Recreate dependent objects in case format or extent changed
148-
graphicsPipeline = nullptr;
149-
createGraphicsPipeline();
150-
createSyncObjects();
151-
// Reset indices to avoid out-of-range after swapchain resize
152-
semaphoreIndex = 0;
153-
currentFrame = 0;
154146
}
155147

156148
void createInstance() {

attachments/18_vertex_input.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class HelloTriangleApplication {
108108
glfwInit();
109109

110110
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
111+
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
111112

112113
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
113114
glfwSetWindowUserPointer(window, this);
@@ -136,18 +137,7 @@ class HelloTriangleApplication {
136137
void mainLoop() {
137138
while (!glfwWindowShouldClose(window)) {
138139
glfwPollEvents();
139-
try {
140-
drawFrame();
141-
} catch (const vk::SystemError& e) {
142-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
143-
// Swapchain is out of date, this can happen during window close
144-
// Just ignore and continue to close
145-
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
146-
} else {
147-
// Rethrow other errors
148-
throw;
149-
}
150-
}
140+
drawFrame();
151141
}
152142

153143
device.waitIdle();
@@ -274,8 +264,9 @@ class HelloTriangleApplication {
274264
{ return strcmp( availableDeviceExtension.extensionName, requiredDeviceExtension ) == 0; } );
275265
} );
276266

277-
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
278-
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
267+
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
268+
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan11Features>().shaderDrawParameters &&
269+
features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
279270
features.template get<vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>().extendedDynamicState;
280271

281272
return supportsVulkan1_3 && supportsGraphics && supportsAllRequiredExtensions && supportsRequiredFeatures;
@@ -309,11 +300,12 @@ class HelloTriangleApplication {
309300
throw std::runtime_error("Could not find a queue for graphics and present -> terminating");
310301
}
311302

312-
// query for Vulkan 1.3 features
313-
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
303+
// query for required features (Vulkan 1.1 and 1.3)
304+
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
314305
{}, // vk::PhysicalDeviceFeatures2
315-
{.synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
316-
{.extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
306+
{ .shaderDrawParameters = true }, // vk::PhysicalDeviceVulkan11Features
307+
{ .synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
308+
{ .extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
317309
};
318310

319311
// create a Device
@@ -553,11 +545,9 @@ class HelloTriangleApplication {
553545
}
554546
} catch (const vk::SystemError& e) {
555547
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
556-
// Swapchain is out of date, this can happen during window close
557-
// Just ignore and continue to close
558-
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
548+
recreateSwapChain();
549+
return;
559550
} else {
560-
// Rethrow other errors
561551
throw;
562552
}
563553
}

attachments/19_vertex_buffer.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class HelloTriangleApplication {
111111
glfwInit();
112112

113113
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
114+
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
114115

115116
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
116117
glfwSetWindowUserPointer(window, this);
@@ -140,18 +141,7 @@ class HelloTriangleApplication {
140141
void mainLoop() {
141142
while (!glfwWindowShouldClose(window)) {
142143
glfwPollEvents();
143-
try {
144-
drawFrame();
145-
} catch (const vk::SystemError& e) {
146-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
147-
// Swapchain is out of date, this can happen during window close
148-
// Just ignore and continue to close
149-
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
150-
} else {
151-
// Rethrow other errors
152-
throw;
153-
}
154-
}
144+
drawFrame();
155145
}
156146

157147
device.waitIdle();
@@ -278,8 +268,9 @@ class HelloTriangleApplication {
278268
{ return strcmp( availableDeviceExtension.extensionName, requiredDeviceExtension ) == 0; } );
279269
} );
280270

281-
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
282-
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
271+
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
272+
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan11Features>().shaderDrawParameters &&
273+
features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
283274
features.template get<vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>().extendedDynamicState;
284275

285276
return supportsVulkan1_3 && supportsGraphics && supportsAllRequiredExtensions && supportsRequiredFeatures;
@@ -313,11 +304,12 @@ class HelloTriangleApplication {
313304
throw std::runtime_error("Could not find a queue for graphics and present -> terminating");
314305
}
315306

316-
// query for Vulkan 1.3 features
317-
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
307+
// query for required features (Vulkan 1.1 and 1.3)
308+
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
318309
{}, // vk::PhysicalDeviceFeatures2
319-
{.synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
320-
{.extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
310+
{ .shaderDrawParameters = true }, // vk::PhysicalDeviceVulkan11Features
311+
{ .synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
312+
{ .extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
321313
};
322314

323315
// create a Device
@@ -353,6 +345,8 @@ class HelloTriangleApplication {
353345
}
354346

355347
void createImageViews() {
348+
swapChainImageViews.clear();
349+
356350
vk::ImageViewCreateInfo imageViewCreateInfo{ .viewType = vk::ImageViewType::e2D, .format = swapChainImageFormat,
357351
.subresourceRange = { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } };
358352
for ( auto image : swapChainImages )
@@ -583,11 +577,9 @@ class HelloTriangleApplication {
583577
}
584578
} catch (const vk::SystemError& e) {
585579
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
586-
// Swapchain is out of date, this can happen during window close
587-
// Just ignore and continue to close
588-
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
580+
recreateSwapChain();
581+
return;
589582
} else {
590-
// Rethrow other errors
591583
throw;
592584
}
593585
}

attachments/20_staging_buffer.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class HelloTriangleApplication {
111111
glfwInit();
112112

113113
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
114+
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
114115

115116
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
116117
glfwSetWindowUserPointer(window, this);
@@ -140,18 +141,7 @@ class HelloTriangleApplication {
140141
void mainLoop() {
141142
while (!glfwWindowShouldClose(window)) {
142143
glfwPollEvents();
143-
try {
144-
drawFrame();
145-
} catch (const vk::SystemError& e) {
146-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
147-
// Swapchain is out of date, this can happen during window close
148-
// Just ignore and continue to close
149-
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
150-
} else {
151-
// Rethrow other errors
152-
throw;
153-
}
154-
}
144+
drawFrame();
155145
}
156146

157147
device.waitIdle();
@@ -278,8 +268,9 @@ class HelloTriangleApplication {
278268
{ return strcmp( availableDeviceExtension.extensionName, requiredDeviceExtension ) == 0; } );
279269
} );
280270

281-
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
282-
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
271+
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
272+
bool supportsRequiredFeatures = features.template get<vk::PhysicalDeviceVulkan11Features>().shaderDrawParameters &&
273+
features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
283274
features.template get<vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>().extendedDynamicState;
284275

285276
return supportsVulkan1_3 && supportsGraphics && supportsAllRequiredExtensions && supportsRequiredFeatures;
@@ -313,11 +304,12 @@ class HelloTriangleApplication {
313304
throw std::runtime_error("Could not find a queue for graphics and present -> terminating");
314305
}
315306

316-
// query for Vulkan 1.3 features
317-
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
307+
// query for required features (Vulkan 1.1 and 1.3)
308+
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
318309
{}, // vk::PhysicalDeviceFeatures2
319-
{.synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
320-
{.extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
310+
{ .shaderDrawParameters = true }, // vk::PhysicalDeviceVulkan11Features
311+
{ .synchronization2 = true, .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
312+
{ .extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
321313
};
322314

323315
// create a Device
@@ -353,6 +345,8 @@ class HelloTriangleApplication {
353345
}
354346

355347
void createImageViews() {
348+
swapChainImageViews.clear();
349+
356350
vk::ImageViewCreateInfo imageViewCreateInfo{ .viewType = vk::ImageViewType::e2D, .format = swapChainImageFormat,
357351
.subresourceRange = { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } };
358352
for ( auto image : swapChainImages )
@@ -602,11 +596,9 @@ class HelloTriangleApplication {
602596
}
603597
} catch (const vk::SystemError& e) {
604598
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
605-
// Swapchain is out of date, this can happen during window close
606-
// Just ignore and continue to close
607-
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
599+
recreateSwapChain();
600+
return;
608601
} else {
609-
// Rethrow other errors
610602
throw;
611603
}
612604
}

0 commit comments

Comments
 (0)