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.

484 lines
12 KiB

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