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.

366 lines
13 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dhw.h
  8. *
  9. * Content: D3D Global definitions and macros.
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights Reserved.
  13. \*****************************************************************************/
  14. #ifdef __D3DHW
  15. #pragma message ("FILE : "__FILE__" : Multiple inclusion")
  16. #endif
  17. #define __D3DHW
  18. #ifndef __DIRECTX
  19. #include "directx.h"
  20. #endif
  21. //-----------------------------------------------------------------------------
  22. // Known Issues in current version of the D3D driver
  23. //-----------------------------------------------------------------------------
  24. //
  25. // Stencil support is not yet completed
  26. //
  27. // Some games may have some issues when running under a Permedia 2 since this
  28. // hw has some limitations, namely:
  29. // 1) Alpha blending modes available
  30. // 2) Alpha channel interpolation is not possible
  31. // 3) There is no mip mapping support
  32. // 4) Texture filtering is applied only to textures being magnified
  33. //
  34. // Also, the fill rules of the Delta setup unit don't follow exactly the D3D
  35. // fill rules, though in practice this shouldn't be a much of a problem for
  36. // most apps.
  37. //-----------------------------------------------------------------------------
  38. // Global enabling/disabling definitions
  39. //-----------------------------------------------------------------------------
  40. // Set to 1 to enable stencil buffer support in the driver
  41. #define D3D_STENCIL 1
  42. // Code stubs to implement a T&L driver. Since the P2 does not support this
  43. // in hw, this symbol should always be set to zero.
  44. #define D3DDX7_TL 0
  45. // Code stubs to implement mip mapping, Since the P2 does not support this
  46. // natively in hw, this symbols should always be set to zero. Only shows
  47. // how/where to grab DDI info to implement it.
  48. #define D3D_MIPMAPPING 0
  49. // This code shows how to add stateblock support into your DX7 driver. It is
  50. // functional code, so this symbols should be set to one.
  51. #define D3D_STATEBLOCKS 1
  52. //-----------------------------------------------------------------------------
  53. // DX6 FVF Support declarations
  54. //-----------------------------------------------------------------------------
  55. typedef struct _P2TEXCOORDS{
  56. D3DVALUE tu;
  57. D3DVALUE tv;
  58. } P2TEXCOORDS, *LPP2TEXCOORDS;
  59. typedef struct _P2COLOR {
  60. D3DCOLOR color;
  61. } P2COLOR, *LPP2COLOR;
  62. typedef struct _P2SPECULAR {
  63. D3DCOLOR specular;
  64. } P2SPECULAR, *LPP2SPECULAR;
  65. typedef struct _P2PSIZE{
  66. D3DVALUE psize;
  67. } P2PSIZE, *LPP2PSIZE;
  68. typedef struct _P2FVFOFFSETS{
  69. DWORD dwColOffset;
  70. DWORD dwSpcOffset;
  71. DWORD dwTexOffset;
  72. DWORD dwTexBaseOffset;
  73. //@@BEGIN_DDKSPLIT
  74. #if D3D_POINTSPRITES
  75. DWORD dwPntSizeOffset;
  76. #endif // D3D_POINTSPRITES
  77. //@@END_DDKSPLIT
  78. DWORD dwStride;
  79. } P2FVFOFFSETS , *LPP2FVFOFFSETS;
  80. // track appropriate pointers to fvf vertex components
  81. __inline void __SetFVFOffsets (DWORD *lpdwColorOffs,
  82. DWORD *lpdwSpecularOffs,
  83. DWORD *lpdwTexOffs,
  84. LPP2FVFOFFSETS lpP2FVFOff)
  85. {
  86. if (lpP2FVFOff == NULL) {
  87. // Default non-FVF case , we just set up everything as for a D3DTLVERTEX
  88. *lpdwColorOffs = offsetof( D3DTLVERTEX, color);
  89. *lpdwSpecularOffs = offsetof( D3DTLVERTEX, specular);
  90. *lpdwTexOffs = offsetof( D3DTLVERTEX, tu);
  91. } else {
  92. // Use the offsets info to setup the corresponding fields
  93. *lpdwColorOffs = lpP2FVFOff->dwColOffset;
  94. *lpdwSpecularOffs = lpP2FVFOff->dwSpcOffset;
  95. *lpdwTexOffs = lpP2FVFOff->dwTexOffset;
  96. }
  97. }
  98. //Size of maximum FVF that we can get. Used for temporary storage
  99. typedef BYTE P2FVFMAXVERTEX[ 3 * sizeof( D3DVALUE ) + // Position coordinates
  100. 5 * 4 + // D3DFVF_XYZB5
  101. sizeof( D3DVALUE ) + // FVF_TRANSFORMED
  102. 3 * sizeof( D3DVALUE ) + // Normals
  103. sizeof( DWORD ) + // RESERVED1
  104. sizeof( DWORD ) + // Diffuse color
  105. sizeof( D3DCOLOR ) + // Specular color
  106. sizeof( D3DVALUE ) + // Point sprite size
  107. 4 * 8 * sizeof( D3DVALUE ) // 8 sets of 4D texture coordinates
  108. ];
  109. #define FVFTEX( lpVtx , dwOffs ) ((LPP2TEXCOORDS)((LPBYTE)(lpVtx) + dwOffs))
  110. #define FVFCOLOR( lpVtx, dwOffs ) ((LPP2COLOR)((LPBYTE)(lpVtx) + dwOffs))
  111. #define FVFSPEC( lpVtx, dwOffs) ((LPP2SPECULAR)((LPBYTE)(lpVtx) + dwOffs))
  112. #define FVFPSIZE( lpVtx, dwOffs) ((LPP2PSIZE)((LPBYTE)(lpVtx) + dwOffs))
  113. //-----------------------------------------------------------------------------
  114. // Miscelaneous definitions
  115. //-----------------------------------------------------------------------------
  116. //AZN9
  117. #ifdef SUPPORTING_MONOFLAG
  118. #define RENDER_MONO (Flags & CTXT_HAS_MONO_ENABLED)
  119. #else
  120. #define RENDER_MONO 0
  121. #endif
  122. // Defines used in the FakeBlendNum field of the P2 D3D context in order to
  123. // make up for missing features in the hw that can be easily simulated
  124. #define FAKE_ALPHABLEND_ONE_ONE 1
  125. #define FAKE_ALPHABLEND_MODULATE 2
  126. #define NOT_HANDLED DBG_D3D((4, " **Not Currently Handled**"));
  127. // This is defined in the the d3dcntxt.h header, we use it to declare functions
  128. struct _permedia_d3dcontext;
  129. typedef struct _permedia_d3dcontext PERMEDIA_D3DCONTEXT;
  130. //-----------------------------------------------------------------------------
  131. // D3D global functions and callbacks
  132. //-----------------------------------------------------------------------------
  133. // Render state processing
  134. DWORD
  135. __ProcessPermediaStates(PERMEDIA_D3DCONTEXT* pContext,
  136. DWORD Count,
  137. LPD3DSTATE lpState,
  138. LPDWORD lpStateMirror);
  139. void
  140. __HandleDirtyPermediaState(PPDev ppdev,
  141. PERMEDIA_D3DCONTEXT* pContext,
  142. LPP2FVFOFFSETS lpP2FVFOff);
  143. void __HWPreProcessTSS(PERMEDIA_D3DCONTEXT *pContext,
  144. DWORD dwStage,
  145. DWORD dwState,
  146. DWORD dwValue);
  147. // Texture functions
  148. void
  149. EnableTexturePermedia(PERMEDIA_D3DCONTEXT* pContext);
  150. void
  151. DisableTexturePermedia(PERMEDIA_D3DCONTEXT* pContext);
  152. void
  153. P2LUTDownload(PPDev ppdev,
  154. PermediaSurfaceData* pPrivateDest,
  155. PERMEDIA_D3DCONTEXT* pContext,
  156. LPDDRAWI_DDRAWSURFACE_LCL pTexture);
  157. // Chip specific
  158. BOOL
  159. SetupDefaultsPermediaContext(PERMEDIA_D3DCONTEXT* pContext);
  160. void
  161. CleanDirect3DContext(PERMEDIA_D3DCONTEXT* pContext, ULONG_PTR dwhContext);
  162. HRESULT
  163. InitPermediaContext(PERMEDIA_D3DCONTEXT* Context);
  164. void
  165. SetupCommonContext(PERMEDIA_D3DCONTEXT* pContext);
  166. void
  167. __PermediaDisableUnits(PERMEDIA_D3DCONTEXT* pContext);
  168. void
  169. DisableAllUnits(PPDev ppdev);
  170. void __DeleteAllStateSets(PERMEDIA_D3DCONTEXT* pContext);
  171. // Hardware primitive setup functions
  172. void
  173. P2_Draw_FVF_Line(PERMEDIA_D3DCONTEXT *pContext,
  174. LPD3DTLVERTEX lpV0,
  175. LPD3DTLVERTEX lpV1,
  176. LPD3DTLVERTEX lpVFlat,
  177. LPP2FVFOFFSETS lpFVFOff);
  178. void
  179. P2_Draw_FVF_Point(PERMEDIA_D3DCONTEXT *pContext,
  180. LPD3DTLVERTEX lpV0,
  181. LPP2FVFOFFSETS lpFVFOff);
  182. void
  183. P2_Draw_FVF_Point_Sprite(PERMEDIA_D3DCONTEXT *pContext,
  184. LPD3DTLVERTEX lpV0,
  185. LPP2FVFOFFSETS lpFVFOff);
  186. typedef void (D3DFVFDRAWTRIFUNC)(PERMEDIA_D3DCONTEXT *,
  187. LPD3DTLVERTEX,
  188. LPD3DTLVERTEX,
  189. LPD3DTLVERTEX,
  190. LPP2FVFOFFSETS);
  191. typedef D3DFVFDRAWTRIFUNC *D3DFVFDRAWTRIFUNCPTR;
  192. typedef void (D3DFVFDRAWPNTFUNC)(PERMEDIA_D3DCONTEXT *,
  193. LPD3DTLVERTEX,
  194. LPP2FVFOFFSETS);
  195. typedef D3DFVFDRAWPNTFUNC *D3DFVFDRAWPNTFUNCPTR;
  196. D3DFVFDRAWPNTFUNCPTR __HWSetPointFunc(PERMEDIA_D3DCONTEXT *pContext,
  197. LPP2FVFOFFSETS lpP2FVFOff);
  198. D3DFVFDRAWTRIFUNC P2_Draw_FVF_Solid_Tri;
  199. D3DFVFDRAWTRIFUNC P2_Draw_FVF_Wire_Tri;
  200. D3DFVFDRAWTRIFUNC P2_Draw_FVF_Point_Tri;
  201. // Driver callbacks
  202. void CALLBACK
  203. D3DHALCreateDriver(PPDev ppdev,
  204. LPD3DHAL_GLOBALDRIVERDATA* lpD3DGlobalDriverData,
  205. LPD3DHAL_CALLBACKS* lpD3DHALCallbacks,
  206. LPDDHAL_D3DBUFCALLBACKS* lpDDExeBufCallbacks);
  207. DWORD CALLBACK
  208. D3DValidateTextureStageState( LPD3DHAL_VALIDATETEXTURESTAGESTATEDATA lpvtssd );
  209. DWORD CALLBACK
  210. D3DDrawPrimitives2( LPD3DNTHAL_DRAWPRIMITIVES2DATA pd );
  211. DWORD CALLBACK
  212. D3DGetDriverState( LPDDHAL_GETDRIVERSTATEDATA);
  213. DWORD CALLBACK
  214. D3DCreateSurfaceEx( LPDDHAL_CREATESURFACEEXDATA);
  215. DWORD CALLBACK
  216. D3DDestroyDDLocal( LPDDHAL_DESTROYDDLOCALDATA);
  217. DWORD CALLBACK
  218. DdSetColorKey(LPDDHAL_SETCOLORKEYDATA psckd);
  219. //-----------------------------------------------------------------------------
  220. // Conversion, math and culling macros
  221. //-----------------------------------------------------------------------------
  222. /*
  223. * This loses one bit of accuracy, but adds and clamps without ifs.
  224. * We first mask all channels with 0xfe. This leaves the lsb of
  225. * each channel clear, so when the terms are added, any carry goes
  226. * into the new highest bit. Now all we have to do is generate a
  227. * mask for any channels that have overflowed. So we shift right
  228. * and eliminate everything but the overflow bits, so each channel
  229. * contains either 0x00 or 0x01. Subtracting each channel from 0x80
  230. * produces 0x7f or 0x80. We just shift this left once and mask to
  231. * give 0xfe or 0x00. (We could eliminate the final mask here, but
  232. * it would introduce noise into the low-bit of every channel..)
  233. */
  234. #define CLAMP8888(result, color, specular) \
  235. result = (color & 0xfefefefe) + (specular & 0xfefefe); \
  236. result |= ((0x808080 - ((result >> 8) & 0x010101)) & 0x7f7f7f) << 1;
  237. #define RGB256_TO_LUMA(r,g,b) (float)(((float)r * 0.001172549019608) + \
  238. ((float)g * 0.002301960784314) + \
  239. ((float)b * 0.000447058823529));
  240. #define LONG_AT(flt) (*(long *)(&flt))
  241. #define ULONG_AT(flt) (*(unsigned long *)(&flt))
  242. //Triangle culling macro
  243. #define CULL_TRI(pCtxt,p0,p1,p2) \
  244. ((pCtxt->CullMode != D3DCULL_NONE) && \
  245. (((p1->sx - p0->sx)*(p2->sy - p0->sy) <= \
  246. (p2->sx - p0->sx)*(p1->sy - p0->sy)) ? \
  247. (pCtxt->CullMode == D3DCULL_CCW) : \
  248. (pCtxt->CullMode == D3DCULL_CW) ) )
  249. ULONG inline RGB888ToHWFmt(ULONG dwRGB888Color, ULONG ColorMask, ULONG RGB888Mask)
  250. {
  251. unsigned long m;
  252. int s = 0;
  253. if (ColorMask)
  254. for (s = 0, m = ColorMask; !(m & RGB888Mask); s++)
  255. m <<= 1;
  256. return ((dwRGB888Color >> s) & ColorMask);
  257. }
  258. //-----------------------------------------------------------------------------
  259. // State Set overrides
  260. //-----------------------------------------------------------------------------
  261. #define IS_OVERRIDE(type) ((DWORD)(type) > D3DSTATE_OVERRIDE_BIAS)
  262. #define GET_OVERRIDE(type) ((DWORD)(type) - D3DSTATE_OVERRIDE_BIAS)
  263. #define MAX_STATE D3DSTATE_OVERRIDE_BIAS
  264. #define DWORD_BITS 32
  265. #define DWORD_SHIFT 5
  266. #define VALID_STATE(type) ((DWORD)(type) < 2*D3DSTATE_OVERRIDE_BIAS)
  267. typedef struct _D3DStateSet {
  268. DWORD bits[MAX_STATE >> DWORD_SHIFT];
  269. } D3DStateSet;
  270. #define STATESET_MASK(set, state) \
  271. (set).bits[((state) - 1) >> DWORD_SHIFT]
  272. #define STATESET_BIT(state) (1 << (((state) - 1) & (DWORD_BITS - 1)))
  273. #define STATESET_ISSET(set, state) \
  274. STATESET_MASK(set, state) & STATESET_BIT(state)
  275. #define STATESET_SET(set, state) \
  276. STATESET_MASK(set, state) |= STATESET_BIT(state)
  277. #define STATESET_CLEAR(set, state) \
  278. STATESET_MASK(set, state) &= ~STATESET_BIT(state)
  279. #define STATESET_INIT(set) memset(&(set), 0, sizeof(set))
  280. //-----------------------------------------------------------------------------
  281. // One special legacy texture op we can;t easily map into the new texture ops
  282. //-----------------------------------------------------------------------------
  283. #define D3DTOP_LEGACY_ALPHAOVR (0x7fffffff)
  284. // Temporary data structure we are using here until d3dnthal.h gets updated AZN
  285. typedef struct {
  286. DWORD dwOperation;
  287. DWORD dwParam;
  288. DWORD dwReserved;
  289. } P2D3DHAL_DP2STATESET;