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.

699 lines
14 KiB

  1. ;---------------------------Module-Header------------------------------;
  2. ; Module Name: span.asm
  3. ;
  4. ; Created: 2/3/94
  5. ; Author: Otto Berkes [ottob]
  6. ;
  7. ; Get serious about drawing scanlines.
  8. ;
  9. ; Copyright (c) 1994 Microsoft Corporation
  10. ;----------------------------------------------------------------------;
  11. .386
  12. .model small,c
  13. assume cs:FLAT,ds:FLAT,es:FLAT,ss:FLAT
  14. assume fs:nothing,gs:nothing
  15. .xlist
  16. include gli386.inc
  17. .list
  18. .data
  19. NOP_CODE = 090h ;nop
  20. JMP_CODE = 0EBh ;short jump
  21. ;; 4x4 (Bayer) dither matrix (Foley & van Dam 13.15) biased for
  22. ;; fractional values between 0 and 0ffh
  23. Dither_4x4 dd 0008020a0h
  24. dd 0c040e060h
  25. dd 030b01090h
  26. dd 0f070d050h
  27. .code
  28. ;; Z-test function opcodes. The assembled operands required for the
  29. ;; selected z-comparison are inserted into the loaded span routine
  30. ztest_fail_functions_short::
  31. psZtest_never:
  32. db 2 dup (NOP_CODE)
  33. psZtest_l:
  34. jb short @target
  35. psZtest_e:
  36. je short @target
  37. psZtest_le:
  38. jbe short @target
  39. psZtest_g:
  40. ja short @target
  41. psZtest_ne:
  42. jne short @target
  43. psZtest_ge:
  44. jae short @target
  45. psZtest_always:
  46. jmp short $+2
  47. ztest_pass_functions_short::
  48. fsZtest_never:
  49. db 2 dup (NOP_CODE)
  50. fsZtest_ge:
  51. jae short @target
  52. fsZtest_ne:
  53. jne short @target
  54. fsZtest_g:
  55. ja short @target
  56. fsZtest_le:
  57. jbe short @target
  58. fsZtest_e:
  59. je short @target
  60. fsZtest_l:
  61. jb short @target
  62. fsZtest_always:
  63. jmp short $+2
  64. @target:
  65. ztest_fail_functions::
  66. pZtest_never:
  67. db 6 dup (NOP_CODE)
  68. pZtest_l:
  69. jb near ptr @target
  70. pZtest_e:
  71. je near ptr @target
  72. pZtest_le:
  73. jbe near ptr @target
  74. pZtest_g:
  75. ja near ptr @target
  76. pZtest_ne:
  77. jne near ptr @target
  78. pZtest_ge:
  79. jae near ptr @target
  80. pZtest_always:
  81. jmp $+6
  82. ztest_pass_functions::
  83. fZtest_never:
  84. db 6 dup (NOP_CODE)
  85. fZtest_ge:
  86. jae near ptr @target
  87. fZtest_ne:
  88. jne near ptr @target
  89. fZtest_g:
  90. ja near ptr @target
  91. fZtest_le:
  92. jbe near ptr @target
  93. fZtest_e:
  94. je near ptr @target
  95. fZtest_l:
  96. jb near ptr @target
  97. fZtest_always:
  98. jmp $+6
  99. ;----------------------------------------------------------------------
  100. ; int __fastProcsSize
  101. ;
  102. ; Returns size needed for function/data storage. This could be done as
  103. ; a global...
  104. ;----------------------------------------------------------------------
  105. __fastProcsSize PROC
  106. mov eax, size __FASTFUNCSINTERNAL
  107. ret
  108. __fastProcsSize ENDP
  109. ;----------------------------------------------------------------------
  110. ; __fastDepthTestSpan
  111. ;
  112. ; Run the z interpolation for the supplied span.
  113. ;----------------------------------------------------------------------
  114. zspan_begin::
  115. __fastDepthTestSpan PROC uses ebx edx esi edi, GLCONTEXT: ptr
  116. LOCAL deltazx: dword
  117. LOCAL scan_len: dword
  118. LOCAL scan_len_org: dword
  119. LOCAL mask_addr: dword
  120. mov esi, GLCONTEXT
  121. mov edi, [esi].CTX_polygon.POLY_shader.SHADE_zbuf ; edi points to z-buffer
  122. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_spanLength
  123. mov scan_len, eax
  124. mov scan_len_org, eax
  125. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_dzdx
  126. mov deltazx, eax
  127. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_stipplePat
  128. mov mask_addr, eax
  129. ; eax is initial z value
  130. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_z
  131. xor esi, esi ; esi maintains "fail" count
  132. align 4
  133. z_loop:
  134. mov ecx, scan_len
  135. sub scan_len, 32
  136. test ecx, ecx
  137. jle z_done
  138. cmp ecx, 32
  139. jle short small_zfrag
  140. mov ecx, 32
  141. small_zfrag:
  142. ;; alternative for above?
  143. ;; mov eax, 32 ; ecx = min(ecx-1, 31)
  144. ;; cmp eax, ecx
  145. ;; sbb ah, 0
  146. ;; dec ecx
  147. ;; or cl, ch
  148. ;; and ecx, 01fh
  149. mov edx, 07fffffffh ; mask bit
  150. mov ebx, -1 ; initial mask value is all 1's
  151. align 4
  152. zrep_pass: ; case for test pass
  153. cmp eax, [edi]
  154. zspan_pass_op::
  155. jae short zcmp_fail_r1
  156. zspan_write::
  157. zcmp_pass_r1:
  158. mov [edi],eax
  159. add eax, deltazx
  160. add edi, __GlzValueSize
  161. ror edx, 1
  162. dec ecx
  163. jg short zrep_pass
  164. mov ecx, mask_addr
  165. mov [ecx], ebx
  166. add ecx, 4
  167. mov mask_addr, ecx
  168. jmp short z_loop
  169. align 4
  170. zrep_fail: ; case for test fail
  171. cmp eax, [edi]
  172. zspan_fail_op::
  173. jb short zcmp_pass_r1
  174. zcmp_fail_r1:
  175. add eax, deltazx
  176. and ebx, edx
  177. inc esi ; increment fail count
  178. add edi, __GLzValueSize
  179. ror edx, 1
  180. dec ecx
  181. jg short zrep_fail
  182. mov ecx, mask_addr
  183. mov [ecx], ebx
  184. add ecx, 4
  185. mov mask_addr, ecx
  186. jmp short z_loop
  187. z_done:
  188. xor eax, eax
  189. cmp esi, 0
  190. jne z_fails
  191. ret
  192. z_fails:
  193. inc eax
  194. xor ebx, ebx
  195. cmp esi, scan_len_org
  196. jne z_fails_some
  197. mov esi, GLCONTEXT
  198. mov dword ptr [esi].CTX_polygon.POLY_shader.SHADE_done, 1
  199. z_fails_some:
  200. ret
  201. __fastDepthTestSpan ENDP
  202. zspan_end::
  203. XOFS MACRO target
  204. mov edi, funcAddr
  205. add edi, offset target - offset zspan_begin
  206. ENDM
  207. ;----------------------------------------------------------------------
  208. ; __fastDepthTestSpanSetup(GLCONTEXT *)
  209. ;
  210. ; Copy the span depth-test span routine from the template and modify it
  211. ; to reflect the current z mode.
  212. ;----------------------------------------------------------------------
  213. __fastDepthTestSpanSetup PROC uses ebx edx esi edi, GLCONTEXT: ptr
  214. LOCAL funcAddr: dword
  215. mov edi, GLCONTEXT
  216. mov edi, [edi].GENCTX_pPrivateArea
  217. add edi, __spanZFunc
  218. mov funcAddr, edi
  219. mov esi, offset __fastDepthTestSpan
  220. mov ecx, (zspan_end - zspan_begin + 3) / 4
  221. rep movsd
  222. mov esi, GLCONTEXT
  223. mov edx, [esi].CTX_drawBuffer
  224. ;; z-test conditions
  225. mov ebx, [esi].CTX_state.ATTR_depth.DEPTH_testFunc
  226. and ebx, 3
  227. add ebx, ebx ; 2 bytes/short jump
  228. ;; z-test pass condition
  229. mov al, byte ptr ztest_pass_functions_short[ebx]
  230. XOFS zspan_pass_op
  231. mov [edi], al
  232. ;; z-test fail condition
  233. mov al, byte ptr ztest_fail_functions_short[ebx]
  234. XOFS zspan_fail_op
  235. mov [edi], al
  236. ;; z write-enable
  237. test dword ptr [esi].CTX_state.ATTR_depth.DEPTH_writeEnable, 1
  238. jne @zwriteEnabled
  239. XOFS zspan_write
  240. mov byte ptr [edi], NOP_CODE
  241. mov byte ptr [edi]+1, NOP_CODE
  242. mov eax, funcAddr
  243. @zwriteEnabled:
  244. ret
  245. __fastDepthTestSpanSetup ENDP
  246. ;----------------------------------------------------------------------
  247. ; __fastDeltaSpan(GLCONTEXT *)
  248. ;
  249. ; Set up the scan x delta values for subsequent spans.
  250. ;----------------------------------------------------------------------
  251. __fastDeltaSpan PROC uses ebx esi edi, GLCONTEXT: ptr, SCANDELTA: ptr
  252. mov esi, GLCONTEXT
  253. mov ebx, [esi].CTX_polygon.POLY_shader.SHADE_modeFlags
  254. mov edi, [esi].GENCTX_pPrivateArea
  255. mov edi, [edi]
  256. mov esi, SCANDELTA
  257. test ebx, __GL_SHADE_RGB
  258. jne @doRGB
  259. mov eax, __spanFlatFunc
  260. test ebx, __GL_SHADE_SMOOTH
  261. je @flatI
  262. mov ecx, [esi].SPANREC_r
  263. mov [edi].FASTFUNCS_spanDelta.SPANREC_r, ecx
  264. cmp ecx, 0
  265. je @flatI
  266. mov eax, __spanSmoothFunc
  267. @flatI:
  268. mov ecx, [esi].SPANREC_z
  269. mov [edi].FASTFUNCS_spanDelta.SPANREC_z, ecx
  270. mov esi, GLCONTEXT
  271. add eax, [esi].GENCTX_pPrivateArea
  272. mov [edi].FASTFUNCS_fastSpanFuncPtr, eax
  273. ret
  274. @doRGB:
  275. mov eax, __spanFlatFunc
  276. test ebx, __GL_SHADE_SMOOTH
  277. je @flatRGB
  278. mov ecx, [esi].SPANREC_r
  279. mov edx, ecx
  280. mov [edi].FASTFUNCS_spanDelta.SPANREC_r, ecx
  281. mov ecx, [esi].SPANREC_g
  282. or edx, ecx
  283. mov [edi].FASTFUNCS_spanDelta.SPANREC_g, ecx
  284. mov ecx, [esi].SPANREC_b
  285. or edx, ecx
  286. mov [edi].FASTFUNCS_spanDelta.SPANREC_b, ecx
  287. je @flatRGB
  288. mov eax, offset __spanSmoothFunc
  289. @flatRGB:
  290. mov ecx, [esi].SPANREC_z
  291. mov [edi].FASTFUNCS_spanDelta.SPANREC_z, ecx
  292. mov esi, GLCONTEXT
  293. add eax, [esi].GENCTX_pPrivateArea
  294. mov [edi].FASTFUNCS_fastSpanFuncPtr, eax
  295. ret
  296. __fastDeltaSpan ENDP
  297. ;======================================================================
  298. ; Smooth-shaded dithered RGB spans.
  299. ;======================================================================
  300. PROCNAME MACRO name
  301. __fastRGB&name
  302. ENDM
  303. XNAME MACRO name
  304. pix_ssrgb_&name
  305. ENDM
  306. COPYPROC MACRO
  307. mov edi, GLCONTEXT
  308. mov edi, [edi].GENCTX_pPrivateArea
  309. add edi, __spanSmoothFunc
  310. mov funcAddr, edi
  311. mov esi, offset __fastRGBSmoothSpan
  312. mov ecx, (pix_ssrgb_end - pix_ssrgb_begin + 3) / 4
  313. rep movsd
  314. ENDM
  315. ;;Macro to compute relative offset between a base and target
  316. XOFS MACRO target
  317. mov edi, funcAddr
  318. add edi, offset pix_ssrgb_&target - offset pix_ssrgb_begin
  319. ;; Note: the assembler produces an error if we try to combine the
  320. ;; above into a single operation due to "mismatched segments". Arg!
  321. ENDM
  322. DITHER = 1
  323. RGBMODE = 1
  324. ;=================
  325. INCLUDE span_s.asm
  326. ;=================
  327. ;======================================================================
  328. ; Flat-shaded dithered RGB spans.
  329. ;======================================================================
  330. PROCNAME MACRO name
  331. __fastRGB&name
  332. ENDM
  333. XNAME MACRO name
  334. pix_fsrgb_&name
  335. ENDM
  336. COPYPROC MACRO
  337. mov edi, GLCONTEXT
  338. mov edi, [edi].GENCTX_pPrivateArea
  339. add edi, __spanFlatFunc
  340. mov funcAddr, edi
  341. mov esi, offset __fastRGBFlatSpan
  342. mov ecx, (pix_fsrgb_end - pix_fsrgb_begin + 3) / 4
  343. rep movsd
  344. ENDM
  345. ;;Macro to compute relative offset between a base and target
  346. XOFS MACRO target
  347. mov edi, funcAddr
  348. add edi, offset pix_fsrgb_&target - offset pix_fsrgb_begin
  349. ENDM
  350. DITHER = 1
  351. RGBMODE = 1
  352. ;=================
  353. INCLUDE span_f.asm
  354. ;=================
  355. ;======================================================================
  356. ; Smooth-shaded dithered CI spans.
  357. ;======================================================================
  358. PROCNAME MACRO name
  359. __fastCI&name
  360. ENDM
  361. XNAME MACRO name
  362. pix_ssci_&name
  363. ENDM
  364. COPYPROC MACRO
  365. mov edi, GLCONTEXT
  366. mov edi, [edi].GENCTX_pPrivateArea
  367. add edi, __spanSmoothFunc
  368. mov funcAddr, edi
  369. mov esi, offset __fastCISmoothSpan
  370. mov ecx, (pix_ssci_end - pix_ssci_begin + 3) / 4
  371. rep movsd
  372. ENDM
  373. ;;Macro to compute relative offset between a base and target
  374. XOFS MACRO target
  375. mov edi, funcAddr
  376. add edi, offset pix_ssci_&target - offset pix_ssci_begin
  377. ENDM
  378. DITHER = 1
  379. RGBMODE = 0
  380. ;=================
  381. INCLUDE span_s.asm
  382. ;=================
  383. ;======================================================================
  384. ; Flat-shaded dithered CI spans.
  385. ;======================================================================
  386. PROCNAME MACRO name
  387. __fastCI&name
  388. ENDM
  389. XNAME MACRO name
  390. pix_fsci_&name
  391. ENDM
  392. COPYPROC MACRO
  393. mov edi, GLCONTEXT
  394. mov edi, [edi].GENCTX_pPrivateArea
  395. add edi, __spanFlatFunc
  396. mov funcAddr, edi
  397. mov esi, offset __fastCIFlatSpan
  398. mov ecx, (pix_fsci_end - pix_fsci_begin + 3) / 4
  399. rep movsd
  400. ENDM
  401. ;;Macro to compute relative offset between a base and target
  402. XOFS MACRO target
  403. mov edi, funcAddr
  404. add edi, offset pix_fsci_&target - offset pix_fsci_begin
  405. ENDM
  406. DITHER = 1
  407. RGBMODE = 0
  408. ;=================
  409. INCLUDE span_f.asm
  410. ;=================
  411. ;======================================================================
  412. ;======================================================================
  413. ;
  414. ; Non-dithered routines
  415. ;
  416. ;======================================================================
  417. ;======================================================================
  418. ;======================================================================
  419. ; Smooth-shaded non-dithered RGB spans.
  420. ;======================================================================
  421. PROCNAME MACRO name
  422. __fastRGBND&name
  423. ENDM
  424. XNAME MACRO name
  425. pix_ssrgbnd_&name
  426. ENDM
  427. COPYPROC MACRO
  428. mov edi, GLCONTEXT
  429. mov edi, [edi].GENCTX_pPrivateArea
  430. add edi, __spanSmoothFunc
  431. mov funcAddr, edi
  432. mov esi, offset __fastRGBNDSmoothSpan
  433. mov ecx, (pix_ssrgbnd_end - pix_ssrgbnd_begin + 3) / 4
  434. rep movsd
  435. ENDM
  436. ;;Macro to compute relative offset between a base and target
  437. XOFS MACRO target
  438. mov edi, funcAddr
  439. add edi, offset pix_ssrgbnd_&target - offset pix_ssrgbnd_begin
  440. ;; Note: the assembler produces an error if we try to combine the
  441. ;; above into a single operation due to "mismatched segments". Arg!
  442. ENDM
  443. DITHER = 0
  444. RGBMODE = 1
  445. ;=================
  446. INCLUDE span_s.asm
  447. ;=================
  448. ;======================================================================
  449. ; Flat-shaded non-dithered RGB spans.
  450. ;======================================================================
  451. PROCNAME MACRO name
  452. __fastRGBND&name
  453. ENDM
  454. XNAME MACRO name
  455. pix_fsrgbnd_&name
  456. ENDM
  457. COPYPROC MACRO
  458. mov edi, GLCONTEXT
  459. mov edi, [edi].GENCTX_pPrivateArea
  460. add edi, __spanFlatFunc
  461. mov funcAddr, edi
  462. mov esi, offset __fastRGBNDFlatSpan
  463. mov ecx, (pix_fsrgbnd_end - pix_fsrgbnd_begin + 3) / 4
  464. rep movsd
  465. ENDM
  466. ;;Macro to compute relative offset between a base and target
  467. XOFS MACRO target
  468. mov edi, funcAddr
  469. add edi, offset pix_fsrgbnd_&target - offset pix_fsrgbnd_begin
  470. ENDM
  471. DITHER = 0
  472. RGBMODE = 1
  473. ;=================
  474. INCLUDE span_f.asm
  475. ;=================
  476. ;======================================================================
  477. ; Smooth-shaded non-dithered CI spans.
  478. ;======================================================================
  479. PROCNAME MACRO name
  480. __fastCIND&name
  481. ENDM
  482. XNAME MACRO name
  483. pix_sscind_&name
  484. ENDM
  485. COPYPROC MACRO
  486. mov edi, GLCONTEXT
  487. mov edi, [edi].GENCTX_pPrivateArea
  488. add edi, __spanSmoothFunc
  489. mov funcAddr, edi
  490. mov esi, offset __fastCINDSmoothSpan
  491. mov ecx, (pix_sscind_end - pix_sscind_begin + 3) / 4
  492. rep movsd
  493. ENDM
  494. ;;Macro to compute relative offset between a base and target
  495. XOFS MACRO target
  496. mov edi, funcAddr
  497. add edi, offset pix_sscind_&target - offset pix_sscind_begin
  498. ENDM
  499. DITHER = 0
  500. RGBMODE = 0
  501. ;=================
  502. INCLUDE span_s.asm
  503. ;=================
  504. ;======================================================================
  505. ; Flat-shaded non-dithered CI spans.
  506. ;======================================================================
  507. PROCNAME MACRO name
  508. __fastCIND&name
  509. ENDM
  510. XNAME MACRO name
  511. pix_fscind_&name
  512. ENDM
  513. COPYPROC MACRO
  514. mov edi, GLCONTEXT
  515. mov edi, [edi].GENCTX_pPrivateArea
  516. add edi, __spanFlatFunc
  517. mov funcAddr, edi
  518. mov esi, offset __fastCINDFlatSpan
  519. mov ecx, (pix_fscind_end - pix_fscind_begin + 3) / 4
  520. rep movsd
  521. ENDM
  522. ;;Macro to compute relative offset between a base and target
  523. XOFS MACRO target
  524. mov edi, funcAddr
  525. add edi, offset pix_fscind_&target - offset pix_fscind_begin
  526. ENDM
  527. DITHER = 0
  528. RGBMODE = 0
  529. ;=================
  530. INCLUDE span_f.asm
  531. ;=================
  532. .data
  533. __FASTFUNCSINTERNAL struct
  534. __funcsPtr dd ?
  535. align 4
  536. __spanZFunc db (zspan_end - zspan_begin + 3) dup (0)
  537. align 4
  538. __spanSmoothFunc db (pix_ssrgb_end - pix_ssrgb_begin + 3) dup (0)
  539. align 4
  540. __spanFlatFunc db (pix_fsrgb_end - pix_fsrgb_begin + 3) dup (0)
  541. align 4
  542. __pad dd ?
  543. __FASTFUNCSINTERNAL ENDS
  544. END