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.

171 lines
4.8 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; This file contains the alpha test functions.
  4. ;
  5. ; Copyright (C) Microsoft Corporation, 1997.
  6. ;
  7. ;
  8. ;-----------------------------------------------------------------------------
  9. INCLUDE iammx.inc
  10. INCLUDE offs_acp.inc
  11. include(`m4hdr.mh')dnl
  12. include(`cvars.mh')dnl
  13. .586
  14. .model flat
  15. .code
  16. EXTERN g_uDitherValue:MMWORD
  17. ; Alpha Test compare macro
  18. ;#define ACMP(p, g, b) \
  19. ;((((((INT32)(g) - (INT32)(b)) & (p)->iAAndMask) - (p)->iANeg) >= 0) ^ (p)->iAXorMask)
  20. define(`d_LabelCounter', 0)dnl
  21. dnl
  22. dnl d_DoZWrite
  23. dnl
  24. dnl Inserts conditional Z Defered write code
  25. dnl $1 the function type, $2 is the format of the Z buffer.
  26. dnl
  27. define(`d_DoZWrite', `
  28. ifelse(`$1', `NoZWrite', `', `
  29. ifelse(`$2', `16', `
  30. ; *((UINT16*)pS->pZ) = (UINT16)pCtx->SI.uZDeferred;
  31. mov esi, XpS(pZ)
  32. movzx edx, word ptr XpCtxSI(uZDeferred)
  33. mov word ptr [esi], dx
  34. ', `
  35. ;*((UINT32*)pS->pZ) = pCtx->SI.uZDeferred;
  36. mov esi, XpS(pZ)
  37. mov edx, dword ptr XpCtxSI(uZDeferred)
  38. mov dword ptr [esi], edx
  39. ')dnl if 16
  40. ')dnl if NoZWrite
  41. ')dnl d_DoZWrite define
  42. dnl d_DoAlphaDitherTest
  43. dnl
  44. dnl
  45. dnl d_DoEnd
  46. dnl
  47. dnl $1 is NoStencil or Stencil
  48. dnl
  49. define(`d_DoEnd', `ifelse($1, `NoStencil', `
  50. ; pCtx->pfnAlphaTestPassEnd(pCtx, pP, pS);
  51. jmp dword ptr XpCtx(pfnAlphaTestPassEnd)
  52. ', `
  53. ; if (pCtx->SI.bStencilPass)
  54. ; {
  55. ; pCtx->pfnAlphaTestPassEnd(pCtx, pP, pS);
  56. ; }
  57. ; else
  58. ; {
  59. ; // in the C code this does a return, since this is the
  60. ; // last bead before write
  61. ; // pCtx->pfnAlphaTestFailEnd(pCtx, pP, pS);
  62. ; }
  63. cmp word ptr XpCtxSI(bStencilPass), 0
  64. je NoWrite ; All cases can jump to same label since all just routine to span loop.
  65. jmp dword ptr XpCtx(pfnAlphaTestPassEnd)
  66. ')')dnl
  67. dnl
  68. dnl Inserts conditional AlphaDither Test code
  69. dnl $1 the function type
  70. dnl $2 is the ZWrite type
  71. dnl $3 is the format of the Z buffer
  72. dnl $4 is whether this function do a conditional return based on stencil
  73. dnl
  74. define(`d_DoAlphaDitherTest', `ifelse(`$1', `NoAlphaDither', `', `
  75. define(`d_LabelCounter', eval(d_LabelCounter+1))dnl
  76. ;INT32 Alpha;
  77. xor eax, eax ; Prevent partial register stall. Since alpha will be one byte.
  78. ;UINT16 uDither = g_uDitherTable[pCtx->SI.uDitherOffset];
  79. mov edx, DWORD PTR g_uDitherValue ; Only need one byte for comparison.
  80. shr edx, 3 ; The dither values are shifted to make color dithering easier.
  81. ; Just shift them back down.
  82. ;if (pCtx->cActTex != 0)
  83. ;{
  84. cmp dword ptr XpCtx(cActTex), 0
  85. je NoTexture`'d_LabelCounter`'
  86. ;Alpha = RGBA_GETALPHA(pCtx->SI.TexCol[0]);
  87. mov al, byte ptr XpCtxSI(TexCol+3)
  88. jmp DoneTexture`'d_LabelCounter`'
  89. ;}
  90. ;else
  91. ;{
  92. NoTexture`'d_LabelCounter`':
  93. ;Alpha = pS->uA >> COLOR_SHIFT;
  94. mov al, byte ptr XpS(uA+1)
  95. ;}
  96. DoneTexture`'d_LabelCounter`':
  97. ;if ((Alpha & 0xff) > uDither)
  98. ;{
  99. cmp al, dl
  100. jbe DitherAlpha`'d_LabelCounter`'
  101. d_DoZWrite($2, $3)
  102. d_DoEnd($4)
  103. ;}
  104. DitherAlpha`'d_LabelCounter`':
  105. ')')dnl
  106. define(`d_AlphaHdr', `
  107. ;void MMX_AlphaTest_$1_$2_$3_$4_$5(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  108. ;{
  109. PUBLIC _MMX_AlphaTest_$1_$2_$3_$4_$5
  110. _MMX_AlphaTest_$1_$2_$3_$4_$5:
  111. ifelse(`$1', `NoAlpha',
  112. `d_DoAlphaDitherTest(`$2', `$3', `$4', `$5')', `
  113. ;if (ACMP(pCtx, pCtx->SI.uBA, pCtx->iARef))
  114. ;{
  115. movzx edx, word ptr XpCtxSI(uBA)
  116. sub edx, dword ptr XpCtx(iARef)
  117. and edx, XpCtx(iAAndMask)
  118. sub edx, XpCtx(iANeg)
  119. sar edx, 31
  120. xor edx, XpCtx(iAXorMask)
  121. test edx, edx
  122. jz NoWrite ; All cases can jump to same label since all just routine to span loop.
  123. ifelse($2, `NoAlphaDither', `
  124. d_DoZWrite(`$3', `$4')
  125. d_DoEnd($5)
  126. ', `
  127. d_DoAlphaDitherTest(`$2', `$3', `$4', `$5')
  128. ')
  129. ;}
  130. ;else
  131. ;{
  132. ;// in the C code this does a return, since this is the
  133. ;// last bead before write
  134. ;// pCtx->pfnAlphaTestFailEnd(pCtx, pP, pS);
  135. ; ASM code has everything jump to same label since it all goes to the same place.
  136. ;}')
  137. dnl
  138. ; If Alpha Test passes, but alpha dither fails, we still need to call
  139. ; AlphaTestFailEnd or code continues to run into next routine.
  140. jmp dword ptr XpCtx(pfnAlphaTestFailEnd)
  141. ;}')
  142. dnl
  143. NoWrite:
  144. jmp dword ptr XpCtx(pfnAlphaTestFailEnd)
  145. d_RepStr(`d_RepStr(`d_RepStr(`d_RepStr(`d_RepStr(`d_AlphaHdr(AA, BB, CC, DD, EE)',
  146. `AA', `NoAlpha', `Alpha')',
  147. `BB', `NoAlphaDither', `AlphaDither')',
  148. `CC', `NoZWrite', `ZWrite')',
  149. `DD', `16', `32')',
  150. `EE', `NoStencil', `Stencil')
  151. END