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.

590 lines
11 KiB

  1. ;----------------------------------------------------------------------
  2. ; Module name: span_f.asm
  3. ;
  4. ; Created: 2/3/94
  5. ; Author: Otto Berkes [ottob]
  6. ;
  7. ; Draw fast flat-shaded, z-buffered scanlines.
  8. ;----------------------------------------------------------------------
  9. .code
  10. ;----------------------------------------------------------------------
  11. ; __fastxxxFlatSpan
  12. ;
  13. ; Draw a flat-shaded span.
  14. ;----------------------------------------------------------------------
  15. XNAME <begin::>
  16. PROCNAME <FlatSpan PROC uses ebx edx esi edi, GLCONTEXT: ptr>
  17. LOCAL xlatAddr: dword
  18. LOCAL rAccum: dword
  19. LOCAL gAccum: dword
  20. LOCAL bAccum: dword
  21. LOCAL aAccum: dword
  22. LOCAL zAccum: dword
  23. LOCAL zDelta: dword
  24. LOCAL ditherVals: dword
  25. LOCAL ditherVals2: dword
  26. LOCAL ditherVals3: dword
  27. LOCAL ditherVals4: dword
  28. mov esi, GLCONTEXT
  29. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_r
  30. mov rAccum, eax
  31. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_g
  32. mov gAccum, eax
  33. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_b
  34. mov bAccum, eax
  35. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_a
  36. mov aAccum, eax
  37. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_z
  38. mov zAccum, eax
  39. mov ebx, [esi].GENCTX_pPrivateArea
  40. mov ebx, [ebx]
  41. mov eax, [ebx].SPANREC_z
  42. mov zDelta, eax
  43. mov edi, [esi].GENCTX_ColorsBits
  44. mov edx, [esi].CTX_polygon.POLY_shader.SHADE_cfb
  45. test dword ptr [edx].BUF_other, DIB_FORMAT
  46. je @no_dib
  47. mov edi, [edx].BUF_base
  48. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_y
  49. sub eax, [esi].CTX_constants.CTXCONST_viewportYAdjust
  50. add eax, [edx].BUF_yOrigin
  51. mov ebx, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_x
  52. sub ebx, [esi].CTX_constants.CTXCONST_viewportXAdjust
  53. add ebx, [edx].BUF_xOrigin
  54. mul dword ptr [edx].BUF_outerWidth
  55. XNAME <bpp::>
  56. shl ebx, 2
  57. add eax, ebx
  58. add edi, eax
  59. @no_dib:
  60. mov eax, [esi].GENCTX_pajTranslateVector
  61. if RGBMODE eq 0
  62. XNAME <cixlat_ofs::>
  63. add eax, GLintSize ; for color-index modes, the first
  64. endif ; entry is the # of entries!
  65. mov xlatAddr, eax
  66. ; calculate dither values for span
  67. if DITHER
  68. mov edx, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_y
  69. and edx, 03h
  70. shl edx, 2
  71. mov edx, Dither_4x4[edx]
  72. mov ecx, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_x
  73. and ecx, 03h
  74. shl ecx, 3
  75. ror edx, cl ;edx has x-aligned dither entries for span
  76. endif
  77. if RGBMODE ;>>>>>>>>>>>>>>>> RGBMODE RGB case
  78. ;; Pre-calculate 4 dither values along scanline since the color is constant
  79. mov ecx, [esi].CTX_polygon.POLY_shader.SHADE_spanLength
  80. lea esi, ditherVals
  81. cmp ecx, 0
  82. jle @fastSpanDone
  83. if DITHER ;>>>>>>>>>>>>>>>> RGB dither case
  84. cmp ecx, 4
  85. jle @genDitherLoop
  86. mov ecx, 4
  87. @genDitherLoop:
  88. ;; Blue component
  89. mov eax, bAccum
  90. shr eax, 8
  91. add al, dl
  92. adc ah, 0
  93. ifdef CLAMPCOLOR
  94. XNAME <bmax::>
  95. mov al, 011111b
  96. cmp al, ah
  97. sbb ah, 0
  98. endif
  99. mov al, ah
  100. xor ah, ah
  101. XNAME <bshift::>
  102. shl eax, 11
  103. mov ebx, eax
  104. ;; Green component
  105. mov eax, gAccum
  106. shr eax, 8
  107. add al, dl
  108. adc ah, 0
  109. ifdef CLAMPCOLOR
  110. XNAME <gmax::>
  111. mov al, 0111111b
  112. cmp al, ah
  113. sbb ah, 0
  114. endif
  115. mov al, ah
  116. xor ah, ah
  117. XNAME <gshift::>
  118. shl eax, 5
  119. or ebx, eax
  120. ;; Red component
  121. mov eax, rAccum
  122. shr eax, 8
  123. add al, dl
  124. adc ah, 0
  125. ifdef CLAMPCOLOR
  126. XNAME <rmax::>
  127. mov al, 011111b
  128. cmp al, ah
  129. sbb ah, 0
  130. endif
  131. mov al, ah
  132. xor ah, ah
  133. XNAME <rshift::>
  134. shl eax, 0
  135. or ebx, eax
  136. xchg ebx, eax
  137. mov ebx, xlatAddr ;translate to physical color
  138. XNAME <xlat::>
  139. xlatb
  140. XNAME <write_dither1::> ;write result into dither buffer
  141. mov [esi], ax
  142. XNAME <write_dither2::>
  143. add esi, 2
  144. ror edx, 8 ;advance dither to next x-address
  145. dec ecx
  146. jg @genDitherLoop
  147. else ;>>>>>>>>>>>>>>>> RGB no-dither case
  148. mov eax, bAccum
  149. shr eax, 16
  150. XNAME <bshift::>
  151. shl eax, 11
  152. mov edx, eax
  153. mov eax, gAccum
  154. shr eax, 16
  155. XNAME <gshift::>
  156. shl eax, 5
  157. or edx, eax
  158. mov eax, rAccum
  159. shr eax, 16
  160. XNAME <rshift::>
  161. shl eax, 0
  162. or edx, eax
  163. mov eax, edx
  164. mov ebx, xlatAddr ;translate to physical color
  165. XNAME <xlat::>
  166. xlatb
  167. mov dl, al
  168. endif ;<<<<<<<<<<<<<<<< end RGB DITHER cases
  169. else ;>>>>>>>>>>>>>>>> RGBMODE color-index case
  170. mov ecx, [esi].CTX_polygon.POLY_shader.SHADE_spanLength
  171. lea esi, ditherVals
  172. cmp ecx, 0
  173. jle @fastSpanDone
  174. if DITHER ;>>>>>>>>>>>>>>>> dithered color-index case
  175. cmp ecx, 4
  176. jle @genDitherLoop
  177. mov ecx, 4
  178. @genDitherLoop:
  179. mov eax, rAccum
  180. shr eax, 8
  181. add al, dl
  182. adc ah, 0
  183. mov al, ah
  184. xor ah, ah
  185. XNAME <cixlat_shift::>
  186. shl eax, 2 ; 4 or 1 byte/entry
  187. add eax, xlatAddr
  188. mov eax, [eax]
  189. XNAME <write_dither1::> ;write result into dither buffer
  190. mov [esi], ax
  191. XNAME <write_dither2::>
  192. add esi, 2
  193. ror edx, 8
  194. dec ecx
  195. jg @genDitherLoop
  196. else ;>>>>>>>>>>>>>>>> solid color-index case
  197. mov eax, rAccum
  198. shr eax, 16
  199. XNAME <cixlat_shift::>
  200. shl eax, 2 ; 4 or 1 byte/entry
  201. add eax, xlatAddr
  202. mov eax, [eax]
  203. mov edx, eax ; we store pre-computed value in edx
  204. endif ;<<<<<<<<<<<<<<<< end color-index DITHER cases
  205. endif ;<<<<<<<<<<<<<<<< end RGBMODE cases
  206. ;; load up interpolation/count registers
  207. mov esi, GLCONTEXT
  208. mov ecx, [esi].CTX_polygon.POLY_shader.SHADE_spanLength
  209. mov eax, zAccum
  210. mov esi, [esi].CTX_polygon.POLY_shader.SHADE_zbuf
  211. if DITHER
  212. xor ebx, ebx
  213. endif
  214. ;; start of z-buffer/color-interpolation loop
  215. ;;ztest-pass case
  216. align 4
  217. @ztest_pass:
  218. XNAME <ztest_begin::>
  219. cmp eax, [esi]
  220. XNAME <ztest_pass::>
  221. jae near ptr @ztest_fail_cont
  222. @ztest_pass_cont:
  223. XNAME <zwrite::>
  224. mov [esi],eax
  225. add eax, zDelta
  226. add esi, __GLzValueSize
  227. XNAME <ztest_end::>
  228. if DITHER
  229. XNAME <and_dither::>
  230. and ebx, 7h
  231. lea edx, ditherVals
  232. XNAME <get_dither::>
  233. mov dx, [edx + ebx]
  234. endif
  235. XNAME <write_pix::>
  236. mov [edi], dx
  237. XNAME <dest_inc1::>
  238. if DITHER
  239. add ebx, 2
  240. endif
  241. add edi, 2
  242. dec ecx
  243. XNAME <ztest_jmp::>
  244. jg near ptr @ztest_pass
  245. jmp short @fastSpanDone
  246. ;;ztest-fail case
  247. ;; not much to do here except advance adresses, dither
  248. align 4
  249. @ztest_fail:
  250. cmp eax, [esi]
  251. XNAME <ztest_fail::>
  252. jb near ptr @ztest_pass_cont
  253. @ztest_fail_cont:
  254. add eax, zDelta
  255. add esi, __GLzValueSize
  256. XNAME <dest_inc2::>
  257. if DITHER
  258. add ebx, 2
  259. endif
  260. add edi, 2
  261. dec ecx
  262. jg short @ztest_fail
  263. @fastSpanDone:
  264. ret
  265. PROCNAME <FlatSpan ENDP>
  266. XNAME <end::>
  267. ;----------------------------------------------------------------------
  268. ; __fastxxxFlatSpanSetup(GLCONTEXT *)
  269. ;
  270. ; Copy the span routine from the template and modify it to reflect
  271. ; the current state.
  272. ;----------------------------------------------------------------------
  273. PROCNAME <FlatSpanSetup PROC uses ebx edx esi edi, GLCONTEXT: ptr>
  274. LOCAL funcAddr: dword
  275. COPYPROC
  276. mov esi, GLCONTEXT
  277. mov edx, [esi].CTX_drawBuffer
  278. ; ecx = bytes/pixel
  279. xor ecx, ecx
  280. mov cl, [esi].GENCTX_CurrentFormat.PFD_cColorBits
  281. add cl, 7
  282. shr cl, 3
  283. ; ebx is index for byte-per-pixel modifications
  284. mov ebx, ecx
  285. and ebx, 0eh
  286. shl ebx, 1
  287. ;; bytes/pixel adjustment (shifts)
  288. mov al, [esi].GENCTX_CurrentFormat.PFD_cColorBits
  289. add al, 7
  290. shr al, 4
  291. XOFS bpp
  292. mov [edi]+2, al
  293. if RGBMODE ;>>>>>>>>>>>>>>>> RGB case
  294. ;; blue max and shift
  295. ifdef CLAMPCOLOR
  296. if DITHER
  297. mov al, [edx].CBUF_blueMax
  298. XOFS bmax
  299. mov [edi]+1, al
  300. endif
  301. endif
  302. mov al, [edx].CBUF_iBlueShift
  303. XOFS bshift
  304. mov [edi]+2, al
  305. ;; green max and shift
  306. ifdef CLAMPCOLOR
  307. if DITHER
  308. mov al, [edx].CBUF_greenMax
  309. XOFS gmax
  310. mov [edi]+1, al
  311. endif
  312. endif
  313. mov al, [edx].CBUF_iGreenShift
  314. XOFS gshift
  315. mov [edi]+2, al
  316. ;; red max and shift
  317. ifdef CLAMPCOLOR
  318. if DITHER
  319. mov al, [edx].CBUF_redMax
  320. XOFS rmax
  321. mov [edi]+1, al
  322. endif
  323. endif
  324. mov al, [edx].CBUF_iRedShift
  325. XOFS rshift
  326. mov [edi]+2, al
  327. ;; paletted-device color-translation
  328. cmp byte ptr [esi].GENCTX_CurrentFormat.PFD_cColorBits, 8
  329. je @doTranslate
  330. XOFS xlat
  331. mov byte ptr [edi], NOP_CODE
  332. @doTranslate:
  333. else ;>>>>>>>>>>>>>>>> color-index case
  334. ; no offset or address-shift needed
  335. cmp byte ptr [esi].GENCTX_CurrentFormat.PFD_cColorBits, 8
  336. jg @longXlat ; for 8-bit CI mode
  337. XOFS cixlat_ofs
  338. mov byte ptr [edi]+2, 0
  339. XOFS cixlat_shift
  340. mov byte ptr [edi]+2, 0
  341. @longXlat:
  342. endif ;>>>>>>>>>>>>>>>> end RGB cases
  343. if DITHER
  344. ;; dither-write
  345. mov ax, word ptr write_dither_ops[ebx]
  346. XOFS write_dither1
  347. mov [edi], ax
  348. mov al, byte ptr write_dither_ops[ebx+2]
  349. mov [edi]+2, al
  350. ; account for pixel size
  351. XOFS write_dither2
  352. mov [edi]+2, cl
  353. endif
  354. ;; pixel-write
  355. mov ax, word ptr write_fpix_ops[ebx]
  356. XOFS write_pix
  357. mov [edi], ax
  358. mov al, byte ptr write_fpix_ops[ebx+2]
  359. mov [edi]+2, al
  360. if DITHER
  361. ;; dither-value fetch
  362. mov eax, dword ptr read_dither_ops[ebx]
  363. XOFS get_dither
  364. mov [edi], eax
  365. endif
  366. ;; z-test conditions
  367. mov eax, [esi].CTX_state.ATTR_depth.DEPTH_testFunc
  368. and eax, 3
  369. mov ebx, eax
  370. shl ebx, 2
  371. shl eax, 1
  372. add ebx, eax ; 6 bytes/jump
  373. ;; z-test pass condition
  374. mov ax, word ptr ztest_pass_functions[ebx]
  375. XOFS ztest_pass
  376. mov [edi], ax
  377. ;; z-test fail condition
  378. mov ax, word ptr ztest_fail_functions[ebx]
  379. XOFS ztest_fail
  380. mov [edi], ax
  381. ;; z write-enable
  382. test dword ptr [esi].CTX_state.ATTR_depth.DEPTH_writeEnable, 1
  383. jne @zwriteEnabled
  384. XOFS zwrite
  385. mov byte ptr [edi], NOP_CODE
  386. mov byte ptr [edi]+1, NOP_CODE
  387. @zwriteEnabled:
  388. ;; destination-offset increment
  389. XOFS dest_inc1
  390. mov [edi]+2, cl
  391. if DITHER
  392. mov [edi]+5, cl
  393. endif
  394. XOFS dest_inc2
  395. mov [edi]+2, cl
  396. if DITHER
  397. mov [edi]+5, cl
  398. shl cl, 2 ; 4 dither entries used
  399. dec cl
  400. XOFS and_dither
  401. mov [edi]+2, cl
  402. endif
  403. ;; z-buffer enable
  404. test dword ptr [esi].CTX_polygon.POLY_shader.SHADE_modeFlags,__GL_SHADE_DEPTH_TEST
  405. jne @depthTestEnabled
  406. XOFS ztest_end
  407. mov eax, edi
  408. XOFS ztest_begin
  409. sub eax, edi
  410. mov ebx, eax
  411. ;if z-buffer is not enabled so jump around initial z test...
  412. XOFS ztest_begin
  413. mov [edi], JMP_CODE
  414. sub bl, 2 ;account for instruction encoding
  415. add [edi]+1, bl
  416. ;and continue to loop "under" z test
  417. XOFS ztest_jmp
  418. add [edi]+2, eax
  419. @depthTestEnabled:
  420. ret
  421. ;; Enumerate the needed read/write operations for the various pixel
  422. ;; sizes. The byte and dword versions have an extra NOP since the
  423. ;; 16-bit operation takes 3 bytes due to the 066h prefix. Alternatively,
  424. ;; we could get around this by fixing up the addresses. The other NOP
  425. ;; pads is not embedded in code; it simply keeps things dword-aligned
  426. align 4
  427. write_fpix_ops:
  428. write_fpix_byte:
  429. mov [edi], dl
  430. nop
  431. nop
  432. write_fpix_word:
  433. mov [edi], dx
  434. nop
  435. write_fpix_dword:
  436. mov [edi], edx
  437. nop
  438. nop
  439. align 4
  440. write_dither_ops:
  441. write_dither_byte:
  442. mov [esi], al
  443. nop
  444. nop
  445. write_dither_word:
  446. mov [esi], ax
  447. nop
  448. write_dither_dword:
  449. mov [esi], eax
  450. nop
  451. nop
  452. align 4
  453. read_dither_ops:
  454. read_dither_byte:
  455. mov dl, [edx+ebx]
  456. nop
  457. read_dither_word:
  458. mov dx, [edx+ebx]
  459. read_dither_dword:
  460. mov edx, [edx+ebx]
  461. nop
  462. PROCNAME <FlatSpanSetup ENDP>