Skip to content

Commit

Permalink
Merge pull request #977 from Sonicadvance1/xfb-scaling-rebased
Browse files Browse the repository at this point in the history
XFB Scaling
  • Loading branch information
Sonicadvance1 committed Sep 19, 2014
2 parents 0d1c1e9 + c5f9301 commit af25b15
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 25 deletions.
5 changes: 3 additions & 2 deletions Source/Core/Core/HW/VideoInterface.cpp
Expand Up @@ -516,7 +516,8 @@ static void BeginField(FieldType field)
// What should actually happen is that we should pass on the correct width,
// stride, and height to the video backend, and it should deinterlace the
// output when appropriate.
u32 fbWidth = m_PictureConfiguration.STD * (field == FIELD_PROGRESSIVE ? 16 : 8);
u32 fbStride = m_PictureConfiguration.STD * (field == FIELD_PROGRESSIVE ? 16 : 8);
u32 fbWidth = m_PictureConfiguration.WPL * 16;
u32 fbHeight = m_VerticalTimingRegister.ACV * (field == FIELD_PROGRESSIVE ? 1 : 2);
u32 xfbAddr;

Expand Down Expand Up @@ -550,7 +551,7 @@ static void BeginField(FieldType field)
m_VerticalTimingRegister.ACV, fieldTypeNames[field]);

if (xfbAddr)
g_video_backend->Video_BeginField(xfbAddr, fbWidth, fbHeight);
g_video_backend->Video_BeginField(xfbAddr, fbWidth, fbStride, fbHeight);
}

static void EndField()
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D/Render.cpp
Expand Up @@ -709,7 +709,7 @@ void formatBufferDump(const u8* in, u8* out, int w, int h, int p)
}

// This function has the final picture. We adjust the aspect ratio here.
void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma)
{
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D/Render.h
Expand Up @@ -40,7 +40,7 @@ class Renderer : public ::Renderer

TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) override;

void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma) override;
void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma) override;

void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) override;

Expand Down
18 changes: 10 additions & 8 deletions Source/Core/VideoBackends/OGL/Render.cpp
Expand Up @@ -1359,7 +1359,7 @@ static void DumpFrame(const std::vector<u8>& data, int w, int h)
}

// This function has the final picture. We adjust the aspect ratio here.
void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma)
{
static int w = 0, h = 0;
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
Expand All @@ -1370,7 +1370,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
}

u32 xfbCount = 0;
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbStride, fbHeight, xfbCount);
if (g_ActiveConfig.VirtualXFBEnabled() && (!xfbSourceList || xfbCount == 0))
{
DumpFrame(frame_data, w, h);
Expand Down Expand Up @@ -1426,14 +1426,14 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
// use virtual xfb with offset
int xfbHeight = xfbSource->srcHeight;
int xfbWidth = xfbSource->srcWidth;
int hOffset = ((s32)xfbSource->srcAddr - (s32)xfbAddr) / ((s32)fbWidth * 2);
int hOffset = ((s32)xfbSource->srcAddr - (s32)xfbAddr) / ((s32)fbStride * 2);

MathUtil::Rectangle<u32> rect_u32;

rect_u32.top = flipped_trc.top - hOffset * flipped_trc.GetHeight() / fbHeight;
rect_u32.bottom = flipped_trc.top - (hOffset + xfbHeight) * flipped_trc.GetHeight() / fbHeight;
rect_u32.left = flipped_trc.left + (flipped_trc.GetWidth() - xfbWidth * flipped_trc.GetWidth() / fbWidth)/2;
rect_u32.right = flipped_trc.left + (flipped_trc.GetWidth() + xfbWidth * flipped_trc.GetWidth() / fbWidth)/2;
rect_u32.left = flipped_trc.left + (flipped_trc.GetWidth() - xfbWidth * flipped_trc.GetWidth() / fbStride)/2;
rect_u32.right = flipped_trc.left + (flipped_trc.GetWidth() + xfbWidth * flipped_trc.GetWidth() / fbStride)/2;

drawRc.top = static_cast<float>(rect_u32.top);
drawRc.bottom = static_cast<float>(rect_u32.bottom);
Expand All @@ -1458,6 +1458,8 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
sourceRc.top = xfbSource->sourceRc.top;
sourceRc.bottom = xfbSource->sourceRc.bottom;

sourceRc.right -= fbStride - fbWidth;

xfbSource->Draw(sourceRc, drawRc);
}
}
Expand Down Expand Up @@ -1603,16 +1605,16 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
}
// Finish up the current frame, print some stats

SetWindowSize(fbWidth, fbHeight);
SetWindowSize(fbStride, fbHeight);

GLInterface->Update(); // just updates the render window position and the backbuffer size

bool xfbchanged = false;

if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight)
if (FramebufferManagerBase::LastXfbWidth() != fbStride || FramebufferManagerBase::LastXfbHeight() != fbHeight)
{
xfbchanged = true;
unsigned int const last_w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth;
unsigned int const last_w = (fbStride < 1 || fbStride > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbStride;
unsigned int const last_h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
FramebufferManagerBase::SetLastXfbWidth(last_w);
FramebufferManagerBase::SetLastXfbHeight(last_h);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/Render.h
Expand Up @@ -76,7 +76,7 @@ class Renderer : public ::Renderer

TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) override;

void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma) override;
void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma) override;

