2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "VideoBackends/Software/EfbCopy.h"
|
2016-01-17 14:54:31 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/HW/Memmap.h"
|
|
|
|
#include "VideoBackends/Software/EfbInterface.h"
|
|
|
|
#include "VideoBackends/Software/TextureEncoder.h"
|
2015-10-09 12:50:36 -06:00
|
|
|
|
|
|
|
#include "VideoCommon/BPMemory.h"
|
2014-07-08 08:49:33 -06:00
|
|
|
#include "VideoCommon/Fifo.h"
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static const float s_gammaLUT[] = {1.0f, 1.7f, 2.2f, 1.0f};
|
2013-08-20 05:51:39 -06:00
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
namespace EfbCopy
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
static void CopyToXfb(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,
|
|
|
|
float Gamma)
|
|
|
|
{
|
2016-09-24 17:06:47 -06:00
|
|
|
DEBUG_LOG(VIDEO, "xfbaddr: %x, fbwidth: %i, fbheight: %i, source: (%i, %i, %i, %i), Gamma %f",
|
|
|
|
xfbAddr, fbWidth, fbHeight, sourceRc.top, sourceRc.left, sourceRc.bottom,
|
|
|
|
sourceRc.right, Gamma);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
EfbInterface::yuv422_packed* xfb_in_ram =
|
|
|
|
(EfbInterface::yuv422_packed*)Memory::GetPointer(xfbAddr);
|
|
|
|
|
|
|
|
EfbInterface::CopyToXFB(xfb_in_ram, fbWidth, fbHeight, sourceRc, Gamma);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CopyToRam()
|
|
|
|
{
|
|
|
|
u8* dest_ptr = Memory::GetPointer(bpmem.copyTexDest << 5);
|
|
|
|
|
|
|
|
TextureEncoder::Encode(dest_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearEfb()
|
|
|
|
{
|
|
|
|
u32 clearColor = (bpmem.clearcolorAR & 0xff) << 24 | bpmem.clearcolorGB << 8 |
|
|
|
|
(bpmem.clearcolorAR & 0xff00) >> 8;
|
|
|
|
|
|
|
|
int left = bpmem.copyTexSrcXY.x;
|
|
|
|
int top = bpmem.copyTexSrcXY.y;
|
|
|
|
int right = left + bpmem.copyTexSrcWH.x;
|
|
|
|
int bottom = top + bpmem.copyTexSrcWH.y;
|
|
|
|
|
|
|
|
for (u16 y = top; y <= bottom; y++)
|
|
|
|
{
|
|
|
|
for (u16 x = left; x <= right; x++)
|
|
|
|
{
|
|
|
|
EfbInterface::SetColor(x, y, (u8*)(&clearColor));
|
|
|
|
EfbInterface::SetDepth(x, y, bpmem.clearZValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CopyEfb()
|
|
|
|
{
|
|
|
|
EFBRectangle rc;
|
|
|
|
rc.left = (int)bpmem.copyTexSrcXY.x;
|
|
|
|
rc.top = (int)bpmem.copyTexSrcXY.y;
|
|
|
|
|
|
|
|
// flipper represents the widths internally as last pixel minus starting pixel, so
|
|
|
|
// these are zero indexed.
|
|
|
|
rc.right = rc.left + (int)bpmem.copyTexSrcWH.x + 1;
|
|
|
|
rc.bottom = rc.top + (int)bpmem.copyTexSrcWH.y + 1;
|
|
|
|
|
|
|
|
if (!Fifo::WillSkipCurrentFrame())
|
|
|
|
{
|
|
|
|
if (bpmem.triggerEFBCopy.copy_to_xfb)
|
|
|
|
{
|
|
|
|
float yScale;
|
|
|
|
if (bpmem.triggerEFBCopy.scale_invert)
|
|
|
|
yScale = 256.0f / (float)bpmem.dispcopyyscale;
|
|
|
|
else
|
|
|
|
yScale = (float)bpmem.dispcopyyscale / 256.0f;
|
|
|
|
|
|
|
|
float xfbLines = ((bpmem.copyTexSrcWH.y + 1.0f) * yScale);
|
|
|
|
|
|
|
|
if (yScale != 1.0)
|
|
|
|
WARN_LOG(VIDEO, "yScale of %f is currently unsupported", yScale);
|
|
|
|
|
|
|
|
if ((u32)xfbLines > MAX_XFB_HEIGHT)
|
|
|
|
{
|
|
|
|
INFO_LOG(VIDEO, "Tried to scale EFB to too many XFB lines (%f)", xfbLines);
|
|
|
|
xfbLines = MAX_XFB_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyToXfb(bpmem.copyTexDest << 5, bpmem.copyMipMapStrideChannels << 4, (u32)xfbLines, rc,
|
|
|
|
s_gammaLUT[bpmem.triggerEFBCopy.gamma]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyToRam(); // FIXME: should use the rectangle we have already created above
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|