Skip to content

Commit

Permalink
Merge pull request #101362 from BlueCube3310/etcpak-v200
Browse files Browse the repository at this point in the history
etcpak: Sync with upstream 2.0
  • Loading branch information
akien-mga committed Jan 9, 2025
2 parents 1730070 + 84c5360 commit a024393
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 132 deletions.
4 changes: 2 additions & 2 deletions modules/etcpak/image_compress_etcpak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ void _compress_etcpak(EtcpakType p_compress_type, Image *r_img) {
break;

case EtcpakType::ETCPAK_TYPE_DXT1:
CompressDxt1Dither(src_mip_read, dest_mip_write, blocks, dest_mip_w);
CompressBc1Dither(src_mip_read, dest_mip_write, blocks, dest_mip_w);
break;

case EtcpakType::ETCPAK_TYPE_DXT5:
case EtcpakType::ETCPAK_TYPE_DXT5_RA_AS_RG:
CompressDxt5(src_mip_read, dest_mip_write, blocks, dest_mip_w);
CompressBc3(src_mip_read, dest_mip_write, blocks, dest_mip_w);
break;

case EtcpakType::ETCPAK_TYPE_RGTC_R:
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ its functionality to IPv4 only.
## etcpak

- Upstream: https://github.com/wolfpld/etcpak
- Version: git (5380688660a3801aec4b25483366027fe0442d7b, 2024)
- Version: 2.0 (a43d6925bee49277945cf3e311e4a022ae0c2073, 2024)
- License: BSD-3-Clause

Files extracted from upstream source:
Expand Down
6 changes: 3 additions & 3 deletions thirdparty/etcpak/ProcessDxtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ static etcpak_force_inline uint64_t ProcessAlpha_SSE( __m128i px0, __m128i px1,
}
#endif

void CompressDxt1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
void CompressBc1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
{
#ifdef __AVX2__
if( width%8 == 0 )
Expand Down Expand Up @@ -867,7 +867,7 @@ void CompressDxt1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t w
}
}

void CompressDxt1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
void CompressBc1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
{
uint32_t buf[4*4];
int i = 0;
Expand Down Expand Up @@ -899,7 +899,7 @@ void CompressDxt1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, si
while( --blocks );
}

void CompressDxt5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
void CompressBc3( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
{
int i = 0;
auto ptr = dst;
Expand Down
6 changes: 3 additions & 3 deletions thirdparty/etcpak/ProcessDxtc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <stddef.h>
#include <stdint.h>

void CompressDxt1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressDxt1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressDxt5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressBc1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressBc1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressBc3( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );

void CompressBc4( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressBc5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
Expand Down
121 changes: 0 additions & 121 deletions thirdparty/etcpak/ProcessRGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3858,127 +3858,6 @@ static etcpak_force_inline uint64_t ProcessAlpha_ETC2( const uint8_t* src )
#endif
}

void CompressEtc1Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
{
int w = 0;
uint32_t buf[4*4];
do
{
#ifdef __SSE4_1__
__m128 px0 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 0 ) ) );
__m128 px1 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 1 ) ) );
__m128 px2 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 2 ) ) );
__m128 px3 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 3 ) ) );

_MM_TRANSPOSE4_PS( px0, px1, px2, px3 );

__m128i c0 = _mm_castps_si128( px0 );
__m128i c1 = _mm_castps_si128( px1 );
__m128i c2 = _mm_castps_si128( px2 );
__m128i c3 = _mm_castps_si128( px3 );

__m128i mask = _mm_setr_epi32( 0x03030303, 0x07070707, 0x0b0b0b0b, 0x0f0f0f0f );
__m128i p0 = _mm_shuffle_epi8( c0, mask );
__m128i p1 = _mm_shuffle_epi8( c1, mask );
__m128i p2 = _mm_shuffle_epi8( c2, mask );
__m128i p3 = _mm_shuffle_epi8( c3, mask );

_mm_store_si128( (__m128i*)(buf + 0), p0 );
_mm_store_si128( (__m128i*)(buf + 4), p1 );
_mm_store_si128( (__m128i*)(buf + 8), p2 );
_mm_store_si128( (__m128i*)(buf + 12), p3 );

src += 4;
#else
auto ptr = buf;
for( int x=0; x<4; x++ )
{
unsigned int a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src += width;
a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src += width;
a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src += width;
a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src -= width * 3 - 1;
}
#endif
if( ++w == width/4 )
{
src += width * 3;
w = 0;
}
*dst++ = ProcessRGB( (uint8_t*)buf );
}
while( --blocks );
}

