Improve memory access patterns in RDO compression.

This commit is contained in:
Bartosz Taudul 2020-06-11 13:36:17 +02:00
parent 2723144678
commit 2608ceca05

View File

@ -77,17 +77,18 @@ void TextureCompression::Rdo( char* data, size_t blocks )
assert( blocks > 0 ); assert( blocks > 0 );
do do
{ {
uint32_t idx; uint64_t blk;
memcpy( &idx, data+4, 4 ); memcpy( &blk, data, 8 );
uint32_t idx = blk >> 32;
if( idx == 0x55555555 ) if( idx == 0x55555555 )
{ {
data += 8; data += 8;
continue; continue;
} }
uint16_t c0, c1; uint16_t c0 = blk & 0xFFFF;
memcpy( &c0, data, 2 ); uint16_t c1 = ( blk >> 16 ) & 0xFFFF;
memcpy( &c1, data+2, 2 );
const int r0b = c0 & 0xF800; const int r0b = c0 & 0xF800;
const int g0b = c0 & 0x07E0; const int g0b = c0 & 0x07E0;
@ -180,12 +181,9 @@ void TextureCompression::Rdo( char* data, size_t blocks )
if( maxDelta23 <= tr3 ) if( maxDelta23 <= tr3 )
{ {
memcpy( data, &c1, 2 ); uint64_t c = c1 | ( uint64_t( c0 ) << 16 );
memcpy( data+2, &c0, 2 ); for( int k=0; k<4; k++ ) c |= uint64_t( Dxtc4To3Table[(idx >> (k*8)) & 0xFF] ) << ( 32 + k*8 );
uint8_t tmp[4]; memcpy( data, &c, 8 );
memcpy( tmp, &idx, 4 );
for( int k=0; k<4; k++ ) tmp[k] = Dxtc4To3Table[tmp[k]];
memcpy( data+4, tmp, 4 );
} }
} }
} }