From 8e2c063d6219b01037d1cb5bdb009000e52d8479 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 3 Nov 2018 00:17:00 +1000 Subject: TextureCache: Implement deferred/batched EFB copies --- Source/Core/VideoCommon/TextureCacheBase.h | 43 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.h') diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index 1c84662065..c797a9a4f0 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "Common/CommonTypes.h" #include "VideoCommon/AbstractTexture.h" @@ -22,6 +23,7 @@ #include "VideoCommon/VideoCommon.h" struct VideoConfig; +class AbstractStagingTexture; struct TextureAndTLUTFormat { @@ -149,6 +151,12 @@ public: // * partially updated textures which refer to this efb copy std::unordered_set references; + // Pending EFB copy + std::unique_ptr pending_efb_copy; + u32 pending_efb_copy_width = 0; + u32 pending_efb_copy_height = 0; + bool pending_efb_copy_invalidated = false; + explicit TCacheEntry(std::unique_ptr tex); ~TCacheEntry(); @@ -216,10 +224,10 @@ public: void Invalidate(); - virtual void CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width, u32 bytes_per_row, - u32 num_blocks_y, u32 memory_stride, const EFBRectangle& src_rect, - bool scale_by_half, float y_scale, float gamma, bool clamp_top, - bool clamp_bottom, + virtual void CopyEFB(AbstractStagingTexture* dst, const EFBCopyParams& params, u32 native_width, + u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, + const EFBRectangle& src_rect, bool scale_by_half, float y_scale, float gamma, + bool clamp_top, bool clamp_bottom, const CopyFilterCoefficientArray& filter_coefficients) = 0; virtual bool CompileShaders() = 0; @@ -278,6 +286,12 @@ public: void ScaleTextureCacheEntryTo(TCacheEntry* entry, u32 new_width, u32 new_height); + // Flushes all pending EFB copies to emulated RAM. + void FlushEFBCopies(); + + // Returns a texture config suitable for drawing a RAM EFB copy into. + static TextureConfig GetEncodingTextureConfig(); + protected: TextureCacheBase(); @@ -329,7 +343,8 @@ private: const CopyFilterCoefficientArray& filter_coefficients) = 0; // Removes and unlinks texture from texture cache and returns it to the pool - TexAddrCache::iterator InvalidateTexture(TexAddrCache::iterator t_iter); + TexAddrCache::iterator InvalidateTexture(TexAddrCache::iterator t_iter, + bool discard_pending_efb_copy = false); void UninitializeXFBMemory(u8* dst, u32 stride, u32 bytes_per_row, u32 num_blocks_y); @@ -339,6 +354,17 @@ private: CopyFilterCoefficientArray GetVRAMCopyFilterCoefficients(const CopyFilterCoefficients::Values& coefficients) const; + // Flushes a pending EFB copy to RAM from the host to the guest RAM. + void WriteEFBCopyToRAM(u8* dst_ptr, u32 width, u32 height, u32 stride, + std::unique_ptr staging_texture); + void FlushEFBCopy(TCacheEntry* entry); + + // Returns a staging texture of the maximum EFB copy size. + std::unique_ptr GetEFBCopyStagingTexture(); + + // Returns an EFB copy staging texture to the pool, so it can be re-used. + void ReleaseEFBCopyStagingTexture(std::unique_ptr tex); + TexAddrCache textures_by_address; TexHashCache textures_by_hash; TexPool texture_pool; @@ -360,6 +386,13 @@ private: bool arbitrary_mipmap_detection; }; BackupConfig backup_config = {}; + + // Pool of readback textures used for deferred EFB copies. + std::vector> m_efb_copy_staging_texture_pool; + + // List of pending EFB copies. It is important that the order is preserved for these, + // so that overlapping textures are written to guest RAM in the order they are issued. + std::vector m_pending_efb_copies; }; extern std::unique_ptr g_texture_cache; -- cgit v1.2.3