From 330d14941fd32c17be6e60a6aab10f1c966c4b96 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 21 Feb 2015 13:51:06 +0100 Subject: [PATCH] gsdx-linux: support dump mode on linux It could be useful to analyze GS dump. Warning it consumes a lot of disk space. --- plugins/GSdx/GSRendererHW.cpp | 26 ++++++++++++------------ plugins/GSdx/GSRendererSW.cpp | 38 +++++++++++++++++------------------ plugins/GSdx/GSState.cpp | 10 +++++++++ plugins/GSdx/GSTextureOGL.cpp | 4 ++++ plugins/GSdx/stdafx.h | 9 +++++++++ 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/plugins/GSdx/GSRendererHW.cpp b/plugins/GSdx/GSRendererHW.cpp index e5d5c4f137..fc4e5ef1d5 100644 --- a/plugins/GSdx/GSRendererHW.cpp +++ b/plugins/GSdx/GSRendererHW.cpp @@ -143,7 +143,7 @@ GSTexture* GSRendererHW::GetOutput(int i) { if(s_save && s_n >= s_saven) { - t->Save(format("c:\\temp2\\_%05d_f%lld_fr%d_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), i, (int)TEX0.TBP0, (int)TEX0.PSM)); + t->Save(root_hw + format("%05d_f%lld_fr%d_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), i, (int)TEX0.TBP0, (int)TEX0.PSM)); } s_n++; @@ -235,19 +235,19 @@ void GSRendererHW::Draw() if(s_save && s_n >= s_saven && tex) { - s = format("c:\\temp2\\_%05d_f%lld_tex_%05x_%d_%d%d_%02x_%02x_%02x_%02x.dds", + s = format("%05d_f%lld_tex_%05x_%d_%d%d_%02x_%02x_%02x_%02x.dds", s_n, frame, (int)context->TEX0.TBP0, (int)context->TEX0.PSM, (int)context->CLAMP.WMS, (int)context->CLAMP.WMT, (int)context->CLAMP.MINU, (int)context->CLAMP.MAXU, (int)context->CLAMP.MINV, (int)context->CLAMP.MAXV); - tex->m_texture->Save(s, true); + tex->m_texture->Save(root_hw+s, true); if(tex->m_palette) { - s = format("c:\\temp2\\_%05d_f%lld_tpx_%05x_%d.dds", s_n, frame, context->TEX0.CBP, context->TEX0.CPSM); + s = format("%05d_f%lld_tpx_%05x_%d.dds", s_n, frame, context->TEX0.CBP, context->TEX0.CPSM); - tex->m_palette->Save(s, true); + tex->m_palette->Save(root_hw+s, true); } } @@ -255,16 +255,16 @@ void GSRendererHW::Draw() if(s_save && s_n >= s_saven) { - s = format("c:\\temp2\\_%05d_f%lld_rt0_%05x_%d.bmp", s_n, frame, context->FRAME.Block(), context->FRAME.PSM); + s = format("%05d_f%lld_rt0_%05x_%d.bmp", s_n, frame, context->FRAME.Block(), context->FRAME.PSM); - rt->m_texture->Save(s); + rt->m_texture->Save(root_hw+s); } if(s_savez && s_n >= s_saven) { - s = format("c:\\temp2\\_%05d_f%lld_rz0_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM); + s = format("%05d_f%lld_rz0_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM); - ds->m_texture->Save(s); + ds->m_texture->Save(root_hw+s); } s_n++; @@ -338,16 +338,16 @@ void GSRendererHW::Draw() if(s_save && s_n >= s_saven) { - s = format("c:\\temp2\\_%05d_f%lld_rt1_%05x_%d.bmp", s_n, frame, context->FRAME.Block(), context->FRAME.PSM); + s = format("%05d_f%lld_rt1_%05x_%d.bmp", s_n, frame, context->FRAME.Block(), context->FRAME.PSM); - rt->m_texture->Save(s); + rt->m_texture->Save(root_hw+s); } if(s_savez && s_n >= s_saven) { - s = format("c:\\temp2\\_%05d_f%lld_rz1_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM); + s = format("%05d_f%lld_rz1_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM); - ds->m_texture->Save(s); + ds->m_texture->Save(root_hw+s); } s_n++; diff --git a/plugins/GSdx/GSRendererSW.cpp b/plugins/GSdx/GSRendererSW.cpp index 71f42f961d..dff587fb8d 100644 --- a/plugins/GSdx/GSRendererSW.cpp +++ b/plugins/GSdx/GSRendererSW.cpp @@ -254,7 +254,7 @@ GSTexture* GSRendererSW::GetOutput(int i) { if(s_save && s_n >= s_saven) { - m_texture[i]->Save(format("c:\\temp1\\_%05d_f%lld_fr%d_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), i, (int)DISPFB.Block(), (int)DISPFB.PSM)); + m_texture[i]->Save(root_sw + format("c:\\temp1\\_%05d_f%lld_fr%d_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), i, (int)DISPFB.Block(), (int)DISPFB.PSM)); } s_n++; @@ -517,25 +517,25 @@ void GSRendererSW::Draw() if(s_save && s_n >= s_saven && PRIM->TME) { - s = format("c:\\temp1\\_%05d_f%lld_tex_%05x_%d.bmp", s_n, frame, (int)m_context->TEX0.TBP0, (int)m_context->TEX0.PSM); + s = format("%05d_f%lld_tex_%05x_%d.bmp", s_n, frame, (int)m_context->TEX0.TBP0, (int)m_context->TEX0.PSM); - m_mem.SaveBMP(s, m_context->TEX0.TBP0, m_context->TEX0.TBW, m_context->TEX0.PSM, 1 << m_context->TEX0.TW, 1 << m_context->TEX0.TH); + m_mem.SaveBMP(root_sw+s, m_context->TEX0.TBP0, m_context->TEX0.TBW, m_context->TEX0.PSM, 1 << m_context->TEX0.TW, 1 << m_context->TEX0.TH); } s_n++; if(s_save && s_n >= s_saven) { - s = format("c:\\temp1\\_%05d_f%lld_rt0_%05x_%d.bmp", s_n, frame, m_context->FRAME.Block(), m_context->FRAME.PSM); + s = format("%05d_f%lld_rt0_%05x_%d.bmp", s_n, frame, m_context->FRAME.Block(), m_context->FRAME.PSM); - m_mem.SaveBMP(s, m_context->FRAME.Block(), m_context->FRAME.FBW, m_context->FRAME.PSM, GetFrameRect().width(), 512); + m_mem.SaveBMP(root_sw+s, m_context->FRAME.Block(), m_context->FRAME.FBW, m_context->FRAME.PSM, GetFrameRect().width(), 512); } if(s_savez && s_n >= s_saven) { - s = format("c:\\temp1\\_%05d_f%lld_rz0_%05x_%d.bmp", s_n, frame, m_context->ZBUF.Block(), m_context->ZBUF.PSM); + s = format("%05d_f%lld_rz0_%05x_%d.bmp", s_n, frame, m_context->ZBUF.Block(), m_context->ZBUF.PSM); - m_mem.SaveBMP(s, m_context->ZBUF.Block(), m_context->FRAME.FBW, m_context->ZBUF.PSM, GetFrameRect().width(), 512); + m_mem.SaveBMP(root_sw+s, m_context->ZBUF.Block(), m_context->FRAME.FBW, m_context->ZBUF.PSM, GetFrameRect().width(), 512); } s_n++; @@ -546,16 +546,16 @@ void GSRendererSW::Draw() if(s_save && s_n >= s_saven) { - s = format("c:\\temp1\\_%05d_f%lld_rt1_%05x_%d.bmp", s_n, frame, m_context->FRAME.Block(), m_context->FRAME.PSM); + s = format("%05d_f%lld_rt1_%05x_%d.bmp", s_n, frame, m_context->FRAME.Block(), m_context->FRAME.PSM); - m_mem.SaveBMP(s, m_context->FRAME.Block(), m_context->FRAME.FBW, m_context->FRAME.PSM, GetFrameRect().width(), 512); + m_mem.SaveBMP(root_sw+s, m_context->FRAME.Block(), m_context->FRAME.FBW, m_context->FRAME.PSM, GetFrameRect().width(), 512); } if(s_savez && s_n >= s_saven) { - s = format("c:\\temp1\\_%05d_f%lld_rz1_%05x_%d.bmp", s_n, frame, m_context->ZBUF.Block(), m_context->ZBUF.PSM); + s = format("%05d_f%lld_rz1_%05x_%d.bmp", s_n, frame, m_context->ZBUF.Block(), m_context->ZBUF.PSM); - m_mem.SaveBMP(s, m_context->ZBUF.Block(), m_context->FRAME.FBW, m_context->ZBUF.PSM, GetFrameRect().width(), 512); + m_mem.SaveBMP(root_sw+s, m_context->ZBUF.Block(), m_context->FRAME.FBW, m_context->ZBUF.PSM, GetFrameRect().width(), 512); } s_n++; @@ -642,16 +642,16 @@ void GSRendererSW::Sync(int reason) if(s_save) { - s = format("c:\\temp1\\_%05d_f%lld_rt1_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), m_context->FRAME.Block(), m_context->FRAME.PSM); + s = format("%05d_f%lld_rt1_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), m_context->FRAME.Block(), m_context->FRAME.PSM); - m_mem.SaveBMP(s, m_context->FRAME.Block(), m_context->FRAME.FBW, m_context->FRAME.PSM, GetFrameRect().width(), 512); + m_mem.SaveBMP(root_sw+s, m_context->FRAME.Block(), m_context->FRAME.FBW, m_context->FRAME.PSM, GetFrameRect().width(), 512); } if(s_savez) { - s = format("c:\\temp1\\_%05d_f%lld_zb1_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), m_context->ZBUF.Block(), m_context->ZBUF.PSM); + s = format("%05d_f%lld_zb1_%05x_%d.bmp", s_n, m_perfmon.GetFrame(), m_context->ZBUF.Block(), m_context->ZBUF.PSM); - m_mem.SaveBMP(s, m_context->ZBUF.Block(), m_context->FRAME.FBW, m_context->ZBUF.PSM, GetFrameRect().width(), 512); + m_mem.SaveBMP(root_sw+s, m_context->ZBUF.Block(), m_context->FRAME.FBW, m_context->ZBUF.PSM, GetFrameRect().width(), 512); } } @@ -1622,9 +1622,9 @@ void GSRendererSW::SharedData::UpdateSource() { for(size_t i = 0; m_tex[i].t != NULL; i++) { - s = format("c:\\temp1\\_%05d_f%lld_tex%d_%05x_%d.bmp", m_parent->s_n - 2, frame, i, (int)m_parent->m_context->TEX0.TBP0, (int)m_parent->m_context->TEX0.PSM); + s = format("%05d_f%lld_tex%d_%05x_%d.bmp", m_parent->s_n - 2, frame, i, (int)m_parent->m_context->TEX0.TBP0, (int)m_parent->m_context->TEX0.PSM); - m_tex[i].t->Save(s); + m_tex[i].t->Save(root_sw+s); } if(global.clut != NULL) @@ -1633,9 +1633,9 @@ void GSRendererSW::SharedData::UpdateSource() t->Update(GSVector4i(0, 0, 256, 1), global.clut, sizeof(uint32) * 256); - s = format("c:\\temp1\\_%05d_f%lld_texp_%05x_%d.bmp", m_parent->s_n - 2, frame, (int)m_parent->m_context->TEX0.TBP0, (int)m_parent->m_context->TEX0.PSM); + s = format("%05d_f%lld_texp_%05x_%d.bmp", m_parent->s_n - 2, frame, (int)m_parent->m_context->TEX0.TBP0, (int)m_parent->m_context->TEX0.PSM); - t->Save(s); + t->Save(root_sw+s); delete t; } diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index c09eb8c226..86f9b73950 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -23,6 +23,10 @@ #include "GSState.h" #include "GSdx.h" +#ifdef __linux__ +#include // mkdir +#endif + //#define Offset_ST // Fixes Persona3 mini map alignment which is off even in software rendering GSState::GSState() @@ -46,6 +50,12 @@ GSState::GSState() s_save = !!theApp.GetConfig("save", 0); s_savez = !!theApp.GetConfig("savez", 0); s_saven = theApp.GetConfig("saven", 0); +#ifdef __linux__ + if (s_dump) { + mkdir("/tmp/GS_HW_dump", 0777); + mkdir("/tmp/GS_SW_dump", 0777); + } +#endif //s_dump = 1; //s_save = 1; diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index a9d04ee0c5..5dcb7bc23a 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -473,6 +473,8 @@ void GSTextureOGL::Save(const string& fn, const void* image, uint32 pitch) { // Build a BMP file FILE* fp = fopen(fn.c_str(), "wb"); + if (fp == NULL) + return; BITMAPINFOHEADER bih; @@ -542,6 +544,8 @@ void GSTextureOGL::SaveRaw(const string& fn, const void* image, uint32 pitch) { // Build a raw CSV file FILE* fp = fopen(fn.c_str(), "w"); + if (fp == NULL) + return; uint32* data = (uint32*)image; diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index 2467405379..16c80c9480 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -473,3 +473,12 @@ extern void vmfree(void* ptr, size_t size); #endif #endif + +// Helper path to dump texture +#ifdef _WINDOWS +const std::string root_sw("c:\\temp1\\_"); +const std::string root_hw("c:\\temp2\\_"); +#else +const std::string root_sw("/tmp/GS_SW_dump/"); +const std::string root_hw("/tmp/GS_HW_dump/"); +#endif