mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-15 02:44:41 +00:00
Qt: Eliminate OSD from debug RAM dumping
This commit is contained in:
@@ -2030,27 +2030,28 @@ u8 GPU::CalculateAutomaticResolutionScale() const
|
||||
return Truncate8(scale);
|
||||
}
|
||||
|
||||
bool GPU::DumpVRAMToFile(const char* filename)
|
||||
bool GPU::DumpVRAMToFile(std::string path, Error* error)
|
||||
{
|
||||
ReadVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
|
||||
|
||||
const char* extension = std::strrchr(filename, '.');
|
||||
if (extension && StringUtil::Strcasecmp(extension, ".png") == 0)
|
||||
const std::string_view extension = Path::GetExtension(path);
|
||||
if (StringUtil::EqualNoCase(extension, "png"))
|
||||
{
|
||||
return DumpVRAMToFile(filename, VRAM_WIDTH, VRAM_HEIGHT, sizeof(u16) * VRAM_WIDTH, g_vram, true);
|
||||
return DumpVRAMToFile(std::move(path), VRAM_WIDTH, VRAM_HEIGHT, sizeof(u16) * VRAM_WIDTH, g_vram, true, error);
|
||||
}
|
||||
else if (extension && StringUtil::Strcasecmp(extension, ".bin") == 0)
|
||||
else if (StringUtil::EqualNoCase(extension, "bin"))
|
||||
{
|
||||
return FileSystem::WriteBinaryFile(filename, g_vram, VRAM_WIDTH * VRAM_HEIGHT * sizeof(u16));
|
||||
return FileSystem::WriteAtomicRenamedFile(std::move(path), g_vram, VRAM_WIDTH * VRAM_HEIGHT * sizeof(u16), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG("Unknown extension: '{}'", filename);
|
||||
Error::SetStringFmt(error, "Unknown extension: '{}'", extension);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool GPU::DumpVRAMToFile(const char* filename, u32 width, u32 height, u32 stride, const void* buffer, bool remove_alpha)
|
||||
bool GPU::DumpVRAMToFile(std::string path, u32 width, u32 height, u32 stride, const void* buffer, bool remove_alpha,
|
||||
Error* error /* = nullptr */)
|
||||
{
|
||||
Image image(width, height, ImageFormat::RGBA8);
|
||||
|
||||
@@ -2074,7 +2075,7 @@ bool GPU::DumpVRAMToFile(const char* filename, u32 width, u32 height, u32 stride
|
||||
ptr_in += stride;
|
||||
}
|
||||
|
||||
return image.SaveToFile(filename);
|
||||
return image.SaveToFile(path.c_str(), Image::DEFAULT_SAVE_QUALITY, error);
|
||||
}
|
||||
|
||||
void GPU::DrawDebugStateWindow(float scale)
|
||||
|
||||
@@ -228,7 +228,7 @@ public:
|
||||
void FrameDoneEvent(TickCount ticks);
|
||||
|
||||
// Dumps raw VRAM to a file.
|
||||
bool DumpVRAMToFile(const char* filename);
|
||||
bool DumpVRAMToFile(std::string path, Error* error);
|
||||
|
||||
// Kicks the current frame to the backend for display.
|
||||
void UpdateDisplay(bool submit_frame);
|
||||
@@ -257,8 +257,8 @@ private:
|
||||
}
|
||||
ALWAYS_INLINE static constexpr TickCount SystemTicksToGPUTicks(TickCount sysclk_ticks) { return sysclk_ticks << 1; }
|
||||
|
||||
static bool DumpVRAMToFile(const char* filename, u32 width, u32 height, u32 stride, const void* buffer,
|
||||
bool remove_alpha);
|
||||
static bool DumpVRAMToFile(std::string path, u32 width, u32 height, u32 stride, const void* buffer, bool remove_alpha,
|
||||
Error* error = nullptr);
|
||||
|
||||
void SoftReset();
|
||||
void ClearDisplay();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/gsvector_formatter.h"
|
||||
#include "common/log.h"
|
||||
#include "common/path.h"
|
||||
#include "common/string_util.h"
|
||||
|
||||
LOG_CHANNEL(GPU);
|
||||
@@ -1017,8 +1018,10 @@ void GPU::FinishVRAMWrite()
|
||||
{
|
||||
if (g_settings.gpu_dump_cpu_to_vram_copies)
|
||||
{
|
||||
DumpVRAMToFile(TinyString::from_format("cpu_to_vram_copy_{}.png", s_cpu_to_vram_dump_id++), m_vram_transfer.width,
|
||||
m_vram_transfer.height, sizeof(u16) * m_vram_transfer.width, m_blit_buffer.data(), true);
|
||||
DumpVRAMToFile(fmt::format("{}" FS_OSPATH_SEPARATOR_STR "cpu_to_vram_copy_{}.png", EmuFolders::DataRoot,
|
||||
s_cpu_to_vram_dump_id++),
|
||||
m_vram_transfer.width, m_vram_transfer.height, sizeof(u16) * m_vram_transfer.width,
|
||||
m_blit_buffer.data(), true);
|
||||
}
|
||||
|
||||
UpdateVRAM(m_vram_transfer.x, m_vram_transfer.y, m_vram_transfer.width, m_vram_transfer.height,
|
||||
@@ -1075,8 +1078,9 @@ bool GPU::HandleCopyRectangleVRAMToCPUCommand()
|
||||
|
||||
if (g_settings.gpu_dump_vram_to_cpu_copies)
|
||||
{
|
||||
DumpVRAMToFile(TinyString::from_format("vram_to_cpu_copy_{}.png", s_vram_to_cpu_dump_id++), m_vram_transfer.width,
|
||||
m_vram_transfer.height, sizeof(u16) * VRAM_WIDTH,
|
||||
DumpVRAMToFile(fmt::format("{}" FS_OSPATH_SEPARATOR_STR "vram_to_cpu_copy_{}.png", EmuFolders::DataRoot,
|
||||
s_vram_to_cpu_dump_id++),
|
||||
m_vram_transfer.width, m_vram_transfer.height, sizeof(u16) * VRAM_WIDTH,
|
||||
&g_vram[m_vram_transfer.y * VRAM_WIDTH + m_vram_transfer.x], true);
|
||||
}
|
||||
|
||||
|
||||
@@ -4041,28 +4041,37 @@ void System::UpdateMultitaps()
|
||||
}
|
||||
}
|
||||
|
||||
bool System::DumpRAM(const char* path)
|
||||
bool System::DumpRAM(std::string path, Error* error)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
Error::SetStringView(error, "Invalid system state.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return FileSystem::WriteBinaryFile(path, Bus::g_unprotected_ram, Bus::g_ram_size);
|
||||
return FileSystem::WriteAtomicRenamedFile(std::move(path), Bus::g_unprotected_ram, Bus::g_ram_size, error);
|
||||
}
|
||||
|
||||
bool System::DumpVRAM(const char* path)
|
||||
bool System::DumpVRAM(std::string path, Error* error)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
Error::SetStringView(error, "Invalid system state.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return g_gpu.DumpVRAMToFile(path);
|
||||
return g_gpu.DumpVRAMToFile(path, error);
|
||||
}
|
||||
|
||||
bool System::DumpSPURAM(const char* path)
|
||||
bool System::DumpSPURAM(std::string path, Error* error)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
Error::SetStringView(error, "Invalid system state.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return FileSystem::WriteBinaryFile(path, SPU::GetRAM().data(), SPU::RAM_SIZE);
|
||||
return FileSystem::WriteAtomicRenamedFile(std::move(path), SPU::GetRAM(), error);
|
||||
}
|
||||
|
||||
bool System::HasMedia()
|
||||
|
||||
@@ -312,13 +312,13 @@ bool IsSavingMemoryCards();
|
||||
void SwapMemoryCards();
|
||||
|
||||
/// Dumps RAM to a file.
|
||||
bool DumpRAM(const char* path);
|
||||
bool DumpRAM(std::string path, Error* error);
|
||||
|
||||
/// Dumps video RAM to a file.
|
||||
bool DumpVRAM(const char* path);
|
||||
bool DumpVRAM(std::string path, Error* error);
|
||||
|
||||
/// Dumps sound RAM to a file.
|
||||
bool DumpSPURAM(const char* path);
|
||||
bool DumpSPURAM(std::string path, Error* error);
|
||||
|
||||
bool HasMedia();
|
||||
std::string GetMediaPath();
|
||||
|
||||
@@ -1606,11 +1606,18 @@ void EmuThread::dumpRAM(const QString& path)
|
||||
return;
|
||||
}
|
||||
|
||||
Error error;
|
||||
const std::string path_str = path.toStdString();
|
||||
if (System::DumpRAM(path_str.c_str()))
|
||||
Host::AddOSDMessage(OSDMessageType::Info, fmt::format("RAM dumped to '{}'", path_str));
|
||||
if (System::DumpRAM(path_str.c_str(), &error))
|
||||
{
|
||||
emit statusMessage(QStringLiteral("RAM dumped to %1.").arg(path));
|
||||
}
|
||||
else
|
||||
Host::ReportErrorAsync("Error", fmt::format("Failed to dump RAM to '{}'", path_str));
|
||||
{
|
||||
emit errorReported(
|
||||
QStringLiteral("Error"),
|
||||
QStringLiteral("Failed to dump RAM to %1: %2").arg(path).arg(QString::fromStdString(error.GetDescription())));
|
||||
}
|
||||
}
|
||||
|
||||
void EmuThread::dumpVRAM(const QString& path)
|
||||
@@ -1621,11 +1628,18 @@ void EmuThread::dumpVRAM(const QString& path)
|
||||
return;
|
||||
}
|
||||
|
||||
Error error;
|
||||
const std::string path_str = path.toStdString();
|
||||
if (System::DumpVRAM(path_str.c_str()))
|
||||
Host::AddOSDMessage(OSDMessageType::Info, fmt::format("VRAM dumped to '{}'", path_str));
|
||||
if (System::DumpVRAM(path_str.c_str(), &error))
|
||||
{
|
||||
emit statusMessage(QStringLiteral("VRAM dumped to %1.").arg(path));
|
||||
}
|
||||
else
|
||||
Host::ReportErrorAsync("Error", fmt::format("Failed to dump VRAM to '{}'", path_str));
|
||||
{
|
||||
emit errorReported(
|
||||
QStringLiteral("Error"),
|
||||
QStringLiteral("Failed to dump VRAM to %1: %2").arg(path).arg(QString::fromStdString(error.GetDescription())));
|
||||
}
|
||||
}
|
||||
|
||||
void EmuThread::dumpSPURAM(const QString& path)
|
||||
@@ -1636,11 +1650,18 @@ void EmuThread::dumpSPURAM(const QString& path)
|
||||
return;
|
||||
}
|
||||
|
||||
Error error;
|
||||
const std::string path_str = path.toStdString();
|
||||
if (System::DumpSPURAM(path_str.c_str()))
|
||||
Host::AddOSDMessage(OSDMessageType::Info, fmt::format("SPU RAM dumped to '{}'", path_str));
|
||||
if (System::DumpSPURAM(path_str.c_str(), &error))
|
||||
{
|
||||
emit statusMessage(QStringLiteral("SPU RAM dumped to %1.").arg(path));
|
||||
}
|
||||
else
|
||||
Host::ReportErrorAsync("Error", fmt::format("Failed to dump SPU RAM to '{}'", path_str));
|
||||
{
|
||||
emit errorReported(
|
||||
QStringLiteral("Error"),
|
||||
QStringLiteral("Failed to dump SPU RAM to %1: %2").arg(path).arg(QString::fromStdString(error.GetDescription())));
|
||||
}
|
||||
}
|
||||
|
||||
void EmuThread::saveScreenshot()
|
||||
|
||||
Reference in New Issue
Block a user