From a3369637a92e07539013cb5a85f09529747bc414 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 9 Oct 2022 13:39:08 +0100 Subject: [PATCH] Don't entirely wipe out per-index TIC cache efter each execution Keep a copy of the old TIC entry and view even after purge caches and use the execution number to check validity instead, if that doesn't match then just memcmp can be used as opposed to a full hash and map lookup. --- .../gpu/interconnect/maxwell_3d/textures.cpp | 15 ++++++++++----- .../gpu/interconnect/maxwell_3d/textures.h | 9 ++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.cpp index d570175e..dcb40691 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.cpp @@ -28,7 +28,6 @@ namespace skyline::gpu::interconnect::maxwell3d { void Textures::MarkAllDirty() { texturePool.MarkDirty(true); - std::fill(textureHeaderCache.begin(), textureHeaderCache.end(), nullptr); } static texture::Format ConvertTicFormat(TextureImageControl::FormatWord format, bool srgb) { @@ -182,9 +181,15 @@ namespace skyline::gpu::interconnect::maxwell3d { auto textureHeaders{texturePool.UpdateGet(ctx).textureHeaders}; if (textureHeaderCache.size() != textureHeaders.size()) { textureHeaderCache.resize(textureHeaders.size()); - std::fill(textureHeaderCache.begin(), textureHeaderCache.end(), nullptr); - } else if (auto cached{textureHeaderCache[index]}) { - return cached; + std::fill(textureHeaderCache.begin(), textureHeaderCache.end(), CacheEntry{}); + } else if (auto &cached{textureHeaderCache[index]}; cached.view) { + if (cached.executionNumber == ctx.executor.executionNumber) + return cached.view; + + if (cached.tic == textureHeaders[index]) { + cached.executionNumber = ctx.executor.executionNumber; + return cached.view; + } } TextureImageControl &textureHeader{textureHeaders[index]}; @@ -310,7 +315,7 @@ namespace skyline::gpu::interconnect::maxwell3d { texture = ctx.executor.AcquireTextureManager().FindOrCreate(guest, ctx.executor.tag); } - textureHeaderCache[index] = texture.get(); + textureHeaderCache[index] = {textureHeader, texture.get(), ctx.executor.executionNumber}; return texture.get(); } } \ No newline at end of file diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.h b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.h index 3367d1e1..26202f13 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/textures.h @@ -36,7 +36,12 @@ namespace skyline::gpu::interconnect::maxwell3d { tsl::robin_map, util::ObjectHash> textureHeaderStore; - std::vector textureHeaderCache; + struct CacheEntry { + TextureImageControl tic; + TextureView *view; + u32 executionNumber; + }; + std::vector textureHeaderCache; public: Textures(DirtyManager &manager, const TexturePoolState::EngineRegisters &engine); @@ -44,5 +49,7 @@ namespace skyline::gpu::interconnect::maxwell3d { void MarkAllDirty(); TextureView *GetTexture(InterconnectContext &ctx, u32 index, Shader::TextureType shaderType); + + Shader::TextureType GetTextureType(InterconnectContext &ctx, u32 index); }; }