2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2015-12-21 19:11:01 +00:00
|
|
|
#include <d3d11.h>
|
|
|
|
#include <memory>
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/D3DTexture.h"
|
|
|
|
#include "VideoCommon/FramebufferManagerBase.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2015-12-21 19:11:01 +00:00
|
|
|
namespace DX11
|
|
|
|
{
|
2010-06-13 19:50:06 +00:00
|
|
|
// On the GameCube, the game sends a request for the graphics processor to
|
|
|
|
// transfer its internal EFB (Embedded Framebuffer) to an area in GameCube RAM
|
|
|
|
// called the XFB (External Framebuffer). The size and location of the XFB is
|
|
|
|
// decided at the time of the copy, and the format is always YUYV. The video
|
|
|
|
// interface is given a pointer to the XFB, which will be decoded and
|
|
|
|
// displayed on the TV.
|
|
|
|
//
|
|
|
|
// There are two ways for Dolphin to emulate this:
|
|
|
|
//
|
|
|
|
// Real XFB mode:
|
|
|
|
//
|
|
|
|
// Dolphin will behave like the GameCube and encode the EFB to
|
|
|
|
// a portion of GameCube RAM. The emulated video interface will decode the data
|
|
|
|
// for output to the screen.
|
|
|
|
//
|
|
|
|
// Advantages: Behaves exactly like the GameCube.
|
|
|
|
// Disadvantages: Resolution will be limited.
|
|
|
|
//
|
|
|
|
// Virtual XFB mode:
|
|
|
|
//
|
|
|
|
// When a request is made to copy the EFB to an XFB, Dolphin
|
|
|
|
// will remember the RAM location and size of the XFB in a Virtual XFB list.
|
|
|
|
// The video interface will look up the XFB in the list and use the enhanced
|
|
|
|
// data stored there, if available.
|
|
|
|
//
|
|
|
|
// Advantages: Enables high resolution graphics, better than real hardware.
|
|
|
|
// Disadvantages: If the GameCube CPU writes directly to the XFB (which is
|
|
|
|
// possible but uncommon), the Virtual XFB will not capture this information.
|
|
|
|
|
|
|
|
// There may be multiple XFBs in GameCube RAM. This is the maximum number to
|
|
|
|
// virtualize.
|
|
|
|
|
2010-11-14 23:31:53 +00:00
|
|
|
struct XFBSource : public XFBSourceBase
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
XFBSource(D3DTexture2D* _tex, int slices) : tex(_tex), m_slices(slices) {}
|
|
|
|
~XFBSource() { tex->Release(); }
|
|
|
|
void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) override;
|
|
|
|
void CopyEFB(float Gamma) override;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
D3DTexture2D* const tex;
|
|
|
|
const int m_slices;
|
2010-06-13 19:50:06 +00:00
|
|
|
};
|
|
|
|
|
2010-11-14 23:31:53 +00:00
|
|
|
class FramebufferManager : public FramebufferManagerBase
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-06-24 08:43:46 +00:00
|
|
|
FramebufferManager();
|
|
|
|
~FramebufferManager();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static D3DTexture2D*& GetEFBColorTexture();
|
|
|
|
static D3DTexture2D*& GetEFBColorReadTexture();
|
|
|
|
static ID3D11Texture2D*& GetEFBColorStagingBuffer();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static D3DTexture2D*& GetEFBDepthTexture();
|
|
|
|
static D3DTexture2D*& GetEFBDepthReadTexture();
|
|
|
|
static ID3D11Texture2D*& GetEFBDepthStagingBuffer();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static D3DTexture2D*& GetResolvedEFBColorTexture();
|
|
|
|
static D3DTexture2D*& GetResolvedEFBDepthTexture();
|
2010-11-23 19:58:02 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static D3DTexture2D*& GetEFBColorTempTexture() { return m_efb.color_temp_tex; }
|
|
|
|
static void SwapReinterpretTexture()
|
|
|
|
{
|
|
|
|
D3DTexture2D* swaptex = GetEFBColorTempTexture();
|
|
|
|
m_efb.color_temp_tex = GetEFBColorTexture();
|
|
|
|
m_efb.color_tex = swaptex;
|
|
|
|
}
|
2011-02-04 17:00:34 +00:00
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
private:
|
2016-06-24 08:43:46 +00:00
|
|
|
std::unique_ptr<XFBSourceBase> CreateXFBSource(unsigned int target_width,
|
|
|
|
unsigned int target_height,
|
|
|
|
unsigned int layers) override;
|
|
|
|
void GetTargetSize(unsigned int* width, unsigned int* height) override;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void CopyToRealXFB(u32 xfbAddr, u32 fbStride, u32 fbHeight, const EFBRectangle& sourceRc,
|
|
|
|
float Gamma) override;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static struct Efb
|
|
|
|
{
|
|
|
|
D3DTexture2D* color_tex;
|
|
|
|
ID3D11Texture2D* color_staging_buf;
|
|
|
|
D3DTexture2D* color_read_texture;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
D3DTexture2D* depth_tex;
|
|
|
|
ID3D11Texture2D* depth_staging_buf;
|
|
|
|
D3DTexture2D* depth_read_texture;
|
2010-11-23 19:58:02 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
D3DTexture2D* color_temp_tex;
|
2011-02-04 17:00:34 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
D3DTexture2D* resolved_color_tex;
|
|
|
|
D3DTexture2D* resolved_depth_tex;
|
2014-11-02 13:51:12 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
int slices;
|
|
|
|
} m_efb;
|
2014-12-24 23:57:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static unsigned int m_target_width;
|
|
|
|
static unsigned int m_target_height;
|
2010-06-13 19:50:06 +00:00
|
|
|
};
|
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
} // namespace DX11
|