summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2023-11-16 01:23:59 -0600
committeriwubcode <iwubcode@users.noreply.github.com>2023-11-26 16:35:03 -0600
commitfb86c6342e02c7cdc297ecaa7f2eb365c846e741 (patch)
tree92500c0fea377fbc8fb1a7f436b7b209927fa2ab /Source
parent1a2d0882d04446550687424e36a81a2c16a6a00d (diff)
VideoCommon: move texture dump function out of texture cache to its own free function so it can be used elsewhere. Doing this change may also slightly improve performance of this operation
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/DolphinLib.props2
-rw-r--r--Source/Core/VideoCommon/AbstractTexture.cpp2
-rw-r--r--Source/Core/VideoCommon/AbstractTexture.h2
-rw-r--r--Source/Core/VideoCommon/CMakeLists.txt2
-rw-r--r--Source/Core/VideoCommon/TextureCacheBase.cpp49
-rw-r--r--Source/Core/VideoCommon/TextureCacheBase.h2
-rw-r--r--Source/Core/VideoCommon/TextureUtils.cpp41
-rw-r--r--Source/Core/VideoCommon/TextureUtils.h16
8 files changed, 76 insertions, 40 deletions
diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props
index 687dd8285a..19d5be642c 100644
--- a/Source/Core/DolphinLib.props
+++ b/Source/Core/DolphinLib.props
@@ -724,6 +724,7 @@
<ClInclude Include="VideoCommon\TextureDecoder_Util.h" />
<ClInclude Include="VideoCommon\TextureDecoder.h" />
<ClInclude Include="VideoCommon\TextureInfo.h" />
+ <ClInclude Include="VideoCommon\TextureUtils.h" />
<ClInclude Include="VideoCommon\TMEM.h" />
<ClInclude Include="VideoCommon\UberShaderCommon.h" />
<ClInclude Include="VideoCommon\UberShaderPixel.h" />
@@ -1337,6 +1338,7 @@
<ClCompile Include="VideoCommon\TextureConverterShaderGen.cpp" />
<ClCompile Include="VideoCommon\TextureDecoder_Common.cpp" />
<ClCompile Include="VideoCommon\TextureInfo.cpp" />
+ <ClCompile Include="VideoCommon\TextureUtils.cpp" />
<ClCompile Include="VideoCommon\TMEM.cpp" />
<ClCompile Include="VideoCommon\UberShaderCommon.cpp" />
<ClCompile Include="VideoCommon\UberShaderPixel.cpp" />
diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp
index b706772a4f..416af06123 100644
--- a/Source/Core/VideoCommon/AbstractTexture.cpp
+++ b/Source/Core/VideoCommon/AbstractTexture.cpp
@@ -19,7 +19,7 @@ void AbstractTexture::FinishedRendering()
{
}
-bool AbstractTexture::Save(const std::string& filename, unsigned int level, int compression)
+bool AbstractTexture::Save(const std::string& filename, unsigned int level, int compression) const
{
// We can't dump compressed textures currently (it would mean drawing them to a RGBA8
// framebuffer, and saving that). TextureCache does not call Save for custom textures
diff --git a/Source/Core/VideoCommon/AbstractTexture.h b/Source/Core/VideoCommon/AbstractTexture.h
index 3ebf1465fc..6ee9ff4b28 100644
--- a/Source/Core/VideoCommon/AbstractTexture.h
+++ b/Source/Core/VideoCommon/AbstractTexture.h
@@ -38,7 +38,7 @@ public:
MathUtil::Rectangle<int> GetRect() const { return m_config.GetRect(); }
MathUtil::Rectangle<int> GetMipRect(u32 level) const { return m_config.GetMipRect(level); }
bool IsMultisampled() const { return m_config.IsMultisampled(); }
- bool Save(const std::string& filename, unsigned int level, int compression = 6);
+ bool Save(const std::string& filename, unsigned int level, int compression = 6) const;
static bool IsCompressedFormat(AbstractTextureFormat format);
static bool IsDepthFormat(AbstractTextureFormat format);
diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt
index 46f1955524..be1243855e 100644
--- a/Source/Core/VideoCommon/CMakeLists.txt
+++ b/Source/Core/VideoCommon/CMakeLists.txt
@@ -155,6 +155,8 @@ add_library(videocommon
TextureDecoder_Util.h
TextureInfo.cpp
TextureInfo.h
+ TextureUtils.cpp
+ TextureUtils.h
TMEM.cpp
TMEM.h
UberShaderCommon.cpp
diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp
index 50464cce5f..849c032b71 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.cpp
+++ b/Source/Core/VideoCommon/TextureCacheBase.cpp
@@ -52,6 +52,7 @@
#include "VideoCommon/TextureConversionShader.h"
#include "VideoCommon/TextureConverterShaderGen.h"
#include "VideoCommon/TextureDecoder.h"
+#include "VideoCommon/TextureUtils.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
@@ -998,39 +999,6 @@ RcTcacheEntry TextureCacheBase::DoPartialTextureUpdates(RcTcacheEntry& entry_to_
return entry_to_update;
}
-void TextureCacheBase::DumpTexture(RcTcacheEntry& entry, std::string basename, unsigned int level,
- bool is_arbitrary)
-{
- std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID();
-
- // make sure that the directory exists
- if (!File::IsDirectory(szDir))
- File::CreateDir(szDir);
-
- if (is_arbitrary)
- {
- basename += "_arb";
- }
-
- if (level > 0)
- {
- if (!g_ActiveConfig.bDumpMipmapTextures)
- return;
- basename += fmt::format("_mip{}", level);
- }
- else
- {
- if (!g_ActiveConfig.bDumpBaseTextures)
- return;
- }
-
- const std::string filename = fmt::format("{}/{}.png", szDir, basename);
- if (File::Exists(filename))
- return;
-
- entry->texture->Save(filename, level, Config::Get(Config::GFX_TEXTURE_PNG_COMPRESSION_LEVEL));
-}
-
// Helper for checking if a BPMemory TexMode0 register is set to Point
// Filtering modes. This is used to decide whether Anisotropic enhancements
// are (mostly) safe in the VideoBackends.
@@ -1838,12 +1806,21 @@ RcTcacheEntry TextureCacheBase::CreateTextureEntry(
entry->has_arbitrary_mips = arbitrary_mip_detector.HasArbitraryMipmaps(dst_buffer);
- if (g_ActiveConfig.bDumpTextures && !skip_texture_dump)
+ if (g_ActiveConfig.bDumpTextures && !skip_texture_dump && texLevels > 0)
{
const std::string basename = texture_info.CalculateTextureName().GetFullName();
- for (u32 level = 0; level < texLevels; ++level)
+ if (g_ActiveConfig.bDumpBaseTextures)
+ {
+ VideoCommon::TextureUtils::DumpTexture(*entry->texture, basename, 0,
+ entry->has_arbitrary_mips);
+ }
+ if (g_ActiveConfig.bDumpMipmapTextures)
{
- DumpTexture(entry, basename, level, entry->has_arbitrary_mips);
+ for (u32 level = 1; level < texLevels; ++level)
+ {
+ VideoCommon::TextureUtils::DumpTexture(*entry->texture, basename, level,
+ entry->has_arbitrary_mips);
+ }
}
}
}
diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h
index 0271677962..42112d1302 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.h
+++ b/Source/Core/VideoCommon/TextureCacheBase.h
@@ -361,8 +361,6 @@ private:
TLUTFormat tlutfmt);
void StitchXFBCopy(RcTcacheEntry& entry_to_update);
- void DumpTexture(RcTcacheEntry& entry, std::string basename, unsigned int level,
- bool is_arbitrary);
void CheckTempSize(size_t required_size);
RcTcacheEntry AllocateCacheEntry(const TextureConfig& config);
diff --git a/Source/Core/VideoCommon/TextureUtils.cpp b/Source/Core/VideoCommon/TextureUtils.cpp
new file mode 100644
index 0000000000..9445cf16d6
--- /dev/null
+++ b/Source/Core/VideoCommon/TextureUtils.cpp
@@ -0,0 +1,41 @@
+// Copyright 2023 Dolphin Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "VideoCommon/TextureUtils.h"
+
+#include <fmt/format.h>
+
+#include "Common/FileUtil.h"
+#include "Core/Config/GraphicsSettings.h"
+#include "Core/ConfigManager.h"
+
+#include "VideoCommon/AbstractTexture.h"
+
+namespace VideoCommon::TextureUtils
+{
+void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
+ bool is_arbitrary)
+{
+ std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID();
+
+ // make sure that the directory exists
+ if (!File::IsDirectory(szDir))
+ File::CreateDir(szDir);
+
+ if (is_arbitrary)
+ {
+ basename += "_arb";
+ }
+
+ if (level > 0)
+ {
+ basename += fmt::format("_mip{}", level);
+ }
+
+ const std::string filename = fmt::format("{}/{}.png", szDir, basename);
+ if (File::Exists(filename))
+ return;
+
+ texture.Save(filename, level, Config::Get(Config::GFX_TEXTURE_PNG_COMPRESSION_LEVEL));
+}
+} // namespace VideoCommon::TextureUtils
diff --git a/Source/Core/VideoCommon/TextureUtils.h b/Source/Core/VideoCommon/TextureUtils.h
new file mode 100644
index 0000000000..1cfe6c20c1
--- /dev/null
+++ b/Source/Core/VideoCommon/TextureUtils.h
@@ -0,0 +1,16 @@
+// Copyright 2023 Dolphin Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <string>
+
+#include "Common/CommonTypes.h"
+
+class AbstractTexture;
+
+namespace VideoCommon::TextureUtils
+{
+void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
+ bool is_arbitrary);
+}