From d573bf9cc91061a9394992e1697807f18e5899d7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 30 Nov 2018 17:46:47 -0800 Subject: [PATCH] Headless: Fix compare for 16-bit output. Most tests have been 32-bit output, so haven't run into this. Enables tests with softgpu to generate 16-bit output. --- headless/Compare.cpp | 44 +++++++++++++++++++++++++++++-------------- headless/StubHost.cpp | 2 +- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/headless/Compare.cpp b/headless/Compare.cpp index 556bd32873..ba35b93c90 100644 --- a/headless/Compare.cpp +++ b/headless/Compare.cpp @@ -301,28 +301,44 @@ std::vector TranslateDebugBufferToCompare(const GPUDebugBuffer *buffer, u32 std::vector data; data.resize(stride * h, 0); - const u32 *pixels = (const u32 *)buffer->GetData(); + const u32 *pixels32 = (const u32 *)buffer->GetData(); + const u16 *pixels16 = (const u16 *)buffer->GetData(); int outStride = buffer->GetStride(); - if (!buffer->GetFlipped()) - { + if (!buffer->GetFlipped()) { // Bitmaps are flipped, so we have to compare backwards in this case. - pixels += outStride * (buffer->GetHeight() - 1); + int toLastRow = outStride * (buffer->GetHeight() - 1); + pixels32 += toLastRow; + pixels16 += toLastRow; outStride = -outStride; } u32 errors = 0; - for (u32 y = 0; y < safeH; ++y) - { - if (buffer->GetFormat() == GPU_DBG_FORMAT_8888) - ConvertBGRA8888ToRGBA8888(&data[y * stride], pixels, safeW); - else if (buffer->GetFormat() == GPU_DBG_FORMAT_8888_BGRA) - memcpy(&data[y * stride], pixels, safeW * sizeof(u32)); - else - { + for (u32 y = 0; y < safeH; ++y) { + switch (buffer->GetFormat()) { + case GPU_DBG_FORMAT_8888: + ConvertBGRA8888ToRGBA8888(&data[y * stride], pixels32, safeW); + break; + case GPU_DBG_FORMAT_8888_BGRA: + memcpy(&data[y * stride], pixels32, safeW * sizeof(u32)); + break; + + case GPU_DBG_FORMAT_565: + ConvertRGB565ToBGRA8888(&data[y * stride], pixels16, safeW); + break; + case GPU_DBG_FORMAT_5551: + ConvertRGBA5551ToBGRA8888(&data[y * stride], pixels16, safeW); + break; + case GPU_DBG_FORMAT_4444: + ConvertRGBA4444ToBGRA8888(&data[y * stride], pixels16, safeW); + break; + + default: data.resize(0); return data; } - pixels += outStride; + + pixels32 += outStride; + pixels16 += outStride; } return data; @@ -365,4 +381,4 @@ double CompareScreenshot(const std::vector &pixels, u32 stride, u32 w, u32 free(reference); return (double) errors / (double) (w * h); -} \ No newline at end of file +} diff --git a/headless/StubHost.cpp b/headless/StubHost.cpp index dc3520013e..6569cc3b1a 100644 --- a/headless/StubHost.cpp +++ b/headless/StubHost.cpp @@ -55,7 +55,7 @@ void HeadlessHost::SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h) std::string error; double errors = CompareScreenshot(pixels, FRAME_STRIDE, FRAME_WIDTH, FRAME_HEIGHT, comparisonScreenshot_, error); if (errors < 0) - SendOrCollectDebugOutput(error); + SendOrCollectDebugOutput(error + "\n"); if (errors > 0) {