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.

812 lines
25 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 4. Perspective Correct Bi-linear
  4. ; 565 input texture NO Z buffer
  5. ; 565 output.
  6. ;
  7. ; Exactly the same as monolith 4 except Z buffer code removed.
  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. ; Big seperating lines seperate code into span code
  19. ; and loop code. If span and loop are not going to
  20. ; end up being combined then it will be easy to
  21. ; seperate the code.
  22. .data
  23. ; Need externs for all of the variables that are needed for various beads
  24. EXTERN IncHighandLow16:MMWORD
  25. EXTERN UFracVFracMask:MMWORD
  26. EXTERN UV32to15Mask:MMWORD
  27. EXTERN Makelow16one:MMWORD
  28. EXTERN MaskKeepUValues:MMWORD
  29. EXTERN MaskKeepVValues:MMWORD
  30. EXTERN UFrac:MMWORD
  31. EXTERN VFrac:MMWORD
  32. EXTERN Zero:MMWORD
  33. EXTERN memD3DTFG_POINT:MMWORD
  34. EXTERN GiveUp:MMWORD
  35. EXTERN LastW:MMWORD
  36. EXTERN Val0x000a000a:MMWORD
  37. EXTERN Val0xffff:MMWORD
  38. EXTERN Val0x0000002000000020:MMWORD
  39. EXTERN Val0x0000ffff0000ffff:MMWORD
  40. EXTERN MaskRed565to888:MMWORD
  41. EXTERN MaskGreen565to888:MMWORD
  42. EXTERN MaskBlue565to888:MMWORD
  43. EXTERN MaskRed555to888:MMWORD
  44. EXTERN MaskGreen555to888:MMWORD
  45. EXTERN MaskBlue555to888:MMWORD
  46. EXTERN MaskAlpha1555to8888:MMWORD
  47. EXTERN MaskRed1555to8888:MMWORD
  48. EXTERN MaskGreen1555to8888:MMWORD
  49. EXTERN MaskBlue1555to8888:MMWORD
  50. ; TBD. I think that I want to do 0xffff instead of 0xff. This will
  51. ; have to be checked. There is a value very similiar to this in
  52. ; buf write.
  53. EXTERN SetAlphato0xffff:MMWORD
  54. EXTERN SetAlphato0xff:MMWORD
  55. ; TODO This equate are identical to the ones in texread.mas. Maybe they should be in a common .inc file.
  56. RedShift565to888 equ 8
  57. GreenShift565to888 equ 5
  58. BlueShift565to888 equ 3
  59. RedShift555to888 equ 9
  60. GreenShift555to888 equ 6
  61. BlueShift555to888 equ 3
  62. AlphaShift1555to8888 equ 16
  63. RedShift1555to8888 equ 9
  64. GreenShift1555to8888 equ 6
  65. BlueShift1555to8888 equ 3
  66. EXTERN BilinearMaskRed565to888:MMWORD
  67. EXTERN BilinearMaskGreen565to888:MMWORD
  68. EXTERN BilinearMaskBlue565to888:MMWORD
  69. ; These are not needed as qwords since they can be done with constants
  70. EXTERN BilinearShiftRed565to888:MMWORD
  71. EXTERN BilinearShiftGreen565to888:MMWORD
  72. EXTERN BilinearShiftBlue565to888:MMWORD
  73. EXTERN Zero:MMWORD
  74. EXTERN DW_One_One:MMWORD
  75. EXTERN MaskOffAlpha:MMWORD
  76. EXTERN ShiftTA:MMWORD
  77. EXTERN Val0x00ff00ff00ff00ff:MMWORD
  78. EXTERN Val0x000000ff00ff00ff:MMWORD
  79. EXTERN Val0X0000000001000000:MMWORD
  80. EXTERN AlphaVal128:MMWORD
  81. EXTERN RGBVal128:MMWORD
  82. EXTERN g_uDitherValue:MMWORD
  83. EXTERN SetAlphato0xff:MMWORD
  84. EXTERN u888to565RedBlueMask:MMWORD
  85. EXTERN u888to565GreenMask:MMWORD
  86. EXTERN u888to565Multiplier:MMWORD
  87. EXTERN uVal0x000007ff03ff07ff:MMWORD
  88. EXTERN uVal0x0000078003c00780:MMWORD
  89. EXTERN u888to555RedBlueMask:MMWORD
  90. EXTERN u888to555GreenMask:MMWORD
  91. EXTERN u888to555Multiplier:MMWORD
  92. EXTERN uVal0x000007ff07ff07ff:MMWORD
  93. EXTERN uVal0x0000078007800780:MMWORD
  94. ;-----------------------------------------------------------------------------
  95. ; Span Variables
  96. StackPos dd ?
  97. uSpans dd ?
  98. ;-----------------------------------------------------------------------------
  99. ;-----------------------------------------------------------------------------
  100. ; Loop Variables
  101. iSurfaceStep dd ?
  102. uPix dd ?
  103. ;-----------------------------------------------------------------------------
  104. .code
  105. PUBLIC _MMXMLRast_11
  106. _MMXMLRast_11:
  107. push ebp
  108. mov StackPos, esp
  109. mov eax, esp
  110. sub esp, 0Ch ; This will need to change if stack frame size changes.
  111. push ebx
  112. push esi
  113. push edi
  114. ; Put pCtx into ebx
  115. mov ebx, [eax+8]
  116. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  117. mov ecx, [ebx+RASTCTX_pPrim]
  118. ;while (pP)
  119. ;{
  120. PrimLoop:
  121. cmp ecx, 0
  122. je ExitPrimLoop
  123. ;UINT16 uSpans = pP->uSpans;
  124. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  125. mov uSpans, eax
  126. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  127. mov ebp, ecx
  128. add ebp, SIZEOF_RASTPRIM
  129. ;while (uSpans-- > 0)
  130. ;{
  131. SpanLoop:
  132. mov edx, uSpans
  133. mov eax, edx
  134. dec eax
  135. mov uSpans, eax
  136. test edx, edx
  137. jle ExitSpanLoop
  138. ;pCtx->pfnBegin(pCtx, pP, pS);
  139. ;-----------------------------------------------------------------------------
  140. ; LoopAny code inserted here. This is to get rid of an extra
  141. ; jump.
  142. ;-----------------------------------------------------------------------------
  143. ; Setup Code begins
  144. ; get values to iterate
  145. ;uPix = pS->uPix;
  146. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  147. mov uPix, eax
  148. ;pCtx->SI.iDW = 0x0;
  149. mov dword ptr [ebx+RASTCTX_SI+SPANITER_iDW], 0
  150. mov esi, [ebp+RASTSPAN_iW]
  151. movq mm5, MMWORD PTR [ebp+RASTSPAN_iUoW1]
  152. ;pCtx->SI.iUd_TexNum = d_WTimesUVoW(pS->iW,pS->iUoW1);
  153. ;pCtx->SI.iVd_TexNum = d_WTimesUVoW(pS->iW,pS->iVoW1);
  154. pslld mm5, 8
  155. shl esi, 4
  156. movd eax, mm5
  157. psrlq mm5, 32
  158. imul esi
  159. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  160. movd eax, mm5
  161. imul esi
  162. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  163. ;if (pP->iDOoWDX > 0)
  164. ;{
  165. cmp dword ptr [ecx+RASTPRIM_iDOoWDX], 0
  166. jg SpecialWLastMonTest
  167. ;// iSpecialW should be negative for the first 3 pixels of span
  168. ;pCtx->SI.iSpecialW = -3;
  169. mov word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW], -3
  170. jmp DoneSpecialWifMonTest
  171. ;}
  172. ;else
  173. ;{
  174. SpecialWLastMonTest:
  175. ;// iSpecialW should be negative for the last 3 pixels of span
  176. ;pCtx->SI.iSpecialW = 0x7fff - uPix;
  177. mov eax, 07fffh
  178. sub eax, uPix
  179. ;pCtx->SI.iSpecialW += 5; // this may wrap, but it should
  180. add eax, 5
  181. mov [ebx+RASTCTX_SI+SPANITER_iSpecialW], eax
  182. ;}
  183. DoneSpecialWifMonTest:
  184. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  185. ;{
  186. mov eax, [ecx+RASTPRIM_uFlags]
  187. and eax, D3DI_RASTPRIM_X_DEC
  188. test eax, eax
  189. jz LeftToRightSpan
  190. ;iSurfaceStep = -pCtx->iSurfaceStep;
  191. mov eax, [ebx+RASTCTX_iSurfaceStep]
  192. neg eax
  193. mov iSurfaceStep, eax
  194. ;}
  195. jmp DoneSpanDirif
  196. ;else
  197. ;{
  198. LeftToRightSpan:
  199. ;iSurfaceStep = pCtx->iSurfaceStep;
  200. mov eax, [ebx+RASTCTX_iSurfaceStep]
  201. mov iSurfaceStep, eax
  202. ;}
  203. DoneSpanDirif:
  204. ; Setup Code Ends
  205. ; ----------------------------------------------------------------------------------------------------------------
  206. ; Loop Code Begins
  207. ;//while (1)
  208. ;//{
  209. PixelLoop:
  210. ; texturecode
  211. ;---------------------------------------------------------------------------
  212. ;void Tex1Addr_TexAddrWrapMirror_Persp_Bilinear_NoMip(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  213. ; PD3DI_RASTSPAN pS)
  214. ;{
  215. ;PD3DI_SPANTEX pTex = &pCtx->Texture[0];
  216. mov esi, [ebx+RASTCTX_pTexture]
  217. ; ----------------------------------------
  218. ; Doing UV calculation a little more accurate
  219. ; Exactly like C code.
  220. ; I shift iU and iV to the right not by (TEX_FINAL_SHIFT - iShiftU0) but by
  221. ; (TEX_FINAL_SHIFT - iShiftU0 - 6). iShiftU0 = pTex->iShiftU - iLOD0
  222. ; (TEX_FINAL_SHIFT - (pTex->iShiftU - iLOD0))
  223. ; (TEX_FINAL_SHIFT + iLOD0 - pTex->iShiftU)
  224. ; COMMENT1**
  225. ; If textures have a max of 1024 then shiftU0 would be at most 10 which would
  226. ; make (TEXT_FINAL_SHIFT - iShiftU - 6) at most zero. This is why I choose 6
  227. ; It will also give bi-linear 6 bits of precision I think it was said that
  228. ; only five was needed.
  229. ;INT16 iShiftU0 = pTex->iShiftU - iLOD0;
  230. ;INT16 iShiftV0 = pTex->iShiftV - iLOD0;
  231. movq mm5, MMWORD PTR Val0x000a000a ; This is TEX_FINAL_SHIFT - 6 = 10.
  232. ;iLOD0 is zero in monolithic case so no subtraction needed.
  233. movd mm4, [esi+SPANTEX_iShiftU]
  234. psubw mm5, mm4
  235. movq mm4, mm5
  236. pand mm5, MMWORD PTR Val0xffff
  237. psrld mm4, 16
  238. movd mm1, [ebx+RASTCTX_SI+SPANITER_iU1]
  239. psrad mm1, mm5
  240. movd mm2, [ebx+RASTCTX_SI+SPANITER_iV1]
  241. psrad mm2, mm4
  242. punpckldq mm1, mm2
  243. psubd mm1, MMWORD PTR Val0x0000002000000020
  244. ; Texture Pitch cannot be calculated so it must be looked up in the iShiftPitch table
  245. movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  246. add edx, 16
  247. movd mm2, edx
  248. movq mm5, MMWORD ptr Makelow16one
  249. pslld mm5, mm2
  250. por mm5, MMWORD ptr Makelow16one
  251. ; Make the low 16 bits of dword one
  252. ; This helps in calculating texture address.
  253. ; Gets U and V value into mm1 so that it can be mirrored, wrapped or
  254. ; clamped. This can be done for two values in the point case
  255. ; or four values in the bilinear case.
  256. ;INT32 iUFrac = iU00 & 0x03f;
  257. ;INT32 iVFrac = iV00 & 0x03f;
  258. ;iU00 >>= 6;
  259. ;iV00 >>= 6;
  260. movq mm2, mm1
  261. psrad mm1, 6
  262. ;pand mm1, MMWORD PTR Val0x0000ffff0000ffff
  263. pand mm2, dword ptr UFracVFracMask ; UFracVFracMask = 0x0000003f0000003f
  264. ; Going to use only 8 bits for bi-linear so that I can do a pmullw.
  265. ; Currently at 6 bits so shift up by 2.
  266. psllw mm2, 2
  267. movq mm0, mm2
  268. ; Replicate VFrac value for bilinear
  269. punpckhwd mm2, mm2
  270. punpcklwd mm2, mm2
  271. ; Replicate UFrac Value for bilinear
  272. punpcklwd mm0, mm0
  273. punpcklwd mm0, mm0
  274. movq dword ptr VFrac, mm2
  275. movq dword ptr UFrac, mm0
  276. ;INT32 iU01 = iU00 + 1;
  277. ;INT32 iV01 = iV00 + 1;
  278. packssdw mm1, mm1 ; replicate U and V value to upper 16 bit locations
  279. paddw mm1, dword ptr IncHighandLow16
  280. ; This will make texture values be (High word to low word):
  281. ; iV01, iU00, iV00, iU01
  282. ; Need to do this to make texture look up for bilinear easier.
  283. ; I have to combine to get all combinations anyway. It just
  284. ; happens to be better for me to have iV00, iU01 pair first.
  285. ;UINT16 uMaskU0 = pTex->uMaskU >> iLOD0; UINT16 uMaskV0 = pTex->uMaskV >> iLOD0;
  286. ; put mask in mm3 and replicate to match location for wrap/mirror/clamp
  287. movd mm0, [esi+SPANTEX_uMaskU] ; Load U and V mask
  288. ; replicate mask if doing bilinear
  289. punpckldq mm0, mm0
  290. ; Monolith cases assumed that iLOD0 was zero so no shift needed.
  291. ;INT16 iFlip;
  292. ; MM1 should contain 16 bit iU and iV for both texture locations
  293. ; End Result is MM1 value wrapped or mirrored
  294. ; in Bilinear Case, four values can be done
  295. ; iU00, iV00, iU01, iV01
  296. ; This code really does alot for the bilinear case and is kinda wasteful
  297. ; in the normal mode.
  298. ;iFlip1 = iU00 & pTex->iFlipMaskU; ;iFlip2 = iV00 & pTex->iFlipMaskV; ;iFlip3 = iU01 & pTex->iFlipMaskU; ;iFlip4 = iV01 & pTex->iFlipMaskV;
  299. movq mm7, mm1
  300. ; Point doesnt need replication
  301. movd mm4, [esi+SPANTEX_iFlipMaskU]
  302. ; if bilinear replicate values together, Point doesnt need this.
  303. punpckldq mm4, mm4
  304. ; Monolith cases assumed that iLOD0 was zero so no shift needed.
  305. pand mm7, mm4
  306. ;iFlip1 = MMX_cmpeqw(iFlip1, 0); ;iFlip2 = MMX_cmpeqw(iFlip2, 0); ;iFlip3 = MMX_cmpeqw(iFlip3, 0); ;iFlip4 = MMX_cmpeqw(iFlip4, 0);
  307. pcmpeqw mm7, MMWORD PTR Zero
  308. ;iFlip1 = uMaskU0 & ~ iFlip1; ;iFlip2 = uMaskV0 & ~ iFlip2; ;iFlip3 = uMaskU0 & ~ iFlip3; ;iFlip4 = uMaskV0 & ~ iFlip4;
  309. pandn mm7, mm0
  310. ;iU00 &= uMaskU0; ;iV00 &= uMaskV0; ;iU01 &= uMaskU0; ;iV01 &= uMaskV0;
  311. pand mm1, mm0
  312. ;iU00 ^= iFlip1; ;iV00 ^= iFlip2; ;iU01 ^= iFlip3; ;iV01 ^= iFlip4;
  313. pxor mm1, mm7
  314. ; Result in mm1 now since TexAddrAll ends up that way.
  315. ; Making other two cases for texture addressing has to be simplier than
  316. ; this and not use so many registers. Puts U1 V0 U0 V1 into mm3.
  317. ; TBD Make this better.
  318. ; values are still stored as iV01, iU00, iV00, iU01
  319. movq mm2, mm1
  320. movq mm3, mm1
  321. ; 1st and 3rd texels
  322. pmaddwd mm1, mm5 ; Throw in first address calculation.
  323. ; Just to get it started. Calculate
  324. ; iU0+iV1*iShiftU0 and iU1+iV0*iShiftU0
  325. ; values are being changed to iV01, iU01, iV00, iU00
  326. ; seven instructions for this seems excessive.
  327. pand mm2, MMWORD ptr MaskKeepUValues
  328. pand mm3, MMWORD ptr MaskKeepVValues
  329. movq mm4, mm2
  330. psllq mm2, 32
  331. psrlq mm4, 32
  332. por mm3, mm2
  333. por mm3, mm4
  334. ; From here until mov edi is code that is needed for border.
  335. ; all sign bits are stored in bytes so that border code can tell if uv went below zero.
  336. ; 2nd and 4th texels
  337. pmaddwd mm3, mm5 ; Calculates iU1+iV0*iShiftU0 and iU0+iV1*iShiftU0
  338. mov edi, [esi+SPANTEX_pBits]
  339. ; was esi. Cant change to esi because it is the pointer to pTex
  340. ; which is used by Border and ColorKey. Use edi for now and
  341. ; call routines through memory. Figure out if this is bad.
  342. ; load the read texture routine address into a register early
  343. ;mov edi, [ebx+RASTCTX_pfnTexRead]
  344. ;UINT32 uTex00 = pCtx->pfnTexRead(iU00, iV00, pTex->iShiftU,
  345. ; pTex->pBits[iLOD0], &pCtx->Texture[0]);
  346. ; Combine U and V values before making call.
  347. ;call edi
  348. ; -------------------- In Monolithic version calls are inlined.
  349. ;D3DCOLOR TexRead_B5G6R5_NoBorder(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  350. ;{
  351. ; added code for working on 2 pixels at a time
  352. ; iV0 iU1 address should be done by now.
  353. ; movq mm2, MMWORD PTR Zero
  354. pxor mm2, mm2
  355. ; 1st (mm1) and 2nd (mm3) texel
  356. movd eax, mm3 ; load 2nd texel address
  357. movzx eax, word ptr [edi+2*eax]
  358. movd mm4, eax ; mm4 = 2nd texel
  359. movd eax, mm1 ; load 1st texel address
  360. movzx eax, word ptr [edi+2*eax]
  361. movd mm7, eax ; mm7 = 1st texel
  362. ; mm7 = 2nd texel (high 32 bits), 1st texel (low 32 bits)
  363. punpckldq mm7, mm4
  364. movq mm5, mm7
  365. movq mm4, mm7
  366. pand mm5, MMWORD PTR BilinearMaskRed565to888 ; = 0x0000f8000000f800
  367. pand mm7, MMWORD PTR BilinearMaskGreen565to888 ; = 0x000007e0000007e0
  368. pand mm4, MMWORD PTR BilinearMaskBlue565to888 ; = 0x0000001f0000001f
  369. pslld mm5, MMWORD PTR BilinearShiftRed565to888 ; = 8
  370. pslld mm7, MMWORD PTR BilinearShiftGreen565to888 ; = 5
  371. pslld mm4, MMWORD PTR BilinearShiftBlue565to888 ; = 3
  372. por mm7, mm5 ; combine R+G
  373. por mm7, mm4 ; combine (R+G) + B
  374. movq mm4, mm7 ; copy 1st and 2nd texels
  375. ; mm4 calculated from high 32 bits of mm3 (2nd texel)
  376. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  377. ; bits for each color component
  378. punpckhbw mm4, mm2
  379. ; mm7 calculated from low 32 bits of mm1 (1st texel)
  380. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  381. ; bits for each color component
  382. punpcklbw mm7, mm2
  383. psrlq mm3, 32 ; shift 4th texel address into low 32 bits
  384. ; mm7 = final calc on 1st and 2nd texel
  385. psubw mm7, mm4
  386. psllw mm4, 8
  387. pmullw mm7, dword ptr UFrac
  388. paddw mm7, mm4
  389. ; 3rd (mm1) and 4th (mm3) texel
  390. movd eax, mm3 ; load 4th texel address
  391. psrlq mm1, 32 ; shift 3rd texel address into low 32 bits
  392. movzx eax, word ptr [edi+2*eax]
  393. movd mm6, eax ; mm6 = 4th texel
  394. movd eax, mm1 ; load 3rd texel address
  395. movzx eax, word ptr [edi+2*eax]
  396. movd mm4, eax ; mm4 = 3rd texel
  397. ; mm6 = 4th texel (high 32 bits), 3rd texel (low 32 bits)
  398. punpckldq mm6, mm4
  399. movq mm5, mm6
  400. movq mm4, mm6
  401. pand mm5, MMWORD PTR BilinearMaskRed565to888 ; = 0x0000f8000000f800
  402. pand mm6, MMWORD PTR BilinearMaskGreen565to888 ; = 0x000007e0000007e0
  403. pand mm4, MMWORD PTR BilinearMaskBlue565to888 ; = 0x0000001f0000001f
  404. pslld mm5, MMWORD PTR BilinearShiftRed565to888 ; = 8
  405. pslld mm6, MMWORD PTR BilinearShiftGreen565to888 ; = 5
  406. pslld mm4, MMWORD PTR BilinearShiftBlue565to888 ; = 3
  407. por mm6, mm5 ; combine R+G
  408. por mm6, mm4 ; combine (R+G) + B
  409. movq mm4, mm6 ; copy 3rd and 4th texels
  410. ; mm4 calculated from high 32 bits of mm3 (4th texel)
  411. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  412. ; bits for each color component
  413. punpckhbw mm4, mm2
  414. ; mm6 calculated from low 32 bits of mm1 (3rd texel)
  415. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  416. ; bits for each color component
  417. punpcklbw mm6, mm2
  418. psubw mm6, mm4
  419. psllw mm4, 8
  420. pmullw mm6, dword ptr UFrac
  421. movq mm1, mm7
  422. ; mm6 = final calc on 3rd and 4th texel
  423. paddw mm6, mm4
  424. ; mm4 = final calc on 1st+2nd texel and 3rd+4th texel
  425. psrlw mm6, 8
  426. psrlw mm7, 8
  427. psubw mm6, mm7
  428. pmullw mm6, dword ptr VFrac
  429. paddw mm6, mm1
  430. ; write
  431. ;*(PUINT16)pS->pSurface =
  432. ; ((pCtx->SI.uBR >> 0) & 0xf800) |
  433. ; ((pCtx->SI.uBG >> 5) & 0x07e0) |
  434. ; ((pCtx->SI.uBB >> 11) & 0x001f);
  435. mov edi, [ebp+RASTSPAN_pSurface]
  436. psrlw mm6, 8 ; Convert color1 from 8.8 two 0.8
  437. packuswb mm6, mm7 ; pack one color
  438. movq mm3, mm6
  439. pand mm6, MMWORD PTR u888to565RedBlueMask
  440. pmaddwd mm6, MMWORD PTR u888to565Multiplier
  441. pand mm3, MMWORD PTR u888to565GreenMask
  442. por mm6, mm3
  443. psrld mm6, 5
  444. movd edx, mm6
  445. mov [edi], dx
  446. ;//if (--uPix <= 0)
  447. ;// break;
  448. dec uPix ;// BUG BUG?? uPix should never start as zero should it?
  449. ;// if so, this is a bug.
  450. jle ExitPixelLoop
  451. ; Doing update code after span length test so that an extra update is not done.
  452. ;void TestFail_Gouraud_PerspTex1_NoSpecularFog(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  453. ; PD3DI_RASTSPAN pS)
  454. ;{
  455. ;pS->uB += pP->iDBDX; pS->uG += pP->iDGDX;
  456. ;pS->uR += pP->iDRDX; pS->uA += pP->iDADX;
  457. movq mm1, [ebp+RASTSPAN_uB]
  458. paddw mm1, [ecx+RASTPRIM_iDBDX]
  459. movq [ebp+RASTSPAN_uB], mm1
  460. ;pS->iUoW1 += pP->iDUoW1DX;
  461. ;pS->iVoW1 += pP->iDVoW1DX;
  462. movq mm5, [ebp+RASTSPAN_iUoW1]
  463. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  464. movq [ebp+RASTSPAN_iUoW1], mm5
  465. ;pS->iOoW += pP->iDOoWDX;
  466. mov eax, [ebp+RASTSPAN_iOoW]
  467. add eax, [ecx+RASTPRIM_iDOoWDX]
  468. mov [ebp+RASTSPAN_iOoW], eax
  469. ;INT32 iWn0 = pS->iW + pCtx->SI.iDW; // 1.15.16
  470. ; TODO Could do this and OoW Add at same time with MMX.
  471. mov edx, [ebp+RASTSPAN_iW]
  472. mov LastW, edx ; Save iW to calc iDW for next time.
  473. add edx, [ebx+RASTCTX_SI+SPANITER_iDW]
  474. ;if (pCtx->SI.iSpecialW < 0)
  475. ;{
  476. xor edi, edi
  477. cmp di, word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  478. jle DontDoSpecialW1
  479. ;DoSpecialW1:
  480. ; This label is a left over from when
  481. ;if (iWn0 < 0)
  482. ;{
  483. cmp edx, edi
  484. jl WOutOfRange1
  485. ;iWn0 = pS->iW >> 1; // use iW/2 as a guess, instead
  486. mov edx, LastW
  487. sar edx, 1
  488. ;}
  489. WOutOfRange1:
  490. ;VAL32 iWn1;
  491. ;INT16 iWnOld = iWn0 + 0x100; // make sure while fails first time
  492. ; Dont need to make sure it fails. I do a post test which guarentees it will execute once.
  493. ;INT32 iGiveUp = 7;
  494. mov GiveUp, 8 ; Pre decrementing instead of post decrementing.
  495. ;while((abs(iWnOld - iWn0) > 0x20) && (iGiveUp-- > 0))
  496. ;{
  497. SpecW1Loop1:
  498. ; Could move this to bottom of loop and combine results somehow.
  499. ; TBD look at it more.
  500. dec GiveUp
  501. jz ExitSpecWLoop1
  502. ; Shift iOoW by one since imul cannot have sign bit set
  503. ; OoW cannot reach one, only 0x7fffffff
  504. ;shr eax, 1 ; 1.31 >> 1 = 1.30
  505. ; Get ready to do Two minus iOoW*iW
  506. mov esi, (1 SHL 16)
  507. ;iWnOld = iWn0;
  508. mov edi, edx
  509. ; Result should be close to one so we want most of the
  510. ; precision in the low bits. Need to give more bits
  511. ; leaway since these are the bad cases.
  512. ; iWn1 = imul32h(pS->iOoW, iWn0); // 1.31*1.15.16 = 1.16.47 >> 32 = 1.16.15
  513. imul edx
  514. ;iWn1 = (1L<<16) - iWn1; // 2.0 - iWn1
  515. sub esi, edx
  516. ;while(iWn1.i < 0)
  517. ;{
  518. SpecW1Loop2:
  519. test esi, esi
  520. jns SpecW1ExitLoop2 ; This jump should be predicted correctly most of the time.
  521. ;iWn1=(iWn1+(1L<<15))>>1; // iWn1 = (iWn1 + 1.0)/2
  522. add esi, (1 SHL 15)
  523. sar esi, 1
  524. jmp SpecW1Loop2
  525. ;}
  526. SpecW1ExitLoop2:
  527. ;iWn1 <<= 15; // 1.16.15 << 15 = 1.1.30
  528. mov eax, edi
  529. shl eax, 5 ; 1.15.16 << 5 = 1.10.21 TBD Can I shift off upper bits??
  530. shl esi, 12 ; 4.15 << 12 = 4.27 ;
  531. ;iWn0 = imul32h(iWn1, iWn0)<<2; // 1.1.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14 << 2 = 1.15.16
  532. ; Actually 4.27 * 1.10.21 = 1.14.48 >> 32 = 1.14.16. No need for post shift.
  533. mul esi
  534. ; Have to do (abs(iWnOld - iWn0) > 0x20) code here.
  535. sub edi, edx
  536. ; These four lines are abs code.
  537. mov eax, edi
  538. sar eax, 31
  539. xor edi, eax
  540. sub edi, eax
  541. cmp edi, 020h ;Assuming that loop will only happen once.
  542. jbe ExitSpecWLoop1
  543. ; Reload eax with iOoW.
  544. mov eax, [ebp+RASTSPAN_iOoW]
  545. jmp SpecW1Loop1
  546. ;}
  547. ;else
  548. ;{
  549. DontDoSpecialW1:
  550. ; Everything should be positive in Non-SpecialW case.
  551. ;INT32 iWn1;
  552. mov esi, (1 SHL 16)
  553. mov edi, edx
  554. ; This should be close to one so Low bits are most important.
  555. ;iWn1 = (iOoW*iWn0)>>15; // 1.31*0.15.16 == 0.16.47 >> 32 = 0.16.15
  556. mul edx
  557. ;iWn1 = (1L<<16) - iWn1; // 2.0 - iWn1
  558. sub esi, edx
  559. ;iWn1 <<= 15; // 1.16.15 << 15 = 1.1.30
  560. shl esi, 15 ; 0.16.15 << 15 = 0.2.30
  561. mov eax, esi
  562. ;iWn0 = imul32h(iWn1, iWn0)<<2; // 1.1.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14 << 2 = 1.15.16
  563. mul edi ; 0.2.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14
  564. shl edx, 2 ; 1.17.14 << 2 = 1.15.16
  565. ;}
  566. ;}
  567. ExitSpecWLoop1:
  568. ;pCtx->SI.iDW = iWn0 - (UINT16)pS->iW;
  569. ;pS->iW = iWn0;
  570. mov [ebp+RASTSPAN_iW], edx
  571. mov esi, edx ; Save W for multiplying by UoW and VoW
  572. sub edx, LastW
  573. mov [ebx+RASTCTX_SI+SPANITER_iDW], edx
  574. ;pCtx->SI.iSpecialW += 1; // this is supposed to wrap past 0x7fff sometimes
  575. inc word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  576. ;pCtx->SI.iU1 = d_WTimesUVoW(pS->iW,pS->iUoW1);
  577. ;pCtx->SI.iV1 = d_WTimesUVoW(pS->iW,pS->iVoW1);
  578. pslld mm5, 8
  579. shl esi, 4
  580. movd eax, mm5
  581. psrlq mm5, 32
  582. imul esi
  583. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  584. movd eax, mm5
  585. imul esi
  586. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  587. ;//pS->pSurface += iSurfaceStep;
  588. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  589. add edx, iSurfaceStep
  590. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  591. ;#ifdef DBG
  592. ;// handy for debug to see where we are
  593. ;//pS->uX += (INT16)pCtx->SI.iXStep;
  594. ;#endif
  595. ;// } // while
  596. jmp PixelLoop
  597. ExitPixelLoop:
  598. ; Loop code ends
  599. ;-----------------------------------------------------------------------------
  600. ; LoopAny code ends here
  601. ;-----------------------------------------------------------------------------
  602. ;pS++;
  603. add ebp, SIZEOF_RASTSPAN
  604. ;}
  605. jmp SpanLoop
  606. ExitSpanLoop:
  607. ;pP = pP->pNext;
  608. mov ecx, [ecx+RASTPRIM_pNext]
  609. ;}
  610. jmp PrimLoop
  611. ExitPrimLoop:
  612. ;_asm{
  613. emms
  614. ;}
  615. ;return S_OK;
  616. xor eax, eax
  617. ;}
  618. pop edi
  619. pop esi
  620. pop ebx
  621. mov esp, StackPos
  622. pop ebp
  623. ret
  624. END