revision 1135:68daed8f38af
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 1135:68daed8f38af |
parent | 1134:f502f3d32f90 |
child | 1136:078a2202958a |
author | nkeynes |
date | Sun Oct 24 11:50:17 2010 +1000 (13 years ago) |
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
(This does mean that if the texture is used with variant parameters it will be
loaded multiple times). 3-4% faster this way
src/pvr2/glrender.c | view | annotate | diff | log | ||
src/pvr2/pvr2.h | view | annotate | diff | log | ||
src/pvr2/texcache.c | view | annotate | diff | log |
1.1 --- a/src/pvr2/glrender.c Fri Oct 22 20:55:32 2010 +10001.2 +++ b/src/pvr2/glrender.c Sun Oct 24 11:50:17 2010 +10001.3 @@ -61,20 +61,16 @@1.4 {1.5 int i;1.7 - texcache_set_config( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03,1.8 + texcache_begin_scene( MMIO_READ( PVR2, RENDER_PALETTE ) & 0x03,1.9 (MMIO_READ( PVR2, RENDER_TEXSIZE ) & 0x003F) << 5 );1.11 for( i=0; i < pvr2_scene.poly_count; i++ ) {1.12 struct polygon_struct *poly = &pvr2_scene.poly_array[i];1.13 if( POLY1_TEXTURED(poly->context[0]) ) {1.14 - poly->tex_id = texcache_get_texture( poly->context[2],1.15 - POLY2_TEX_WIDTH(poly->context[1]),1.16 - POLY2_TEX_HEIGHT(poly->context[1]) );1.17 + poly->tex_id = texcache_get_texture( poly->context[1], poly->context[2] );1.18 if( poly->mod_vertex_index != -1 ) {1.19 if( pvr2_scene.shadow_mode == SHADOW_FULL ) {1.20 - poly->mod_tex_id = texcache_get_texture( poly->context[4],1.21 - POLY2_TEX_WIDTH(poly->context[3]),1.22 - POLY2_TEX_HEIGHT(poly->context[3]) );1.23 + poly->mod_tex_id = texcache_get_texture( poly->context[3], poly->context[4] );1.24 } else {1.25 poly->mod_tex_id = poly->tex_id;1.26 }1.27 @@ -155,21 +151,6 @@1.28 if( POLY1_TEXTURED(poly1) ) {1.29 glEnable(GL_TEXTURE_2D);1.30 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, pvr2_poly_texblend[POLY2_TEX_BLEND(poly2)] );1.31 -1.32 - if( POLY2_TEX_CLAMP_U(poly2) ) {1.33 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );1.34 - } else if( POLY2_TEX_MIRROR_U(poly2) ) {1.35 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB );1.36 - } else {1.37 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );1.38 - }1.39 - if( POLY2_TEX_CLAMP_V(poly2) ) {1.40 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );1.41 - } else if( POLY2_TEX_MIRROR_V(poly2) ) {1.42 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB );1.43 - } else {1.44 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );1.45 - }1.46 } else {1.47 glDisable( GL_TEXTURE_2D );1.48 }
2.1 --- a/src/pvr2/pvr2.h Fri Oct 22 20:55:32 2010 +10002.2 +++ b/src/pvr2/pvr2.h Sun Oct 24 11:50:17 2010 +10002.3 @@ -344,7 +344,7 @@2.4 * Set the global texture parameters for the scene (possibly invalidating2.5 * some existing textures)2.6 */2.7 -void texcache_set_config( uint32_t palette_mode, uint32_t stride_width );2.8 +void texcache_begin_scene( uint32_t palette_mode, uint32_t stride_width );2.10 /**2.11 * Return a texture ID for the texture specified at the supplied address2.12 @@ -356,7 +356,7 @@2.13 * If the texture has already been bound, return the ID to which it was2.14 * bound. Otherwise obtain an unused texture ID and set it up appropriately.2.15 */2.16 -GLuint texcache_get_texture( uint32_t texture_word, int width, int height );2.17 +GLuint texcache_get_texture( uint32_t poly2_word, uint32_t texture_word );2.19 render_buffer_t texcache_get_render_buffer( uint32_t texture_addr, int mode, int width, int height );
3.1 --- a/src/pvr2/texcache.c Fri Oct 22 20:55:32 2010 +10003.2 +++ b/src/pvr2/texcache.c Sun Oct 24 11:50:17 2010 +10003.3 @@ -47,7 +47,7 @@3.5 typedef struct texcache_entry {3.6 uint32_t texture_addr;3.7 - int width, height, mode;3.8 + uint32_t poly2_mode, tex_mode;3.9 GLuint texture_id;3.10 render_buffer_t buffer;3.11 texcache_entry_index next;3.12 @@ -230,7 +230,7 @@3.13 int i;3.14 for( i=0; i<MAX_TEXTURES; i++ ) {3.15 if( texcache_active_list[i].texture_addr != -1 &&3.16 - PVR2_TEX_IS_PALETTE(texcache_active_list[i].mode) ) {3.17 + PVR2_TEX_IS_PALETTE(texcache_active_list[i].tex_mode) ) {3.18 texcache_evict( i );3.19 texcache_free_ptr--;3.20 texcache_free_list[texcache_free_ptr] = i;3.21 @@ -246,7 +246,7 @@3.22 int i;3.23 for( i=0; i<MAX_TEXTURES; i++ ) {3.24 if( texcache_active_list[i].texture_addr != -1 &&3.25 - PVR2_TEX_IS_STRIDE(texcache_active_list[i].mode) ) {3.26 + PVR2_TEX_IS_STRIDE(texcache_active_list[i].tex_mode) ) {3.27 texcache_evict( i );3.28 texcache_free_ptr--;3.29 texcache_free_list[texcache_free_ptr] = i;3.30 @@ -254,7 +254,7 @@3.31 }3.32 }3.34 -void texcache_set_config( uint32_t palette_mode, uint32_t stride )3.35 +void texcache_begin_scene( uint32_t palette_mode, uint32_t stride )3.36 {3.37 if( palette_mode != texcache_palette_mode )3.38 texcache_invalidate_palette();3.39 @@ -579,7 +579,7 @@3.40 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);3.41 }3.43 -static int texcache_find_texture_slot( uint32_t texture_word, int width, int height )3.44 +static int texcache_find_texture_slot( uint32_t poly2_masked_word, uint32_t texture_word )3.45 {3.46 uint32_t texture_addr = (texture_word & 0x000FFFFF)<<3;3.47 uint32_t texture_page = texture_addr >> 12;3.48 @@ -587,10 +587,8 @@3.49 texcache_entry_index idx = texcache_page_lookup[texture_page];3.50 while( idx != EMPTY_ENTRY ) {3.51 texcache_entry_t entry = &texcache_active_list[idx];3.52 - if( entry->texture_addr == texture_addr &&3.53 - entry->mode == texture_word &&3.54 - entry->width == width &&3.55 - entry->height == height ) {3.56 + if( entry->tex_mode == texture_word &&3.57 + entry->poly2_mode == poly2_masked_word ) {3.58 entry->lru_count = texcache_ref_counter++;3.59 return idx;3.60 }3.61 @@ -599,7 +597,7 @@3.62 return -1;3.63 }3.65 -static int texcache_alloc_texture_slot( uint32_t texture_word, int width, int height )3.66 +static int texcache_alloc_texture_slot( uint32_t poly2_word, uint32_t texture_word )3.67 {3.68 uint32_t texture_addr = (texture_word & 0x000FFFFF)<<3;3.69 uint32_t texture_page = texture_addr >> 12;3.70 @@ -614,9 +612,8 @@3.71 /* Construct new entry */3.72 assert( texcache_active_list[slot].texture_addr == -1 );3.73 texcache_active_list[slot].texture_addr = texture_addr;3.74 - texcache_active_list[slot].width = width;3.75 - texcache_active_list[slot].height = height;3.76 - texcache_active_list[slot].mode = texture_word;3.77 + texcache_active_list[slot].tex_mode = texture_word;3.78 + texcache_active_list[slot].poly2_mode = poly2_word;3.79 texcache_active_list[slot].lru_count = texcache_ref_counter++;3.81 /* Add entry to the lookup table */3.82 @@ -640,29 +637,50 @@3.83 * Return a texture ID for the texture specified at the supplied address3.84 * and given parameters (the same sequence of bytes could in theory have3.85 * multiple interpretations). We use the texture address as the primary3.86 - * index, but allow for multiple instances at each address. The texture3.87 - * will be bound to the GL_TEXTURE_2D target before being returned.3.88 + * index, but allow for multiple instances at each address.3.89 *3.90 * If the texture has already been bound, return the ID to which it was3.91 * bound. Otherwise obtain an unused texture ID and set it up appropriately.3.92 + * The current GL_TEXTURE_2D binding will be changed in this case.3.93 */3.94 -GLuint texcache_get_texture( uint32_t texture_word, int width, int height )3.95 +GLuint texcache_get_texture( uint32_t poly2_word, uint32_t texture_word )3.96 {3.97 - int slot = texcache_find_texture_slot( texture_word, width, height );3.98 + poly2_word &= 0x000F803F; /* Get just the texture-relevant bits */3.99 + int slot = texcache_find_texture_slot( poly2_word, texture_word );3.101 if( slot == -1 ) {3.102 /* Not found - check the free list */3.103 - slot = texcache_alloc_texture_slot( texture_word, width, height );3.104 + slot = texcache_alloc_texture_slot( poly2_word, texture_word );3.106 /* Construct the GL texture */3.107 uint32_t texture_addr = (texture_word & 0x000FFFFF)<<3;3.108 + unsigned width = POLY2_TEX_WIDTH(poly2_word);3.109 + unsigned height = POLY2_TEX_HEIGHT(poly2_word);3.110 +3.111 glBindTexture( GL_TEXTURE_2D, texcache_active_list[slot].texture_id );3.112 texcache_load_texture( texture_addr, width, height, texture_word );3.113 +3.114 + /* Set texture parameters from the poly2 word */3.115 + if( POLY2_TEX_CLAMP_U(poly2_word) ) {3.116 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );3.117 + } else if( POLY2_TEX_MIRROR_U(poly2_word) ) {3.118 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB );3.119 + } else {3.120 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );3.121 + }3.122 + if( POLY2_TEX_CLAMP_V(poly2_word) ) {3.123 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );3.124 + } else if( POLY2_TEX_MIRROR_V(poly2_word) ) {3.125 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB );3.126 + } else {3.127 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );3.128 + }3.129 }3.131 return texcache_active_list[slot].texture_id;3.132 }3.134 +#if 03.135 render_buffer_t texcache_get_render_buffer( uint32_t texture_addr, int mode, int width, int height )3.136 {3.137 uint32_t texture_word = ((texture_addr >> 3) & 0x000FFFFF) | PVR2_TEX_UNTWIDDLED;3.138 @@ -693,6 +711,7 @@3.140 return entry->buffer;3.141 }3.142 +#endif3.144 /**3.145 * Check the integrity of the texcache. Verifies that every cache slot
.