video_core: Clear runtime on rasterizer cache flush

* When changing res scale or custom textures a large number of textures will be replaced so better not keep the old ones
This commit is contained in:
GPUCode
2023-02-23 21:35:00 +02:00
parent 8e8097e7c0
commit 94ee7c68fc
7 changed files with 47 additions and 21 deletions

View File

@ -1264,6 +1264,7 @@ void RasterizerCache<T>::UnregisterAll() {
}
texture_cube_cache.clear();
remove_surfaces.clear();
runtime.Clear();
}
template <class T>

View File

@ -96,6 +96,11 @@ TextureRuntime::TextureRuntime(Driver& driver)
TextureRuntime::~TextureRuntime() = default;
void TextureRuntime::Clear() {
framebuffer_cache.clear();
texture_recycler.clear();
}
StagingData TextureRuntime::FindStaging(u32 size, bool upload) {
if (!upload) {
if (size > download_buffer.size()) {

View File

@ -97,6 +97,9 @@ public:
/// Causes a GPU command flush
void Finish() const {}
/// Destroys runtime cached resources
void Clear();
/// Takes back ownership of the allocation for recycling
void Recycle(const HostTextureTag tag, Allocation&& alloc);

View File

@ -32,13 +32,17 @@ RenderpassCache::~RenderpassCache() {
}
}
for (auto& [key, framebuffer] : framebuffers) {
device.destroyFramebuffer(framebuffer);
}
ClearFramebuffers();
device.destroyRenderPass(present_renderpass);
}
void RenderpassCache::ClearFramebuffers() {
for (auto& [key, framebuffer] : framebuffers) {
instance.GetDevice().destroyFramebuffer(framebuffer);
}
framebuffers.clear();
}
void RenderpassCache::EnterRenderpass(Surface* const color, Surface* const depth_stencil,
vk::Rect2D render_area, bool do_clear, vk::ClearValue clear) {
return EnterRenderpass(Framebuffer{color, depth_stencil, render_area}, do_clear, clear);

View File

@ -49,6 +49,9 @@ public:
RenderpassCache(const Instance& instance, Scheduler& scheduler);
~RenderpassCache();
/// Destroys cached framebuffers
void ClearFramebuffers();
/// Begins a new renderpass only when no other renderpass is currently active
void EnterRenderpass(const Framebuffer& framebuffer, bool do_clear = false,
vk::ClearValue clear = {});

View File

@ -130,23 +130,7 @@ TextureRuntime::TextureRuntime(const Instance& instance, Scheduler& scheduler,
}
TextureRuntime::~TextureRuntime() {
VmaAllocator allocator = instance.GetAllocator();
vk::Device device = instance.GetDevice();
device.waitIdle();
for (const auto& [key, alloc] : texture_recycler) {
vmaDestroyImage(allocator, alloc.image, alloc.allocation);
device.destroyImageView(alloc.image_view);
if (alloc.depth_view) {
device.destroyImageView(alloc.depth_view);
device.destroyImageView(alloc.stencil_view);
}
if (alloc.storage_view) {
device.destroyImageView(alloc.storage_view);
}
}
texture_recycler.clear();
Clear();
}
StagingData TextureRuntime::FindStaging(u32 size, bool upload) {
@ -164,6 +148,29 @@ void TextureRuntime::Finish() {
scheduler.Finish();
}
void TextureRuntime::Clear() {
scheduler.Finish();
VmaAllocator allocator = instance.GetAllocator();
vk::Device device = instance.GetDevice();
device.waitIdle();
renderpass_cache.ClearFramebuffers();
for (const auto& [key, alloc] : texture_recycler) {
vmaDestroyImage(allocator, alloc.image, alloc.allocation);
device.destroyImageView(alloc.image_view);
if (alloc.depth_view) {
device.destroyImageView(alloc.depth_view);
device.destroyImageView(alloc.stencil_view);
}
if (alloc.storage_view) {
device.destroyImageView(alloc.storage_view);
}
}
texture_recycler.clear();
}
Allocation TextureRuntime::Allocate(u32 width, u32 height, u32 levels,
VideoCore::PixelFormat format, VideoCore::TextureType type) {
const FormatTraits traits = instance.GetTraits(format);

View File

@ -92,6 +92,9 @@ public:
/// Causes a GPU command flush
void Finish();
/// Destroys runtime cached resources
void Clear();
/// Takes back ownership of the allocation for recycling
void Recycle(const HostTextureTag tag, Allocation&& alloc);