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.

449 lines
11 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 10. Perspective Correct Nearest texturing
  4. ; 16 bit NO Zbuffer 565
  5. ;
  6. ; Exactly the same as monolith 3 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_10
  88. _MMXMLRast_10:
  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 edx, word ptr [edi+2*eax]
  223. mov edi, [ebp+RASTSPAN_pSurface]
  224. mov [edi], dx
  225. dec uPix
  226. jle ExitPixelLoop
  227. movq mm1, [ebp+RASTSPAN_uB]
  228. paddw mm1, [ecx+RASTPRIM_iDBDX]
  229. movq [ebp+RASTSPAN_uB], mm1
  230. movq mm5, [ebp+RASTSPAN_iUoW1]
  231. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  232. movq [ebp+RASTSPAN_iUoW1], mm5
  233. xor eax, eax
  234. mov ax, [ebp+RASTSPAN_iLOD]
  235. add ax, [ebp+RASTSPAN_iDLOD]
  236. mov [ebp+RASTSPAN_iLOD], ax
  237. mov eax, [ebp+RASTSPAN_iOoW]
  238. add eax, [ecx+RASTPRIM_iDOoWDX]
  239. mov [ebp+RASTSPAN_iOoW], eax
  240. mov edx, [ebp+RASTSPAN_iW]
  241. mov LastW, edx ; Save iW to calc iDW for next time.
  242. add edx, [ebx+RASTCTX_SI+SPANITER_iDW]
  243. xor edi, edi
  244. cmp di, word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  245. jle DontDoSpecialW1
  246. cmp edx, edi
  247. jl WOutOfRange1
  248. mov edx, LastW
  249. sar edx, 1
  250. WOutOfRange1:
  251. mov GiveUp, 8 ; Pre decrementing instead of post decrementing.
  252. SpecW1Loop1:
  253. dec GiveUp
  254. jz ExitSpecWLoop1
  255. mov esi, (1 SHL 16)
  256. mov edi, edx
  257. imul edx
  258. sub esi, edx
  259. SpecW1Loop2:
  260. test esi, esi
  261. jns SpecW1ExitLoop2 ; This jump should be predicted correctly most of the time.
  262. add esi, (1 SHL 15)
  263. sar esi, 1
  264. jmp SpecW1Loop2
  265. SpecW1ExitLoop2:
  266. mov eax, edi
  267. shl eax, 5 ; 1.15.16 << 5 = 1.10.21 TBD Can I shift off upper bits??
  268. shl esi, 12 ; 4.15 << 12 = 4.27 ;
  269. mul esi
  270. sub edi, edx
  271. mov eax, edi
  272. sar eax, 31
  273. xor edi, eax
  274. sub edi, eax
  275. cmp edi, 020h ;Assuming that loop will only happen once.
  276. jbe ExitSpecWLoop1
  277. mov eax, [ebp+RASTSPAN_iOoW]
  278. jmp SpecW1Loop1
  279. DontDoSpecialW1:
  280. mov esi, (1 SHL 16)
  281. mov edi, edx
  282. mul edx
  283. sub esi, edx
  284. shl esi, 15
  285. mov eax, esi
  286. mul edi ; 0.2.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14
  287. shl edx, 2 ; 1.17.14 << 2 = 1.15.16
  288. ExitSpecWLoop1:
  289. mov [ebp+RASTSPAN_iW], edx
  290. mov esi, edx ; Save W for multiplying by UoW and VoW
  291. sub edx, LastW
  292. mov [ebx+RASTCTX_SI+SPANITER_iDW], edx
  293. inc word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  294. pslld mm5, 8
  295. shl esi, 4
  296. movd eax, mm5
  297. psrlq mm5, 32
  298. imul esi
  299. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  300. movd eax, mm5
  301. imul esi
  302. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  303. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  304. add edx, iSurfaceStep
  305. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  306. jmp PixelLoop
  307. ExitPixelLoop:
  308. ; Loop code ends
  309. ;-----------------------------------------------------------------------------
  310. ; LoopAny code ends here
  311. ;-----------------------------------------------------------------------------
  312. ;pS++;
  313. add ebp, SIZEOF_RASTSPAN
  314. ;}
  315. jmp SpanLoop
  316. ExitSpanLoop:
  317. ;pP = pP->pNext;
  318. mov ecx, [ecx+RASTPRIM_pNext]
  319. ;}
  320. jmp PrimLoop
  321. ExitPrimLoop:
  322. ;_asm{
  323. emms
  324. ;}
  325. ;return S_OK;
  326. xor eax, eax
  327. ;}
  328. pop edi
  329. pop esi
  330. pop ebx
  331. mov esp, StackPos
  332. pop ebp
  333. ret
  334. END