filename | src/pvr2/texcache.c |
changeset | 736:a02d1475ccfd |
prev | 677:3ee62740ff8f |
next | 856:02ac5f37bfc9 |
author | nkeynes |
date | Wed Jul 30 22:50:44 2008 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Bug #61: OpenBSD support (Modified) patch from bsdmaniak, thanks! |
file | annotate | diff | log | raw |
1.1 --- a/src/pvr2/texcache.c Thu May 29 10:50:25 2008 +00001.2 +++ b/src/pvr2/texcache.c Wed Jul 30 22:50:44 2008 +00001.3 @@ -64,12 +64,12 @@1.4 {1.5 int i;1.6 for( i=0; i<PVR2_RAM_PAGES; i++ ) {1.7 - texcache_page_lookup[i] = EMPTY_ENTRY;1.8 + texcache_page_lookup[i] = EMPTY_ENTRY;1.9 }1.10 for( i=0; i<MAX_TEXTURES; i++ ) {1.11 - texcache_free_list[i] = i;1.12 - texcache_active_list[i].texture_addr = -1;1.13 - texcache_active_list[i].next = EMPTY_ENTRY;1.14 + texcache_free_list[i] = i;1.15 + texcache_active_list[i].texture_addr = -1;1.16 + texcache_active_list[i].next = EMPTY_ENTRY;1.17 }1.18 texcache_free_ptr = 0;1.19 texcache_ref_counter = 0;1.20 @@ -86,7 +86,7 @@1.22 glGenTextures( MAX_TEXTURES, texids );1.23 for( i=0; i<MAX_TEXTURES; i++ ) {1.24 - texcache_active_list[i].texture_id = texids[i];1.25 + texcache_active_list[i].texture_id = texids[i];1.26 }1.27 }1.29 @@ -98,11 +98,11 @@1.30 int i;1.31 /* clear structures */1.32 for( i=0; i<PVR2_RAM_PAGES; i++ ) {1.33 - texcache_page_lookup[i] = EMPTY_ENTRY;1.34 + texcache_page_lookup[i] = EMPTY_ENTRY;1.35 }1.36 for( i=0; i<MAX_TEXTURES; i++ ) {1.37 - texcache_free_list[i] = i;1.38 - texcache_active_list[i].next = EMPTY_ENTRY;1.39 + texcache_free_list[i] = i;1.40 + texcache_active_list[i].next = EMPTY_ENTRY;1.41 }1.42 texcache_free_ptr = 0;1.43 texcache_ref_counter = 0;1.44 @@ -118,9 +118,9 @@1.45 GLuint texids[MAX_TEXTURES];1.46 int i;1.47 texcache_flush();1.48 -1.49 +1.50 for( i=0; i<MAX_TEXTURES; i++ ) {1.51 - texids[i] = texcache_active_list[i].texture_id;1.52 + texids[i] = texcache_active_list[i].texture_id;1.53 }1.54 glDeleteTextures( MAX_TEXTURES, texids );1.55 }1.56 @@ -134,19 +134,19 @@1.57 texcache_active_list[slot].texture_addr = -1;1.58 texcache_active_list[slot].next = EMPTY_ENTRY; /* Just for safety */1.59 if( texcache_page_lookup[evict_page] == slot ) {1.60 - texcache_page_lookup[evict_page] = replace_next;1.61 + texcache_page_lookup[evict_page] = replace_next;1.62 } else {1.63 - texcache_entry_index idx = texcache_page_lookup[evict_page];1.64 - texcache_entry_index next;1.65 - do {1.66 - next = texcache_active_list[idx].next;1.67 - if( next == slot ) {1.68 - assert( idx != replace_next );1.69 - texcache_active_list[idx].next = replace_next;1.70 - break;1.71 - }1.72 - idx = next;1.73 - } while( next != EMPTY_ENTRY );1.74 + texcache_entry_index idx = texcache_page_lookup[evict_page];1.75 + texcache_entry_index next;1.76 + do {1.77 + next = texcache_active_list[idx].next;1.78 + if( next == slot ) {1.79 + assert( idx != replace_next );1.80 + texcache_active_list[idx].next = replace_next;1.81 + break;1.82 + }1.83 + idx = next;1.84 + } while( next != EMPTY_ENTRY );1.85 }1.86 }1.88 @@ -161,14 +161,14 @@1.89 int lru_value = texcache_active_list[0].lru_count;1.90 int i;1.91 for( i=1; i<MAX_TEXTURES; i++ ) {1.92 - /* FIXME: account for rollover */1.93 - if( texcache_active_list[i].lru_count < lru_value ) {1.94 - slot = i;1.95 - lru_value = texcache_active_list[i].lru_count;1.96 - }1.97 + /* FIXME: account for rollover */1.98 + if( texcache_active_list[i].lru_count < lru_value ) {1.99 + slot = i;1.100 + lru_value = texcache_active_list[i].lru_count;1.101 + }1.102 }1.103 texcache_evict(slot);1.104 -1.105 +1.106 return slot;1.107 }1.109 @@ -179,16 +179,16 @@1.110 uint32_t texture_page = texture_addr >> 12;1.111 texcache_entry_index idx = texcache_page_lookup[texture_page];1.112 if( idx == EMPTY_ENTRY )1.113 - return;1.114 + return;1.115 assert( texcache_free_ptr >= 0 );1.116 do {1.117 - texcache_entry_t entry = &texcache_active_list[idx];1.118 - entry->texture_addr = -1;1.119 - /* release entry */1.120 - texcache_free_ptr--;1.121 - texcache_free_list[texcache_free_ptr] = idx;1.122 - idx = entry->next;1.123 - entry->next = EMPTY_ENTRY;1.124 + texcache_entry_t entry = &texcache_active_list[idx];1.125 + entry->texture_addr = -1;1.126 + /* release entry */1.127 + texcache_free_ptr--;1.128 + texcache_free_list[texcache_free_ptr] = idx;1.129 + idx = entry->next;1.130 + entry->next = EMPTY_ENTRY;1.131 } while( idx != EMPTY_ENTRY );1.132 texcache_page_lookup[texture_page] = EMPTY_ENTRY;1.133 }1.134 @@ -203,12 +203,12 @@1.135 {1.136 int i;1.137 for( i=0; i<MAX_TEXTURES; i++ ) {1.138 - if( texcache_active_list[i].texture_addr != -1 &&1.139 - PVR2_TEX_IS_PALETTE(texcache_active_list[i].mode) ) {1.140 - texcache_evict( i );1.141 - texcache_free_ptr--;1.142 - texcache_free_list[texcache_free_ptr] = i;1.143 - }1.144 + if( texcache_active_list[i].texture_addr != -1 &&1.145 + PVR2_TEX_IS_PALETTE(texcache_active_list[i].mode) ) {1.146 + texcache_evict( i );1.147 + texcache_free_ptr--;1.148 + texcache_free_list[texcache_free_ptr] = i;1.149 + }1.150 }1.151 }1.153 @@ -216,7 +216,7 @@1.154 {1.155 int i;1.156 for( i=0; i<inbytes; i++ ) {1.157 - *out++ = pal[*in++];1.158 + *out++ = pal[*in++];1.159 }1.160 }1.162 @@ -224,7 +224,7 @@1.163 {1.164 int i;1.165 for( i=0; i<inbytes; i++ ) {1.166 - *out++ = (uint16_t)pal[*in++];1.167 + *out++ = (uint16_t)pal[*in++];1.168 }1.169 }1.171 @@ -232,9 +232,9 @@1.172 {1.173 int i;1.174 for( i=0; i<inbytes; i++ ) {1.175 - *out++ = pal[*in & 0x0F];1.176 - *out++ = pal[(*in >> 4)];1.177 - in++;1.178 + *out++ = pal[*in & 0x0F];1.179 + *out++ = pal[(*in >> 4)];1.180 + in++;1.181 }1.182 }1.184 @@ -243,9 +243,9 @@1.185 {1.186 int i;1.187 for( i=0; i<inbytes; i++ ) {1.188 - *out++ = (uint16_t)pal[*in & 0x0F];1.189 - *out++ = (uint16_t)pal[(*in >> 4)];1.190 - in++;1.191 + *out++ = (uint16_t)pal[*in & 0x0F];1.192 + *out++ = (uint16_t)pal[(*in >> 4)];1.193 + in++;1.194 }1.195 }1.197 @@ -256,32 +256,32 @@1.198 };1.200 static void vq_get_codebook( struct vq_codebook *codebook,1.201 - uint16_t *input )1.202 + uint16_t *input )1.203 {1.204 /* Detwiddle the codebook, for the sake of my own sanity if nothing else */1.205 uint16_t *p = (uint16_t *)input;1.206 int i;1.207 for( i=0; i<256; i++ ) {1.208 - codebook->quad[i][0] = *p++;1.209 - codebook->quad[i][2] = *p++;1.210 - codebook->quad[i][1] = *p++;1.211 - codebook->quad[i][3] = *p++;1.212 + codebook->quad[i][0] = *p++;1.213 + codebook->quad[i][2] = *p++;1.214 + codebook->quad[i][1] = *p++;1.215 + codebook->quad[i][3] = *p++;1.216 }1.217 }1.219 static void vq_decode( uint16_t *output, unsigned char *input, int width, int height,1.220 - struct vq_codebook *codebook ) {1.221 + struct vq_codebook *codebook ) {1.222 int i,j;1.223 -1.224 +1.225 uint8_t *c = (uint8_t *)input;1.226 for( j=0; j<height; j+=2 ) {1.227 - for( i=0; i<width; i+=2 ) {1.228 - uint8_t code = *c++;1.229 - output[i + j*width] = codebook->quad[code][0];1.230 - output[i + 1 + j*width] = codebook->quad[code][1];1.231 - output[i + (j+1)*width] = codebook->quad[code][2];1.232 - output[i + 1 + (j+1)*width] = codebook->quad[code][3];1.233 - }1.234 + for( i=0; i<width; i+=2 ) {1.235 + uint8_t code = *c++;1.236 + output[i + j*width] = codebook->quad[code][0];1.237 + output[i + 1 + j*width] = codebook->quad[code][1];1.238 + output[i + (j+1)*width] = codebook->quad[code][2];1.239 + output[i + 1 + (j+1)*width] = codebook->quad[code][3];1.240 + }1.241 }1.242 }1.244 @@ -310,15 +310,15 @@1.245 int x, y;1.246 uint32_t *p = input;1.247 for( y=0; y<height; y++ ) {1.248 - for( x=0; x<width; x+=2 ) {1.249 - float u = (float)(*p & 0xFF);1.250 - float y0 = (float)( (*p>>8)&0xFF );1.251 - float v = (float)( (*p>>16)&0xFF );1.252 - float y1 = (float)( (*p>>24)&0xFF );1.253 - *output++ = yuv_to_rgb32( y0, u, v );1.254 - *output++ = yuv_to_rgb32( y1, u, v );1.255 - p++;1.256 - }1.257 + for( x=0; x<width; x+=2 ) {1.258 + float u = (float)(*p & 0xFF);1.259 + float y0 = (float)( (*p>>8)&0xFF );1.260 + float v = (float)( (*p>>16)&0xFF );1.261 + float y1 = (float)( (*p>>24)&0xFF );1.262 + *output++ = yuv_to_rgb32( y0, u, v );1.263 + *output++ = yuv_to_rgb32( y1, u, v );1.264 + p++;1.265 + }1.266 }1.267 }1.269 @@ -327,7 +327,7 @@1.270 * bound OpenGL texture.1.271 */1.272 static void texcache_load_texture( uint32_t texture_addr, int width, int height,1.273 - int mode ) {1.274 + int mode ) {1.275 int bpp_shift = 1; /* bytes per (output) pixel as a power of 2 */1.276 GLint intFormat = GL_RGBA, format, type;1.277 int tex_format = mode & PVR2_TEX_FORMAT_MASK;1.278 @@ -340,179 +340,179 @@1.279 switch( tex_format ) {1.280 case PVR2_TEX_FORMAT_IDX4:1.281 case PVR2_TEX_FORMAT_IDX8:1.282 - /* For indexed-colour modes, we need to lookup the palette control1.283 - * word to determine the de-indexed texture format.1.284 - */1.285 - switch( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03 ) {1.286 - case 0: /* ARGB1555 */1.287 - format = GL_BGRA;1.288 - type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.289 - break;1.290 - case 1: /* RGB565 */1.291 - intFormat = GL_RGB;1.292 - format = GL_RGB;1.293 - type = GL_UNSIGNED_SHORT_5_6_5;1.294 - break;1.295 - case 2: /* ARGB4444 */1.296 - format = GL_BGRA;1.297 - type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.298 - break;1.299 - case 3: /* ARGB8888 */1.300 - format = GL_BGRA;1.301 - type = GL_UNSIGNED_BYTE;1.302 - bpp_shift = 2;1.303 - break;1.304 - default:1.305 - return; /* Can't happen, but it makes gcc stop complaining */1.306 - }1.307 - break;1.308 -1.309 - case PVR2_TEX_FORMAT_ARGB1555:1.310 - format = GL_BGRA;1.311 - type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.312 - break;1.313 - case PVR2_TEX_FORMAT_RGB565:1.314 - intFormat = GL_RGB;1.315 - format = GL_RGB;1.316 - type = GL_UNSIGNED_SHORT_5_6_5;1.317 - break;1.318 - case PVR2_TEX_FORMAT_ARGB4444:1.319 - format = GL_BGRA;1.320 - type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.321 - break;1.322 - case PVR2_TEX_FORMAT_YUV422:1.323 - /* YUV422 isn't directly supported by most implementations, so decode1.324 - * it to a (reasonably) standard ARGB32.1.325 - */1.326 - bpp_shift = 2;1.327 - format = GL_BGRA;1.328 - type = GL_UNSIGNED_BYTE;1.329 - break;1.330 - case PVR2_TEX_FORMAT_BUMPMAP:1.331 - ERROR( "Bumpmap not supported" );1.332 - return;1.333 - default:1.334 - ERROR( "Undefined texture format" );1.335 - return;1.336 + /* For indexed-colour modes, we need to lookup the palette control1.337 + * word to determine the de-indexed texture format.1.338 + */1.339 + switch( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03 ) {1.340 + case 0: /* ARGB1555 */1.341 + format = GL_BGRA;1.342 + type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.343 + break;1.344 + case 1: /* RGB565 */1.345 + intFormat = GL_RGB;1.346 + format = GL_RGB;1.347 + type = GL_UNSIGNED_SHORT_5_6_5;1.348 + break;1.349 + case 2: /* ARGB4444 */1.350 + format = GL_BGRA;1.351 + type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.352 + break;1.353 + case 3: /* ARGB8888 */1.354 + format = GL_BGRA;1.355 + type = GL_UNSIGNED_BYTE;1.356 + bpp_shift = 2;1.357 + break;1.358 + default:1.359 + return; /* Can't happen, but it makes gcc stop complaining */1.360 + }1.361 + break;1.362 +1.363 + case PVR2_TEX_FORMAT_ARGB1555:1.364 + format = GL_BGRA;1.365 + type = GL_UNSIGNED_SHORT_1_5_5_5_REV;1.366 + break;1.367 + case PVR2_TEX_FORMAT_RGB565:1.368 + intFormat = GL_RGB;1.369 + format = GL_RGB;1.370 + type = GL_UNSIGNED_SHORT_5_6_5;1.371 + break;1.372 + case PVR2_TEX_FORMAT_ARGB4444:1.373 + format = GL_BGRA;1.374 + type = GL_UNSIGNED_SHORT_4_4_4_4_REV;1.375 + break;1.376 + case PVR2_TEX_FORMAT_YUV422:1.377 + /* YUV422 isn't directly supported by most implementations, so decode1.378 + * it to a (reasonably) standard ARGB32.1.379 + */1.380 + bpp_shift = 2;1.381 + format = GL_BGRA;1.382 + type = GL_UNSIGNED_BYTE;1.383 + break;1.384 + case PVR2_TEX_FORMAT_BUMPMAP:1.385 + ERROR( "Bumpmap not supported" );1.386 + return;1.387 + default:1.388 + ERROR( "Undefined texture format" );1.389 + return;1.390 }1.391 -1.392 +1.393 if( PVR2_TEX_IS_STRIDE(mode) && tex_format != PVR2_TEX_FORMAT_IDX4 &&1.394 - tex_format != PVR2_TEX_FORMAT_IDX8 ) {1.395 - /* Stride textures cannot be mip-mapped, compressed, indexed or twiddled */1.396 - uint32_t stride = (MMIO_READ( PVR2, RENDER_TEXSIZE ) & 0x003F) << 5;1.397 - unsigned char data[(width*height) << bpp_shift];1.398 - if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.399 - unsigned char tmp[(width*height)<<1];1.400 - pvr2_vram64_read_stride( tmp, width<<1, texture_addr, stride<<1, height );1.401 - yuv_decode( (uint32_t *)data, (uint32_t *)tmp, width, height );1.402 - } else {1.403 - pvr2_vram64_read_stride( data, width<<bpp_shift, texture_addr, stride<<bpp_shift, height );1.404 - }1.405 - glTexImage2D( GL_TEXTURE_2D, 0, intFormat, width, height, 0, format, type, data );1.406 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);1.407 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);1.408 - return;1.409 + tex_format != PVR2_TEX_FORMAT_IDX8 ) {1.410 + /* Stride textures cannot be mip-mapped, compressed, indexed or twiddled */1.411 + uint32_t stride = (MMIO_READ( PVR2, RENDER_TEXSIZE ) & 0x003F) << 5;1.412 + unsigned char data[(width*height) << bpp_shift];1.413 + if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.414 + unsigned char tmp[(width*height)<<1];1.415 + pvr2_vram64_read_stride( tmp, width<<1, texture_addr, stride<<1, height );1.416 + yuv_decode( (uint32_t *)data, (uint32_t *)tmp, width, height );1.417 + } else {1.418 + pvr2_vram64_read_stride( data, width<<bpp_shift, texture_addr, stride<<bpp_shift, height );1.419 + }1.420 + glTexImage2D( GL_TEXTURE_2D, 0, intFormat, width, height, 0, format, type, data );1.421 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);1.422 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);1.423 + return;1.424 }1.426 if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.427 - uint16_t tmp[VQ_CODEBOOK_SIZE];1.428 - pvr2_vram64_read( (unsigned char *)tmp, texture_addr, VQ_CODEBOOK_SIZE );1.429 - texture_addr += VQ_CODEBOOK_SIZE;1.430 - vq_get_codebook( &codebook, tmp );1.431 + uint16_t tmp[VQ_CODEBOOK_SIZE];1.432 + pvr2_vram64_read( (unsigned char *)tmp, texture_addr, VQ_CODEBOOK_SIZE );1.433 + texture_addr += VQ_CODEBOOK_SIZE;1.434 + vq_get_codebook( &codebook, tmp );1.435 }1.437 int level=0, last_level = 0, mip_width = width, mip_height = height, src_bytes, dest_bytes;1.438 if( PVR2_TEX_IS_MIPMAPPED(mode) ) {1.439 - uint32_t src_offset = 0;1.440 - filter = GL_LINEAR_MIPMAP_LINEAR;1.441 - mip_height = height = width;1.442 - while( (1<<last_level) < width ) {1.443 - last_level++;1.444 - src_offset += ((width>>last_level)*(width>>last_level));1.445 - }1.446 - if( width != 1 ) {1.447 - src_offset += 3;1.448 - }1.449 - if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.450 - src_offset >>= 2;1.451 - } else if( tex_format == PVR2_TEX_FORMAT_IDX4 ) {1.452 - src_offset >>= 1;1.453 - } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.454 - src_offset <<= 1;1.455 - } else if( tex_format != PVR2_TEX_FORMAT_IDX8 ) {1.456 - src_offset <<= bpp_shift;1.457 - }1.458 - texture_addr += src_offset;1.459 + uint32_t src_offset = 0;1.460 + filter = GL_LINEAR_MIPMAP_LINEAR;1.461 + mip_height = height = width;1.462 + while( (1<<last_level) < width ) {1.463 + last_level++;1.464 + src_offset += ((width>>last_level)*(width>>last_level));1.465 + }1.466 + if( width != 1 ) {1.467 + src_offset += 3;1.468 + }1.469 + if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.470 + src_offset >>= 2;1.471 + } else if( tex_format == PVR2_TEX_FORMAT_IDX4 ) {1.472 + src_offset >>= 1;1.473 + } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.474 + src_offset <<= 1;1.475 + } else if( tex_format != PVR2_TEX_FORMAT_IDX8 ) {1.476 + src_offset <<= bpp_shift;1.477 + }1.478 + texture_addr += src_offset;1.479 }1.480 -1.481 +1.483 dest_bytes = (mip_width * mip_height) << bpp_shift;1.484 src_bytes = dest_bytes; // Modes will change this (below)1.486 for( level=0; level<= last_level; level++ ) {1.487 - unsigned char data[dest_bytes];1.488 - /* load data from image, detwiddling/uncompressing as required */1.489 - if( tex_format == PVR2_TEX_FORMAT_IDX8 ) {1.490 - src_bytes = (mip_width * mip_height);1.491 - int bank = (mode >> 25) &0x03;1.492 - uint32_t *palette = ((uint32_t *)mmio_region_PVR2PAL.mem) + (bank<<8);1.493 - unsigned char tmp[src_bytes];1.494 - pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width, mip_height );1.495 - if( bpp_shift == 2 ) {1.496 - decode_pal8_to_32( (uint32_t *)data, tmp, src_bytes, palette );1.497 - } else {1.498 - decode_pal8_to_16( (uint16_t *)data, tmp, src_bytes, palette );1.499 - }1.500 - } else if( tex_format == PVR2_TEX_FORMAT_IDX4 ) {1.501 - src_bytes = (mip_width * mip_height) >> 1;1.502 - int bank = (mode >>21 ) & 0x3F;1.503 - uint32_t *palette = ((uint32_t *)mmio_region_PVR2PAL.mem) + (bank<<4);1.504 - unsigned char tmp[src_bytes];1.505 - pvr2_vram64_read_twiddled_4( tmp, texture_addr, mip_width, mip_height );1.506 - if( bpp_shift == 2 ) {1.507 - decode_pal4_to_32( (uint32_t *)data, tmp, src_bytes, palette );1.508 - } else {1.509 - decode_pal4_to_16( (uint16_t *)data, tmp, src_bytes, palette );1.510 - }1.511 - } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.512 - src_bytes = ((mip_width*mip_height)<<1);1.513 - unsigned char tmp[src_bytes];1.514 - if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.515 - pvr2_vram64_read_twiddled_16( tmp, texture_addr, mip_width, mip_height );1.516 - } else {1.517 - pvr2_vram64_read( tmp, texture_addr, src_bytes );1.518 - }1.519 - yuv_decode( (uint32_t *)data, (uint32_t *)tmp, mip_width, mip_height );1.520 - } else if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.521 - src_bytes = ((mip_width*mip_height) >> 2);1.522 - unsigned char tmp[src_bytes];1.523 - if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.524 - pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width>>1, mip_height>>1 );1.525 - } else {1.526 - pvr2_vram64_read( tmp, texture_addr, src_bytes );1.527 - }1.528 - vq_decode( (uint16_t *)data, tmp, mip_width, mip_height, &codebook );1.529 - } else if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.530 - pvr2_vram64_read_twiddled_16( data, texture_addr, mip_width, mip_height );1.531 - } else {1.532 - pvr2_vram64_read( data, texture_addr, src_bytes );1.533 - }1.534 -1.535 - /* Pass to GL */1.536 - if( level == last_level && level != 0 ) { /* 1x1 stored within a 2x2 */1.537 - glTexImage2D( GL_TEXTURE_2D, level, intFormat, 1, 1, 0, format, type,1.538 - data + (3 << bpp_shift) );1.539 - } else {1.540 - glTexImage2D( GL_TEXTURE_2D, level, intFormat, mip_width, mip_height, 0, format, type,1.541 - data );1.542 - if( mip_width > 2 ) {1.543 - mip_width >>= 1;1.544 - mip_height >>= 1;1.545 - dest_bytes >>= 2;1.546 - src_bytes >>= 2;1.547 - }1.548 - texture_addr -= src_bytes;1.549 - }1.550 + unsigned char data[dest_bytes];1.551 + /* load data from image, detwiddling/uncompressing as required */1.552 + if( tex_format == PVR2_TEX_FORMAT_IDX8 ) {1.553 + src_bytes = (mip_width * mip_height);1.554 + int bank = (mode >> 25) &0x03;1.555 + uint32_t *palette = ((uint32_t *)mmio_region_PVR2PAL.mem) + (bank<<8);1.556 + unsigned char tmp[src_bytes];1.557 + pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width, mip_height );1.558 + if( bpp_shift == 2 ) {1.559 + decode_pal8_to_32( (uint32_t *)data, tmp, src_bytes, palette );1.560 + } else {1.561 + decode_pal8_to_16( (uint16_t *)data, tmp, src_bytes, palette );1.562 + }1.563 + } else if( tex_format == PVR2_TEX_FORMAT_IDX4 ) {1.564 + src_bytes = (mip_width * mip_height) >> 1;1.565 + int bank = (mode >>21 ) & 0x3F;1.566 + uint32_t *palette = ((uint32_t *)mmio_region_PVR2PAL.mem) + (bank<<4);1.567 + unsigned char tmp[src_bytes];1.568 + pvr2_vram64_read_twiddled_4( tmp, texture_addr, mip_width, mip_height );1.569 + if( bpp_shift == 2 ) {1.570 + decode_pal4_to_32( (uint32_t *)data, tmp, src_bytes, palette );1.571 + } else {1.572 + decode_pal4_to_16( (uint16_t *)data, tmp, src_bytes, palette );1.573 + }1.574 + } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {1.575 + src_bytes = ((mip_width*mip_height)<<1);1.576 + unsigned char tmp[src_bytes];1.577 + if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.578 + pvr2_vram64_read_twiddled_16( tmp, texture_addr, mip_width, mip_height );1.579 + } else {1.580 + pvr2_vram64_read( tmp, texture_addr, src_bytes );1.581 + }1.582 + yuv_decode( (uint32_t *)data, (uint32_t *)tmp, mip_width, mip_height );1.583 + } else if( PVR2_TEX_IS_COMPRESSED(mode) ) {1.584 + src_bytes = ((mip_width*mip_height) >> 2);1.585 + unsigned char tmp[src_bytes];1.586 + if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.587 + pvr2_vram64_read_twiddled_8( tmp, texture_addr, mip_width>>1, mip_height>>1 );1.588 + } else {1.589 + pvr2_vram64_read( tmp, texture_addr, src_bytes );1.590 + }1.591 + vq_decode( (uint16_t *)data, tmp, mip_width, mip_height, &codebook );1.592 + } else if( PVR2_TEX_IS_TWIDDLED(mode) ) {1.593 + pvr2_vram64_read_twiddled_16( data, texture_addr, mip_width, mip_height );1.594 + } else {1.595 + pvr2_vram64_read( data, texture_addr, src_bytes );1.596 + }1.597 +1.598 + /* Pass to GL */1.599 + if( level == last_level && level != 0 ) { /* 1x1 stored within a 2x2 */1.600 + glTexImage2D( GL_TEXTURE_2D, level, intFormat, 1, 1, 0, format, type,1.601 + data + (3 << bpp_shift) );1.602 + } else {1.603 + glTexImage2D( GL_TEXTURE_2D, level, intFormat, mip_width, mip_height, 0, format, type,1.604 + data );1.605 + if( mip_width > 2 ) {1.606 + mip_width >>= 1;1.607 + mip_height >>= 1;1.608 + dest_bytes >>= 2;1.609 + src_bytes >>= 2;1.610 + }1.611 + texture_addr -= src_bytes;1.612 + }1.613 }1.615 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);1.616 @@ -536,25 +536,25 @@1.617 texcache_entry_index next;1.618 texcache_entry_index idx = texcache_page_lookup[texture_page];1.619 while( idx != EMPTY_ENTRY ) {1.620 - texcache_entry_t entry = &texcache_active_list[idx];1.621 - if( entry->texture_addr == texture_addr &&1.622 - entry->mode == texture_word &&1.623 - entry->width == width &&1.624 - entry->height == height ) {1.625 - entry->lru_count = texcache_ref_counter++;1.626 - return entry->texture_id;1.627 - }1.628 + texcache_entry_t entry = &texcache_active_list[idx];1.629 + if( entry->texture_addr == texture_addr &&1.630 + entry->mode == texture_word &&1.631 + entry->width == width &&1.632 + entry->height == height ) {1.633 + entry->lru_count = texcache_ref_counter++;1.634 + return entry->texture_id;1.635 + }1.636 idx = entry->next;1.637 }1.639 -1.640 +1.641 /* Not found - check the free list */1.642 texcache_entry_index slot = 0;1.644 if( texcache_free_ptr < MAX_TEXTURES ) {1.645 - slot = texcache_free_list[texcache_free_ptr++];1.646 + slot = texcache_free_list[texcache_free_ptr++];1.647 } else {1.648 - slot = texcache_evict_lru();1.649 + slot = texcache_evict_lru();1.650 }1.652 /* Construct new entry */1.653 @@ -567,14 +567,14 @@1.654 /* Add entry to the lookup table */1.655 next = texcache_page_lookup[texture_page];1.656 if( next == slot ) {1.657 - int i;1.658 - fprintf( stderr, "Active list: " );1.659 - for( i=0; i<MAX_TEXTURES; i++ ) {1.660 - fprintf( stderr, "%d, ", texcache_active_list[i].next );1.661 - }1.662 - fprintf( stderr, "\n" );1.663 - assert( next != slot );1.664 -1.665 + int i;1.666 + fprintf( stderr, "Active list: " );1.667 + for( i=0; i<MAX_TEXTURES; i++ ) {1.668 + fprintf( stderr, "%d, ", texcache_active_list[i].next );1.669 + }1.670 + fprintf( stderr, "\n" );1.671 + assert( next != slot );1.672 +1.673 }1.674 assert( next != slot );1.675 texcache_active_list[slot].next = next;1.676 @@ -597,30 +597,30 @@1.677 {1.678 int i;1.679 int slot_found[MAX_TEXTURES];1.680 -1.681 +1.682 memset( slot_found, 0, sizeof(slot_found) );1.684 /* Check entries on the free list */1.685 for( i= texcache_free_ptr; i< MAX_TEXTURES; i++ ) {1.686 - int slot = texcache_free_list[i];1.687 - assert( slot_found[slot] == 0 );1.688 - assert( texcache_active_list[slot].next == EMPTY_ENTRY );1.689 - slot_found[slot] = 1;1.690 + int slot = texcache_free_list[i];1.691 + assert( slot_found[slot] == 0 );1.692 + assert( texcache_active_list[slot].next == EMPTY_ENTRY );1.693 + slot_found[slot] = 1;1.694 }1.696 /* Check entries on the active lists */1.697 for( i=0; i< PVR2_RAM_PAGES; i++ ) {1.698 - int slot = texcache_page_lookup[i];1.699 - while( slot != EMPTY_ENTRY ) {1.700 - assert( slot_found[slot] == 0 );1.701 - assert( (texcache_active_list[slot].texture_addr >> 12) == i );1.702 - slot_found[slot] = 2;1.703 - slot = texcache_active_list[slot].next;1.704 - }1.705 + int slot = texcache_page_lookup[i];1.706 + while( slot != EMPTY_ENTRY ) {1.707 + assert( slot_found[slot] == 0 );1.708 + assert( (texcache_active_list[slot].texture_addr >> 12) == i );1.709 + slot_found[slot] = 2;1.710 + slot = texcache_active_list[slot].next;1.711 + }1.712 }1.714 /* Make sure we didn't miss any entries */1.715 for( i=0; i<MAX_TEXTURES; i++ ) {1.716 - assert( slot_found[i] != 0 );1.717 + assert( slot_found[i] != 0 );1.718 }1.719 }
.