From bf7db3f88835d3b69800c9ed5596e31c7ba96346 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 24 Oct 2017 00:44:14 -0500 Subject: [PATCH] Software Backend: Remove reinterpret_cast which violates the strict aliasing rule --- .../VideoBackends/Software/EfbInterface.cpp | 17 +++++++++++------ .../Core/VideoBackends/Software/EfbInterface.h | 3 +-- .../Core/VideoBackends/Software/SWTexture.cpp | 11 +++++++++-- .../VideoBackends/Software/TextureEncoder.cpp | 3 +-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Source/Core/VideoBackends/Software/EfbInterface.cpp b/Source/Core/VideoBackends/Software/EfbInterface.cpp index 55462ce33f..a94ac467b8 100644 --- a/Source/Core/VideoBackends/Software/EfbInterface.cpp +++ b/Source/Core/VideoBackends/Software/EfbInterface.cpp @@ -497,8 +497,7 @@ u8* GetPixelPointer(u16 x, u16 y, bool depth) return &efb[GetColorOffset(x, y)]; } -void EncodeXFB(yuv422_packed* xfb_in_ram, u32 memory_stride, const EFBRectangle& source_rect, - float y_scale) +void EncodeXFB(u8* xfb_in_ram, u32 memory_stride, const EFBRectangle& source_rect, float y_scale) { if (!xfb_in_ram) { @@ -555,10 +554,16 @@ void EncodeXFB(yuv422_packed* xfb_in_ram, u32 memory_stride, const EFBRectangle& src_ptr += memory_stride; } - // Apply y scaling and copy to the xfb memory location - SW::CopyRegion(source.data(), source_rect, xfb_in_ram, - EFBRectangle{source_rect.left, source_rect.top, source_rect.right, - static_cast(static_cast(source_rect.bottom) * y_scale)}); + auto dest_rect = EFBRectangle{source_rect.left, source_rect.top, source_rect.right, + static_cast(static_cast(source_rect.bottom) * y_scale)}; + + const std::size_t destination_size = dest_rect.GetWidth() * dest_rect.GetHeight() * 2; + static std::vector destination; + destination.resize(dest_rect.GetWidth() * dest_rect.GetHeight()); + + SW::CopyRegion(source.data(), source_rect, destination.data(), dest_rect); + + memcpy(xfb_in_ram, destination.data(), destination_size); } bool ZCompare(u16 x, u16 y, u32 z) diff --git a/Source/Core/VideoBackends/Software/EfbInterface.h b/Source/Core/VideoBackends/Software/EfbInterface.h index 24baf37689..a95d6b8aeb 100644 --- a/Source/Core/VideoBackends/Software/EfbInterface.h +++ b/Source/Core/VideoBackends/Software/EfbInterface.h @@ -57,8 +57,7 @@ u32 GetDepth(u16 x, u16 y); u8* GetPixelPointer(u16 x, u16 y, bool depth); -void EncodeXFB(yuv422_packed* xfb_in_ram, u32 memory_stride, const EFBRectangle& source_rect, - float y_scale); +void EncodeXFB(u8* xfb_in_ram, u32 memory_stride, const EFBRectangle& source_rect, float y_scale); extern u32 perf_values[PQ_NUM_MEMBERS]; inline void IncPerfCounterQuadCount(PerfQueryType type) diff --git a/Source/Core/VideoBackends/Software/SWTexture.cpp b/Source/Core/VideoBackends/Software/SWTexture.cpp index 2ca31343f4..aa279b520b 100644 --- a/Source/Core/VideoBackends/Software/SWTexture.cpp +++ b/Source/Core/VideoBackends/Software/SWTexture.cpp @@ -44,8 +44,15 @@ void SWTexture::CopyRectangleFromTexture(const AbstractTexture* source, } else { - CopyRegion(reinterpret_cast(software_source_texture->GetData()), srcrect, - reinterpret_cast(GetData()), dstrect); + std::vector source_pixels; + source_pixels.resize(srcrect.GetHeight() * srcrect.GetWidth() * 4); + memcpy(source_pixels.data(), software_source_texture->GetData(), source_pixels.size()); + + std::vector destination_pixels; + destination_pixels.resize(dstrect.GetHeight() * dstrect.GetWidth() * 4); + + CopyRegion(source_pixels.data(), srcrect, destination_pixels.data(), dstrect); + memcpy(GetData(), destination_pixels.data(), destination_pixels.size()); } } diff --git a/Source/Core/VideoBackends/Software/TextureEncoder.cpp b/Source/Core/VideoBackends/Software/TextureEncoder.cpp index 52a709d04e..4d0997ebf5 100644 --- a/Source/Core/VideoBackends/Software/TextureEncoder.cpp +++ b/Source/Core/VideoBackends/Software/TextureEncoder.cpp @@ -1469,8 +1469,7 @@ void Encode(u8* dst, const EFBCopyParams& params, u32 native_width, u32 bytes_pe { if (params.copy_format == EFBCopyFormat::XFB) { - EfbInterface::EncodeXFB(reinterpret_cast(dst), native_width, - src_rect, params.y_scale); + EfbInterface::EncodeXFB(dst, native_width, src_rect, params.y_scale); } else {