From ef6e574ea1ef60a2650a56c0602f3b0cd5f46057 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Tue, 15 Sep 2009 21:05:31 +0000 Subject: [PATCH] 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 --- .../Plugin_VideoDX9/Src/BPFunctions.cpp | 19 +++++++------------ .../Src/FramebufferManager.cpp | 12 +++++++++--- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 16 ++++++++++------ .../Plugin_VideoDX9/Src/TextureCache.cpp | 19 +++++-------------- .../Plugin_VideoDX9/Src/TextureCache.h | 19 ++++++++++++------- .../Plugins/Plugin_VideoOGL/Src/TextureMngr.h | 3 +-- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp index 5843e681b6..b053c93648 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp @@ -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]; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp index dbc8c659b1..a2bf8562a6 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp @@ -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. @@ -47,7 +54,7 @@ void Create() D3DPOOL_DEFAULT, &s_efb_color_texture, NULL); CHECK(hr); - hr = s_efb_color_texture->GetSurfaceLevel(0, &s_efb_color_surface); + hr = s_efb_color_texture->GetSurfaceLevel(0, &s_efb_color_surface); CHECK(hr); hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, D3DFMT_D24S8, @@ -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 \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index db439319ea..b142a3639c 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -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(); } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp index bc8035b876..087c2b4ff2 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp @@ -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; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h index 13c6bbfd47..a3cba00bfe 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h @@ -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); }; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h index 322594b592..174df84e12 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h @@ -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;