From dcdf8fd3ced5e5d2b94299bc710a69ee06bab0d6 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 29 Oct 2015 17:48:35 +0100 Subject: [PATCH] TextureCache: Split efb2ram from efb2tex --- .../Core/VideoBackends/D3D/TextureCache.cpp | 10 +++--- Source/Core/VideoBackends/D3D/TextureCache.h | 4 +++ .../Core/VideoBackends/D3D/TextureEncoder.h | 2 +- .../Core/VideoBackends/OGL/TextureCache.cpp | 34 +++++++++---------- Source/Core/VideoBackends/OGL/TextureCache.h | 4 +++ Source/Core/VideoCommon/TextureCacheBase.cpp | 19 +++++++++++ Source/Core/VideoCommon/TextureCacheBase.h | 4 +++ 7 files changed, 54 insertions(+), 23 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp index eab591c7ee..f2f5ae96b4 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp @@ -236,11 +236,13 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, unsigned int dstFormat D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV()); g_renderer->RestoreAPIState(); +} - if (g_ActiveConfig.bSkipEFBCopyToRam) - this->Zero(dst); - else - g_encoder->Encode(dst, format, native_width, BytesPerRow(), NumBlocksY(), memory_stride, srcFormat, srcRect, isIntensity, scaleByHalf); +void TextureCache::CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, + PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, + bool isIntensity, bool scaleByHalf) +{ + g_encoder->Encode(dst, format, native_width, bytes_per_row, num_blocks_y, memory_stride, srcFormat, srcRect, isIntensity, scaleByHalf); } const char palette_shader[] = diff --git a/Source/Core/VideoBackends/D3D/TextureCache.h b/Source/Core/VideoBackends/D3D/TextureCache.h index fa6aeafc3b..c852d2469c 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.h +++ b/Source/Core/VideoBackends/D3D/TextureCache.h @@ -49,6 +49,10 @@ private: void ConvertTexture(TCacheEntryBase* entry, TCacheEntryBase* unconverted, void* palette, TlutFormat format) override; + void CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, + PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, + bool isIntensity, bool scaleByHalf) override; + void CompileShaders() override { } void DeleteShaders() override { } diff --git a/Source/Core/VideoBackends/D3D/TextureEncoder.h b/Source/Core/VideoBackends/D3D/TextureEncoder.h index 2e3eef99ad..52ac6ba25e 100644 --- a/Source/Core/VideoBackends/D3D/TextureEncoder.h +++ b/Source/Core/VideoBackends/D3D/TextureEncoder.h @@ -26,7 +26,7 @@ public: virtual void Init() = 0; virtual void Shutdown() = 0; // Returns size in bytes of encoded block of memory - virtual void Encode(u8* dst, const TextureCacheBase::TCacheEntryBase* texture_entry, + virtual void Encode(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf) = 0; diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 24fcb81e82..e733cd8d87 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -266,25 +266,23 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dstPointer, unsigned int ds FramebufferManager::SetFramebuffer(0); g_renderer->RestoreAPIState(); +} - if (g_ActiveConfig.bSkipEFBCopyToRam) - { - this->Zero(dstPointer); - } - else - { - TextureConverter::EncodeToRamFromTexture( - dstPointer, - format, - native_width, - BytesPerRow(), - NumBlocksY(), - memory_stride, - srcFormat, - isIntensity, - scaleByHalf, - srcRect); - } +void TextureCache::CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, + PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, + bool isIntensity, bool scaleByHalf) +{ + TextureConverter::EncodeToRamFromTexture( + dst, + format, + native_width, + bytes_per_row, + num_blocks_y, + memory_stride, + srcFormat, + isIntensity, + scaleByHalf, + srcRect); } TextureCache::TextureCache() diff --git a/Source/Core/VideoBackends/OGL/TextureCache.h b/Source/Core/VideoBackends/OGL/TextureCache.h index 10c4a57378..3028a25d38 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.h +++ b/Source/Core/VideoBackends/OGL/TextureCache.h @@ -56,6 +56,10 @@ private: TCacheEntryBase* CreateTexture(const TCacheEntryConfig& config) override; void ConvertTexture(TCacheEntryBase* entry, TCacheEntryBase* unconverted, void* palette, TlutFormat format) override; + void CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, + PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, + bool isIntensity, bool scaleByHalf) override; + void CompileShaders() override; void DeleteShaders() override; }; diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 8f1d700dfd..44fdf9fe48 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -1050,6 +1050,25 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFo entry->FromRenderTarget(dst, dstFormat, dstStride, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat); + if (g_ActiveConfig.bSkipEFBCopyToRam) + { + entry->Zero(dst); + } + else + { + g_texture_cache->CopyEFB( + dst, + entry->format, + entry->native_width, + entry->BytesPerRow(), + entry->NumBlocksY(), + entry->memory_stride, + srcFormat, + srcRect, + isIntensity, + scaleByHalf); + } + u64 hash = entry->CalculateHash(); entry->SetHashes(hash, hash); diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index 9e7b4a7c71..1dbddd253f 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -130,6 +130,10 @@ public: virtual TCacheEntryBase* CreateTexture(const TCacheEntryConfig& config) = 0; + virtual void CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, + PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect, + bool isIntensity, bool scaleByHalf) = 0; + virtual void CompileShaders() = 0; // currently only implemented by OGL virtual void DeleteShaders() = 0; // currently only implemented by OGL