summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Byte2022-10-06 20:59:40 +0200
committerGravatar Fernando Sahmkow2022-10-06 21:00:54 +0200
commitdf6dffa30baefd9f1e73399c632ab4e5f6475bab (patch)
tree14803b31b6817294d40d57446f6fa94c5ff3fe9a
parentmaxwell_dma: remove warnings from implemented functionality (diff)
downloadyuzu-df6dffa30baefd9f1e73399c632ab4e5f6475bab.tar.gz
yuzu-df6dffa30baefd9f1e73399c632ab4e5f6475bab.tar.xz
yuzu-df6dffa30baefd9f1e73399c632ab4e5f6475bab.zip
vulkan_blitter: Fix pool allocation double free.
-rw-r--r--src/video_core/renderer_vulkan/vk_blit_screen.cpp13
-rw-r--r--src/video_core/renderer_vulkan/vk_blit_screen.h2
-rw-r--r--src/video_core/vulkan_common/vulkan_wrapper.h20
3 files changed, 10 insertions, 25 deletions
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp
index 444c29f68..cb7fa2078 100644
--- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp
+++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp
@@ -145,6 +145,11 @@ VkSemaphore BlitScreen::Draw(const Tegra::FramebufferConfig& framebuffer,
145 // Finish any pending renderpass 145 // Finish any pending renderpass
146 scheduler.RequestOutsideRenderPassOperationContext(); 146 scheduler.RequestOutsideRenderPassOperationContext();
147 147
148 if (const auto swapchain_images = swapchain.GetImageCount(); swapchain_images != image_count) {
149 image_count = swapchain_images;
150 Recreate();
151 }
152
148 const std::size_t image_index = swapchain.GetImageIndex(); 153 const std::size_t image_index = swapchain.GetImageIndex();
149 154
150 scheduler.Wait(resource_ticks[image_index]); 155 scheduler.Wait(resource_ticks[image_index]);
@@ -448,15 +453,15 @@ vk::Framebuffer BlitScreen::CreateFramebuffer(const VkImageView& image_view, VkE
448 453
449void BlitScreen::CreateStaticResources() { 454void BlitScreen::CreateStaticResources() {
450 CreateShaders(); 455 CreateShaders();
456 CreateSampler();
457}
458
459void BlitScreen::CreateDynamicResources() {
451 CreateSemaphores(); 460 CreateSemaphores();
452 CreateDescriptorPool(); 461 CreateDescriptorPool();
453 CreateDescriptorSetLayout(); 462 CreateDescriptorSetLayout();
454 CreateDescriptorSets(); 463 CreateDescriptorSets();
455 CreatePipelineLayout(); 464 CreatePipelineLayout();
456 CreateSampler();
457}
458
459void BlitScreen::CreateDynamicResources() {
460 CreateRenderPass(); 465 CreateRenderPass();
461 CreateFramebuffers(); 466 CreateFramebuffers();
462 CreateGraphicsPipeline(); 467 CreateGraphicsPipeline();
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.h b/src/video_core/renderer_vulkan/vk_blit_screen.h
index b8c67bef0..29e2ea925 100644
--- a/src/video_core/renderer_vulkan/vk_blit_screen.h
+++ b/src/video_core/renderer_vulkan/vk_blit_screen.h
@@ -109,7 +109,7 @@ private:
109 MemoryAllocator& memory_allocator; 109 MemoryAllocator& memory_allocator;
110 Swapchain& swapchain; 110 Swapchain& swapchain;
111 Scheduler& scheduler; 111 Scheduler& scheduler;
112 const std::size_t image_count; 112 std::size_t image_count;
113 const ScreenInfo& screen_info; 113 const ScreenInfo& screen_info;
114 114
115 vk::ShaderModule vertex_shader; 115 vk::ShaderModule vertex_shader;
diff --git a/src/video_core/vulkan_common/vulkan_wrapper.h b/src/video_core/vulkan_common/vulkan_wrapper.h
index 795f16bfb..1b3f493bd 100644
--- a/src/video_core/vulkan_common/vulkan_wrapper.h
+++ b/src/video_core/vulkan_common/vulkan_wrapper.h
@@ -519,9 +519,7 @@ public:
519 dld{rhs.dld} {} 519 dld{rhs.dld} {}
520 520
521 /// Assign an allocation transfering ownership from another allocation. 521 /// Assign an allocation transfering ownership from another allocation.
522 /// Releases any previously held allocation.
523 PoolAllocations& operator=(PoolAllocations&& rhs) noexcept { 522 PoolAllocations& operator=(PoolAllocations&& rhs) noexcept {
524 Release();
525 allocations = std::move(rhs.allocations); 523 allocations = std::move(rhs.allocations);
526 num = rhs.num; 524 num = rhs.num;
527 device = rhs.device; 525 device = rhs.device;
@@ -530,11 +528,6 @@ public:
530 return *this; 528 return *this;
531 } 529 }
532 530
533 /// Destroys any held allocation.
534 ~PoolAllocations() {
535 Release();
536 }
537
538 /// Returns the number of allocations. 531 /// Returns the number of allocations.
539 std::size_t size() const noexcept { 532 std::size_t size() const noexcept {
540 return num; 533 return num;
@@ -557,19 +550,6 @@ public:
557 } 550 }
558 551
559private: 552private:
560 /// Destroys the held allocations if they exist.
561 void Release() noexcept {
562 if (!allocations) {
563 return;
564 }
565 const Span<AllocationType> span(allocations.get(), num);
566 const VkResult result = Free(device, pool, span, *dld);
567 // There's no way to report errors from a destructor.
568 if (result != VK_SUCCESS) {
569 std::terminate();
570 }
571 }
572
573 std::unique_ptr<AllocationType[]> allocations; 553 std::unique_ptr<AllocationType[]> allocations;
574 std::size_t num = 0; 554 std::size_t num = 0;
575 VkDevice device = nullptr; 555 VkDevice device = nullptr;