mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-04-26 10:06:17 -05:00
VideoCommon: add a texture pool for resource management
This commit is contained in:
parent
2d21a99205
commit
989ecca235
|
|
@ -756,6 +756,7 @@
|
||||||
<ClInclude Include="VideoCommon\Resources\CustomResourceManager.h" />
|
<ClInclude Include="VideoCommon\Resources\CustomResourceManager.h" />
|
||||||
<ClInclude Include="VideoCommon\Resources\Resource.h" />
|
<ClInclude Include="VideoCommon\Resources\Resource.h" />
|
||||||
<ClInclude Include="VideoCommon\Resources\TextureDataResource.h" />
|
<ClInclude Include="VideoCommon\Resources\TextureDataResource.h" />
|
||||||
|
<ClInclude Include="VideoCommon\Resources\TexturePool.h" />
|
||||||
<ClInclude Include="VideoCommon\ShaderCache.h" />
|
<ClInclude Include="VideoCommon\ShaderCache.h" />
|
||||||
<ClInclude Include="VideoCommon\ShaderCompileUtils.h" />
|
<ClInclude Include="VideoCommon\ShaderCompileUtils.h" />
|
||||||
<ClInclude Include="VideoCommon\ShaderGenCommon.h" />
|
<ClInclude Include="VideoCommon\ShaderGenCommon.h" />
|
||||||
|
|
@ -1409,6 +1410,7 @@
|
||||||
<ClCompile Include="VideoCommon\Resources\CustomResourceManager.cpp" />
|
<ClCompile Include="VideoCommon\Resources\CustomResourceManager.cpp" />
|
||||||
<ClCompile Include="VideoCommon\Resources\Resource.cpp" />
|
<ClCompile Include="VideoCommon\Resources\Resource.cpp" />
|
||||||
<ClCompile Include="VideoCommon\Resources\TextureDataResource.cpp" />
|
<ClCompile Include="VideoCommon\Resources\TextureDataResource.cpp" />
|
||||||
|
<ClCompile Include="VideoCommon\Resources\TexturePool.cpp" />
|
||||||
<ClCompile Include="VideoCommon\ShaderCache.cpp" />
|
<ClCompile Include="VideoCommon\ShaderCache.cpp" />
|
||||||
<ClCompile Include="VideoCommon\ShaderCompileUtils.cpp" />
|
<ClCompile Include="VideoCommon\ShaderCompileUtils.cpp" />
|
||||||
<ClCompile Include="VideoCommon\ShaderGenCommon.cpp" />
|
<ClCompile Include="VideoCommon\ShaderGenCommon.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,8 @@ add_library(videocommon
|
||||||
Resources/Resource.h
|
Resources/Resource.h
|
||||||
Resources/TextureDataResource.cpp
|
Resources/TextureDataResource.cpp
|
||||||
Resources/TextureDataResource.h
|
Resources/TextureDataResource.h
|
||||||
|
Resources/TexturePool.cpp
|
||||||
|
Resources/TexturePool.h
|
||||||
ShaderCache.cpp
|
ShaderCache.cpp
|
||||||
ShaderCache.h
|
ShaderCache.h
|
||||||
ShaderCompileUtils.cpp
|
ShaderCompileUtils.cpp
|
||||||
|
|
|
||||||
43
Source/Core/VideoCommon/Resources/TexturePool.cpp
Normal file
43
Source/Core/VideoCommon/Resources/TexturePool.cpp
Normal file
|
|
@ -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
|
||||||
25
Source/Core/VideoCommon/Resources/TexturePool.h
Normal file
25
Source/Core/VideoCommon/Resources/TexturePool.h
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user