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.

246 lines
7.3 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dtxman.h
  8. *
  9. * Content: D3D Texture cache manager definitions and macros.
  10. *
  11. * Copyright (c) 1995-2003 Microsoft Corporation. All rights Reserved.
  12. \*****************************************************************************/
  13. #ifndef __D3DTEXMAN
  14. #define __D3DTEXMAN
  15. #if DX7_TEXMANAGEMENT
  16. __inline ULONGLONG TextureCost(P3_SURF_INTERNAL* pTexture)
  17. {
  18. #ifdef _X86_
  19. ULONGLONG retval = 0;
  20. _asm
  21. {
  22. mov ebx, pTexture;
  23. mov eax, [ebx]P3_SURF_INTERNAL.m_dwPriority;
  24. mov ecx, eax;
  25. shr eax, 1;
  26. mov DWORD PTR retval + 4, eax;
  27. shl ecx, 31;
  28. mov eax, [ebx]P3_SURF_INTERNAL.m_dwTicks;
  29. shr eax, 1;
  30. or eax, ecx;
  31. mov DWORD PTR retval, eax;
  32. }
  33. return retval;
  34. #else
  35. return ((ULONGLONG)pTexture->m_dwPriority << 31) +
  36. ((ULONGLONG)(pTexture->m_dwTicks >> 1));
  37. #endif
  38. }
  39. typedef struct _TextureHeap
  40. {
  41. DWORD m_next;
  42. DWORD m_size;
  43. P3_SURF_INTERNAL **m_data_p;
  44. } TextureHeap, *PTextureHeap;
  45. typedef struct _TextureCacheManager
  46. {
  47. TextureHeap m_heap;
  48. unsigned int tcm_ticks;
  49. #if DX7_TEXMANAGEMENT_STATS
  50. D3DDEVINFO_TEXTUREMANAGER m_stats;
  51. #endif
  52. }TextureCacheManager, *PTextureCacheManager;
  53. //
  54. // Texture Management function declarations
  55. //
  56. void __TM_TextureHeapHeapify(PTextureHeap,DWORD);
  57. BOOL __TM_TextureHeapAddSurface(PTextureHeap,P3_SURF_INTERNAL *);
  58. P3_SURF_INTERNAL* __TM_TextureHeapExtractMin(PTextureHeap);
  59. P3_SURF_INTERNAL* __TM_TextureHeapExtractMax(PTextureHeap);
  60. void __TM_TextureHeapDelSurface(PTextureHeap,DWORD);
  61. void __TM_TextureHeapUpdate(PTextureHeap,DWORD,DWORD,DWORD);
  62. BOOL __TM_FreeTextures(P3_D3DCONTEXT* , DWORD);
  63. HRESULT _D3D_TM_Ctx_Initialize(P3_D3DCONTEXT* pContext);
  64. void _D3D_TM_Ctx_Destroy(P3_D3DCONTEXT* pContext);
  65. void _D3D_TM_RemoveTexture(P3_THUNKEDDATA* pThisDisplay, P3_SURF_INTERNAL*);
  66. void _D3D_TM_RemoveDDSurface(P3_THUNKEDDATA* , LPDDRAWI_DDRAWSURFACE_LCL);
  67. HRESULT _D3D_TM_AllocTexture(P3_D3DCONTEXT*,P3_SURF_INTERNAL*);
  68. void _D3D_TM_EvictAllManagedTextures(P3_D3DCONTEXT*);
  69. void _DD_TM_EvictAllManagedTextures(P3_THUNKEDDATA* pThisDisplay);
  70. void _D3D_TM_TimeStampTexture(PTextureCacheManager,P3_SURF_INTERNAL*);
  71. BOOL _D3D_TM_Preload_Tex_IntoVidMem(P3_D3DCONTEXT*, P3_SURF_INTERNAL*);
  72. void _D3D_TM_MarkDDSurfaceAsDirty(P3_THUNKEDDATA*,LPDDRAWI_DDRAWSURFACE_LCL, BOOL);
  73. void _D3D_TM_HW_FreeVidmemSurface(P3_THUNKEDDATA*,P3_SURF_INTERNAL*);
  74. void _D3D_TM_HW_AllocVidmemSurface(P3_D3DCONTEXT*,P3_SURF_INTERNAL*);
  75. //
  76. // Macros to get surface offset and pointer
  77. //
  78. #if WNT_DDRAW
  79. #define DDSURF_GETPOINTER(pSurfGbl, pThisDisplay) \
  80. (pSurfGbl->fpVidMem + (FLATPTR)pThisDisplay->ppdev->pjScreen)
  81. #define D3DMIPLVL_GETPOINTER(pMipLevel, pThisDisplay) \
  82. (pMipLevel->fpVidMem + (FLATPTR)pThisDisplay->ppdev->pjScreen)
  83. #define D3DSURF_GETPOINTER(pSurfInt, pThisDisplay) \
  84. (pSurfInt->fpVidMem + (FLATPTR)pThisDisplay->ppdev->pjScreen)
  85. #define D3DTMMIPLVL_GETOFFSET(mipLevel, pThisDisplay) \
  86. (mipLevel.fpVidMemTM)
  87. #else
  88. #define DDSURF_GETPOINTER(pSurfGbl, pThisDisplay) \
  89. (pSurfGbl->fpVidMem)
  90. #define D3DMIPLVL_GETPOINTER(pMipLevel, pThisDisplay) \
  91. (pMipLevel->fpVidMem)
  92. #define D3DSURF_GETPOINTER(pSurfInt, pThisDisplay) \
  93. (pSurfInt->fpVidMem)
  94. #define D3DTMMIPLVL_GETOFFSET(mipLevel, pThisDisplay) \
  95. (mipLevel.fpVidMemTM - pThisDisplay->dwScreenFlatAddr)
  96. #endif // WNT_DDRAW
  97. //
  98. // Inline function definitions
  99. //
  100. __inline void _D3D_TM_InitSurfData(P3_SURF_INTERNAL* pD3DSurf,
  101. LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl)
  102. {
  103. pD3DSurf->m_dwBytes = pD3DSurf->wHeight * pD3DSurf->lPitch;
  104. pD3DSurf->m_bTMNeedUpdate = TRUE;
  105. pD3DSurf->dwCaps2= pDDSLcl->lpSurfMore->ddsCapsEx.dwCaps2;
  106. pD3DSurf->m_dwTexLOD = 0;
  107. }
  108. #if DX7_TEXMANAGEMENT_STATS
  109. __inline void __TM_STAT_Inc_TotSz(
  110. PTextureCacheManager pTextureCacheManager,
  111. P3_SURF_INTERNAL* pD3DSurf)
  112. {
  113. ++pTextureCacheManager->m_stats.dwTotalManaged;
  114. pTextureCacheManager->m_stats.dwTotalBytes += pD3DSurf->m_dwBytes;
  115. }
  116. __inline void __TM_STAT_Inc_WrkSet(
  117. PTextureCacheManager pTextureCacheManager,
  118. P3_SURF_INTERNAL* pD3DSurf)
  119. {
  120. ++pTextureCacheManager->m_stats.dwWorkingSet;
  121. pTextureCacheManager->m_stats.dwWorkingSetBytes += pD3DSurf->m_dwBytes;
  122. }
  123. __inline void __TM_STAT_Dec_TotSz(
  124. PTextureCacheManager pTextureCacheManager,
  125. P3_SURF_INTERNAL* pD3DSurf)
  126. {
  127. --pTextureCacheManager->m_stats.dwTotalManaged;
  128. pTextureCacheManager->m_stats.dwTotalBytes -= pD3DSurf->m_dwBytes;
  129. }
  130. __inline void __TM_STAT_Dec_WrkSet(
  131. PTextureCacheManager pTextureCacheManager,
  132. P3_SURF_INTERNAL* pD3DSurf)
  133. {
  134. --pTextureCacheManager->m_stats.dwWorkingSet;
  135. pTextureCacheManager->m_stats.dwWorkingSetBytes -= pD3DSurf->m_dwBytes;
  136. }
  137. __inline void _D3D_TM_STAT_Inc_NumUsedTexInVid(P3_D3DCONTEXT *pContext,
  138. P3_SURF_INTERNAL* pD3DSurf)
  139. {
  140. if (pD3DSurf->m_dwHeapIndex)
  141. {
  142. ++pContext->pTextureManager->m_stats.dwNumUsedTexInVid;
  143. }
  144. }
  145. __inline void _D3D_TM_STAT_Inc_NumTexturesUsed(P3_D3DCONTEXT *pContext)
  146. {
  147. ++pContext->pTextureManager->m_stats.dwNumTexturesUsed;
  148. }
  149. __inline void _D3D_TM_STAT_ResetCounters(P3_D3DCONTEXT *pContext)
  150. {
  151. pContext->pTextureManager->m_stats.bThrashing = 0;
  152. pContext->pTextureManager->m_stats.dwNumEvicts = 0;
  153. pContext->pTextureManager->m_stats.dwNumVidCreates = 0;
  154. pContext->pTextureManager->m_stats.dwNumUsedTexInVid = 0;
  155. pContext->pTextureManager->m_stats.dwNumTexturesUsed = 0;
  156. }
  157. __inline void _D3D_TM_STAT_GetStats(P3_D3DCONTEXT *pContext,
  158. D3DDEVINFO_TEXTUREMANAGER* stats)
  159. {
  160. memcpy(stats,
  161. &pContext->pTextureManager->m_stats,
  162. sizeof(D3DDEVINFO_TEXTUREMANAGER));
  163. }
  164. #else
  165. // since we won't collect any stats, we just don't do anything
  166. // inside these inlined functions
  167. __inline void __TM_STAT_Inc_TotSz(
  168. PTextureCacheManager pTextureCacheManager,
  169. P3_SURF_INTERNAL* pD3DSurf)
  170. {
  171. NULL;
  172. }
  173. __inline void __TM_STAT_Inc_WrkSet(
  174. PTextureCacheManager pTextureCacheManager,
  175. P3_SURF_INTERNAL* pD3DSurf)
  176. {
  177. NULL;
  178. }
  179. __inline void __TM_STAT_Dec_TotSz(
  180. PTextureCacheManager pTextureCacheManager,
  181. P3_SURF_INTERNAL* pD3DSurf)
  182. {
  183. NULL;
  184. }
  185. __inline void __TM_STAT_Dec_WrkSet(
  186. PTextureCacheManager pTextureCacheManager,
  187. P3_SURF_INTERNAL* pD3DSurf)
  188. {
  189. NULL;
  190. }
  191. __inline void _D3D_TM_STAT_Inc_NumUsedTexInVid(P3_D3DCONTEXT *pContext,
  192. P3_SURF_INTERNAL* pD3DSurf)
  193. {
  194. NULL;
  195. }
  196. __inline void _D3D_TM_STAT_Inc_NumTexturesUsed(P3_D3DCONTEXT *pContext)
  197. {
  198. NULL;
  199. }
  200. __inline void _D3D_TM_STAT_ResetCounters(P3_D3DCONTEXT *pContext)
  201. {
  202. NULL;
  203. }
  204. #endif // DX7_TEXMANAGEMENT_STATS
  205. #endif // DX7_TEXMANAGEMENT
  206. #endif // __D3DTEXMAN