filename | src/pvr2/texcache.c |
changeset | 1135:68daed8f38af |
prev | 1075:1a21750d300c |
next | 1140:7dc1c71ece76 |
author | nkeynes |
date | Sun Oct 24 11:50:17 2010 +1000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Set gl texture parameters at texture load time rather than render time. (This does mean that if the texture is used with variant parameters it will be loaded multiple times). 3-4% faster this way |
file | annotate | diff | log | raw |
1.1 --- a/src/pvr2/texcache.c Fri Jul 31 13:45:32 2009 +10001.2 +++ b/src/pvr2/texcache.c Sun Oct 24 11:50:17 2010 +10001.3 @@ -47,7 +47,7 @@1.5 typedef struct texcache_entry {1.6 uint32_t texture_addr;1.7 - int width, height, mode;1.8 + uint32_t poly2_mode, tex_mode;1.9 GLuint texture_id;1.10 render_buffer_t buffer;1.11 texcache_entry_index next;1.12 @@ -230,7 +230,7 @@1.13 int i;1.14 for( i=0; i<MAX_TEXTURES; i++ ) {1.15 if( texcache_active_list[i].texture_addr != -1 &&1.16 - PVR2_TEX_IS_PALETTE(texcache_active_list[i].mode) ) {1.17 + PVR2_TEX_IS_PALETTE(texcache_active_list[i].tex_mode) ) {1.18 texcache_evict( i );1.19 texcache_free_ptr--;1.20 texcache_free_list[texcache_free_ptr] = i;1.21 @@ -246,7 +246,7 @@1.22 int i;1.23 for( i=0; i<MAX_TEXTURES; i++ ) {1.24 if( texcache_active_list[i].texture_addr != -1 &&1.25 - PVR2_TEX_IS_STRIDE(texcache_active_list[i].mode) ) {1.26 + PVR2_TEX_IS_STRIDE(texcache_active_list[i].tex_mode) ) {1.27 texcache_evict( i );1.28 texcache_free_ptr--;1.29 texcache_free_list[texcache_free_ptr] = i;1.30 @@ -254,7 +254,7 @@1.31 }1.32 }1.34 -void texcache_set_config( uint32_t palette_mode, uint32_t stride )1.35 +void texcache_begin_scene( uint32_t palette_mode, uint32_t stride )1.36 {1.37 if( palette_mode != texcache_palette_mode )1.38 texcache_invalidate_palette();1.39 @@ -579,7 +579,7 @@1.40 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);1.41 }1.43 -static int texcache_find_texture_slot( uint32_t texture_word, int width, int height )1.44 +static int texcache_find_texture_slot( uint32_t poly2_masked_word, uint32_t texture_word )1.45 {1.46 uint32_t texture_addr = (texture_word & 0x000FFFFF)<<3;1.47 uint32_t texture_page = texture_addr >> 12;1.48 @@ -587,10 +587,8 @@1.49 texcache_entry_index idx = texcache_page_lookup[texture_page];1.50 while( idx != EMPTY_ENTRY ) {1.51 texcache_entry_t entry = &texcache_active_list[idx];1.52 - if( entry->texture_addr == texture_addr &&1.53 - entry->mode == texture_word &&1.54 - entry->width == width &&1.55 - entry->height == height ) {1.56 + if( entry->tex_mode == texture_word &&1.57 + entry->poly2_mode == poly2_masked_word ) {1.58 entry->lru_count = texcache_ref_counter++;1.59 return idx;1.60 }1.61 @@ -599,7 +597,7 @@1.62 return -1;1.63 }1.65 -static int texcache_alloc_texture_slot( uint32_t texture_word, int width, int height )1.66 +static int texcache_alloc_texture_slot( uint32_t poly2_word, uint32_t texture_word )1.67 {1.68 uint32_t texture_addr = (texture_word & 0x000FFFFF)<<3;1.69 uint32_t texture_page = texture_addr >> 12;1.70 @@ -614,9 +612,8 @@1.71 /* Construct new entry */1.72 assert( texcache_active_list[slot].texture_addr == -1 );1.73 texcache_active_list[slot].texture_addr = texture_addr;1.74 - texcache_active_list[slot].width = width;1.75 - texcache_active_list[slot].height = height;1.76 - texcache_active_list[slot].mode = texture_word;1.77 + texcache_active_list[slot].tex_mode = texture_word;1.78 + texcache_active_list[slot].poly2_mode = poly2_word;1.79 texcache_active_list[slot].lru_count = texcache_ref_counter++;1.81 /* Add entry to the lookup table */1.82 @@ -640,29 +637,50 @@1.83 * Return a texture ID for the texture specified at the supplied address1.84 * and given parameters (the same sequence of bytes could in theory have1.85 * multiple interpretations). We use the texture address as the primary1.86 - * index, but allow for multiple instances at each address. The texture1.87 - * will be bound to the GL_TEXTURE_2D target before being returned.1.88 + * index, but allow for multiple instances at each address.1.89 *1.90 * If the texture has already been bound, return the ID to which it was1.91 * bound. Otherwise obtain an unused texture ID and set it up appropriately.1.92 + * The current GL_TEXTURE_2D binding will be changed in this case.1.93 */1.94 -GLuint texcache_get_texture( uint32_t texture_word, int width, int height )1.95 +GLuint texcache_get_texture( uint32_t poly2_word, uint32_t texture_word )1.96 {1.97 - int slot = texcache_find_texture_slot( texture_word, width, height );1.98 + poly2_word &= 0x000F803F; /* Get just the texture-relevant bits */1.99 + int slot = texcache_find_texture_slot( poly2_word, texture_word );1.101 if( slot == -1 ) {1.102 /* Not found - check the free list */1.103 - slot = texcache_alloc_texture_slot( texture_word, width, height );1.104 + slot = texcache_alloc_texture_slot( poly2_word, texture_word );1.106 /* Construct the GL texture */1.107 uint32_t texture_addr = (texture_word & 0x000FFFFF)<<3;1.108 + unsigned width = POLY2_TEX_WIDTH(poly2_word);1.109 + unsigned height = POLY2_TEX_HEIGHT(poly2_word);1.110 +1.111 glBindTexture( GL_TEXTURE_2D, texcache_active_list[slot].texture_id );1.112 texcache_load_texture( texture_addr, width, height, texture_word );1.113 +1.114 + /* Set texture parameters from the poly2 word */1.115 + if( POLY2_TEX_CLAMP_U(poly2_word) ) {1.116 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );1.117 + } else if( POLY2_TEX_MIRROR_U(poly2_word) ) {1.118 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB );1.119 + } else {1.120 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );1.121 + }1.122 + if( POLY2_TEX_CLAMP_V(poly2_word) ) {1.123 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );1.124 + } else if( POLY2_TEX_MIRROR_V(poly2_word) ) {1.125 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB );1.126 + } else {1.127 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );1.128 + }1.129 }1.131 return texcache_active_list[slot].texture_id;1.132 }1.134 +#if 01.135 render_buffer_t texcache_get_render_buffer( uint32_t texture_addr, int mode, int width, int height )1.136 {1.137 uint32_t texture_word = ((texture_addr >> 3) & 0x000FFFFF) | PVR2_TEX_UNTWIDDLED;1.138 @@ -693,6 +711,7 @@1.140 return entry->buffer;1.141 }1.142 +#endif1.144 /**1.145 * Check the integrity of the texcache. Verifies that every cache slot
.