GS/SW: Remove use of GSTextureSW for dumping

This commit is contained in:
Stenzek 2023-12-30 18:52:34 +10:00 committed by Connor McLaughlin
parent a4b40ab9e1
commit d020ea8f63
3 changed files with 32 additions and 46 deletions

View File

@ -4,6 +4,7 @@
#include "GS/Renderers/SW/GSRendererSW.h"
#include "GS/Renderers/SW/GSTextureSW.h"
#include "GS/GSGL.h"
#include "GS/GSPng.h"
#include "common/StringUtil.h"
@ -1519,17 +1520,17 @@ void GSRendererSW::SharedData::ReleasePages()
void GSRendererSW::SharedData::SetSource(GSTextureCacheSW::Texture* t, const GSVector4i& r, int level)
{
pxAssert(m_tex[level].t == NULL);
pxAssert(!m_tex[level].t);
m_tex[level].t = t;
m_tex[level].r = r;
m_tex[level + 1].t = NULL;
m_tex[level + 1].t = nullptr;
}
void GSRendererSW::SharedData::UpdateSource()
{
for (size_t i = 0; m_tex[i].t != NULL; i++)
for (size_t i = 0; m_tex[i].t; i++)
{
if (m_tex[i].t->Update(m_tex[i].r))
{
@ -1547,13 +1548,13 @@ void GSRendererSW::SharedData::UpdateSource()
if (GSConfig.DumpGSData)
{
u64 frame = g_perfmon.GetFrame();
const u64 frame = g_perfmon.GetFrame();
std::string s;
if (GSConfig.SaveTexture && g_gs_renderer->s_n >= GSConfig.SaveN)
{
for (size_t i = 0; m_tex[i].t != NULL; i++)
for (size_t i = 0; m_tex[i].t; i++)
{
const GIFRegTEX0& TEX0 = g_gs_renderer->GetTex0Layer(i);
@ -1562,17 +1563,10 @@ void GSRendererSW::SharedData::UpdateSource()
m_tex[i].t->Save(s);
}
if (global.clut != NULL)
if (global.clut)
{
GSTextureSW* t = new GSTextureSW(GSTexture::Type::Invalid, 256, 1);
t->Update(GSVector4i(0, 0, 256, 1), global.clut, sizeof(u32) * 256);
s = GetDrawDumpPath("%05d_f%lld_itexp_%05x_%s.bmp", g_gs_renderer->s_n, frame, (int)g_gs_renderer->m_context->TEX0.CBP, psm_str(g_gs_renderer->m_context->TEX0.CPSM));
t->Save(s);
delete t;
GSPng::Save(IsDevBuild ? GSPng::RGB_A_PNG : GSPng::RGB_PNG, s, reinterpret_cast<const u8*>(global.clut), 256, 1, sizeof(u32) * 256, GSConfig.PNGCompressionLevel, false);
}
}
}

View File

@ -4,6 +4,7 @@
#include "GS/Renderers/SW/GSTextureCacheSW.h"
#include "GS/GSExtra.h"
#include "GS/GSPerfMon.h"
#include "GS/GSPng.h"
#include "GS/GSUtil.h"
GSTextureCacheSW::GSTextureCacheSW() = default;
@ -304,45 +305,36 @@ bool GSTextureCacheSW::Texture::Update(const GSVector4i& rect)
return true;
}
#include "GSTextureSW.h"
bool GSTextureCacheSW::Texture::Save(const std::string& fn, bool dds) const
bool GSTextureCacheSW::Texture::Save(const std::string& fn) const
{
const u32* RESTRICT clut = g_gs_renderer->m_mem.m_clut;
int w = 1 << m_TEX0.TW;
int h = 1 << m_TEX0.TH;
const u32 w = 1 << m_TEX0.TW;
const u32 h = 1 << m_TEX0.TH;
GSTextureSW t(GSTexture::Type::Invalid, w, h);
GSTexture::GSMap m;
if (t.Map(m, nullptr))
constexpr GSPng::Format format = IsDevBuild ? GSPng::RGB_A_PNG : GSPng::RGB_PNG;
const GSLocalMemory::psm_t& psm = GSLocalMemory::m_psm[m_TEX0.PSM];
const u8* RESTRICT src = (u8*)m_buff;
const u32 src_pitch = 1u << (m_tw + (psm.pal == 0 ? 2 : 0));
if (psm.pal == 0)
{
const GSLocalMemory::psm_t& psm = GSLocalMemory::m_psm[m_TEX0.PSM];
// no clut => dump directly
return GSPng::Save(format, fn, src, w, h, src_pitch, GSConfig.PNGCompressionLevel);
}
else
{
const std::unique_ptr<u32[]> dumptex = std::make_unique<u32[]>(w * h);
u32* dst = dumptex.get();
const u8* RESTRICT src = (u8*)m_buff;
int pitch = 1 << (m_tw + (psm.pal == 0 ? 2 : 0));
for (int j = 0; j < h; j++, src += pitch, m.bits += m.pitch)
for (u32 j = 0; j < h; j++)
{
if (psm.pal == 0)
{
memcpy(m.bits, src, sizeof(u32) * w);
}
else
{
for (int i = 0; i < w; i++)
{
((u32*)m.bits)[i] = clut[src[i]];
}
}
for (u32 i = 0; i < w; i++)
*(dst++) = clut[src[i]];
src += src_pitch;
}
t.Unmap();
return t.Save(fn);
return GSPng::Save(format, fn, reinterpret_cast<const u8*>(dumptex.get()),
w, h, w * sizeof(u32), GSConfig.PNGCompressionLevel);
}
return false;
}

View File

@ -37,7 +37,7 @@ public:
void Reset(u32 tw0, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA);
bool Update(const GSVector4i& r);
bool Save(const std::string& fn, bool dds = false) const;
bool Save(const std::string& fn) const;
};
protected: