D3D: Handle device resets (resizes) a little bit better .. not quite there yet. some random cleanup.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4279 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2009-09-15 21:05:31 +00:00
parent e0baa817e4
commit ef6e574ea1
6 changed files with 44 additions and 44 deletions

View File

@ -102,12 +102,10 @@ void FlushPipeline()
void SetGenerationMode(const BPCmd &bp)
{
// dev->SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
D3D::SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
if (bpmem.genMode.cullmode == 3)
{
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, 0);
}
else
@ -118,7 +116,6 @@ void SetGenerationMode(const BPCmd &bp)
if (bpmem.blendmode.colorupdate)
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, write);
}
}
@ -295,19 +292,17 @@ void SetSamplerState(const BPCmd &bp)
if ((bp.address & 0xE0) == 0xA0)
stage += 4;
if (g_ActiveConfig.iMaxAnisotropy > 1)
if (mag == D3DTEXF_LINEAR && min == D3DTEXF_LINEAR &&
g_ActiveConfig.iMaxAnisotropy > 1)
{
mag = D3DTEXF_LINEAR;
min = D3DTEXF_ANISOTROPIC;
mip = D3DTEXF_LINEAR;
}
dev->SetSamplerState(stage, D3DSAMP_MINFILTER, min);
dev->SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
dev->SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
D3D::SetSamplerState(stage, D3DSAMP_MINFILTER, min);
D3D::SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
D3D::SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
dev->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, g_ActiveConfig.iMaxAnisotropy);
dev->SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
dev->SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
//wip
//dev->SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,tm0.lod_bias/4.0f);
//char temp[256];

View File

@ -37,6 +37,13 @@ LPDIRECT3DTEXTURE9 GetEFBColorTexture(const EFBRectangle& sourceRc)
return s_efb_color_texture;
}
LPDIRECT3DTEXTURE9 GetEFBDepthTexture(const EFBRectangle &sourceRc)
{
// Depth textures not supported under DX9. We're gonna fake this
// with a secondary render target later.
return NULL;
}
void Create()
{
// Simplest possible setup to start with.
@ -62,10 +69,9 @@ void Destroy()
s_efb_color_surface->Release();
s_efb_color_surface = NULL;
#ifdef TEXSURF
s_efb_color_texture->Release();
s_efb_color_texture = NULL;
#endif
}
} // namespace

View File

@ -68,12 +68,19 @@ void SetupDeviceObjects()
D3D::font.Init();
VertexLoaderManager::Init();
FBManager::Create();
VertexShaderManager::Init();
PixelShaderManager::Init();
// Tex and shader caches will recreate themselves over time.
}
// Kill off all POOL_DEFAULT device objects.
void TeardownDeviceObjects()
{
VertexShaderManager::Shutdown();
PixelShaderManager::Shutdown();
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
FBManager::Destroy();
@ -83,8 +90,6 @@ void TeardownDeviceObjects()
VertexLoaderManager::Shutdown();
VertexShaderCache::Clear();
PixelShaderCache::Clear();
// This really should be all but Zelda for example still fails...
}
bool Renderer::Init()
@ -134,8 +139,8 @@ bool Renderer::Init()
SetupDeviceObjects();
for (int i = 0; i < 8; i++)
D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16);
for (int stage = 0; stage < 8; stage++)
D3D::SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, g_ActiveConfig.iMaxAnisotropy);
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 0, 0);
@ -358,7 +363,6 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
D3D::dev->SetRenderState(D3DRS_ZENABLE, TRUE);
RECT rc;
rc.left = 0;
@ -366,7 +370,7 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect
rc.right = (LONG)s_target_width;
rc.bottom = (LONG)s_target_height;
D3D::dev->SetScissorRect(&rc);
D3D::dev->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
D3D::SetRenderState(D3DRS_SCISSORTESTENABLE, false);
UpdateViewport();
}

View File

@ -49,7 +49,7 @@ void TextureCache::TCacheEntry::Destroy(bool shutdown)
texture = 0;
if (!isRenderTarget && !shutdown)
{
u32 *ptr = (u32*)g_VideoInitialize.pGetMemoryPointer(addr + hashoffset*4);
u32 *ptr = (u32*)g_VideoInitialize.pGetMemoryPointer(addr);
if (ptr && *ptr == hash)
*ptr = oldpixel;
}
@ -211,11 +211,10 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
//Make an entry in the table
TCacheEntry& entry = textures[texID];
entry.hashoffset = 0;
entry.hash = hash_value;
//entry.hash = (u32)(((double)rand() / RAND_MAX) * 0xFFFFFFFF);
entry.paletteHash = palhash;
entry.oldpixel = ((u32 *)ptr)[entry.hashoffset];
entry.oldpixel = ((u32 *)ptr)[0];
//((u32 *)ptr)[entry.hashoffset] = entry.hash;
entry.addr = address;
@ -226,32 +225,25 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
entry.w = width;
entry.h = height;
entry.fmt = format;
entry.mode = bpmem.tex[stage > 3].texMode0[stage & 3];
if (g_ActiveConfig.bDumpTextures)
{ // dump texture to file
char szTemp[MAX_PATH];
char szDir[MAX_PATH];
const char* uniqueId = globals->unique_id;
bool bCheckedDumpDir = false;
sprintf(szDir,"%s/%s",FULL_DUMP_TEXTURES_DIR,uniqueId);
if(!bCheckedDumpDir)
sprintf(szDir, "%s/%s", FULL_DUMP_TEXTURES_DIR, uniqueId);
if (!bCheckedDumpDir)
{
if (!File::Exists(szDir) || !File::IsDirectory(szDir))
File::CreateDir(szDir);
bCheckedDumpDir = true;
}
sprintf(szTemp, "%s/%s_%08x_%i.png",szDir, uniqueId, tex_hash, format);
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir, uniqueId, tex_hash, format);
//sprintf(szTemp, "%s\\txt_%04i_%i.png", g_Config.texDumpPath.c_str(), counter++, format); <-- Old method
if (!File::Exists(szTemp))
D3DXSaveTextureToFileA(szTemp,D3DXIFF_BMP,entry.texture,0);
}
INCSTAT(stats.numTexturesCreated);
@ -298,7 +290,6 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo
TCacheEntry entry;
entry.isRenderTarget = true;
entry.hash = 0;
entry.hashoffset = 0;
entry.frameCount = frameCount;
entry.w = tex_w;
entry.h = tex_h;

View File

@ -31,21 +31,26 @@ public:
struct TCacheEntry
{
LPDIRECT3DTEXTURE9 texture;
u32 addr;
u32 size_in_bytes;
u32 hash;
u32 paletteHash;
u32 hashoffset;
u32 oldpixel;
int frameCount;
int w, h, fmt;
bool isRenderTarget;
bool isNonPow2;
int frameCount;
int w,h,fmt;
TexMode0 mode; // current filter and clamp modes that texture is set to
TCacheEntry()
{
texture=0;
isRenderTarget=0;
hash=0;
texture = 0;
isRenderTarget = 0;
hash = 0;
paletteHash = 0;
oldpixel = 0;
}
void Destroy(bool shutdown);
};

View File

@ -29,7 +29,7 @@ class TextureMngr
public:
struct TCacheEntry
{
TCacheEntry() : texture(0), addr(0), size_in_bytes(0), hash(0), w(0), h(0), scaleX(1.0f), scaleY(1.0f), isRenderTarget(false), isUpsideDown(false), isRectangle(true), bHaveMipMaps(false) { mode.hex = 0xFCFCFCFC; }
TCacheEntry() : texture(0), addr(0), size_in_bytes(0), hash(0), w(0), h(0), scaleX(1.0f), scaleY(1.0f), isRenderTarget(false), isRectangle(true), bHaveMipMaps(false) { mode.hex = 0xFCFCFCFC; }
GLuint texture;
u32 addr;
@ -47,7 +47,6 @@ public:
bool isRenderTarget; // if render texture, then rendertex is filled with the direct copy of the render target
// later conversions would have to convert properly from rendertexfmt to texfmt
bool isUpsideDown;
bool isRectangle; // if nonpow2, use GL_TEXTURE_2D, else GL_TEXTURE_RECTANGLE_NV
bool bHaveMipMaps;