summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software
diff options
context:
space:
mode:
authorStenzek <stenzek@users.noreply.github.com>2017-12-01 14:24:06 +1000
committerGitHub <noreply@github.com>2017-12-01 14:24:06 +1000
commitcd68b3606cea8a7041751bda482170533bae3220 (patch)
tree4edef80bda42a82a50ff9f9e86d64aac38c8aff3 /Source/Core/VideoBackends/Software
parent0773a48c6c990c488e70ff7c1f46713593440ddc (diff)
parent7f217a8bb24da323042081a02b65f84f9ce9761f (diff)
Merge pull request #6193 from stenzek/readbacks
Abstract Staging Textures - VideoCommon interface for texture readbacks/uploads
Diffstat (limited to 'Source/Core/VideoBackends/Software')
-rw-r--r--Source/Core/VideoBackends/Software/SWRenderer.cpp12
-rw-r--r--Source/Core/VideoBackends/Software/SWRenderer.h4
-rw-r--r--Source/Core/VideoBackends/Software/SWTexture.cpp86
-rw-r--r--Source/Core/VideoBackends/Software/SWTexture.h32
-rw-r--r--Source/Core/VideoBackends/Software/TextureCache.h5
5 files changed, 124 insertions, 15 deletions
diff --git a/Source/Core/VideoBackends/Software/SWRenderer.cpp b/Source/Core/VideoBackends/Software/SWRenderer.cpp
index 4c298e927e..4b84655002 100644
--- a/Source/Core/VideoBackends/Software/SWRenderer.cpp
+++ b/Source/Core/VideoBackends/Software/SWRenderer.cpp
@@ -14,6 +14,7 @@
#include "VideoBackends/Software/EfbCopy.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/SWOGLWindow.h"
+#include "VideoBackends/Software/SWTexture.h"
#include "VideoCommon/BoundingBox.h"
#include "VideoCommon/OnScreenDisplay.h"
@@ -34,6 +35,17 @@ void SWRenderer::Shutdown()
UpdateActiveConfig();
}
+std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config)
+{
+ return std::make_unique<SW::SWTexture>(config);
+}
+
+std::unique_ptr<AbstractStagingTexture>
+SWRenderer::CreateStagingTexture(StagingTextureType type, const TextureConfig& config)
+{
+ return std::make_unique<SW::SWStagingTexture>(type, config);
+}
+
void SWRenderer::RenderText(const std::string& pstr, int left, int top, u32 color)
{
SWOGLWindow::s_instance->PrintText(pstr, left, top, color);
diff --git a/Source/Core/VideoBackends/Software/SWRenderer.h b/Source/Core/VideoBackends/Software/SWRenderer.h
index a87531fcab..312acd1991 100644
--- a/Source/Core/VideoBackends/Software/SWRenderer.h
+++ b/Source/Core/VideoBackends/Software/SWRenderer.h
@@ -16,6 +16,10 @@ public:
static void Init();
static void Shutdown();
+ std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
+ std::unique_ptr<AbstractStagingTexture>
+ CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
+
void RenderText(const std::string& pstr, int left, int top, u32 color) override;
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
diff --git a/Source/Core/VideoBackends/Software/SWTexture.cpp b/Source/Core/VideoBackends/Software/SWTexture.cpp
index aa279b520b..13d2828fe9 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 <cstring>
+#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<size_t>(src_y) * src_stride + static_cast<size_t>(src_x) * texel_size;
+ size_t dst_stride = dst_config.GetStride();
+ size_t dst_offset =
+ static_cast<size_t>(dst_y) * dst_stride + static_cast<size_t>(dst_x) * texel_size;
+ size_t copy_len = static_cast<size_t>(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);
@@ -31,9 +56,19 @@ void SWTexture::Bind(unsigned int stage)
{
}
-void SWTexture::CopyRectangleFromTexture(const AbstractTexture* source,
- const MathUtil::Rectangle<int>& srcrect,
- const MathUtil::Rectangle<int>& dstrect)
+void SWTexture::CopyRectangleFromTexture(const AbstractTexture* src,
+ const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
+ u32 src_level, const MathUtil::Rectangle<int>& 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<const SWTexture*>(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<int>& srcrect,
+ const MathUtil::Rectangle<int>& dstrect)
{
const SWTexture* software_source_texture = static_cast<const SWTexture*>(source);
@@ -72,10 +107,49 @@ u8* SWTexture::GetData()
return m_data.data();
}
-std::optional<AbstractTexture::RawTextureInfo> SWTexture::MapFullImpl()
+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<char*>(m_data.data());
+ m_map_stride = m_texel_size * config.width;
+}
+
+SWStagingTexture::~SWStagingTexture() = default;
+
+void SWStagingTexture::CopyFromTexture(const AbstractTexture* src,
+ const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
+ u32 src_level, const MathUtil::Rectangle<int>& dst_rect)
+{
+ _assert_(src_level == 0 && src_layer == 0);
+ CopyTextureData(src->GetConfig(), static_cast<const SWTexture*>(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<int>& src_rect, AbstractTexture* dst,
+ const MathUtil::Rectangle<int>& 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<SWTexture*>(dst)->GetData(),
+ dst_rect.left, dst_rect.top);
+ m_needs_flush = true;
+}
+
+bool SWStagingTexture::Map()
+{
+ return true;
+}
+
+void SWStagingTexture::Unmap()
{
- return AbstractTexture::RawTextureInfo{GetData(), m_config.width * 4, m_config.width,
- m_config.height};
}
+void SWStagingTexture::Flush()
+{
+ m_needs_flush = false;
+}
} // namespace SW
diff --git a/Source/Core/VideoBackends/Software/SWTexture.h b/Source/Core/VideoBackends/Software/SWTexture.h
index fa7fea5308..0aaf12c2ad 100644
--- a/Source/Core/VideoBackends/Software/SWTexture.h
+++ b/Source/Core/VideoBackends/Software/SWTexture.h
@@ -8,6 +8,7 @@
#include "Common/CommonTypes.h"
+#include "VideoCommon/AbstractStagingTexture.h"
#include "VideoCommon/AbstractTexture.h"
namespace SW
@@ -20,9 +21,13 @@ public:
void Bind(unsigned int stage) override;
- void CopyRectangleFromTexture(const AbstractTexture* source,
- const MathUtil::Rectangle<int>& srcrect,
- const MathUtil::Rectangle<int>& dstrect) override;
+ void CopyRectangleFromTexture(const AbstractTexture* src,
+ const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
+ u32 src_level, const MathUtil::Rectangle<int>& dst_rect,
+ u32 dst_layer, u32 dst_level) override;
+ void ScaleRectangleFromTexture(const AbstractTexture* source,
+ const MathUtil::Rectangle<int>& srcrect,
+ const MathUtil::Rectangle<int>& dstrect) override;
void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
size_t buffer_size) override;
@@ -30,8 +35,27 @@ public:
u8* GetData();
private:
- std::optional<RawTextureInfo> MapFullImpl() override;
+ std::vector<u8> m_data;
+};
+
+class SWStagingTexture final : public AbstractStagingTexture
+{
+public:
+ explicit SWStagingTexture(StagingTextureType type, const TextureConfig& config);
+ ~SWStagingTexture();
+
+ void CopyFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& src_rect,
+ u32 src_layer, u32 src_level,
+ const MathUtil::Rectangle<int>& dst_rect) override;
+ void CopyToTexture(const MathUtil::Rectangle<int>& src_rect, AbstractTexture* dst,
+ const MathUtil::Rectangle<int>& dst_rect, u32 dst_layer,
+ u32 dst_level) override;
+ bool Map() override;
+ void Unmap() override;
+ void Flush() override;
+
+private:
std::vector<u8> m_data;
};
diff --git a/Source/Core/VideoBackends/Software/TextureCache.h b/Source/Core/VideoBackends/Software/TextureCache.h
index 3573d36ebb..49612394c2 100644
--- a/Source/Core/VideoBackends/Software/TextureCache.h
+++ b/Source/Core/VideoBackends/Software/TextureCache.h
@@ -25,11 +25,6 @@ public:
}
private:
- std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override
- {
- return std::make_unique<SWTexture>(config);
- }
-
void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, const EFBRectangle& src_rect,
bool scale_by_half, unsigned int cbuf_id, const float* colmat) override
{