From f43d85921dc85ae586d69b21d28a7578835a55bd Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 22 Oct 2017 00:49:40 +1000 Subject: VideoBackends: Add AbstractStagingTexture class Can be used for asynchronous readback or upload of textures. --- Source/Core/VideoBackends/Software/SWTexture.cpp | 70 ++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'Source/Core/VideoBackends/Software/SWTexture.cpp') diff --git a/Source/Core/VideoBackends/Software/SWTexture.cpp b/Source/Core/VideoBackends/Software/SWTexture.cpp index aa279b520b..184a223392 100644 --- a/Source/Core/VideoBackends/Software/SWTexture.cpp +++ b/Source/Core/VideoBackends/Software/SWTexture.cpp @@ -5,6 +5,7 @@ #include "VideoBackends/Software/SWTexture.h" #include +#include "Common/Assert.h" #include "VideoBackends/Software/CopyRegion.h" @@ -21,7 +22,31 @@ struct Pixel u8 a; }; #pragma pack(pop) + +void CopyTextureData(const TextureConfig& src_config, const u8* src_ptr, u32 src_x, u32 src_y, + u32 width, u32 height, const TextureConfig& dst_config, u8* dst_ptr, u32 dst_x, + u32 dst_y) +{ + size_t texel_size = AbstractTexture::GetTexelSizeForFormat(src_config.format); + size_t src_stride = src_config.GetStride(); + size_t src_offset = + static_cast(src_y) * src_stride + static_cast(src_x) * texel_size; + size_t dst_stride = dst_config.GetStride(); + size_t dst_offset = + static_cast(dst_y) * dst_stride + static_cast(dst_x) * texel_size; + size_t copy_len = static_cast(width) * texel_size; + + src_ptr += src_offset; + dst_ptr += dst_offset; + for (u32 i = 0; i < height; i++) + { + std::memcpy(dst_ptr, src_ptr, copy_len); + src_ptr += src_stride; + dst_ptr += dst_stride; + } +} } + SWTexture::SWTexture(const TextureConfig& tex_config) : AbstractTexture(tex_config) { m_data.resize(tex_config.width * tex_config.height * 4); @@ -78,4 +103,49 @@ std::optional SWTexture::MapFullImpl() m_config.height}; } +SWStagingTexture::SWStagingTexture(StagingTextureType type, const TextureConfig& config) + : AbstractStagingTexture(type, config) +{ + m_data.resize(m_texel_size * config.width * config.height); + m_map_pointer = reinterpret_cast(m_data.data()); + m_map_stride = m_texel_size * config.width; +} + +SWStagingTexture::~SWStagingTexture() = default; + +void SWStagingTexture::CopyFromTexture(const AbstractTexture* src, + const MathUtil::Rectangle& src_rect, u32 src_layer, + u32 src_level, const MathUtil::Rectangle& dst_rect) +{ + _assert_(src_level == 0 && src_layer == 0); + CopyTextureData(src->GetConfig(), static_cast(src)->GetData(), src_rect.left, + src_rect.top, src_rect.GetWidth(), src_rect.GetHeight(), m_config, m_data.data(), + dst_rect.left, dst_rect.top); + m_needs_flush = true; +} + +void SWStagingTexture::CopyToTexture(const MathUtil::Rectangle& src_rect, AbstractTexture* dst, + const MathUtil::Rectangle& dst_rect, u32 dst_layer, + u32 dst_level) +{ + _assert_(dst_level == 0 && dst_layer == 0); + CopyTextureData(m_config, m_data.data(), src_rect.left, src_rect.top, src_rect.GetWidth(), + src_rect.GetHeight(), dst->GetConfig(), static_cast(dst)->GetData(), + dst_rect.left, dst_rect.top); + m_needs_flush = true; +} + +bool SWStagingTexture::Map() +{ + return true; +} + +void SWStagingTexture::Unmap() +{ +} + +void SWStagingTexture::Flush() +{ + m_needs_flush = false; +} } // namespace SW -- cgit v1.2.3 From 56afebeb44f1ace990d9383e9b840fdc27610029 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 30 Oct 2017 21:51:42 +1000 Subject: AbstractTexture: Seperate CopyRectangleFromTexture to two methods ScaleRectangleFromTexture, which does a draw, and CopyRectangleFromTexture, which where possible, does a bit-for-bit copy. --- Source/Core/VideoBackends/Software/SWTexture.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/Software/SWTexture.cpp') diff --git a/Source/Core/VideoBackends/Software/SWTexture.cpp b/Source/Core/VideoBackends/Software/SWTexture.cpp index 184a223392..db9b56020a 100644 --- a/Source/Core/VideoBackends/Software/SWTexture.cpp +++ b/Source/Core/VideoBackends/Software/SWTexture.cpp @@ -56,9 +56,19 @@ void SWTexture::Bind(unsigned int stage) { } -void SWTexture::CopyRectangleFromTexture(const AbstractTexture* source, - const MathUtil::Rectangle& srcrect, - const MathUtil::Rectangle& dstrect) +void SWTexture::CopyRectangleFromTexture(const AbstractTexture* src, + const MathUtil::Rectangle& src_rect, u32 src_layer, + u32 src_level, const MathUtil::Rectangle& dst_rect, + u32 dst_layer, u32 dst_level) +{ + _assert_(src_level == 0 && src_layer == 0 && dst_layer == 0 && dst_level == 0); + CopyTextureData(src->GetConfig(), static_cast(src)->m_data.data(), + src_rect.left, src_rect.top, src_rect.GetWidth(), src_rect.GetHeight(), m_config, + m_data.data(), dst_rect.left, dst_rect.top); +} +void SWTexture::ScaleRectangleFromTexture(const AbstractTexture* source, + const MathUtil::Rectangle& srcrect, + const MathUtil::Rectangle& dstrect) { const SWTexture* software_source_texture = static_cast(source); -- cgit v1.2.3 From db1d9de933a914ff0c35a179d3ba1112fb0bcab1 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 19 Nov 2017 17:46:00 +1000 Subject: AbstractTexture: Drop slow map readback path --- Source/Core/VideoBackends/Software/SWTexture.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'Source/Core/VideoBackends/Software/SWTexture.cpp') diff --git a/Source/Core/VideoBackends/Software/SWTexture.cpp b/Source/Core/VideoBackends/Software/SWTexture.cpp index db9b56020a..13d2828fe9 100644 --- a/Source/Core/VideoBackends/Software/SWTexture.cpp +++ b/Source/Core/VideoBackends/Software/SWTexture.cpp @@ -107,12 +107,6 @@ u8* SWTexture::GetData() return m_data.data(); } -std::optional SWTexture::MapFullImpl() -{ - return AbstractTexture::RawTextureInfo{GetData(), m_config.width * 4, m_config.width, - m_config.height}; -} - SWStagingTexture::SWStagingTexture(StagingTextureType type, const TextureConfig& config) : AbstractStagingTexture(type, config) { -- cgit v1.2.3