From a584ccc7d882213d93586cae9063d9865311aaad Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 9 Sep 2017 15:24:41 +1000 Subject: AbstractTexture: Support BGRA8 formats Used for some driver's swap chains, and EFB to RAM. --- Source/Core/VideoCommon/AbstractTexture.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/AbstractTexture.cpp') diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp index 7e4f493601..9fa099e602 100644 --- a/Source/Core/VideoCommon/AbstractTexture.cpp +++ b/Source/Core/VideoCommon/AbstractTexture.cpp @@ -5,7 +5,7 @@ #include #include "Common/Assert.h" - +#include "Common/MsgHandler.h" #include "VideoCommon/AbstractTexture.h" #include "VideoCommon/ImageWrite.h" @@ -102,8 +102,17 @@ AbstractTexture::MapRegionImpl(u32 level, u32 x, u32 y, u32 width, u32 height) bool AbstractTexture::IsCompressedHostTextureFormat(AbstractTextureFormat format) { - // This will need to be changed if we add any other uncompressed formats. - return format != AbstractTextureFormat::RGBA8; + switch (format) + { + case AbstractTextureFormat::DXT1: + case AbstractTextureFormat::DXT3: + case AbstractTextureFormat::DXT5: + case AbstractTextureFormat::BPTC: + return true; + + default: + return false; + } } size_t AbstractTexture::CalculateHostTextureLevelPitch(AbstractTextureFormat format, u32 row_length) @@ -117,8 +126,11 @@ size_t AbstractTexture::CalculateHostTextureLevelPitch(AbstractTextureFormat for case AbstractTextureFormat::BPTC: return static_cast(std::max(1u, row_length / 4)) * 16; case AbstractTextureFormat::RGBA8: - default: + case AbstractTextureFormat::BGRA8: return static_cast(row_length) * 4; + default: + PanicAlert("Unhandled texture format."); + return 0; } } -- cgit v1.2.3 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/VideoCommon/AbstractTexture.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/AbstractTexture.cpp') diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp index 9fa099e602..7e09be5344 100644 --- a/Source/Core/VideoCommon/AbstractTexture.cpp +++ b/Source/Core/VideoCommon/AbstractTexture.cpp @@ -100,7 +100,7 @@ AbstractTexture::MapRegionImpl(u32 level, u32 x, u32 y, u32 width, u32 height) return {}; } -bool AbstractTexture::IsCompressedHostTextureFormat(AbstractTextureFormat format) +bool AbstractTexture::IsCompressedFormat(AbstractTextureFormat format) { switch (format) { @@ -115,7 +115,7 @@ bool AbstractTexture::IsCompressedHostTextureFormat(AbstractTextureFormat format } } -size_t AbstractTexture::CalculateHostTextureLevelPitch(AbstractTextureFormat format, u32 row_length) +size_t AbstractTexture::CalculateStrideForFormat(AbstractTextureFormat format, u32 row_length) { switch (format) { @@ -134,6 +134,25 @@ size_t AbstractTexture::CalculateHostTextureLevelPitch(AbstractTextureFormat for } } +size_t AbstractTexture::GetTexelSizeForFormat(AbstractTextureFormat format) +{ + switch (format) + { + case AbstractTextureFormat::DXT1: + return 8; + case AbstractTextureFormat::DXT3: + case AbstractTextureFormat::DXT5: + case AbstractTextureFormat::BPTC: + return 16; + case AbstractTextureFormat::RGBA8: + case AbstractTextureFormat::BGRA8: + return 4; + default: + PanicAlert("Unhandled texture format."); + return 0; + } +} + const TextureConfig& AbstractTexture::GetConfig() const { return m_config; -- cgit v1.2.3 From c2cc128f1b6be695a4facd3c0fd697a24c3df17a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 30 Oct 2017 22:00:15 +1000 Subject: AbstractTexture: Implement Save using new common methods --- Source/Core/VideoCommon/AbstractTexture.cpp | 32 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'Source/Core/VideoCommon/AbstractTexture.cpp') diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp index 7e09be5344..109bb52897 100644 --- a/Source/Core/VideoCommon/AbstractTexture.cpp +++ b/Source/Core/VideoCommon/AbstractTexture.cpp @@ -6,8 +6,10 @@ #include "Common/Assert.h" #include "Common/MsgHandler.h" +#include "VideoCommon/AbstractStagingTexture.h" #include "VideoCommon/AbstractTexture.h" #include "VideoCommon/ImageWrite.h" +#include "VideoCommon/RenderBase.h" AbstractTexture::AbstractTexture(const TextureConfig& c) : m_config(c) { @@ -20,17 +22,33 @@ bool AbstractTexture::Save(const std::string& filename, unsigned int level) // We can't dump compressed textures currently (it would mean drawing them to a RGBA8 // framebuffer, and saving that). TextureCache does not call Save for custom textures // anyway, so this is fine for now. - _assert_(m_config.format == AbstractTextureFormat::RGBA8); + _assert_(!IsCompressedFormat(m_config.format)); + _assert_(level < m_config.levels); - auto result = level == 0 ? Map() : Map(level); + // Determine dimensions of image we want to save. + u32 level_width = std::max(1u, m_config.width >> level); + u32 level_height = std::max(1u, m_config.height >> level); + + // Use a temporary staging texture for the download. Certainly not optimal, + // but this is not a frequently-executed code path.. + TextureConfig readback_texture_config(level_width, level_height, 1, 1, + AbstractTextureFormat::RGBA8, false); + auto readback_texture = + g_renderer->CreateStagingTexture(StagingTextureType::Readback, readback_texture_config); + if (!readback_texture) + return false; - if (!result.has_value()) - { + // Copy to the readback texture's buffer. + readback_texture->CopyFromTexture(this, 0, level); + readback_texture->Flush(); + + // Map it so we can encode it to the file. + if (!readback_texture->Map()) return false; - } - auto raw_data = result.value(); - return TextureToPng(raw_data.data, raw_data.stride, filename, raw_data.width, raw_data.height); + return TextureToPng(reinterpret_cast(readback_texture->GetMappedPointer()), + static_cast(readback_texture->GetMappedStride()), filename, level_width, + level_height); } std::optional AbstractTexture::Map() -- 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/VideoCommon/AbstractTexture.cpp | 67 ----------------------------- 1 file changed, 67 deletions(-) (limited to 'Source/Core/VideoCommon/AbstractTexture.cpp') diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp index 109bb52897..896d75feb8 100644 --- a/Source/Core/VideoCommon/AbstractTexture.cpp +++ b/Source/Core/VideoCommon/AbstractTexture.cpp @@ -51,73 +51,6 @@ bool AbstractTexture::Save(const std::string& filename, unsigned int level) level_height); } -std::optional AbstractTexture::Map() -{ - if (m_currently_mapped) - { - Unmap(); - m_currently_mapped = false; - } - auto result = MapFullImpl(); - - if (!result.has_value()) - { - m_currently_mapped = false; - return {}; - } - - m_currently_mapped = true; - return result; -} - -std::optional AbstractTexture::Map(u32 level, u32 x, u32 y, - u32 width, u32 height) -{ - _assert_(level < m_config.levels); - - u32 max_level_width = std::max(m_config.width >> level, 1u); - u32 max_level_height = std::max(m_config.height >> level, 1u); - - _assert_(width < max_level_width); - _assert_(height < max_level_height); - - auto result = MapRegionImpl(level, x, y, width, height); - - if (!result.has_value()) - { - m_currently_mapped = false; - return {}; - } - - m_currently_mapped = true; - return result; -} - -std::optional AbstractTexture::Map(u32 level) -{ - _assert_(level < m_config.levels); - - u32 level_width = std::max(m_config.width >> level, 1u); - u32 level_height = std::max(m_config.height >> level, 1u); - - return Map(level, 0, 0, level_width, level_height); -} - -void AbstractTexture::Unmap() -{ -} - -std::optional AbstractTexture::MapFullImpl() -{ - return {}; -} - -std::optional -AbstractTexture::MapRegionImpl(u32 level, u32 x, u32 y, u32 width, u32 height) -{ - return {}; -} - bool AbstractTexture::IsCompressedFormat(AbstractTextureFormat format) { switch (format) -- cgit v1.2.3