summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2018-11-07 09:32:37 +0100
committerGitHub <noreply@github.com>2018-11-07 09:32:37 +0100
commitdac58a859ca30262b79f72036f1e78ea54be83c4 (patch)
tree9567559377284d746b77b07a14a01518017c99d4 /Source/Core/VideoBackends
parent710b893b914bcc1e812f1a63fdb9a143ff682561 (diff)
parenta45f977d265bb4360ca0b4a7fd189f4a30362f61 (diff)
Merge pull request #7539 from stenzek/batched-efb-copies
TextureCache: Deferred/batched EFB copies
Diffstat (limited to 'Source/Core/VideoBackends')
-rw-r--r--Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp24
-rw-r--r--Source/Core/VideoBackends/D3D/PSTextureEncoder.h7
-rw-r--r--Source/Core/VideoBackends/D3D/TextureCache.cpp4
-rw-r--r--Source/Core/VideoBackends/D3D/TextureCache.h11
-rw-r--r--Source/Core/VideoBackends/Null/TextureCache.h4
-rw-r--r--Source/Core/VideoBackends/OGL/TextureCache.cpp4
-rw-r--r--Source/Core/VideoBackends/OGL/TextureCache.h4
-rw-r--r--Source/Core/VideoBackends/OGL/TextureConverter.cpp28
-rw-r--r--Source/Core/VideoBackends/OGL/TextureConverter.h5
-rw-r--r--Source/Core/VideoBackends/Software/SWTexture.h2
-rw-r--r--Source/Core/VideoBackends/Software/TextureCache.h4
-rw-r--r--Source/Core/VideoBackends/Software/TextureEncoder.cpp22
-rw-r--r--Source/Core/VideoBackends/Software/TextureEncoder.h6
-rw-r--r--Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp4
-rw-r--r--Source/Core/VideoBackends/Vulkan/StateTracker.cpp21
-rw-r--r--Source/Core/VideoBackends/Vulkan/StateTracker.h7
-rw-r--r--Source/Core/VideoBackends/Vulkan/TextureCache.cpp7
-rw-r--r--Source/Core/VideoBackends/Vulkan/TextureCache.h4
-rw-r--r--Source/Core/VideoBackends/Vulkan/TextureConverter.cpp22
-rw-r--r--Source/Core/VideoBackends/Vulkan/TextureConverter.h19
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKTexture.cpp1
21 files changed, 104 insertions, 106 deletions
diff --git a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp
index 7c6dbd4411..231f317488 100644
--- a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp
+++ b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp
@@ -46,13 +46,8 @@ PSTextureEncoder::~PSTextureEncoder() = default;
void PSTextureEncoder::Init()
{
- // TODO: Move this to a constant somewhere in common.
- TextureConfig encoding_texture_config(EFB_WIDTH * 4, 1024, 1, 1, 1, AbstractTextureFormat::BGRA8,
- true);
- m_encoding_render_texture = g_renderer->CreateTexture(encoding_texture_config);
- m_encoding_readback_texture =
- g_renderer->CreateStagingTexture(StagingTextureType::Readback, encoding_texture_config);
- ASSERT(m_encoding_render_texture && m_encoding_readback_texture);
+ m_encoding_render_texture = g_renderer->CreateTexture(TextureCache::GetEncodingTextureConfig());
+ ASSERT(m_encoding_render_texture);
// Create constant buffer for uploading data to shaders
D3D11_BUFFER_DESC bd = CD3D11_BUFFER_DESC(sizeof(EFBEncodeParams), D3D11_BIND_CONSTANT_BUFFER);
@@ -71,9 +66,9 @@ void PSTextureEncoder::Shutdown()
}
void PSTextureEncoder::Encode(
- 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,
+ 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 TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients)
{
// Resolve MSAA targets before copying.
@@ -133,14 +128,7 @@ void PSTextureEncoder::Encode(
// Copy to staging buffer
MathUtil::Rectangle<int> copy_rect(0, 0, words_per_row, num_blocks_y);
- m_encoding_readback_texture->CopyFromTexture(m_encoding_render_texture.get(), copy_rect, 0, 0,
- copy_rect);
- m_encoding_readback_texture->Flush();
- if (m_encoding_readback_texture->Map())
- {
- m_encoding_readback_texture->ReadTexels(copy_rect, dst, memory_stride);
- m_encoding_readback_texture->Unmap();
- }
+ dst->CopyFromTexture(m_encoding_render_texture.get(), copy_rect, 0, 0, copy_rect);
}
g_renderer->RestoreAPIState();
diff --git a/Source/Core/VideoBackends/D3D/PSTextureEncoder.h b/Source/Core/VideoBackends/D3D/PSTextureEncoder.h
index 4054b07fbf..43f153c4cf 100644
--- a/Source/Core/VideoBackends/D3D/PSTextureEncoder.h
+++ b/Source/Core/VideoBackends/D3D/PSTextureEncoder.h
@@ -38,9 +38,9 @@ public:
void Init();
void Shutdown();
- void Encode(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,
+ void Encode(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 TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients);
private:
@@ -48,7 +48,6 @@ private:
ID3D11Buffer* m_encode_params = nullptr;
std::unique_ptr<AbstractTexture> m_encoding_render_texture;
- std::unique_ptr<AbstractStagingTexture> m_encoding_readback_texture;
std::map<EFBCopyParams, ID3D11PixelShader*> m_encoding_shaders;
};
}
diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp
index 41ad435817..f17d12f4c3 100644
--- a/Source/Core/VideoBackends/D3D/TextureCache.cpp
+++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp
@@ -31,8 +31,8 @@ namespace DX11
{
static std::unique_ptr<PSTextureEncoder> g_encoder;
-void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width,
- u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
+void TextureCache::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)
diff --git a/Source/Core/VideoBackends/D3D/TextureCache.h b/Source/Core/VideoBackends/D3D/TextureCache.h
index 24dda22d60..1bfa34c045 100644
--- a/Source/Core/VideoBackends/D3D/TextureCache.h
+++ b/Source/Core/VideoBackends/D3D/TextureCache.h
@@ -22,18 +22,11 @@ public:
~TextureCache();
private:
- u64 EncodeToRamFromTexture(u32 address, void* source_texture, u32 SourceW, u32 SourceH,
- bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf,
- const EFBRectangle& source)
- {
- return 0;
- };
-
void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette,
TLUTFormat format) override;
- 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,
+ 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) override;
diff --git a/Source/Core/VideoBackends/Null/TextureCache.h b/Source/Core/VideoBackends/Null/TextureCache.h
index 25803344a4..648871f626 100644
--- a/Source/Core/VideoBackends/Null/TextureCache.h
+++ b/Source/Core/VideoBackends/Null/TextureCache.h
@@ -25,8 +25,8 @@ public:
{
}
- 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,
+ 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) override
{
diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp
index 10f191448e..4fbbb39935 100644
--- a/Source/Core/VideoBackends/OGL/TextureCache.cpp
+++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp
@@ -159,8 +159,8 @@ void main()
//#define TIME_TEXTURE_DECODING 1
-void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width,
- u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
+void TextureCache::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)
diff --git a/Source/Core/VideoBackends/OGL/TextureCache.h b/Source/Core/VideoBackends/OGL/TextureCache.h
index 54dc4afef8..89fc82ee9d 100644
--- a/Source/Core/VideoBackends/OGL/TextureCache.h
+++ b/Source/Core/VideoBackends/OGL/TextureCache.h
@@ -63,8 +63,8 @@ private:
void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette,
TLUTFormat format) override;
- 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,
+ 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) override;
diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp
index 699e988196..095365140f 100644
--- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp
+++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp
@@ -46,7 +46,6 @@ struct EncodingProgram
std::map<EFBCopyParams, EncodingProgram> s_encoding_programs;
std::unique_ptr<AbstractTexture> s_encoding_render_texture;
-std::unique_ptr<AbstractStagingTexture> s_encoding_readback_texture;
const int renderBufferWidth = EFB_WIDTH * 4;
const int renderBufferHeight = 1024;
@@ -93,16 +92,11 @@ static EncodingProgram& GetOrCreateEncodingShader(const EFBCopyParams& params)
void Init()
{
- TextureConfig config(renderBufferWidth, renderBufferHeight, 1, 1, 1, AbstractTextureFormat::BGRA8,
- true);
- s_encoding_render_texture = g_renderer->CreateTexture(config);
- s_encoding_readback_texture =
- g_renderer->CreateStagingTexture(StagingTextureType::Readback, config);
+ s_encoding_render_texture = g_renderer->CreateTexture(TextureCache::GetEncodingTextureConfig());
}
void Shutdown()
{
- s_encoding_readback_texture.reset();
s_encoding_render_texture.reset();
for (auto& program : s_encoding_programs)
@@ -112,8 +106,9 @@ void Shutdown()
// dst_line_size, writeStride in bytes
-static void EncodeToRamUsingShader(GLuint srcTexture, u8* destAddr, u32 dst_line_size,
- u32 dstHeight, u32 writeStride, bool linearFilter, float y_scale)
+static void EncodeToRamUsingShader(GLuint srcTexture, AbstractStagingTexture* destAddr,
+ u32 dst_line_size, u32 dstHeight, u32 writeStride,
+ bool linearFilter, float y_scale)
{
FramebufferManager::SetFramebuffer(
static_cast<OGLTexture*>(s_encoding_render_texture.get())->GetFramebuffer());
@@ -137,15 +132,14 @@ static void EncodeToRamUsingShader(GLuint srcTexture, u8* destAddr, u32 dst_line
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
MathUtil::Rectangle<int> copy_rect(0, 0, dst_line_size / 4, dstHeight);
- s_encoding_readback_texture->CopyFromTexture(s_encoding_render_texture.get(), copy_rect, 0, 0,
- copy_rect);
- s_encoding_readback_texture->ReadTexels(copy_rect, destAddr, writeStride);
+
+ destAddr->CopyFromTexture(s_encoding_render_texture.get(), copy_rect, 0, 0, copy_rect);
}
-void EncodeToRamFromTexture(u8* dest_ptr, 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, float clamp_top, float clamp_bottom,
+void EncodeToRamFromTexture(AbstractStagingTexture* dest, 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, float clamp_top, float clamp_bottom,
const TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients)
{
g_renderer->ResetAPIState();
@@ -165,7 +159,7 @@ void EncodeToRamFromTexture(u8* dest_ptr, const EFBCopyParams& params, u32 nativ
FramebufferManager::ResolveAndGetDepthTarget(src_rect) :
FramebufferManager::ResolveAndGetRenderTarget(src_rect);
- EncodeToRamUsingShader(read_texture, dest_ptr, bytes_per_row, num_blocks_y, memory_stride,
+ EncodeToRamUsingShader(read_texture, dest, bytes_per_row, num_blocks_y, memory_stride,
scale_by_half && !params.depth, y_scale);
g_renderer->RestoreAPIState();
diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.h b/Source/Core/VideoBackends/OGL/TextureConverter.h
index 0d7450e4b6..575fbf5bd0 100644
--- a/Source/Core/VideoBackends/OGL/TextureConverter.h
+++ b/Source/Core/VideoBackends/OGL/TextureConverter.h
@@ -10,6 +10,9 @@
#include "VideoCommon/TextureCacheBase.h"
#include "VideoCommon/VideoCommon.h"
+struct EFBCopyParams;
+class AbstractStagingTexture;
+
namespace OGL
{
// Converts textures between formats using shaders
@@ -21,7 +24,7 @@ void Shutdown();
// returns size of the encoded data (in bytes)
void EncodeToRamFromTexture(
- u8* dest_ptr, const EFBCopyParams& params, u32 native_width, u32 bytes_per_row,
+ AbstractStagingTexture* dest, 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, float clamp_top, float clamp_bottom,
const TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients);
diff --git a/Source/Core/VideoBackends/Software/SWTexture.h b/Source/Core/VideoBackends/Software/SWTexture.h
index 5c403f54ba..f9d5c50485 100644
--- a/Source/Core/VideoBackends/Software/SWTexture.h
+++ b/Source/Core/VideoBackends/Software/SWTexture.h
@@ -57,6 +57,8 @@ public:
void Unmap() override;
void Flush() override;
+ void SetMapStride(size_t stride) { m_map_stride = stride; }
+
private:
std::vector<u8> m_data;
};
diff --git a/Source/Core/VideoBackends/Software/TextureCache.h b/Source/Core/VideoBackends/Software/TextureCache.h
index f3d9c91938..06bfbf73fa 100644
--- a/Source/Core/VideoBackends/Software/TextureCache.h
+++ b/Source/Core/VideoBackends/Software/TextureCache.h
@@ -16,8 +16,8 @@ public:
TLUTFormat format) override
{
}
- 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,
+ 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) override
{
diff --git a/Source/Core/VideoBackends/Software/TextureEncoder.cpp b/Source/Core/VideoBackends/Software/TextureEncoder.cpp
index a31888e544..07eba31530 100644
--- a/Source/Core/VideoBackends/Software/TextureEncoder.cpp
+++ b/Source/Core/VideoBackends/Software/TextureEncoder.cpp
@@ -5,12 +5,14 @@
#include "VideoBackends/Software/TextureEncoder.h"
#include "Common/Align.h"
+#include "Common/Assert.h"
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Common/Swap.h"
#include "VideoBackends/Software/EfbInterface.h"
+#include "VideoBackends/Software/SWTexture.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/LookUpTables.h"
@@ -1468,18 +1470,26 @@ void EncodeEfbCopy(u8* dst, const EFBCopyParams& params, u32 native_width, u32 b
}
}
-void Encode(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)
+void Encode(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)
{
+ // HACK: Override the memory stride for this staging texture with new copy stride.
+ // This is required because the texture encoder assumes that we're writing directly to memory,
+ // and each row is tightly packed with no padding, whereas our encoding abstract texture has
+ // a width of 2560. When we copy the texture back later on, it'll use the tightly packed stride.
+ ASSERT(memory_stride <= (dst->GetConfig().width * dst->GetTexelSize()));
+ static_cast<SW::SWStagingTexture*>(dst)->SetMapStride(memory_stride);
+
if (params.copy_format == EFBCopyFormat::XFB)
{
- EfbInterface::EncodeXFB(dst, native_width, src_rect, y_scale, gamma);
+ EfbInterface::EncodeXFB(reinterpret_cast<u8*>(dst->GetMappedPointer()), native_width, src_rect,
+ y_scale, gamma);
}
else
{
- EncodeEfbCopy(dst, params, native_width, bytes_per_row, num_blocks_y, memory_stride, src_rect,
- scale_by_half);
+ EncodeEfbCopy(reinterpret_cast<u8*>(dst->GetMappedPointer()), params, native_width,
+ bytes_per_row, num_blocks_y, memory_stride, src_rect, scale_by_half);
}
}
}
diff --git a/Source/Core/VideoBackends/Software/TextureEncoder.h b/Source/Core/VideoBackends/Software/TextureEncoder.h
index 20aa05605a..705fa2e81b 100644
--- a/Source/Core/VideoBackends/Software/TextureEncoder.h
+++ b/Source/Core/VideoBackends/Software/TextureEncoder.h
@@ -10,7 +10,7 @@
namespace TextureEncoder
{
-void Encode(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);
+void Encode(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);
}
diff --git a/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp b/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp
index 27eeeb58ba..cd1fbd9c82 100644
--- a/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp
+++ b/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp
@@ -611,7 +611,7 @@ bool FramebufferManager::PopulateColorReadbackTexture()
{
// Can't be in our normal render pass.
StateTracker::GetInstance()->EndRenderPass();
- StateTracker::GetInstance()->OnReadback();
+ StateTracker::GetInstance()->OnCPUEFBAccess();
// Issue a copy from framebuffer -> copy texture if we have >1xIR or MSAA on.
VkRect2D src_region = {{0, 0}, {GetEFBWidth(), GetEFBHeight()}};
@@ -684,7 +684,7 @@ bool FramebufferManager::PopulateDepthReadbackTexture()
{
// Can't be in our normal render pass.
StateTracker::GetInstance()->EndRenderPass();
- StateTracker::GetInstance()->OnReadback();
+ StateTracker::GetInstance()->OnCPUEFBAccess();
// Issue a copy from framebuffer -> copy texture if we have >1xIR or MSAA on.
VkRect2D src_region = {{0, 0}, {GetEFBWidth(), GetEFBHeight()}};
diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
index 38a91c61ad..f3b2752ddd 100644
--- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
+++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
@@ -513,7 +513,7 @@ void StateTracker::OnDraw()
}
}
-void StateTracker::OnReadback()
+void StateTracker::OnCPUEFBAccess()
{
// Check this isn't another access without any draws inbetween.
if (!m_cpu_accesses_this_frame.empty() && m_cpu_accesses_this_frame.back() == m_draw_counter)
@@ -523,9 +523,28 @@ void StateTracker::OnReadback()
m_cpu_accesses_this_frame.emplace_back(m_draw_counter);
}
+void StateTracker::OnEFBCopyToRAM()
+{
+ // If we're not deferring, try to preempt it next frame.
+ if (!g_ActiveConfig.bDeferEFBCopies)
+ {
+ OnCPUEFBAccess();
+ return;
+ }
+
+ // Otherwise, only execute if we have at least 10 objects between us and the last copy.
+ const u32 diff = m_draw_counter - m_last_efb_copy_draw_counter;
+ m_last_efb_copy_draw_counter = m_draw_counter;
+ if (diff < MINIMUM_DRAW_CALLS_PER_COMMAND_BUFFER_FOR_READBACK)
+ return;
+
+ Util::ExecuteCurrentCommandsAndRestoreState(true);
+}
+
void StateTracker::OnEndFrame()
{
m_draw_counter = 0;
+ m_last_efb_copy_draw_counter = 0;
m_scheduled_command_buffer_kicks.clear();
// If we have no CPU access at all, leave everything in the one command buffer for maximum
diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.h b/Source/Core/VideoBackends/Vulkan/StateTracker.h
index 547c62f655..895e139756 100644
--- a/Source/Core/VideoBackends/Vulkan/StateTracker.h
+++ b/Source/Core/VideoBackends/Vulkan/StateTracker.h
@@ -86,8 +86,10 @@ public:
void OnDraw();
// Call after CPU access is requested.
- // This can be via EFBCache or EFB2RAM.
- void OnReadback();
+ void OnCPUEFBAccess();
+
+ // Call after an EFB copy to RAM. If true, the current command buffer should be executed.
+ void OnEFBCopyToRAM();
// Call at the end of a frame.
void OnEndFrame();
@@ -182,6 +184,7 @@ private:
// CPU access tracking
u32 m_draw_counter = 0;
+ u32 m_last_efb_copy_draw_counter = 0;
std::vector<u32> m_cpu_accesses_this_frame;
std::vector<u32> m_scheduled_command_buffer_kicks;
bool m_allow_background_execution = true;
diff --git a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp
index 334b3f9b1a..e9b92ba1e1 100644
--- a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp
+++ b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp
@@ -98,8 +98,8 @@ void TextureCache::ConvertTexture(TCacheEntry* destination, TCacheEntry* source,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
-void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width,
- u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
+void TextureCache::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)
@@ -126,7 +126,6 @@ void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_widt
// The barrier has to happen after the render pass, not inside it, as we are going to be
// reading from the texture immediately afterwards.
StateTracker::GetInstance()->EndRenderPass();
- StateTracker::GetInstance()->OnReadback();
// Transition to shader resource before reading.
VkImageLayout original_layout = src_texture->GetLayout();
@@ -139,6 +138,8 @@ void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_widt
// Transition back to original state
src_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), original_layout);
+
+ StateTracker::GetInstance()->OnEFBCopyToRAM();
}
bool TextureCache::SupportsGPUTextureDecode(TextureFormat format, TLUTFormat palette_format)
diff --git a/Source/Core/VideoBackends/Vulkan/TextureCache.h b/Source/Core/VideoBackends/Vulkan/TextureCache.h
index 846761d1d5..fd6b57981a 100644
--- a/Source/Core/VideoBackends/Vulkan/TextureCache.h
+++ b/Source/Core/VideoBackends/Vulkan/TextureCache.h
@@ -36,8 +36,8 @@ public:
void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette,
TLUTFormat format) override;
- 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,
+ 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) override;
diff --git a/Source/Core/VideoBackends/Vulkan/TextureConverter.cpp b/Source/Core/VideoBackends/Vulkan/TextureConverter.cpp
index da40b08667..c5acdc8e7f 100644
--- a/Source/Core/VideoBackends/Vulkan/TextureConverter.cpp
+++ b/Source/Core/VideoBackends/Vulkan/TextureConverter.cpp
@@ -207,10 +207,10 @@ void TextureConverter::ConvertTexture(TextureCacheBase::TCacheEntry* dst_entry,
}
void TextureConverter::EncodeTextureToMemory(
- VkImageView src_texture, u8* dest_ptr, 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 TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients)
+ VkImageView src_texture, AbstractStagingTexture* dest, 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 TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients)
{
VkShaderModule shader = GetEncodingShader(params);
if (shader == VK_NULL_HANDLE)
@@ -273,9 +273,7 @@ void TextureConverter::EncodeTextureToMemory(
draw.EndRenderPass();
MathUtil::Rectangle<int> copy_rect(0, 0, render_width, render_height);
- m_encoding_readback_texture->CopyFromTexture(m_encoding_render_texture.get(), copy_rect, 0, 0,
- copy_rect);
- m_encoding_readback_texture->ReadTexels(copy_rect, dest_ptr, memory_stride);
+ dest->CopyFromTexture(m_encoding_render_texture.get(), copy_rect, 0, 0, copy_rect);
}
bool TextureConverter::SupportsTextureDecoding(TextureFormat format, TLUTFormat palette_format)
@@ -610,14 +608,8 @@ VkShaderModule TextureConverter::GetEncodingShader(const EFBCopyParams& params)
bool TextureConverter::CreateEncodingTexture()
{
- TextureConfig config(ENCODING_TEXTURE_WIDTH, ENCODING_TEXTURE_HEIGHT, 1, 1, 1,
- ENCODING_TEXTURE_FORMAT, true);
-
- m_encoding_render_texture = g_renderer->CreateTexture(config);
- m_encoding_readback_texture =
- g_renderer->CreateStagingTexture(StagingTextureType::Readback, config);
-
- return m_encoding_render_texture && m_encoding_readback_texture;
+ m_encoding_render_texture = g_renderer->CreateTexture(TextureCache::GetEncodingTextureConfig());
+ return m_encoding_render_texture != nullptr;
}
bool TextureConverter::CreateDecodingTexture()
diff --git a/Source/Core/VideoBackends/Vulkan/TextureConverter.h b/Source/Core/VideoBackends/Vulkan/TextureConverter.h
index f85efc4d5c..9c035296b2 100644
--- a/Source/Core/VideoBackends/Vulkan/TextureConverter.h
+++ b/Source/Core/VideoBackends/Vulkan/TextureConverter.h
@@ -21,7 +21,6 @@ class AbstractStagingTexture;
namespace Vulkan
{
-class StagingTexture2D;
class Texture2D;
class VKTexture;
@@ -38,14 +37,12 @@ public:
TextureCache::TCacheEntry* src_entry, const void* palette,
TLUTFormat palette_format);
- // Uses an encoding shader to copy src_texture to dest_ptr.
- // NOTE: Executes the current command buffer.
- void
- EncodeTextureToMemory(VkImageView src_texture, u8* dest_ptr, 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 TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients);
+ // Uses an encoding shader to copy src_texture to dest.
+ void EncodeTextureToMemory(
+ VkImageView src_texture, AbstractStagingTexture* dest, 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 TextureCacheBase::CopyFilterCoefficientArray& filter_coefficients);
bool SupportsTextureDecoding(TextureFormat format, TLUTFormat palette_format);
void DecodeTexture(VkCommandBuffer command_buffer, TextureCache::TCacheEntry* entry,
@@ -54,9 +51,6 @@ public:
const u8* palette, TLUTFormat palette_format);
private:
- static const u32 ENCODING_TEXTURE_WIDTH = EFB_WIDTH * 4;
- static const u32 ENCODING_TEXTURE_HEIGHT = 1024;
- static const AbstractTextureFormat ENCODING_TEXTURE_FORMAT = AbstractTextureFormat::BGRA8;
static const size_t NUM_PALETTE_CONVERSION_SHADERS = 3;
// Maximum size of a texture based on BP registers.
@@ -100,7 +94,6 @@ private:
// Texture encoding - RGBA8->GX format in memory
std::map<EFBCopyParams, VkShaderModule> m_encoding_shaders;
std::unique_ptr<AbstractTexture> m_encoding_render_texture;
- std::unique_ptr<AbstractStagingTexture> m_encoding_readback_texture;
// Texture decoding - GX format in memory->RGBA8
struct TextureDecodingPipeline
diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
index b3c111d5a2..63b88195c0 100644
--- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
@@ -466,6 +466,7 @@ void VKStagingTexture::CopyFromTexture(Texture2D* src, const MathUtil::Rectangle
m_needs_flush = false;
g_command_buffer_mgr->RemoveFencePointCallback(
this);
+ m_staging_buffer->InvalidateCPUCache();
});
}