Nvidiaでの修正

守矢諏訪子 <suwako@076.moe>、2026-07-21 22:30
コミット cc5e0bd205c85a80cbc21ef6ff5279e2a23eec60 ・親 b30771d ・ファイルを見る

2個のファイル、+28 -21

@@ -42,13 +42,13 @@
4242 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4343 <ConfigurationType>Application</ConfigurationType>
4444 <UseDebugLibraries>true</UseDebugLibraries>
45- <PlatformToolset>v145</PlatformToolset>
45+ <PlatformToolset>v143</PlatformToolset>
4646 <CharacterSet>Unicode</CharacterSet>
4747 </PropertyGroup>
4848 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4949 <ConfigurationType>Application</ConfigurationType>
5050 <UseDebugLibraries>false</UseDebugLibraries>
51- <PlatformToolset>v145</PlatformToolset>
51+ <PlatformToolset>v143</PlatformToolset>
5252 <WholeProgramOptimization>true</WholeProgramOptimization>
5353 <CharacterSet>Unicode</CharacterSet>
5454 </PropertyGroup>
@@ -1,4 +1,5 @@
1-#define NOMINMAX
1+#define NOMINMAX
2+//#define VULKAN_HPP_NO_EXCEPTIONS
23
34 #pragma region headers
45 #include <util/file.hh>
@@ -31,14 +32,13 @@
3132 vk::PhysicalDevice physicalDevice;
3233 vk::Device device;
3334 vk::SurfaceKHR surface;
34-vk::SwapchainKHR swapChain;
35+vk::SwapchainKHR swapChain = nullptr;
3536 vk::SurfaceFormatKHR swapChainFormat;
3637 vk::SurfaceCapabilitiesKHR surfaceCapabilities;
3738 std::vector<vk::SurfaceFormatKHR> availFormats;
3839 std::vector<vk::PresentModeKHR> availPresentModes;
3940 GLFWwindow *window;
4041
41-
4242 vk::Buffer vertBuf = nullptr;
4343 vk::DeviceMemory vertBufMem = nullptr;
4444
@@ -112,7 +112,7 @@
112112 #pragma endregion
113113
114114 #pragma region swapchain
115-void createSwapChain() {
115+void createSwapChain(vk::SwapchainKHR oldSwapChain = nullptr) {
116116 surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR(surface);
117117 availFormats = physicalDevice.getSurfaceFormatsKHR(surface);
118118 availPresentModes = physicalDevice.getSurfacePresentModesKHR(surface);
@@ -156,6 +156,7 @@
156156 swapChainCreateInfo.compositeAlpha = vk::CompositeAlphaFlagBitsKHR::eOpaque;
157157 swapChainCreateInfo.presentMode = presentMode;
158158 swapChainCreateInfo.clipped = true;
159+ swapChainCreateInfo.oldSwapchain = oldSwapChain;
159160
160161 swapChain = device.createSwapchainKHR(swapChainCreateInfo);
161162 swapChainImages = device.getSwapchainImagesKHR(swapChain);
@@ -190,8 +191,10 @@
190191 for (auto &view : swapChainImageViews) device.destroyImageView(view);
191192 swapChainImageViews.clear();
192193
193- if (swapChain) device.destroySwapchainKHR(swapChain);
194- swapChain = nullptr;
194+ if (swapChain) {
195+ device.destroySwapchainKHR(swapChain);
196+ swapChain = nullptr;
197+ }
195198 }
196199
197200 void recreateSwapChain() {
@@ -203,9 +206,18 @@
203206 }
204207
205208 device.waitIdle();
206- cleanupSwapChain();
207- createSwapChain();
209+
210+ vk::SwapchainKHR oldSwapchain = swapChain;
211+
212+ for (auto &view : swapChainImageViews) device.destroyImageView(view);
213+ swapChainImageViews.clear();
214+
215+ createSwapChain(oldSwapchain);
208216 createImageViews();
217+
218+ if (oldSwapchain) {
219+ device.destroySwapchainKHR(oldSwapchain);
220+ }
209221 }
210222 #pragma endregion
211223
@@ -645,12 +657,6 @@
645657 }
646658 #pragma endregion
647659
648-#pragma region framesInFlight
649-#pragma endregion
650-
651-#pragma region swapChainRecreate
652-#pragma endregion
653-
654660 while (!glfwWindowShouldClose(window)) {
655661 if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
656662 glfwSetWindowShouldClose(window, true);
@@ -659,6 +665,11 @@
659665 glfwPollEvents();
660666
661667 #pragma region drawFrame
668+ if (framebufferResized) {
669+ recreateSwapChain();
670+ framebufferResized = false;
671+ }
672+
662673 auto fenceResult = device.waitForFences(inFlightFences[frameIdx], vk::True, UINT64_MAX);
663674 if (fenceResult != vk::Result::eSuccess) {
664675 assert(false && "フェンスまで待つに失敗。");
@@ -671,14 +682,10 @@
671682 if (acquireRes == vk::Result::eErrorOutOfDateKHR) {
672683 recreateSwapChain();
673684 framebufferResized = false;
674- continue;
675- }
676- if (acquireRes != vk::Result::eSuccess && acquireRes != vk::Result::eSuboptimalKHR) {
685+ } else if (acquireRes != vk::Result::eSuccess && acquireRes != vk::Result::eSuboptimalKHR) {
677686 assert((acquireRes == vk::Result::eTimeout || acquireRes == vk::Result::eNotReady) && "次の画像の受け取りに失敗。");
678687 break;
679688 }
680-
681- device.resetFences(inFlightFences[frameIdx]);
682689
683690 recordCmdBuf(imgIdx);
684691