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.

493 lines
12 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 17. Perspective Correct Nearest texturing
  4. ; 16 bit Zbuffer (LE or GR) X888
  5. ;
  6. ; Exactly the same as monolith 3 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_17
  90. _MMXMLRast_17:
  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. mov edx, dword ptr [edi+4*eax]
  256. and edx, 000ffffffh ; Have to make alpha 0x00 in 32 bit cases.
  257. mov edi, [ebp+RASTSPAN_pSurface]
  258. mov [edi], edx
  259. FailLabel:
  260. dec uPix
  261. jle ExitPixelLoop
  262. movq mm1, [ebp+RASTSPAN_uB]
  263. paddw mm1, [ecx+RASTPRIM_iDBDX]
  264. movq [ebp+RASTSPAN_uB], mm1
  265. movq mm5, [ebp+RASTSPAN_iUoW1]
  266. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  267. movq [ebp+RASTSPAN_iUoW1], mm5
  268. xor eax, eax
  269. mov ax, [ebp+RASTSPAN_iLOD]
  270. add ax, [ebp+RASTSPAN_iDLOD]
  271. mov [ebp+RASTSPAN_iLOD], ax
  272. mov eax, [ebp+RASTSPAN_iOoW]
  273. add eax, [ecx+RASTPRIM_iDOoWDX]
  274. mov [ebp+RASTSPAN_iOoW], eax
  275. mov edx, [ebp+RASTSPAN_iW]
  276. mov LastW, edx ; Save iW to calc iDW for next time.
  277. add edx, [ebx+RASTCTX_SI+SPANITER_iDW]
  278. xor edi, edi
  279. cmp di, word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  280. jle DontDoSpecialW1
  281. cmp edx, edi
  282. jl WOutOfRange1
  283. mov edx, LastW
  284. sar edx, 1
  285. WOutOfRange1:
  286. mov GiveUp, 8 ; Pre decrementing instead of post decrementing.
  287. SpecW1Loop1:
  288. dec GiveUp
  289. jz ExitSpecWLoop1
  290. mov esi, (1 SHL 16)
  291. mov edi, edx
  292. imul edx
  293. sub esi, edx
  294. SpecW1Loop2:
  295. test esi, esi
  296. jns SpecW1ExitLoop2 ; This jump should be predicted correctly most of the time.
  297. add esi, (1 SHL 15)
  298. sar esi, 1
  299. jmp SpecW1Loop2
  300. SpecW1ExitLoop2:
  301. mov eax, edi
  302. shl eax, 5 ; 1.15.16 << 5 = 1.10.21 TBD Can I shift off upper bits??
  303. shl esi, 12 ; 4.15 << 12 = 4.27 ;
  304. mul esi
  305. sub edi, edx
  306. mov eax, edi
  307. sar eax, 31
  308. xor edi, eax
  309. sub edi, eax
  310. cmp edi, 020h ;Assuming that loop will only happen once.
  311. jbe ExitSpecWLoop1
  312. mov eax, [ebp+RASTSPAN_iOoW]
  313. jmp SpecW1Loop1
  314. DontDoSpecialW1:
  315. mov esi, (1 SHL 16)
  316. mov edi, edx
  317. mul edx
  318. sub esi, edx
  319. shl esi, 15
  320. mov eax, esi
  321. mul edi ; 0.2.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14
  322. shl edx, 2 ; 1.17.14 << 2 = 1.15.16
  323. ExitSpecWLoop1:
  324. mov [ebp+RASTSPAN_iW], edx
  325. mov esi, edx ; Save W for multiplying by UoW and VoW
  326. sub edx, LastW
  327. mov [ebx+RASTCTX_SI+SPANITER_iDW], edx
  328. inc word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  329. pslld mm5, 8
  330. shl esi, 4
  331. movd eax, mm5
  332. psrlq mm5, 32
  333. imul esi
  334. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  335. movd eax, mm5
  336. imul esi
  337. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  338. mov eax, dword ptr [ebp+RASTSPAN_pZ]
  339. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  340. add eax, iZStep
  341. add edx, iSurfaceStep
  342. mov dword ptr [ebp+RASTSPAN_pZ], eax
  343. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  344. jmp PixelLoop
  345. ExitPixelLoop:
  346. ; Loop code ends
  347. ;-----------------------------------------------------------------------------
  348. ; LoopAny code ends here
  349. ;-----------------------------------------------------------------------------
  350. ;pS++;
  351. add ebp, SIZEOF_RASTSPAN
  352. ;}
  353. jmp SpanLoop
  354. ExitSpanLoop:
  355. ;pP = pP->pNext;
  356. mov ecx, [ecx+RASTPRIM_pNext]
  357. ;}
  358. jmp PrimLoop
  359. ExitPrimLoop:
  360. ;_asm{
  361. emms
  362. ;}
  363. ;return S_OK;
  364. xor eax, eax
  365. ;}
  366. pop edi
  367. pop esi
  368. pop ebx
  369. mov esp, StackPos
  370. pop ebp
  371. ret
  372. END