mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-21 01:31:39 +00:00
Merged some FramebufferManager code into VideoCommon.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6417 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
2378b443c1
commit
0da42fcca7
27 changed files with 840 additions and 1319 deletions
|
@ -23,117 +23,84 @@
|
|||
#include "VertexShaderCache.h"
|
||||
#include "TextureConverter.h"
|
||||
|
||||
// TODO: this is probably somewhere else
|
||||
#define SAFE_RELEASE(p) if (p) { (p)->Release(); (p) = NULL; }
|
||||
|
||||
#undef CHECK
|
||||
#define CHECK(hr, Message, ...) if (FAILED(hr)) { PanicAlert(__FUNCTION__ "Failed in %s at line %d: " Message, __FILE__, __LINE__, __VA_ARGS__); }
|
||||
|
||||
FramebufferManager g_framebufferManager;
|
||||
FramebufferManager::Efb FramebufferManager::s_efb;
|
||||
|
||||
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorRTSurface()
|
||||
FramebufferManager::FramebufferManager()
|
||||
{
|
||||
return s_efb_color_surface;
|
||||
}
|
||||
s_efb.color_texture = NULL;
|
||||
s_efb.colorRead_texture = NULL;
|
||||
s_efb.depth_texture = NULL;
|
||||
s_efb.depthRead_texture = NULL;
|
||||
|
||||
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthRTSurface()
|
||||
{
|
||||
return s_efb_depth_surface;
|
||||
}
|
||||
s_efb.depth_surface = NULL;
|
||||
s_efb.color_surface = NULL;
|
||||
s_efb.color_ReadBuffer = NULL;
|
||||
s_efb.depth_ReadBuffer = NULL;
|
||||
s_efb.color_OffScreenReadBuffer = NULL;
|
||||
s_efb.depth_OffScreenReadBuffer = NULL;
|
||||
|
||||
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorOffScreenRTSurface()
|
||||
{
|
||||
return s_efb_color_OffScreenReadBuffer;
|
||||
}
|
||||
s_efb.color_surface_Format = D3DFMT_FORCE_DWORD;
|
||||
s_efb.depth_surface_Format = D3DFMT_FORCE_DWORD;
|
||||
s_efb.depth_ReadBuffer_Format = D3DFMT_FORCE_DWORD;
|
||||
|
||||
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthOffScreenRTSurface()
|
||||
{
|
||||
return s_efb_depth_OffScreenReadBuffer;
|
||||
}
|
||||
|
||||
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorReadSurface()
|
||||
{
|
||||
return s_efb_color_ReadBuffer;
|
||||
}
|
||||
|
||||
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthReadSurface()
|
||||
{
|
||||
return s_efb_depth_ReadBuffer;
|
||||
}
|
||||
|
||||
D3DFORMAT FramebufferManager::GetEFBDepthRTSurfaceFormat()
|
||||
{
|
||||
return s_efb_depth_surface_Format;
|
||||
}
|
||||
|
||||
D3DFORMAT FramebufferManager::GetEFBDepthReadSurfaceFormat()
|
||||
{
|
||||
return s_efb_depth_ReadBuffer_Format;
|
||||
}
|
||||
|
||||
D3DFORMAT FramebufferManager::GetEFBColorRTSurfaceFormat()
|
||||
{
|
||||
return s_efb_color_surface_Format;
|
||||
}
|
||||
|
||||
LPDIRECT3DTEXTURE9 FramebufferManager::GetEFBColorTexture()
|
||||
{
|
||||
return s_efb_color_texture;
|
||||
}
|
||||
|
||||
LPDIRECT3DTEXTURE9 FramebufferManager::GetEFBDepthTexture()
|
||||
{
|
||||
return s_efb_depth_texture;
|
||||
}
|
||||
|
||||
void FramebufferManager::Create()
|
||||
{
|
||||
// Simplest possible setup to start with.
|
||||
int target_width = Renderer::GetFullTargetWidth();
|
||||
int target_height = Renderer::GetFullTargetHeight();
|
||||
|
||||
s_efb_color_surface_Format = D3DFMT_A8R8G8B8;
|
||||
s_efb.color_surface_Format = D3DFMT_A8R8G8B8;
|
||||
// Get the framebuffer texture
|
||||
HRESULT hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb_color_texture, NULL);
|
||||
if(s_efb_color_texture)
|
||||
HRESULT hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb.color_surface_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb.color_texture, NULL);
|
||||
if (s_efb.color_texture)
|
||||
{
|
||||
hr = s_efb_color_texture->GetSurfaceLevel(0, &s_efb_color_surface);
|
||||
hr = s_efb.color_texture->GetSurfaceLevel(0, &s_efb.color_surface);
|
||||
}
|
||||
CHECK(hr, "Create color texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
|
||||
hr = D3D::dev->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb_colorRead_texture, NULL);
|
||||
hr = D3D::dev->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, s_efb.color_surface_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb.colorRead_texture, NULL);
|
||||
CHECK(hr, "Create Color Read Texture (hr=%#x)", hr);
|
||||
if(s_efb_colorRead_texture)
|
||||
if (s_efb.colorRead_texture)
|
||||
{
|
||||
s_efb_colorRead_texture->GetSurfaceLevel(0, &s_efb_color_ReadBuffer);
|
||||
s_efb.colorRead_texture->GetSurfaceLevel(0, &s_efb.color_ReadBuffer);
|
||||
}
|
||||
// Create an offscreen surface that we can lock to retrieve the data
|
||||
hr = D3D::dev->CreateOffscreenPlainSurface(1, 1, s_efb_color_surface_Format, D3DPOOL_SYSTEMMEM, &s_efb_color_OffScreenReadBuffer, NULL);
|
||||
hr = D3D::dev->CreateOffscreenPlainSurface(1, 1, s_efb.color_surface_Format, D3DPOOL_SYSTEMMEM, &s_efb.color_OffScreenReadBuffer, NULL);
|
||||
CHECK(hr, "Create offscreen color surface (hr=%#x)", hr);
|
||||
|
||||
// Select a Z-buffer format with hardware support
|
||||
D3DFORMAT *DepthTexFormats = new D3DFORMAT[5];
|
||||
DepthTexFormats[0] = FOURCC_INTZ;
|
||||
DepthTexFormats[1] = FOURCC_DF24;
|
||||
DepthTexFormats[2] = FOURCC_RAWZ;
|
||||
DepthTexFormats[3] = FOURCC_DF16;
|
||||
DepthTexFormats[4] = D3DFMT_D24X8;
|
||||
D3DFORMAT DepthTexFormats[5] = {
|
||||
FOURCC_INTZ,
|
||||
FOURCC_DF24,
|
||||
FOURCC_RAWZ,
|
||||
FOURCC_DF16,
|
||||
D3DFMT_D24X8
|
||||
};
|
||||
|
||||
for(int i = 0; i < 5; i++)
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
s_efb_depth_surface_Format = DepthTexFormats[i];
|
||||
s_efb.depth_surface_Format = DepthTexFormats[i];
|
||||
// Create the framebuffer depth texture
|
||||
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_DEPTHSTENCIL, s_efb_depth_surface_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb_depth_texture, NULL);
|
||||
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_DEPTHSTENCIL, s_efb.depth_surface_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb.depth_texture, NULL);
|
||||
if (!FAILED(hr))
|
||||
break;
|
||||
}
|
||||
|
||||
CHECK(hr, "Framebuffer depth texture (size: %dx%d; hr=%#x)", target_width, target_height, hr);
|
||||
// Get the Surface
|
||||
if(s_efb_depth_texture)
|
||||
if (s_efb.depth_texture)
|
||||
{
|
||||
s_efb_depth_texture->GetSurfaceLevel(0, &s_efb_depth_surface);
|
||||
s_efb.depth_texture->GetSurfaceLevel(0, &s_efb.depth_surface);
|
||||
}
|
||||
|
||||
// Create a 4x4 pixel texture to work as a buffer for peeking
|
||||
if(s_efb_depth_surface_Format == FOURCC_RAWZ || s_efb_depth_surface_Format == D3DFMT_D24X8)
|
||||
if (s_efb.depth_surface_Format == FOURCC_RAWZ || s_efb.depth_surface_Format == D3DFMT_D24X8)
|
||||
{
|
||||
DepthTexFormats[0] = D3DFMT_A8R8G8B8;
|
||||
}
|
||||
|
@ -141,161 +108,82 @@ void FramebufferManager::Create()
|
|||
{
|
||||
DepthTexFormats[0] = D3DFMT_R32F;
|
||||
}
|
||||
|
||||
DepthTexFormats[1] = D3DFMT_A8R8G8B8;
|
||||
|
||||
for(int i = 0; i < 2; i++)
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
s_efb_depth_ReadBuffer_Format = DepthTexFormats[i];
|
||||
s_efb.depth_ReadBuffer_Format = DepthTexFormats[i];
|
||||
// Get the framebuffer Depth texture
|
||||
hr = D3D::dev->CreateTexture(4, 4, 1, D3DUSAGE_RENDERTARGET, s_efb_depth_ReadBuffer_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb_depthRead_texture, NULL);
|
||||
hr = D3D::dev->CreateTexture(4, 4, 1, D3DUSAGE_RENDERTARGET, s_efb.depth_ReadBuffer_Format,
|
||||
D3DPOOL_DEFAULT, &s_efb.depthRead_texture, NULL);
|
||||
if (!FAILED(hr))
|
||||
break;
|
||||
}
|
||||
|
||||
CHECK(hr, "Create depth read texture (hr=%#x)", hr);
|
||||
if(s_efb_depthRead_texture)
|
||||
if (s_efb.depthRead_texture)
|
||||
{
|
||||
s_efb_depthRead_texture->GetSurfaceLevel(0, &s_efb_depth_ReadBuffer);
|
||||
s_efb.depthRead_texture->GetSurfaceLevel(0, &s_efb.depth_ReadBuffer);
|
||||
}
|
||||
|
||||
// Create an offscreen surface that we can lock to retrieve the data
|
||||
hr = D3D::dev->CreateOffscreenPlainSurface(4, 4, s_efb_depth_ReadBuffer_Format, D3DPOOL_SYSTEMMEM, &s_efb_depth_OffScreenReadBuffer, NULL);
|
||||
hr = D3D::dev->CreateOffscreenPlainSurface(4, 4, s_efb.depth_ReadBuffer_Format, D3DPOOL_SYSTEMMEM, &s_efb.depth_OffScreenReadBuffer, NULL);
|
||||
CHECK(hr, "Create depth offscreen surface (hr=%#x)", hr);
|
||||
delete [] DepthTexFormats;
|
||||
}
|
||||
|
||||
void FramebufferManager::Destroy()
|
||||
FramebufferManager::~FramebufferManager()
|
||||
{
|
||||
if (s_efb_depth_surface)
|
||||
s_efb_depth_surface->Release();
|
||||
s_efb_depth_surface = NULL;
|
||||
|
||||
if (s_efb_color_surface)
|
||||
s_efb_color_surface->Release();
|
||||
s_efb_color_surface = NULL;
|
||||
|
||||
if (s_efb_color_ReadBuffer)
|
||||
s_efb_color_ReadBuffer->Release();
|
||||
s_efb_color_ReadBuffer = NULL;
|
||||
|
||||
if (s_efb_depth_ReadBuffer)
|
||||
s_efb_depth_ReadBuffer->Release();
|
||||
s_efb_depth_ReadBuffer = NULL;
|
||||
|
||||
if (s_efb_color_OffScreenReadBuffer)
|
||||
s_efb_color_OffScreenReadBuffer->Release();
|
||||
s_efb_color_OffScreenReadBuffer = NULL;
|
||||
|
||||
if (s_efb_depth_OffScreenReadBuffer)
|
||||
s_efb_depth_OffScreenReadBuffer->Release();
|
||||
s_efb_depth_OffScreenReadBuffer = NULL;
|
||||
|
||||
if (s_efb_color_texture)
|
||||
s_efb_color_texture->Release();
|
||||
s_efb_color_texture = NULL;
|
||||
|
||||
if (s_efb_colorRead_texture)
|
||||
s_efb_colorRead_texture->Release();
|
||||
s_efb_colorRead_texture = NULL;
|
||||
|
||||
if (s_efb_depth_texture)
|
||||
s_efb_depth_texture->Release();
|
||||
s_efb_depth_texture = NULL;
|
||||
|
||||
if (s_efb_depthRead_texture)
|
||||
s_efb_depthRead_texture->Release();
|
||||
s_efb_depthRead_texture = NULL;
|
||||
|
||||
for (VirtualXFBListType::iterator it = m_virtualXFBList.begin(); it != m_virtualXFBList.end(); ++it)
|
||||
{
|
||||
if(it->xfbSource.texture)
|
||||
it->xfbSource.texture->Release();
|
||||
}
|
||||
m_virtualXFBList.clear();
|
||||
if(m_realXFBSource.texture)
|
||||
m_realXFBSource.texture->Release();
|
||||
m_realXFBSource.texture = NULL;
|
||||
|
||||
SAFE_RELEASE(s_efb.depth_surface);
|
||||
SAFE_RELEASE(s_efb.color_surface);
|
||||
SAFE_RELEASE(s_efb.color_ReadBuffer);
|
||||
SAFE_RELEASE(s_efb.depth_ReadBuffer);
|
||||
SAFE_RELEASE(s_efb.color_OffScreenReadBuffer);
|
||||
SAFE_RELEASE(s_efb.depth_OffScreenReadBuffer);
|
||||
SAFE_RELEASE(s_efb.color_texture);
|
||||
SAFE_RELEASE(s_efb.colorRead_texture);
|
||||
SAFE_RELEASE(s_efb.depth_texture);
|
||||
SAFE_RELEASE(s_efb.depthRead_texture);
|
||||
}
|
||||
|
||||
void FramebufferManager::CopyToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc)
|
||||
XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height)
|
||||
{
|
||||
if (g_ActiveConfig.bUseRealXFB)
|
||||
copyToRealXFB(xfbAddr, fbWidth, fbHeight, sourceRc);
|
||||
else
|
||||
copyToVirtualXFB(xfbAddr, fbWidth, fbHeight, sourceRc);
|
||||
LPDIRECT3DTEXTURE9 tex;
|
||||
D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET,
|
||||
s_efb.color_surface_Format, D3DPOOL_DEFAULT, &tex, NULL);
|
||||
|
||||
return new XFBSource(tex);
|
||||
}
|
||||
|
||||
const XFBSource** FramebufferManager::GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32 &xfbCount)
|
||||
void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc)
|
||||
{
|
||||
if (g_ActiveConfig.bUseRealXFB)
|
||||
return getRealXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
|
||||
else
|
||||
return getVirtualXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
|
||||
const float scaleX = Renderer::GetXFBScaleX();
|
||||
const float scaleY = Renderer::GetXFBScaleY();
|
||||
|
||||
TargetRectangle targetSource;
|
||||
|
||||
targetSource.top = (int)(sourceRc.top *scaleY);
|
||||
targetSource.bottom = (int)(sourceRc.bottom *scaleY);
|
||||
targetSource.left = (int)(sourceRc.left *scaleX);
|
||||
targetSource.right = (int)(sourceRc.right * scaleX);
|
||||
|
||||
*width = targetSource.right - targetSource.left;
|
||||
*height = targetSource.bottom - targetSource.top;
|
||||
}
|
||||
|
||||
FramebufferManager::VirtualXFBListType::iterator FramebufferManager::findVirtualXFB(u32 xfbAddr, u32 width, u32 height)
|
||||
void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,
|
||||
const MathUtil::Rectangle<float> &drawrc, int width, int height) const
|
||||
{
|
||||
u32 srcLower = xfbAddr;
|
||||
u32 srcUpper = xfbAddr + 2 * width * height;
|
||||
|
||||
VirtualXFBListType::iterator it;
|
||||
for (it = m_virtualXFBList.begin(); it != m_virtualXFBList.end(); ++it)
|
||||
{
|
||||
u32 dstLower = it->xfbAddr;
|
||||
u32 dstUpper = it->xfbAddr + 2 * it->xfbWidth * it->xfbHeight;
|
||||
|
||||
if (dstLower >= srcLower && dstUpper <= srcUpper)
|
||||
return it;
|
||||
}
|
||||
|
||||
// That address is not in the Virtual XFB list.
|
||||
return m_virtualXFBList.end();
|
||||
D3D::drawShadedTexSubQuad(texture, &sourcerc, texWidth, texHeight, &drawrc, width , height,
|
||||
PixelShaderCache::GetColorCopyProgram(0), VertexShaderCache::GetSimpleVertexShader(0));
|
||||
}
|
||||
|
||||
void FramebufferManager::replaceVirtualXFB()
|
||||
void XFBSource::DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
|
||||
{
|
||||
VirtualXFBListType::iterator it = m_virtualXFBList.begin();
|
||||
|
||||
s32 srcLower = it->xfbAddr;
|
||||
s32 srcUpper = it->xfbAddr + 2 * it->xfbWidth * it->xfbHeight;
|
||||
s32 lineSize = 2 * it->xfbWidth;
|
||||
|
||||
++it;
|
||||
|
||||
while (it != m_virtualXFBList.end())
|
||||
{
|
||||
s32 dstLower = it->xfbAddr;
|
||||
s32 dstUpper = it->xfbAddr + 2 * it->xfbWidth * it->xfbHeight;
|
||||
|
||||
if (dstLower >= srcLower && dstUpper <= srcUpper)
|
||||
{
|
||||
// Invalidate the data
|
||||
it->xfbAddr = 0;
|
||||
it->xfbHeight = 0;
|
||||
it->xfbWidth = 0;
|
||||
}
|
||||
else if (addrRangesOverlap(srcLower, srcUpper, dstLower, dstUpper))
|
||||
{
|
||||
s32 upperOverlap = (srcUpper - dstLower) / lineSize;
|
||||
s32 lowerOverlap = (dstUpper - srcLower) / lineSize;
|
||||
|
||||
if (upperOverlap > 0 && lowerOverlap < 0)
|
||||
{
|
||||
it->xfbAddr += lineSize * upperOverlap;
|
||||
it->xfbHeight -= upperOverlap;
|
||||
}
|
||||
else if (lowerOverlap > 0)
|
||||
{
|
||||
it->xfbHeight -= lowerOverlap;
|
||||
}
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, texture);
|
||||
}
|
||||
|
||||
void FramebufferManager::copyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc)
|
||||
void FramebufferManager::CopyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc)
|
||||
{
|
||||
u8* xfb_in_ram = Memory_GetPtr(xfbAddr);
|
||||
if (!xfb_in_ram)
|
||||
|
@ -308,190 +196,47 @@ void FramebufferManager::copyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, c
|
|||
TextureConverter::EncodeToRamYUYV(GetEFBColorTexture(), targetRc, xfb_in_ram, fbWidth, fbHeight);
|
||||
}
|
||||
|
||||
void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc)
|
||||
void XFBSource::CopyEFB()
|
||||
{
|
||||
LPDIRECT3DTEXTURE9 xfbTexture;
|
||||
HRESULT hr = 0;
|
||||
|
||||
VirtualXFBListType::iterator it = findVirtualXFB(xfbAddr, fbWidth, fbHeight);
|
||||
|
||||
if (it == m_virtualXFBList.end() && (int)m_virtualXFBList.size() >= MAX_VIRTUAL_XFB)
|
||||
{
|
||||
// Replace the last virtual XFB
|
||||
--it;
|
||||
}
|
||||
|
||||
float scaleX = Renderer::GetXFBScaleX();
|
||||
float scaleY = Renderer::GetXFBScaleY();
|
||||
TargetRectangle targetSource,efbSource;
|
||||
efbSource = Renderer::ConvertEFBRectangle(sourceRc);
|
||||
targetSource.top = (int)(sourceRc.top *scaleY);
|
||||
targetSource.bottom = (int)(sourceRc.bottom *scaleY);
|
||||
targetSource.left = (int)(sourceRc.left *scaleX);
|
||||
targetSource.right = (int)(sourceRc.right * scaleX);
|
||||
int target_width = targetSource.right - targetSource.left;
|
||||
int target_height = targetSource.bottom - targetSource.top;
|
||||
if (it != m_virtualXFBList.end())
|
||||
{
|
||||
// Overwrite an existing Virtual XFB.
|
||||
|
||||
it->xfbAddr = xfbAddr;
|
||||
it->xfbWidth = fbWidth;
|
||||
it->xfbHeight = fbHeight;
|
||||
|
||||
it->xfbSource.srcAddr = xfbAddr;
|
||||
it->xfbSource.srcWidth = fbWidth;
|
||||
it->xfbSource.srcHeight = fbHeight;
|
||||
|
||||
if(it->xfbSource.texWidth != target_width || it->xfbSource.texHeight != target_height || !(it->xfbSource.texture))
|
||||
{
|
||||
if(it->xfbSource.texture)
|
||||
it->xfbSource.texture->Release();
|
||||
it->xfbSource.texture = NULL;
|
||||
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
|
||||
D3DPOOL_DEFAULT, &(it->xfbSource.texture), NULL);
|
||||
|
||||
}
|
||||
|
||||
xfbTexture = it->xfbSource.texture;
|
||||
|
||||
it->xfbSource.texWidth = target_width;
|
||||
it->xfbSource.texHeight = target_height;
|
||||
|
||||
// Move this Virtual XFB to the front of the list.
|
||||
m_virtualXFBList.splice(m_virtualXFBList.begin(), m_virtualXFBList, it);
|
||||
|
||||
// Keep stale XFB data from being used
|
||||
replaceVirtualXFB();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a new Virtual XFB and place it at the front of the list.
|
||||
|
||||
D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
|
||||
D3DPOOL_DEFAULT, &xfbTexture, NULL);
|
||||
VirtualXFB newVirt;
|
||||
|
||||
newVirt.xfbAddr = xfbAddr;
|
||||
newVirt.xfbWidth = fbWidth;
|
||||
newVirt.xfbHeight = fbHeight;
|
||||
|
||||
newVirt.xfbSource.texture = xfbTexture;
|
||||
newVirt.xfbSource.texWidth = target_width;
|
||||
newVirt.xfbSource.texHeight = target_height;
|
||||
|
||||
// Add the new Virtual XFB to the list
|
||||
|
||||
if ((int)m_virtualXFBList.size() >= MAX_VIRTUAL_XFB)
|
||||
{
|
||||
// List overflowed; delete the oldest.
|
||||
m_virtualXFBList.back().xfbSource.texture->Release();
|
||||
m_virtualXFBList.pop_back();
|
||||
}
|
||||
|
||||
m_virtualXFBList.push_front(newVirt);
|
||||
}
|
||||
|
||||
// Copy EFB data to XFB and restore render target again
|
||||
if(!xfbTexture)
|
||||
return;
|
||||
LPDIRECT3DTEXTURE9 read_texture = GetEFBColorTexture();
|
||||
|
||||
Renderer::ResetAPIState(); // Reset any game specific settings
|
||||
LPDIRECT3DSURFACE9 Rendersurf = NULL;
|
||||
|
||||
xfbTexture->GetSurfaceLevel(0, &Rendersurf);
|
||||
texture->GetSurfaceLevel(0, &Rendersurf);
|
||||
D3D::dev->SetDepthStencilSurface(NULL);
|
||||
D3D::dev->SetRenderTarget(0, Rendersurf);
|
||||
|
||||
D3DVIEWPORT9 vp;
|
||||
|
||||
D3DVIEWPORT9 vp;
|
||||
vp.X = 0;
|
||||
vp.Y = 0;
|
||||
vp.Width = target_width;
|
||||
vp.Height = target_height;
|
||||
vp.Width = texWidth;
|
||||
vp.Height = texHeight;
|
||||
vp.MinZ = 0.0f;
|
||||
vp.MaxZ = 1.0f;
|
||||
D3D::dev->SetViewport(&vp);
|
||||
|
||||
RECT sourcerect;
|
||||
sourcerect.bottom = efbSource.bottom;
|
||||
sourcerect.left = efbSource.left;
|
||||
sourcerect.right = efbSource.right;
|
||||
sourcerect.top = efbSource.top;
|
||||
sourcerect.bottom = sourceRc.bottom;
|
||||
sourcerect.left = sourceRc.left;
|
||||
sourcerect.right = sourceRc.right;
|
||||
sourcerect.top = sourceRc.top;
|
||||
|
||||
D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
D3D::drawShadedTexQuad(
|
||||
read_texture,
|
||||
FramebufferManager::GetEFBColorTexture(),
|
||||
&sourcerect,
|
||||
Renderer::GetFullTargetWidth(),
|
||||
Renderer::GetFullTargetHeight(),
|
||||
target_width,
|
||||
target_height,
|
||||
texWidth,
|
||||
texHeight,
|
||||
PixelShaderCache::GetColorCopyProgram( g_ActiveConfig.iMultisampleMode),
|
||||
VertexShaderCache::GetSimpleVertexShader( g_ActiveConfig.iMultisampleMode));
|
||||
|
||||
|
||||
|
||||
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
|
||||
D3D::RefreshSamplerState(0, D3DSAMP_MAGFILTER);
|
||||
D3D::SetTexture(0, NULL);
|
||||
D3D::dev->SetRenderTarget(0, GetEFBColorRTSurface());
|
||||
D3D::dev->SetDepthStencilSurface(GetEFBDepthRTSurface());
|
||||
Renderer::RestoreAPIState();
|
||||
D3D::dev->SetRenderTarget(0, FramebufferManager::GetEFBColorRTSurface());
|
||||
D3D::dev->SetDepthStencilSurface(FramebufferManager::GetEFBDepthRTSurface());
|
||||
|
||||
Rendersurf->Release();
|
||||
}
|
||||
|
||||
const XFBSource** FramebufferManager::getRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32 &xfbCount)
|
||||
{
|
||||
xfbCount = 1;
|
||||
|
||||
m_realXFBSource.texWidth = fbWidth;
|
||||
m_realXFBSource.texHeight = fbHeight;
|
||||
|
||||
m_realXFBSource.srcAddr = xfbAddr;
|
||||
m_realXFBSource.srcWidth = fbWidth;
|
||||
m_realXFBSource.srcHeight = fbHeight;
|
||||
|
||||
if (!m_realXFBSource.texture)
|
||||
{
|
||||
D3D::dev->CreateTexture(fbWidth, fbHeight, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
|
||||
D3DPOOL_DEFAULT, &m_realXFBSource.texture, NULL);
|
||||
}
|
||||
|
||||
// Decode YUYV data from GameCube RAM
|
||||
TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, m_realXFBSource.texture);
|
||||
|
||||
m_overlappingXFBArray[0] = &m_realXFBSource;
|
||||
|
||||
return &m_overlappingXFBArray[0];
|
||||
}
|
||||
|
||||
const XFBSource** FramebufferManager::getVirtualXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32 &xfbCount)
|
||||
{
|
||||
xfbCount = 0;
|
||||
|
||||
if (m_virtualXFBList.size() == 0)
|
||||
{
|
||||
// No Virtual XFBs available.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u32 srcLower = xfbAddr;
|
||||
u32 srcUpper = xfbAddr + 2 * fbWidth * fbHeight;
|
||||
|
||||
VirtualXFBListType::reverse_iterator it;
|
||||
for (it = m_virtualXFBList.rbegin(); it != m_virtualXFBList.rend(); ++it)
|
||||
{
|
||||
u32 dstLower = it->xfbAddr;
|
||||
u32 dstUpper = it->xfbAddr + 2 * it->xfbWidth * it->xfbHeight;
|
||||
|
||||
if (addrRangesOverlap(srcLower, srcUpper, dstLower, dstUpper))
|
||||
{
|
||||
m_overlappingXFBArray[xfbCount] = &(it->xfbSource);
|
||||
xfbCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return &m_overlappingXFBArray[0];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue