Merge pull request #12656 from jordan-woyak/texture-dump-no-dups
VideoCommon: Scan texture dumping directory + subdirectories to not re-dump existing files.
This commit is contained in:
commit
1331332d38
|
@ -52,7 +52,6 @@
|
||||||
#include "VideoCommon/TextureConversionShader.h"
|
#include "VideoCommon/TextureConversionShader.h"
|
||||||
#include "VideoCommon/TextureConverterShaderGen.h"
|
#include "VideoCommon/TextureConverterShaderGen.h"
|
||||||
#include "VideoCommon/TextureDecoder.h"
|
#include "VideoCommon/TextureDecoder.h"
|
||||||
#include "VideoCommon/TextureUtils.h"
|
|
||||||
#include "VideoCommon/VertexManagerBase.h"
|
#include "VideoCommon/VertexManagerBase.h"
|
||||||
#include "VideoCommon/VideoCommon.h"
|
#include "VideoCommon/VideoCommon.h"
|
||||||
#include "VideoCommon/VideoConfig.h"
|
#include "VideoCommon/VideoConfig.h"
|
||||||
|
@ -1818,15 +1817,13 @@ RcTcacheEntry TextureCacheBase::CreateTextureEntry(
|
||||||
const std::string basename = texture_info.CalculateTextureName().GetFullName();
|
const std::string basename = texture_info.CalculateTextureName().GetFullName();
|
||||||
if (g_ActiveConfig.bDumpBaseTextures)
|
if (g_ActiveConfig.bDumpBaseTextures)
|
||||||
{
|
{
|
||||||
VideoCommon::TextureUtils::DumpTexture(*entry->texture, basename, 0,
|
m_texture_dumper.DumpTexture(*entry->texture, basename, 0, entry->has_arbitrary_mips);
|
||||||
entry->has_arbitrary_mips);
|
|
||||||
}
|
}
|
||||||
if (g_ActiveConfig.bDumpMipmapTextures)
|
if (g_ActiveConfig.bDumpMipmapTextures)
|
||||||
{
|
{
|
||||||
for (u32 level = 1; level < texLevels; ++level)
|
for (u32 level = 1; level < texLevels; ++level)
|
||||||
{
|
{
|
||||||
VideoCommon::TextureUtils::DumpTexture(*entry->texture, basename, level,
|
m_texture_dumper.DumpTexture(*entry->texture, basename, level, entry->has_arbitrary_mips);
|
||||||
entry->has_arbitrary_mips);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "VideoCommon/TextureConfig.h"
|
#include "VideoCommon/TextureConfig.h"
|
||||||
#include "VideoCommon/TextureDecoder.h"
|
#include "VideoCommon/TextureDecoder.h"
|
||||||
#include "VideoCommon/TextureInfo.h"
|
#include "VideoCommon/TextureInfo.h"
|
||||||
|
#include "VideoCommon/TextureUtils.h"
|
||||||
#include "VideoCommon/VideoEvents.h"
|
#include "VideoCommon/VideoEvents.h"
|
||||||
|
|
||||||
class AbstractFramebuffer;
|
class AbstractFramebuffer;
|
||||||
|
@ -460,6 +461,8 @@ private:
|
||||||
|
|
||||||
Common::EventHook m_frame_event =
|
Common::EventHook m_frame_event =
|
||||||
AfterFrameEvent::Register([this](Core::System&) { OnFrameEnd(); }, "TextureCache");
|
AfterFrameEvent::Register([this](Core::System&) { OnFrameEnd(); }, "TextureCache");
|
||||||
|
|
||||||
|
VideoCommon::TextureUtils::TextureDumper m_texture_dumper;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::unique_ptr<TextureCacheBase> g_texture_cache;
|
extern std::unique_ptr<TextureCacheBase> g_texture_cache;
|
||||||
|
|
|
@ -5,37 +5,76 @@
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include "Common/FileSearch.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
#include "Core/Config/GraphicsSettings.h"
|
#include "Core/Config/GraphicsSettings.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
|
||||||
#include "VideoCommon/AbstractTexture.h"
|
#include "VideoCommon/AbstractTexture.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::string BuildDumpTextureFilename(std::string basename, u32 level, bool is_arbitrary)
|
||||||
|
{
|
||||||
|
if (is_arbitrary)
|
||||||
|
basename += "_arb";
|
||||||
|
|
||||||
|
if (level > 0)
|
||||||
|
basename += fmt::format("_mip{}", level);
|
||||||
|
|
||||||
|
return basename;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
namespace VideoCommon::TextureUtils
|
namespace VideoCommon::TextureUtils
|
||||||
{
|
{
|
||||||
void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
|
void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
|
||||||
bool is_arbitrary)
|
bool is_arbitrary)
|
||||||
{
|
{
|
||||||
std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID();
|
const std::string dump_dir =
|
||||||
|
File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID();
|
||||||
|
|
||||||
// make sure that the directory exists
|
if (!File::IsDirectory(dump_dir))
|
||||||
if (!File::IsDirectory(szDir))
|
File::CreateDir(dump_dir);
|
||||||
File::CreateDir(szDir);
|
|
||||||
|
|
||||||
if (is_arbitrary)
|
const std::string name = BuildDumpTextureFilename(std::move(basename), level, is_arbitrary);
|
||||||
{
|
const std::string filename = fmt::format("{}/{}.png", dump_dir, name);
|
||||||
basename += "_arb";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level > 0)
|
|
||||||
{
|
|
||||||
basename += fmt::format("_mip{}", level);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string filename = fmt::format("{}/{}.png", szDir, basename);
|
|
||||||
if (File::Exists(filename))
|
if (File::Exists(filename))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
texture.Save(filename, level, Config::Get(Config::GFX_TEXTURE_PNG_COMPRESSION_LEVEL));
|
texture.Save(filename, level, Config::Get(Config::GFX_TEXTURE_PNG_COMPRESSION_LEVEL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureDumper::DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
|
||||||
|
bool is_arbitrary)
|
||||||
|
{
|
||||||
|
const std::string dump_dir =
|
||||||
|
File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID();
|
||||||
|
|
||||||
|
if (m_dumped_textures.empty())
|
||||||
|
{
|
||||||
|
if (!File::IsDirectory(dump_dir))
|
||||||
|
File::CreateDir(dump_dir);
|
||||||
|
|
||||||
|
for (auto& filename : Common::DoFileSearch({dump_dir}, {".png"}, true))
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
SplitPath(filename, nullptr, &name, nullptr);
|
||||||
|
m_dumped_textures.insert(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
NOTICE_LOG_FMT(VIDEO, "Found {} dumped textures that will not be re-dumped.",
|
||||||
|
m_dumped_textures.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string name = BuildDumpTextureFilename(std::move(basename), level, is_arbitrary);
|
||||||
|
const bool file_existed = !m_dumped_textures.insert(name).second;
|
||||||
|
if (file_existed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
texture.Save(fmt::format("{}/{}.png", dump_dir, name), level,
|
||||||
|
Config::Get(Config::GFX_TEXTURE_PNG_COMPRESSION_LEVEL));
|
||||||
|
}
|
||||||
} // namespace VideoCommon::TextureUtils
|
} // namespace VideoCommon::TextureUtils
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
@ -11,6 +12,18 @@ class AbstractTexture;
|
||||||
|
|
||||||
namespace VideoCommon::TextureUtils
|
namespace VideoCommon::TextureUtils
|
||||||
{
|
{
|
||||||
|
class TextureDumper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Only dumps if texture did not already exist anywhere within the dump-textures path.
|
||||||
|
void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
|
||||||
|
bool is_arbitrary);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_set<std::string> m_dumped_textures;
|
||||||
|
};
|
||||||
|
|
||||||
void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
|
void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
|
||||||
bool is_arbitrary);
|
bool is_arbitrary);
|
||||||
}
|
|
||||||
|
} // namespace VideoCommon::TextureUtils
|
||||||
|
|
Loading…
Reference in New Issue