Nvidiaでの修正
守矢諏訪子 <suwako@076.moe>、2026-07-21 22:30
コミット cc5e0bd205c85a80cbc21ef6ff5279e2a23eec60
・親 b30771d
・ファイルを見る
2個のファイル、+28 -21
| @@ -42,13 +42,13 @@ | ||
| 42 | 42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
| 43 | 43 | <ConfigurationType>Application</ConfigurationType> |
| 44 | 44 | <UseDebugLibraries>true</UseDebugLibraries> |
| 45 | - <PlatformToolset>v145</PlatformToolset> | |
| 45 | + <PlatformToolset>v143</PlatformToolset> | |
| 46 | 46 | <CharacterSet>Unicode</CharacterSet> |
| 47 | 47 | </PropertyGroup> |
| 48 | 48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
| 49 | 49 | <ConfigurationType>Application</ConfigurationType> |
| 50 | 50 | <UseDebugLibraries>false</UseDebugLibraries> |
| 51 | - <PlatformToolset>v145</PlatformToolset> | |
| 51 | + <PlatformToolset>v143</PlatformToolset> | |
| 52 | 52 | <WholeProgramOptimization>true</WholeProgramOptimization> |
| 53 | 53 | <CharacterSet>Unicode</CharacterSet> |
| 54 | 54 | </PropertyGroup> |
| @@ -1,4 +1,5 @@ | ||
| 1 | -#define NOMINMAX | |
| 1 | +#define NOMINMAX | |
| 2 | +//#define VULKAN_HPP_NO_EXCEPTIONS | |
| 2 | 3 | |
| 3 | 4 | #pragma region headers |
| 4 | 5 | #include <util/file.hh> |
| @@ -31,14 +32,13 @@ | ||
| 31 | 32 | vk::PhysicalDevice physicalDevice; |
| 32 | 33 | vk::Device device; |
| 33 | 34 | vk::SurfaceKHR surface; |
| 34 | -vk::SwapchainKHR swapChain; | |
| 35 | +vk::SwapchainKHR swapChain = nullptr; | |
| 35 | 36 | vk::SurfaceFormatKHR swapChainFormat; |
| 36 | 37 | vk::SurfaceCapabilitiesKHR surfaceCapabilities; |
| 37 | 38 | std::vector<vk::SurfaceFormatKHR> availFormats; |
| 38 | 39 | std::vector<vk::PresentModeKHR> availPresentModes; |
| 39 | 40 | GLFWwindow *window; |
| 40 | 41 | |
| 41 | - | |
| 42 | 42 | vk::Buffer vertBuf = nullptr; |
| 43 | 43 | vk::DeviceMemory vertBufMem = nullptr; |
| 44 | 44 | |
| @@ -112,7 +112,7 @@ | ||
| 112 | 112 | #pragma endregion |
| 113 | 113 | |
| 114 | 114 | #pragma region swapchain |
| 115 | -void createSwapChain() { | |
| 115 | +void createSwapChain(vk::SwapchainKHR oldSwapChain = nullptr) { | |
| 116 | 116 | surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR(surface); |
| 117 | 117 | availFormats = physicalDevice.getSurfaceFormatsKHR(surface); |
| 118 | 118 | availPresentModes = physicalDevice.getSurfacePresentModesKHR(surface); |
| @@ -156,6 +156,7 @@ | ||
| 156 | 156 | swapChainCreateInfo.compositeAlpha = vk::CompositeAlphaFlagBitsKHR::eOpaque; |
| 157 | 157 | swapChainCreateInfo.presentMode = presentMode; |
| 158 | 158 | swapChainCreateInfo.clipped = true; |
| 159 | + swapChainCreateInfo.oldSwapchain = oldSwapChain; | |
| 159 | 160 | |
| 160 | 161 | swapChain = device.createSwapchainKHR(swapChainCreateInfo); |
| 161 | 162 | swapChainImages = device.getSwapchainImagesKHR(swapChain); |
| @@ -190,8 +191,10 @@ | ||
| 190 | 191 | for (auto &view : swapChainImageViews) device.destroyImageView(view); |
| 191 | 192 | swapChainImageViews.clear(); |
| 192 | 193 | |
| 193 | - if (swapChain) device.destroySwapchainKHR(swapChain); | |
| 194 | - swapChain = nullptr; | |
| 194 | + if (swapChain) { | |
| 195 | + device.destroySwapchainKHR(swapChain); | |
| 196 | + swapChain = nullptr; | |
| 197 | + } | |
| 195 | 198 | } |
| 196 | 199 | |
| 197 | 200 | void recreateSwapChain() { |
| @@ -203,9 +206,18 @@ | ||
| 203 | 206 | } |
| 204 | 207 | |
| 205 | 208 | 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); | |
| 208 | 216 | createImageViews(); |
| 217 | + | |
| 218 | + if (oldSwapchain) { | |
| 219 | + device.destroySwapchainKHR(oldSwapchain); | |
| 220 | + } | |
| 209 | 221 | } |
| 210 | 222 | #pragma endregion |
| 211 | 223 | |
| @@ -645,12 +657,6 @@ | ||
| 645 | 657 | } |
| 646 | 658 | #pragma endregion |
| 647 | 659 | |
| 648 | -#pragma region framesInFlight | |
| 649 | -#pragma endregion | |
| 650 | - | |
| 651 | -#pragma region swapChainRecreate | |
| 652 | -#pragma endregion | |
| 653 | - | |
| 654 | 660 | while (!glfwWindowShouldClose(window)) { |
| 655 | 661 | if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { |
| 656 | 662 | glfwSetWindowShouldClose(window, true); |
| @@ -659,6 +665,11 @@ | ||
| 659 | 665 | glfwPollEvents(); |
| 660 | 666 | |
| 661 | 667 | #pragma region drawFrame |
| 668 | + if (framebufferResized) { | |
| 669 | + recreateSwapChain(); | |
| 670 | + framebufferResized = false; | |
| 671 | + } | |
| 672 | + | |
| 662 | 673 | auto fenceResult = device.waitForFences(inFlightFences[frameIdx], vk::True, UINT64_MAX); |
| 663 | 674 | if (fenceResult != vk::Result::eSuccess) { |
| 664 | 675 | assert(false && "フェンスまで待つに失敗。"); |
| @@ -671,14 +682,10 @@ | ||
| 671 | 682 | if (acquireRes == vk::Result::eErrorOutOfDateKHR) { |
| 672 | 683 | recreateSwapChain(); |
| 673 | 684 | 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) { | |
| 677 | 686 | assert((acquireRes == vk::Result::eTimeout || acquireRes == vk::Result::eNotReady) && "次の画像の受け取りに失敗。"); |
| 678 | 687 | break; |
| 679 | 688 | } |
| 680 | - | |
| 681 | - device.resetFences(inFlightFences[frameIdx]); | |
| 682 | 689 | |
| 683 | 690 | recordCmdBuf(imgIdx); |
| 684 | 691 |