Skip to content

Commit 6c0bd8e

Browse files
committed
Update etcpak to 2.0
1 parent 96be44c commit 6c0bd8e

File tree

8 files changed

+62
-133
lines changed

8 files changed

+62
-133
lines changed

modules/etcpak/SCsub

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ thirdparty_sources = [
1414
"Dither.cpp",
1515
"ProcessDxtc.cpp",
1616
"ProcessRGB.cpp",
17-
"Tables.cpp",
17+
"Tables.cpp"
1818
]
1919
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
2020

modules/etcpak/image_compress_etcpak.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ void _compress_etcpak(EtcpakType p_compress_type, Image *r_img) {
276276
break;
277277

278278
case EtcpakType::ETCPAK_TYPE_DXT1:
279-
CompressDxt1Dither(src_mip_read, dest_mip_write, blocks, dest_mip_w);
279+
CompressBc1Dither(src_mip_read, dest_mip_write, blocks, dest_mip_w);
280280
break;
281281

282282
case EtcpakType::ETCPAK_TYPE_DXT5:
283283
case EtcpakType::ETCPAK_TYPE_DXT5_RA_AS_RG:
284-
CompressDxt5(src_mip_read, dest_mip_write, blocks, dest_mip_w);
284+
CompressBc3(src_mip_read, dest_mip_write, blocks, dest_mip_w);
285285
break;
286286

287287
case EtcpakType::ETCPAK_TYPE_RGTC_R:

thirdparty/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ its functionality to IPv4 only.
218218
## etcpak
219219

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

224224
Files extracted from upstream source:

thirdparty/etcpak/ProcessDxtc.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ static etcpak_force_inline uint64_t ProcessAlpha_SSE( __m128i px0, __m128i px1,
807807
}
808808
#endif
809809

810-
void CompressDxt1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
810+
void CompressBc1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
811811
{
812812
#ifdef __AVX2__
813813
if( width%8 == 0 )
@@ -867,7 +867,7 @@ void CompressDxt1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t w
867867
}
868868
}
869869

870-
void CompressDxt1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
870+
void CompressBc1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
871871
{
872872
uint32_t buf[4*4];
873873
int i = 0;
@@ -899,7 +899,7 @@ void CompressDxt1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, si
899899
while( --blocks );
900900
}
901901

