Software Backend: Remove reinterpret_cast which violates the strict aliasing rule

This commit is contained in:
iwubcode 2017-10-24 00:44:14 -05:00
parent 332af8aa49
commit bf7db3f888
4 changed files with 22 additions and 12 deletions

View file

@ -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<int>(static_cast<float>(source_rect.bottom) * y_scale)});
auto dest_rect = EFBRectangle{source_rect.left, source_rect.top, source_rect.right,
static_cast<int>(static_cast<float>(source_rect.bottom) * y_scale)};
const std::size_t destination_size = dest_rect.GetWidth() * dest_rect.GetHeight() * 2;
static std::vector<yuv422_packed> 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)

View file

@ -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)

View file

@ -44,8 +44,15 @@ void SWTexture::CopyRectangleFromTexture(const AbstractTexture* source,
}
else
{
CopyRegion(reinterpret_cast<const Pixel*>(software_source_texture->GetData()), srcrect,
reinterpret_cast<Pixel*>(GetData()), dstrect);
std::vector<Pixel> source_pixels;
source_pixels.resize(srcrect.GetHeight() * srcrect.GetWidth() * 4);
memcpy(source_pixels.data(), software_source_texture->GetData(), source_pixels.size());
std::vector<Pixel> 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());
}
}

View file

@ -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<EfbInterface::yuv422_packed*>(dst), native_width,
src_rect, params.y_scale);
EfbInterface::EncodeXFB(dst, native_width, src_rect, params.y_scale);
}
else
{