Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.4 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dtxman.h
  8. *
  9. * Content: D3D Texture manager definitions and macros.
  10. *
  11. * Copyright (c) 1995-1999 Microsoft Corporation. All rights Reserved.
  12. \*****************************************************************************/
  13. #ifdef __D3DTEXMAN
  14. #pragma message ("FILE : "__FILE__" : Multiple inclusion")
  15. #endif
  16. #define __D3DTEXMAN
  17. #ifndef __D3DHW
  18. #include "d3dhw.h"
  19. #endif
  20. #ifndef __DCONTEXT
  21. #include "d3dcntxt.h"
  22. #endif
  23. #define parent(k) (k / 2)
  24. #define lchild(k) (k * 2)
  25. #define rchild(k) (k * 2 + 1)
  26. __inline ULONGLONG TextureCost(PPERMEDIA_D3DTEXTURE pTexture)
  27. {
  28. #ifdef _X86_
  29. ULONGLONG retval = 0;
  30. _asm
  31. {
  32. mov ebx, pTexture;
  33. mov eax, [ebx]PERMEDIA_D3DTEXTURE.m_dwPriority;
  34. mov ecx, eax;
  35. shr eax, 1;
  36. mov DWORD PTR retval + 4, eax;
  37. shl ecx, 31;
  38. mov eax, [ebx]PERMEDIA_D3DTEXTURE.m_dwTicks;
  39. shr eax, 1;
  40. or eax, ecx;
  41. mov DWORD PTR retval, eax;
  42. }
  43. return retval;
  44. #else
  45. return ((ULONGLONG)pTexture->m_dwPriority << 31) +
  46. ((ULONGLONG)(pTexture->m_dwTicks >> 1));
  47. #endif
  48. }
  49. typedef struct _TextureHeap
  50. {
  51. DWORD m_next;
  52. DWORD m_size;
  53. PPERMEDIA_D3DTEXTURE *m_data_p;
  54. } TextureHeap, *PTextureHeap;
  55. void TextureHeapHeapify(PTextureHeap,DWORD);
  56. bool TextureHeapAdd(PTextureHeap,PPERMEDIA_D3DTEXTURE);
  57. PPERMEDIA_D3DTEXTURE TextureHeapExtractMin(PTextureHeap);
  58. PPERMEDIA_D3DTEXTURE TextureHeapExtractMax(PTextureHeap);
  59. void TextureHeapDel(PTextureHeap,DWORD);
  60. void TextureHeapUpdate(PTextureHeap,DWORD,DWORD,DWORD);
  61. typedef struct _TextureCacheManager
  62. {
  63. TextureHeap m_heap;
  64. unsigned int tcm_ticks;
  65. D3DDEVINFO_TEXTUREMANAGER m_stats;
  66. }TextureCacheManager, *PTextureCacheManager;
  67. // Free the LRU texture
  68. BOOL TextureCacheManagerFreeTextures(PTextureCacheManager,DWORD, DWORD);
  69. //remove all HW handles and release surface
  70. void TextureCacheManagerRemove(PTextureCacheManager,PPERMEDIA_D3DTEXTURE);
  71. HRESULT TextureCacheManagerAllocNode(PERMEDIA_D3DCONTEXT*,PPERMEDIA_D3DTEXTURE);
  72. HRESULT TextureCacheManagerInitialize(PTextureCacheManager);
  73. __inline void TextureCacheManagerRemoveFromHeap(
  74. PTextureCacheManager pTextureCacheManager,
  75. PPERMEDIA_D3DTEXTURE lpD3DTexI)
  76. {
  77. TextureHeapDel(&pTextureCacheManager->m_heap,lpD3DTexI->m_dwHeapIndex);
  78. }
  79. __inline void TextureCacheManagerUpdatePriority(
  80. PTextureCacheManager pTextureCacheManager,
  81. PPERMEDIA_D3DTEXTURE lpD3DTexI)
  82. {
  83. TextureHeapUpdate(&pTextureCacheManager->m_heap,
  84. lpD3DTexI->m_dwHeapIndex,
  85. lpD3DTexI->m_dwPriority, lpD3DTexI->m_dwTicks);
  86. }
  87. __inline void TextureCacheManagerIncTotSz(
  88. PTextureCacheManager pTextureCacheManager,
  89. DWORD dwSize)
  90. {
  91. ++pTextureCacheManager->m_stats.dwTotalManaged;
  92. pTextureCacheManager->m_stats.dwTotalBytes += dwSize;
  93. }
  94. __inline void TextureCacheManagerDecTotSz(
  95. PTextureCacheManager pTextureCacheManager,
  96. DWORD dwSize)
  97. {
  98. --pTextureCacheManager->m_stats.dwTotalManaged;
  99. pTextureCacheManager->m_stats.dwTotalBytes -= dwSize;
  100. }
  101. __inline void TextureCacheManagerIncNumSetTexInVid(
  102. PTextureCacheManager pTextureCacheManager)
  103. {
  104. ++pTextureCacheManager->m_stats.dwNumUsedTexInVid;
  105. }
  106. __inline void TextureCacheManagerIncNumTexturesSet(
  107. PTextureCacheManager pTextureCacheManager)
  108. {
  109. ++pTextureCacheManager->m_stats.dwNumTexturesUsed;
  110. }
  111. __inline void TextureCacheManagerResetStatCounters(
  112. PTextureCacheManager pTextureCacheManager)
  113. {
  114. pTextureCacheManager->m_stats.bThrashing = 0;
  115. pTextureCacheManager->m_stats.dwNumEvicts = 0;
  116. pTextureCacheManager->m_stats.dwNumVidCreates = 0;
  117. pTextureCacheManager->m_stats.dwNumUsedTexInVid = 0;
  118. pTextureCacheManager->m_stats.dwNumTexturesUsed = 0;
  119. }
  120. __inline void TextureCacheManagerGetStats(
  121. PERMEDIA_D3DCONTEXT *pContext,
  122. LPD3DDEVINFO_TEXTUREMANAGER stats)
  123. {
  124. memcpy(stats, &pContext->pTextureManager->m_stats,
  125. sizeof(D3DDEVINFO_TEXTUREMANAGER));
  126. }
  127. void TextureCacheManagerEvictTextures(PTextureCacheManager);
  128. void TextureCacheManagerTimeStamp(PTextureCacheManager,PPERMEDIA_D3DTEXTURE);