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.

496 lines
9.3 KiB

  1. ;----------------------------------------------------------------------
  2. ; Module name: span_s.asm
  3. ;
  4. ; Created: 2/3/94
  5. ; Author: Otto Berkes [ottob]
  6. ;
  7. ; Draw fast smooth-shaded, z-buffered scanlines.
  8. ;----------------------------------------------------------------------
  9. .code
  10. ;----------------------------------------------------------------------
  11. ; __fastxxxSmoothSpan
  12. ;
  13. ; Draw a smooth-shaded span.
  14. ;----------------------------------------------------------------------
  15. XNAME <begin::>
  16. PROCNAME <SmoothSpan 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 rDelta: dword
  24. LOCAL gDelta: dword
  25. LOCAL bDelta: dword
  26. LOCAL aDelta: dword
  27. LOCAL zDelta: dword
  28. ; all this copying is needed for multi-threaded operation. We could
  29. ; optimize for color-index...
  30. mov esi, GLCONTEXT
  31. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_r
  32. mov rAccum, eax
  33. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_g
  34. mov gAccum, eax
  35. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_b
  36. mov bAccum, eax
  37. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_color.COLOR_a
  38. mov aAccum, eax
  39. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_z
  40. mov zAccum, eax
  41. mov ebx, [esi].GENCTX_pPrivateArea
  42. mov ebx, [ebx]
  43. mov eax, [ebx].SPANREC_r
  44. mov rDelta, eax
  45. mov eax, [ebx].SPANREC_g
  46. mov gDelta, eax
  47. mov eax, [ebx].SPANREC_b
  48. mov bDelta, eax
  49. mov eax, [ebx].SPANREC_a
  50. mov aDelta, eax
  51. mov eax, [ebx].SPANREC_z
  52. mov zDelta, eax
  53. mov edi, [esi].GENCTX_ColorsBits
  54. mov edx, [esi].CTX_polygon.POLY_shader.SHADE_cfb
  55. test dword ptr [edx].BUF_other, DIB_FORMAT
  56. je @no_dib
  57. mov edi, [edx].BUF_base
  58. mov eax, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_y
  59. sub eax, [esi].CTX_constants.CTXCONST_viewportYAdjust
  60. add eax, [edx].BUF_yOrigin
  61. mov ebx, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_x
  62. sub ebx, [esi].CTX_constants.CTXCONST_viewportXAdjust
  63. add ebx, [edx].BUF_xOrigin
  64. mul dword ptr [edx].BUF_outerWidth
  65. XNAME <bpp::>
  66. shl ebx, 2
  67. add eax, ebx
  68. add edi, eax
  69. @no_dib:
  70. mov eax, [esi].GENCTX_pajTranslateVector
  71. if RGBMODE eq 0
  72. XNAME <cixlat_ofs::>
  73. add eax, GLintSize ; for color-index modes, the first
  74. endif ; entry is the # of entries!
  75. mov xlatAddr, eax
  76. ; calculate dither values for span
  77. if DITHER
  78. mov edx, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_y
  79. and edx, 03h
  80. shl edx, 2
  81. mov edx, Dither_4x4[edx]
  82. mov ecx, [esi].CTX_polygon.POLY_shader.SHADE_frag.FRAG_x
  83. and ecx, 03h
  84. shl ecx, 3
  85. ror edx, cl ;edx has x-aligned dither entries for span
  86. endif
  87. mov ecx, [esi].CTX_polygon.POLY_shader.SHADE_spanLength
  88. cmp ecx, 0
  89. jle @fastSpanDone
  90. ;esi now points to z-buffer
  91. mov esi, [esi].CTX_polygon.POLY_shader.SHADE_zbuf
  92. if DITHER eq 0
  93. mov edx, zAccum
  94. endif
  95. if RGBMODE eq 0
  96. mov ebx, rAccum
  97. endif
  98. ;; start of z-buffer/color-interpolation loop
  99. ;;ztest-pass case
  100. align 4
  101. @ztest_pass:
  102. XNAME <ztest_begin::>
  103. if DITHER
  104. mov eax, zAccum ; perform z test
  105. cmp eax, [esi]
  106. else
  107. cmp edx, [esi]
  108. endif
  109. XNAME <ztest_pass::> ; check condition
  110. jae near ptr @ztest_fail_cont
  111. @ztest_pass_cont: ; test passed->write the z value
  112. XNAME <zwrite::>
  113. mov [esi],eax
  114. if DITHER ; increment z interpolation
  115. add eax, zDelta ; and address
  116. mov zAccum, eax
  117. else
  118. add edx, zDelta
  119. endif
  120. add esi, __GLzValueSize
  121. XNAME <ztest_end::>
  122. if RGBMODE ;>>>>>>>>>>>>>>>> RGBMODE RGB case
  123. ;; Red component (r bits) ; calculate color value for RGB
  124. mov eax, rAccum
  125. if DITHER
  126. shr eax, 8
  127. add al, dl
  128. adc ah, 0
  129. ifdef CLAMPCOLOR
  130. XNAME <rmax::>
  131. mov al, 011111b
  132. cmp al, ah
  133. sbb ah, 0
  134. endif
  135. mov al, ah
  136. xor ah, ah
  137. else
  138. shr eax, 16
  139. endif
  140. XNAME <rshift::>
  141. shl eax, 0
  142. mov ebx, eax
  143. ;; Green component (g bits)
  144. mov eax, gAccum
  145. if DITHER
  146. shr eax, 8
  147. add al, dl
  148. adc ah, 0
  149. ifdef CLAMPCOLOR
  150. XNAME <gmax::>
  151. mov al, 0111111b
  152. cmp al, ah
  153. sbb ah, 0
  154. endif
  155. mov al, ah
  156. xor ah, ah
  157. else
  158. shr eax, 16
  159. endif
  160. XNAME <gshift::>
  161. shl eax, 5
  162. or ebx, eax
  163. ;; Blue component (b bits)
  164. mov eax, bAccum
  165. if DITHER
  166. shr eax, 8
  167. add al, dl
  168. adc ah, 0
  169. ifdef CLAMPCOLOR
  170. XNAME <bmax::>
  171. mov al, 011111b
  172. cmp al, ah
  173. sbb ah, 0
  174. endif
  175. mov al, ah
  176. xor ah, ah
  177. else
  178. shr eax, 16
  179. endif
  180. XNAME <bshift::>
  181. shl eax, 11
  182. or ebx, eax
  183. xchg ebx, eax
  184. mov ebx, xlatAddr ;translate to physical color
  185. XNAME <xlat::>
  186. xlatb
  187. else ;>>>>>>>>>>>>>>>> RGBMODE color-index case
  188. ;; Red component (r bits) ; calculate color value for indexed
  189. ; mode
  190. mov eax, ebx
  191. if DITHER
  192. shr eax, 8
  193. add al, dl
  194. adc ah, 0
  195. mov al, ah
  196. xor ah, ah
  197. else
  198. shr eax, 16
  199. endif
  200. XNAME <cixlat_shift::>
  201. shl eax, 2 ; 4 or 1 bytes/entry
  202. add eax, xlatAddr
  203. mov eax, [eax]
  204. endif ;<<<<<<<<<<<<<<<< end RGBMODE cases
  205. XNAME <write_pix::> ; write the color value
  206. mov [edi], ax
  207. XNAME <dest_inc1::>
  208. add edi, 2
  209. if DITHER ; increment color values, dither
  210. ror edx, 8
  211. endif
  212. if RGBMODE
  213. mov ebx, rDelta
  214. add rAccum, ebx
  215. mov ebx, gDelta
  216. add gAccum, ebx
  217. mov ebx, bDelta
  218. add bAccum, ebx
  219. else
  220. add ebx, rDelta
  221. endif
  222. dec ecx
  223. XNAME <ztest_jmp::>
  224. jg near ptr @ztest_pass
  225. jmp short @fastSpanDone
  226. ;;ztest-fail case
  227. ;; not much to do here except advance interpolation values
  228. align 4
  229. @ztest_fail:
  230. if DITHER
  231. cmp eax, [esi] ; perform z test
  232. else
  233. cmp edx, [esi]
  234. endif
  235. XNAME <ztest_fail::>
  236. jb near ptr @ztest_pass_cont ; check condition
  237. @ztest_fail_cont:
  238. if DITHER
  239. add eax, zDelta ; increment z interpolator
  240. else
  241. add edx, zDelta
  242. endif
  243. add esi, __GLzValueSize
  244. if RGBMODE
  245. mov ebx, rDelta ; increment color interpolators
  246. add rAccum, ebx
  247. mov ebx, gDelta
  248. add gAccum, ebx
  249. mov ebx, bDelta
  250. add bAccum, ebx
  251. else
  252. add ebx, rDelta
  253. endif
  254. XNAME <dest_inc2::>
  255. add edi, 2
  256. if DITHER
  257. ror edx, 8
  258. endif
  259. dec ecx
  260. jg short @ztest_fail
  261. @fastSpanDone:
  262. ret
  263. PROCNAME <SmoothSpan ENDP>
  264. XNAME <end::>
  265. ;----------------------------------------------------------------------
  266. ; __fastxxxSmoothSpanSetup(GLCONTEXT *)
  267. ;
  268. ; Copy the span routine from the template and modify it to reflect
  269. ; the current state.
  270. ;----------------------------------------------------------------------
  271. PROCNAME <SmoothSpanSetup PROC uses ebx edx esi edi, GLCONTEXT: ptr>
  272. LOCAL funcAddr: dword
  273. COPYPROC
  274. mov esi, GLCONTEXT
  275. mov edx, [esi].CTX_drawBuffer
  276. ;; bytes/pixel adjustment (shifts)
  277. mov al, [esi].GENCTX_CurrentFormat.PFD_cColorBits
  278. add al, 7
  279. shr al, 4
  280. XOFS bpp
  281. mov [edi]+2, al
  282. ;; z-test conditions
  283. mov eax, [esi].CTX_state.ATTR_depth.DEPTH_testFunc
  284. and eax, 3
  285. mov ebx, eax
  286. shl ebx, 2
  287. shl eax, 1
  288. add ebx, eax ; 6 bytes/jump
  289. ;; z-test pass condition
  290. mov ax, word ptr ztest_pass_functions[ebx]
  291. XOFS ztest_pass
  292. mov [edi], ax
  293. ;; z-test fail condition
  294. mov ax, word ptr ztest_fail_functions[ebx]
  295. XOFS ztest_fail
  296. mov [edi], ax
  297. ;; z write-enable
  298. test dword ptr [esi].CTX_state.ATTR_depth.DEPTH_writeEnable, 1
  299. jne @zwriteEnabled
  300. XOFS zwrite
  301. mov byte ptr [edi], NOP_CODE
  302. mov byte ptr [edi]+1, NOP_CODE
  303. @zwriteEnabled:
  304. if RGBMODE
  305. ;; blue max and shift
  306. ifdef CLAMPCOLOR
  307. if DITHER
  308. mov al, [edx].CBUF_blueMax
  309. XOFS bmax
  310. mov [edi]+1, al
  311. endif
  312. endif
  313. mov al, [edx].CBUF_iBlueShift
  314. XOFS bshift
  315. mov [edi]+2, al
  316. ;; green max and shift
  317. ifdef CLAMPCOLOR
  318. if DITHER
  319. mov al, [edx].CBUF_greenMax
  320. XOFS gmax
  321. mov [edi]+1, al
  322. endif
  323. endif
  324. mov al, [edx].CBUF_iGreenShift
  325. XOFS gshift
  326. mov [edi]+2, al
  327. ;; red max and shift
  328. ifdef CLAMPCOLOR
  329. if DITHER
  330. mov al, [edx].CBUF_redMax
  331. XOFS rmax
  332. mov [edi]+1, al
  333. endif
  334. endif
  335. mov al, [edx].CBUF_iRedShift
  336. XOFS rshift
  337. mov [edi]+2, al
  338. ;; color-translation
  339. cmp byte ptr [esi].GENCTX_CurrentFormat.PFD_cColorBits, 8
  340. je @doTranslate
  341. XOFS xlat
  342. mov byte ptr [edi], NOP_CODE
  343. @doTranslate:
  344. else ;>>>>>>>>>>>>>>>> color-index case
  345. ; no offset or address-shift needed for 8-bit color
  346. cmp byte ptr [esi].GENCTX_CurrentFormat.PFD_cColorBits, 8
  347. jg @longXlat ; for 8-bit CI mode
  348. XOFS cixlat_ofs
  349. mov byte ptr [edi]+2, 0
  350. XOFS cixlat_shift
  351. mov byte ptr [edi]+2, 0
  352. @longXlat:
  353. endif ;>>>>>>>>>>>>>>>> end RGB cases
  354. ;; pixel-write
  355. xor ebx, ebx
  356. mov bl, [esi].GENCTX_CurrentFormat.PFD_cColorBits
  357. add bl, 7
  358. shr bl, 3
  359. mov ecx, ebx
  360. and ebx, 0eh
  361. shl ebx, 1
  362. mov ax, word ptr write_pixel_ops[ebx]
  363. XOFS write_pix
  364. mov [edi], ax
  365. mov al, byte ptr write_pixel_ops[ebx+2]
  366. mov [edi]+2, al
  367. ;; destination-offset increment
  368. XOFS dest_inc1
  369. mov [edi]+2, cl
  370. XOFS dest_inc2
  371. mov [edi]+2, cl
  372. ;; z-buffer enable
  373. test dword ptr [esi].CTX_polygon.POLY_shader.SHADE_modeFlags,__GL_SHADE_DEPTH_TEST
  374. jne @depthTestEnabled
  375. XOFS ztest_end
  376. mov eax, edi
  377. XOFS ztest_begin
  378. sub eax, edi
  379. mov ebx, eax
  380. ;if z-buffer is not enabled so jump around initial z test...
  381. XOFS ztest_begin
  382. mov [edi], JMP_CODE
  383. sub bl, 2 ;account for instruction encoding
  384. add [edi]+1, bl
  385. ;and continue to loop "under" z test
  386. XOFS ztest_jmp
  387. add [edi]+2, eax
  388. @depthTestEnabled:
  389. ret
  390. align 4
  391. write_pixel_ops:
  392. write_pix_byte:
  393. mov [edi], al
  394. nop
  395. nop
  396. write_pix_word:
  397. mov [edi], ax
  398. nop
  399. write_pix_dword:
  400. mov [edi], eax
  401. nop
  402. nop
  403. PROCNAME <SmoothSpanSetup ENDP>