From b389c6e1037082241a369f53c51e5bf375b5e810 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 23 Jan 2022 16:07:40 +1000 Subject: [PATCH] GS: Only allocate valid page array when needed --- pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 9 +++++---- pcsx2/GS/Renderers/HW/GSTextureCache.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index 85961fd07b..655e2220a5 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -760,9 +760,9 @@ void GSTextureCache::InvalidateVideoMem(const GSOffset& off, const GSVector4i& r } else { - u32* RESTRICT valid = s->m_valid; + u32* RESTRICT valid = s->m_valid.get(); - if (!s->CanPreload()) + if (valid && !s->CanPreload()) { // Invalidate data of input texture if (s->m_repeating) @@ -1729,8 +1729,6 @@ GSTextureCache::Source::Source(GSRenderer* r, const GIFRegTEX0& TEX0, const GIFR memset(m_layer_TEX0, 0, sizeof(m_layer_TEX0)); memset(m_layer_hash, 0, sizeof(m_layer_hash)); - memset(m_valid, 0, sizeof(m_valid)); - m_write.rect = (GSVector4i*)_aligned_malloc(3 * sizeof(GSVector4i), 32); m_write.count = 0; @@ -1776,6 +1774,9 @@ void GSTextureCache::Source::Update(const GSVector4i& rect, int level) u32 blocks = 0; + if (!m_valid) + m_valid = std::make_unique(MAX_PAGES); + if (m_repeating) { for (int y = r.top; y < r.bottom; y += bs.y, bn.nextBlockY()) diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.h b/pcsx2/GS/Renderers/HW/GSTextureCache.h index 7657676227..3fae8eeba3 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.h +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.h @@ -153,8 +153,8 @@ public: public: std::shared_ptr m_palette_obj; + std::unique_ptr m_valid;// each u32 bits map to the 32 blocks of that page GSTexture* m_palette; - u32 m_valid[MAX_PAGES]; // each u32 bits map to the 32 blocks of that page GSVector4i m_valid_rect; u8 m_valid_hashes = 0; u8 m_complete_layers = 0;