Skip to content

Commit 6437a5d

Browse files
committed
GPU/TextureCache: Dump textures asynchronously
Saves lagging the emulation.
1 parent 95797b0 commit 6437a5d

1 file changed

Lines changed: 27 additions & 25 deletions

File tree

src/core/gpu_hw_texture_cache.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,7 @@ void GPUTextureCache::DumpTexture(TextureReplacementType type, u32 offset_x, u32
28092809
SmallString filename = name.ToString();
28102810
filename.append(".png");
28112811

2812-
const std::string path = Path::Combine(dump_directory, filename);
2812+
std::string path = Path::Combine(dump_directory, filename);
28132813
if (FileSystem::FileExists(path.c_str()))
28142814
return;
28152815

@@ -2819,39 +2819,41 @@ void GPUTextureCache::DumpTexture(TextureReplacementType type, u32 offset_x, u32
28192819
GPUTextureCache::DecodeTexture(mode, &g_vram[rect.top * VRAM_WIDTH + rect.left], palette_data, image.GetPixels(),
28202820
image.GetPitch(), width, height, GPUTexture::Format::RGBA8);
28212821

2822-
// TODO: Vectorize this.
2823-
u32* image_pixels = reinterpret_cast<u32*>(image.GetPixels());
2824-
const u32* image_pixels_end = image_pixels + (width * height);
2825-
if (s_state.config.dump_texture_force_alpha_channel)
2826-
{
2827-
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
2828-
*pixel |= 0xFF000000u;
2829-
}
2830-
else
2831-
{
2832-
if (semitransparent)
2822+
System::QueueAsyncTask([path = std::move(path), image = std::move(image), width, height, semitransparent]() mutable {
2823+
// TODO: Vectorize this.
2824+
u32* image_pixels = reinterpret_cast<u32*>(image.GetPixels());
2825+
const u32* image_pixels_end = image_pixels + (width * height);
2826+
if (s_state.config.dump_texture_force_alpha_channel)
28332827
{
2834-
// Alpha channel should be inverted, because 0 means opaque, 1 is semitransparent.
2835-
// Pixel value of 0000 is still completely transparent.
28362828
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
2837-
{
2838-
const u32 val = *pixel;
2839-
*pixel = (val == 0u) ? 0u : ((val & 0xFFFFFFFu) | ((val & 0x80000000u) ? 0x80000000u : 0xFF000000u));
2840-
}
2829+
*pixel |= 0xFF000000u;
28412830
}
28422831
else
28432832
{
2844-
// Only cut out 0000 pixels.
2845-
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
2833+
if (semitransparent)
2834+
{
2835+
// Alpha channel should be inverted, because 0 means opaque, 1 is semitransparent.
2836+
// Pixel value of 0000 is still completely transparent.
2837+
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
2838+
{
2839+
const u32 val = *pixel;
2840+
*pixel = (val == 0u) ? 0u : ((val & 0xFFFFFFFu) | ((val & 0x80000000u) ? 0x80000000u : 0xFF000000u));
2841+
}
2842+
}
2843+
else
28462844
{
2847-
const u32 val = *pixel;
2848-
*pixel = (val == 0u) ? 0u : (val | 0xFF000000u);
2845+
// Only cut out 0000 pixels.
2846+
for (u32* pixel = image_pixels; pixel != image_pixels_end; pixel++)
2847+
{
2848+
const u32 val = *pixel;
2849+
*pixel = (val == 0u) ? 0u : (val | 0xFF000000u);
2850+
}
28492851
}
28502852
}
2851-
}
28522853

2853-
if (!image.SaveToFile(path.c_str()))
2854-
ERROR_LOG("Failed to write texture dump to {}.", Path::GetFileName(path));
2854+
if (!image.SaveToFile(path.c_str()))
2855+
ERROR_LOG("Failed to write texture dump to {}.", Path::GetFileName(path));
2856+
});
28552857
}
28562858

28572859
bool GPUTextureCache::IsMatchingReplacementPalette(HashType full_palette_hash, GPUTextureMode mode,

0 commit comments

Comments
 (0)