2013-08-17 11:23:51 +02:00
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
# include "math/lin/matrix4x4.h"
# include "Core/Host.h"
# include "Core/MemMap.h"
# include "Core/Config.h"
# include "Core/System.h"
2013-11-15 14:24:25 +01:00
# include "Core/Reporting.h"
2013-08-17 11:23:51 +02:00
# include "GPU/ge_constants.h"
# include "GPU/GPUState.h"
# include "helper/dx_state.h"
# include "helper/fbo.h"
2014-09-09 08:12:42 -07:00
# include "GPU/Common/FramebufferCommon.h"
2014-09-13 16:37:59 -07:00
# include "GPU/Common/TextureDecoder.h"
2013-09-15 12:46:14 +02:00
# include "GPU/Directx9/FramebufferDX9.h"
# include "GPU/Directx9/ShaderManagerDX9.h"
2014-09-13 14:23:18 -07:00
# include "GPU/Directx9/TextureCacheDX9.h"
# include "GPU/Directx9/TransformPipelineDX9.h"
2013-08-17 11:23:51 +02:00
2013-09-17 00:48:14 -04:00
# include <algorithm>
2013-09-15 08:53:21 -07:00
namespace DX9 {
2013-11-15 14:24:25 +01:00
inline u16 RGBA8888toRGB565 ( u32 px ) {
return ( ( px > > 3 ) & 0x001F ) | ( ( px > > 5 ) & 0x07E0 ) | ( ( px > > 8 ) & 0xF800 ) ;
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
inline u16 RGBA8888toRGBA4444 ( u32 px ) {
return ( ( px > > 4 ) & 0x000F ) | ( ( px > > 8 ) & 0x00F0 ) | ( ( px > > 12 ) & 0x0F00 ) | ( ( px > > 16 ) & 0xF000 ) ;
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
inline u16 RGBA8888toRGBA5551 ( u32 px ) {
return ( ( px > > 3 ) & 0x001F ) | ( ( px > > 6 ) & 0x03E0 ) | ( ( px > > 9 ) & 0x7C00 ) | ( ( px > > 16 ) & 0x8000 ) ;
}
2013-08-17 11:23:51 +02:00
2014-09-13 16:37:59 -07:00
inline u16 BGRA8888toRGB565 ( u32 px ) {
return ( ( px > > 19 ) & 0x001F ) | ( ( px > > 5 ) & 0x07E0 ) | ( ( px < < 8 ) & 0xF800 ) ;
}
inline u16 BGRA8888toRGBA4444 ( u32 px ) {
return ( ( px > > 20 ) & 0x000F ) | ( ( px > > 8 ) & 0x00F0 ) | ( ( px < < 4 ) & 0x0F00 ) | ( ( px > > 16 ) & 0xF000 ) ;
}
static void ConvertFromRGBA8888 ( u8 * dst , u8 * src , u32 dstStride , u32 srcStride , u32 width , u32 height , GEBufferFormat format ) ;
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
void CenterRect ( float * x , float * y , float * w , float * h ,
float origW , float origH , float frameW , float frameH ) {
if ( g_Config . bStretchToDisplay ) {
* x = 0 ;
* y = 0 ;
* w = frameW ;
* h = frameH ;
return ;
}
float origRatio = origW / origH ;
float frameRatio = frameW / frameH ;
if ( origRatio > frameRatio ) {
// Image is wider than frame. Center vertically.
float scale = origW / frameW ;
* x = 0.0f ;
* w = frameW ;
* h = frameW / origRatio ;
// Stretch a little bit
if ( g_Config . bPartialStretch )
* h = ( frameH + * h ) / 2.0f ; // (408 + 720) / 2 = 564
* y = ( frameH - * h ) / 2.0f ;
} else {
// Image is taller than frame. Center horizontally.
float scale = origH / frameH ;
* y = 0.0f ;
* h = frameH ;
* w = frameH * origRatio ;
* x = ( frameW - * w ) / 2.0f ;
}
2013-08-17 11:23:51 +02:00
}
2014-09-09 08:12:42 -07:00
void FramebufferManagerDX9 : : ClearBuffer ( ) {
2014-08-30 11:18:18 -07:00
dxstate . scissorTest . disable ( ) ;
dxstate . depthWrite . set ( TRUE ) ;
2013-11-15 14:24:25 +01:00
dxstate . colorMask . set ( true , true , true , true ) ;
2014-08-30 11:18:18 -07:00
dxstate . stencilFunc . set ( D3DCMP_ALWAYS , 0 , 0 ) ;
dxstate . stencilMask . set ( 0xFF ) ;
2013-11-15 14:24:25 +01:00
pD3Ddevice - > Clear ( 0 , NULL , D3DCLEAR_STENCIL | D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , D3DCOLOR_XRGB ( 0 , 0 , 0 ) , 0 , 0 ) ;
}
2013-08-17 11:23:51 +02:00
2014-09-09 08:12:42 -07:00
void FramebufferManagerDX9 : : ClearDepthBuffer ( ) {
dxstate . scissorTest . disable ( ) ;
dxstate . depthWrite . set ( TRUE ) ;
dxstate . colorMask . set ( false , false , false , false ) ;
dxstate . stencilFunc . set ( D3DCMP_NEVER , 0 , 0 ) ;
pD3Ddevice - > Clear ( 0 , NULL , D3DCLEAR_ZBUFFER , D3DCOLOR_XRGB ( 0 , 0 , 0 ) , 0 , 0 ) ;
}
void FramebufferManagerDX9 : : DisableState ( ) {
2013-11-15 14:24:25 +01:00
dxstate . blend . disable ( ) ;
dxstate . cullMode . set ( false , false ) ;
dxstate . depthTest . disable ( ) ;
dxstate . scissorTest . disable ( ) ;
dxstate . stencilTest . disable ( ) ;
2014-08-30 11:18:18 -07:00
dxstate . colorMask . set ( true , true , true , true ) ;
dxstate . stencilMask . set ( 0xFF ) ;
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
FramebufferManagerDX9 : : FramebufferManagerDX9 ( ) :
drawPixelsTex_ ( 0 ) ,
2014-09-13 15:09:30 -07:00
convBuf ( 0 ) ,
2014-09-14 02:21:41 -07:00
stencilUploadPS_ ( nullptr ) ,
stencilUploadVS_ ( nullptr ) ,
stencilUploadFailed_ ( false ) ,
2014-09-13 19:56:08 -07:00
gameUsesSequentialCopies_ ( false ) {
2013-11-15 14:24:25 +01:00
}
FramebufferManagerDX9 : : ~ FramebufferManagerDX9 ( ) {
2014-09-13 19:56:08 -07:00
if ( drawPixelsTex_ ) {
2013-11-15 14:24:25 +01:00
drawPixelsTex_ - > Release ( ) ;
}
2014-09-13 22:39:54 -07:00
for ( auto it = tempFBOs_ . begin ( ) , end = tempFBOs_ . end ( ) ; it ! = end ; + + it ) {
fbo_destroy ( it - > second . fbo ) ;
}
2014-09-13 22:28:39 -07:00
for ( auto it = offscreenSurfaces_ . begin ( ) , end = offscreenSurfaces_ . end ( ) ; it ! = end ; + + it ) {
it - > second . surface - > Release ( ) ;
}
2013-11-15 14:24:25 +01:00
delete [ ] convBuf ;
2014-09-14 02:21:41 -07:00
if ( stencilUploadPS_ ) {
stencilUploadPS_ - > Release ( ) ;
}
if ( stencilUploadVS_ ) {
stencilUploadVS_ - > Release ( ) ;
}
2013-11-15 14:24:25 +01:00
}
static inline void ARGB8From4444 ( u16 c , u32 * dst ) {
* dst = ( ( c & 0xf ) < < 4 ) | ( ( ( c > > 4 ) & 0xf ) < < 12 ) | ( ( ( c > > 8 ) & 0xf ) < < 20 ) | ( ( c > > 12 ) < < 28 ) ;
}
static inline void ARGB8From565 ( u16 c , u32 * dst ) {
* dst = ( ( c & 0x001f ) < < 19 ) | ( ( ( c > > 5 ) & 0x003f ) < < 11 ) | ( ( ( ( c > > 10 ) & 0x001f ) < < 3 ) ) | 0xFF000000 ;
}
static inline void ARGB8From5551 ( u16 c , u32 * dst ) {
* dst = ( ( c & 0x001f ) < < 19 ) | ( ( ( c > > 5 ) & 0x001f ) < < 11 ) | ( ( ( ( c > > 10 ) & 0x001f ) < < 3 ) ) | 0xFF000000 ;
2013-08-17 11:23:51 +02:00
}
2014-09-13 14:53:14 -07:00
// TODO: Swizzle the texture access instead.
static inline u32 RGBA2BGRA ( u32 src ) {
const u32 r = ( src & 0x000000FF ) < < 16 ;
const u32 ga = src & 0xFF00FF00 ;
const u32 b = ( src & 0x00FF0000 ) > > 16 ;
return r | ga | b ;
2013-11-15 14:24:25 +01:00
}
2013-08-19 20:36:43 +02:00
2014-09-13 13:09:26 -07:00
void FramebufferManagerDX9 : : MakePixelTexture ( const u8 * srcPixels , GEBufferFormat srcPixelFormat , int srcStride , int width , int height ) {
u8 * convBuf = NULL ;
2013-11-15 14:24:25 +01:00
D3DLOCKED_RECT rect ;
2013-08-19 20:36:43 +02:00
2014-09-13 19:56:08 -07:00
// TODO: Check / use D3DCAPS2_DYNAMICTEXTURES?
if ( drawPixelsTex_ & & ( drawPixelsTexW_ ! = width | | drawPixelsTexH_ ! = height ) ) {
drawPixelsTex_ - > Release ( ) ;
drawPixelsTex_ = nullptr ;
}
if ( ! drawPixelsTex_ ) {
int usage = 0 ;
D3DPOOL pool = D3DPOOL_MANAGED ;
if ( pD3DdeviceEx ) {
pool = D3DPOOL_DEFAULT ;
usage = D3DUSAGE_DYNAMIC ;
}
HRESULT hr = pD3Ddevice - > CreateTexture ( width , height , 1 , usage , D3DFMT ( D3DFMT_A8R8G8B8 ) , pool , & drawPixelsTex_ , NULL ) ;
if ( FAILED ( hr ) ) {
drawPixelsTex_ = nullptr ;
ERROR_LOG ( G3D , " Failed to create drawpixels texture " ) ;
}
2014-09-13 21:45:18 -07:00
drawPixelsTexW_ = width ;
drawPixelsTexH_ = height ;
2014-09-13 19:56:08 -07:00
}
2014-09-09 22:28:35 +02:00
if ( ! drawPixelsTex_ ) {
return ;
}
2014-09-01 08:20:27 -07:00
drawPixelsTex_ - > LockRect ( 0 , & rect , NULL , 0 ) ;
2013-08-19 20:36:43 +02:00
2013-11-15 14:24:25 +01:00
convBuf = ( u8 * ) rect . pBits ;
2013-08-17 11:23:51 +02:00
2014-09-13 14:53:14 -07:00
// Final format is BGRA(directx)
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
// TODO: We can just change the texture format and flip some bits around instead of this.
2014-09-13 13:09:26 -07:00
if ( srcPixelFormat ! = GE_FORMAT_8888 | | srcStride ! = 512 ) {
2014-09-13 14:54:53 -07:00
for ( int y = 0 ; y < height ; y + + ) {
2014-09-13 13:09:26 -07:00
switch ( srcPixelFormat ) {
2013-11-15 14:24:25 +01:00
// not tested
case GE_FORMAT_565 :
{
2014-09-13 14:53:14 -07:00
const u16_le * src = ( const u16_le * ) srcPixels + srcStride * y ;
u32 * dst = ( u32 * ) ( convBuf + rect . Pitch * y ) ;
2014-09-13 14:54:53 -07:00
for ( int x = 0 ; x < width ; x + + ) {
2013-11-15 14:24:25 +01:00
u16_le col0 = src [ x + 0 ] ;
ARGB8From565 ( col0 , & dst [ x + 0 ] ) ;
}
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
break ;
// faster
case GE_FORMAT_5551 :
{
2014-09-13 14:53:14 -07:00
const u16_le * src = ( const u16_le * ) srcPixels + srcStride * y ;
u32 * dst = ( u32 * ) ( convBuf + rect . Pitch * y ) ;
2014-09-13 14:54:53 -07:00
for ( int x = 0 ; x < width ; x + + ) {
2013-11-15 14:24:25 +01:00
u16_le col0 = src [ x + 0 ] ;
ARGB8From5551 ( col0 , & dst [ x + 0 ] ) ;
}
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
break ;
case GE_FORMAT_4444 :
2013-08-17 11:23:51 +02:00
{
2014-09-13 14:53:14 -07:00
const u16_le * src = ( const u16_le * ) srcPixels + srcStride * y ;
2014-09-13 21:50:38 -07:00
u8 * dst = ( u8 * ) ( convBuf + rect . Pitch * y ) ;
2014-09-13 14:54:53 -07:00
for ( int x = 0 ; x < width ; x + + )
2013-11-15 14:24:25 +01:00
{
u16_le col = src [ x ] ;
dst [ x * 4 + 0 ] = ( col > > 12 ) < < 4 ;
dst [ x * 4 + 1 ] = ( ( col > > 8 ) & 0xf ) < < 4 ;
dst [ x * 4 + 2 ] = ( ( col > > 4 ) & 0xf ) < < 4 ;
dst [ x * 4 + 3 ] = ( col & 0xf ) < < 4 ;
}
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
break ;
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
case GE_FORMAT_8888 :
2013-08-24 19:07:15 +02:00
{
2014-09-13 14:53:14 -07:00
const u32_le * src = ( const u32_le * ) srcPixels + srcStride * y ;
u32 * dst = ( u32 * ) ( convBuf + rect . Pitch * y ) ;
2014-09-13 14:54:53 -07:00
for ( int x = 0 ; x < width ; x + + )
2013-11-15 14:24:25 +01:00
{
2014-09-13 14:53:14 -07:00
dst [ x ] = RGBA2BGRA ( src [ x ] ) ;
2013-11-15 14:24:25 +01:00
}
2013-08-24 19:07:15 +02:00
}
2013-11-15 14:24:25 +01:00
break ;
2013-08-17 11:23:51 +02:00
}
}
2013-11-15 14:24:25 +01:00
} else {
2014-09-13 14:54:53 -07:00
for ( int y = 0 ; y < height ; y + + ) {
2014-09-13 14:53:14 -07:00
const u32_le * src = ( const u32_le * ) srcPixels + srcStride * y ;
u32 * dst = ( u32 * ) ( convBuf + rect . Pitch * y ) ;
2014-09-13 14:54:53 -07:00
for ( int x = 0 ; x < width ; x + + )
2013-11-15 14:24:25 +01:00
{
2014-09-13 14:53:14 -07:00
dst [ x ] = RGBA2BGRA ( src [ x ] ) ;
2013-11-15 14:24:25 +01:00
}
2013-08-24 19:07:15 +02:00
}
}
2013-08-23 11:07:39 +02:00
2013-11-15 14:24:25 +01:00
drawPixelsTex_ - > UnlockRect ( 0 ) ;
// D3DXSaveTextureToFile("game:\\cc.png", D3DXIFF_PNG, drawPixelsTex_, NULL);
2014-09-13 13:09:26 -07:00
}
void FramebufferManagerDX9 : : DrawPixels ( VirtualFramebuffer * vfb , int dstX , int dstY , const u8 * srcPixels , GEBufferFormat srcPixelFormat , int srcStride , int width , int height ) {
if ( useBufferedRendering_ & & vfb - > fbo ) {
fbo_bind_as_render_target ( vfb - > fbo ) ;
}
dxstate . viewport . set ( 0 , 0 , vfb - > renderWidth , vfb - > renderHeight ) ;
MakePixelTexture ( srcPixels , srcPixelFormat , srcStride , width , height ) ;
DisableState ( ) ;
2014-09-13 14:57:45 -07:00
DrawActiveTexture ( drawPixelsTex_ , dstX , dstY , width , height , vfb - > bufferWidth , vfb - > bufferHeight , false , 0.0f , 0.0f , 1.0f , 1.0f ) ;
textureCache_ - > ForgetLastTexture ( ) ;
2014-09-13 13:09:26 -07:00
}
void FramebufferManagerDX9 : : DrawFramebuffer ( const u8 * srcPixels , GEBufferFormat srcPixelFormat , int srcStride , bool applyPostShader ) {
MakePixelTexture ( srcPixels , srcPixelFormat , srcStride , 512 , 272 ) ;
2013-11-15 14:24:25 +01:00
2014-09-13 13:09:26 -07:00
DisableState ( ) ;
// This might draw directly at the backbuffer (if so, applyPostShader is set) so if there's a post shader, we need to apply it here.
// Should try to unify this path with the regular path somehow, but this simple solution works for most of the post shaders
// (it always runs at output resolution so FXAA may look odd).
2013-11-15 14:24:25 +01:00
float x , y , w , h ;
CenterRect ( & x , & y , & w , & h , 480.0f , 272.0f , ( float ) PSP_CoreParameter ( ) . pixelWidth , ( float ) PSP_CoreParameter ( ) . pixelHeight ) ;
2014-09-13 13:09:26 -07:00
DrawActiveTexture ( drawPixelsTex_ , x , y , w , h , ( float ) PSP_CoreParameter ( ) . pixelWidth , ( float ) PSP_CoreParameter ( ) . pixelHeight , false , 0.0f , 0.0f , 480.0f / 512.0f ) ;
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
// Depth in ogl is between -1;1 we need between 0;1
static void ConvertMatrices ( Matrix4x4 & in ) {
/*
in . zz * = 0.5f ;
in . wz + = 1.f ;
*/
Matrix4x4 s ;
Matrix4x4 t ;
s . setScaling ( Vec3 ( 1 , 1 , 0.5f ) ) ;
t . setTranslation ( Vec3 ( 0 , 0 , 0.5f ) ) ;
in = in * s ;
in = in * t ;
2013-08-17 11:23:51 +02:00
}
2014-09-13 13:09:26 -07:00
void FramebufferManagerDX9 : : DrawActiveTexture ( LPDIRECT3DTEXTURE9 tex , float x , float y , float w , float h , float destW , float destH , bool flip , float u0 , float v0 , float u1 , float v1 ) {
if ( flip ) {
std : : swap ( v0 , v1 ) ;
}
// TODO: StretchRect instead?
float coord [ 20 ] = {
x , y , 0 , u0 , v0 ,
x + w , y , 0 , u1 , v0 ,
x + w , y + h , 0 , u1 , v1 ,
x , y + h , 0 , u0 , v1 ,
} ;
2013-11-15 14:24:25 +01:00
2014-09-13 13:09:26 -07:00
float invDestW = 1.0f / ( destW * 0.5f ) ;
float invDestH = 1.0f / ( destH * 0.5f ) ;
2013-11-15 14:24:25 +01:00
for ( int i = 0 ; i < 4 ; i + + ) {
2014-09-13 13:09:26 -07:00
coord [ i * 5 ] = coord [ i * 5 ] * invDestW - 1.0f ;
coord [ i * 5 + 1 ] = - ( coord [ i * 5 + 1 ] * invDestH - 1.0f ) ;
2013-11-15 14:24:25 +01:00
}
//pD3Ddevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
pD3Ddevice - > SetRenderState ( D3DRS_CULLMODE , D3DCULL_NONE ) ;
pD3Ddevice - > SetVertexDeclaration ( pFramebufferVertexDecl ) ;
pD3Ddevice - > SetPixelShader ( pFramebufferPixelShader ) ;
pD3Ddevice - > SetVertexShader ( pFramebufferVertexShader ) ;
2014-09-13 20:05:41 -07:00
shaderManager_ - > DirtyLastShader ( ) ;
2013-11-15 14:24:25 +01:00
if ( tex ! = NULL ) {
pD3Ddevice - > SetTexture ( 0 , tex ) ;
}
2014-09-13 19:21:59 -07:00
HRESULT hr = pD3Ddevice - > DrawPrimitiveUP ( D3DPT_TRIANGLEFAN , 2 , coord , 5 * sizeof ( float ) ) ;
if ( FAILED ( hr ) ) {
ERROR_LOG_REPORT ( G3D , " DrawActiveTexture() failed: %08x " , hr ) ;
}
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
2014-09-09 08:12:42 -07:00
void FramebufferManagerDX9 : : DestroyFramebuf ( VirtualFramebuffer * v ) {
2013-11-15 14:24:25 +01:00
textureCache_ - > NotifyFramebuffer ( v - > fb_address , v , NOTIFY_FB_DESTROYED ) ;
if ( v - > fbo ) {
fbo_destroy ( v - > fbo ) ;
v - > fbo = 0 ;
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
// Wipe some pointers
if ( currentRenderVfb_ = = v )
currentRenderVfb_ = 0 ;
if ( displayFramebuf_ = = v )
displayFramebuf_ = 0 ;
if ( prevDisplayFramebuf_ = = v )
prevDisplayFramebuf_ = 0 ;
if ( prevPrevDisplayFramebuf_ = = v )
prevPrevDisplayFramebuf_ = 0 ;
delete v ;
}
2013-08-17 11:23:51 +02:00
2014-09-13 14:26:39 -07:00
void FramebufferManagerDX9 : : RebindFramebuffer ( ) {
if ( currentRenderVfb_ & & currentRenderVfb_ - > fbo ) {
fbo_bind_as_render_target ( currentRenderVfb_ - > fbo ) ;
} else {
fbo_unbind ( ) ;
}
}
2014-09-09 22:56:54 -07:00
void FramebufferManagerDX9 : : ResizeFramebufFBO ( VirtualFramebuffer * vfb , u16 w , u16 h , bool force ) {
float renderWidthFactor = ( float ) vfb - > renderWidth / ( float ) vfb - > bufferWidth ;
float renderHeightFactor = ( float ) vfb - > renderHeight / ( float ) vfb - > bufferHeight ;
VirtualFramebuffer old = * vfb ;
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
if ( force ) {
vfb - > bufferWidth = w ;
vfb - > bufferHeight = h ;
} else {
if ( vfb - > bufferWidth > = w & & vfb - > bufferHeight > = h ) {
return ;
}
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
// In case it gets thin and wide, don't resize down either side.
vfb - > bufferWidth = std : : max ( vfb - > bufferWidth , w ) ;
vfb - > bufferHeight = std : : max ( vfb - > bufferHeight , h ) ;
}
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
vfb - > renderWidth = vfb - > bufferWidth * renderWidthFactor ;
vfb - > renderHeight = vfb - > bufferHeight * renderHeightFactor ;
2013-08-20 18:46:57 +02:00
2014-09-09 22:56:54 -07:00
bool trueColor = g_Config . bTrueColor ;
if ( hackForce04154000Download_ & & vfb - > fb_address = = 0x00154000 ) {
trueColor = true ;
}
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
if ( trueColor ) {
vfb - > colorDepth = FBO_8888 ;
} else {
switch ( vfb - > format ) {
case GE_FORMAT_4444 :
vfb - > colorDepth = FBO_4444 ;
break ;
case GE_FORMAT_5551 :
vfb - > colorDepth = FBO_5551 ;
break ;
case GE_FORMAT_565 :
vfb - > colorDepth = FBO_565 ;
break ;
case GE_FORMAT_8888 :
default :
vfb - > colorDepth = FBO_8888 ;
break ;
2013-11-15 14:24:25 +01:00
}
}
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
textureCache_ - > ForgetLastTexture ( ) ;
fbo_unbind ( ) ;
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
if ( ! useBufferedRendering_ ) {
if ( vfb - > fbo ) {
fbo_destroy ( vfb - > fbo ) ;
vfb - > fbo = 0 ;
2013-08-17 11:23:51 +02:00
}
2014-09-09 22:56:54 -07:00
return ;
}
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
vfb - > fbo = fbo_create ( vfb - > renderWidth , vfb - > renderHeight , 1 , true , ( FBOColorDepth ) vfb - > colorDepth ) ;
if ( old . fbo ) {
INFO_LOG ( SCEGE , " Resizing FBO for %08x : %i x %i x %i " , vfb - > fb_address , w , h , vfb - > format ) ;
if ( vfb - > fbo ) {
2014-09-13 18:46:59 -07:00
fbo_bind_as_render_target ( vfb - > fbo ) ;
2014-09-09 22:56:54 -07:00
ClearBuffer ( ) ;
if ( ! g_Config . bDisableSlowFramebufEffects ) {
2014-09-13 15:12:06 -07:00
BlitFramebuffer ( vfb , 0 , 0 , & old , 0 , 0 , std : : min ( vfb - > bufferWidth , vfb - > width ) , std : : min ( vfb - > height , vfb - > bufferHeight ) , 0 ) ;
2013-11-15 14:24:25 +01:00
}
2013-08-17 11:23:51 +02:00
}
2014-09-09 22:56:54 -07:00
fbo_destroy ( old . fbo ) ;
if ( vfb - > fbo ) {
fbo_bind_as_render_target ( vfb - > fbo ) ;
}
}
2013-08-20 18:46:57 +02:00
2014-09-09 22:56:54 -07:00
if ( ! vfb - > fbo ) {
ERROR_LOG ( SCEGE , " Error creating FBO! %i x %i " , vfb - > renderWidth , vfb - > renderHeight ) ;
}
}
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
void FramebufferManagerDX9 : : NotifyRenderFramebufferCreated ( VirtualFramebuffer * vfb ) {
if ( ! useBufferedRendering_ ) {
fbo_unbind ( ) ;
// Let's ignore rendering to targets that have not (yet) been displayed.
gstate_c . skipDrawReason | = SKIPDRAW_NON_DISPLAYED_FB ;
}
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
textureCache_ - > NotifyFramebuffer ( vfb - > fb_address , vfb , NOTIFY_FB_CREATED ) ;
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
ClearBuffer ( ) ;
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
// ugly...
if ( gstate_c . curRTWidth ! = vfb - > width | | gstate_c . curRTHeight ! = vfb - > height ) {
shaderManager_ - > DirtyUniform ( DIRTY_PROJTHROUGHMATRIX ) ;
}
2014-09-13 22:01:32 -07:00
if ( gstate_c . curRTRenderWidth ! = vfb - > renderWidth | | gstate_c . curRTRenderHeight ! = vfb - > renderHeight ) {
shaderManager_ - > DirtyUniform ( DIRTY_PROJMATRIX ) ;
shaderManager_ - > DirtyUniform ( DIRTY_PROJTHROUGHMATRIX ) ;
}
2014-09-09 22:56:54 -07:00
}
void FramebufferManagerDX9 : : NotifyRenderFramebufferSwitched ( VirtualFramebuffer * prevVfb , VirtualFramebuffer * vfb ) {
if ( ShouldDownloadFramebuffer ( vfb ) & & ! vfb - > memoryUpdated ) {
2014-09-13 15:09:30 -07:00
ReadFramebufferToMemory ( vfb , true , 0 , 0 , vfb - > width , vfb - > height ) ;
2014-09-09 22:56:54 -07:00
}
textureCache_ - > ForgetLastTexture ( ) ;
if ( useBufferedRendering_ ) {
if ( vfb - > fbo ) {
fbo_bind_as_render_target ( vfb - > fbo ) ;
2013-08-17 11:23:51 +02:00
} else {
2014-09-09 22:56:54 -07:00
// wtf? This should only happen very briefly when toggling bBufferedRendering
2013-08-17 11:23:51 +02:00
fbo_unbind ( ) ;
2014-09-09 22:56:54 -07:00
}
} else {
if ( vfb - > fbo ) {
// wtf? This should only happen very briefly when toggling bBufferedRendering
textureCache_ - > NotifyFramebuffer ( vfb - > fb_address , vfb , NOTIFY_FB_DESTROYED ) ;
fbo_destroy ( vfb - > fbo ) ;
vfb - > fbo = 0 ;
}
fbo_unbind ( ) ;
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
// Let's ignore rendering to targets that have not (yet) been displayed.
if ( vfb - > usageFlags & FB_USAGE_DISPLAYED_FRAMEBUFFER ) {
gstate_c . skipDrawReason & = ~ SKIPDRAW_NON_DISPLAYED_FB ;
} else {
gstate_c . skipDrawReason | = SKIPDRAW_NON_DISPLAYED_FB ;
2013-11-15 14:24:25 +01:00
}
2014-09-09 22:56:54 -07:00
}
textureCache_ - > NotifyFramebuffer ( vfb - > fb_address , vfb , NOTIFY_FB_UPDATED ) ;
2013-08-17 11:23:51 +02:00
2014-09-09 22:56:54 -07:00
// Copy depth pixel value from the read framebuffer to the draw framebuffer
if ( prevVfb & & ! g_Config . bDisableSlowFramebufEffects ) {
// TODO
//BlitFramebufferDepth(prevVfb, vfb);
}
if ( vfb - > drawnFormat ! = vfb - > format ) {
// TODO: Might ultimately combine this with the resize step in DoSetRenderFrameBuffer().
// TODO
//ReformatFramebufferFrom(vfb, vfb->drawnFormat);
}
// ugly...
if ( gstate_c . curRTWidth ! = vfb - > width | | gstate_c . curRTHeight ! = vfb - > height ) {
shaderManager_ - > DirtyUniform ( DIRTY_PROJTHROUGHMATRIX ) ;
}
2014-09-13 22:01:32 -07:00
if ( gstate_c . curRTRenderWidth ! = vfb - > renderWidth | | gstate_c . curRTRenderHeight ! = vfb - > renderHeight ) {
shaderManager_ - > DirtyUniform ( DIRTY_PROJMATRIX ) ;
shaderManager_ - > DirtyUniform ( DIRTY_PROJTHROUGHMATRIX ) ;
}
2014-09-09 22:56:54 -07:00
}
void FramebufferManagerDX9 : : NotifyRenderFramebufferUpdated ( VirtualFramebuffer * vfb , bool vfbFormatChanged ) {
if ( vfbFormatChanged ) {
textureCache_ - > NotifyFramebuffer ( vfb - > fb_address , vfb , NOTIFY_FB_UPDATED ) ;
if ( vfb - > drawnFormat ! = vfb - > format ) {
// TODO
//ReformatFramebufferFrom(vfb, vfb->drawnFormat);
2013-11-15 14:24:25 +01:00
}
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
// ugly...
if ( gstate_c . curRTWidth ! = vfb - > width | | gstate_c . curRTHeight ! = vfb - > height ) {
shaderManager_ - > DirtyUniform ( DIRTY_PROJTHROUGHMATRIX ) ;
}
2014-09-13 22:01:32 -07:00
if ( gstate_c . curRTRenderWidth ! = vfb - > renderWidth | | gstate_c . curRTRenderHeight ! = vfb - > renderHeight ) {
shaderManager_ - > DirtyUniform ( DIRTY_PROJMATRIX ) ;
shaderManager_ - > DirtyUniform ( DIRTY_PROJTHROUGHMATRIX ) ;
}
2013-08-17 11:23:51 +02:00
}
2014-09-13 22:39:54 -07:00
FBO * FramebufferManagerDX9 : : GetTempFBO ( u16 w , u16 h , FBOColorDepth depth ) {
u64 key = ( ( u64 ) depth < < 32 ) | ( w < < 16 ) | h ;
auto it = tempFBOs_ . find ( key ) ;
if ( it ! = tempFBOs_ . end ( ) ) {
it - > second . last_frame_used = gpuStats . numFlips ;
return it - > second . fbo ;
}
textureCache_ - > ForgetLastTexture ( ) ;
FBO * fbo = fbo_create ( w , h , 1 , false , depth ) ;
if ( ! fbo )
return fbo ;
fbo_bind_as_render_target ( fbo ) ;
ClearBuffer ( ) ;
const TempFBO info = { fbo , gpuStats . numFlips } ;
tempFBOs_ [ key ] = info ;
return fbo ;
}
2014-09-13 22:28:39 -07:00
LPDIRECT3DSURFACE9 FramebufferManagerDX9 : : GetOffscreenSurface ( LPDIRECT3DSURFACE9 similarSurface ) {
D3DSURFACE_DESC desc ;
similarSurface - > GetDesc ( & desc ) ;
u64 key = ( ( u64 ) desc . Format < < 32 ) | ( desc . Width < < 16 ) | desc . Height ;
auto it = offscreenSurfaces_ . find ( key ) ;
if ( it ! = offscreenSurfaces_ . end ( ) ) {
it - > second . last_frame_used = gpuStats . numFlips ;
return it - > second . surface ;
}
textureCache_ - > ForgetLastTexture ( ) ;
LPDIRECT3DSURFACE9 offscreen = nullptr ;
HRESULT hr = pD3Ddevice - > CreateOffscreenPlainSurface ( desc . Width , desc . Height , desc . Format , D3DPOOL_SYSTEMMEM , & offscreen , NULL ) ;
if ( FAILED ( hr ) | | ! offscreen ) {
ERROR_LOG_REPORT ( G3D , " Unable to create offscreen surface %dx%d @%d " , desc . Width , desc . Height , desc . Format ) ;
return nullptr ;
}
const OffscreenSurface info = { offscreen , gpuStats . numFlips } ;
offscreenSurfaces_ [ key ] = info ;
return offscreen ;
}
2013-11-15 14:24:25 +01:00
void FramebufferManagerDX9 : : CopyDisplayToOutput ( ) {
2013-08-24 19:07:15 +02:00
2013-11-15 14:24:25 +01:00
fbo_unbind ( ) ;
dxstate . viewport . set ( 0 , 0 , PSP_CoreParameter ( ) . pixelWidth , PSP_CoreParameter ( ) . pixelHeight ) ;
currentRenderVfb_ = 0 ;
2013-08-25 13:56:29 +02:00
2014-09-13 12:07:30 -07:00
u32 offsetX = 0 ;
u32 offsetY = 0 ;
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * vfb = GetVFBAt ( displayFramebufPtr_ ) ;
2014-09-13 12:07:30 -07:00
if ( ! vfb ) {
// Let's search for a framebuf within this range.
const u32 addr = ( displayFramebufPtr_ & 0x03FFFFFF ) | 0x04000000 ;
for ( size_t i = 0 ; i < vfbs_ . size ( ) ; + + i ) {
VirtualFramebuffer * v = vfbs_ [ i ] ;
const u32 v_addr = ( v - > fb_address & 0x03FFFFFF ) | 0x04000000 ;
const u32 v_size = FramebufferByteSize ( v ) ;
if ( addr > = v_addr & & addr < v_addr + v_size ) {
const u32 dstBpp = v - > format = = GE_FORMAT_8888 ? 4 : 2 ;
const u32 v_offsetX = ( ( addr - v_addr ) / dstBpp ) % v - > fb_stride ;
const u32 v_offsetY = ( ( addr - v_addr ) / dstBpp ) / v - > fb_stride ;
// We have enough space there for the display, right?
if ( v_offsetX + 480 > ( u32 ) v - > fb_stride | | v - > bufferHeight < v_offsetY + 272 ) {
continue ;
}
// Check for the closest one.
if ( offsetY = = 0 | | offsetY > v_offsetY ) {
offsetX = v_offsetX ;
offsetY = v_offsetY ;
vfb = v ;
}
}
}
if ( vfb ) {
// Okay, we found one above.
INFO_LOG_REPORT_ONCE ( displayoffset , HLE , " Rendering from framebuf with offset %08x -> %08x+%dx%d " , addr , vfb - > fb_address , offsetX , offsetY ) ;
}
}
if ( vfb & & vfb - > format ! = displayFormat_ ) {
if ( vfb - > last_frame_render + FBO_OLD_AGE < gpuStats . numFlips ) {
// The game probably switched formats on us.
vfb - > format = displayFormat_ ;
} else {
vfb = 0 ;
}
}
2013-11-15 14:24:25 +01:00
if ( ! vfb ) {
if ( Memory : : IsValidAddress ( displayFramebufPtr_ ) ) {
// The game is displaying something directly from RAM. In GTA, it's decoded video.
// First check that it's not a known RAM copy of a VRAM framebuffer though, as in MotoGP
2014-09-13 15:40:55 -07:00
for ( auto iter = knownFramebufferRAMCopies_ . begin ( ) ; iter ! = knownFramebufferRAMCopies_ . end ( ) ; + + iter ) {
2013-11-15 14:24:25 +01:00
if ( iter - > second = = displayFramebufPtr_ ) {
vfb = GetVFBAt ( iter - > first ) ;
}
}
if ( ! vfb ) {
// Just a pointer to plain memory to draw. Draw it.
2014-09-13 13:09:26 -07:00
DrawFramebuffer ( Memory : : GetPointer ( displayFramebufPtr_ ) , displayFormat_ , displayStride_ , true ) ;
2013-11-15 14:24:25 +01:00
return ;
}
} else {
DEBUG_LOG ( SCEGE , " Found no FBO to display! displayFBPtr = %08x " , displayFramebufPtr_ ) ;
// No framebuffer to display! Clear to black.
ClearBuffer ( ) ;
return ;
}
2013-08-24 19:07:15 +02:00
}
2013-11-15 14:24:25 +01:00
vfb - > usageFlags | = FB_USAGE_DISPLAYED_FRAMEBUFFER ;
vfb - > dirtyAfterDisplay = false ;
vfb - > reallyDirtyAfterDisplay = false ;
if ( prevDisplayFramebuf_ ! = displayFramebuf_ ) {
prevPrevDisplayFramebuf_ = prevDisplayFramebuf_ ;
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
if ( displayFramebuf_ ! = vfb ) {
prevDisplayFramebuf_ = displayFramebuf_ ;
}
displayFramebuf_ = vfb ;
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
if ( resized_ ) {
ClearBuffer ( ) ;
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
if ( vfb - > fbo ) {
DEBUG_LOG ( SCEGE , " Displaying FBO %08x " , vfb - > fb_address ) ;
DisableState ( ) ;
LPDIRECT3DTEXTURE9 colorTexture = fbo_get_color_texture ( vfb - > fbo ) ;
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
// Output coordinates
float x , y , w , h ;
CenterRect ( & x , & y , & w , & h , 480.0f , 272.0f , ( float ) PSP_CoreParameter ( ) . pixelWidth , ( float ) PSP_CoreParameter ( ) . pixelHeight ) ;
2013-08-19 20:36:43 +02:00
2013-11-15 14:24:25 +01:00
// TODO ES3: Use glInvalidateFramebuffer to discard depth/stencil data at the end of frame.
// and to discard extraFBOs_ after using them.
2014-08-23 01:52:46 +02:00
2014-09-13 12:07:30 -07:00
const float u0 = offsetX / ( float ) vfb - > bufferWidth ;
const float v0 = offsetY / ( float ) vfb - > bufferHeight ;
const float u1 = ( 480.0f + offsetX ) / ( float ) vfb - > bufferWidth ;
const float v1 = ( 272.0f + offsetY ) / ( float ) vfb - > bufferHeight ;
2013-11-15 14:24:25 +01:00
if ( 1 ) {
2014-09-14 00:20:59 -07:00
const u32 rw = PSP_CoreParameter ( ) . pixelWidth ;
const u32 rh = PSP_CoreParameter ( ) . pixelHeight ;
const RECT srcRect = { ( LONG ) ( u0 * vfb - > renderWidth ) , ( LONG ) ( v0 * vfb - > renderHeight ) , ( LONG ) ( u1 * vfb - > renderWidth ) , ( LONG ) ( v1 * vfb - > renderHeight ) } ;
const RECT dstRect = { x * rw / w , y * rh / h , ( x + w ) * rw / w , ( y + h ) * rh / h } ;
2014-09-13 20:31:01 -07:00
HRESULT hr = fbo_blit_color ( vfb - > fbo , & srcRect , nullptr , & dstRect , g_Config . iBufFilter = = SCALE_LINEAR ? D3DTEXF_LINEAR : D3DTEXF_POINT ) ;
if ( FAILED ( hr ) ) {
ERROR_LOG_REPORT ( G3D , " fbo_blit_color failed on display: %08x " , hr ) ;
dxstate . viewport . set ( 0 , 0 , PSP_CoreParameter ( ) . pixelWidth , PSP_CoreParameter ( ) . pixelHeight ) ;
// These are in the output display coordinates
if ( g_Config . iBufFilter = = SCALE_LINEAR ) {
dxstate . texMagFilter . set ( D3DTEXF_LINEAR ) ;
dxstate . texMinFilter . set ( D3DTEXF_LINEAR ) ;
} else {
dxstate . texMagFilter . set ( D3DTEXF_POINT ) ;
dxstate . texMinFilter . set ( D3DTEXF_POINT ) ;
}
dxstate . texMipFilter . set ( D3DTEXF_NONE ) ;
dxstate . texMipLodBias . set ( 0 ) ;
DrawActiveTexture ( colorTexture , x , y , w , h , ( float ) PSP_CoreParameter ( ) . pixelWidth , ( float ) PSP_CoreParameter ( ) . pixelHeight , false , u0 , v0 , u1 , v1 ) ;
2014-08-24 14:04:55 +02:00
}
2013-11-15 14:24:25 +01:00
}
/*
else if ( usePostShader_ & & extraFBOs_ . size ( ) = = 1 & & ! postShaderAtOutputResolution_ ) {
// An additional pass, post-processing shader to the extra FBO.
fbo_bind_as_render_target ( extraFBOs_ [ 0 ] ) ;
int fbo_w , fbo_h ;
fbo_get_dimensions ( extraFBOs_ [ 0 ] , & fbo_w , & fbo_h ) ;
glstate . viewport . set ( 0 , 0 , fbo_w , fbo_h ) ;
DrawActiveTexture ( colorTexture , 0 , 0 , fbo_w , fbo_h , fbo_w , fbo_h , true , 1.0f , 1.0f , postShaderProgram_ ) ;
2013-08-20 18:46:57 +02:00
2013-11-15 14:24:25 +01:00
fbo_unbind ( ) ;
2013-08-19 20:36:43 +02:00
2013-11-15 14:24:25 +01:00
// Use the extra FBO, with applied post-processing shader, as a texture.
// fbo_bind_color_as_texture(extraFBOs_[0], 0);
if ( extraFBOs_ . size ( ) = = 0 ) {
ERROR_LOG ( G3D , " WTF? " ) ;
return ;
}
colorTexture = fbo_get_color_texture ( extraFBOs_ [ 0 ] ) ;
glstate . viewport . set ( 0 , 0 , PSP_CoreParameter ( ) . pixelWidth , PSP_CoreParameter ( ) . pixelHeight ) ;
// These are in the output display coordinates
DrawActiveTexture ( colorTexture , x , y , w , h , ( float ) PSP_CoreParameter ( ) . pixelWidth , ( float ) PSP_CoreParameter ( ) . pixelHeight , true , 480.0f / ( float ) vfb - > width , 272.0f / ( float ) vfb - > height ) ;
} else {
// Use post-shader, but run shader at output resolution.
glstate . viewport . set ( 0 , 0 , PSP_CoreParameter ( ) . pixelWidth , PSP_CoreParameter ( ) . pixelHeight ) ;
// These are in the output display coordinates
DrawActiveTexture ( colorTexture , x , y , w , h , ( float ) PSP_CoreParameter ( ) . pixelWidth , ( float ) PSP_CoreParameter ( ) . pixelHeight , true , 480.0f / ( float ) vfb - > width , 272.0f / ( float ) vfb - > height , postShaderProgram_ ) ;
}
*/
pD3Ddevice - > SetTexture ( 0 , NULL ) ;
}
2013-08-17 11:23:51 +02:00
}
2014-09-13 15:09:30 -07:00
void FramebufferManagerDX9 : : ReadFramebufferToMemory ( VirtualFramebuffer * vfb , bool sync , int x , int y , int w , int h ) {
2013-11-15 14:24:25 +01:00
#if 0
if ( sync ) {
PackFramebufferAsync_ ( NULL ) ; // flush async just in case when we go for synchronous update
}
# endif
2013-08-19 20:36:43 +02:00
2014-09-13 15:09:30 -07:00
if ( vfb ) {
2013-11-15 14:24:25 +01:00
// We'll pseudo-blit framebuffers here to get a resized and flipped version of vfb.
// For now we'll keep these on the same struct as the ones that can get displayed
// (and blatantly copy work already done above while at it).
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * nvfb = 0 ;
2013-11-15 14:24:25 +01:00
// We maintain a separate vector of framebuffer objects for blitting.
for ( size_t i = 0 ; i < bvfbs_ . size ( ) ; + + i ) {
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * v = bvfbs_ [ i ] ;
2013-11-15 14:24:25 +01:00
if ( MaskedEqual ( v - > fb_address , vfb - > fb_address ) & & v - > format = = vfb - > format ) {
if ( v - > bufferWidth = = vfb - > bufferWidth & & v - > bufferHeight = = vfb - > bufferHeight ) {
nvfb = v ;
v - > fb_stride = vfb - > fb_stride ;
v - > width = vfb - > width ;
v - > height = vfb - > height ;
break ;
}
2013-08-17 11:23:51 +02:00
}
}
2013-11-15 14:24:25 +01:00
// Create a new fbo if none was found for the size
if ( ! nvfb ) {
2014-09-09 08:12:42 -07:00
nvfb = new VirtualFramebuffer ( ) ;
2013-11-15 14:24:25 +01:00
nvfb - > fbo = 0 ;
nvfb - > fb_address = vfb - > fb_address ;
nvfb - > fb_stride = vfb - > fb_stride ;
nvfb - > z_address = vfb - > z_address ;
nvfb - > z_stride = vfb - > z_stride ;
nvfb - > width = vfb - > width ;
nvfb - > height = vfb - > height ;
nvfb - > renderWidth = vfb - > width ;
nvfb - > renderHeight = vfb - > height ;
nvfb - > bufferWidth = vfb - > bufferWidth ;
nvfb - > bufferHeight = vfb - > bufferHeight ;
nvfb - > format = vfb - > format ;
2014-09-13 15:09:30 -07:00
nvfb - > drawnWidth = vfb - > drawnWidth ;
nvfb - > drawnHeight = vfb - > drawnHeight ;
nvfb - > drawnFormat = vfb - > format ;
2013-11-15 14:24:25 +01:00
nvfb - > usageFlags = FB_USAGE_RENDERTARGET ;
nvfb - > dirtyAfterDisplay = true ;
2014-09-13 18:25:45 -07:00
nvfb - > colorDepth = FBO_8888 ;
2013-08-17 11:23:51 +02:00
2014-09-13 15:09:30 -07:00
textureCache_ - > ForgetLastTexture ( ) ;
2014-09-09 08:12:42 -07:00
nvfb - > fbo = fbo_create ( nvfb - > width , nvfb - > height , 1 , true , ( FBOColorDepth ) nvfb - > colorDepth ) ;
2013-11-15 14:24:25 +01:00
if ( ! ( nvfb - > fbo ) ) {
ERROR_LOG ( SCEGE , " Error creating FBO! %i x %i " , nvfb - > renderWidth , nvfb - > renderHeight ) ;
return ;
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
nvfb - > last_frame_render = gpuStats . numFlips ;
bvfbs_ . push_back ( nvfb ) ;
2014-09-13 18:46:59 -07:00
fbo_bind_as_render_target ( nvfb - > fbo ) ;
2013-11-15 14:24:25 +01:00
ClearBuffer ( ) ;
} else {
nvfb - > usageFlags | = FB_USAGE_RENDERTARGET ;
gstate_c . textureChanged = true ;
nvfb - > last_frame_render = gpuStats . numFlips ;
nvfb - > dirtyAfterDisplay = true ;
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
#if 0
if ( nvfb - > fbo ) {
fbo_bind_as_render_target ( nvfb - > fbo ) ;
}
2013-08-19 20:36:43 +02:00
2013-11-15 14:24:25 +01:00
// Some tiled mobile GPUs benefit IMMENSELY from clearing an FBO before rendering
// to it. This broke stuff before, so now it only clears on the first use of an
// FBO in a frame. This means that some games won't be able to avoid the on-some-GPUs
// performance-crushing framebuffer reloads from RAM, but we'll have to live with that.
if ( nvfb - > last_frame_render ! = gpuStats . numFlips ) {
ClearBuffer ( ) ;
}
2013-08-17 11:23:51 +02:00
# endif
2013-11-15 14:24:25 +01:00
}
2013-08-17 11:23:51 +02:00
2014-09-13 15:09:30 -07:00
if ( gameUsesSequentialCopies_ ) {
// Ignore the x/y/etc., read the entire thing.
x = 0 ;
y = 0 ;
w = vfb - > width ;
h = vfb - > height ;
}
if ( x = = 0 & & y = = 0 & & w = = vfb - > width & & h = = vfb - > height ) {
vfb - > memoryUpdated = true ;
} else {
const static int FREQUENT_SEQUENTIAL_COPIES = 3 ;
static int frameLastCopy = 0 ;
static u32 bufferLastCopy = 0 ;
static int copiesThisFrame = 0 ;
if ( frameLastCopy ! = gpuStats . numFlips | | bufferLastCopy ! = vfb - > fb_address ) {
frameLastCopy = gpuStats . numFlips ;
bufferLastCopy = vfb - > fb_address ;
copiesThisFrame = 0 ;
}
if ( + + copiesThisFrame > FREQUENT_SEQUENTIAL_COPIES ) {
gameUsesSequentialCopies_ = true ;
}
}
2014-09-13 15:12:06 -07:00
BlitFramebuffer ( nvfb , x , y , vfb , x , y , w , h , 0 , false ) ;
2013-08-17 11:23:51 +02:00
2014-09-13 16:37:59 -07:00
PackFramebufferDirectx9_ ( nvfb , x , y , w , h ) ;
2014-09-13 14:26:39 -07:00
RebindFramebuffer ( ) ;
2013-11-15 14:24:25 +01:00
}
2013-08-17 11:23:51 +02:00
}
2014-09-13 15:12:06 -07:00
void FramebufferManagerDX9 : : BlitFramebuffer ( VirtualFramebuffer * dst , int dstX , int dstY , VirtualFramebuffer * src , int srcX , int srcY , int w , int h , int bpp , bool flip ) {
2014-09-13 13:09:26 -07:00
if ( ! dst - > fbo | | ! src - > fbo | | ! useBufferedRendering_ ) {
// This can happen if they recently switched from non-buffered.
2013-11-15 14:24:25 +01:00
fbo_unbind ( ) ;
return ;
}
2013-08-20 18:46:57 +02:00
2014-09-13 20:08:29 -07:00
float srcXFactor = flip ? 1.0f : ( float ) src - > renderWidth / ( float ) src - > bufferWidth ;
float srcYFactor = flip ? 1.0f : ( float ) src - > renderHeight / ( float ) src - > bufferHeight ;
2014-09-13 13:09:26 -07:00
const int srcBpp = src - > format = = GE_FORMAT_8888 ? 4 : 2 ;
if ( srcBpp ! = bpp & & bpp ! = 0 ) {
srcXFactor = ( srcXFactor * bpp ) / srcBpp ;
}
int srcX1 = srcX * srcXFactor ;
int srcX2 = ( srcX + w ) * srcXFactor ;
2014-09-13 17:10:57 -07:00
int srcY1 = srcY * srcYFactor ;
int srcY2 = ( srcY + h ) * srcYFactor ;
2014-09-13 13:09:26 -07:00
2014-09-13 20:08:29 -07:00
float dstXFactor = flip ? 1.0f : ( float ) dst - > renderWidth / ( float ) dst - > bufferWidth ;
float dstYFactor = flip ? 1.0f : ( float ) dst - > renderHeight / ( float ) dst - > bufferHeight ;
2014-09-13 13:09:26 -07:00
const int dstBpp = dst - > format = = GE_FORMAT_8888 ? 4 : 2 ;
if ( dstBpp ! = bpp & & bpp ! = 0 ) {
dstXFactor = ( dstXFactor * bpp ) / dstBpp ;
}
int dstX1 = dstX * dstXFactor ;
int dstX2 = ( dstX + w ) * dstXFactor ;
2014-09-13 17:10:57 -07:00
int dstY1 = dstY * dstYFactor ;
int dstY2 = ( dstY + h ) * dstYFactor ;
2014-09-13 13:09:26 -07:00
2014-09-13 20:08:29 -07:00
if ( flip ) {
fbo_bind_as_render_target ( dst - > fbo ) ;
dxstate . viewport . set ( 0 , 0 , dst - > renderWidth , dst - > renderHeight ) ;
DisableState ( ) ;
fbo_bind_color_as_texture ( src - > fbo , 0 ) ;
float srcW = src - > bufferWidth ;
float srcH = src - > bufferHeight ;
DrawActiveTexture ( 0 , dstX1 , dstY , w * dstXFactor , h , dst - > bufferWidth , dst - > bufferHeight , flip , srcX1 / srcW , srcY / srcH , srcX2 / srcW , ( srcY + h ) / srcH ) ;
pD3Ddevice - > SetTexture ( 0 , NULL ) ;
textureCache_ - > ForgetLastTexture ( ) ;
dxstate . viewport . restore ( ) ;
RebindFramebuffer ( ) ;
} else {
2014-09-13 20:31:01 -07:00
LPDIRECT3DSURFACE9 srcSurf = fbo_get_color_for_read ( src - > fbo ) ;
LPDIRECT3DSURFACE9 dstSurf = fbo_get_color_for_write ( dst - > fbo ) ;
2014-09-13 20:08:29 -07:00
RECT srcRect = { srcX1 , srcY1 , srcX2 , srcY2 } ;
RECT dstRect = { dstX1 , dstY1 , dstX2 , dstY2 } ;
D3DSURFACE_DESC desc ;
srcSurf - > GetDesc ( & desc ) ;
srcRect . right = std : : min ( srcRect . right , ( LONG ) desc . Width ) ;
srcRect . bottom = std : : min ( srcRect . bottom , ( LONG ) desc . Height ) ;
dstSurf - > GetDesc ( & desc ) ;
dstRect . right = std : : min ( dstRect . right , ( LONG ) desc . Width ) ;
dstRect . bottom = std : : min ( dstRect . bottom , ( LONG ) desc . Height ) ;
2014-09-13 22:39:54 -07:00
// Direct3D 9 doesn't support rect -> self.
FBO * srcFBO = src - > fbo ;
if ( src = = dst ) {
FBO * tempFBO = GetTempFBO ( src - > renderWidth , src - > renderHeight , ( FBOColorDepth ) src - > colorDepth ) ;
HRESULT hr = fbo_blit_color ( src - > fbo , & srcRect , tempFBO , & srcRect , D3DTEXF_POINT ) ;
if ( SUCCEEDED ( hr ) ) {
srcFBO = tempFBO ;
}
}
HRESULT hr = fbo_blit_color ( srcFBO , & srcRect , dst - > fbo , & dstRect , D3DTEXF_POINT ) ;
2014-09-13 20:08:29 -07:00
if ( FAILED ( hr ) ) {
2014-09-13 20:31:01 -07:00
ERROR_LOG_REPORT ( G3D , " fbo_blit_color failed in blit: %08x (%08x -> %08x) " , hr , src - > fb_address , dst - > fb_address ) ;
2014-09-13 20:08:29 -07:00
}
}
2013-11-15 14:24:25 +01:00
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
// TODO: SSE/NEON
// Could also make C fake-simd for 64-bit, two 8888 pixels fit in a register :)
2014-09-13 16:37:59 -07:00
void ConvertFromRGBA8888 ( u8 * dst , u8 * src , u32 dstStride , u32 srcStride , u32 width , u32 height , GEBufferFormat format ) {
// Must skip stride in the cases below. Some games pack data into the cracks, like MotoGP.
const u32 * src32 = ( const u32 * ) src ;
if ( format = = GE_FORMAT_8888 ) {
u32 * dst32 = ( u32 * ) dst ;
if ( src = = dst ) {
2013-11-15 14:24:25 +01:00
return ;
2014-09-13 16:37:59 -07:00
} else {
for ( u32 y = 0 ; y < height ; + + y ) {
ConvertBGRA8888ToRGBA8888 ( dst32 , src32 , width ) ;
src32 + = srcStride ;
dst32 + = dstStride ;
}
2013-08-20 18:46:57 +02:00
}
2014-09-13 16:37:59 -07:00
} else {
// But here it shouldn't matter if they do intersect
2013-11-15 14:24:25 +01:00
u16 * dst16 = ( u16 * ) dst ;
switch ( format ) {
case GE_FORMAT_565 : // BGR 565
2014-09-13 16:37:59 -07:00
for ( u32 y = 0 ; y < height ; + + y ) {
for ( u32 x = 0 ; x < width ; + + x ) {
dst16 [ x ] = BGRA8888toRGB565 ( src32 [ x ] ) ;
}
src32 + = srcStride ;
dst16 + = dstStride ;
2013-11-15 14:24:25 +01:00
}
break ;
case GE_FORMAT_5551 : // ABGR 1555
2014-09-13 16:37:59 -07:00
for ( u32 y = 0 ; y < height ; + + y ) {
ConvertBGRA8888ToRGBA5551 ( dst16 , src32 , width ) ;
src32 + = srcStride ;
dst16 + = dstStride ;
2013-11-15 14:24:25 +01:00
}
break ;
case GE_FORMAT_4444 : // ABGR 4444
2014-09-13 16:37:59 -07:00
for ( u32 y = 0 ; y < height ; + + y ) {
for ( u32 x = 0 ; x < width ; + + x ) {
dst16 [ x ] = BGRA8888toRGBA4444 ( src32 [ x ] ) ;
}
src32 + = srcStride ;
dst16 + = dstStride ;
2013-11-15 14:24:25 +01:00
}
break ;
case GE_FORMAT_8888 :
2014-09-13 16:37:59 -07:00
case GE_FORMAT_INVALID :
2013-11-15 14:24:25 +01:00
// Not possible.
break ;
2013-08-20 18:46:57 +02:00
}
2013-08-17 11:23:51 +02:00
}
}
2014-09-13 16:37:59 -07:00
void FramebufferManagerDX9 : : PackFramebufferDirectx9_ ( VirtualFramebuffer * vfb , int x , int y , int w , int h ) {
if ( ! vfb - > fbo ) {
ERROR_LOG_REPORT_ONCE ( vfbfbozero , SCEGE , " PackFramebufferDirectx9_: vfb->fbo == 0 " ) ;
2013-11-15 15:15:12 +01:00
fbo_unbind ( ) ;
return ;
}
2014-09-13 16:37:59 -07:00
const u32 fb_address = ( 0x04000000 ) | vfb - > fb_address ;
const int dstBpp = vfb - > format = = GE_FORMAT_8888 ? 4 : 2 ;
// We always need to convert from the framebuffer native format.
// Right now that's always 8888.
DEBUG_LOG ( HLE , " Reading framebuffer to mem, fb_address = %08x " , fb_address ) ;
2014-09-13 20:31:01 -07:00
LPDIRECT3DSURFACE9 renderTarget = fbo_get_color_for_read ( vfb - > fbo ) ;
2014-09-13 16:37:59 -07:00
D3DSURFACE_DESC desc ;
renderTarget - > GetDesc ( & desc ) ;
2014-09-13 22:28:39 -07:00
LPDIRECT3DSURFACE9 offscreen = GetOffscreenSurface ( renderTarget ) ;
if ( offscreen ) {
HRESULT hr = pD3Ddevice - > GetRenderTargetData ( renderTarget , offscreen ) ;
2014-09-13 16:37:59 -07:00
if ( SUCCEEDED ( hr ) ) {
D3DLOCKED_RECT locked ;
2014-09-13 17:14:29 -07:00
u32 widthFactor = vfb - > renderWidth / vfb - > bufferWidth ;
u32 heightFactor = vfb - > renderHeight / vfb - > bufferHeight ;
2014-09-13 19:57:49 -07:00
RECT rect = { x * widthFactor , y * heightFactor , ( x + w ) * widthFactor , ( y + h ) * heightFactor } ;
2014-09-13 16:37:59 -07:00
hr = offscreen - > LockRect ( & locked , & rect , D3DLOCK_READONLY ) ;
if ( SUCCEEDED ( hr ) ) {
// TODO: Handle the other formats? We don't currently create them, I think.
2014-09-13 17:14:29 -07:00
const int dstByteOffset = ( y * vfb - > fb_stride + x ) * dstBpp ;
2014-09-13 16:37:59 -07:00
// Pixel size always 4 here because we always request BGRA8888.
2014-09-13 17:14:29 -07:00
ConvertFromRGBA8888 ( Memory : : GetPointer ( fb_address + dstByteOffset ) , ( u8 * ) locked . pBits , vfb - > fb_stride , locked . Pitch / 4 , w , h , vfb - > format ) ;
2014-09-13 16:37:59 -07:00
offscreen - > UnlockRect ( ) ;
2014-09-13 19:21:59 -07:00
} else {
ERROR_LOG_REPORT ( G3D , " Unable to lock rect from %08x: %d,%d %dx%d of %dx%d " , fb_address , rect . left , rect . top , rect . right , rect . bottom , vfb - > renderWidth , vfb - > renderHeight ) ;
2014-09-13 16:37:59 -07:00
}
2014-09-13 19:21:59 -07:00
} else {
ERROR_LOG_REPORT ( G3D , " Unable to download render target data from %08x " , fb_address ) ;
2013-11-15 14:24:25 +01:00
}
2013-08-17 11:23:51 +02:00
}
}
2014-09-13 22:28:39 -07:00
2013-11-15 14:24:25 +01:00
void FramebufferManagerDX9 : : EndFrame ( ) {
if ( resized_ ) {
DestroyAllFBOs ( ) ;
dxstate . viewport . set ( 0 , 0 , PSP_CoreParameter ( ) . pixelWidth , PSP_CoreParameter ( ) . pixelHeight ) ;
resized_ = false ;
}
2013-11-15 15:15:12 +01:00
#if 0
// We flush to memory last requested framebuffer, if any
PackFramebufferAsync_ ( NULL ) ;
# endif
2013-11-15 14:24:25 +01:00
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
void FramebufferManagerDX9 : : DeviceLost ( ) {
DestroyAllFBOs ( ) ;
resized_ = false ;
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
std : : vector < FramebufferInfo > FramebufferManagerDX9 : : GetFramebufferList ( ) {
std : : vector < FramebufferInfo > list ;
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
for ( size_t i = 0 ; i < vfbs_ . size ( ) ; + + i ) {
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * vfb = vfbs_ [ i ] ;
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
FramebufferInfo info ;
info . fb_address = vfb - > fb_address ;
info . z_address = vfb - > z_address ;
info . format = vfb - > format ;
info . width = vfb - > width ;
info . height = vfb - > height ;
info . fbo = vfb - > fbo ;
list . push_back ( info ) ;
2013-08-17 11:23:51 +02:00
}
2013-11-15 14:24:25 +01:00
return list ;
}
2013-08-17 11:23:51 +02:00
2013-11-15 14:24:25 +01:00
void FramebufferManagerDX9 : : DecimateFBOs ( ) {
fbo_unbind ( ) ;
currentRenderVfb_ = 0 ;
bool updateVram = ! ( g_Config . iRenderingMode = = FB_NON_BUFFERED_MODE | | g_Config . iRenderingMode = = FB_BUFFERED_MODE ) ;
for ( size_t i = 0 ; i < vfbs_ . size ( ) ; + + i ) {
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * vfb = vfbs_ [ i ] ;
int age = frameLastFramebufUsed_ - std : : max ( vfb - > last_frame_render , vfb - > last_frame_used ) ;
2013-11-15 14:24:25 +01:00
2014-09-13 15:09:30 -07:00
if ( ShouldDownloadFramebuffer ( vfb ) & & age = = 0 & & ! vfb - > memoryUpdated ) {
ReadFramebufferToMemory ( vfb , false , 0 , 0 , vfb - > width , vfb - > height ) ;
}
2013-11-15 14:24:25 +01:00
if ( vfb = = displayFramebuf_ | | vfb = = prevDisplayFramebuf_ | | vfb = = prevPrevDisplayFramebuf_ ) {
continue ;
}
if ( age > FBO_OLD_AGE ) {
INFO_LOG ( SCEGE , " Decimating FBO for %08x (%i x %i x %i), age %i " , vfb - > fb_address , vfb - > width , vfb - > height , vfb - > format , age ) ;
DestroyFramebuf ( vfb ) ;
vfbs_ . erase ( vfbs_ . begin ( ) + i - - ) ;
}
}
2014-09-13 22:39:54 -07:00
for ( auto it = tempFBOs_ . begin ( ) ; it ! = tempFBOs_ . end ( ) ; ) {
int age = frameLastFramebufUsed_ - it - > second . last_frame_used ;
if ( age > FBO_OLD_AGE ) {
fbo_destroy ( it - > second . fbo ) ;
tempFBOs_ . erase ( it + + ) ;
} else {
+ + it ;
}
}
2014-09-13 22:28:39 -07:00
for ( auto it = offscreenSurfaces_ . begin ( ) ; it ! = offscreenSurfaces_ . end ( ) ; ) {
int age = frameLastFramebufUsed_ - it - > second . last_frame_used ;
if ( age > FBO_OLD_AGE ) {
it - > second . surface - > Release ( ) ;
offscreenSurfaces_ . erase ( it + + ) ;
} else {
+ + it ;
}
}
2013-11-15 14:24:25 +01:00
// Do the same for ReadFramebuffersToMemory's VFBs
for ( size_t i = 0 ; i < bvfbs_ . size ( ) ; + + i ) {
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * vfb = bvfbs_ [ i ] ;
int age = frameLastFramebufUsed_ - vfb - > last_frame_render ;
2013-11-15 14:24:25 +01:00
if ( age > FBO_OLD_AGE ) {
INFO_LOG ( SCEGE , " Decimating FBO for %08x (%i x %i x %i), age %i " , vfb - > fb_address , vfb - > width , vfb - > height , vfb - > format , age ) ;
DestroyFramebuf ( vfb ) ;
bvfbs_ . erase ( bvfbs_ . begin ( ) + i - - ) ;
}
2013-08-17 11:23:51 +02:00
}
}
2013-11-15 14:24:25 +01:00
void FramebufferManagerDX9 : : DestroyAllFBOs ( ) {
2013-08-17 11:23:51 +02:00
fbo_unbind ( ) ;
currentRenderVfb_ = 0 ;
2013-11-15 14:24:25 +01:00
displayFramebuf_ = 0 ;
prevDisplayFramebuf_ = 0 ;
prevPrevDisplayFramebuf_ = 0 ;
2013-08-17 11:23:51 +02:00
for ( size_t i = 0 ; i < vfbs_ . size ( ) ; + + i ) {
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * vfb = vfbs_ [ i ] ;
2013-11-15 14:24:25 +01:00
INFO_LOG ( SCEGE , " Destroying FBO for %08x : %i x %i x %i " , vfb - > fb_address , vfb - > width , vfb - > height , vfb - > format ) ;
DestroyFramebuf ( vfb ) ;
}
vfbs_ . clear ( ) ;
2014-09-13 22:28:39 -07:00
for ( size_t i = 0 ; i < bvfbs_ . size ( ) ; + + i ) {
VirtualFramebuffer * vfb = bvfbs_ [ i ] ;
DestroyFramebuf ( vfb ) ;
}
bvfbs_ . clear ( ) ;
2014-09-13 22:39:54 -07:00
for ( auto it = tempFBOs_ . begin ( ) , end = tempFBOs_ . end ( ) ; it ! = end ; + + it ) {
fbo_destroy ( it - > second . fbo ) ;
}
tempFBOs_ . clear ( ) ;
2014-09-13 22:28:39 -07:00
for ( auto it = offscreenSurfaces_ . begin ( ) , end = offscreenSurfaces_ . end ( ) ; it ! = end ; + + it ) {
it - > second . surface - > Release ( ) ;
}
offscreenSurfaces_ . clear ( ) ;
DisableState ( ) ;
2013-11-15 14:24:25 +01:00
}
2014-09-13 14:23:18 -07:00
void FramebufferManagerDX9 : : FlushBeforeCopy ( ) {
// Flush anything not yet drawn before blitting, downloading, or uploading.
// This might be a stalled list, or unflushed before a block transfer, etc.
SetRenderFrameBuffer ( ) ;
transformDraw_ - > Flush ( ) ;
}
2013-11-15 14:24:25 +01:00
void FramebufferManagerDX9 : : Resized ( ) {
resized_ = true ;
2013-08-17 11:23:51 +02:00
}
2013-09-15 08:53:21 -07:00
2013-11-15 14:24:25 +01:00
bool FramebufferManagerDX9 : : GetCurrentFramebuffer ( GPUDebugBuffer & buffer ) {
2014-08-24 21:23:23 -07:00
u32 fb_address = gstate . getFrameBufRawAddress ( ) ;
int fb_stride = gstate . FrameBufStride ( ) ;
2014-09-09 08:12:42 -07:00
VirtualFramebuffer * vfb = currentRenderVfb_ ;
2014-08-24 21:23:23 -07:00
if ( ! vfb ) {
vfb = GetVFBAt ( fb_address ) ;
}
if ( ! vfb ) {
// If there's no vfb and we're drawing there, must be memory?
buffer = GPUDebugBuffer ( Memory : : GetPointer ( fb_address | 0x04000000 ) , fb_stride , 512 , gstate . FrameBufFormat ( ) ) ;
return true ;
}
2014-09-11 23:52:06 -07:00
LPDIRECT3DSURFACE9 renderTarget = nullptr ;
2014-08-24 21:23:23 -07:00
HRESULT hr ;
hr = pD3Ddevice - > GetRenderTarget ( 0 , & renderTarget ) ;
if ( ! renderTarget | | ! SUCCEEDED ( hr ) )
return false ;
D3DSURFACE_DESC desc ;
renderTarget - > GetDesc ( & desc ) ;
2014-09-13 22:28:39 -07:00
LPDIRECT3DSURFACE9 offscreen = GetOffscreenSurface ( renderTarget ) ;
if ( ! offscreen ) {
2014-09-11 23:52:06 -07:00
renderTarget - > Release ( ) ;
2014-08-24 21:23:23 -07:00
return false ;
2014-09-11 23:52:06 -07:00
}
2014-08-24 21:23:23 -07:00
bool success = false ;
hr = pD3Ddevice - > GetRenderTargetData ( renderTarget , offscreen ) ;
if ( SUCCEEDED ( hr ) ) {
D3DLOCKED_RECT locked ;
RECT rect = { 0 , 0 , vfb - > renderWidth , vfb - > renderHeight } ;
hr = offscreen - > LockRect ( & locked , & rect , D3DLOCK_READONLY ) ;
if ( SUCCEEDED ( hr ) ) {
2014-08-24 22:08:28 -07:00
// TODO: Handle the other formats? We don't currently create them, I think.
2014-09-09 01:42:21 -07:00
buffer . Allocate ( locked . Pitch / 4 , desc . Height , GPU_DBG_FORMAT_8888_BGRA , false ) ;
memcpy ( buffer . GetData ( ) , locked . pBits , locked . Pitch * desc . Height ) ;
2014-08-24 21:23:23 -07:00
offscreen - > UnlockRect ( ) ;
success = true ;
}
}
2014-09-11 23:52:06 -07:00
renderTarget - > Release ( ) ;
2014-08-24 21:23:23 -07:00
return success ;
2013-11-15 14:24:25 +01:00
}
bool FramebufferManagerDX9 : : GetCurrentDepthbuffer ( GPUDebugBuffer & buffer ) {
2014-08-24 21:23:23 -07:00
// TODO: Is this possible?
2013-11-15 14:24:25 +01:00
return false ;
}
bool FramebufferManagerDX9 : : GetCurrentStencilbuffer ( GPUDebugBuffer & buffer ) {
2014-08-24 21:23:23 -07:00
// TODO: Is this possible?
2013-11-15 14:24:25 +01:00
return false ;
}
} // namespace DX9