diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index bd0fd38ae..3a5840207 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -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."), diff --git a/src/core/gpu_hw_texture_cache.cpp b/src/core/gpu_hw_texture_cache.cpp index 8dbf665ef..81004ca78 100644 --- a/src/core/gpu_hw_texture_cache.cpp +++ b/src/core/gpu_hw_texture_cache.cpp @@ -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); @@ -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() @@ -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); @@ -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, @@ -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()) diff --git a/src/duckstation-qt/graphicssettingswidget.cpp b/src/duckstation-qt/graphicssettingswidget.cpp index ec5eedb04..f651e0500 100644 --- a/src/duckstation-qt/graphicssettingswidget.cpp +++ b/src/duckstation-qt/graphicssettingswidget.cpp @@ -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); @@ -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() diff --git a/src/duckstation-qt/graphicssettingswidget.h b/src/duckstation-qt/graphicssettingswidget.h index d1ae58060..f86913901 100644 --- a/src/duckstation-qt/graphicssettingswidget.h +++ b/src/duckstation-qt/graphicssettingswidget.h @@ -40,7 +40,7 @@ private Q_SLOTS: void onMediaCaptureAudioEnabledChanged(); void onEnableTextureCacheChanged(); - void onEnableTextureDumpingChanged(); + void onEnableAnyTextureDumpingChanged(); void onEnableAnyTextureReplacementsChanged(); void onTextureReplacementOptionsClicked();