From 68941f6cbe78e9384b499bb18b17297c069d95c4 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Tue, 16 Jun 2015 19:43:15 +0600 Subject: [PATCH] Optimize frame buffer copy to RDRAM: read from pixel buffer one time per pixel. Old code does 4 reads from the pixel buffer per pixel. The optimization makes color buffer read circa 4 times faster. Thanks Lars Bishop for finding the sources of the problem and for suggested solution. --- src/FrameBuffer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp index 4e6d7504..4d1f465f 100644 --- a/src/FrameBuffer.cpp +++ b/src/FrameBuffer.cpp @@ -34,8 +34,11 @@ public: private: void _copyWhite(FrameBuffer * _pBuffer); - struct RGBA { - u8 r, g, b, a; + union RGBA { + struct { + u8 r, g, b, a; + }; + u32 raw; }; GLuint m_FBO; @@ -983,11 +986,12 @@ void FrameBufferToRDRAM::CopyToRDRAM(u32 _address) } } else { u16 *ptr_dst = (u16*)(RDRAM + _address); - RGBA * ptr_src = (RGBA*)pixelData; + u32 * ptr_src = (u32*)pixelData; + RGBA c; for (u32 y = 0; y < height; ++y) { for (u32 x = 0; x < VI.width; ++x) { - const RGBA & c = ptr_src[x + (height - y - 1)*VI.width]; + c.raw = ptr_src[x + (height - y - 1)*VI.width]; ptr_dst[(x + y*VI.width)^1] = ((c.r>>3)<<11) | ((c.g>>3)<<6) | ((c.b>>3)<<1) | (c.a == 0 ? 0 : 1); } }