From 6666b400a32249752815a33ac78e9fd1557f3bca Mon Sep 17 00:00:00 2001 From: skidau Date: Sun, 7 Nov 2010 04:28:33 +0000 Subject: [PATCH] Updated with a less aggressive optimisation to EFB copy to RAM. The destination texture now does not get invalidated if its hash is found in the texture cache. Fixes Metroid Prime 3. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6353 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/TextureCacheBase.cpp | 4 +--- .../Plugin_VideoDX9/Src/TextureConverter.cpp | 14 +++++++------- .../Plugin_VideoOGL/Src/TextureConverter.cpp | 16 ++++++++-------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp index ba54adbac5..65a74b71dc 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp @@ -137,9 +137,7 @@ void TextureCache::MakeRangeDynamic(u32 start_address, u32 size) bool TextureCache::Find(u32 start_address, u64 hash) { - TexCache::iterator - iter = textures.lower_bound(start_address), - tcend = textures.upper_bound(start_address); + TexCache::iterator iter = textures.lower_bound(start_address); if (iter->second->hash == hash) return true; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp index 05514d1919..3ae3ab9cb7 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp @@ -271,7 +271,7 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr // Draw... D3D::drawShadedTexQuad(srcTexture,&SrcRect,1,1,dstWidth,dstHeight,shader,VertexShaderCache::GetSimpleVertexShader(0)); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); - // .. and then readback the results. + // .. and then read back the results. // TODO: make this less slow. D3DLOCKED_RECT drect; @@ -406,12 +406,6 @@ u64 EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture,u32 Sou int size_in_bytes = TexDecoder_GetTextureSizeInBytes(width, height, format); - u64 hash = GetHash64(dest_ptr,size_in_bytes,g_ActiveConfig.iSafeTextureCache_ColorSamples); - - // If the texture in RAM is already in the texture cache, do not copy it again as it has not changed. - if (TextureCache::Find(address, hash)) - return hash; - u16 blkW = TexDecoder_GetBlockWidthInTexels(format) - 1; u16 blkH = TexDecoder_GetBlockHeightInTexels(format) - 1; u16 samples = TextureConversionShader::GetEncodedSampleCount(format); @@ -444,6 +438,12 @@ u64 EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture,u32 Sou int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format); EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, true, bScaleByHalf > 0); + u64 hash = GetHash64(dest_ptr,size_in_bytes,g_ActiveConfig.iSafeTextureCache_ColorSamples); + + // If the texture in RAM is already in the texture cache, do not copy it again as it has not changed. + if (TextureCache::Find(address, hash)) + return hash; + TextureCache::MakeRangeDynamic(address,size_in_bytes); return hash; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index ee1236b8d1..dd4d321665 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -214,7 +214,7 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar glEnd(); GL_REPORT_ERRORD(); - // .. and then readback the results. + // .. and then read back the results. // TODO: make this less slow. int writeStride = bpmem.copyMipMapStrideChannels * 32; @@ -345,12 +345,6 @@ u64 EncodeToRamFromTexture(u32 address,GLuint source_texture,float MValueX,float int size_in_bytes = TexDecoder_GetTextureSizeInBytes(width, height, format); - u64 hash = GetHash64(dest_ptr,size_in_bytes,g_ActiveConfig.iSafeTextureCache_ColorSamples); - - // If the texture in RAM is already in the texture cache, do not copy it again as it has not changed. - if (TextureCache::Find(address, hash)) - return hash; - u16 blkW = TexDecoder_GetBlockWidthInTexels(format) - 1; u16 blkH = TexDecoder_GetBlockHeightInTexels(format) - 1; u16 samples = TextureConversionShader::GetEncodedSampleCount(format); @@ -380,6 +374,12 @@ u64 EncodeToRamFromTexture(u32 address,GLuint source_texture,float MValueX,float int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format); EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, true, bScaleByHalf > 0 && !bFromZBuffer); + u64 hash = GetHash64(dest_ptr,size_in_bytes,g_ActiveConfig.iSafeTextureCache_ColorSamples); + + // If the texture in RAM is already in the texture cache, do not copy it again as it has not changed. + if (TextureCache::Find(address, hash)) + return hash; + TextureCache::MakeRangeDynamic(address,size_in_bytes); return hash; } @@ -411,7 +411,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur Renderer::ResetAPIState(); // reset any game specific settings - // swich to texture converter frame buffer + // switch to texture converter frame buffer // attach destTexture as color destination g_framebufferManager.SetFramebuffer(s_texConvFrameBuffer); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, destTexture);