#include <Windows.h>#include "Glide.h"#include "BaseType.h"#include "GMemMGr.h"Go to the source code of this file.
|
|
Definition at line 35 of file GCache.h. Referenced by GCache_Create(). |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 411 of file GCache.c. References AppendHack, GCache::CacheTypes, GCache_FreeAllSlots(), GCACHE_MAX_CACHE_TYPES, GCache_Slot, GCache_Type, GCache_WriteToFile(), GE_FALSE, GE_TRUE, geBoolean, GMemMgr_AllocMem(), GMemMgr_GetFreeMemory(), GMemMgr_Reset(), GCache_Type::Info, int32, GCache_Slot::MemAddr, GCache::MemMgr, NULL, GCache_Type::RefCount, GCache_Slot::SelfCheck, GCache_Type::Slots, GCache_Slot::Type, uint32, and GCache_Type::UsedSlots. Referenced by GTHandle_CheckTextures().
00412 {
00413 GCache_Type *pCacheType;
00414 int32 i;
00415
00416 GCache_FreeAllSlots(Cache);
00417
00418 GMemMgr_Reset(Cache->MemMgr); // Reset the caches memory manager
00419
00420 while(1)
00421 {
00422 GCache_Slot *LastSlot;
00423
00424 LastSlot = NULL;
00425
00426 pCacheType = Cache->CacheTypes;
00427
00428 for (i=0; i< GCACHE_MAX_CACHE_TYPES; i++, pCacheType++)
00429 {
00430 GCache_Slot *pSlot;
00431 uint32 Size;
00432
00433 if (pCacheType->RefCount <= 0)
00434 {
00435 assert(pCacheType->Slots == NULL);
00436 assert(pCacheType->UsedSlots == 0);
00437 continue;
00438 }
00439
00440 if (pCacheType->UsedSlots >= pCacheType->RefCount)
00441 continue; // This is all we need for this slot...
00442
00443 if (!pCacheType->Slots) // If no slots have been allocated, allocate them now...
00444 {
00445 assert(pCacheType->UsedSlots == 0);
00446
00447 pCacheType->Slots = malloc(sizeof(GCache_Type)*pCacheType->RefCount);
00448
00449 if (!pCacheType->Slots)
00450 return GE_FALSE;
00451
00452 memset(pCacheType->Slots, 0, sizeof(GCache_Type)*pCacheType->RefCount);
00453 }
00454
00455 Size = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, &pCacheType->Info);
00456
00457 if (GMemMgr_GetFreeMemory(Cache->MemMgr) < Size)
00458 break; // Took all available ram from memmgr. No choice, but to stop
00459
00460 pSlot = &pCacheType->Slots[pCacheType->UsedSlots++];
00461 pSlot->SelfCheck = pSlot;
00462
00463 pSlot->Type = pCacheType;
00464
00465 if (!GMemMgr_AllocMem(Cache->MemMgr, Size, &pSlot->MemAddr))
00466 {
00467 pCacheType->UsedSlots--; // Cancel last operation
00468 break;
00469 }
00470
00471 LastSlot = pSlot;
00472 }
00473
00474 if (!LastSlot) // Nothing was allocated on that pass, so assume we are out of memory
00475 break;
00476 }
00477
00478 pCacheType = Cache->CacheTypes;
00479
00480 // Go through one last time, and make sure all got allocated
00481 for (i=0; i< GCACHE_MAX_CACHE_TYPES; i++, pCacheType++)
00482 {
00483 if (pCacheType->RefCount <= 0)
00484 {
00485 assert(pCacheType->Slots == NULL);
00486 assert(pCacheType->UsedSlots == 0);
00487 continue;
00488 }
00489
00490 if (pCacheType->UsedSlots <= 0) // Oops...
00491 return GE_FALSE;
00492
00493 assert(pCacheType->Slots != NULL);
00494 }
00495
00496 #ifdef GCACHE_WRITELOG
00497 GCache_WriteToFile(Cache, "GCache.Log", AppendHack);
00498
00499 AppendHack = GE_TRUE;
00500 #endif
00501
00502 return GE_TRUE;
00503 }
|
|
||||||||||||
|
Definition at line 94 of file GCache.c. References GCache, GCACHE_MAX_NAME, GCache_Reset(), GCache::LastMemAddr, GCache::MemMgr, MemMgr, GCache::Name, NULL, and GCache::SelfCheck. Referenced by GTHandle_Startup().
00095 {
00096 GCache *Cache;
00097
00098 assert(Name);
00099 assert(strlen(Name) < GCACHE_MAX_NAME);
00100 assert(MemMgr);
00101
00102 Cache = malloc(sizeof(GCache));
00103
00104 if (!Cache)
00105 return NULL;
00106
00107 memset(Cache, 0, sizeof(GCache));
00108
00109 strcpy(Cache->Name, Name);
00110
00111 Cache->MemMgr = MemMgr;
00112
00113 Cache->LastMemAddr = 0xffffffff;
00114
00115 Cache->SelfCheck = Cache;
00116
00117 if (!GCache_Reset(Cache))
00118 goto ExitWithError;
00119
00120 return Cache;
00121
00122 ExitWithError:
00123 {
00124 if (Cache)
00125 free(Cache);
00126
00127 return NULL;
00128 }
00129 }
|
|
|
Definition at line 134 of file GCache.c. Referenced by GTHandle_FreeAllCaches().
00135 {
00136 assert(Cache);
00137
00138 free(Cache);
00139 }
|
|
||||||||||||
|
Definition at line 168 of file GCache.c. References GCache::CacheTypes, GCACHE_MAX_CACHE_TYPES, GCache_Type, GCache_Type::Info, int32, NULL, and GCache_Type::RefCount. Referenced by GCache_TypeCreate().
00169 {
00170 int32 i;
00171 GCache_Type *pCacheType;
00172
00173 pCacheType = Cache->CacheTypes;
00174
00175 for (i=0; i<GCACHE_MAX_CACHE_TYPES; i++, pCacheType++)
00176 {
00177 //uint32 Size;
00178
00179 if (pCacheType->RefCount == 0) // Nobody is using this slot yet
00180 continue;
00181
00182 if (Info->smallLod != pCacheType->Info.smallLod)
00183 continue;
00184 if (Info->largeLod != pCacheType->Info.largeLod)
00185 continue;
00186 if (Info->aspectRatio != pCacheType->Info.aspectRatio)
00187 continue;
00188
00189 if (Info->format != pCacheType->Info.format)
00190 continue;
00191
00192 #if 0
00193 // Check to see if the size required to create the surface matches
00194 Size = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, (GrTexInfo*)Info);
00195
00196 //if (Size != pCacheType->Size)
00197 continue;
00198 #endif
00199
00200 return pCacheType; // Found a match
00201 }
00202
00203 return NULL; // Cache Type not found!!!
00204 }
|
|
|
Definition at line 322 of file GCache.c. References GCache::CacheTypes, GCACHE_MAX_CACHE_TYPES, GCache_Type, GE_TRUE, geBoolean, int32, NULL, GCache_Type::RefCount, GCache_Type::Slots, and GCache_Type::UsedSlots. Referenced by GCache_AdjustSlots(), and GCache_Reset().
00323 {
00324 int32 i;
00325 GCache_Type *pCacheType;
00326
00327 pCacheType = Cache->CacheTypes;
00328
00329 for (i=0; i< GCACHE_MAX_CACHE_TYPES; i++, pCacheType++)
00330 {
00331 assert(pCacheType->RefCount >= 0);
00332
00333 if (pCacheType->RefCount == 0)
00334 {
00335 assert(pCacheType->Slots == NULL);
00336 assert(pCacheType->UsedSlots == 0);
00337 continue;
00338 }
00339
00340 if (pCacheType->Slots)
00341 {
00342 assert(pCacheType->UsedSlots > 0);
00343 free(pCacheType->Slots);
00344 }
00345 else
00346 assert(pCacheType->UsedSlots == 0);
00347
00348 pCacheType->Slots = NULL;
00349 pCacheType->UsedSlots = 0;
00350 }
00351
00352 return GE_TRUE;
00353 }
|
|
||||||||||||||||||||||||
|
Definition at line 208 of file GCache.c. References GCache::CacheTypes, GCACHE_MAX_CACHE_TYPES, GCache_Type, GCache_Type::Height, GCache_Type::Info, int32, NULL, GCache_Type::NumMipLevels, GCache_Type::RefCount, GCache_Type::Size, GCache_Type::Slots, uint8, GCache_Type::UsedSlots, and GCache_Type::Width. Referenced by GCache_TypeCreate().
00209 {
00210 int32 i;
00211 GCache_Type *pCacheType;
00212
00213 assert(NumMipLevels <= 255);
00214 assert(NumMipLevels >= 0);
00215
00216 pCacheType = Cache->CacheTypes;
00217
00218 for (i=0; i<GCACHE_MAX_CACHE_TYPES; i++, pCacheType++)
00219 {
00220 if (pCacheType->RefCount == 0) // Nobody is using this slot yet
00221 {
00222 assert(pCacheType->Slots == NULL);
00223 assert(pCacheType->UsedSlots == 0);
00224 break;
00225 }
00226 }
00227
00228 if (i == GCACHE_MAX_CACHE_TYPES) // No types left
00229 return NULL;
00230
00231 pCacheType->Info = *Info;
00232 pCacheType->Info.data = NULL;
00233 pCacheType->Width = Width;
00234 pCacheType->Height = Height;
00235 pCacheType->NumMipLevels = (uint8)NumMipLevels;
00236 pCacheType->Size = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, (GrTexInfo*)Info);
00237
00238 // Found one
00239 pCacheType->RefCount++;
00240
00241 return pCacheType;
00242 }
|
|
|
Definition at line 143 of file GCache.c. References GCache::CacheTypes, GCache_FreeAllSlots(), GCACHE_MAX_CACHE_TYPES, GCache_Type, GE_TRUE, geBoolean, and int32. Referenced by GCache_Create().
00144 {
00145 int32 i;
00146 GCache_Type *pCacheType;
00147
00148 GCache_FreeAllSlots(Cache);
00149
00150 for (pCacheType = Cache->CacheTypes, i=0; i<GCACHE_MAX_CACHE_TYPES; i++, pCacheType++)
00151 {
00152 memset(pCacheType, 0, sizeof(GCache_Type));
00153
00154 #ifdef DYNAMIC_CACHE
00155 // Set prev/next pointers in array
00156 if (i > 0)
00157 pCacheType->PrevNext[0] = (pCacheType-1);
00158 if (i < GCACHE_MAX_CACHE_TYPES-1)
00159 pCacheType->PrevNext[1] = (pCacheType+1);
00160 #endif
00161 }
00162
00163 return GE_TRUE;
00164 }
|
|
||||||||||||
|
Definition at line 259 of file GCache.c. References GCache_SlotIsValid(), GE_TRUE, geBoolean, GMemMgr_GetTmu(), GCache_Type::Info, GCache::LastMemAddr, GCache_Slot::LRU, GCache_Slot::MemAddr, GCache::MemMgr, and GCache_Slot::Type.
00260 {
00261 assert(GCache_SlotIsValid(Slot));
00262
00263 if (Cache->LastMemAddr == Slot->MemAddr)
00264 return GE_TRUE;
00265
00266 grTexSource(GMemMgr_GetTmu(Cache->MemMgr), Slot->MemAddr, GR_MIPMAPLEVELMASK_BOTH, &Slot->Type->Info);
00267
00268 Cache->LastMemAddr = Slot->MemAddr;
00269
00270 Slot->LRU++;
00271
00272 return GE_TRUE;
00273 }
|
|
|
Definition at line 701 of file GCache.c. References GCache_SlotIsValid(), GCache_Type::Info, and GCache_Slot::Type. Referenced by DownloadLightmap(), RenderLightmapPoly(), and SetupTexture().
00702 {
00703 assert(GCache_SlotIsValid(Slot));
00704
00705 return &Slot->Type->Info;
00706 }
|
|
|
Definition at line 508 of file GCache.c. References GCache_SlotIsValid(), GCache_Slot::MemAddr, and uint32. Referenced by RenderLightmapPoly(), and SetupTexture().
00509 {
00510 assert(GCache_SlotIsValid(Slot));
00511
00512 return Slot->MemAddr;
00513 }
|
|
|
Definition at line 691 of file GCache.c. References GCache_SlotIsValid(), and GCache_Slot::UserData. Referenced by SetupLMapTexture(), and SetupTexture().
00692 {
00693 assert(GCache_SlotIsValid(Slot));
00694
00695 return Slot->UserData;
00696 }
|
|
|
Definition at line 518 of file GCache.c. References GE_FALSE, GE_TRUE, geBoolean, and GCache_Slot::SelfCheck. Referenced by GCache_SetTexture(), GCache_SlotGetInfo(), GCache_SlotGetMemAddress(), GCache_SlotGetUserData(), GCache_SlotSetLRU(), GCache_SlotSetUserData(), and GCache_UpdateSlot().
|
|
||||||||||||
|
Definition at line 711 of file GCache.c. References GCache_SlotIsValid(), and GCache_Slot::LRU. Referenced by RenderLightmapPoly(), SetupLMapTexture(), and SetupTexture().
00712 {
00713 assert(GCache_SlotIsValid(Slot));
00714
00715 Slot->LRU = LRU;
00716 }
|
|
||||||||||||
|
Definition at line 681 of file GCache.c. References GCache_SlotIsValid(), and GCache_Slot::UserData. Referenced by SetupLMapTexture(), and SetupTexture().
00682 {
00683 assert(GCache_SlotIsValid(Slot));
00684
00685 Slot->UserData = UserData;
00686 }
|
|
||||||||||||||||||||||||
|
Definition at line 277 of file GCache.c. References GCache_FindCacheTypeByInfo(), GCache_InsertCacheTypeByInfo(), GCache_Type, and GCache_Type::RefCount. Referenced by Create3DTexture(), and CreateLightmapTexture().
00278 {
00279 GCache_Type *CacheType;
00280
00281 CacheType = GCache_FindCacheTypeByInfo(Cache, Info);
00282
00283 if (CacheType)
00284 {
00285 CacheType->RefCount++;
00286 return CacheType;
00287 }
00288
00289 // Could not find one allready in the list, so add a new one...
00290 return GCache_InsertCacheTypeByInfo(Cache, Width, Height, NumMipLevels, Info);
00291 }
|
|
|
Definition at line 296 of file GCache.c. References NULL, GCache_Type::RefCount, GCache_Type::Slots, and GCache_Type::UsedSlots. Referenced by GTHandle_FreeTextureHandle().
00297 {
00298 assert(CacheType->RefCount > 0);
00299
00300 CacheType->RefCount--;
00301
00302 if (CacheType->RefCount == 0)
00303 {
00304 if (CacheType->Slots)
00305 {
00306 assert(CacheType->UsedSlots > 0);
00307 free(CacheType->Slots);
00308 }
00309 else
00310 {
00311 assert(CacheType->UsedSlots == 0);
00312 }
00313
00314 CacheType->UsedSlots = 0;
00315 CacheType->Slots = NULL;
00316 }
00317 }
|
|
|
Definition at line 640 of file GCache.c. References GCache_Slot, int32, GCache_Slot::LRU, NULL, GCache_Type::Slots, uint32, GCache_Type::UsedSlots, and GCache_Slot::UserData. Referenced by SetupLMapTexture(), and SetupTexture().
00641 {
00642 GCache_Slot *pBestSlot, *pSlot;
00643 uint32 BestLRU;
00644 int32 i;
00645
00646 assert(CacheType->Slots);
00647
00648 #ifdef DYNAMIC_CACHE
00649 // First, try to steal a slot from one of our neigbors...
00650 // Try the biggest side first
00651 if (pBestSlot = GCache_TypeGrow(CacheType))
00652 goto GotIt;
00653 #endif
00654
00655 pSlot = CacheType->Slots;
00656 pBestSlot = pSlot;
00657 BestLRU = pBestSlot->LRU;
00658
00659 for (i=0; i< CacheType->UsedSlots; i++, pSlot++)
00660 {
00661 if (pSlot->LRU < BestLRU)
00662 {
00663 pBestSlot = pSlot;
00664 BestLRU = pSlot->LRU;
00665 }
00666 }
00667
00668 #ifdef DYNAMIC_CACHE
00669 GotIt:
00670 #endif
00671
00672 pBestSlot->LRU = 0;
00673 pBestSlot->UserData = NULL;
00674
00675 return pBestSlot;
00676 }
|
|
||||||||||||||||
|
Definition at line 247 of file GCache.c. References GCache_SlotIsValid(), GE_TRUE, geBoolean, GMemMgr_GetTmu(), GCache_Slot::MemAddr, and GCache::MemMgr. Referenced by DownloadLightmap(), and SetupTexture().
00248 {
00249 assert(GCache_SlotIsValid(Slot));
00250
00251 grTexDownloadMipMap(GMemMgr_GetTmu(Cache->MemMgr), Slot->MemAddr, GR_MIPMAPLEVELMASK_BOTH, Info);
00252
00253 return GE_TRUE;
00254 }
|
1.3.2