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.

343 lines
12 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // setup.hpp
  4. //
  5. // Setup declarations.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #ifndef _SETUP_HPP_
  11. #define _SETUP_HPP_
  12. #pragma warning(disable:4786)
  13. #include "stp_base.h"
  14. // PrimProcessor flags.
  15. #define PPF_IN_BEGIN 0x00000001
  16. #define PPF_STATE_CHANGED 0x00000002
  17. #define PPF_NORMALIZE_RHW 0x00000004
  18. #define PPF_DRAW_LAST_LINE_PIXEL 0x00000008
  19. // Bounds for normalized RHWs. These are not quite the ideal bounds to
  20. // avoid over- and underflow after normalization when at least one RHW is
  21. // guaranteed to be at the bounds. There is no reason it
  22. // has to be normalized to [0,1] anway, other than to try and spread
  23. // the values across the desired range.
  24. #define NORMALIZED_RHW_MIN g_fZero
  25. #define NORMALIZED_RHW_MAX g_fp95
  26. //----------------------------------------------------------------------------
  27. //
  28. // PrimProcessor
  29. //
  30. // Accepts primitives to be rasterized. Primitive and span descriptions
  31. // are put into a buffer for later processing by the span-level code.
  32. //
  33. //----------------------------------------------------------------------------
  34. class DllExport PrimProcessor
  35. {
  36. public:
  37. PrimProcessor(void);
  38. HRESULT Initialize(void);
  39. ~PrimProcessor(void);
  40. inline UINT GetFlags(void);
  41. inline void SetFlags(UINT uFlags);
  42. inline void ClrFlags(UINT uFlags);
  43. inline void StateChanged();
  44. void SetCtx(PD3DI_RASTCTX pCtx);
  45. void BeginPrimSet(D3DPRIMITIVETYPE PrimType,
  46. RAST_VERTEX_TYPE VertType);
  47. HRESULT Point(LPD3DTLVERTEX pV0,
  48. LPD3DTLVERTEX pFlatVtx);
  49. HRESULT Line(LPD3DTLVERTEX pV0,
  50. LPD3DTLVERTEX pV1,
  51. LPD3DTLVERTEX pFlatVtx);
  52. HRESULT Tri(LPD3DTLVERTEX pV0,
  53. LPD3DTLVERTEX pV1,
  54. LPD3DTLVERTEX pV2);
  55. void Begin(void);
  56. HRESULT End(void);
  57. HRESULT AllocSpans(PUINT pcSpans, PD3DI_RASTSPAN *ppSpan);
  58. void FreeSpans(UINT cSpans);
  59. private:
  60. // Original FP control word.
  61. UINT16 m_uFpCtrl;
  62. // Buffer space and current pointer.
  63. PUINT8 m_pBuffer;
  64. PUINT8 m_pBufferStart;
  65. PUINT8 m_pBufferEnd;
  66. PUINT8 m_pCur;
  67. // Flags.
  68. UINT m_uPpFlags;
  69. //
  70. // Intermediate results shared between methods.
  71. //
  72. SETUPCTX m_StpCtx;
  73. // Previous primitive, for primitive chaining.
  74. PD3DI_RASTPRIM m_pOldPrim;
  75. // Attribute function table index.
  76. INT m_iAttrFnIdx;
  77. // Old primitive and vertex types.
  78. D3DPRIMITIVETYPE m_PrimType;
  79. RAST_VERTEX_TYPE m_VertType;
  80. //
  81. // Triangle values.
  82. //
  83. // Y values and trapezoid heights.
  84. INT m_iY1, m_iY2;
  85. UINT m_uHeight10, m_uHeight21, m_uHeight20;
  86. // Triangle X extent.
  87. INT m_iXWidth;
  88. // Original RHW saved during RHW normalization.
  89. D3DVALUE m_dvV0RHW;
  90. D3DVALUE m_dvV1RHW;
  91. D3DVALUE m_dvV2RHW;
  92. //
  93. // Point methods.
  94. //
  95. void NormalizePointRHW(LPD3DTLVERTEX pV0);
  96. void FillPointSpan(LPD3DTLVERTEX pV0, PD3DI_RASTSPAN pSpan);
  97. //
  98. // Line methods.
  99. //
  100. void NormalizeLineRHW(LPD3DTLVERTEX pV0, LPD3DTLVERTEX pV1);
  101. BOOL PointDiamondCheck(INT32 iXFrac, INT32 iYFrac,
  102. BOOL bSlopeIsOne, BOOL bSlopeIsPosOne);
  103. BOOL LineSetup(LPD3DTLVERTEX pV0, LPD3DTLVERTEX pV1);
  104. //
  105. // Triangle methods.
  106. //
  107. void NormalizeTriRHW(LPD3DTLVERTEX pV0, LPD3DTLVERTEX pV1,
  108. LPD3DTLVERTEX pV2);
  109. BOOL TriSetup(LPD3DTLVERTEX pV0, LPD3DTLVERTEX pV1, LPD3DTLVERTEX pV2);
  110. inline void SetTriFunctions(void);
  111. //
  112. // Buffer management methods.
  113. //
  114. inline void ResetBuffer(void);
  115. HRESULT Flush(void);
  116. HRESULT FlushPartial(void);
  117. HRESULT AppendPrim(void);
  118. #if DBG
  119. //
  120. // Debug methods. Only callable within DBG builds.
  121. //
  122. inline HRESULT ValidateVertex(LPD3DTLVERTEX pV);
  123. #endif
  124. };
  125. //----------------------------------------------------------------------------
  126. //
  127. // PrimProcessor::GetFlags
  128. //
  129. // Returns the current PrimProcessor flags.
  130. //
  131. //----------------------------------------------------------------------------
  132. inline UINT
  133. PrimProcessor::GetFlags(void)
  134. {
  135. return m_uPpFlags;
  136. }
  137. //----------------------------------------------------------------------------
  138. //
  139. // PrimProcessor::SetFlags
  140. //
  141. // Sets the given flags.
  142. //
  143. //----------------------------------------------------------------------------
  144. inline void
  145. PrimProcessor::SetFlags(UINT uFlags)
  146. {
  147. m_uPpFlags |= uFlags;
  148. }
  149. //----------------------------------------------------------------------------
  150. //
  151. // PrimProcessor::ClrFlags
  152. //
  153. // Clears the given flags.
  154. //
  155. //----------------------------------------------------------------------------
  156. inline void
  157. PrimProcessor::ClrFlags(UINT uFlags)
  158. {
  159. m_uPpFlags &= ~uFlags;
  160. }
  161. //----------------------------------------------------------------------------
  162. //
  163. // PrimProcessor::StateChanged
  164. //
  165. // Notifies the PrimProcessor that state has changed.
  166. // Could be done through SetFlags but this hides the actual implementation.
  167. //
  168. //----------------------------------------------------------------------------
  169. inline void
  170. PrimProcessor::StateChanged(void)
  171. {
  172. m_uPpFlags |= PPF_STATE_CHANGED;
  173. }
  174. //----------------------------------------------------------------------------
  175. //
  176. // PrimProcessor::ComputeIntCarry
  177. //
  178. // Takes an FP coordinate value and span delta and computes integer form
  179. // for int/carry arithmetic.
  180. //
  181. // NOTE: Assumes iV already computed.
  182. //
  183. // Written as a macro because the compiler doesn't inline it even when
  184. // declared as an inline method.
  185. //
  186. //----------------------------------------------------------------------------
  187. // Prototype is:
  188. // inline void
  189. // PrimProcessor::ComputeIntCarry(FLOAT fV, FLOAT fDVDS, PINTCARRYVAL pICY)
  190. //
  191. // Fraction is biased by one to handle exactly-integer coordinate
  192. // values properly.
  193. #define ComputeIntCarry(fV, fDVDS, pICY) \
  194. ((pICY)->iFrac = (SCALED_FRACTION((fV) - FLOORF(fV)) - 1) & 0x7fffffff, \
  195. (pICY)->iNC = FTOI(fDVDS), \
  196. (pICY)->iDFrac = SCALED_FRACTION((fDVDS) - (pICY)->iNC), \
  197. (pICY)->iCY = FLOAT_LTZ(fDVDS) ? (pICY)->iNC - 1 : (pICY)->iNC + 1)
  198. //----------------------------------------------------------------------------
  199. //
  200. // PrimProcessor::GetPrim
  201. //
  202. // Moves prim pointer to the next position in the buffer, flushing
  203. // to make space if necessary. Checks to see if there's space for
  204. // at least one span also since it doesn't make much sense to not
  205. // flush if there's exactly enough space for just the prim structure.
  206. //
  207. // Does not update m_pCur until CommitPrim. m_pCur == pPrim
  208. // indicates pPrim is not fully valid.
  209. //
  210. // Written as a macro because the compiler doesn't inline it even when
  211. // declared as an inline method.
  212. //
  213. //----------------------------------------------------------------------------
  214. #define GET_PRIM() \
  215. { \
  216. if (m_pCur + (sizeof(D3DI_RASTPRIM) + sizeof(D3DI_RASTSPAN)) > \
  217. m_pBufferEnd) \
  218. { \
  219. HRESULT hr; \
  220. \
  221. RSHRRET(Flush()); \
  222. } \
  223. \
  224. m_StpCtx.pPrim = (PD3DI_RASTPRIM)m_pCur; \
  225. }
  226. //----------------------------------------------------------------------------
  227. //
  228. // PrimProcessor::CommitPrim
  229. //
  230. // Commits the current primitive space so that spans may be added.
  231. // The primitive data can be partly or fulled cleared as part of
  232. // the commit.
  233. //
  234. // Written as a macro because the compiler doesn't inline it even when
  235. // declared as an inline method.
  236. //
  237. //----------------------------------------------------------------------------
  238. #define COMMIT_PRIM(bClearAll) \
  239. { \
  240. m_pCur = (PUINT8)(m_StpCtx.pPrim + 1); \
  241. \
  242. if (m_pOldPrim != NULL) \
  243. { \
  244. m_pOldPrim->pNext = m_StpCtx.pPrim; \
  245. } \
  246. m_pOldPrim = m_StpCtx.pPrim; \
  247. \
  248. if (bClearAll) \
  249. { \
  250. memset(m_StpCtx.pPrim, 0, sizeof(*m_StpCtx.pPrim)); \
  251. } \
  252. else \
  253. { \
  254. m_StpCtx.pPrim->uSpans = 0; \
  255. m_StpCtx.pPrim->pNext = NULL; \
  256. } \
  257. }
  258. #define ALLOC_SPANS(pStpCtx, pcSpans, ppSpan) \
  259. ((PrimProcessor *)pStpCtx->PrimProcessor)->AllocSpans(pcSpans, ppSpan)
  260. #define FREE_SPANS(pStpCtx, cSpans) \
  261. ((PrimProcessor *)pStpCtx->PrimProcessor)->FreeSpans(cSpans)
  262. // Compute texture difference times 1/W.
  263. #define PERSP_TEXTURE_DELTA(fTb, fRb, fTa, fTRa, iWrap) \
  264. ((TextureDiff((fTb), (fTa), (iWrap)) + (fTa)) * (fRb) - (fTRa))
  265. // Extract components from a packed color.
  266. #define SPLIT_COLOR(uPacked, uB, uG, uR, uA) \
  267. ((uB) = (UINT)RGBA_GETBLUE(uPacked), \
  268. (uG) = (UINT)RGBA_GETGREEN(uPacked), \
  269. (uR) = (UINT)RGBA_GETRED(uPacked), \
  270. (uA) = (UINT)RGBA_GETALPHA(uPacked))
  271. // Compute FP deltas from the difference of the given packed color
  272. // and the given components.
  273. #define COLOR_DELTA(uPacked, uB, uG, uR, uA, fDB, fDG, fDR, fDA) \
  274. ((fDB) = (FLOAT)((INT)((UINT)RGBA_GETBLUE(uPacked)-(uB)) << COLOR_SHIFT), \
  275. (fDG) = (FLOAT)((INT)((UINT)RGBA_GETGREEN(uPacked)-(uG)) << COLOR_SHIFT),\
  276. (fDR) = (FLOAT)((INT)((UINT)RGBA_GETRED(uPacked)-(uR)) << COLOR_SHIFT), \
  277. (fDA) = (FLOAT)((INT)((UINT)RGBA_GETALPHA(uPacked)-(uA)) << COLOR_SHIFT))
  278. // Extract components from a packed index color.
  279. // Applies a .5F offset to the color index to effect rounding
  280. // when the color index is truncated.
  281. #define SPLIT_IDX_COLOR(uPacked, iIdx, iA) \
  282. ((iIdx) = (INT32)CI_MASKALPHA(uPacked) + (1<<(INDEX_COLOR_VERTEX_SHIFT-1)), \
  283. (iA) = (INT32)CI_GETALPHA(uPacked))
  284. #define IDX_COLOR_DELTA(uPacked, iIdx, iA, fDIdx, fDA) \
  285. ((fDIdx) = (FLOAT)((((INT32)CI_MASKALPHA(uPacked) + \
  286. (1<<(INDEX_COLOR_VERTEX_SHIFT-1))) - (iIdx)) << \
  287. INDEX_COLOR_FIXED_SHIFT), \
  288. (fDA) = (FLOAT)(((INT32)CI_GETALPHA(uPacked) - (iA)) << \
  289. INDEX_COLOR_SHIFT))
  290. #endif // #ifndef _SETUP_HPP_