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.

190 lines
6.2 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains texture addressing functions.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. // WARNING WARNING WARNING
  8. // This cpp file generated from mcp file.
  9. // EDIT THE MCP FILE.
  10. // I warned you.
  11. // WARNING WARNING WARNING
  12. //
  13. //-----------------------------------------------------------------------------
  14. include(`m4hdr.mh')dnl
  15. #include "rgb_pch.h"
  16. #pragma hdrstop
  17. #include "ctest_mh.h"
  18. dnl
  19. dnl d_StencilOp
  20. dnl
  21. dnl Macro to do stencil operation test routine
  22. dnl
  23. dnl $1 is one of STENCILFUNC
  24. dnl returns new stencil value in uS
  25. dnl
  26. define(`d_StencilOp', `
  27. switch($1)
  28. {
  29. case D3DSTENCILOP_KEEP:
  30. uS = uSB;
  31. break;
  32. case D3DSTENCILOP_ZERO:
  33. uS = 0;
  34. break;
  35. case D3DSTENCILOP_REPLACE:
  36. uS = uSR;
  37. break;
  38. case D3DSTENCILOP_INCRSAT:
  39. uS = min< INT32>(uSB + 1, 0xff);
  40. break;
  41. case D3DSTENCILOP_DECRSAT:
  42. uS = (UINT32)max< INT32>((INT32)uSB - 1, 0x00);
  43. break;
  44. case D3DSTENCILOP_INVERT:
  45. uS = ~uSB;
  46. break;
  47. case D3DSTENCILOP_INCR:
  48. uS = uSB + 1;
  49. break;
  50. case D3DSTENCILOP_DECR:
  51. uS = uSB - 1;
  52. break;
  53. }
  54. // do write mask, do not let stencil mess up Z bits
  55. uS &= pCtx->pdwRenderState[D3DRS_STENCILWRITEMASK];
  56. uSB &= ~(pCtx->pdwRenderState[D3DRS_STENCILWRITEMASK]);
  57. uS |= uSB;
  58. uS &= 0xff;
  59. ')dnl
  60. dnl
  61. dnl
  62. dnl d_Test
  63. dnl
  64. dnl Macro to build test routine
  65. dnl
  66. dnl $1 is one of 16 32
  67. dnl $2 is one of ZWrite NoZWrite (D3DRS_ZWRITEENABLE)
  68. dnl $3 is one of ZDeferred NoZDeferred (is there an alpha test bead)
  69. dnl $4 is one of ZAll ZNeverAlways ZLessGreaterEqual ZEqualNotEqual ZGreaterLessEqual
  70. dnl $5 is one of NoStencil Stencil
  71. dnl
  72. define(`d_Test', `
  73. void C_Test_$1_$2_$3_$4_$5(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  74. PD3DI_RASTSPAN pS)
  75. {
  76. ifelse(eval((d_index(`$1', `16') == 0) && (d_index(`$5', `Stencil') == 0)), `1', `
  77. // D3D_WARN(0, "16 bit Z with stencil should never be called");
  78. // DDASSERT(0);
  79. ', eval((d_index(`$4', `ZAll') == 0) && (d_index(`$5', `NoStencil') == 0)), `1', `
  80. // D3D_WARN(0, "ZAll AND NoStencil, more optimal code should be called");
  81. // DDASSERT(0);
  82. ', `
  83. ifelse(`$1', `16', `
  84. // 16 bit unsigned format
  85. UINT16 uZ = (UINT16)(pS->uZ>>15);
  86. UINT16 uZB = *((UINT16*)pS->pZ);', `
  87. // 24S8 bit unsigned format
  88. UINT32 uZ = pS->uZ;
  89. UINT32 uZB = *((UINT32*)pS->pZ);
  90. UINT32 uSB = uZB & 0xff;
  91. ifelse(eval((d_index(`$4', `ZNeverAlways') == 0) && (d_index(`$5', `NoStencil') == 0)), `1', `', `
  92. UINT32 uZBS = uZB >> 1;')')
  93. pS->uZ += pP->iDZDX;
  94. dnl
  95. ifelse(`$5', `Stencil', `
  96. uZ &= ~0x7f; // clear stencil region
  97. uZBS &= ~0x7f;
  98. uZB &= ~0xff;
  99. UINT32 uS; // holds final stencil value
  100. UINT32 uSR = pCtx->pdwRenderState[D3DRS_STENCILREF];
  101. UINT32 uMask = pCtx->pdwRenderState[D3DRS_STENCILMASK];
  102. pCtx->SI.bStencilPass = FALSE;
  103. if (SCMP(pCtx, uSR&uMask, uSB&uMask))
  104. {
  105. if (ZCMP32(pCtx, uZ, uZBS))
  106. {
  107. // true only if should write RGB after potential alpha test
  108. pCtx->SI.bStencilPass = TRUE;
  109. d_StencilOp(pCtx->pdwRenderState[D3DRS_STENCILPASS])
  110. ifelse(`$3', `NoZDeferred', `*((UINT32*)pS->pZ) = ifelse($2, `ZWrite', `(uZ<<1)', `uZB') | uS;',
  111. `pCtx->SI.uZDeferred = ifelse($2, `ZWrite', `(uZ<<1)', `uZB') | uS;')
  112. pCtx->pfnTestPassEnd(pCtx, pP, pS);
  113. }
  114. else
  115. {
  116. d_StencilOp(pCtx->pdwRenderState[D3DRS_STENCILZFAIL])
  117. // write stencil only
  118. ifelse(`$3', `NoZDeferred', `*((UINT32*)pS->pZ) = uZB | uS;',
  119. `pCtx->SI.uZDeferred = uZB | uS;')
  120. pCtx->pfnTestFailEnd(pCtx, pP, pS);
  121. }
  122. }
  123. else
  124. {
  125. d_StencilOp(pCtx->pdwRenderState[D3DRS_STENCILFAIL])
  126. // write stencil only
  127. ifelse(`$3', `NoZDeferred', `*((UINT32*)pS->pZ) = uZB | uS;',
  128. `pCtx->SI.uZDeferred = uZB | uS;')
  129. pCtx->pfnTestFailEnd(pCtx, pP, pS);
  130. }
  131. ', `
  132. dnl
  133. ifelse(eval((d_index(`$4', `ZNeverAlways') != 0) && (d_index(`$1', `16') != 0)), `1', `
  134. uZ &= ~0x7f; // clear stencil bits so equal compare will work
  135. uZBS &= ~0x7f;')
  136. ifelse(`$4', `ZAll', `
  137. ifelse(`$1', `16', `if (ZCMP16(pCtx, uZ, uZB))', `if (ZCMP32(pCtx, uZ, uZBS))')',
  138. `$4', `ZNeverAlways', `
  139. if (!(pCtx->iZXorMask))',
  140. `$4', `ZLessGreaterEqual', `
  141. // using bitwise XOR for logical op, OK since all bits of mask are set
  142. if ((pCtx->iZXorMask)^(uZ >= ifelse(`$1', `16', `uZB', `uZBS')))',
  143. `$4', `ZEqualNotEqual', `
  144. if ((pCtx->iZXorMask)^(uZ != ifelse(`$1', `16', `uZB', `uZBS')))',
  145. `$4', `ZGreaterLessEqual', `
  146. if ((pCtx->iZXorMask)^(uZ > ifelse(`$1', `16', `uZB', `uZBS')))', `
  147. #error Invalid arg to d_Test')
  148. {
  149. ifelse(`$3', `NoZDeferred',
  150. `ifelse(`$1', `16',
  151. `ifelse($2, `ZWrite',
  152. `*((UINT16*)pS->pZ) = uZ;',
  153. `//*((UINT16*)pS->pZ) = uZB; Done already')',
  154. `ifelse($2, `ZWrite',
  155. `*((UINT32*)pS->pZ) = (uZ<<1) | uSB;',
  156. `*((UINT32*)pS->pZ) = uZB | uSB;')')',
  157. `ifelse(`$1', `16',
  158. `ifelse($2, `ZWrite',
  159. `pCtx->SI.uZDeferred = uZ;',
  160. `pCtx->SI.uZDeferred = uZB;')',
  161. `ifelse($2, `ZWrite',
  162. `pCtx->SI.uZDeferred = (uZ<<1) | uSB;',
  163. `pCtx->SI.uZDeferred = uZB | uSB;')')')
  164. pCtx->pfnTestPassEnd(pCtx, pP, pS);
  165. }
  166. else
  167. {
  168. ifelse(`$3', `ZDeferred', `pCtx->SI.uZDeferred = uZB;')
  169. pCtx->pfnTestFailEnd(pCtx, pP, pS);
  170. }
  171. ')')}')dnl
  172. dnl
  173. d_RepStr(`d_RepStr(`d_RepStr(`d_RepStr(`d_Test(AA, BB, CC, DD, NoStencil)',
  174. `AA', `16', `32')',
  175. `BB', `NoZWrite', `ZWrite')',
  176. `CC', `NoZDeferred', `ZDeferred')',
  177. `DD', `ZNeverAlways', `ZLessGreaterEqual', `ZEqualNotEqual', `ZGreaterLessEqual')
  178. d_RepStr(`d_RepStr(`d_RepStr(`d_RepStr(`d_Test(AA, BB, CC, ZAll, DD)',
  179. `AA', `16', `32')',
  180. `BB', `NoZWrite', `ZWrite')',
  181. `CC', `NoZDeferred', `ZDeferred')',
  182. `DD', `NoStencil', `Stencil')