Skip to content

Commit

Permalink
fast implementation off hybrid xfb just to put in pair with master fu…
Browse files Browse the repository at this point in the history
…nctionality until merges from master are merged.
  • Loading branch information
Tinob committed Aug 27, 2018
1 parent 8486c03 commit 66b3bd0
Show file tree
Hide file tree
Showing 9 changed files with 864 additions and 480 deletions.
1,200 changes: 786 additions & 414 deletions Source/Core/DolphinWX/VideoConfigDiag.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D12/Render.cpp
Expand Up @@ -738,7 +738,7 @@ void Renderer::DrawFrame(const TargetRectangle& target_rc, const EFBRectangle& s
{
if (g_ActiveConfig.bUseXFB)
{
if (g_ActiveConfig.bUseRealXFB)
if (xfb_count == 0 || (xfb_count > 0 && xfb_sources[0]->real))
DrawRealXFB(target_rc, xfb_sources, xfb_count, dst_texture, dst_size, fb_width, fb_stride, fb_height);
else
DrawVirtualXFB(target_rc, xfb_addr, xfb_sources, xfb_count, dst_texture, dst_size, fb_width, fb_stride, fb_height, Gamma);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/DX11/Render.cpp
Expand Up @@ -852,7 +852,7 @@ void Renderer::DrawFrame(const TargetRectangle& target_rc, const EFBRectangle& s
{
if (g_ActiveConfig.bUseXFB)
{
if (g_ActiveConfig.bUseRealXFB)
if (xfb_count == 0 || (xfb_count > 0 && xfb_sources[0]->real))
DrawRealXFB(target_rc, xfb_addr, dst_texture, dst_size, fb_width, fb_stride, fb_height);
else
DrawVirtualXFB(target_rc, xfb_addr, xfb_sources, xfb_count, dst_texture, dst_size, fb_width, fb_stride, fb_height, Gamma);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/DX9/Render.cpp
Expand Up @@ -572,7 +572,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
sourceRc.right = (float)xfbSource->sourceRc.right;
sourceRc.top = (float)xfbSource->sourceRc.top;
sourceRc.bottom = (float)xfbSource->sourceRc.bottom;
if (g_ActiveConfig.bUseRealXFB)
if (xfbSource->real)
{
drawRc.top = 1;
drawRc.bottom = -1;
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/VideoBackends/DX9/TextureConverter.cpp
Expand Up @@ -151,7 +151,9 @@ void CreateYuyvToRgbProgram()
" out float4 ocol0 : COLOR0,\n"
" in float2 uv0 : TEXCOORD0)\n"
"{\n"
" float4 c0 = tex2D(samp0, uv0 / blkDims.zw).rgba;\n"
" float2 uv1 = uv0 / blkDims.zw;\n"
" uv1.y = 1.0 - uv1.y;\n"
" float4 c0 = tex2D(samp0, uv1).rgba;\n"
" float f = step(0.5, frac(uv0.x));\n"
" float y = lerp(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/Render.cpp
Expand Up @@ -1505,7 +1505,7 @@ void Renderer::DrawFrame(const TargetRectangle& target_rc, const EFBRectangle& s
{
if (g_ActiveConfig.bUseXFB)
{
if (g_ActiveConfig.bUseRealXFB)
if (xfb_count == 0 || (xfb_count > 0 && xfb_sources[0]->real))
DrawRealXFB(target_rc, xfb_sources, xfb_count, dst_texture, dst_size, fb_width, fb_stride, fb_height);
else
DrawVirtualXFB(target_rc, xfb_addr, xfb_sources, xfb_count, dst_texture, dst_size, fb_width, fb_stride, fb_height, Gamma);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Vulkan/Renderer.cpp
Expand Up @@ -657,7 +657,7 @@ void Renderer::DrawFrame(const TargetRectangle& target_rc, const TargetRectangle
{
if (!g_ActiveConfig.bUseXFB)
DrawEFB(target_rc, scaled_source_rc, dst_texture, dst_size, Gamma);
else if (g_ActiveConfig.bUseRealXFB)
else if (xfb_count == 0 || (xfb_count > 0 && xfb_sources[0]->real))
DrawRealXFB(target_rc, xfb_sources, xfb_count, fb_width, fb_stride, fb_height, dst_texture, dst_size, Gamma);
else
DrawVirtualXFB(target_rc, xfb_addr, xfb_sources, xfb_count, dst_texture, dst_size, fb_width, fb_stride, fb_height, Gamma);
Expand Down
51 changes: 35 additions & 16 deletions Source/Core/VideoCommon/FramebufferManagerBase.cpp
Expand Up @@ -6,6 +6,9 @@
#include <array>
#include <memory>
#include <utility>

#include "Core/HW/Memmap.h"

#include "VideoCommon/FramebufferManagerBase.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoConfig.h"
Expand Down Expand Up @@ -39,11 +42,22 @@ const XFBSourceBase* const* FramebufferManagerBase::GetXFBSource(u32 xfbAddr, u3
{
if (!g_ActiveConfig.bUseXFB)
return nullptr;

if (g_ActiveConfig.bUseRealXFB)
return GetRealXFBSource(xfbAddr, fbWidth, fbHeight, xfbCountP);
else
return GetVirtualXFBSource(xfbAddr, fbWidth, fbHeight, xfbCountP);
const XFBSourceBase* const* source = GetVirtualXFBSource(xfbAddr, fbWidth, fbHeight, xfbCountP);
if (g_ActiveConfig.bUseRealXFB && source != nullptr)
{
bool modified = false;
for (size_t i = 0; i < *xfbCountP && !modified; i++)
{
size_t srcHash = GetHash64(Memory::GetPointer(xfbAddr), source[i]->srcHeight * source[i]->srcStride,
g_ActiveConfig.iSafeTextureCache_ColorSamples);
modified = modified || srcHash != source[i]->hash;
}
if (modified)
{
return GetRealXFBSource(xfbAddr, fbWidth, fbHeight, xfbCountP);
}
}
return source;
}

const XFBSourceBase* const* FramebufferManagerBase::GetRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCountP)
Expand Down Expand Up @@ -72,7 +86,7 @@ const XFBSourceBase* const* FramebufferManagerBase::GetRealXFBSource(u32 xfbAddr
m_realXFBSource->sourceRc.top = 0;
m_realXFBSource->sourceRc.right = fbWidth;
m_realXFBSource->sourceRc.bottom = fbHeight;

m_realXFBSource->real = true;
// Decode YUYV data from GameCube RAM
m_realXFBSource->DecodeToTexture(xfbAddr, fbWidth, fbHeight);

Expand Down Expand Up @@ -113,22 +127,17 @@ const XFBSourceBase* const* FramebufferManagerBase::GetVirtualXFBSource(u32 xfbA

void FramebufferManagerBase::CopyToXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
{
if (!g_framebuffer_manager)
return;
if (g_ActiveConfig.bUseRealXFB)
{
if (g_framebuffer_manager)
g_framebuffer_manager->CopyToRealXFB(xfbAddr, fbStride, fbHeight, sourceRc, Gamma);
}
else
{
CopyToVirtualXFB(xfbAddr, fbStride, fbHeight, sourceRc, Gamma);
g_framebuffer_manager->CopyToRealXFB(xfbAddr, fbStride, fbHeight, sourceRc, Gamma);
}
CopyToVirtualXFB(xfbAddr, fbStride, fbHeight, sourceRc, Gamma);
}

void FramebufferManagerBase::CopyToVirtualXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
{
if (!g_framebuffer_manager)
return;

VirtualXFBListType::iterator vxfb = FindVirtualXFB(xfbAddr, sourceRc.GetWidth(), fbHeight);

if (m_virtualXFBList.end() == vxfb)
Expand Down Expand Up @@ -171,7 +180,17 @@ void FramebufferManagerBase::CopyToVirtualXFB(u32 xfbAddr, u32 fbStride, u32 fbH
vxfb->xfbSource->srcAddr = vxfb->xfbAddr = xfbAddr;
vxfb->xfbSource->srcWidth = vxfb->xfbWidth = sourceRc.GetWidth();
vxfb->xfbSource->srcHeight = vxfb->xfbHeight = fbHeight;

vxfb->xfbSource->srcStride = fbStride;
vxfb->xfbSource->real = false;
if (g_ActiveConfig.bUseRealXFB)
{
vxfb->xfbSource->hash = GetHash64(Memory::GetPointer(xfbAddr), fbHeight * fbStride,
g_ActiveConfig.iSafeTextureCache_ColorSamples);
}
else
{
vxfb->xfbSource->hash = 0;
}
vxfb->xfbSource->sourceRc = g_renderer->ConvertEFBRectangle(sourceRc);

// keep stale XFB data from being used
Expand Down
79 changes: 35 additions & 44 deletions Source/Core/VideoCommon/FramebufferManagerBase.h
Expand Up @@ -18,22 +18,22 @@ inline bool AddressRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper)

struct XFBSourceBase
{
virtual ~XFBSourceBase()
{}
virtual ~XFBSourceBase() {}

virtual void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) = 0;

virtual void CopyEFB(float Gamma) = 0;

u32 srcAddr;
u32 srcWidth;
u32 srcHeight;

unsigned int texWidth;
unsigned int texHeight;

bool real = 0;
u32 srcAddr = 0;
u32 srcWidth = 0;
u32 srcHeight = 0;
u32 srcStride = 0;

unsigned int texWidth = 0;
unsigned int texHeight = 0;
size_t hash = 0;
// TODO: only used by OGL
TargetRectangle sourceRc;
TargetRectangle sourceRc{};
};

class FramebufferManagerBase
Expand All @@ -49,40 +49,26 @@ class FramebufferManagerBase
FramebufferManagerBase();
virtual ~FramebufferManagerBase();

static void CopyToXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma);
static const XFBSourceBase* const* GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount);
static void CopyToXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc,
float Gamma);
static const XFBSourceBase* const* GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight,
u32* xfbCount);

static void SetLastXfbWidth(unsigned int width)
{
s_last_xfb_width = width;
}
static void SetLastXfbHeight(unsigned int height)
{
s_last_xfb_height = height;
}
static unsigned int LastXfbWidth()
{
return s_last_xfb_width;
}
static unsigned int LastXfbHeight()
{
return s_last_xfb_height;
}
static void SetLastXfbWidth(unsigned int width) { s_last_xfb_width = width; }
static void SetLastXfbHeight(unsigned int height) { s_last_xfb_height = height; }
static unsigned int LastXfbWidth() { return s_last_xfb_width; }
static unsigned int LastXfbHeight() { return s_last_xfb_height; }

static int ScaleToVirtualXfbWidth(int x);
static int ScaleToVirtualXfbHeight(int y);

static unsigned int GetEFBLayers()
{
return m_EFBLayers;
}
static unsigned int GetEFBLayers() { return m_EFBLayers; }
virtual void GetTargetSize(unsigned int* width, unsigned int* height) = 0;

protected:
struct VirtualXFB
{
VirtualXFB()
{}
VirtualXFB() {}

// Address and size in GameCube RAM
u32 xfbAddr = 0;
Expand All @@ -97,21 +83,26 @@ class FramebufferManagerBase
static unsigned int m_EFBLayers;

private:
virtual std::unique_ptr<XFBSourceBase> CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) = 0;
virtual std::unique_ptr<XFBSourceBase>
CreateXFBSource(unsigned int target_width, unsigned int target_height, unsigned int layers) = 0;

static VirtualXFBListType::iterator FindVirtualXFB(u32 xfbAddr, u32 width, u32 height);

static void ReplaceVirtualXFB();

// TODO: merge these virtual funcs, they are nearly all the same
virtual void CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma = 1.0f) = 0;
static void CopyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma = 1.0f);

static const XFBSourceBase* const* GetRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount);
static const XFBSourceBase* const* GetVirtualXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32* xfbCount);

static std::unique_ptr<XFBSourceBase> m_realXFBSource; // Only used in Real XFB mode
static VirtualXFBListType m_virtualXFBList; // Only used in Virtual XFB mode
virtual void CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc,
float Gamma = 1.0f) = 0;
static void CopyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,
float Gamma = 1.0f);

static const XFBSourceBase* const* GetRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight,
u32* xfbCount);
static const XFBSourceBase* const* GetVirtualXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight,
u32* xfbCount);

static std::unique_ptr<XFBSourceBase> m_realXFBSource; // Only used in Real XFB mode
static VirtualXFBListType m_virtualXFBList; // Only used in Virtual XFB mode

static std::array<const XFBSourceBase*, MAX_VIRTUAL_XFB> m_overlappingXFBArray;

Expand Down

0 comments on commit 66b3bd0

Please sign in to comment.