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.

469 lines
11 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 27. Perspective Correct Nearest Gouraud Modulated
  4. ; NO Z buffer X888.
  5. ;
  6. ; Exactly the same as monolith 6 except color input is 32 bits and
  7. ; output is 32 bits and no Z buffer code
  8. ;
  9. ;-----------------------------------------------------------------------------
  10. INCLUDE iammx.inc
  11. INCLUDE offs_acp.inc
  12. ; Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
  13. ; at the LSB, then six bits of green, then five bits of red.
  14. ;TBD check to see if this value is correct.
  15. COLOR_SHIFT equ 8
  16. .586
  17. .model flat
  18. .data
  19. EXTERN IncHighandLow16:MMWORD
  20. EXTERN UFracVFracMask:MMWORD
  21. EXTERN UV32to15Mask:MMWORD
  22. EXTERN Makelow16one:MMWORD
  23. EXTERN MaskKeepUValues:MMWORD
  24. EXTERN MaskKeepVValues:MMWORD
  25. EXTERN UFrac:MMWORD
  26. EXTERN VFrac:MMWORD
  27. EXTERN Zero:MMWORD
  28. EXTERN memD3DTFG_POINT:MMWORD
  29. EXTERN GiveUp:MMWORD
  30. EXTERN LastW:MMWORD
  31. EXTERN Val0x000a000a:MMWORD
  32. EXTERN Val0xffff:MMWORD
  33. EXTERN Val0x0000002000000020:MMWORD
  34. EXTERN Val0x0000ffff0000ffff:MMWORD
  35. opt_MaskRed565to888 MMWORD 000000000000F800H
  36. EXTERN MaskRed565to888:MMWORD
  37. EXTERN MaskGreen565to888:MMWORD
  38. EXTERN MaskBlue565to888:MMWORD
  39. EXTERN MaskRed555to888:MMWORD
  40. EXTERN MaskGreen555to888:MMWORD
  41. EXTERN MaskBlue555to888:MMWORD
  42. EXTERN MaskAlpha1555to8888:MMWORD
  43. EXTERN MaskRed1555to8888:MMWORD
  44. EXTERN MaskGreen1555to8888:MMWORD
  45. EXTERN MaskBlue1555to8888:MMWORD
  46. EXTERN SetAlphato0xffff:MMWORD
  47. EXTERN SetAlphato0xff:MMWORD
  48. RedShift565to888 equ 8
  49. GreenShift565to888 equ 5
  50. BlueShift565to888 equ 3
  51. RedShift555to888 equ 9
  52. GreenShift555to888 equ 6
  53. BlueShift555to888 equ 3
  54. AlphaShift1555to8888 equ 16
  55. RedShift1555to8888 equ 9
  56. GreenShift1555to8888 equ 6
  57. BlueShift1555to8888 equ 3
  58. EXTERN Zero:MMWORD
  59. EXTERN DW_One_One:MMWORD
  60. EXTERN MaskOffAlpha:MMWORD
  61. EXTERN ShiftTA:MMWORD
  62. EXTERN Val0x00ff00ff00ff00ff:MMWORD
  63. EXTERN Val0x000000ff00ff00ff:MMWORD
  64. EXTERN Val0X0000000001000000:MMWORD
  65. EXTERN AlphaVal128:MMWORD
  66. EXTERN RGBVal128:MMWORD
  67. EXTERN g_uDitherValue:MMWORD
  68. EXTERN SetAlphato0xff:MMWORD
  69. EXTERN u888to565RedBlueMask:MMWORD
  70. EXTERN u888to565GreenMask:MMWORD
  71. EXTERN u888to565Multiplier:MMWORD
  72. EXTERN uVal0x000007ff03ff07ff:MMWORD
  73. EXTERN uVal0x0000078003c00780:MMWORD
  74. EXTERN u888to555RedBlueMask:MMWORD
  75. EXTERN u888to555GreenMask:MMWORD
  76. EXTERN u888to555Multiplier:MMWORD
  77. EXTERN uVal0x000007ff07ff07ff:MMWORD
  78. EXTERN uVal0x0000078007800780:MMWORD
  79. ; Span Variables
  80. StackPos dd ?
  81. uSpans dd ?
  82. ;-----------------------------------------------------------------------------
  83. ; Loop Variables
  84. iSurfaceStep dd ?
  85. uPix dd ?
  86. ;-----------------------------------------------------------------------------
  87. .code
  88. PUBLIC _MMXMLRast_27
  89. _MMXMLRast_27:
  90. push ebp
  91. mov StackPos, esp
  92. mov eax, esp
  93. sub esp, 0Ch ; This will need to change if stack frame size changes.
  94. push ebx
  95. push esi
  96. push edi
  97. ; Put pCtx into ebx
  98. mov ebx, [eax+8]
  99. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  100. mov ecx, [ebx+RASTCTX_pPrim]
  101. ;while (pP)
  102. ;{
  103. PrimLoop:
  104. cmp ecx, 0
  105. je ExitPrimLoop
  106. ;UINT16 uSpans = pP->uSpans;
  107. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  108. mov uSpans, eax
  109. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  110. mov ebp, ecx
  111. add ebp, SIZEOF_RASTPRIM
  112. ;while (uSpans-- > 0)
  113. ;{
  114. SpanLoop:
  115. mov edx, uSpans
  116. mov eax, edx
  117. dec eax
  118. mov uSpans, eax
  119. test edx, edx
  120. jle ExitSpanLoop
  121. ;pCtx->pfnBegin(pCtx, pP, pS);
  122. ;-----------------------------------------------------------------------------
  123. ; LoopAny code inserted here. This is to get rid of an extra
  124. ; jump.
  125. ;-----------------------------------------------------------------------------
  126. ; Setup Code begins
  127. ; get values to iterate
  128. ;uPix = pS->uPix;
  129. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  130. mov uPix, eax
  131. ;pCtx->SI.iDW = 0x0;
  132. mov dword ptr [ebx+RASTCTX_SI+SPANITER_iDW], 0
  133. mov esi, [ebp+RASTSPAN_iW]
  134. movq mm5, MMWORD PTR [ebp+RASTSPAN_iUoW1]
  135. ;pCtx->SI.iUd_TexNum = d_WTimesUVoW(pS->iW,pS->iUoW1);
  136. ;pCtx->SI.iVd_TexNum = d_WTimesUVoW(pS->iW,pS->iVoW1);
  137. pslld mm5, 8
  138. shl esi, 4
  139. movd eax, mm5
  140. psrlq mm5, 32
  141. imul esi
  142. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  143. movd eax, mm5
  144. imul esi
  145. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  146. ;if (pP->iDOoWDX > 0)
  147. ;{
  148. cmp dword ptr [ecx+RASTPRIM_iDOoWDX], 0
  149. jg SpecialWLastMonTest
  150. ;// iSpecialW should be negative for the first 3 pixels of span
  151. ;pCtx->SI.iSpecialW = -3;
  152. mov word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW], -3
  153. jmp DoneSpecialWifMonTest
  154. ;}
  155. ;else
  156. ;{
  157. SpecialWLastMonTest:
  158. ;// iSpecialW should be negative for the last 3 pixels of span
  159. ;pCtx->SI.iSpecialW = 0x7fff - uPix;
  160. mov eax, 07fffh
  161. sub eax, uPix
  162. ;pCtx->SI.iSpecialW += 5; // this may wrap, but it should
  163. add eax, 5
  164. mov [ebx+RASTCTX_SI+SPANITER_iSpecialW], eax
  165. ;}
  166. DoneSpecialWifMonTest:
  167. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  168. ;{
  169. mov eax, [ecx+RASTPRIM_uFlags]
  170. and eax, D3DI_RASTPRIM_X_DEC
  171. test eax, eax
  172. jz LeftToRightSpan
  173. ;iSurfaceStep = -pCtx->iSurfaceStep;
  174. mov eax, [ebx+RASTCTX_iSurfaceStep]
  175. neg eax
  176. mov iSurfaceStep, eax
  177. ;}
  178. jmp DoneSpanDirif
  179. ;else
  180. ;{
  181. LeftToRightSpan:
  182. ;iSurfaceStep = pCtx->iSurfaceStep;
  183. mov eax, [ebx+RASTCTX_iSurfaceStep]
  184. mov iSurfaceStep, eax
  185. ;}
  186. DoneSpanDirif:
  187. ; Setup Code Ends
  188. ; ----------------------------------------------------------------------------------------------------------------
  189. ; Loop Code Begins
  190. PixelLoop:
  191. ; texturecode
  192. mov esi, [ebx+RASTCTX_pTexture]
  193. movq mm5, MMWORD PTR Val0x000a000a ; This is TEX_FINAL_SHIFT - 6 = 10.
  194. movd mm4, [esi+SPANTEX_iShiftU]
  195. psubw mm5, mm4
  196. movq mm4, mm5
  197. pand mm5, MMWORD PTR Val0xffff
  198. psrld mm4, 16
  199. movd mm1, [ebx+RASTCTX_SI+SPANITER_iU1]
  200. psrad mm1, mm5
  201. movd mm2, [ebx+RASTCTX_SI+SPANITER_iV1]
  202. psrad mm2, mm4
  203. punpckldq mm1, mm2
  204. movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  205. add edx, 16
  206. movd mm2, edx
  207. movq mm5, MMWORD ptr Makelow16one
  208. pslld mm5, mm2
  209. por mm5, MMWORD ptr Makelow16one
  210. psrad mm1, 6
  211. packssdw mm1, mm1 ; Value needs to be packed since all wrap/mirror
  212. movd mm0, [esi+SPANTEX_uMaskU] ; Load U and V mask
  213. movq mm7, mm1
  214. movd mm4, [esi+SPANTEX_iFlipMaskU]
  215. pand mm7, mm4
  216. pcmpeqw mm7, MMWORD PTR Zero
  217. pandn mm7, mm0
  218. pand mm1, mm0
  219. pxor mm1, mm7
  220. pmaddwd mm1, mm5
  221. mov edi, [esi+SPANTEX_pBits]
  222. movd eax, mm1
  223. pxor mm1, mm1
  224. movd mm2, dword ptr [edi+4*eax]
  225. punpcklbw mm2, mm1
  226. ;modulate
  227. movq mm1, [ebp+RASTSPAN_uB]
  228. psrlw mm1, COLOR_SHIFT ; COLOR_SHIFT is set to 8.
  229. pmullw mm1, mm2
  230. ;write
  231. mov edi, [ebp+RASTSPAN_pSurface]
  232. psrlw mm1, 8 ; Convert color1 from 8.8 two 0.8
  233. packuswb mm1, mm7 ; pack one color
  234. movd edx, mm1
  235. and edx, 000ffffffh
  236. mov [edi], edx
  237. dec uPix ;// BUG BUG?? uPix should never start as zero should it?
  238. jle ExitPixelLoop
  239. movq mm1, [ebp+RASTSPAN_uB]
  240. paddw mm1, [ecx+RASTPRIM_iDBDX]
  241. movq [ebp+RASTSPAN_uB], mm1
  242. movq mm5, [ebp+RASTSPAN_iUoW1]
  243. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  244. movq [ebp+RASTSPAN_iUoW1], mm5
  245. xor eax, eax
  246. mov ax, [ebp+RASTSPAN_iLOD]
  247. add ax, [ebp+RASTSPAN_iDLOD]
  248. mov [ebp+RASTSPAN_iLOD], ax
  249. mov eax, [ebp+RASTSPAN_iOoW]
  250. add eax, [ecx+RASTPRIM_iDOoWDX]
  251. mov [ebp+RASTSPAN_iOoW], eax
  252. mov edx, [ebp+RASTSPAN_iW]
  253. mov LastW, edx ; Save iW to calc iDW for next time.
  254. add edx, [ebx+RASTCTX_SI+SPANITER_iDW]
  255. xor edi, edi
  256. cmp di, word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  257. jle DontDoSpecialW1
  258. cmp edx, edi
  259. jl WOutOfRange1
  260. mov edx, LastW
  261. sar edx, 1
  262. WOutOfRange1:
  263. mov GiveUp, 8 ; Pre decrementing instead of post decrementing.
  264. SpecW1Loop1:
  265. dec GiveUp
  266. jz ExitSpecWLoop1
  267. mov esi, (1 SHL 16)
  268. mov edi, edx
  269. imul edx
  270. sub esi, edx
  271. SpecW1Loop2:
  272. test esi, esi
  273. jns SpecW1ExitLoop2 ; This jump should be predicted correctly most of the time.
  274. add esi, (1 SHL 15)
  275. sar esi, 1
  276. jmp SpecW1Loop2
  277. SpecW1ExitLoop2:
  278. mov eax, edi
  279. shl eax, 5 ; 1.15.16 << 5 = 1.10.21 TBD Can I shift off upper bits??
  280. shl esi, 12 ; 4.15 << 12 = 4.27 ;
  281. mul esi
  282. sub edi, edx
  283. mov eax, edi
  284. sar eax, 31
  285. xor edi, eax
  286. sub edi, eax
  287. cmp edi, 020h ;Assuming that loop will only happen once.
  288. jbe ExitSpecWLoop1
  289. mov eax, [ebp+RASTSPAN_iOoW]
  290. jmp SpecW1Loop1
  291. DontDoSpecialW1:
  292. mov esi, (1 SHL 16)
  293. mov edi, edx
  294. mul edx
  295. sub esi, edx
  296. shl esi, 15
  297. mov eax, esi
  298. mul edi ; 0.2.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14
  299. shl edx, 2 ; 1.17.14 << 2 = 1.15.16
  300. ExitSpecWLoop1:
  301. mov [ebp+RASTSPAN_iW], edx
  302. mov esi, edx ; Save W for multiplying by UoW and VoW
  303. sub edx, LastW
  304. mov [ebx+RASTCTX_SI+SPANITER_iDW], edx
  305. inc word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  306. pslld mm5, 8
  307. shl esi, 4
  308. movd eax, mm5
  309. psrlq mm5, 32
  310. imul esi
  311. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  312. movd eax, mm5
  313. imul esi
  314. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  315. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  316. add edx, iSurfaceStep
  317. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  318. jmp PixelLoop
  319. ExitPixelLoop:
  320. ; Loop code ends
  321. ;-----------------------------------------------------------------------------
  322. ; LoopAny code ends here
  323. ;-----------------------------------------------------------------------------
  324. ;pS++;
  325. add ebp, SIZEOF_RASTSPAN
  326. ;}
  327. jmp SpanLoop
  328. ExitSpanLoop:
  329. ;pP = pP->pNext;
  330. mov ecx, [ecx+RASTPRIM_pNext]
  331. ;}
  332. jmp PrimLoop
  333. ExitPrimLoop:
  334. ;_asm{
  335. emms
  336. ;}
  337. ;return S_OK;
  338. xor eax, eax
  339. ;}
  340. pop edi
  341. pop esi
  342. pop ebx
  343. mov esp, StackPos
  344. pop ebp
  345. ret
  346. END