void CompressEtc2Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, bool useHeuristics )
{
int w = 0;
uint32_t buf[4*4];
do
{
#ifdef __SSE4_1__
__m128 px0 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 0 ) ) );
__m128 px1 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 1 ) ) );
__m128 px2 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 2 ) ) );
__m128 px3 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 3 ) ) );

_MM_TRANSPOSE4_PS( px0, px1, px2, px3 );

__m128i c0 = _mm_castps_si128( px0 );
__m128i c1 = _mm_castps_si128( px1 );
__m128i c2 = _mm_castps_si128( px2 );
__m128i c3 = _mm_castps_si128( px3 );

__m128i mask = _mm_setr_epi32( 0x03030303, 0x07070707, 0x0b0b0b0b, 0x0f0f0f0f );
__m128i p0 = _mm_shuffle_epi8( c0, mask );
__m128i p1 = _mm_shuffle_epi8( c1, mask );
__m128i p2 = _mm_shuffle_epi8( c2, mask );
__m128i p3 = _mm_shuffle_epi8( c3, mask );

_mm_store_si128( (__m128i*)(buf + 0), p0 );
_mm_store_si128( (__m128i*)(buf + 4), p1 );
_mm_store_si128( (__m128i*)(buf + 8), p2 );
_mm_store_si128( (__m128i*)(buf + 12), p3 );

src += 4;
#else
auto ptr = buf;
for( int x=0; x<4; x++ )
{
unsigned int a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src += width;
a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src += width;
a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src += width;
a = *src >> 24;
*ptr++ = a | ( a << 8 ) | ( a << 16 );
src -= width * 3 - 1;
}
#endif
if( ++w == width/4 )
{
src += width * 3;
w = 0;
}
*dst++ = ProcessRGB_ETC2( (uint8_t*)buf, useHeuristics );
}
while( --blocks );
}

#include <chrono>
#include <thread>

void CompressEtc1Rgb( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
{
int w = 0;
Expand Down
2 changes: 0 additions & 2 deletions thirdparty/etcpak/ProcessRGB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include <stdint.h>

void CompressEtc1Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressEtc2Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, bool useHeuristics );
void CompressEtc1Rgb( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressEtc1RgbDither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressEtc2Rgb( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, bool useHeuristics );
Expand Down
52 changes: 52 additions & 0 deletions thirdparty/etcpak/patches/bc7e_remove.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
diff --git a/thirdparty/etcpak/ProcessDxtc.cpp b/thirdparty/etcpak/ProcessDxtc.cpp
index 5373b75cdc..e1bc6a5cb6 100644
--- a/thirdparty/etcpak/ProcessDxtc.cpp
+++ b/thirdparty/etcpak/ProcessDxtc.cpp
@@ -1,4 +1,3 @@
-#include "bc7enc.h"
#include "Dither.hpp"
#include "ForceInline.hpp"
#include "ProcessDxtc.hpp"
@@ -1085,29 +1084,3 @@ void CompressBc5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t wi
#endif
} while( --blocks );
}
-
-void CompressBc7( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, const bc7enc_compress_block_params* params )
-{
- int i = 0;
- auto ptr = dst;
- do
- {
- uint32_t rgba[4*4];
-
- auto tmp = (char*)rgba;
- memcpy( tmp, src + width * 0, 4*4 );
- memcpy( tmp + 4*4, src + width * 1, 4*4 );
- memcpy( tmp + 8*4, src + width * 2, 4*4 );
- memcpy( tmp + 12*4, src + width * 3, 4*4 );
- src += 4;
- if( ++i == width/4 )
- {
- src += width * 3;
- i = 0;
- }
-
- bc7enc_compress_block( ptr, rgba, params );
- ptr += 2;
- }
- while( --blocks );
-}
diff --git a/thirdparty/etcpak/ProcessDxtc.hpp b/thirdparty/etcpak/ProcessDxtc.hpp
index 7655bb33be..8145493872 100644
--- a/thirdparty/etcpak/ProcessDxtc.hpp
+++ b/thirdparty/etcpak/ProcessDxtc.hpp
@@ -11,8 +11,4 @@ void CompressBc3( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t wi
void CompressBc4( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
void CompressBc5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );

-struct bc7enc_compress_block_params;
-
-void CompressBc7( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, const bc7enc_compress_block_params* params );
-
#endif

0 comments on commit a024393

Please sign in to comment.