Search
lxdream.org :: lxdream/src/pvr2/texcache.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/texcache.c
changeset 886:2bc6d2329cce
prev870:8d4deb2bc1ea
next1066:ddffe9d2b332
author nkeynes
date Mon Oct 20 05:08:31 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Fix texcache_init failing to clear texture_addr to -1
Replace direct references to PVR2 registers with a texcache_set_config() function called from glrender.c.
This also now actually does invalidation when palette mode or stride changes as well.
file annotate diff log raw
1.1 --- a/src/pvr2/texcache.c Fri Oct 10 00:10:26 2008 +0000
1.2 +++ b/src/pvr2/texcache.c Mon Oct 20 05:08:31 2008 +0000
1.3 @@ -57,6 +57,8 @@
1.4 static texcache_entry_index texcache_page_lookup[PVR2_RAM_PAGES];
1.5 static uint32_t texcache_ref_counter;
1.6 static struct texcache_entry texcache_active_list[MAX_TEXTURES];
1.7 +static uint32_t texcache_palette_mode;
1.8 +static uint32_t texcache_stride_width;
1.9
1.10 /**
1.11 * Initialize the texture cache.
1.12 @@ -75,6 +77,8 @@
1.13 }
1.14 texcache_free_ptr = 0;
1.15 texcache_ref_counter = 0;
1.16 + texcache_palette_mode = 0;
1.17 + texcache_stride_width = 0;
1.18 }
1.19
1.20 /**
1.21 @@ -112,6 +116,7 @@
1.22 for( i=0; i<MAX_TEXTURES; i++ ) {
1.23 texcache_free_list[i] = i;
1.24 texcache_active_list[i].next = EMPTY_ENTRY;
1.25 + texcache_active_list[i].texture_addr = -1;
1.26 if( texcache_active_list[i].buffer != NULL ) {
1.27 texcache_release_render_buffer(texcache_active_list[i].buffer);
1.28 texcache_active_list[i].buffer = NULL;
1.29 @@ -232,6 +237,33 @@
1.30 }
1.31 }
1.32 }
1.33 +/**
1.34 + * Mark all stride textures as needing a re-read (ie when the stride width
1.35 + * is changed).
1.36 + */
1.37 +void texcache_invalidate_stride( )
1.38 +{
1.39 + int i;
1.40 + for( i=0; i<MAX_TEXTURES; i++ ) {
1.41 + if( texcache_active_list[i].texture_addr != -1 &&
1.42 + PVR2_TEX_IS_STRIDE(texcache_active_list[i].mode) ) {
1.43 + texcache_evict( i );
1.44 + texcache_free_ptr--;
1.45 + texcache_free_list[texcache_free_ptr] = i;
1.46 + }
1.47 + }
1.48 +}
1.49 +
1.50 +void texcache_set_config( uint32_t palette_mode, uint32_t stride )
1.51 +{
1.52 + if( palette_mode != texcache_palette_mode )
1.53 + texcache_invalidate_palette();
1.54 + if( stride != texcache_stride_width )
1.55 + texcache_invalidate_stride();
1.56 +
1.57 + texcache_palette_mode = palette_mode;
1.58 + texcache_stride_width = stride;
1.59 +}
1.60
1.61 static void decode_pal8_to_32( uint32_t *out, uint8_t *in, int inbytes, uint32_t *pal )
1.62 {
1.63 @@ -374,7 +406,7 @@
1.64 /* For indexed-colour modes, we need to lookup the palette control
1.65 * word to determine the de-indexed texture format.
1.66 */
1.67 - switch( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03 ) {
1.68 + switch( texcache_palette_mode ) {
1.69 case 0: /* ARGB1555 */
1.70 format = GL_BGRA;
1.71 type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1.72 @@ -428,14 +460,13 @@
1.73 if( PVR2_TEX_IS_STRIDE(mode) && tex_format != PVR2_TEX_FORMAT_IDX4 &&
1.74 tex_format != PVR2_TEX_FORMAT_IDX8 ) {
1.75 /* Stride textures cannot be mip-mapped, compressed, indexed or twiddled */
1.76 - uint32_t stride = (MMIO_READ( PVR2, RENDER_TEXSIZE ) & 0x003F) << 5;
1.77 unsigned char data[(width*height) << bpp_shift];
1.78 if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {
1.79 unsigned char tmp[(width*height)<<1];
1.80 - pvr2_vram64_read_stride( tmp, width<<1, texture_addr, stride<<1, height );
1.81 + pvr2_vram64_read_stride( tmp, width<<1, texture_addr, texcache_stride_width<<1, height );
1.82 yuv_decode( (uint32_t *)data, (uint32_t *)tmp, width, height );
1.83 } else {
1.84 - pvr2_vram64_read_stride( data, width<<bpp_shift, texture_addr, stride<<bpp_shift, height );
1.85 + pvr2_vram64_read_stride( data, width<<bpp_shift, texture_addr, texcache_stride_width<<bpp_shift, height );
1.86 }
1.87 glTexImage2D( GL_TEXTURE_2D, 0, intFormat, width, height, 0, format, type, data );
1.88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
1.89 @@ -581,6 +612,7 @@
1.90 }
1.91
1.92 /* Construct new entry */
1.93 + assert( texcache_active_list[slot].texture_addr == -1 );
1.94 texcache_active_list[slot].texture_addr = texture_addr;
1.95 texcache_active_list[slot].width = width;
1.96 texcache_active_list[slot].height = height;
1.97 @@ -599,7 +631,6 @@
1.98 assert( next != slot );
1.99
1.100 }
1.101 - assert( next != slot );
1.102 texcache_active_list[slot].next = next;
1.103 texcache_page_lookup[texture_page] = slot;
1.104 return slot;
.