2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-09-21 22:53:13 +00:00
|
|
|
#include "VideoBackends/Software/EfbInterface.h"
|
|
|
|
|
2014-03-29 02:22:15 +00:00
|
|
|
#include <algorithm>
|
2018-05-18 19:36:37 +00:00
|
|
|
#include <array>
|
2016-09-21 22:53:13 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
2017-08-24 02:46:23 +00:00
|
|
|
#include <vector>
|
2014-03-29 02:22:15 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
|
2017-08-24 02:46:23 +00:00
|
|
|
#include "VideoBackends/Software/CopyRegion.h"
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoCommon/BPMemory.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/LookUpTables.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "VideoCommon/PerfQueryBase.h"
|
2019-07-17 00:18:48 +00:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
namespace EfbInterface
|
|
|
|
{
|
2018-05-18 19:36:37 +00:00
|
|
|
static std::array<u8, EFB_WIDTH * EFB_HEIGHT * 6> efb;
|
2018-05-18 19:09:37 +00:00
|
|
|
|
2018-05-18 19:36:37 +00:00
|
|
|
static std::array<u32, PQ_NUM_MEMBERS> perf_values;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-08-11 01:51:05 +00:00
|
|
|
static inline u32 GetColorOffset(u16 x, u16 y)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
return (x + y * EFB_WIDTH) * 3;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-08-11 01:51:05 +00:00
|
|
|
static inline u32 GetDepthOffset(u16 x, u16 y)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2018-05-18 19:43:26 +00:00
|
|
|
constexpr u32 depth_buffer_start = EFB_WIDTH * EFB_HEIGHT * 3;
|
|
|
|
|
|
|
|
return (x + y * EFB_WIDTH) * 3 + depth_buffer_start;
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelAlphaOnly(u32 offset, u8 a)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB8_Z24:
|
|
|
|
case PixelFormat::Z24:
|
|
|
|
case PixelFormat::RGB565_Z16:
|
2009-10-12 00:48:24 +00:00
|
|
|
// do nothing
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGBA6_Z24:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 a32 = a;
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
2010-12-31 06:45:18 +00:00
|
|
|
u32 val = *dst & 0xffffffc0;
|
|
|
|
val |= (a32 >> 2) & 0x0000003f;
|
2009-10-12 00:48:24 +00:00
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-02-11 02:11:31 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Unsupported pixel format: {}", bpmem.zcontrol.pixel_format);
|
2020-11-09 08:13:59 +00:00
|
|
|
break;
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelColorOnly(u32 offset, u8* rgb)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB8_Z24:
|
|
|
|
case PixelFormat::Z24:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 src = *(u32*)rgb;
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2009-10-12 00:48:24 +00:00
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGBA6_Z24:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 src = *(u32*)rgb;
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
2010-12-31 06:45:18 +00:00
|
|
|
u32 val = *dst & 0xff00003f;
|
|
|
|
val |= (src >> 4) & 0x00000fc0; // blue
|
|
|
|
val |= (src >> 6) & 0x0003f000; // green
|
|
|
|
val |= (src >> 8) & 0x00fc0000; // red
|
2009-10-12 00:48:24 +00:00
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB565_Z16:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2022-03-08 21:59:55 +00:00
|
|
|
// TODO: RGB565_Z16 is not supported correctly yet
|
2009-10-12 00:48:24 +00:00
|
|
|
u32 src = *(u32*)rgb;
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2009-10-12 00:48:24 +00:00
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-02-11 02:11:31 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Unsupported pixel format: {}", bpmem.zcontrol.pixel_format);
|
2020-11-09 08:13:59 +00:00
|
|
|
break;
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelAlphaColor(u32 offset, u8* color)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB8_Z24:
|
|
|
|
case PixelFormat::Z24:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 src = *(u32*)color;
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2009-10-12 00:48:24 +00:00
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGBA6_Z24:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 src = *(u32*)color;
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= (src >> 2) & 0x0000003f; // alpha
|
|
|
|
val |= (src >> 4) & 0x00000fc0; // blue
|
|
|
|
val |= (src >> 6) & 0x0003f000; // green
|
|
|
|
val |= (src >> 8) & 0x00fc0000; // red
|
2009-10-12 00:48:24 +00:00
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB565_Z16:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2022-03-08 21:59:55 +00:00
|
|
|
// TODO: RGB565_Z16 is not supported correctly yet
|
2009-10-12 00:48:24 +00:00
|
|
|
u32 src = *(u32*)color;
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2009-10-12 00:48:24 +00:00
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-02-11 02:11:31 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Unsupported pixel format: {}", bpmem.zcontrol.pixel_format);
|
2020-11-09 08:13:59 +00:00
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-09-21 22:53:13 +00:00
|
|
|
static u32 GetPixelColor(u32 offset)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2016-09-21 22:53:13 +00:00
|
|
|
u32 src;
|
|
|
|
std::memcpy(&src, &efb[offset], sizeof(u32));
|
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB8_Z24:
|
|
|
|
case PixelFormat::Z24:
|
2016-09-21 22:53:13 +00:00
|
|
|
return 0xff | ((src & 0x00ffffff) << 8);
|
|
|
|
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGBA6_Z24:
|
2016-09-21 22:53:13 +00:00
|
|
|
return Convert6To8(src & 0x3f) | // Alpha
|
|
|
|
Convert6To8((src >> 6) & 0x3f) << 8 | // Blue
|
|
|
|
Convert6To8((src >> 12) & 0x3f) << 16 | // Green
|
|
|
|
Convert6To8((src >> 18) & 0x3f) << 24; // Red
|
|
|
|
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB565_Z16:
|
2022-03-08 21:59:55 +00:00
|
|
|
// TODO: RGB565_Z16 is not supported correctly yet
|
2016-09-21 22:53:13 +00:00
|
|
|
return 0xff | ((src & 0x00ffffff) << 8);
|
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
default:
|
2021-02-11 02:11:31 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Unsupported pixel format: {}", bpmem.zcontrol.pixel_format);
|
2016-09-21 22:53:13 +00:00
|
|
|
return 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelDepth(u32 offset, u32 depth)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB8_Z24:
|
|
|
|
case PixelFormat::RGBA6_Z24:
|
|
|
|
case PixelFormat::Z24:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32* dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
|
|
|
val |= depth & 0x00ffffff;
|
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB565_Z16:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2022-03-08 21:59:55 +00:00
|
|
|
// TODO: RGB565_Z16 is not supported correctly yet
|
2009-10-12 00:48:24 +00:00
|
|
|
u32* dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
|
|
|
val |= depth & 0x00ffffff;
|
|
|
|
*dst = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-02-11 02:11:31 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Unsupported pixel format: {}", bpmem.zcontrol.pixel_format);
|
2020-11-09 08:13:59 +00:00
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static u32 GetPixelDepth(u32 offset)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 depth = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB8_Z24:
|
|
|
|
case PixelFormat::RGBA6_Z24:
|
|
|
|
case PixelFormat::Z24:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
depth = (*(u32*)&efb[offset]) & 0x00ffffff;
|
|
|
|
}
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case PixelFormat::RGB565_Z16:
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2022-03-08 21:59:55 +00:00
|
|
|
// TODO: RGB565_Z16 is not supported correctly yet
|
2009-10-12 00:48:24 +00:00
|
|
|
depth = (*(u32*)&efb[offset]) & 0x00ffffff;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-02-11 02:11:31 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Unsupported pixel format: {}", bpmem.zcontrol.pixel_format);
|
2020-11-09 08:13:59 +00:00
|
|
|
break;
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
return depth;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-11 02:11:31 +00:00
|
|
|
static u32 GetSourceFactor(u8* srcClr, u8* dstClr, SrcBlendFactor mode)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2014-03-24 19:21:34 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::Zero:
|
2014-03-24 19:21:34 +00:00
|
|
|
return 0;
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::One:
|
2014-03-24 19:21:34 +00:00
|
|
|
return 0xffffffff;
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::DstClr:
|
2014-03-24 19:21:34 +00:00
|
|
|
return *(u32*)dstClr;
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::InvDstClr:
|
2014-03-24 19:21:34 +00:00
|
|
|
return 0xffffffff - *(u32*)dstClr;
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::SrcAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::InvSrcAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = 0xff - srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::DstAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = dstClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2021-02-11 02:11:31 +00:00
|
|
|
case SrcBlendFactor::InvDstAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = 0xff - dstClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2014-03-24 19:21:34 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-11 02:11:31 +00:00
|
|
|
static u32 GetDestinationFactor(u8* srcClr, u8* dstClr, DstBlendFactor mode)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2014-03-24 19:21:34 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::Zero:
|
2014-03-24 19:21:34 +00:00
|
|
|
return 0;
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::One:
|
2014-03-24 19:21:34 +00:00
|
|
|
return 0xffffffff;
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::SrcClr:
|
2014-03-24 19:21:34 +00:00
|
|
|
return *(u32*)srcClr;
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::InvSrcClr:
|
2014-03-24 19:21:34 +00:00
|
|
|
return 0xffffffff - *(u32*)srcClr;
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::SrcAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::InvSrcAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = 0xff - srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::DstAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = dstClr[ALP_C] & 0xff;
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2021-02-11 02:11:31 +00:00
|
|
|
case DstBlendFactor::InvDstAlpha:
|
2014-03-24 19:21:34 +00:00
|
|
|
{
|
|
|
|
u8 alpha = 0xff - dstClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2014-03-24 19:21:34 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void BlendColor(u8* srcClr, u8* dstClr)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 srcFactor = GetSourceFactor(srcClr, dstClr, bpmem.blendmode.srcfactor);
|
|
|
|
u32 dstFactor = GetDestinationFactor(srcClr, dstClr, bpmem.blendmode.dstfactor);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
// add MSB of factors to make their range 0 -> 256
|
|
|
|
u32 sf = (srcFactor & 0xff);
|
|
|
|
sf += sf >> 7;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
u32 df = (dstFactor & 0xff);
|
|
|
|
df += df >> 7;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
u32 color = (srcClr[i] * sf + dstClr[i] * df) >> 8;
|
|
|
|
dstClr[i] = (color > 255) ? 255 : color;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
dstFactor >>= 8;
|
|
|
|
srcFactor >>= 8;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-02-11 02:11:31 +00:00
|
|
|
static void LogicBlend(u32 srcClr, u32* dstClr, LogicOp op)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Clear:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = 0;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::And:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr & *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::AndReverse:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr & (~*dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Copy:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::AndInverted:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = (~srcClr) & *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::NoOp:
|
2014-03-24 19:21:34 +00:00
|
|
|
// Do nothing
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Xor:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr ^ *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Or:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr | *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Nor:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~(srcClr | *dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Equiv:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~(srcClr ^ *dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Invert:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~*dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::OrReverse:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr | (~*dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::CopyInverted:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~srcClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::OrInverted:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = (~srcClr) | *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Nand:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~(srcClr & *dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case LogicOp::Set:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = 0xffffffff;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SubtractBlend(u8* srcClr, u8* dstClr)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
int c = (int)dstClr[i] - (int)srcClr[i];
|
|
|
|
dstClr[i] = (c < 0) ? 0 : c;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-15 01:27:54 +00:00
|
|
|
static void Dither(u16 x, u16 y, u8* color)
|
|
|
|
{
|
|
|
|
// No blending for RGB8 mode
|
2021-02-11 02:11:31 +00:00
|
|
|
if (!bpmem.blendmode.dither || bpmem.zcontrol.pixel_format != PixelFormat::RGBA6_Z24)
|
2016-02-15 01:27:54 +00:00
|
|
|
return;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-15 01:27:54 +00:00
|
|
|
// Flipper uses a standard 2x2 Bayer Matrix for 6 bit dithering
|
|
|
|
static const u8 dither[2][2] = {{0, 2}, {3, 1}};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-15 01:27:54 +00:00
|
|
|
// Only the color channels are dithered?
|
|
|
|
for (int i = BLU_C; i <= RED_C; i++)
|
|
|
|
color[i] = ((color[i] - (color[i] >> 6)) + dither[y & 1][x & 1]) & 0xfc;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void BlendTev(u16 x, u16 y, u8* color)
|
|
|
|
{
|
2016-09-21 22:53:13 +00:00
|
|
|
const u32 offset = GetColorOffset(x, y);
|
|
|
|
u32 dstClr = GetPixelColor(offset);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
u8* dstClrPtr = (u8*)&dstClr;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
if (bpmem.blendmode.blendenable)
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.subtract)
|
|
|
|
SubtractBlend(color, dstClrPtr);
|
|
|
|
else
|
|
|
|
BlendColor(color, dstClrPtr);
|
|
|
|
}
|
|
|
|
else if (bpmem.blendmode.logicopenable)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-10-02 06:20:46 +00:00
|
|
|
LogicBlend(*((u32*)color), &dstClr, bpmem.blendmode.logicmode);
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2009-10-12 00:48:24 +00:00
|
|
|
else
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2009-10-12 00:48:24 +00:00
|
|
|
dstClrPtr = color;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
if (bpmem.dstalpha.enable)
|
2010-12-31 06:45:18 +00:00
|
|
|
dstClrPtr[ALP_C] = bpmem.dstalpha.alpha;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
if (bpmem.blendmode.colorupdate)
|
|
|
|
{
|
2016-02-15 01:27:54 +00:00
|
|
|
Dither(x, y, dstClrPtr);
|
2009-10-12 00:48:24 +00:00
|
|
|
if (bpmem.blendmode.alphaupdate)
|
|
|
|
SetPixelAlphaColor(offset, dstClrPtr);
|
|
|
|
else
|
|
|
|
SetPixelColorOnly(offset, dstClrPtr);
|
|
|
|
}
|
|
|
|
else if (bpmem.blendmode.alphaupdate)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-12-31 06:45:18 +00:00
|
|
|
SetPixelAlphaOnly(offset, dstClrPtr[ALP_C]);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
void SetColor(u16 x, u16 y, u8* color)
|
|
|
|
{
|
|
|
|
u32 offset = GetColorOffset(x, y);
|
|
|
|
if (bpmem.blendmode.colorupdate)
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.alphaupdate)
|
|
|
|
SetPixelAlphaColor(offset, color);
|
|
|
|
else
|
|
|
|
SetPixelColorOnly(offset, color);
|
|
|
|
}
|
|
|
|
else if (bpmem.blendmode.alphaupdate)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-12-31 06:45:18 +00:00
|
|
|
SetPixelAlphaOnly(offset, color[ALP_C]);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-14 13:08:36 +00:00
|
|
|
void SetDepth(u16 x, u16 y, u32 depth)
|
|
|
|
{
|
|
|
|
if (bpmem.zmode.updateenable)
|
|
|
|
SetPixelDepth(GetDepthOffset(x, y), depth);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-09-21 22:53:13 +00:00
|
|
|
u32 GetColor(u16 x, u16 y)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
|
|
|
u32 offset = GetColorOffset(x, y);
|
2016-09-21 22:53:13 +00:00
|
|
|
return GetPixelColor(offset);
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-05-17 20:21:02 +00:00
|
|
|
static u32 VerticalFilter(const std::array<u32, 3>& colors,
|
|
|
|
const std::array<u8, 7>& filterCoefficients)
|
|
|
|
{
|
|
|
|
u8 in_colors[3][4];
|
|
|
|
std::memcpy(&in_colors, colors.data(), sizeof(in_colors));
|
|
|
|
|
|
|
|
// Alpha channel is not used
|
|
|
|
u8 out_color[4];
|
|
|
|
out_color[ALP_C] = 0;
|
|
|
|
|
|
|
|
// All Coefficients should sum to 64, otherwise the total brightness will change, which many games
|
|
|
|
// do on purpose to implement a brightness filter across the whole copy.
|
|
|
|
for (int i = BLU_C; i <= RED_C; i++)
|
|
|
|
{
|
|
|
|
// TODO: implement support for multisampling.
|
|
|
|
// In non-multisampling mode:
|
|
|
|
// * Coefficients 2, 3 and 4 sample from the current pixel.
|
|
|
|
// * Coefficients 0 and 1 sample from the pixel above this one
|
|
|
|
// * Coefficients 5 and 6 sample from the pixel below this one
|
|
|
|
int sum =
|
|
|
|
in_colors[0][i] * (filterCoefficients[0] + filterCoefficients[1]) +
|
|
|
|
in_colors[1][i] * (filterCoefficients[2] + filterCoefficients[3] + filterCoefficients[4]) +
|
|
|
|
in_colors[2][i] * (filterCoefficients[5] + filterCoefficients[6]);
|
|
|
|
|
|
|
|
// TODO: this clamping behavior appears to be correct, but isn't confirmed on hardware.
|
|
|
|
out_color[i] = std::min(255, sum >> 6); // clamp larger values to 255
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 out_color32;
|
|
|
|
std::memcpy(&out_color32, out_color, sizeof(out_color32));
|
|
|
|
return out_color32;
|
|
|
|
}
|
|
|
|
|
2018-04-29 08:52:30 +00:00
|
|
|
static u32 GammaCorrection(u32 color, const float gamma_rcp)
|
|
|
|
{
|
|
|
|
u8 in_colors[4];
|
|
|
|
std::memcpy(&in_colors, &color, sizeof(in_colors));
|
|
|
|
|
|
|
|
u8 out_color[4];
|
|
|
|
for (int i = BLU_C; i <= RED_C; i++)
|
|
|
|
{
|
|
|
|
out_color[i] = static_cast<u8>(
|
2017-12-25 23:38:44 +00:00
|
|
|
std::clamp(std::pow(in_colors[i] / 255.0f, gamma_rcp) * 255.0f, 0.0f, 255.0f));
|
2018-04-29 08:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 out_color32;
|
|
|
|
std::memcpy(&out_color32, out_color, sizeof(out_color32));
|
|
|
|
return out_color32;
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// For internal used only, return a non-normalized value, which saves work later.
|
2016-05-17 20:21:02 +00:00
|
|
|
static yuv444 ConvertColorToYUV(u32 color)
|
2013-08-20 11:51:39 +00:00
|
|
|
{
|
2016-09-21 22:53:13 +00:00
|
|
|
const u8 red = static_cast<u8>(color >> 24);
|
|
|
|
const u8 green = static_cast<u8>(color >> 16);
|
|
|
|
const u8 blue = static_cast<u8>(color >> 8);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// GameCube/Wii uses the BT.601 standard algorithm for converting to YCbCr; see
|
|
|
|
// http://www.equasys.de/colorconversion.html#YCbCr-RGBColorFormatConversion
|
2016-09-21 22:53:13 +00:00
|
|
|
return {static_cast<u8>(0.257f * red + 0.504f * green + 0.098f * blue),
|
|
|
|
static_cast<s8>(-0.148f * red + -0.291f * green + 0.439f * blue),
|
|
|
|
static_cast<s8>(0.439f * red + -0.368f * green + -0.071f * blue)};
|
2013-08-20 11:51:39 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
u32 GetDepth(u16 x, u16 y)
|
|
|
|
{
|
|
|
|
u32 offset = GetDepthOffset(x, y);
|
|
|
|
return GetPixelDepth(offset);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
u8* GetPixelPointer(u16 x, u16 y, bool depth)
|
|
|
|
{
|
|
|
|
if (depth)
|
|
|
|
return &efb[GetDepthOffset(x, y)];
|
|
|
|
return &efb[GetColorOffset(x, y)];
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-04-15 14:47:46 +00:00
|
|
|
void EncodeXFB(u8* xfb_in_ram, u32 memory_stride, const MathUtil::Rectangle<int>& source_rect,
|
|
|
|
float y_scale, float gamma)
|
2014-08-11 01:18:38 +00:00
|
|
|
{
|
2013-08-20 11:51:39 +00:00
|
|
|
if (!xfb_in_ram)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2020-11-09 08:13:59 +00:00
|
|
|
WARN_LOG_FMT(VIDEO, "Tried to copy to invalid XFB address");
|
2013-08-20 11:51:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-04-29 08:52:30 +00:00
|
|
|
const int left = source_rect.left;
|
|
|
|
const int right = source_rect.right;
|
|
|
|
const bool clamp_top = bpmem.triggerEFBCopy.clamp_top;
|
|
|
|
const bool clamp_bottom = bpmem.triggerEFBCopy.clamp_bottom;
|
|
|
|
const float gamma_rcp = 1.0f / gamma;
|
|
|
|
const auto filter_coefficients = bpmem.copyfilter.GetCoefficients();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// this assumes copies will always start on an even (YU) pixel and the
|
|
|
|
// copy always has an even width, which might not be true.
|
2014-08-11 01:18:38 +00:00
|
|
|
if (left & 1 || right & 1)
|
|
|
|
{
|
2020-11-09 08:13:59 +00:00
|
|
|
WARN_LOG_FMT(VIDEO, "Trying to copy XFB to from unaligned EFB source");
|
2013-08-20 11:51:39 +00:00
|
|
|
// this will show up as wrongly encoded
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// Scanline buffer, leave room for borders
|
2013-11-23 10:44:05 +00:00
|
|
|
yuv444 scanline[EFB_WIDTH + 2];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-08-24 02:46:23 +00:00
|
|
|
static std::vector<yuv422_packed> source;
|
|
|
|
source.resize(EFB_WIDTH * EFB_HEIGHT);
|
|
|
|
yuv422_packed* src_ptr = &source[0];
|
|
|
|
|
2016-05-17 20:21:02 +00:00
|
|
|
for (int y = source_rect.top; y < source_rect.bottom; y++)
|
2013-08-20 11:51:39 +00:00
|
|
|
{
|
2016-05-17 20:21:02 +00:00
|
|
|
// Clamping behavior
|
|
|
|
// NOTE: when the clamp bits aren't set, the hardware will happily read beyond the EFB,
|
|
|
|
// which returns random garbage from the empty bus (confirmed by hardware tests).
|
|
|
|
//
|
|
|
|
// In our implementation, the garbage just so happens to be the top or bottom row.
|
|
|
|
// Statistically, that could happen.
|
2019-04-28 09:39:59 +00:00
|
|
|
const u16 y_prev = static_cast<u16>(std::max(clamp_top ? source_rect.top : 0, y - 1));
|
2021-11-16 20:29:16 +00:00
|
|
|
const u16 y_next = static_cast<u16>(
|
|
|
|
std::min<int>((clamp_bottom ? source_rect.bottom : EFB_HEIGHT) - 1, y + 1));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-05-17 20:21:02 +00:00
|
|
|
// Get a scanline of YUV pixels in 4:4:4 format
|
2013-08-20 11:51:39 +00:00
|
|
|
for (int i = 1, x = left; x < right; i++, x++)
|
|
|
|
{
|
2016-05-17 20:21:02 +00:00
|
|
|
// Get RGB colors
|
|
|
|
std::array<u32, 3> colors = {{GetColor(x, y_prev), GetColor(x, y), GetColor(x, y_next)}};
|
|
|
|
|
|
|
|
// Vertical Filter (Multisampling resolve, deflicker, brightness)
|
2018-04-29 08:52:30 +00:00
|
|
|
u32 filtered = VerticalFilter(colors, filter_coefficients);
|
2016-05-17 20:21:02 +00:00
|
|
|
|
2018-04-29 08:52:30 +00:00
|
|
|
// Gamma correction happens here.
|
|
|
|
filtered = GammaCorrection(filtered, gamma_rcp);
|
2016-05-17 20:21:02 +00:00
|
|
|
|
|
|
|
scanline[i] = ConvertColorToYUV(filtered);
|
2013-08-20 11:51:39 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-05-29 22:02:09 +00:00
|
|
|
// Flipper clamps the border colors
|
|
|
|
scanline[0] = scanline[1];
|
|
|
|
scanline[right + 1] = scanline[right];
|
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// And Downsample them to 4:2:2
|
|
|
|
for (int i = 1, x = left; x < right; i += 2, x += 2)
|
2009-10-12 00:48:24 +00:00
|
|
|
{
|
2013-08-20 11:51:39 +00:00
|
|
|
// YU pixel
|
2017-08-24 02:46:23 +00:00
|
|
|
src_ptr[x].Y = scanline[i].Y + 16;
|
2014-11-14 02:28:27 +00:00
|
|
|
// we mix our color differences in 10 bit space so it will round more accurately
|
2013-08-22 12:07:21 +00:00
|
|
|
// U[i] = 1/4 * U[i-1] + 1/2 * U[i] + 1/4 * U[i+1]
|
2017-09-03 02:30:34 +00:00
|
|
|
src_ptr[x].UV = 128 + ((scanline[i - 1].U + (scanline[i].U << 1) + scanline[i + 1].U) >> 2);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// YV pixel
|
2017-08-24 02:46:23 +00:00
|
|
|
src_ptr[x + 1].Y = scanline[i + 1].Y + 16;
|
2013-08-22 12:07:21 +00:00
|
|
|
// V[i] = 1/4 * V[i-1] + 1/2 * V[i] + 1/4 * V[i+1]
|
2017-08-24 02:46:23 +00:00
|
|
|
src_ptr[x + 1].UV =
|
2016-05-18 22:16:26 +00:00
|
|
|
128 + ((scanline[i - 1].V + (scanline[i].V << 1) + scanline[i + 1].V) >> 2);
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2017-08-24 02:46:23 +00:00
|
|
|
src_ptr += memory_stride;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2017-08-24 02:46:23 +00:00
|
|
|
|
2020-12-12 07:04:32 +00:00
|
|
|
const int src_width = source_rect.GetWidth();
|
|
|
|
const int src_height = source_rect.GetHeight();
|
|
|
|
const int dst_width = src_width;
|
|
|
|
const int dst_height = src_height * y_scale;
|
2017-10-24 05:44:14 +00:00
|
|
|
|
2020-12-12 07:04:32 +00:00
|
|
|
SW::CopyRegion(source.data(), src_width, src_height, reinterpret_cast<yuv422_packed*>(xfb_in_ram),
|
|
|
|
dst_width, dst_height);
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
bool ZCompare(u16 x, u16 y, u32 z)
|
|
|
|
{
|
|
|
|
u32 offset = GetDepthOffset(x, y);
|
|
|
|
u32 depth = GetPixelDepth(offset);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
bool pass;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
switch (bpmem.zmode.func)
|
|
|
|
{
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::Never:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = false;
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::Less:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = z < depth;
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::Equal:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = z == depth;
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::LEqual:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = z <= depth;
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::Greater:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = z > depth;
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::NEqual:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = z != depth;
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::GEqual:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = z >= depth;
|
|
|
|
break;
|
2021-02-11 02:11:31 +00:00
|
|
|
case CompareMode::Always:
|
2014-03-24 19:21:34 +00:00
|
|
|
pass = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pass = false;
|
2021-02-11 02:11:31 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Bad Z compare mode {}", bpmem.zmode.func);
|
2020-11-09 08:13:59 +00:00
|
|
|
break;
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
if (pass && bpmem.zmode.updateenable)
|
|
|
|
{
|
|
|
|
SetPixelDepth(offset, z);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-10-12 00:48:24 +00:00
|
|
|
return pass;
|
|
|
|
}
|
2018-05-18 19:13:03 +00:00
|
|
|
|
|
|
|
u32 GetPerfQueryResult(PerfQueryType type)
|
|
|
|
{
|
|
|
|
return perf_values[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetPerfQuery()
|
|
|
|
{
|
2018-05-18 19:36:37 +00:00
|
|
|
perf_values = {};
|
2018-05-18 19:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IncPerfCounterQuadCount(PerfQueryType type)
|
|
|
|
{
|
|
|
|
// NOTE: hardware doesn't process individual pixels but quads instead.
|
|
|
|
// Current software renderer architecture works on pixels though, so
|
|
|
|
// we have this "quad" hack here to only increment the registers on
|
|
|
|
// every fourth rendered pixel
|
|
|
|
static u32 quad[PQ_NUM_MEMBERS];
|
|
|
|
if (++quad[type] != 3)
|
|
|
|
return;
|
|
|
|
quad[type] = 0;
|
|
|
|
++perf_values[type];
|
|
|
|
}
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace EfbInterface
|