mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-07 03:55:33 +00:00
GPU/TextureCache: Dump textures asynchronously
Saves lagging the emulation.
This commit is contained in:
parent
95797b05f1
commit
6437a5db60
@ -2809,7 +2809,7 @@ void GPUTextureCache::DumpTexture(TextureReplacementType type, u32 offset_x, u32
|
|||||||
SmallString filename = name.ToString();
|
SmallString filename = name.ToString();
|
||||||
filename.append(".png");
|
filename.append(".png");
|
||||||
|
|
||||||
const std::string path = Path::Combine(dump_directory, filename);
|
std::string path = Path::Combine(dump_directory, filename);
|
||||||
if (FileSystem::FileExists(path.c_str()))
|
if (FileSystem::FileExists(path.c_str()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2819,39 +2819,41 @@ void GPUTextureCache::DumpTexture(TextureReplacementType type, u32 offset_x, u32
|
|||||||
GPUTextureCache::DecodeTexture(mode, &g_vram[rect.top * VRAM_WIDTH + rect.left], palette_data, image.GetPixels(),
|
GPUTextureCache::DecodeTexture(mode, &g_vram[rect.top * VRAM_WIDTH + rect.left], palette_data, image.GetPixels(),
|
||||||
image.GetPitch(), width, height, GPUTexture::Format::RGBA8);
|
image.GetPitch(), width, height, GPUTexture::Format::RGBA8);
|
||||||
|
|
||||||
// TODO: Vectorize this.
|
System::QueueAsyncTask([path = std::move(path), image = std::move(image), width, height, semitransparent]() mutable {
|
||||||
u32* image_pixels = reinterpret_cast<u32*>(image.GetPixels());
|
// TODO: Vectorize this.
|
||||||
const u32* image_pixels_end = image_pixels + (width * height);
|
u32* image_pixels = reinterpret_cast<u32*>(image.GetPixels());
|
||||||
if (s_state.config.dump_texture_force_alpha_channel)
|
const u32* image_pixels_end = image_pixels + (width * height);
|
||||||
{
|
if (s_state.config.dump_texture_force_alpha_channel)
|
||||||
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
|
|
||||||
*pixel |= 0xFF000000u;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (semitransparent)
|
|
||||||
{
|
{
|
||||||
// Alpha channel should be inverted, because 0 means opaque, 1 is semitransparent.
|
|
||||||
// Pixel value of 0000 is still completely transparent.
|
|
||||||
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
|
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
|
||||||
{
|
*pixel |= 0xFF000000u;
|
||||||
const u32 val = *pixel;
|
|
||||||
*pixel = (val == 0u) ? 0u : ((val & 0xFFFFFFFu) | ((val & 0x80000000u) ? 0x80000000u : 0xFF000000u));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Only cut out 0000 pixels.
|
if (semitransparent)
|
||||||
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
|
|
||||||
{
|
{
|
||||||
const u32 val = *pixel;
|
// Alpha channel should be inverted, because 0 means opaque, 1 is semitransparent.
|
||||||
*pixel = (val == 0u) ? 0u : (val | 0xFF000000u);
|
// Pixel value of 0000 is still completely transparent.
|
||||||
|
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
|
||||||
|
{
|
||||||
|
const u32 val = *pixel;
|
||||||
|
*pixel = (val == 0u) ? 0u : ((val & 0xFFFFFFFu) | ((val & 0x80000000u) ? 0x80000000u : 0xFF000000u));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Only cut out 0000 pixels.
|
||||||
|
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
|
||||||
|
{
|
||||||
|
const u32 val = *pixel;
|
||||||
|
*pixel = (val == 0u) ? 0u : (val | 0xFF000000u);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!image.SaveToFile(path.c_str()))
|
if (!image.SaveToFile(path.c_str()))
|
||||||
ERROR_LOG("Failed to write texture dump to {}.", Path::GetFileName(path));
|
ERROR_LOG("Failed to write texture dump to {}.", Path::GetFileName(path));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPUTextureCache::IsMatchingReplacementPalette(HashType full_palette_hash, GPUTextureMode mode,
|
bool GPUTextureCache::IsMatchingReplacementPalette(HashType full_palette_hash, GPUTextureMode mode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user