From a45eeb56ed0d5cad47fbd4a1addcb58755b1b77c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 8 Jan 2022 16:06:17 -0800 Subject: [PATCH] Headless: Fix compare of smaller buffers. When the buffer is smaller, we need to flip properly to compare the correct pixels. --- headless/Compare.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/headless/Compare.cpp b/headless/Compare.cpp index be8dad3738..890ff6cc6a 100644 --- a/headless/Compare.cpp +++ b/headless/Compare.cpp @@ -305,16 +305,14 @@ bool CompareOutput(const Path &bootFilename, const std::string &output, bool ver } } -inline int ComparePixel(u32 pix1, u32 pix2) -{ +inline int ComparePixel(u32 pix1, u32 pix2) { // For now, if they're different at all except alpha, it's an error. if ((pix1 & 0xFFFFFF) != (pix2 & 0xFFFFFF)) return 1; return 0; } -std::vector TranslateDebugBufferToCompare(const GPUDebugBuffer *buffer, u32 stride, u32 h) -{ +std::vector TranslateDebugBufferToCompare(const GPUDebugBuffer *buffer, u32 stride, u32 h) { // If the output was small, act like everything outside was 0. // This can happen depending on viewport parameters. u32 safeW = std::min(stride, buffer->GetStride()); @@ -334,24 +332,30 @@ std::vector TranslateDebugBufferToCompare(const GPUDebugBuffer *buffer, u32 outStride = -outStride; } + // Skip the bottom of the image in the buffer was smaller. Remember, we're flipped. + u32 *dst = &data[0]; + if (safeH < h) { + dst += (h - safeH) * stride; + } + u32 errors = 0; for (u32 y = 0; y < safeH; ++y) { switch (buffer->GetFormat()) { case GPU_DBG_FORMAT_8888: - ConvertBGRA8888ToRGBA8888(&data[y * stride], pixels32, safeW); + ConvertBGRA8888ToRGBA8888(&dst[y * stride], pixels32, safeW); break; case GPU_DBG_FORMAT_8888_BGRA: - memcpy(&data[y * stride], pixels32, safeW * sizeof(u32)); + memcpy(&dst[y * stride], pixels32, safeW * sizeof(u32)); break; case GPU_DBG_FORMAT_565: - ConvertRGB565ToBGRA8888(&data[y * stride], pixels16, safeW); + ConvertRGB565ToBGRA8888(&dst[y * stride], pixels16, safeW); break; case GPU_DBG_FORMAT_5551: - ConvertRGBA5551ToBGRA8888(&data[y * stride], pixels16, safeW); + ConvertRGBA5551ToBGRA8888(&dst[y * stride], pixels16, safeW); break; case GPU_DBG_FORMAT_4444: - ConvertRGBA4444ToBGRA8888(&data[y * stride], pixels16, safeW); + ConvertRGBA4444ToBGRA8888(&dst[y * stride], pixels16, safeW); break; default: