Skip to content

Commit 3992eb0

Browse files
committed
Move RDO threshold logic to tables.
1 parent 2ab605d commit 3992eb0

2 files changed

Lines changed: 31 additions & 48 deletions

File tree

extra/rdotbl.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
//int a = 16, b = 44, s = 4;
6+
//int av = 12, bv = 6, cv = 3;
7+
8+
//int a = 32, b = 48, s = 16;
9+
//int av = 12, bv = 6, cv = 3;
10+
11+
int a = 48, b = 64, s = 16;
12+
int av = 48, bv = 32, cv = 24;
13+
14+
printf( "int TrTbl[] = { " );
15+
int first = 1;
16+
for( int i=0; i<256; i+=s )
17+
{
18+
if( first ) first = 0; else printf( ", " );
19+
if( i < a ) printf( "%i", av );
20+
else if( i < b ) printf( "%i", bv );
21+
else printf( "%i", cv );
22+
}
23+
printf( " };\n" );
24+
}

server/TracyTextureCompression.cpp

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ static tracy_force_inline int max3( int a, int b, int c )
8484
}
8585
}
8686

87+
static constexpr int TrTbl1[] = { 12, 12, 12, 12, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
88+
static constexpr int TrTbl2[] = { 12, 12, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
89+
static constexpr int TrTbl3[] = { 48, 48, 48, 32, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 };
90+
8791
void TextureCompression::Rdo( char* data, size_t blocks )
8892
{
8993
assert( blocks > 0 );
@@ -124,22 +128,7 @@ void TextureCompression::Rdo( char* data, size_t blocks )
124128

125129
const int maxChan1 = max3( r0-1, g0, b0-2 );
126130
const int maxDelta1 = max3( dr-1, dg, db-2 );
127-
const int tr1a = 16;
128-
const int tr1b = 45;
129-
int tr1;
130-
if( maxChan1 < tr1a )
131-
{
132-
tr1 = 12;
133-
}
134-
else if( maxChan1 < tr1b )
135-
{
136-
tr1 = 6;
137-
}
138-
else
139-
{
140-
tr1 = 3;
141-
}
142-
131+
const int tr1 = TrTbl1[maxChan1 / 4];
143132
if( maxDelta1 <= tr1 )
144133
{
145134
uint64_t blk =
@@ -152,45 +141,15 @@ void TextureCompression::Rdo( char* data, size_t blocks )
152141
{
153142
const int maxChan23 = max3( r0-2, g0, b0-5 );
154143
const int maxDelta23 = max3( dr-2, dg, db-5 );
155-
const int tr2a = 32;
156-
const int tr2b = 48;
157-
int tr2 = 0;
158-
if( maxChan23 < tr2a )
159-
{
160-
tr2 = 12;
161-
}
162-
else if( maxChan23 < tr2b )
163-
{
164-
tr2 = 6;
165-
}
166-
else
167-
{
168-
tr2 = 3;
169-
}
170-
144+
const int tr2 = TrTbl2[maxChan23 / 16];
171145
if( maxDelta23 <= tr2 )
172146
{
173147
idx &= 0x55555555;
174148
memcpy( data+4, &idx, 4 );
175149
}
176150
else
177151
{
178-
const int tr3a = 48;
179-
const int tr3b = 64;
180-
int tr3;
181-
if( maxChan23 < tr3a )
182-
{
183-
tr3 = 48;
184-
}
185-
else if( maxChan23 < tr3b )
186-
{
187-
tr3 = 32;
188-
}
189-
else
190-
{
191-
tr3 = 24;
192-
}
193-
152+
const int tr3 = TrTbl3[maxChan23 / 16];
194153
if( maxDelta23 <= tr3 )
195154
{
196155
uint64_t c = c1 | ( uint64_t( c0 ) << 16 );

0 commit comments

Comments
 (0)