902-
void CompressDxt5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
902+
void CompressBc3( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
903903
{
904904
int i = 0;
905905
auto ptr = dst;

thirdparty/etcpak/ProcessDxtc.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <stddef.h>
55
#include <stdint.h>
66

7-
void CompressDxt1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
8-
void CompressDxt1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
9-
void CompressDxt5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
7+
void CompressBc1( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
8+
void CompressBc1Dither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
9+
void CompressBc3( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
1010

1111
void CompressBc4( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
1212
void CompressBc5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );

thirdparty/etcpak/ProcessRGB.cpp

-121
Original file line numberDiff line numberDiff line change
@@ -3858,127 +3858,6 @@ static etcpak_force_inline uint64_t ProcessAlpha_ETC2( const uint8_t* src )
38583858
#endif
38593859
}
38603860

3861-
void CompressEtc1Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
3862-
{
3863-
int w = 0;
3864-
uint32_t buf[4*4];
3865-
do
3866-
{
3867-
#ifdef __SSE4_1__
3868-
__m128 px0 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 0 ) ) );
3869-
__m128 px1 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 1 ) ) );
3870-
__m128 px2 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 2 ) ) );
3871-
__m128 px3 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 3 ) ) );
3872-
3873-
_MM_TRANSPOSE4_PS( px0, px1, px2, px3 );
3874-
3875-
__m128i c0 = _mm_castps_si128( px0 );
3876-
__m128i c1 = _mm_castps_si128( px1 );
3877-
__m128i c2 = _mm_castps_si128( px2 );
3878-
__m128i c3 = _mm_castps_si128( px3 );
3879-
3880-
__m128i mask = _mm_setr_epi32( 0x03030303, 0x07070707, 0x0b0b0b0b, 0x0f0f0f0f );
3881-
__m128i p0 = _mm_shuffle_epi8( c0, mask );
3882-
__m128i p1 = _mm_shuffle_epi8( c1, mask );
3883-
__m128i p2 = _mm_shuffle_epi8( c2, mask );
3884-
__m128i p3 = _mm_shuffle_epi8( c3, mask );
3885-
3886-
_mm_store_si128( (__m128i*)(buf + 0), p0 );
3887-
_mm_store_si128( (__m128i*)(buf + 4), p1 );
3888-
_mm_store_si128( (__m128i*)(buf + 8), p2 );
3889-
_mm_store_si128( (__m128i*)(buf + 12), p3 );
3890-
3891-
src += 4;
3892-
#else
3893-
auto ptr = buf;
3894-
for( int x=0; x<4; x++ )
3895-
{
3896-
unsigned int a = *src >> 24;
3897-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3898-
src += width;
3899-
a = *src >> 24;
3900-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3901-
src += width;
3902-
a = *src >> 24;
3903-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3904-
src += width;
3905-
a = *src >> 24;
3906-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3907-
src -= width * 3 - 1;
3908-
}
3909-
#endif
3910-
if( ++w == width/4 )
3911-
{
3912-
src += width * 3;
3913-
w = 0;
3914-
}
3915-
*dst++ = ProcessRGB( (uint8_t*)buf );
3916-
}
3917-
while( --blocks );
3918-
}
3919-
3920-
void CompressEtc2Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, bool useHeuristics )
3921-
{
3922-
int w = 0;
3923-
uint32_t buf[4*4];
3924-
do
3925-
{
3926-
#ifdef __SSE4_1__
3927-
__m128 px0 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 0 ) ) );
3928-
__m128 px1 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 1 ) ) );
3929-
__m128 px2 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 2 ) ) );
3930-
__m128 px3 = _mm_castsi128_ps( _mm_loadu_si128( (__m128i*)( src + width * 3 ) ) );
3931-
3932-
_MM_TRANSPOSE4_PS( px0, px1, px2, px3 );
3933-
3934-
__m128i c0 = _mm_castps_si128( px0 );
3935-
__m128i c1 = _mm_castps_si128( px1 );
3936-
__m128i c2 = _mm_castps_si128( px2 );
3937-
__m128i c3 = _mm_castps_si128( px3 );
3938-
3939-
__m128i mask = _mm_setr_epi32( 0x03030303, 0x07070707, 0x0b0b0b0b, 0x0f0f0f0f );
3940-
__m128i p0 = _mm_shuffle_epi8( c0, mask );
3941-
__m128i p1 = _mm_shuffle_epi8( c1, mask );
3942-
__m128i p2 = _mm_shuffle_epi8( c2, mask );
3943-
__m128i p3 = _mm_shuffle_epi8( c3, mask );
3944-
3945-
_mm_store_si128( (__m128i*)(buf + 0), p0 );
3946-
_mm_store_si128( (__m128i*)(buf + 4), p1 );
3947-
_mm_store_si128( (__m128i*)(buf + 8), p2 );
3948-
_mm_store_si128( (__m128i*)(buf + 12), p3 );
3949-
3950-
src += 4;
3951-
#else
3952-
auto ptr = buf;
3953-
for( int x=0; x<4; x++ )
3954-
{
3955-
unsigned int a = *src >> 24;
3956-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3957-
src += width;
3958-
a = *src >> 24;
3959-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3960-
src += width;
3961-
a = *src >> 24;
3962-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3963-
src += width;
3964-
a = *src >> 24;
3965-
*ptr++ = a | ( a << 8 ) | ( a << 16 );
3966-
src -= width * 3 - 1;
3967-
}
3968-
#endif
3969-
if( ++w == width/4 )
3970-
{
3971-
src += width * 3;
3972-
w = 0;
3973-
}
3974-
*dst++ = ProcessRGB_ETC2( (uint8_t*)buf, useHeuristics );
3975-
}
3976-
while( --blocks );
3977-
}
3978-
3979-
#include <chrono>
3980-
#include <thread>
3981-
39823861
void CompressEtc1Rgb( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width )
39833862
{
39843863
int w = 0;

thirdparty/etcpak/ProcessRGB.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#include <stdint.h>
55

6-
void CompressEtc1Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
7-
void CompressEtc2Alpha( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, bool useHeuristics );
86
void CompressEtc1Rgb( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
97
void CompressEtc1RgbDither( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
108
void CompressEtc2Rgb( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, bool useHeuristics );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
diff --git a/thirdparty/etcpak/ProcessDxtc.cpp b/thirdparty/etcpak/ProcessDxtc.cpp
2+
index 5373b75cdc..e1bc6a5cb6 100644
3+
--- a/thirdparty/etcpak/ProcessDxtc.cpp
4+
+++ b/thirdparty/etcpak/ProcessDxtc.cpp
5+
@@ -1,4 +1,3 @@
6+
-#include "bc7enc.h"
7+
#include "Dither.hpp"
8+
#include "ForceInline.hpp"
9+
#include "ProcessDxtc.hpp"
10+
@@ -1085,29 +1084,3 @@ void CompressBc5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t wi
11+
#endif
12+
} while( --blocks );
13+
}
14+
-
15+
-void CompressBc7( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, const bc7enc_compress_block_params* params )
16+
-{
17+
- int i = 0;
18+
- auto ptr = dst;
19+
- do
20+
- {
21+
- uint32_t rgba[4*4];
22+
-
23+
- auto tmp = (char*)rgba;
24+
- memcpy( tmp, src + width * 0, 4*4 );
25+
- memcpy( tmp + 4*4, src + width * 1, 4*4 );
26+
- memcpy( tmp + 8*4, src + width * 2, 4*4 );
27+
- memcpy( tmp + 12*4, src + width * 3, 4*4 );
28+
- src += 4;
29+
- if( ++i == width/4 )
30+
- {
31+
- src += width * 3;
32+
- i = 0;
33+
- }
34+
-
35+
- bc7enc_compress_block( ptr, rgba, params );
36+
- ptr += 2;
37+
- }
38+
- while( --blocks );
39+
-}
40+
diff --git a/thirdparty/etcpak/ProcessDxtc.hpp b/thirdparty/etcpak/ProcessDxtc.hpp
41+
index 7655bb33be..8145493872 100644
42+
--- a/thirdparty/etcpak/ProcessDxtc.hpp
43+
+++ b/thirdparty/etcpak/ProcessDxtc.hpp
44+
@@ -11,8 +11,4 @@ void CompressBc3( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t wi
45+
void CompressBc4( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
46+
void CompressBc5( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width );
47+
48+
-struct bc7enc_compress_block_params;
49+
-
50+
-void CompressBc7( const uint32_t* src, uint64_t* dst, uint32_t blocks, size_t width, const bc7enc_compress_block_params* params );
51+
-
52+
#endif

0 commit comments

Comments
 (0)