Skip to content

Commit

Permalink
GPU/TextureCache: Apply 'Dump Replaced Textures' option to background…
Browse files Browse the repository at this point in the history
…s too
  • Loading branch information
stenzek committed Dec 25, 2024
1 parent b03127b commit 8c2fe43
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/core/fullscreen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4682,7 +4682,9 @@ void FullscreenUI::DrawGraphicsSettingsPage()
DrawToggleSetting(
bsi, FSUI_ICONSTR(ICON_FA_FILE, "Dump Replaced Textures"),
FSUI_CSTR("Dumps textures that have replacements already loaded."), "TextureReplacements", "DumpReplacedTextures",
false, texture_cache_enabled && GetEffectiveBoolSetting(bsi, "TextureReplacements", "DumpTextures", false));
false,
(texture_cache_enabled && GetEffectiveBoolSetting(bsi, "TextureReplacements", "DumpTextures", false)) ||
GetEffectiveBoolSetting(bsi, "TextureReplacements", "DumpVRAMWrites", false));

DrawToggleSetting(bsi, FSUI_ICONSTR(ICON_FA_FILE_ALT, "Enable VRAM Write Replacement"),
FSUI_CSTR("Enables the replacement of background textures in supported games."),
Expand Down
27 changes: 20 additions & 7 deletions src/core/gpu_hw_texture_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static std::string GetTextureReplacementDirectory();
static std::string GetTextureDumpDirectory();

static VRAMReplacementName GetVRAMWriteHash(u32 width, u32 height, const void* pixels);
static std::string GetVRAMWriteDumpFilename(const VRAMReplacementName& name);
static std::string GetVRAMWriteDumpPath(const VRAMReplacementName& name);

static bool IsMatchingReplacementPalette(HashType full_palette_hash, GPUTextureMode mode, GPUTexturePaletteReg palette,
const TextureReplacementName& name);
Expand Down Expand Up @@ -812,6 +812,7 @@ void GPUTextureCache::Shutdown()
s_state.vram_write_texture_replacements.clear();
s_state.texture_page_texture_replacements.clear();
s_state.dumped_textures.clear();
s_state.dumped_vram_writes.clear();
}

void GPUTextureCache::SetHashCacheTextureFormat()
Expand Down Expand Up @@ -2689,8 +2690,15 @@ void GPUTextureCache::DumpVRAMWrite(u32 width, u32 height, const void* pixels)

s_state.dumped_vram_writes.insert(name);

const std::string filename = GetVRAMWriteDumpFilename(name);
if (filename.empty() || FileSystem::FileExists(filename.c_str()))
if (!g_gpu_settings.texture_replacements.dump_replaced_textures &&
s_state.vram_replacements.find(name) != s_state.vram_replacements.end())
{
INFO_LOG("Not dumping VRAM write '{}' because it already has a replacement", name.ToString());
return;
}

const std::string path = GetVRAMWriteDumpPath(name);
if (path.empty() || FileSystem::FileExists(path.c_str()))
return;

Image image(width, height, ImageFormat::RGBA8);
Expand All @@ -2711,9 +2719,14 @@ void GPUTextureCache::DumpVRAMWrite(u32 width, u32 height, const void* pixels)
if (s_state.config.dump_vram_write_force_alpha_channel)
image.SetAllPixelsOpaque();

INFO_LOG("Dumping {}x{} VRAM write to '{}'", width, height, Path::GetFileName(filename));
if (!image.SaveToFile(filename.c_str())) [[unlikely]]
ERROR_LOG("Failed to dump {}x{} VRAM write to '{}'", width, height, filename);
INFO_LOG("Dumping {}x{} VRAM write to '{}'", width, height, Path::GetFileName(path));

Error error;
if (!image.SaveToFile(path.c_str(), Image::DEFAULT_SAVE_QUALITY, &error)) [[unlikely]]
{
ERROR_LOG("Failed to dump {}x{} VRAM write to '{}': {}", width, height, Path::GetFileName(path),
error.GetDescription());
}
}

void GPUTextureCache::DumpTexture(TextureReplacementType type, u32 offset_x, u32 offset_y, u32 src_width,
Expand Down Expand Up @@ -3390,7 +3403,7 @@ GPUTextureCache::VRAMReplacementName GPUTextureCache::GetVRAMWriteHash(u32 width
return {hash.low64, hash.high64};
}

std::string GPUTextureCache::GetVRAMWriteDumpFilename(const VRAMReplacementName& name)
std::string GPUTextureCache::GetVRAMWriteDumpPath(const VRAMReplacementName& name)
{
std::string ret;
if (!EnsureGameDirectoryExists())
Expand Down
15 changes: 10 additions & 5 deletions src/duckstation-qt/graphicssettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,11 @@ GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* dialog, QWidget*
connect(m_ui.enableTextureReplacements, &QCheckBox::checkStateChanged, this,
&GraphicsSettingsWidget::onEnableAnyTextureReplacementsChanged);
connect(m_ui.enableTextureDumping, &QCheckBox::checkStateChanged, this,
&GraphicsSettingsWidget::onEnableTextureDumpingChanged);
&GraphicsSettingsWidget::onEnableAnyTextureDumpingChanged);
connect(m_ui.vramWriteReplacement, &QCheckBox::checkStateChanged, this,
&GraphicsSettingsWidget::onEnableAnyTextureReplacementsChanged);
connect(m_ui.vramWriteDumping, &QCheckBox::checkStateChanged, this,
&GraphicsSettingsWidget::onEnableAnyTextureDumpingChanged);
connect(m_ui.textureReplacementOptions, &QPushButton::clicked, this,
&GraphicsSettingsWidget::onTextureReplacementOptionsClicked);

Expand Down Expand Up @@ -1169,16 +1171,19 @@ void GraphicsSettingsWidget::onEnableTextureCacheChanged()
m_ui.enableTextureReplacements->setEnabled(tc_enabled);
m_ui.enableTextureDumping->setEnabled(tc_enabled);
m_ui.alwaysTrackUploads->setEnabled(tc_enabled);
onEnableTextureDumpingChanged();
onEnableAnyTextureDumpingChanged();
onEnableAnyTextureReplacementsChanged();
}

void GraphicsSettingsWidget::onEnableTextureDumpingChanged()
void GraphicsSettingsWidget::onEnableAnyTextureDumpingChanged()
{
const bool tc_enabled = m_dialog->getEffectiveBoolValue("GPU", "EnableTextureCache", false);
const bool dumping_enabled =
tc_enabled && m_dialog->getEffectiveBoolValue("TextureReplacements", "DumpTextures", false);
m_ui.dumpReplacedTextures->setEnabled(dumping_enabled);
(tc_enabled && m_dialog->getEffectiveBoolValue("TextureReplacements", "DumpTextures", false));
const bool background_dumping_enabled =
m_dialog->getEffectiveBoolValue("TextureReplacements", "DumpVRAMWrites", false);
const bool any_dumping_enabled = (dumping_enabled || background_dumping_enabled);
m_ui.dumpReplacedTextures->setEnabled(any_dumping_enabled);
}

void GraphicsSettingsWidget::onEnableAnyTextureReplacementsChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/duckstation-qt/graphicssettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private Q_SLOTS:
void onMediaCaptureAudioEnabledChanged();

void onEnableTextureCacheChanged();
void onEnableTextureDumpingChanged();
void onEnableAnyTextureDumpingChanged();
void onEnableAnyTextureReplacementsChanged();
void onTextureReplacementOptionsClicked();

Expand Down

0 comments on commit 8c2fe43

Please sign in to comment.