From 6b0c2c6fd828d5f396d9f01eea4ea94666b716c3 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 31 Aug 2023 20:52:53 -0500 Subject: [PATCH] hwr2: fix unaligned software copies --- src/hwr2/software_screen_renderer.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/hwr2/software_screen_renderer.cpp b/src/hwr2/software_screen_renderer.cpp index 863efb9a5..5d1d8c843 100644 --- a/src/hwr2/software_screen_renderer.cpp +++ b/src/hwr2/software_screen_renderer.cpp @@ -50,21 +50,12 @@ void SoftwareScreenRenderer::draw(Rhi& rhi, Handle ctx) // If the screen width won't fit the unpack alignment, we need to copy the screen. if (width_ % kPixelRowUnpackAlignment > 0) { - std::size_t padded_width = (width_ + (kPixelRowUnpackAlignment - 1)) & !kPixelRowUnpackAlignment; + std::size_t padded_width = (width_ + (kPixelRowUnpackAlignment - 1)) & ~(kPixelRowUnpackAlignment - 1); copy_buffer_.clear(); - copy_buffer_.reserve(padded_width * height_); + copy_buffer_.resize(padded_width * height_, 0); for (std::size_t y = 0; y < height_; y++) { - for (std::size_t x = 0; x < width_; x++) - { - copy_buffer_.push_back(vid.buffer[(width_ * y) + x]); - } - - // Padding to unpack alignment - for (std::size_t i = 0; i < padded_width - width_; i++) - { - copy_buffer_.push_back(0); - } + std::copy(&vid.buffer[width_ * y], &vid.buffer[width_ * (y + 1)], ©_buffer_[padded_width * y]); } }