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.

175 lines
5.6 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 "pch.cpp"
  16. #pragma hdrstop
  17. #include "mtest_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(uSB + 1, 0xff);
  40. break;
  41. case D3DSTENCILOP_DECRSAT:
  42. uS = (UINT32)max((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[D3DRENDERSTATE_STENCILWRITEMASK];
  56. uSB &= ~(pCtx->pdwRenderState[D3DRENDERSTATE_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
  68. dnl $3 is one of ZAll ZNeverAlways ZLessGreaterEqual ZEqualNotEqual ZGreaterLessEqual
  69. dnl $4 is one of NoStipple Stipple
  70. dnl $5 is one of NoStencil Stencil
  71. dnl
  72. define(`d_Test', `
  73. void CMMX_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. DPF(0, "16 bit Z with stencil should never be called");
  78. DDASSERT(0);
  79. ', eval((d_index(`$3', `ZAll') == 0) && (d_index(`$4', `NoStipple') == 0) && (d_index(`$5', `NoStencil') == 0)), `1', `
  80. DPF(0, "ZAll AND NoStipple 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. ifelse(eval((d_index(`$3', `ZNeverAlways') == 0) && (d_index(`$5', `NoStencil') == 0)), `1', `', `
  91. UINT32 uZBS = uZB >> 1;')')
  92. pS->uZ += pP->iDZDX;
  93. dnl
  94. ifelse(`$4', `Stipple', `
  95. // ATTENTION stippling unimplemented
  96. DPF(0, "stippling unimplemented");')
  97. dnl
  98. ifelse(`$5', `Stencil', `
  99. UINT32 uSB = uZB & 0xff;
  100. uZ &= ~0x7f; // clear stencil region
  101. uZB &= ~0xff;
  102. UINT32 uS; // holds final stencil value
  103. UINT32 uSR = pCtx->pdwRenderState[D3DRENDERSTATE_STENCILREF];
  104. UINT32 uMask = pCtx->pdwRenderState[D3DRENDERSTATE_STENCILMASK];
  105. if (SCMP(pCtx, uSR&uMask, uSB&uMask))
  106. {
  107. if (ZCMP32(pCtx, uZ, uZBS))
  108. {
  109. d_StencilOp(pCtx->pdwRenderState[D3DRENDERSTATE_STENCILPASS])
  110. ifelse(`$2', `ZWrite', `*((UINT32*)pS->pZ) = (uZ<<1) | uS;',
  111. `*((UINT32*)pS->pZ) = uZB | uS; // write stencil unconditionally
  112. pCtx->SI.uZDeferred = (uZ<<1) | uS;')
  113. pCtx->pfnTestPassEnd(pCtx, pP, pS);
  114. }
  115. else
  116. {
  117. d_StencilOp(pCtx->pdwRenderState[D3DRENDERSTATE_STENCILZFAIL])
  118. *((UINT32*)pS->pZ) = uZB | uS; // write stencil only
  119. ifelse(`$2', `NoZWrite', `pCtx->SI.uZDeferred = uZB | uS;')
  120. pCtx->pfnTestFailEnd(pCtx, pP, pS);
  121. }
  122. }
  123. else
  124. {
  125. d_StencilOp(pCtx->pdwRenderState[D3DRENDERSTATE_STENCILFAIL])
  126. *((UINT32*)pS->pZ) = uZB | uS; // write stencil only
  127. pCtx->pfnTestFailEnd(pCtx, pP, pS);
  128. }
  129. ', `
  130. dnl
  131. ifelse(eval((d_index(`$3', `ZNeverAlways') != 0) && (d_index(`$1', `16') != 0)), `1', `
  132. uZ &= ~0x7f; // clear stencil bits so equal compare will work
  133. uZBS &= ~0x7f;')
  134. ifelse(`$3', `ZAll', `
  135. ifelse(`$1', `16', `if (ZCMP16(pCtx, uZ, uZB))', `if (ZCMP32(pCtx, uZ, uZBS))')',
  136. `$3', `ZNeverAlways', `
  137. if (!(pCtx->iZXorMask))',
  138. `$3', `ZLessGreaterEqual', `
  139. // using bitwise XOR for logical op, OK since all bits of mask are set
  140. if ((pCtx->iZXorMask)^(uZ >= ifelse(`$1', `16', `uZB', `uZBS')))',
  141. `$3', `ZEqualNotEqual', `
  142. if ((pCtx->iZXorMask)^(uZ != ifelse(`$1', `16', `uZB', `uZBS')))',
  143. `$3', `ZGreaterLessEqual', `
  144. if ((pCtx->iZXorMask)^(uZ > ifelse(`$1', `16', `uZB', `uZBS')))', `
  145. #error Invalid arg to d_Test')
  146. {
  147. ifelse(`$2', `ZWrite', `ifelse(`$1', `16',
  148. `*((UINT16*)pS->pZ) = uZ;', `*((UINT32*)pS->pZ) = (uZ << 1);')',
  149. `pCtx->SI.uZDeferred = ifelse(`$1', `16', `uZ', `(uZ << 1)');')
  150. pCtx->pfnTestPassEnd(pCtx, pP, pS);
  151. }
  152. else
  153. {
  154. ifelse(`$2', `NoZWrite', `pCtx->SI.uZDeferred = uZB;')
  155. pCtx->pfnTestFailEnd(pCtx, pP, pS);
  156. }
  157. ')')}')dnl
  158. dnl
  159. d_RepStr(`d_RepStr(`d_RepStr(`d_Test(AA, BB, CC, NoStipple, NoStencil)',
  160. `AA', `16', `32')',
  161. `BB', `ZWrite', `NoZWrite')',
  162. `CC', `ZNeverAlways', `ZLessGreaterEqual', `ZEqualNotEqual', `ZGreaterLessEqual')
  163. d_RepStr(`d_RepStr(`d_RepStr(`d_RepStr(`d_Test(AA, BB, ZAll, CC, DD)',
  164. `AA', `16', `32')',
  165. `BB', `ZWrite', `NoZWrite')',
  166. `CC', `NoStipple', `Stipple')',
  167. `DD', `NoStencil', `Stencil')