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.

513 lines
12 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 20. Perspective Correct Nearest Gouraud Modulated
  4. ; Z buffer (LE or GT) X888
  5. ;
  6. ; Exactly the same as monolith 6 except color input is 32 bits and
  7. ; output is 32 bits
  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. iZStep dd ?
  86. uPix dd ?
  87. ;-----------------------------------------------------------------------------
  88. .code
  89. PUBLIC _MMXMLRast_20
  90. _MMXMLRast_20:
  91. push ebp
  92. mov StackPos, esp
  93. mov eax, esp
  94. sub esp, 0Ch ; This will need to change if stack frame size changes.
  95. push ebx
  96. push esi
  97. push edi
  98. ; Put pCtx into ebx
  99. mov ebx, [eax+8]
  100. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  101. mov ecx, [ebx+RASTCTX_pPrim]
  102. ;while (pP)
  103. ;{
  104. PrimLoop:
  105. cmp ecx, 0
  106. je ExitPrimLoop
  107. ;UINT16 uSpans = pP->uSpans;
  108. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  109. mov uSpans, eax
  110. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  111. mov ebp, ecx
  112. add ebp, SIZEOF_RASTPRIM
  113. ;while (uSpans-- > 0)
  114. ;{
  115. SpanLoop:
  116. mov edx, uSpans
  117. mov eax, edx
  118. dec eax
  119. mov uSpans, eax
  120. test edx, edx
  121. jle ExitSpanLoop
  122. ;pCtx->pfnBegin(pCtx, pP, pS);
  123. ;-----------------------------------------------------------------------------
  124. ; LoopAny code inserted here. This is to get rid of an extra
  125. ; jump.
  126. ;-----------------------------------------------------------------------------
  127. ; Setup Code begins
  128. ; get values to iterate
  129. ;uPix = pS->uPix;
  130. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  131. mov uPix, eax
  132. ;pCtx->SI.iDW = 0x0;
  133. mov dword ptr [ebx+RASTCTX_SI+SPANITER_iDW], 0
  134. mov esi, [ebp+RASTSPAN_iW]
  135. movq mm5, MMWORD PTR [ebp+RASTSPAN_iUoW1]
  136. ;pCtx->SI.iUd_TexNum = d_WTimesUVoW(pS->iW,pS->iUoW1);
  137. ;pCtx->SI.iVd_TexNum = d_WTimesUVoW(pS->iW,pS->iVoW1);
  138. pslld mm5, 8
  139. shl esi, 4
  140. movd eax, mm5
  141. psrlq mm5, 32
  142. imul esi
  143. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  144. movd eax, mm5
  145. imul esi
  146. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  147. ;if (pP->iDOoWDX > 0)
  148. ;{
  149. cmp dword ptr [ecx+RASTPRIM_iDOoWDX], 0
  150. jg SpecialWLastMonTest
  151. ;// iSpecialW should be negative for the first 3 pixels of span
  152. ;pCtx->SI.iSpecialW = -3;
  153. mov word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW], -3
  154. jmp DoneSpecialWifMonTest
  155. ;}
  156. ;else
  157. ;{
  158. SpecialWLastMonTest:
  159. ;// iSpecialW should be negative for the last 3 pixels of span
  160. ;pCtx->SI.iSpecialW = 0x7fff - uPix;
  161. mov eax, 07fffh
  162. sub eax, uPix
  163. ;pCtx->SI.iSpecialW += 5; // this may wrap, but it should
  164. add eax, 5
  165. mov [ebx+RASTCTX_SI+SPANITER_iSpecialW], eax
  166. ;}
  167. DoneSpecialWifMonTest:
  168. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  169. ;{
  170. mov eax, [ecx+RASTPRIM_uFlags]
  171. and eax, D3DI_RASTPRIM_X_DEC
  172. test eax, eax
  173. jz LeftToRightSpan
  174. ;iZStep = -pCtx->iZStep;
  175. mov eax, [ebx+RASTCTX_iZStep]
  176. neg eax
  177. mov iZStep, eax
  178. ;iSurfaceStep = -pCtx->iSurfaceStep;
  179. mov eax, [ebx+RASTCTX_iSurfaceStep]
  180. neg eax
  181. mov iSurfaceStep, eax
  182. ;}
  183. jmp DoneSpanDirif
  184. ;else
  185. ;{
  186. LeftToRightSpan:
  187. ;iZStep = pCtx->iZStep;
  188. mov eax, [ebx+RASTCTX_iZStep]
  189. mov iZStep, eax
  190. ;iSurfaceStep = pCtx->iSurfaceStep;
  191. mov eax, [ebx+RASTCTX_iSurfaceStep]
  192. mov iSurfaceStep, eax
  193. ;}
  194. DoneSpanDirif:
  195. ; Setup Code Ends
  196. ; ----------------------------------------------------------------------------------------------------------------
  197. ; Loop Code Begins
  198. PixelLoop:
  199. ; Ztestcode
  200. ; edx is uZ
  201. ; eax is uZB
  202. ; 16 bit unsigned format
  203. ;UINT16 uZ = (UINT16)(pS->uZ>>15);
  204. ;UINT16 uZB = *((UINT16*)pS->pZ);
  205. mov edx, [ebp+RASTSPAN_uZ]
  206. movd mm4, edx
  207. mov esi, [ebp+RASTSPAN_pZ]
  208. shr edx, 15
  209. movzx eax, word ptr [esi]
  210. ;pS->uZ += pP->iDZDX;
  211. ;if ((pCtx->iZXorMask)^(uZ > uZB))
  212. ; !(uZ > uZB) <==>
  213. ; (uZ <= uZB) <==>
  214. ; (uZ < uZB+1) <==>
  215. ;
  216. sub eax, edx
  217. paddd mm4, [ecx+RASTPRIM_iDZDX]
  218. movd [ebp+RASTSPAN_uZ], mm4
  219. xor eax, [ebx+RASTCTX_iZXorMask]
  220. test eax, eax
  221. js FailLabel
  222. mov word ptr [esi], dx
  223. ; texturecode
  224. mov esi, [ebx+RASTCTX_pTexture]
  225. movq mm5, MMWORD PTR Val0x000a000a ; This is TEX_FINAL_SHIFT - 6 = 10.
  226. movd mm4, [esi+SPANTEX_iShiftU]
  227. psubw mm5, mm4
  228. movq mm4, mm5
  229. pand mm5, MMWORD PTR Val0xffff
  230. psrld mm4, 16
  231. movd mm1, [ebx+RASTCTX_SI+SPANITER_iU1]
  232. psrad mm1, mm5
  233. movd mm2, [ebx+RASTCTX_SI+SPANITER_iV1]
  234. psrad mm2, mm4
  235. punpckldq mm1, mm2
  236. movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  237. add edx, 16
  238. movd mm2, edx
  239. movq mm5, MMWORD ptr Makelow16one
  240. pslld mm5, mm2
  241. por mm5, MMWORD ptr Makelow16one
  242. psrad mm1, 6
  243. packssdw mm1, mm1 ; Value needs to be packed since all wrap/mirror
  244. movd mm0, [esi+SPANTEX_uMaskU] ; Load U and V mask
  245. movq mm7, mm1
  246. movd mm4, [esi+SPANTEX_iFlipMaskU]
  247. pand mm7, mm4
  248. pcmpeqw mm7, MMWORD PTR Zero
  249. pandn mm7, mm0
  250. pand mm1, mm0
  251. pxor mm1, mm7
  252. pmaddwd mm1, mm5
  253. mov edi, [esi+SPANTEX_pBits]
  254. movd eax, mm1
  255. pxor mm1, mm1
  256. movd mm2, dword ptr [edi+4*eax]
  257. ; got rid of the pupack with zero
  258. ; in color conversion.
  259. punpcklbw mm2, mm1
  260. ;modulate
  261. movq mm1, [ebp+RASTSPAN_uB]
  262. psrlw mm1, COLOR_SHIFT ; COLOR_SHIFT is set to 8.
  263. pmullw mm1, mm2
  264. ;write
  265. mov edi, [ebp+RASTSPAN_pSurface]
  266. psrlw mm1, 8 ; Convert color1 from 8.8 two 0.8
  267. packuswb mm1, mm7 ; pack one color1
  268. movd edx, mm1
  269. and edx, 000ffffffh
  270. mov [edi], edx
  271. FailLabel:
  272. dec uPix ;// BUG BUG?? uPix should never start as zero should it?
  273. jle ExitPixelLoop
  274. movq mm1, [ebp+RASTSPAN_uB]
  275. paddw mm1, [ecx+RASTPRIM_iDBDX]
  276. movq [ebp+RASTSPAN_uB], mm1
  277. movq mm5, [ebp+RASTSPAN_iUoW1]
  278. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  279. movq [ebp+RASTSPAN_iUoW1], mm5
  280. xor eax, eax
  281. mov ax, [ebp+RASTSPAN_iLOD]
  282. add ax, [ebp+RASTSPAN_iDLOD]
  283. mov [ebp+RASTSPAN_iLOD], ax
  284. mov eax, [ebp+RASTSPAN_iOoW]
  285. add eax, [ecx+RASTPRIM_iDOoWDX]
  286. mov [ebp+RASTSPAN_iOoW], eax
  287. mov edx, [ebp+RASTSPAN_iW]
  288. mov LastW, edx ; Save iW to calc iDW for next time.
  289. add edx, [ebx+RASTCTX_SI+SPANITER_iDW]
  290. xor edi, edi
  291. cmp di, word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  292. jle DontDoSpecialW1
  293. cmp edx, edi
  294. jl WOutOfRange1
  295. mov edx, LastW
  296. sar edx, 1
  297. WOutOfRange1:
  298. mov GiveUp, 8 ; Pre decrementing instead of post decrementing.
  299. SpecW1Loop1:
  300. dec GiveUp
  301. jz ExitSpecWLoop1
  302. mov esi, (1 SHL 16)
  303. mov edi, edx
  304. imul edx
  305. sub esi, edx
  306. SpecW1Loop2:
  307. test esi, esi
  308. jns SpecW1ExitLoop2 ; This jump should be predicted correctly most of the time.
  309. add esi, (1 SHL 15)
  310. sar esi, 1
  311. jmp SpecW1Loop2
  312. SpecW1ExitLoop2:
  313. mov eax, edi
  314. shl eax, 5 ; 1.15.16 << 5 = 1.10.21 TBD Can I shift off upper bits??
  315. shl esi, 12 ; 4.15 << 12 = 4.27 ;
  316. mul esi
  317. sub edi, edx
  318. mov eax, edi
  319. sar eax, 31
  320. xor edi, eax
  321. sub edi, eax
  322. cmp edi, 020h ;Assuming that loop will only happen once.
  323. jbe ExitSpecWLoop1
  324. mov eax, [ebp+RASTSPAN_iOoW]
  325. jmp SpecW1Loop1
  326. DontDoSpecialW1:
  327. mov esi, (1 SHL 16)
  328. mov edi, edx
  329. mul edx
  330. sub esi, edx
  331. shl esi, 15
  332. mov eax, esi
  333. mul edi ; 0.2.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14
  334. shl edx, 2 ; 1.17.14 << 2 = 1.15.16
  335. ExitSpecWLoop1:
  336. mov [ebp+RASTSPAN_iW], edx
  337. mov esi, edx ; Save W for multiplying by UoW and VoW
  338. sub edx, LastW
  339. mov [ebx+RASTCTX_SI+SPANITER_iDW], edx
  340. inc word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  341. pslld mm5, 8
  342. shl esi, 4
  343. movd eax, mm5
  344. psrlq mm5, 32
  345. imul esi
  346. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  347. movd eax, mm5
  348. imul esi
  349. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  350. mov eax, dword ptr [ebp+RASTSPAN_pZ]
  351. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  352. add eax, iZStep
  353. add edx, iSurfaceStep
  354. mov dword ptr [ebp+RASTSPAN_pZ], eax
  355. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  356. jmp PixelLoop
  357. ExitPixelLoop:
  358. ; Loop code ends
  359. ;-----------------------------------------------------------------------------
  360. ; LoopAny code ends here
  361. ;-----------------------------------------------------------------------------
  362. ;pS++;
  363. add ebp, SIZEOF_RASTSPAN
  364. ;}
  365. jmp SpanLoop
  366. ExitSpanLoop:
  367. ;pP = pP->pNext;
  368. mov ecx, [ecx+RASTPRIM_pNext]
  369. ;}
  370. jmp PrimLoop
  371. ExitPrimLoop:
  372. ;_asm{
  373. emms
  374. ;}
  375. ;return S_OK;
  376. xor eax, eax
  377. ;}
  378. pop edi
  379. pop esi
  380. pop ebx
  381. mov esp, StackPos
  382. pop ebp
  383. ret
  384. END