From 8ce8410a5be92e20d66601319ec3b81fe2bf39ea Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 31 Mar 2025 13:03:47 +0300 Subject: [PATCH] vk: Use garbage collector to handle buffer views - Legacy stuff left over from almost a decade ago --- rpcs3/Emu/RSX/VK/VKDraw.cpp | 2 +- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 9 +++------ rpcs3/Emu/RSX/VK/VKGSRenderTypes.hpp | 10 +--------- rpcs3/Emu/RSX/VK/VKPresent.cpp | 3 --- rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp | 12 ++++++++---- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKDraw.cpp b/rpcs3/Emu/RSX/VK/VKDraw.cpp index acff7b7954..1d6b376e7c 100644 --- a/rpcs3/Emu/RSX/VK/VKDraw.cpp +++ b/rpcs3/Emu/RSX/VK/VKDraw.cpp @@ -837,7 +837,7 @@ void VKGSRender::emit_geometry(u32 sub_index) if (m_vertex_layout_storage && m_vertex_layout_storage->info.buffer != m_vertex_layout_ring_info.heap->value) { - m_current_frame->buffer_views_to_clean.push_back(std::move(m_vertex_layout_storage)); + vk::get_gc()->dispose(m_vertex_layout_storage); } vk::clear_status_interrupt(vk::heap_changed); diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index 9a8c293e21..b5ccb885a9 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -834,19 +834,14 @@ VKGSRender::~VKGSRender() { // Return resources back to the owner m_current_frame = &frame_context_storage[m_current_queue_index]; - m_current_frame->swap_storage(m_aux_frame_context); m_current_frame->grab_resources(m_aux_frame_context); } - m_aux_frame_context.buffer_views_to_clean.clear(); - // NOTE: aux_context uses descriptor pools borrowed from the main queues and any allocations will be automatically freed when pool is destroyed for (auto &ctx : frame_context_storage) { vkDestroySemaphore((*m_device), ctx.present_wait_semaphore, nullptr); vkDestroySemaphore((*m_device), ctx.acquire_signal_semaphore, nullptr); - - ctx.buffer_views_to_clean.clear(); } // Textures @@ -2291,7 +2286,9 @@ void VKGSRender::update_vertex_env(u32 id, const vk::vertex_upload_info& vertex_ ensure(m_texbuffer_view_size >= m_vertex_layout_stream_info.range); if (m_vertex_layout_storage) - m_current_frame->buffer_views_to_clean.push_back(std::move(m_vertex_layout_storage)); + { + vk::get_gc()->dispose(m_vertex_layout_storage); + } const usz alloc_addr = m_vertex_layout_stream_info.offset; const usz view_size = (alloc_addr + m_texbuffer_view_size) > m_vertex_layout_ring_info.size() ? m_vertex_layout_ring_info.size() - alloc_addr : m_texbuffer_view_size; diff --git a/rpcs3/Emu/RSX/VK/VKGSRenderTypes.hpp b/rpcs3/Emu/RSX/VK/VKGSRenderTypes.hpp index bc29c0eaf2..acd4c42cb2 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRenderTypes.hpp +++ b/rpcs3/Emu/RSX/VK/VKGSRenderTypes.hpp @@ -182,8 +182,6 @@ namespace vk rsx::flags32_t flags = 0; - std::vector> buffer_views_to_clean; - u32 present_image = -1; command_buffer_chunk* swap_command_buffer = nullptr; @@ -197,16 +195,9 @@ namespace vk acquire_signal_semaphore = other.acquire_signal_semaphore; descriptor_set.swap(other.descriptor_set); flags = other.flags; - heap_snapshot = other.heap_snapshot; } - // Exchange storage (non-copyable) - void swap_storage(frame_context_t& other) - { - std::swap(buffer_views_to_clean, other.buffer_views_to_clean); - } - void tag_frame_end() { heap_snapshot = data_heap_manager::get_heap_snapshot(); @@ -216,6 +207,7 @@ namespace vk void reset_heap_ptrs() { last_frame_sync_time = 0; + heap_snapshot.clear(); } }; diff --git a/rpcs3/Emu/RSX/VK/VKPresent.cpp b/rpcs3/Emu/RSX/VK/VKPresent.cpp index 4f4d868537..0d2912df89 100644 --- a/rpcs3/Emu/RSX/VK/VKPresent.cpp +++ b/rpcs3/Emu/RSX/VK/VKPresent.cpp @@ -232,8 +232,6 @@ void VKGSRender::frame_context_cleanup(vk::frame_context_t *ctx) vk::reset_global_resources(); - ctx->buffer_views_to_clean.clear(); - if (ctx->last_frame_sync_time > m_last_heap_sync_time) { m_last_heap_sync_time = ctx->last_frame_sync_time; @@ -408,7 +406,6 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info) } // Swap aux storage and current frame; aux storage should always be ready for use at all times - m_current_frame->swap_storage(m_aux_frame_context); m_current_frame->grab_resources(m_aux_frame_context); } else if (m_current_frame->swap_command_buffer) diff --git a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp index 526f592eb6..941e0b68d1 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp @@ -320,13 +320,13 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() if (m_persistent_attribute_storage && m_persistent_attribute_storage->info.buffer != m_attrib_ring_info.heap->value) { - m_current_frame->buffer_views_to_clean.push_back(std::move(m_persistent_attribute_storage)); + vk::get_gc()->dispose(m_persistent_attribute_storage); } if (m_volatile_attribute_storage && m_volatile_attribute_storage->info.buffer != m_attrib_ring_info.heap->value) { - m_current_frame->buffer_views_to_clean.push_back(std::move(m_volatile_attribute_storage)); + vk::get_gc()->dispose(m_volatile_attribute_storage); } vk::clear_status_interrupt(vk::heap_changed); @@ -339,7 +339,9 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() ensure(m_texbuffer_view_size >= required.first); // "Incompatible driver (MacOS?)" if (m_persistent_attribute_storage) - m_current_frame->buffer_views_to_clean.push_back(std::move(m_persistent_attribute_storage)); + { + vk::get_gc()->dispose(m_persistent_attribute_storage); + } //View 64M blocks at a time (different drivers will only allow a fixed viewable heap size, 64M should be safe) const usz view_size = (persistent_range_base + m_texbuffer_view_size) > m_attrib_ring_info.size() ? m_attrib_ring_info.size() - persistent_range_base : m_texbuffer_view_size; @@ -355,7 +357,9 @@ vk::vertex_upload_info VKGSRender::upload_vertex_data() ensure(m_texbuffer_view_size >= required.second); // "Incompatible driver (MacOS?)" if (m_volatile_attribute_storage) - m_current_frame->buffer_views_to_clean.push_back(std::move(m_volatile_attribute_storage)); + { + vk::get_gc()->dispose(m_persistent_attribute_storage); + } const usz view_size = (volatile_range_base + m_texbuffer_view_size) > m_attrib_ring_info.size() ? m_attrib_ring_info.size() - volatile_range_base : m_texbuffer_view_size; m_volatile_attribute_storage = std::make_unique(*m_device, m_attrib_ring_info.heap->value, VK_FORMAT_R8_UINT, volatile_range_base, view_size);