restore previous twiddle table for non-square tex

This commit is contained in:
Flyinghead 2020-02-07 19:13:23 +01:00
parent dd80114bf7
commit 391cbdc044
2 changed files with 73 additions and 28 deletions

View File

@ -23,23 +23,60 @@ u32 palette32_ram[1024];
u32 pal_hash_256[4];
u32 pal_hash_16[64];
u32 detwiddle[1024];
u32 detwiddle[2][10][1024];
//input : address in the yyyyyxxxxx format
//output : address in the xyxyxyxy format
//U : x resolution , V : y resolution
//twiddle works on 64b words
void BuildTwiddleTable()
static u32 twiddle_slow(u32 x,u32 y,u32 x_sz,u32 y_sz)
{
for (u32 j = 0; j < ARRAY_SIZE(detwiddle); j++)
{
u32 detwiddled = 0;
for (int i = 0; i < 10; i++)
{
u32 shift = 1 << i;
detwiddled |= ((j & shift) << i);
}
detwiddle[j] = detwiddled;
}
u32 rv=0;//low 2 bits are directly passed -> needs some misc stuff to work.However
//Pvr internally maps the 64b banks "as if" they were twiddled :p
u32 sh=0;
x_sz>>=1;
y_sz>>=1;
while(x_sz!=0 || y_sz!=0)
{
if (y_sz)
{
u32 temp=y&1;
rv|=temp<<sh;
y_sz>>=1;
y>>=1;
sh++;
}
if (x_sz)
{
u32 temp=x&1;
rv|=temp<<sh;
x_sz>>=1;
x>>=1;
sh++;
}
}
return rv;
}
static OnLoad btt(&BuildTwiddleTable);
static void BuildTwiddleTables()
{
for (u32 s = 0; s < 10; s++)
{
u32 x_sz = 1024;
u32 y_sz = 2 << s;
for (u32 i = 0; i < x_sz; i++)
{
detwiddle[0][s][i] = twiddle_slow(i, 0, x_sz, y_sz);
detwiddle[1][s][i] = twiddle_slow(0, i, y_sz, x_sz);
}
}
}
static OnLoad btt(&BuildTwiddleTables);
void palette_update()
{
@ -1099,3 +1136,4 @@ void dump_screenshot(u8 *buffer, u32 width, u32 height, bool alpha, u32 rowPitch
}
#endif

View File

@ -17,7 +17,7 @@ extern u32 pal_hash_256[4];
extern u32 pal_hash_16[64];
extern bool KillTex;
extern u32 detwiddle[1024];
extern u32 detwiddle[2][10][1024];
template<class pixel_type>
class PixelBuffer
@ -168,6 +168,8 @@ __forceinline u32 YUV422(s32 Y,s32 Yu,s32 Yv)
return PixelPacker::packRGB(clamp(0,255,R),clamp(0,255,G),clamp(0,255,B));
}
#define twop(x,y,bcx,bcy) (detwiddle[0][bcy][x]+detwiddle[1][bcx][y])
//pixel packers !
struct pp_565
{
@ -517,23 +519,24 @@ void texture_PL(PixelBuffer<pixel_type>* pb,u8* p_in,u32 Width,u32 Height)
}
}
static inline u32 get_tw_texel_position(u32 x, u32 y)
{
return detwiddle[y] | detwiddle[x] << 1;
}
template<class PixelConvertor, class pixel_type>
void texture_TW(PixelBuffer<pixel_type>* pb,u8* p_in,u32 Width,u32 Height)
{
pb->amove(0,0);
const u32 divider = PixelConvertor::xpp * PixelConvertor::ypp;
const u32 divider=PixelConvertor::xpp*PixelConvertor::ypp;
for (u32 y = 0; y < Height; y += PixelConvertor::ypp)
unsigned long bcx_,bcy_;
bcx_=bitscanrev(Width);
bcy_=bitscanrev(Height);
const u32 bcx=bcx_-1;
const u32 bcy=bcy_-1;
for (u32 y=0;y<Height;y+=PixelConvertor::ypp)
{
for (u32 x = 0; x < Width; x += PixelConvertor::xpp)
for (u32 x=0;x<Width;x+=PixelConvertor::xpp)
{
u8* p = &p_in[get_tw_texel_position(x, y) / divider * 8];
u8* p = &p_in[(twop(x,y,bcx,bcy)/divider)<<3];
PixelConvertor::Convert(pb,p);
pb->rmovex(PixelConvertor::xpp);
@ -548,14 +551,18 @@ void texture_VQ(PixelBuffer<pixel_type>* pb,u8* p_in,u32 Width,u32 Height)
p_in+=256*4*2;
pb->amove(0,0);
Height /= PixelConvertor::ypp;
Width /= PixelConvertor::xpp;
const u32 divider=PixelConvertor::xpp*PixelConvertor::ypp;
unsigned long bcx_,bcy_;
bcx_=bitscanrev(Width);
bcy_=bitscanrev(Height);
const u32 bcx=bcx_-1;
const u32 bcy=bcy_-1;
for (u32 y = 0; y < Height; y++)
for (u32 y=0;y<Height;y+=PixelConvertor::ypp)
{
for (u32 x = 0; x < Width; x++)
for (u32 x=0;x<Width;x+=PixelConvertor::xpp)
{
u8 p = p_in[get_tw_texel_position(x, y)];
u8 p = p_in[twop(x,y,bcx,bcy)/divider];
PixelConvertor::Convert(pb,&vq_codebook[p*8]);
pb->rmovex(PixelConvertor::xpp);