diff options
| author | iwubcode <iwubcode@users.noreply.github.com> | 2025-11-02 14:39:33 -0600 |
|---|---|---|
| committer | iwubcode <iwubcode@users.noreply.github.com> | 2025-11-23 11:04:24 -0600 |
| commit | 989ecca23539cc6714daad3625445e30cd3b153a (patch) | |
| tree | 2c6e98b8162d52c100dec0e3a6f639dc7336dd78 /Source/Core/VideoCommon | |
| parent | 2d21a9920577b8c827d056d9a5e03dcf026ae6e1 (diff) | |
VideoCommon: add a texture pool for resource management
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Resources/TexturePool.cpp | 43 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/Resources/TexturePool.h | 25 |
3 files changed, 70 insertions, 0 deletions
diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt index 4830c67113..1b0906ca19 100644 --- a/Source/Core/VideoCommon/CMakeLists.txt +++ b/Source/Core/VideoCommon/CMakeLists.txt @@ -152,6 +152,8 @@ add_library(videocommon Resources/Resource.h Resources/TextureDataResource.cpp Resources/TextureDataResource.h + Resources/TexturePool.cpp + Resources/TexturePool.h ShaderCache.cpp ShaderCache.h ShaderCompileUtils.cpp diff --git a/Source/Core/VideoCommon/Resources/TexturePool.cpp b/Source/Core/VideoCommon/Resources/TexturePool.cpp new file mode 100644 index 0000000000..ce76dc5b24 --- /dev/null +++ b/Source/Core/VideoCommon/Resources/TexturePool.cpp @@ -0,0 +1,43 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoCommon/Resources/TexturePool.h" + +#include "Common/Logging/Log.h" + +#include "VideoCommon/AbstractGfx.h" +#include "VideoCommon/AbstractTexture.h" + +namespace VideoCommon +{ +void TexturePool::Reset() +{ + m_cache.clear(); +} + +std::unique_ptr<AbstractTexture> TexturePool::AllocateTexture(const TextureConfig& config) +{ + const auto iter = m_cache.find(config); + if (iter != m_cache.end()) + { + auto entry = std::move(iter->second); + m_cache.erase(iter); + return entry; + } + + std::unique_ptr<AbstractTexture> texture = g_gfx->CreateTexture(config); + if (!texture) + { + ERROR_LOG_FMT(VIDEO, "Failed to allocate a {}x{}x{} texture", config.width, config.height, + config.layers); + return {}; + } + return texture; +} + +void TexturePool::ReleaseTexture(std::unique_ptr<AbstractTexture> texture) +{ + auto config = texture->GetConfig(); + (void)m_cache.emplace(config, std::move(texture)); +} +} // namespace VideoCommon diff --git a/Source/Core/VideoCommon/Resources/TexturePool.h b/Source/Core/VideoCommon/Resources/TexturePool.h new file mode 100644 index 0000000000..6040a3ae76 --- /dev/null +++ b/Source/Core/VideoCommon/Resources/TexturePool.h @@ -0,0 +1,25 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <memory> +#include <unordered_map> + +#include "VideoCommon/AbstractTexture.h" +#include "VideoCommon/TextureConfig.h" + +namespace VideoCommon +{ +class TexturePool +{ +public: + void Reset(); + + std::unique_ptr<AbstractTexture> AllocateTexture(const TextureConfig& config); + void ReleaseTexture(std::unique_ptr<AbstractTexture> texture); + +private: + std::unordered_multimap<TextureConfig, std::unique_ptr<AbstractTexture>> m_cache; +}; +} // namespace VideoCommon |
