Search
lxdream.org :: lxdream :: r311:5be79c6b4367
lxdream 0.9.1
released Jun 29
Download Now
changeset311:5be79c6b4367
parent310:00cd8897ad5e
child312:2c34bdc36cbd
authornkeynes
dateMon Jan 22 21:26:39 2007 +0000 (12 years ago)
Refactor to use the detwiddle vram methods
src/pvr2/texcache.c
1.1 --- a/src/pvr2/texcache.c Mon Jan 22 11:45:37 2007 +0000
1.2 +++ b/src/pvr2/texcache.c Mon Jan 22 21:26:39 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: texcache.c,v 1.15 2007-01-17 09:21:55 nkeynes Exp $
1.6 + * $Id: texcache.c,v 1.16 2007-01-22 21:26:39 nkeynes Exp $
1.7 *
1.8 * Texture cache. Responsible for maintaining a working set of OpenGL
1.9 * textures.
1.10 @@ -179,72 +179,28 @@
1.11 return slot;
1.12 }
1.13
1.14 -static void detwiddle_pal8_to_32(int x1, int y1, int size, int totsize,
1.15 - char **in, uint32_t *out, uint32_t *pal) {
1.16 - if (size == 1) {
1.17 - out[y1 * totsize + x1] = pal[**in];
1.18 - (*in)++;
1.19 - } else {
1.20 - int ns = size>>1;
1.21 - detwiddle_pal8_to_32(x1, y1, ns, totsize, in, out, pal);
1.22 - detwiddle_pal8_to_32(x1, y1+ns, ns, totsize, in, out, pal);
1.23 - detwiddle_pal8_to_32(x1+ns, y1, ns, totsize, in, out, pal);
1.24 - detwiddle_pal8_to_32(x1+ns, y1+ns, ns, totsize, in, out, pal);
1.25 +static void decode_pal8_to_32( uint32_t *out, uint8_t *in, int inbytes, uint32_t *pal )
1.26 +{
1.27 + int i;
1.28 + for( i=0; i<inbytes; i++ ) {
1.29 + *out++ = pal[*in++];
1.30 }
1.31 }
1.32
1.33 -static void detwiddle_pal8_to_16(int x1, int y1, int size, int totsize,
1.34 - char **in, uint16_t *out, uint16_t *pal) {
1.35 - if (size == 1) {
1.36 - out[y1 * totsize + x1] = pal[**in];
1.37 - (*in)++;
1.38 - } else {
1.39 - int ns = size>>1;
1.40 - detwiddle_pal8_to_16(x1, y1, ns, totsize, in, out, pal);
1.41 - detwiddle_pal8_to_16(x1, y1+ns, ns, totsize, in, out, pal);
1.42 - detwiddle_pal8_to_16(x1+ns, y1, ns, totsize, in, out, pal);
1.43 - detwiddle_pal8_to_16(x1+ns, y1+ns, ns, totsize, in, out, pal);
1.44 +static void decode_pal8_to_16( uint16_t *out, uint8_t *in, int inbytes, uint16_t *pal )
1.45 +{
1.46 + int i;
1.47 + for( i=0; i<inbytes; i++ ) {
1.48 + *out++ = pal[*in++];
1.49 }
1.50 }
1.51
1.52 -static void detwiddle_16_to_16(int x1, int y1, int size, int totsize,
1.53 - uint16_t **in, uint16_t *out ) {
1.54 - if (size == 1) {
1.55 - out[y1 * totsize + x1] = **in;
1.56 - (*in)++;
1.57 - } else {
1.58 - int ns = size>>1;
1.59 - detwiddle_16_to_16(x1, y1, ns, totsize, in, out);
1.60 - detwiddle_16_to_16(x1, y1+ns, ns, totsize, in, out);
1.61 - detwiddle_16_to_16(x1+ns, y1, ns, totsize, in, out);
1.62 - detwiddle_16_to_16(x1+ns, y1+ns, ns, totsize, in, out);
1.63 - }
1.64 -}
1.65 -
1.66 #define VQ_CODEBOOK_SIZE 2048 /* 256 entries * 4 pixels per quad * 2 byte pixels */
1.67
1.68 struct vq_codebook {
1.69 uint16_t quad[256][4];
1.70 };
1.71
1.72 -static void detwiddle_vq_to_16(int x1, int y1, int size, int totsize,
1.73 - uint8_t **in, uint16_t *out, struct vq_codebook *codebook ) {
1.74 - if( size == 2 ) {
1.75 - uint8_t code = **in;
1.76 - (*in)++;
1.77 - out[y1 * totsize + x1] = codebook->quad[code][0];
1.78 - out[y1 * totsize + x1 + 1] = codebook->quad[code][1];
1.79 - out[(y1+1) * totsize + x1] = codebook->quad[code][2];
1.80 - out[(y1+1) * totsize + x1 + 1] = codebook->quad[code][3];
1.81 - } else {
1.82 - int ns = size>>1;
1.83 - detwiddle_vq_to_16(x1, y1, ns, totsize, in, out, codebook);
1.84 - detwiddle_vq_to_16(x1, y1+ns, ns, totsize, in, out, codebook);
1.85 - detwiddle_vq_to_16(x1+ns, y1, ns, totsize, in, out, codebook);
1.86 - detwiddle_vq_to_16(x1+ns, y1+ns, ns, totsize, in, out, codebook);
1.87 - }
1.88 -}
1.89 -
1.90 static void vq_get_codebook( struct vq_codebook *codebook,
1.91 uint16_t *input )
1.92 {
1.93 @@ -259,23 +215,18 @@
1.94 }
1.95 }
1.96
1.97 -
1.98 -static void vq_decode( int width, int height, char *input, uint16_t *output,
1.99 - struct vq_codebook *codebook, int twiddled ) {
1.100 +static void vq_decode( uint16_t *output, char *input, int width, int height,
1.101 + struct vq_codebook *codebook ) {
1.102 int i,j;
1.103
1.104 uint8_t *c = (uint8_t *)input;
1.105 - if( twiddled ) {
1.106 - detwiddle_vq_to_16( 0, 0, width, width, &c, output, codebook );
1.107 - } else {
1.108 - for( j=0; j<height; j+=2 ) {
1.109 - for( i=0; i<width; i+=2 ) {
1.110 - uint8_t code = *c;
1.111 - output[i + j*width] = codebook->quad[code][0];
1.112 - output[i + 1 + j*width] = codebook->quad[code][1];
1.113 - output[i + (j+1)*width] = codebook->quad[code][2];
1.114 - output[i + 1 + (j+1)*width] = codebook->quad[code][3];
1.115 - }
1.116 + for( j=0; j<height; j+=2 ) {
1.117 + for( i=0; i<width; i+=2 ) {
1.118 + uint8_t code = *c;
1.119 + output[i + j*width] = codebook->quad[code][0];
1.120 + output[i + 1 + j*width] = codebook->quad[code][1];
1.121 + output[i + (j+1)*width] = codebook->quad[code][2];
1.122 + output[i + 1 + (j+1)*width] = codebook->quad[code][3];
1.123 }
1.124 }
1.125 }
1.126 @@ -295,12 +246,12 @@
1.127
1.128
1.129 /**
1.130 - * Convert non-twiddled YUV texture data into RGB32 data - most GL implementations don't
1.131 + * Convert raster YUV texture data into RGB32 data - most GL implementations don't
1.132 * directly support this format unfortunately. The input data is formatted as
1.133 * 32 bits = 2 horizontal pixels, UYVY. This is currently done rather inefficiently
1.134 * in floating point.
1.135 */
1.136 -static void yuv_decode( int width, int height, uint32_t *input, uint32_t *output )
1.137 +static void yuv_decode( uint32_t *output, uint32_t *input, int width, int height )
1.138 {
1.139 int x, y;
1.140 uint32_t *p = input;
1.141 @@ -398,7 +349,7 @@
1.142 if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {
1.143 char tmp[(width*height)<<1];
1.144 pvr2_vram64_read_stride( tmp, width<<1, texture_addr, stride<<1, height );
1.145 - yuv_decode(width, height, (uint32_t *)tmp, (uint32_t *)data );
1.146 + yuv_decode( (uint32_t *)data, (uint32_t *)tmp, width, height );
1.147 } else {
1.148 pvr2_vram64_read_stride( data, width<<bpp_shift, texture_addr, stride<<bpp_shift, height );
1.149 }
1.150 @@ -411,10 +362,10 @@
1.151 int level=0, last_level = 0, mip_width = width, mip_height = height, mip_bytes;
1.152 if( PVR2_TEX_IS_MIPMAPPED(mode) ) {
1.153 int i;
1.154 - for( i=0; 1<<(i+1) < width; i++ );
1.155 + for( i=0; 1<<i < width; i++ );
1.156 last_level = i;
1.157 - mip_width = width >> i;
1.158 - mip_height= height >> i;
1.159 + mip_width = 1;
1.160 + mip_height= 1;
1.161 filter = GL_LINEAR_MIPMAP_LINEAR;
1.162 }
1.163 mip_bytes = (mip_width * mip_height) << bpp_shift;
1.164 @@ -435,42 +386,32 @@
1.165 char *palette = mmio_region_PVR2PAL.mem + (bank * (256 << bpp_shift));
1.166 char tmp[inputlength];
1.167 char *p = tmp;
1.168 - pvr2_vram64_read( tmp, texture_addr, inputlength );
1.169 + pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width, mip_height );
1.170 if( bpp_shift == 2 ) {
1.171 - detwiddle_pal8_to_32( 0, 0, mip_width, mip_width, &p,
1.172 - (uint32_t *)data, (uint32_t *)palette );
1.173 + decode_pal8_to_32( (uint32_t *)data, tmp, inputlength, (uint32_t*)palette );
1.174 } else {
1.175 - detwiddle_pal8_to_16( 0, 0, mip_width, mip_width, &p,
1.176 - (uint16_t *)data, (uint16_t *)palette );
1.177 + decode_pal8_to_16( (uint16_t *)data, tmp, inputlength, (uint16_t*)palette );
1.178 }
1.179 } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {
1.180 int inputlength = ((mip_width*mip_height)<<1);
1.181 char tmp[inputlength];
1.182 pvr2_vram64_read( tmp, texture_addr, inputlength );
1.183 - yuv_decode( mip_width, mip_height, (uint32_t *)tmp, (uint32_t *)data );
1.184 + yuv_decode( (uint32_t *)data, (uint32_t *)tmp, mip_width, mip_height );
1.185 } else if( PVR2_TEX_IS_COMPRESSED(mode) ) {
1.186 int inputlength = ((mip_width*mip_height) >> 2);
1.187 char tmp[inputlength];
1.188 - pvr2_vram64_read( tmp, texture_addr, inputlength );
1.189 - vq_decode( mip_width, mip_height, tmp, (uint16_t *)data, &codebook,
1.190 - PVR2_TEX_IS_TWIDDLED(mode) );
1.191 + if( PVR2_TEX_IS_TWIDDLED(mode) ) {
1.192 + pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width, mip_height );
1.193 + } else {
1.194 + pvr2_vram64_read( tmp, texture_addr, inputlength );
1.195 + }
1.196 + vq_decode( (uint16_t *)data, tmp, mip_width, mip_height, &codebook );
1.197 } else if( PVR2_TEX_IS_TWIDDLED(mode) ) {
1.198 - char tmp[mip_bytes];
1.199 - uint16_t *p = (uint16_t *)tmp;
1.200 - pvr2_vram64_read( tmp, texture_addr, mip_bytes );
1.201 - /* Untwiddle */
1.202 - detwiddle_16_to_16( 0, 0, mip_width, mip_width, &p, (uint16_t *)data );
1.203 + pvr2_vram64_read_twiddled_16( data, texture_addr, mip_width, mip_height );
1.204 } else {
1.205 pvr2_vram64_read( data, texture_addr, mip_bytes );
1.206 }
1.207
1.208 - if( PVR2_TEX_IS_MIPMAPPED(mode) && mip_width == 2 ) {
1.209 - /* Opengl requires a 1x1 texture, but the PVR2 doesn't. This should
1.210 - * strictly speaking be the average of the 2x2 texture, but we're
1.211 - * lazy at the moment */
1.212 - glTexImage2D( GL_TEXTURE_2D, level+1, intFormat, 1, 1, 0, format, type, data );
1.213 - }
1.214 -
1.215 /* Pass to GL */
1.216 glTexImage2D( GL_TEXTURE_2D, level, intFormat, mip_width, mip_height, 0, format, type,
1.217 data );
.