From 0fb7ff488e5bd960bf0630bd1f6120963de52f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 15 Mar 2023 14:48:32 +0100 Subject: [PATCH] Add a convenient define to experiment with parallel copy --- GPU/Common/ReplacedTexture.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/GPU/Common/ReplacedTexture.cpp b/GPU/Common/ReplacedTexture.cpp index 3a9d47e3a4..d183743688 100644 --- a/GPU/Common/ReplacedTexture.cpp +++ b/GPU/Common/ReplacedTexture.cpp @@ -682,6 +682,8 @@ bool ReplacedTexture::CopyLevelTo(int level, void *out, int rowPitch) { return false; } +#define PARALLEL_COPY + if (fmt == Draw::DataFormat::R8G8B8A8_UNORM) { if (rowPitch < info.w * 4) { ERROR_LOG(G3D, "Replacement rowPitch=%d, but w=%d (level=%d)", rowPitch, info.w * 4, level); @@ -691,18 +693,32 @@ bool ReplacedTexture::CopyLevelTo(int level, void *out, int rowPitch) { _assert_msg_(data.size() == info.w * info.h * 4, "Data has wrong size"); if (rowPitch == info.w * 4) { +#ifdef PARALLEL_COPY + memcpy(out, data.data(), info.w * 4 * info.h); +#else ParallelMemcpy(&g_threadManager, out, &data[0], info.w * 4 * info.h); +#endif } else { +#ifdef PARALLEL_COPY + for (int y = 0; y < info.h; ++y) { + memcpy((uint8_t *)out + rowPitch * y, &data[0] + info.w * 4 * y, info.w * 4); + } +#else const int MIN_LINES_PER_THREAD = 4; ParallelRangeLoop(&g_threadManager, [&](int l, int h) { for (int y = l; y < h; ++y) { memcpy((uint8_t *)out + rowPitch * y, &data[0] + info.w * 4 * y, info.w * 4); } }, 0, info.h, MIN_LINES_PER_THREAD); +#endif } } else { +#ifdef PARALLEL_COPY // TODO: Add sanity checks here for other formats? ParallelMemcpy(&g_threadManager, out, data.data(), data.size()); +#else + memcpy(out, data.data(), data.size()); +#endif } return true;