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.

779 lines
23 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 28. Perspective Correct Bi-linear gouraud modulated
  4. ; X888 input texture NO Z buffer
  5. ; X888 output.
  6. ;
  7. ; Exactly the same as monolith 7 except color input is 32 bits and
  8. ; output is 32 bits and no Z buffer code
  9. ;
  10. ;-----------------------------------------------------------------------------
  11. INCLUDE iammx.inc
  12. INCLUDE offs_acp.inc
  13. ; Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
  14. ; at the LSB, then six bits of green, then five bits of red.
  15. ;TBD check to see if this value is correct.
  16. COLOR_SHIFT equ 8
  17. .586
  18. .model flat
  19. ; Big seperating lines seperate code into span code
  20. ; and loop code. If span and loop are not going to
  21. ; end up being combined then it will be easy to
  22. ; seperate the code.
  23. .data
  24. ; Need externs for all of the variables that are needed for various beads
  25. EXTERN IncHighandLow16:MMWORD
  26. EXTERN UFracVFracMask:MMWORD
  27. EXTERN UV32to15Mask:MMWORD
  28. EXTERN Makelow16one:MMWORD
  29. EXTERN MaskKeepUValues:MMWORD
  30. EXTERN MaskKeepVValues:MMWORD
  31. EXTERN UFrac:MMWORD
  32. EXTERN VFrac:MMWORD
  33. EXTERN Zero:MMWORD
  34. EXTERN memD3DTFG_POINT:MMWORD
  35. EXTERN GiveUp:MMWORD
  36. EXTERN LastW:MMWORD
  37. EXTERN Val0x000a000a:MMWORD
  38. EXTERN Val0xffff:MMWORD
  39. EXTERN Val0x0000002000000020:MMWORD
  40. EXTERN Val0x0000ffff0000ffff:MMWORD
  41. EXTERN MaskRed565to888:MMWORD
  42. EXTERN MaskGreen565to888:MMWORD
  43. EXTERN MaskBlue565to888:MMWORD
  44. EXTERN MaskRed555to888:MMWORD
  45. EXTERN MaskGreen555to888:MMWORD
  46. EXTERN MaskBlue555to888:MMWORD
  47. EXTERN MaskAlpha1555to8888:MMWORD
  48. EXTERN MaskRed1555to8888:MMWORD
  49. EXTERN MaskGreen1555to8888:MMWORD
  50. EXTERN MaskBlue1555to8888:MMWORD
  51. ; TBD. I think that I want to do 0xffff instead of 0xff. This will
  52. ; have to be checked. There is a value very similiar to this in
  53. ; buf write.
  54. EXTERN SetAlphato0xffff:MMWORD
  55. EXTERN SetAlphato0xff:MMWORD
  56. ; TODO This equate are identical to the ones in texread.mas. Maybe they should be in a common .inc file.
  57. RedShift565to888 equ 8
  58. GreenShift565to888 equ 5
  59. BlueShift565to888 equ 3
  60. RedShift555to888 equ 9
  61. GreenShift555to888 equ 6
  62. BlueShift555to888 equ 3
  63. AlphaShift1555to8888 equ 16
  64. RedShift1555to8888 equ 9
  65. GreenShift1555to8888 equ 6
  66. BlueShift1555to8888 equ 3
  67. EXTERN BilinearMaskRed565to888:MMWORD
  68. EXTERN BilinearMaskGreen565to888:MMWORD
  69. EXTERN BilinearMaskBlue565to888:MMWORD
  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_28
  106. _MMXMLRast_28:
  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. ; ----------------- Start of hack
  246. ; ATTENTION This is really hacked right now. Just to get it working
  247. ; Pitch would be better for me, instead of shift pitch.
  248. ; With actual pitch, this would be two moves and a shift.
  249. ;shl eax, 1
  250. movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  251. add edx, 16
  252. movd mm2, edx
  253. movq mm5, MMWORD ptr Makelow16one
  254. pslld mm5, mm2
  255. ;pslld mm5, 16 ;. Use this after hack.
  256. ; not needed in hacked version since i add to shifted value.
  257. ; ----------------- End of hack
  258. por mm5, MMWORD ptr Makelow16one
  259. ; Make the low 16 bits of dword one
  260. ; This helps in calculating texture address.
  261. ; Gets U and V value into mm1 so that it can be mirrored, wrapped or
  262. ; clamped. This can be done for two values in the point case
  263. ; or four values in the bilinear case.
  264. ;INT32 iUFrac = iU00 & 0x03f;
  265. ;INT32 iVFrac = iV00 & 0x03f;
  266. ;iU00 >>= 6;
  267. ;iV00 >>= 6;
  268. movq mm2, mm1
  269. psrad mm1, 6
  270. ;pand mm1, MMWORD PTR Val0x0000ffff0000ffff
  271. pand mm2, dword ptr UFracVFracMask ; UFracVFracMask = 0x0000003f0000003f
  272. ; Going to use only 8 bits for bi-linear so that I can do a pmullw.
  273. ; Currently at 6 bits so shift up by 2.
  274. psllw mm2, 2
  275. movq mm0, mm2
  276. ; Replicate VFrac value for bilinear
  277. punpckhwd mm2, mm2
  278. punpcklwd mm2, mm2
  279. ; Replicate UFrac Value for bilinear
  280. punpcklwd mm0, mm0
  281. punpcklwd mm0, mm0
  282. movq dword ptr VFrac, mm2
  283. movq dword ptr UFrac, mm0
  284. ;INT32 iU01 = iU00 + 1;
  285. ;INT32 iV01 = iV00 + 1;
  286. packssdw mm1, mm1 ; replicate U and V value to upper 16 bit locations
  287. paddw mm1, dword ptr IncHighandLow16
  288. ; This will make texture values be (High word to low word):
  289. ; iV01, iU00, iV00, iU01
  290. ; Need to do this to make texture look up for bilinear easier.
  291. ; I have to combine to get all combinations anyway. It just
  292. ; happens to be better for me to have iV00, iU01 pair first.
  293. ;UINT16 uMaskU0 = pTex->uMaskU >> iLOD0; UINT16 uMaskV0 = pTex->uMaskV >> iLOD0;
  294. ; put mask in mm3 and replicate to match location for wrap/mirror/clamp
  295. movd mm0, [esi+SPANTEX_uMaskU] ; Load U and V mask
  296. ; replicate mask if doing bilinear
  297. punpckldq mm0, mm0
  298. ; Monolith cases assumed that iLOD0 was zero so no shift needed.
  299. ;INT16 iFlip;
  300. ; MM1 should contain 16 bit iU and iV for both texture locations
  301. ; End Result is MM1 value wrapped or mirrored
  302. ; in Bilinear Case, four values can be done
  303. ; iU00, iV00, iU01, iV01
  304. ; This code really does alot for the bilinear case and is kinda wasteful
  305. ; in the normal mode.
  306. ;iFlip1 = iU00 & pTex->iFlipMaskU; ;iFlip2 = iV00 & pTex->iFlipMaskV; ;iFlip3 = iU01 & pTex->iFlipMaskU; ;iFlip4 = iV01 & pTex->iFlipMaskV;
  307. movq mm7, mm1
  308. ; Point doesnt need replication
  309. movd mm4, [esi+SPANTEX_iFlipMaskU]
  310. ; if bilinear replicate values together, Point doesnt need this.
  311. punpckldq mm4, mm4
  312. ; Monolith cases assumed that iLOD0 was zero so no shift needed.
  313. pand mm7, mm4
  314. ;iFlip1 = MMX_cmpeqw(iFlip1, 0); ;iFlip2 = MMX_cmpeqw(iFlip2, 0); ;iFlip3 = MMX_cmpeqw(iFlip3, 0); ;iFlip4 = MMX_cmpeqw(iFlip4, 0);
  315. pcmpeqw mm7, MMWORD PTR Zero
  316. ;iFlip1 = uMaskU0 & ~ iFlip1; ;iFlip2 = uMaskV0 & ~ iFlip2; ;iFlip3 = uMaskU0 & ~ iFlip3; ;iFlip4 = uMaskV0 & ~ iFlip4;
  317. pandn mm7, mm0
  318. ;iU00 &= uMaskU0; ;iV00 &= uMaskV0; ;iU01 &= uMaskU0; ;iV01 &= uMaskV0;
  319. pand mm1, mm0
  320. ;iU00 ^= iFlip1; ;iV00 ^= iFlip2; ;iU01 ^= iFlip3; ;iV01 ^= iFlip4;
  321. pxor mm1, mm7
  322. ; Result in mm1 now since TexAddrAll ends up that way.
  323. ; Making other two cases for texture addressing has to be simplier than
  324. ; this and not use so many registers. Puts U1 V0 U0 V1 into mm3.
  325. ; TBD Make this better.
  326. ; values are still stored as iV01, iU00, iV00, iU01
  327. movq mm2, mm1
  328. movq mm3, mm1
  329. ; Calculate address for 1st and 3rd texels
  330. pmaddwd mm1, mm5 ; Throw in first address calculation.
  331. ; Just to get it started. Calculate
  332. ; iU0+iV1*iShiftU0 and iU1+iV0*iShiftU0
  333. ; values are being changed to iV01, iU01, iV00, iU00
  334. ; seven instructions for this seems excessive.
  335. pand mm2, MMWORD ptr MaskKeepUValues
  336. pand mm3, MMWORD ptr MaskKeepVValues
  337. movq mm4, mm2
  338. psllq mm2, 32
  339. psrlq mm4, 32
  340. por mm3, mm2
  341. por mm3, mm4
  342. ; Calculate address for 2nd and 4th texels
  343. pmaddwd mm3, mm5 ; Calculates iU1+iV0*iShiftU0 and iU0+iV1*iShiftU0
  344. mov edi, [esi+SPANTEX_pBits]
  345. ;UINT32 uTex00 = pCtx->pfnTexRead(iU00, iV00, pTex->iShiftU,
  346. ; pTex->pBits[iLOD0], &pCtx->Texture[0]);
  347. ; Combine U and V values before making call.
  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 color converting 2 pixels at a time
  352. ; movq mm2, MMWORD PTR Zero
  353. pxor mm2, mm2
  354. ; 1st (mm1) and 2nd (mm3) texel
  355. movd eax, mm3 ; load 2nd texel address
  356. movd mm4, dword ptr [edi+4*eax] ; mm4 = 2nd texel
  357. movd eax, mm1 ; load 1st texel address
  358. movd mm7, dword ptr [edi+4*eax] ; mm7 = 1st texel
  359. ; mm4 calculated from high 32 bits of mm3 (2nd texel)
  360. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  361. ; bits for each color component
  362. punpcklbw mm4, mm2
  363. ; mm7 calculated from low 32 bits of mm1 (1st texel)
  364. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  365. ; bits for each color component
  366. punpcklbw mm7, mm2
  367. psrlq mm3, 32 ; shift 4th texel address into low 32 bits
  368. ; mm7 = final calc on 1st and 2nd texel
  369. psubw mm7, mm4
  370. psllw mm4, 8
  371. pmullw mm7, dword ptr UFrac
  372. paddw mm7, mm4
  373. ; 3rd (mm1) and 4th (mm3) texel
  374. movd eax, mm3 ; load 4th texel address
  375. psrlq mm1, 32 ; shift 3rd texel address into low 32 bits
  376. movd mm6, dword ptr [edi+4*eax] ; mm6 = 4th texel
  377. movd eax, mm1 ; load 3rd texel address
  378. movd mm4, dword ptr [edi+4*eax] ; mm4 = 3rd texel
  379. ; mm4 calculated from high 32 bits of mm3 (4th texel)
  380. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  381. ; bits for each color component
  382. punpcklbw mm4, mm2
  383. ; mm6 calculated from low 32 bits of mm1 (3rd texel)
  384. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  385. ; bits for each color component
  386. punpcklbw mm6, mm2
  387. psubw mm6, mm4
  388. psllw mm4, 8
  389. pmullw mm6, dword ptr UFrac
  390. movq mm1, mm7
  391. ; mm6 = final calc on 3rd and 4th texel
  392. paddw mm6, mm4
  393. ; mm1 = final calc on 1st+2nd texel and 3rd+4th texel
  394. psrlw mm6, 8
  395. psrlw mm7, 8
  396. psubw mm6, mm7
  397. pmullw mm6, dword ptr VFrac
  398. paddw mm1, mm6
  399. psrlw mm1, 8
  400. ;modulate
  401. ;UINT16 uB = pS->uB>>COLOR_SHIFT;
  402. ;UINT16 uG = pS->uG>>COLOR_SHIFT;
  403. ;UINT16 uR = pS->uR>>COLOR_SHIFT;
  404. movq mm4, [ebp+RASTSPAN_uB]
  405. psrlw mm4, COLOR_SHIFT ; COLOR_SHIFT is set to 8.
  406. ; Alpha not needed in this monolith
  407. ;UINT16 uTB = (UINT16)(RGBA_GETBLUE(pCtx->SI.TexCol[0]));
  408. ;UINT16 uTG = (UINT16)(RGBA_GETGREEN(pCtx->SI.TexCol[0]));
  409. ;UINT16 uTR = (UINT16)(RGBA_GETRED(pCtx->SI.TexCol[0]));
  410. ;UINT16 uTA = (UINT16)(RGBA_GETALPHA(pCtx->SI.TexCol[0]));
  411. ; this is a PMULLW, which works on unsigned 16 bit quantities
  412. ;pCtx->SI.uBB = uB*uTB;
  413. ;pCtx->SI.uBG = uG*uTG;
  414. ;pCtx->SI.uBR = uR*uTR;
  415. ;pCtx->SI.uBA = uTA<<COLOR_SHIFT;
  416. pmullw mm4, mm1
  417. ; write
  418. mov edi, [ebp+RASTSPAN_pSurface]
  419. psrlw mm4, 8 ; Convert color1 from 8.8 two 0.8
  420. packuswb mm4, mm7 ; pack one color
  421. movd edx, mm4
  422. and edx, 000ffffffh
  423. mov [edi], edx
  424. ;//if (--uPix <= 0)
  425. ;// break;
  426. dec uPix ;// BUG BUG?? uPix should never start as zero should it?
  427. ;// if so, this is a bug.
  428. jle ExitPixelLoop
  429. ; Doing update code after span length test so that an extra update is not done.
  430. ;void TestFail_Gouraud_PerspTex1_NoSpecularFog(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  431. ; PD3DI_RASTSPAN pS)
  432. ;{
  433. ;pS->uB += pP->iDBDX; pS->uG += pP->iDGDX;
  434. ;pS->uR += pP->iDRDX; pS->uA += pP->iDADX;
  435. movq mm1, [ebp+RASTSPAN_uB]
  436. paddw mm1, [ecx+RASTPRIM_iDBDX]
  437. movq [ebp+RASTSPAN_uB], mm1
  438. ;pS->iUoW1 += pP->iDUoW1DX;
  439. ;pS->iVoW1 += pP->iDVoW1DX;
  440. movq mm5, [ebp+RASTSPAN_iUoW1]
  441. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  442. movq [ebp+RASTSPAN_iUoW1], mm5
  443. ;pS->iOoW += pP->iDOoWDX;
  444. mov eax, [ebp+RASTSPAN_iOoW]
  445. add eax, [ecx+RASTPRIM_iDOoWDX]
  446. mov [ebp+RASTSPAN_iOoW], eax
  447. ;INT32 iWn0 = pS->iW + pCtx->SI.iDW; // 1.15.16
  448. ; TODO Could do this and OoW Add at same time with MMX.
  449. mov edx, [ebp+RASTSPAN_iW]
  450. mov LastW, edx ; Save iW to calc iDW for next time.
  451. add edx, [ebx+RASTCTX_SI+SPANITER_iDW]
  452. ;if (pCtx->SI.iSpecialW < 0)
  453. ;{
  454. xor edi, edi
  455. cmp di, word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  456. jle DontDoSpecialW1
  457. ;DoSpecialW1:
  458. ; This label is a left over from when
  459. ;if (iWn0 < 0)
  460. ;{
  461. cmp edx, edi
  462. jl WOutOfRange1
  463. ;iWn0 = pS->iW >> 1; // use iW/2 as a guess, instead
  464. mov edx, LastW
  465. sar edx, 1
  466. ;}
  467. WOutOfRange1:
  468. ;VAL32 iWn1;
  469. ;INT16 iWnOld = iWn0 + 0x100; // make sure while fails first time
  470. ; Dont need to make sure it fails. I do a post test which guarentees it will execute once.
  471. ;INT32 iGiveUp = 7;
  472. mov GiveUp, 8 ; Pre decrementing instead of post decrementing.
  473. ;while((abs(iWnOld - iWn0) > 0x20) && (iGiveUp-- > 0))
  474. ;{
  475. SpecW1Loop1:
  476. ; Could move this to bottom of loop and combine results somehow.
  477. ; TBD look at it more.
  478. dec GiveUp
  479. jz ExitSpecWLoop1
  480. ; Shift iOoW by one since imul cannot have sign bit set
  481. ; OoW cannot reach one, only 0x7fffffff
  482. ;shr eax, 1 ; 1.31 >> 1 = 1.30
  483. ; Get ready to do Two minus iOoW*iW
  484. mov esi, (1 SHL 16)
  485. ;iWnOld = iWn0;
  486. mov edi, edx
  487. ; Result should be close to one so we want most of the
  488. ; precision in the low bits. Need to give more bits
  489. ; leaway since these are the bad cases.
  490. ; iWn1 = imul32h(pS->iOoW, iWn0); // 1.31*1.15.16 = 1.16.47 >> 32 = 1.16.15
  491. imul edx
  492. ;iWn1 = (1L<<16) - iWn1; // 2.0 - iWn1
  493. sub esi, edx
  494. ;while(iWn1.i < 0)
  495. ;{
  496. SpecW1Loop2:
  497. test esi, esi
  498. jns SpecW1ExitLoop2 ; This jump should be predicted correctly most of the time.
  499. ;iWn1=(iWn1+(1L<<15))>>1; // iWn1 = (iWn1 + 1.0)/2
  500. add esi, (1 SHL 15)
  501. sar esi, 1
  502. jmp SpecW1Loop2
  503. ;}
  504. SpecW1ExitLoop2:
  505. ;iWn1 <<= 15; // 1.16.15 << 15 = 1.1.30
  506. mov eax, edi
  507. shl eax, 5 ; 1.15.16 << 5 = 1.10.21 TBD Can I shift off upper bits??
  508. shl esi, 12 ; 4.15 << 12 = 4.27 ;
  509. ;iWn0 = imul32h(iWn1, iWn0)<<2; // 1.1.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14 << 2 = 1.15.16
  510. ; Actually 4.27 * 1.10.21 = 1.14.48 >> 32 = 1.14.16. No need for post shift.
  511. mul esi
  512. ; Have to do (abs(iWnOld - iWn0) > 0x20) code here.
  513. sub edi, edx
  514. ; These four lines are abs code.
  515. mov eax, edi
  516. sar eax, 31
  517. xor edi, eax
  518. sub edi, eax
  519. cmp edi, 020h ;Assuming that loop will only happen once.
  520. jbe ExitSpecWLoop1
  521. ; Reload eax with iOoW.
  522. mov eax, [ebp+RASTSPAN_iOoW]
  523. jmp SpecW1Loop1
  524. ;}
  525. ;else
  526. ;{
  527. DontDoSpecialW1:
  528. ; Everything should be positive in Non-SpecialW case.
  529. ;INT32 iWn1;
  530. mov esi, (1 SHL 16)
  531. mov edi, edx
  532. ; This should be close to one so Low bits are most important.
  533. ;iWn1 = (iOoW*iWn0)>>15; // 1.31*0.15.16 == 0.16.47 >> 32 = 0.16.15
  534. mul edx
  535. ;iWn1 = (1L<<16) - iWn1; // 2.0 - iWn1
  536. sub esi, edx
  537. ;iWn1 <<= 15; // 1.16.15 << 15 = 1.1.30
  538. shl esi, 15 ; 0.16.15 << 15 = 0.2.30
  539. mov eax, esi
  540. ;iWn0 = imul32h(iWn1, iWn0)<<2; // 1.1.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14 << 2 = 1.15.16
  541. mul edi ; 0.2.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14
  542. shl edx, 2 ; 1.17.14 << 2 = 1.15.16
  543. ;}
  544. ;}
  545. ExitSpecWLoop1:
  546. ;pCtx->SI.iDW = iWn0 - (UINT16)pS->iW;
  547. ;pS->iW = iWn0;
  548. mov [ebp+RASTSPAN_iW], edx
  549. mov esi, edx ; Save W for multiplying by UoW and VoW
  550. sub edx, LastW
  551. mov [ebx+RASTCTX_SI+SPANITER_iDW], edx
  552. ;pCtx->SI.iSpecialW += 1; // this is supposed to wrap past 0x7fff sometimes
  553. inc word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  554. ;pCtx->SI.iU1 = d_WTimesUVoW(pS->iW,pS->iUoW1);
  555. ;pCtx->SI.iV1 = d_WTimesUVoW(pS->iW,pS->iVoW1);
  556. pslld mm5, 8
  557. shl esi, 4
  558. movd eax, mm5
  559. psrlq mm5, 32
  560. imul esi
  561. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  562. movd eax, mm5
  563. imul esi
  564. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  565. ;//pS->pSurface += iSurfaceStep;
  566. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  567. add edx, iSurfaceStep
  568. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  569. ;#ifdef DBG
  570. ;// handy for debug to see where we are
  571. ;//pS->uX += (INT16)pCtx->SI.iXStep;
  572. ;#endif
  573. ;// } // while
  574. jmp PixelLoop
  575. ExitPixelLoop:
  576. ; Loop code ends
  577. ;-----------------------------------------------------------------------------
  578. ; LoopAny code ends here
  579. ;-----------------------------------------------------------------------------
  580. ;pS++;
  581. add ebp, SIZEOF_RASTSPAN
  582. ;}
  583. jmp SpanLoop
  584. ExitSpanLoop:
  585. ;pP = pP->pNext;
  586. mov ecx, [ecx+RASTPRIM_pNext]
  587. ;}
  588. jmp PrimLoop
  589. ExitPrimLoop:
  590. ;_asm{
  591. emms
  592. ;}
  593. ;return S_OK;
  594. xor eax, eax
  595. ;}
  596. pop edi
  597. pop esi
  598. pop ebx
  599. mov esp, StackPos
  600. pop ebp
  601. ret
  602. END