From 84c53607ab362efbe6a0164ad5c5276cb1f09259 Mon Sep 17 00:00:00 2001 From: BlueCube3310 <53150244+BlueCube3310@users.noreply.github.com> Date: Thu, 9 Jan 2025 19:20:35 +0100 Subject: [PATCH] Etcpak: Sync with upstream --- modules/etcpak/image_compress_etcpak.cpp | 4 +- thirdparty/README.md | 2 +- thirdparty/etcpak/ProcessDxtc.cpp | 6 +- thirdparty/etcpak/ProcessDxtc.hpp | 6 +- thirdparty/etcpak/ProcessRGB.cpp | 121 -------------------- thirdparty/etcpak/ProcessRGB.hpp | 2 - thirdparty/etcpak/patches/bc7e_remove.patch | 52 +++++++++ 7 files changed, 61 insertions(+), 132 deletions(-) create mode 100644 thirdparty/etcpak/patches/bc7e_remove.patch diff --git a/modules/etcpak/image_compress_etcpak.cpp b/modules/etcpak/image_compress_etcpak.cpp index 14887ce469c..8492b2578a6 100644 --- a/modules/etcpak/image_compress_etcpak.cpp +++ b/modules/etcpak/image_compress_etcpak.cpp @@ -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: diff --git a/thirdparty/README.md b/thirdparty/README.md index dc7eee4a0d6..6694201fdc1 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -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: diff --git a/thirdparty/etcpak/ProcessDxtc.cpp b/thirdparty/etcpak/ProcessDxtc.cpp index 7f7f1a4be4f..e1bc6a5cb6b 100644 --- a/thirdparty/etcpak/ProcessDxtc.cpp +++ b/thirdparty/etcpak/ProcessDxtc.cpp @@ -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 ) @@ -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; @@ -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; diff --git a/thirdparty/etcpak/ProcessDxtc.hpp b/thirdparty/etcpak/ProcessDxtc.hpp index ea4cbaa094e..81454938727 100644 --- a/thirdparty/etcpak/ProcessDxtc.hpp +++ b/thirdparty/etcpak/ProcessDxtc.hpp @@ -4,9 +4,9 @@ #include #include -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 ); diff --git a/thirdparty/etcpak/ProcessRGB.cpp b/thirdparty/etcpak/ProcessRGB.cpp index e1487fa7676..1391bb9545b 100644 --- a/thirdparty/etcpak/ProcessRGB.cpp +++ b/thirdparty/etcpak/ProcessRGB.cpp @@ -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 -#include - void CompressEtc1Rgb( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width ) { int w = 0; diff --git a/thirdparty/etcpak/ProcessRGB.hpp b/thirdparty/etcpak/ProcessRGB.hpp index e3247d842b9..087118fb0c5 100644 --- a/thirdparty/etcpak/ProcessRGB.hpp +++ b/thirdparty/etcpak/ProcessRGB.hpp @@ -3,8 +3,6 @@ #include -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 ); diff --git a/thirdparty/etcpak/patches/bc7e_remove.patch b/thirdparty/etcpak/patches/bc7e_remove.patch new file mode 100644 index 00000000000..c72c36575d3 --- /dev/null +++ b/thirdparty/etcpak/patches/bc7e_remove.patch @@ -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