void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) override;

Expand Down
5 changes: 4 additions & 1 deletion Source/Core/VideoBackends/Software/SWmain.cpp
Expand Up @@ -201,8 +201,11 @@ void VideoSoftware::Video_Prepare()
}

// Run from the CPU thread (from VideoInterface.cpp)
void VideoSoftware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
void VideoSoftware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight)
{
// XXX: fbStride should be implemented properly here
// If stride isn't implemented then there are problems with XFB
// Animal Crossing is a good example for this.
s_beginFieldArgs.xfbAddr = xfbAddr;
s_beginFieldArgs.fbWidth = fbWidth;
s_beginFieldArgs.fbHeight = fbHeight;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Software/VideoBackend.h
Expand Up @@ -27,7 +27,7 @@ class VideoSoftware : public VideoBackend

void Video_EnterLoop() override;
void Video_ExitLoop() override;
void Video_BeginField(u32, u32, u32) override;
void Video_BeginField(u32, u32, u32, u32) override;
void Video_EndField() override;

u32 Video_AccessEFB(EFBAccessType, u32, u32, u32) override;
Expand Down
8 changes: 5 additions & 3 deletions Source/Core/VideoCommon/MainBase.cpp
Expand Up @@ -29,6 +29,7 @@ static volatile struct
{
u32 xfbAddr;
u32 fbWidth;
u32 fbStride;
u32 fbHeight;
} s_beginFieldArgs;

Expand Down Expand Up @@ -74,7 +75,7 @@ static void VideoFifo_CheckSwapRequest()
if (s_swapRequested.IsSet())
{
EFBRectangle rc;
Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight,rc);
Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbStride, s_beginFieldArgs.fbHeight, rc);
s_swapRequested.Clear();
}
}
Expand All @@ -90,7 +91,7 @@ void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
u32 aLower = xfbAddr;
u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight;
u32 bLower = s_beginFieldArgs.xfbAddr;
u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight;
u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbStride * s_beginFieldArgs.fbHeight;

if (addrRangesOverlap(aLower, aUpper, bLower, bUpper))
VideoFifo_CheckSwapRequest();
Expand All @@ -99,14 +100,15 @@ void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
}

// Run from the CPU thread (from VideoInterface.cpp)
void VideoBackendHardware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
void VideoBackendHardware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight)
{
if (s_BackendInitialized && g_ActiveConfig.bUseXFB)
{
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
VideoFifo_CheckSwapRequest();
s_beginFieldArgs.xfbAddr = xfbAddr;
s_beginFieldArgs.fbWidth = fbWidth;
s_beginFieldArgs.fbStride = fbStride;
s_beginFieldArgs.fbHeight = fbHeight;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoCommon/RenderBase.cpp
Expand Up @@ -122,7 +122,7 @@ void Renderer::RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbWidt
}
else
{
Swap(xfbAddr, fbWidth, fbHeight,sourceRc,Gamma);
Swap(xfbAddr, fbWidth, fbWidth, fbHeight, sourceRc, Gamma);
s_swapRequested.Clear();
}
}
Expand Down Expand Up @@ -514,10 +514,10 @@ void Renderer::RecordVideoMemory()
FifoRecorder::GetInstance().SetVideoMemory(bpmem_ptr, cpmem, xfmem_ptr, xfregs_ptr, xfregs_size);
}

void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc, float Gamma)
void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma)
{
// TODO: merge more generic parts into VideoCommon
g_renderer->SwapImpl(xfbAddr, fbWidth, fbHeight, rc, Gamma);
g_renderer->SwapImpl(xfbAddr, fbWidth, fbStride, fbHeight, rc, Gamma);

if (XFBWrited)
g_renderer->m_fps_counter.Update();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/RenderBase.h
Expand Up @@ -109,8 +109,8 @@ class Renderer
virtual void RestoreAPIState() = 0;

// Finish up the current frame, print some stats
static void Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f);
virtual void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f) = 0;
static void Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f);
virtual void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma = 1.0f) = 0;

virtual bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc) = 0;

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/VideoBackendBase.h
Expand Up @@ -84,7 +84,7 @@ class VideoBackend
virtual void Video_ExitLoop() = 0;
virtual void Video_Cleanup() = 0; // called from gl/d3d thread

virtual void Video_BeginField(u32, u32, u32) = 0;
virtual void Video_BeginField(u32, u32, u32, u32) = 0;
virtual void Video_EndField() = 0;

virtual u32 Video_AccessEFB(EFBAccessType, u32, u32, u32) = 0;
Expand Down Expand Up @@ -130,7 +130,7 @@ class VideoBackendHardware : public VideoBackend

void Video_EnterLoop() override;
void Video_ExitLoop() override;
void Video_BeginField(u32, u32, u32) override;
void Video_BeginField(u32, u32, u32, u32) override;
void Video_EndField() override;

u32 Video_AccessEFB(EFBAccessType, u32, u32, u32) override;
Expand Down

0 comments on commit af25b15

Please sign in to comment.