From 4bc698d698241d70224435922c9309c28990fefe Mon Sep 17 00:00:00 2001 From: gabest11 Date: Thu, 28 May 2009 02:57:01 +0000 Subject: [PATCH] GSdx: just fixing slow texture uploads with dx9... (odin sphere back to 40-50 fps) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1279 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GSTexture.h | 2 +- plugins/GSdx/GSTexture10.cpp | 9 +++++++- plugins/GSdx/GSTexture10.h | 2 +- plugins/GSdx/GSTexture7.cpp | 9 +++++++- plugins/GSdx/GSTexture7.h | 2 +- plugins/GSdx/GSTexture9.cpp | 4 ++-- plugins/GSdx/GSTexture9.h | 2 +- plugins/GSdx/GSTextureCache.cpp | 39 +++++++++++++++++++++++++-------- plugins/GSdx/GSTextureNull.h | 2 +- plugins/GSdx/GSUtil.cpp | 4 +++- 10 files changed, 56 insertions(+), 19 deletions(-) diff --git a/plugins/GSdx/GSTexture.h b/plugins/GSdx/GSTexture.h index d21d778425..26de1ca667 100644 --- a/plugins/GSdx/GSTexture.h +++ b/plugins/GSdx/GSTexture.h @@ -40,7 +40,7 @@ public: virtual int GetHeight() const = 0; virtual int GetFormat() const = 0; virtual bool Update(const GSVector4i& r, const void* data, int pitch) = 0; - virtual bool Map(uint8** bits, int& pitch) = 0; + virtual bool Map(uint8** bits, int& pitch, const GSVector4i* r = NULL) = 0; virtual void Unmap() = 0; virtual bool Save(const string& fn, bool dds = false) = 0; diff --git a/plugins/GSdx/GSTexture10.cpp b/plugins/GSdx/GSTexture10.cpp index 051cbb07fd..830a1d5878 100644 --- a/plugins/GSdx/GSTexture10.cpp +++ b/plugins/GSdx/GSTexture10.cpp @@ -83,8 +83,15 @@ bool GSTexture10::Update(const GSVector4i& r, const void* data, int pitch) return false; } -bool GSTexture10::Map(uint8** bits, int& pitch) +bool GSTexture10::Map(uint8** bits, int& pitch, const GSVector4i* r) { + if(r != NULL) + { + // ASSERT(0); // not implemented + + return false; + } + if(m_texture) { D3D10_MAPPED_TEXTURE2D map; diff --git a/plugins/GSdx/GSTexture10.h b/plugins/GSdx/GSTexture10.h index e01ae272f2..e11233d48f 100644 --- a/plugins/GSdx/GSTexture10.h +++ b/plugins/GSdx/GSTexture10.h @@ -44,7 +44,7 @@ public: int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); - bool Map(uint8** bits, int& pitch); + bool Map(uint8** bits, int& pitch, const GSVector4i* r); void Unmap(); bool Save(const string& fn, bool dds = false); diff --git a/plugins/GSdx/GSTexture7.cpp b/plugins/GSdx/GSTexture7.cpp index fd2d2dcbef..28c5fafe81 100644 --- a/plugins/GSdx/GSTexture7.cpp +++ b/plugins/GSdx/GSTexture7.cpp @@ -133,10 +133,17 @@ bool GSTexture7::Update(const GSVector4i& r, const void* data, int pitch) return false; } -bool GSTexture7::Map(uint8** bits, int& pitch) +bool GSTexture7::Map(uint8** bits, int& pitch, const GSVector4i* r) { HRESULT hr; + if(r != NULL) + { + // ASSERT(0); // not implemented + + return false; + } + DDSURFACEDESC2 desc; if(SUCCEEDED(hr = m_system->Lock(NULL, &desc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL))) diff --git a/plugins/GSdx/GSTexture7.h b/plugins/GSdx/GSTexture7.h index fafccbd863..21baa62d95 100644 --- a/plugins/GSdx/GSTexture7.h +++ b/plugins/GSdx/GSTexture7.h @@ -44,7 +44,7 @@ public: int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); - bool Map(uint8** bits, int& pitch); + bool Map(uint8** bits, int& pitch, const GSVector4i* r); void Unmap(); bool Save(const string& fn, bool dds = false); diff --git a/plugins/GSdx/GSTexture9.cpp b/plugins/GSdx/GSTexture9.cpp index e0eaa212b6..f4eb298a0c 100644 --- a/plugins/GSdx/GSTexture9.cpp +++ b/plugins/GSdx/GSTexture9.cpp @@ -113,7 +113,7 @@ bool GSTexture9::Update(const GSVector4i& r, const void* data, int pitch) return false; } -bool GSTexture9::Map(uint8** bits, int& pitch) +bool GSTexture9::Map(uint8** bits, int& pitch, const GSVector4i* r) { HRESULT hr; @@ -121,7 +121,7 @@ bool GSTexture9::Map(uint8** bits, int& pitch) { D3DLOCKED_RECT lr; - if(SUCCEEDED(hr = surface->LockRect(&lr, NULL, 0))) + if(SUCCEEDED(hr = surface->LockRect(&lr, (LPRECT)r, 0))) { *bits = (uint8*)lr.pBits; pitch = (int)lr.Pitch; diff --git a/plugins/GSdx/GSTexture9.h b/plugins/GSdx/GSTexture9.h index dff127d4ac..f8779e3222 100644 --- a/plugins/GSdx/GSTexture9.h +++ b/plugins/GSdx/GSTexture9.h @@ -43,7 +43,7 @@ public: int GetHeight() const; int GetFormat() const; bool Update(const GSVector4i& r, const void* data, int pitch); - bool Map(uint8** bits, int& pitch); + bool Map(uint8** bits, int& pitch, const GSVector4i* r); void Unmap(); bool Save(const string& fn, bool dds = false); diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 90f717fd8a..27b789ee0f 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -698,20 +698,41 @@ void GSTextureCache::GSCachedTexture::Update() m_valid = m_valid.runion(r); - static uint8* bits = (uint8*)::_aligned_malloc(1024 * 1024 * 4, 16); - - int pitch = ((r.width() + 3) & ~3) * 4; - - if(m_renderer->m_psrr) + uint8* bits = NULL; + int pitch = 0; + + if(m_texture->Map(&bits, pitch, &r)) { - m_renderer->m_mem.ReadTextureNPNC(r, bits, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); + // in dx9 managed textures can be written directly, less copying is faster, but still not as fast as dx10's UpdateResource + + if(m_renderer->m_psrr) + { + m_renderer->m_mem.ReadTextureNPNC(r, bits, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); + } + else + { + m_renderer->m_mem.ReadTextureNP(r, bits, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); + } + + m_texture->Unmap(); } else { - m_renderer->m_mem.ReadTextureNP(r, bits, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); - } + static uint8* buff = (uint8*)::_aligned_malloc(1024 * 1024 * 4, 16); + + pitch = ((r.width() + 3) & ~3) * 4; - m_texture->Update(r, bits, pitch); + if(m_renderer->m_psrr) + { + m_renderer->m_mem.ReadTextureNPNC(r, buff, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); + } + else + { + m_renderer->m_mem.ReadTextureNP(r, buff, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); + } + + m_texture->Update(r, buff, pitch); + } m_renderer->m_perfmon.Put(GSPerfMon::Unswizzle, r.width() * r.height() * m_bpp >> 3); } diff --git a/plugins/GSdx/GSTextureNull.h b/plugins/GSdx/GSTextureNull.h index cc094240a8..ec3ada8357 100644 --- a/plugins/GSdx/GSTextureNull.h +++ b/plugins/GSdx/GSTextureNull.h @@ -38,7 +38,7 @@ public: int GetHeight() const {return m_desc.h;} int GetFormat() const {return m_desc.format;} bool Update(const GSVector4i& r, const void* data, int pitch) {return true;} - bool Map(uint8** bits, int& pitch) {return true;} + bool Map(uint8** bits, int& pitch, const GSVector4i* r) {return false;} void Unmap() {} bool Save(const string& fn, bool dds = false) {return false;} }; diff --git a/plugins/GSdx/GSUtil.cpp b/plugins/GSdx/GSUtil.cpp index 5656f48c45..620464f6ef 100644 --- a/plugins/GSdx/GSUtil.cpp +++ b/plugins/GSdx/GSUtil.cpp @@ -174,7 +174,9 @@ bool GSUtil::IsDirect3D10Available() char* GSUtil::GetLibName() { - static string str = format("GSdx %d", SVN_REV); + static string str; + + str = format("GSdx %d", SVN_REV); if(SVN_MODS) str += "m";