Search
lxdream.org :: lxdream/src/pvr2/texcache.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/texcache.c
changeset 653:3202ff01d48e
prev561:533f6b478071
next654:d40b3b68fbdf
author nkeynes
date Fri Mar 28 12:32:25 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Merge lxdream-render branch (643:670) to trunk
file annotate diff log raw
1.1 --- a/src/pvr2/texcache.c Tue Jan 01 05:08:38 2008 +0000
1.2 +++ b/src/pvr2/texcache.c Fri Mar 28 12:32:25 2008 +0000
1.3 @@ -19,6 +19,7 @@
1.4 */
1.5
1.6 #include <assert.h>
1.7 +#include <string.h>
1.8 #include "pvr2/pvr2.h"
1.9
1.10 /** Specifies the maximum number of OpenGL
1.11 @@ -67,6 +68,7 @@
1.12 for( i=0; i<MAX_TEXTURES; i++ ) {
1.13 texcache_free_list[i] = i;
1.14 texcache_active_list[i].texture_addr = -1;
1.15 + texcache_active_list[i].next = EMPTY_ENTRY;
1.16 }
1.17 texcache_free_ptr = 0;
1.18 texcache_ref_counter = 0;
1.19 @@ -99,6 +101,7 @@
1.20 }
1.21 for( i=0; i<MAX_TEXTURES; i++ ) {
1.22 texcache_free_list[i] = i;
1.23 + texcache_active_list[i].next = EMPTY_ENTRY;
1.24 }
1.25 texcache_free_ptr = 0;
1.26 texcache_ref_counter = 0;
1.27 @@ -507,25 +510,25 @@
1.28 * If the texture has already been bound, return the ID to which it was
1.29 * bound. Otherwise obtain an unused texture ID and set it up appropriately.
1.30 */
1.31 -GLuint texcache_get_texture( uint32_t texture_addr, int width, int height,
1.32 - int mode )
1.33 +GLuint texcache_get_texture( uint32_t texture_word, int width, int height )
1.34 {
1.35 + uint32_t texture_addr = (texture_word & 0x000FFFFF)<<3;
1.36 uint32_t texture_page = texture_addr >> 12;
1.37 texcache_entry_index next;
1.38 texcache_entry_index idx = texcache_page_lookup[texture_page];
1.39 while( idx != EMPTY_ENTRY ) {
1.40 texcache_entry_t entry = &texcache_active_list[idx];
1.41 if( entry->texture_addr == texture_addr &&
1.42 - entry->mode == mode &&
1.43 + entry->mode == texture_word &&
1.44 entry->width == width &&
1.45 entry->height == height ) {
1.46 entry->lru_count = texcache_ref_counter++;
1.47 - glBindTexture( GL_TEXTURE_2D, entry->texture_id );
1.48 return entry->texture_id;
1.49 }
1.50 idx = entry->next;
1.51 }
1.52
1.53 +
1.54 /* Not found - check the free list */
1.55 texcache_entry_index slot = 0;
1.56
1.57 @@ -539,7 +542,7 @@
1.58 texcache_active_list[slot].texture_addr = texture_addr;
1.59 texcache_active_list[slot].width = width;
1.60 texcache_active_list[slot].height = height;
1.61 - texcache_active_list[slot].mode = mode;
1.62 + texcache_active_list[slot].mode = texture_word;
1.63 texcache_active_list[slot].lru_count = texcache_ref_counter++;
1.64
1.65 /* Add entry to the lookup table */
1.66 @@ -560,7 +563,45 @@
1.67
1.68 /* Construct the GL texture */
1.69 glBindTexture( GL_TEXTURE_2D, texcache_active_list[slot].texture_id );
1.70 - texcache_load_texture( texture_addr, width, height, mode );
1.71 -
1.72 + texcache_load_texture( texture_addr, width, height, texture_word );
1.73 +
1.74 return texcache_active_list[slot].texture_id;
1.75 }
1.76 +
1.77 +/**
1.78 + * Check the integrity of the texcache. Verifies that every cache slot
1.79 + * appears exactly once on either the free list or one page list. For
1.80 + * active slots, the texture address must also match the page it appears on.
1.81 + *
1.82 + */
1.83 +void texcache_integrity_check()
1.84 +{
1.85 + int i;
1.86 + int slot_found[MAX_TEXTURES];
1.87 +
1.88 + memset( slot_found, 0, sizeof(slot_found) );
1.89 +
1.90 + /* Check entries on the free list */
1.91 + for( i= texcache_free_ptr; i< MAX_TEXTURES; i++ ) {
1.92 + int slot = texcache_free_list[i];
1.93 + assert( slot_found[slot] == 0 );
1.94 + assert( texcache_active_list[slot].next == EMPTY_ENTRY );
1.95 + slot_found[slot] = 1;
1.96 + }
1.97 +
1.98 + /* Check entries on the active lists */
1.99 + for( i=0; i< PVR2_RAM_PAGES; i++ ) {
1.100 + int slot = texcache_page_lookup[i];
1.101 + while( slot != EMPTY_ENTRY ) {
1.102 + assert( slot_found[slot] == 0 );
1.103 + assert( (texcache_active_list[slot].texture_addr >> 12) == i );
1.104 + slot_found[slot] = 2;
1.105 + slot = texcache_active_list[slot].next;
1.106 + }
1.107 + }
1.108 +
1.109 + /* Make sure we didn't miss any entries */
1.110 + for( i=0; i<MAX_TEXTURES; i++ ) {
1.111 + assert( slot_found[i] != 0 );
1.112 + }
1.113 +}
.