diff options
| author | 2020-03-05 19:38:42 -0500 | |
|---|---|---|
| committer | 2020-03-05 19:38:42 -0500 | |
| commit | 49eff536d08d2fd560bce6d03a8d446a13e4b90a (patch) | |
| tree | cb8c6de0cee3cf9a692ac1a107e5c3bc09ec7e6e /src | |
| parent | Merge pull request #3479 from jroweboy/dont-log-on-no-input (diff) | |
| parent | vk_swapchain: Silence TOCTOU race condition (diff) | |
| download | yuzu-49eff536d08d2fd560bce6d03a8d446a13e4b90a.tar.gz yuzu-49eff536d08d2fd560bce6d03a8d446a13e4b90a.tar.xz yuzu-49eff536d08d2fd560bce6d03a8d446a13e4b90a.zip | |
Merge pull request #3463 from ReinUsesLisp/vk-toctou
vk_swapchain: Silence TOCTOU race condition
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_swapchain.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp index f47b691a8..9e73fa9cd 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.cpp +++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp | |||
| @@ -141,11 +141,6 @@ void VKSwapchain::CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities | |||
| 141 | 141 | ||
| 142 | const vk::SurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats, srgb)}; | 142 | const vk::SurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats, srgb)}; |
| 143 | const vk::PresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)}; | 143 | const vk::PresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)}; |
| 144 | extent = ChooseSwapExtent(capabilities, width, height); | ||
| 145 | |||
| 146 | current_width = extent.width; | ||
| 147 | current_height = extent.height; | ||
| 148 | current_srgb = srgb; | ||
| 149 | 144 | ||
| 150 | u32 requested_image_count{capabilities.minImageCount + 1}; | 145 | u32 requested_image_count{capabilities.minImageCount + 1}; |
| 151 | if (capabilities.maxImageCount > 0 && requested_image_count > capabilities.maxImageCount) { | 146 | if (capabilities.maxImageCount > 0 && requested_image_count > capabilities.maxImageCount) { |
| @@ -153,10 +148,9 @@ void VKSwapchain::CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities | |||
| 153 | } | 148 | } |
| 154 | 149 | ||
| 155 | vk::SwapchainCreateInfoKHR swapchain_ci( | 150 | vk::SwapchainCreateInfoKHR swapchain_ci( |
| 156 | {}, surface, requested_image_count, surface_format.format, surface_format.colorSpace, | 151 | {}, surface, requested_image_count, surface_format.format, surface_format.colorSpace, {}, 1, |
| 157 | extent, 1, vk::ImageUsageFlagBits::eColorAttachment, {}, {}, {}, | 152 | vk::ImageUsageFlagBits::eColorAttachment, {}, {}, {}, capabilities.currentTransform, |
| 158 | capabilities.currentTransform, vk::CompositeAlphaFlagBitsKHR::eOpaque, present_mode, false, | 153 | vk::CompositeAlphaFlagBitsKHR::eOpaque, present_mode, false, {}); |
| 159 | {}); | ||
| 160 | 154 | ||
| 161 | const u32 graphics_family{device.GetGraphicsFamily()}; | 155 | const u32 graphics_family{device.GetGraphicsFamily()}; |
| 162 | const u32 present_family{device.GetPresentFamily()}; | 156 | const u32 present_family{device.GetPresentFamily()}; |
| @@ -169,9 +163,18 @@ void VKSwapchain::CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities | |||
| 169 | swapchain_ci.imageSharingMode = vk::SharingMode::eExclusive; | 163 | swapchain_ci.imageSharingMode = vk::SharingMode::eExclusive; |
| 170 | } | 164 | } |
| 171 | 165 | ||
| 166 | // Request the size again to reduce the possibility of a TOCTOU race condition. | ||
| 167 | const auto updated_capabilities = physical_device.getSurfaceCapabilitiesKHR(surface, dld); | ||
| 168 | swapchain_ci.imageExtent = ChooseSwapExtent(updated_capabilities, width, height); | ||
| 169 | // Don't add code within this and the swapchain creation. | ||
| 172 | const auto dev{device.GetLogical()}; | 170 | const auto dev{device.GetLogical()}; |
| 173 | swapchain = dev.createSwapchainKHRUnique(swapchain_ci, nullptr, dld); | 171 | swapchain = dev.createSwapchainKHRUnique(swapchain_ci, nullptr, dld); |
| 174 | 172 | ||
| 173 | extent = swapchain_ci.imageExtent; | ||
| 174 | current_width = extent.width; | ||
| 175 | current_height = extent.height; | ||
| 176 | current_srgb = srgb; | ||
| 177 | |||
| 175 | images = dev.getSwapchainImagesKHR(*swapchain, dld); | 178 | images = dev.getSwapchainImagesKHR(*swapchain, dld); |
| 176 | image_count = static_cast<u32>(images.size()); | 179 | image_count = static_cast<u32>(images.size()); |
| 177 | image_format = surface_format.format; | 180 | image_format = surface_format.format; |