Clone of mesa.
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.

intel_tris.c 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. /**************************************************************************
  2. *
  3. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. /** @file intel_tris.c
  28. *
  29. * This file contains functions for managing the vertex buffer and emitting
  30. * primitives into it.
  31. */
  32. #include "main/glheader.h"
  33. #include "main/context.h"
  34. #include "main/macros.h"
  35. #include "main/enums.h"
  36. #include "main/texobj.h"
  37. #include "main/state.h"
  38. #include "main/dd.h"
  39. #include "main/fbobject.h"
  40. #include "swrast/swrast.h"
  41. #include "swrast_setup/swrast_setup.h"
  42. #include "tnl/t_context.h"
  43. #include "tnl/t_pipeline.h"
  44. #include "tnl/t_vertex.h"
  45. #include "intel_screen.h"
  46. #include "intel_context.h"
  47. #include "intel_tris.h"
  48. #include "intel_batchbuffer.h"
  49. #include "intel_buffers.h"
  50. #include "intel_reg.h"
  51. #include "intel_span.h"
  52. #include "i830_context.h"
  53. #include "i830_reg.h"
  54. #include "i915_context.h"
  55. static void intelRenderPrimitive(struct gl_context * ctx, GLenum prim);
  56. static void intelRasterPrimitive(struct gl_context * ctx, GLenum rprim,
  57. GLuint hwprim);
  58. static void
  59. intel_flush_inline_primitive(struct intel_context *intel)
  60. {
  61. GLuint used = intel->batch.used - intel->prim.start_ptr;
  62. assert(intel->prim.primitive != ~0);
  63. /* printf("/\n"); */
  64. if (used < 2)
  65. goto do_discard;
  66. intel->batch.map[intel->prim.start_ptr] =
  67. _3DPRIMITIVE | intel->prim.primitive | (used - 2);
  68. goto finished;
  69. do_discard:
  70. intel->batch.used = intel->prim.start_ptr;
  71. finished:
  72. intel->prim.primitive = ~0;
  73. intel->prim.start_ptr = 0;
  74. intel->prim.flush = 0;
  75. }
  76. static void intel_start_inline(struct intel_context *intel, uint32_t prim)
  77. {
  78. BATCH_LOCALS;
  79. intel->vtbl.emit_state(intel);
  80. intel->no_batch_wrap = true;
  81. /*printf("%s *", __progname);*/
  82. /* Emit a slot which will be filled with the inline primitive
  83. * command later.
  84. */
  85. BEGIN_BATCH(1);
  86. intel->prim.start_ptr = intel->batch.used;
  87. intel->prim.primitive = prim;
  88. intel->prim.flush = intel_flush_inline_primitive;
  89. OUT_BATCH(0);
  90. ADVANCE_BATCH();
  91. intel->no_batch_wrap = false;
  92. /* printf(">"); */
  93. }
  94. static void intel_wrap_inline(struct intel_context *intel)
  95. {
  96. GLuint prim = intel->prim.primitive;
  97. intel_flush_inline_primitive(intel);
  98. intel_batchbuffer_flush(intel);
  99. intel_start_inline(intel, prim); /* ??? */
  100. }
  101. static GLuint *intel_extend_inline(struct intel_context *intel, GLuint dwords)
  102. {
  103. GLuint *ptr;
  104. assert(intel->prim.flush == intel_flush_inline_primitive);
  105. if (intel_batchbuffer_space(intel) < dwords * sizeof(GLuint))
  106. intel_wrap_inline(intel);
  107. /* printf("."); */
  108. intel->vtbl.assert_not_dirty(intel);
  109. ptr = intel->batch.map + intel->batch.used;
  110. intel->batch.used += dwords;
  111. return ptr;
  112. }
  113. /** Sets the primitive type for a primitive sequence, flushing as needed. */
  114. void intel_set_prim(struct intel_context *intel, uint32_t prim)
  115. {
  116. /* if we have no VBOs */
  117. if (intel->intelScreen->no_vbo) {
  118. intel_start_inline(intel, prim);
  119. return;
  120. }
  121. if (prim != intel->prim.primitive) {
  122. INTEL_FIREVERTICES(intel);
  123. intel->prim.primitive = prim;
  124. }
  125. }
  126. /** Returns mapped VB space for the given number of vertices */
  127. uint32_t *intel_get_prim_space(struct intel_context *intel, unsigned int count)
  128. {
  129. uint32_t *addr;
  130. if (intel->intelScreen->no_vbo) {
  131. return intel_extend_inline(intel, count * intel->vertex_size);
  132. }
  133. /* Check for space in the existing VB */
  134. if (intel->prim.vb_bo == NULL ||
  135. (intel->prim.current_offset +
  136. count * intel->vertex_size * 4) > INTEL_VB_SIZE ||
  137. (intel->prim.count + count) >= (1 << 16)) {
  138. /* Flush existing prim if any */
  139. INTEL_FIREVERTICES(intel);
  140. intel_finish_vb(intel);
  141. /* Start a new VB */
  142. if (intel->prim.vb == NULL)
  143. intel->prim.vb = malloc(INTEL_VB_SIZE);
  144. intel->prim.vb_bo = drm_intel_bo_alloc(intel->bufmgr, "vb",
  145. INTEL_VB_SIZE, 4);
  146. intel->prim.start_offset = 0;
  147. intel->prim.current_offset = 0;
  148. }
  149. intel->prim.flush = intel_flush_prim;
  150. addr = (uint32_t *)(intel->prim.vb + intel->prim.current_offset);
  151. intel->prim.current_offset += intel->vertex_size * 4 * count;
  152. intel->prim.count += count;
  153. return addr;
  154. }
  155. /** Dispatches the accumulated primitive to the batchbuffer. */
  156. void intel_flush_prim(struct intel_context *intel)
  157. {
  158. drm_intel_bo *aper_array[2];
  159. drm_intel_bo *vb_bo;
  160. unsigned int offset, count;
  161. BATCH_LOCALS;
  162. /* Must be called after an intel_start_prim. */
  163. assert(intel->prim.primitive != ~0);
  164. if (intel->prim.count == 0)
  165. return;
  166. /* Clear the current prims out of the context state so that a batch flush
  167. * flush triggered by emit_state doesn't loop back to flush_prim again.
  168. */
  169. vb_bo = intel->prim.vb_bo;
  170. drm_intel_bo_reference(vb_bo);
  171. count = intel->prim.count;
  172. intel->prim.count = 0;
  173. offset = intel->prim.start_offset;
  174. intel->prim.start_offset = intel->prim.current_offset;
  175. if (intel->gen < 3)
  176. intel->prim.current_offset = intel->prim.start_offset = ALIGN(intel->prim.start_offset, 128);
  177. intel->prim.flush = NULL;
  178. intel->vtbl.emit_state(intel);
  179. aper_array[0] = intel->batch.bo;
  180. aper_array[1] = vb_bo;
  181. if (dri_bufmgr_check_aperture_space(aper_array, 2)) {
  182. intel_batchbuffer_flush(intel);
  183. intel->vtbl.emit_state(intel);
  184. }
  185. /* Ensure that we don't start a new batch for the following emit, which
  186. * depends on the state just emitted. emit_state should be making sure we
  187. * have the space for this.
  188. */
  189. intel->no_batch_wrap = true;
  190. if (intel->always_flush_cache) {
  191. intel_batchbuffer_emit_mi_flush(intel);
  192. }
  193. #if 0
  194. printf("emitting %d..%d=%d vertices size %d\n", offset,
  195. intel->prim.current_offset, count,
  196. intel->vertex_size * 4);
  197. #endif
  198. if (intel->gen >= 3) {
  199. struct i915_context *i915 = i915_context(&intel->ctx);
  200. unsigned int cmd = 0, len = 0;
  201. if (vb_bo != i915->current_vb_bo) {
  202. cmd |= I1_LOAD_S(0);
  203. len++;
  204. }
  205. if (intel->vertex_size != i915->current_vertex_size) {
  206. cmd |= I1_LOAD_S(1);
  207. len++;
  208. }
  209. if (len)
  210. len++;
  211. BEGIN_BATCH(2+len);
  212. if (cmd)
  213. OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | cmd | (len - 2));
  214. if (vb_bo != i915->current_vb_bo) {
  215. OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
  216. i915->current_vb_bo = vb_bo;
  217. }
  218. if (intel->vertex_size != i915->current_vertex_size) {
  219. OUT_BATCH((intel->vertex_size << S1_VERTEX_WIDTH_SHIFT) |
  220. (intel->vertex_size << S1_VERTEX_PITCH_SHIFT));
  221. i915->current_vertex_size = intel->vertex_size;
  222. }
  223. OUT_BATCH(_3DPRIMITIVE |
  224. PRIM_INDIRECT |
  225. PRIM_INDIRECT_SEQUENTIAL |
  226. intel->prim.primitive |
  227. count);
  228. OUT_BATCH(offset / (intel->vertex_size * 4));
  229. ADVANCE_BATCH();
  230. } else {
  231. struct i830_context *i830 = i830_context(&intel->ctx);
  232. BEGIN_BATCH(5);
  233. OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
  234. I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
  235. /* S0 */
  236. assert((offset & ~S0_VB_OFFSET_MASK_830) == 0);
  237. OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0,
  238. offset | (intel->vertex_size << S0_VB_PITCH_SHIFT_830) |
  239. S0_VB_ENABLE_830);
  240. /* S2
  241. * This is somewhat unfortunate -- VB width is tied up with
  242. * vertex format data that we've already uploaded through
  243. * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
  244. * STATE_IMMEDIATE_1 like this to avoid duplication.
  245. */
  246. OUT_BATCH((i830->state.Ctx[I830_CTXREG_VF] & VFT0_TEX_COUNT_MASK) >>
  247. VFT0_TEX_COUNT_SHIFT << S2_TEX_COUNT_SHIFT_830 |
  248. (i830->state.Ctx[I830_CTXREG_VF2] << 16) |
  249. intel->vertex_size << S2_VERTEX_0_WIDTH_SHIFT_830);
  250. OUT_BATCH(_3DPRIMITIVE |
  251. PRIM_INDIRECT |
  252. PRIM_INDIRECT_SEQUENTIAL |
  253. intel->prim.primitive |
  254. count);
  255. OUT_BATCH(0); /* Beginning vertex index */
  256. ADVANCE_BATCH();
  257. }
  258. if (intel->always_flush_cache) {
  259. intel_batchbuffer_emit_mi_flush(intel);
  260. }
  261. intel->no_batch_wrap = false;
  262. drm_intel_bo_unreference(vb_bo);
  263. }
  264. /**
  265. * Uploads the locally-accumulated VB into the buffer object.
  266. *
  267. * This avoids us thrashing the cachelines in and out as the buffer gets
  268. * filled, dispatched, then reused as the hardware completes rendering from it,
  269. * and also lets us clflush less if we dispatch with a partially-filled VB.
  270. *
  271. * This is called normally from get_space when we're finishing a BO, but also
  272. * at batch flush time so that we don't try accessing the contents of a
  273. * just-dispatched buffer.
  274. */
  275. void intel_finish_vb(struct intel_context *intel)
  276. {
  277. if (intel->prim.vb_bo == NULL)
  278. return;
  279. drm_intel_bo_subdata(intel->prim.vb_bo, 0, intel->prim.start_offset,
  280. intel->prim.vb);
  281. drm_intel_bo_unreference(intel->prim.vb_bo);
  282. intel->prim.vb_bo = NULL;
  283. }
  284. /***********************************************************************
  285. * Emit primitives as inline vertices *
  286. ***********************************************************************/
  287. #ifdef __i386__
  288. #define COPY_DWORDS( j, vb, vertsize, v ) \
  289. do { \
  290. int __tmp; \
  291. __asm__ __volatile__( "rep ; movsl" \
  292. : "=%c" (j), "=D" (vb), "=S" (__tmp) \
  293. : "0" (vertsize), \
  294. "D" ((long)vb), \
  295. "S" ((long)v) ); \
  296. } while (0)
  297. #else
  298. #define COPY_DWORDS( j, vb, vertsize, v ) \
  299. do { \
  300. for ( j = 0 ; j < vertsize ; j++ ) { \
  301. vb[j] = ((GLuint *)v)[j]; \
  302. } \
  303. vb += vertsize; \
  304. } while (0)
  305. #endif
  306. static void
  307. intel_draw_quad(struct intel_context *intel,
  308. intelVertexPtr v0,
  309. intelVertexPtr v1, intelVertexPtr v2, intelVertexPtr v3)
  310. {
  311. GLuint vertsize = intel->vertex_size;
  312. GLuint *vb = intel_get_prim_space(intel, 6);
  313. int j;
  314. COPY_DWORDS(j, vb, vertsize, v0);
  315. COPY_DWORDS(j, vb, vertsize, v1);
  316. /* If smooth shading, draw like a trifan which gives better
  317. * rasterization. Otherwise draw as two triangles with provoking
  318. * vertex in third position as required for flat shading.
  319. */
  320. if (intel->ctx.Light.ShadeModel == GL_FLAT) {
  321. COPY_DWORDS(j, vb, vertsize, v3);
  322. COPY_DWORDS(j, vb, vertsize, v1);
  323. }
  324. else {
  325. COPY_DWORDS(j, vb, vertsize, v2);
  326. COPY_DWORDS(j, vb, vertsize, v0);
  327. }
  328. COPY_DWORDS(j, vb, vertsize, v2);
  329. COPY_DWORDS(j, vb, vertsize, v3);
  330. }
  331. static void
  332. intel_draw_triangle(struct intel_context *intel,
  333. intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
  334. {
  335. GLuint vertsize = intel->vertex_size;
  336. GLuint *vb = intel_get_prim_space(intel, 3);
  337. int j;
  338. COPY_DWORDS(j, vb, vertsize, v0);
  339. COPY_DWORDS(j, vb, vertsize, v1);
  340. COPY_DWORDS(j, vb, vertsize, v2);
  341. }
  342. static void
  343. intel_draw_line(struct intel_context *intel,
  344. intelVertexPtr v0, intelVertexPtr v1)
  345. {
  346. GLuint vertsize = intel->vertex_size;
  347. GLuint *vb = intel_get_prim_space(intel, 2);
  348. int j;
  349. COPY_DWORDS(j, vb, vertsize, v0);
  350. COPY_DWORDS(j, vb, vertsize, v1);
  351. }
  352. static void
  353. intel_draw_point(struct intel_context *intel, intelVertexPtr v0)
  354. {
  355. GLuint vertsize = intel->vertex_size;
  356. GLuint *vb = intel_get_prim_space(intel, 1);
  357. int j;
  358. /* Adjust for sub pixel position -- still required for conform. */
  359. *(float *) &vb[0] = v0->v.x;
  360. *(float *) &vb[1] = v0->v.y;
  361. for (j = 2; j < vertsize; j++)
  362. vb[j] = v0->ui[j];
  363. }
  364. /***********************************************************************
  365. * Fixup for ARB_point_parameters *
  366. ***********************************************************************/
  367. /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
  368. * represented in the fragment program InputsRead field.
  369. */
  370. static void
  371. intel_atten_point(struct intel_context *intel, intelVertexPtr v0)
  372. {
  373. struct gl_context *ctx = &intel->ctx;
  374. GLfloat psz[4], col[4], restore_psz, restore_alpha;
  375. _tnl_get_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
  376. _tnl_get_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
  377. restore_psz = psz[0];
  378. restore_alpha = col[3];
  379. if (psz[0] >= ctx->Point.Threshold) {
  380. psz[0] = MIN2(psz[0], ctx->Point.MaxSize);
  381. }
  382. else {
  383. GLfloat dsize = psz[0] / ctx->Point.Threshold;
  384. psz[0] = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
  385. col[3] *= dsize * dsize;
  386. }
  387. if (psz[0] < 1.0)
  388. psz[0] = 1.0;
  389. if (restore_psz != psz[0] || restore_alpha != col[3]) {
  390. _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
  391. _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
  392. intel_draw_point(intel, v0);
  393. psz[0] = restore_psz;
  394. col[3] = restore_alpha;
  395. _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
  396. _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
  397. }
  398. else
  399. intel_draw_point(intel, v0);
  400. }
  401. /***********************************************************************
  402. * Fixup for I915 WPOS texture coordinate *
  403. ***********************************************************************/
  404. static void
  405. intel_emit_fragcoord(struct intel_context *intel, intelVertexPtr v)
  406. {
  407. struct gl_context *ctx = &intel->ctx;
  408. struct gl_framebuffer *fb = ctx->DrawBuffer;
  409. GLuint offset = intel->wpos_offset;
  410. float *vertex_position = (float *)v;
  411. float *fragcoord = (float *)((char *)v + offset);
  412. fragcoord[0] = vertex_position[0];
  413. if (_mesa_is_user_fbo(fb))
  414. fragcoord[1] = vertex_position[1];
  415. else
  416. fragcoord[1] = fb->Height - vertex_position[1];
  417. fragcoord[2] = vertex_position[2];
  418. fragcoord[3] = vertex_position[3];
  419. }
  420. static void
  421. intel_wpos_triangle(struct intel_context *intel,
  422. intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
  423. {
  424. intel_emit_fragcoord(intel, v0);
  425. intel_emit_fragcoord(intel, v1);
  426. intel_emit_fragcoord(intel, v2);
  427. intel_draw_triangle(intel, v0, v1, v2);
  428. }
  429. static void
  430. intel_wpos_line(struct intel_context *intel,
  431. intelVertexPtr v0, intelVertexPtr v1)
  432. {
  433. intel_emit_fragcoord(intel, v0);
  434. intel_emit_fragcoord(intel, v1);
  435. intel_draw_line(intel, v0, v1);
  436. }
  437. static void
  438. intel_wpos_point(struct intel_context *intel, intelVertexPtr v0)
  439. {
  440. intel_emit_fragcoord(intel, v0);
  441. intel_draw_point(intel, v0);
  442. }
  443. /***********************************************************************
  444. * Macros for t_dd_tritmp.h to draw basic primitives *
  445. ***********************************************************************/
  446. #define TRI( a, b, c ) \
  447. do { \
  448. if (DO_FALLBACK) \
  449. intel->draw_tri( intel, a, b, c ); \
  450. else \
  451. intel_draw_triangle( intel, a, b, c ); \
  452. } while (0)
  453. #define QUAD( a, b, c, d ) \
  454. do { \
  455. if (DO_FALLBACK) { \
  456. intel->draw_tri( intel, a, b, d ); \
  457. intel->draw_tri( intel, b, c, d ); \
  458. } else \
  459. intel_draw_quad( intel, a, b, c, d ); \
  460. } while (0)
  461. #define LINE( v0, v1 ) \
  462. do { \
  463. if (DO_FALLBACK) \
  464. intel->draw_line( intel, v0, v1 ); \
  465. else \
  466. intel_draw_line( intel, v0, v1 ); \
  467. } while (0)
  468. #define POINT( v0 ) \
  469. do { \
  470. if (DO_FALLBACK) \
  471. intel->draw_point( intel, v0 ); \
  472. else \
  473. intel_draw_point( intel, v0 ); \
  474. } while (0)
  475. /***********************************************************************
  476. * Build render functions from dd templates *
  477. ***********************************************************************/
  478. #define INTEL_OFFSET_BIT 0x01
  479. #define INTEL_TWOSIDE_BIT 0x02
  480. #define INTEL_UNFILLED_BIT 0x04
  481. #define INTEL_FALLBACK_BIT 0x08
  482. #define INTEL_MAX_TRIFUNC 0x10
  483. static struct
  484. {
  485. tnl_points_func points;
  486. tnl_line_func line;
  487. tnl_triangle_func triangle;
  488. tnl_quad_func quad;
  489. } rast_tab[INTEL_MAX_TRIFUNC];
  490. #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
  491. #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
  492. #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
  493. #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
  494. #define DO_FLAT 0
  495. #define DO_TRI 1
  496. #define DO_QUAD 1
  497. #define DO_LINE 1
  498. #define DO_POINTS 1
  499. #define DO_FULL_QUAD 1
  500. #define HAVE_SPEC 1
  501. #define HAVE_BACK_COLORS 0
  502. #define HAVE_HW_FLATSHADE 1
  503. #define VERTEX intelVertex
  504. #define TAB rast_tab
  505. /* Only used to pull back colors into vertices (ie, we know color is
  506. * floating point).
  507. */
  508. #define INTEL_COLOR( dst, src ) \
  509. do { \
  510. UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
  511. UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
  512. UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
  513. UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
  514. } while (0)
  515. #define INTEL_SPEC( dst, src ) \
  516. do { \
  517. UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
  518. UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
  519. UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
  520. } while (0)
  521. #define DEPTH_SCALE intel->polygon_offset_scale
  522. #define UNFILLED_TRI unfilled_tri
  523. #define UNFILLED_QUAD unfilled_quad
  524. #define VERT_X(_v) _v->v.x
  525. #define VERT_Y(_v) _v->v.y
  526. #define VERT_Z(_v) _v->v.z
  527. #define AREA_IS_CCW( a ) (a > 0)
  528. #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
  529. #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
  530. #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
  531. #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
  532. #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
  533. #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
  534. #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
  535. #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
  536. #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
  537. #define LOCAL_VARS(n) \
  538. struct intel_context *intel = intel_context(ctx); \
  539. GLuint color[n] = { 0, }, spec[n] = { 0, }; \
  540. GLuint coloroffset = intel->coloroffset; \
  541. GLuint specoffset = intel->specoffset; \
  542. (void) color; (void) spec; (void) coloroffset; (void) specoffset;
  543. /***********************************************************************
  544. * Helpers for rendering unfilled primitives *
  545. ***********************************************************************/
  546. static const GLuint hw_prim[GL_POLYGON + 1] = {
  547. PRIM3D_POINTLIST,
  548. PRIM3D_LINELIST,
  549. PRIM3D_LINELIST,
  550. PRIM3D_LINELIST,
  551. PRIM3D_TRILIST,
  552. PRIM3D_TRILIST,
  553. PRIM3D_TRILIST,
  554. PRIM3D_TRILIST,
  555. PRIM3D_TRILIST,
  556. PRIM3D_TRILIST
  557. };
  558. #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
  559. #define RENDER_PRIMITIVE intel->render_primitive
  560. #define TAG(x) x
  561. #define IND INTEL_FALLBACK_BIT
  562. #include "tnl_dd/t_dd_unfilled.h"
  563. #undef IND
  564. /***********************************************************************
  565. * Generate GL render functions *
  566. ***********************************************************************/
  567. #define IND (0)
  568. #define TAG(x) x
  569. #include "tnl_dd/t_dd_tritmp.h"
  570. #define IND (INTEL_OFFSET_BIT)
  571. #define TAG(x) x##_offset
  572. #include "tnl_dd/t_dd_tritmp.h"
  573. #define IND (INTEL_TWOSIDE_BIT)
  574. #define TAG(x) x##_twoside
  575. #include "tnl_dd/t_dd_tritmp.h"
  576. #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
  577. #define TAG(x) x##_twoside_offset
  578. #include "tnl_dd/t_dd_tritmp.h"
  579. #define IND (INTEL_UNFILLED_BIT)
  580. #define TAG(x) x##_unfilled
  581. #include "tnl_dd/t_dd_tritmp.h"
  582. #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
  583. #define TAG(x) x##_offset_unfilled
  584. #include "tnl_dd/t_dd_tritmp.h"
  585. #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
  586. #define TAG(x) x##_twoside_unfilled
  587. #include "tnl_dd/t_dd_tritmp.h"
  588. #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
  589. #define TAG(x) x##_twoside_offset_unfilled
  590. #include "tnl_dd/t_dd_tritmp.h"
  591. #define IND (INTEL_FALLBACK_BIT)
  592. #define TAG(x) x##_fallback
  593. #include "tnl_dd/t_dd_tritmp.h"
  594. #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
  595. #define TAG(x) x##_offset_fallback
  596. #include "tnl_dd/t_dd_tritmp.h"
  597. #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
  598. #define TAG(x) x##_twoside_fallback
  599. #include "tnl_dd/t_dd_tritmp.h"
  600. #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
  601. #define TAG(x) x##_twoside_offset_fallback
  602. #include "tnl_dd/t_dd_tritmp.h"
  603. #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
  604. #define TAG(x) x##_unfilled_fallback
  605. #include "tnl_dd/t_dd_tritmp.h"
  606. #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
  607. #define TAG(x) x##_offset_unfilled_fallback
  608. #include "tnl_dd/t_dd_tritmp.h"
  609. #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
  610. #define TAG(x) x##_twoside_unfilled_fallback
  611. #include "tnl_dd/t_dd_tritmp.h"
  612. #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
  613. INTEL_FALLBACK_BIT)
  614. #define TAG(x) x##_twoside_offset_unfilled_fallback
  615. #include "tnl_dd/t_dd_tritmp.h"
  616. static void
  617. init_rast_tab(void)
  618. {
  619. init();
  620. init_offset();
  621. init_twoside();
  622. init_twoside_offset();
  623. init_unfilled();
  624. init_offset_unfilled();
  625. init_twoside_unfilled();
  626. init_twoside_offset_unfilled();
  627. init_fallback();
  628. init_offset_fallback();
  629. init_twoside_fallback();
  630. init_twoside_offset_fallback();
  631. init_unfilled_fallback();
  632. init_offset_unfilled_fallback();
  633. init_twoside_unfilled_fallback();
  634. init_twoside_offset_unfilled_fallback();
  635. }
  636. /***********************************************************************
  637. * Rasterization fallback helpers *
  638. ***********************************************************************/
  639. /* This code is hit only when a mix of accelerated and unaccelerated
  640. * primitives are being drawn, and only for the unaccelerated
  641. * primitives.
  642. */
  643. static void
  644. intel_fallback_tri(struct intel_context *intel,
  645. intelVertex * v0, intelVertex * v1, intelVertex * v2)
  646. {
  647. struct gl_context *ctx = &intel->ctx;
  648. SWvertex v[3];
  649. if (0)
  650. fprintf(stderr, "\n%s\n", __FUNCTION__);
  651. INTEL_FIREVERTICES(intel);
  652. _swsetup_Translate(ctx, v0, &v[0]);
  653. _swsetup_Translate(ctx, v1, &v[1]);
  654. _swsetup_Translate(ctx, v2, &v[2]);
  655. intelSpanRenderStart(ctx);
  656. _swrast_Triangle(ctx, &v[0], &v[1], &v[2]);
  657. intelSpanRenderFinish(ctx);
  658. }
  659. static void
  660. intel_fallback_line(struct intel_context *intel,
  661. intelVertex * v0, intelVertex * v1)
  662. {
  663. struct gl_context *ctx = &intel->ctx;
  664. SWvertex v[2];
  665. if (0)
  666. fprintf(stderr, "\n%s\n", __FUNCTION__);
  667. INTEL_FIREVERTICES(intel);
  668. _swsetup_Translate(ctx, v0, &v[0]);
  669. _swsetup_Translate(ctx, v1, &v[1]);
  670. intelSpanRenderStart(ctx);
  671. _swrast_Line(ctx, &v[0], &v[1]);
  672. intelSpanRenderFinish(ctx);
  673. }
  674. static void
  675. intel_fallback_point(struct intel_context *intel,
  676. intelVertex * v0)
  677. {
  678. struct gl_context *ctx = &intel->ctx;
  679. SWvertex v[1];
  680. if (0)
  681. fprintf(stderr, "\n%s\n", __FUNCTION__);
  682. INTEL_FIREVERTICES(intel);
  683. _swsetup_Translate(ctx, v0, &v[0]);
  684. intelSpanRenderStart(ctx);
  685. _swrast_Point(ctx, &v[0]);
  686. intelSpanRenderFinish(ctx);
  687. }
  688. /**********************************************************************/
  689. /* Render unclipped begin/end objects */
  690. /**********************************************************************/
  691. #define IND 0
  692. #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
  693. #define RENDER_POINTS( start, count ) \
  694. for ( ; start < count ; start++) POINT( V(ELT(start)) );
  695. #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
  696. #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
  697. #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
  698. #define INIT(x) intelRenderPrimitive( ctx, x )
  699. #undef LOCAL_VARS
  700. #define LOCAL_VARS \
  701. struct intel_context *intel = intel_context(ctx); \
  702. GLubyte *vertptr = (GLubyte *)intel->verts; \
  703. const GLuint vertsize = intel->vertex_size; \
  704. const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
  705. (void) elt;
  706. #define RESET_STIPPLE
  707. #define RESET_OCCLUSION
  708. #define PRESERVE_VB_DEFS
  709. #define ELT(x) x
  710. #define TAG(x) intel_##x##_verts
  711. #include "tnl/t_vb_rendertmp.h"
  712. #undef ELT
  713. #undef TAG
  714. #define TAG(x) intel_##x##_elts
  715. #define ELT(x) elt[x]
  716. #include "tnl/t_vb_rendertmp.h"
  717. /**********************************************************************/
  718. /* Render clipped primitives */
  719. /**********************************************************************/
  720. static void
  721. intelRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
  722. {
  723. struct intel_context *intel = intel_context(ctx);
  724. TNLcontext *tnl = TNL_CONTEXT(ctx);
  725. struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
  726. GLuint prim = intel->render_primitive;
  727. /* Render the new vertices as an unclipped polygon.
  728. */
  729. {
  730. GLuint *tmp = VB->Elts;
  731. VB->Elts = (GLuint *) elts;
  732. tnl->Driver.Render.PrimTabElts[GL_POLYGON] (ctx, 0, n,
  733. PRIM_BEGIN | PRIM_END);
  734. VB->Elts = tmp;
  735. }
  736. /* Restore the render primitive
  737. */
  738. if (prim != GL_POLYGON)
  739. tnl->Driver.Render.PrimitiveNotify(ctx, prim);
  740. }
  741. static void
  742. intelRenderClippedLine(struct gl_context * ctx, GLuint ii, GLuint jj)
  743. {
  744. TNLcontext *tnl = TNL_CONTEXT(ctx);
  745. tnl->Driver.Render.Line(ctx, ii, jj);
  746. }
  747. static void
  748. intelFastRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
  749. {
  750. struct intel_context *intel = intel_context(ctx);
  751. const GLuint vertsize = intel->vertex_size;
  752. GLuint *vb = intel_get_prim_space(intel, (n - 2) * 3);
  753. GLubyte *vertptr = (GLubyte *) intel->verts;
  754. const GLuint *start = (const GLuint *) V(elts[0]);
  755. int i, j;
  756. for (i = 2; i < n; i++) {
  757. COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
  758. COPY_DWORDS(j, vb, vertsize, V(elts[i]));
  759. COPY_DWORDS(j, vb, vertsize, start);
  760. }
  761. }
  762. /**********************************************************************/
  763. /* Choose render functions */
  764. /**********************************************************************/
  765. #define DD_TRI_LIGHT_TWOSIDE (1 << 1)
  766. #define DD_TRI_UNFILLED (1 << 2)
  767. #define DD_TRI_STIPPLE (1 << 4)
  768. #define DD_TRI_OFFSET (1 << 5)
  769. #define DD_LINE_STIPPLE (1 << 7)
  770. #define DD_POINT_ATTEN (1 << 9)
  771. #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN)
  772. #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
  773. void
  774. intelChooseRenderState(struct gl_context * ctx)
  775. {
  776. TNLcontext *tnl = TNL_CONTEXT(ctx);
  777. struct intel_context *intel = intel_context(ctx);
  778. GLuint flags =
  779. ((ctx->Light.Enabled &&
  780. ctx->Light.Model.TwoSide) ? DD_TRI_LIGHT_TWOSIDE : 0) |
  781. ((ctx->Polygon.FrontMode != GL_FILL ||
  782. ctx->Polygon.BackMode != GL_FILL) ? DD_TRI_UNFILLED : 0) |
  783. (ctx->Polygon.StippleFlag ? DD_TRI_STIPPLE : 0) |
  784. ((ctx->Polygon.OffsetPoint ||
  785. ctx->Polygon.OffsetLine ||
  786. ctx->Polygon.OffsetFill) ? DD_TRI_OFFSET : 0) |
  787. (ctx->Line.StippleFlag ? DD_LINE_STIPPLE : 0) |
  788. (ctx->Point._Attenuated ? DD_POINT_ATTEN : 0);
  789. const struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
  790. bool have_wpos = (fprog && (fprog->Base.InputsRead & VARYING_BIT_POS));
  791. GLuint index = 0;
  792. if (INTEL_DEBUG & DEBUG_STATE)
  793. fprintf(stderr, "\n%s\n", __FUNCTION__);
  794. if ((flags & (ANY_FALLBACK_FLAGS | ANY_RASTER_FLAGS)) || have_wpos) {
  795. if (flags & ANY_RASTER_FLAGS) {
  796. if (flags & DD_TRI_LIGHT_TWOSIDE)
  797. index |= INTEL_TWOSIDE_BIT;
  798. if (flags & DD_TRI_OFFSET)
  799. index |= INTEL_OFFSET_BIT;
  800. if (flags & DD_TRI_UNFILLED)
  801. index |= INTEL_UNFILLED_BIT;
  802. }
  803. if (have_wpos) {
  804. intel->draw_point = intel_wpos_point;
  805. intel->draw_line = intel_wpos_line;
  806. intel->draw_tri = intel_wpos_triangle;
  807. /* Make sure these get called:
  808. */
  809. index |= INTEL_FALLBACK_BIT;
  810. }
  811. else {
  812. intel->draw_point = intel_draw_point;
  813. intel->draw_line = intel_draw_line;
  814. intel->draw_tri = intel_draw_triangle;
  815. }
  816. /* Hook in fallbacks for specific primitives.
  817. */
  818. if (flags & ANY_FALLBACK_FLAGS) {
  819. if (flags & DD_LINE_STIPPLE)
  820. intel->draw_line = intel_fallback_line;
  821. if ((flags & DD_TRI_STIPPLE) && !intel->hw_stipple)
  822. intel->draw_tri = intel_fallback_tri;
  823. if (flags & DD_POINT_ATTEN) {
  824. if (0)
  825. intel->draw_point = intel_atten_point;
  826. else
  827. intel->draw_point = intel_fallback_point;
  828. }
  829. index |= INTEL_FALLBACK_BIT;
  830. }
  831. }
  832. if (intel->RenderIndex != index) {
  833. intel->RenderIndex = index;
  834. tnl->Driver.Render.Points = rast_tab[index].points;
  835. tnl->Driver.Render.Line = rast_tab[index].line;
  836. tnl->Driver.Render.Triangle = rast_tab[index].triangle;
  837. tnl->Driver.Render.Quad = rast_tab[index].quad;
  838. if (index == 0) {
  839. tnl->Driver.Render.PrimTabVerts = intel_render_tab_verts;
  840. tnl->Driver.Render.PrimTabElts = intel_render_tab_elts;
  841. tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
  842. tnl->Driver.Render.ClippedPolygon = intelFastRenderClippedPoly;
  843. }
  844. else {
  845. tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
  846. tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
  847. tnl->Driver.Render.ClippedLine = intelRenderClippedLine;
  848. tnl->Driver.Render.ClippedPolygon = intelRenderClippedPoly;
  849. }
  850. }
  851. }
  852. static const GLenum reduced_prim[GL_POLYGON + 1] = {
  853. GL_POINTS,
  854. GL_LINES,
  855. GL_LINES,
  856. GL_LINES,
  857. GL_TRIANGLES,
  858. GL_TRIANGLES,
  859. GL_TRIANGLES,
  860. GL_TRIANGLES,
  861. GL_TRIANGLES,
  862. GL_TRIANGLES
  863. };
  864. /**********************************************************************/
  865. /* High level hooks for t_vb_render.c */
  866. /**********************************************************************/
  867. static void
  868. intelRunPipeline(struct gl_context * ctx)
  869. {
  870. struct intel_context *intel = intel_context(ctx);
  871. _mesa_lock_context_textures(ctx);
  872. if (ctx->NewState)
  873. _mesa_update_state_locked(ctx);
  874. /* We need to get this done before we start the pipeline, or a
  875. * change in the INTEL_FALLBACK() of its intel_draw_buffers() call
  876. * while the pipeline is running will result in mismatched swrast
  877. * map/unmaps, and later assertion failures.
  878. */
  879. intel_prepare_render(intel);
  880. if (intel->NewGLState) {
  881. if (intel->NewGLState & _NEW_TEXTURE) {
  882. intel->vtbl.update_texture_state(intel);
  883. }
  884. if (!intel->Fallback) {
  885. if (intel->NewGLState & _INTEL_NEW_RENDERSTATE)
  886. intelChooseRenderState(ctx);
  887. }
  888. intel->NewGLState = 0;
  889. }
  890. intel->tnl_pipeline_running = true;
  891. _tnl_run_pipeline(ctx);
  892. intel->tnl_pipeline_running = false;
  893. _mesa_unlock_context_textures(ctx);
  894. }
  895. static void
  896. intelRenderStart(struct gl_context * ctx)
  897. {
  898. struct intel_context *intel = intel_context(ctx);
  899. intel_check_front_buffer_rendering(intel);
  900. intel->vtbl.render_start(intel_context(ctx));
  901. intel->vtbl.emit_state(intel);
  902. }
  903. static void
  904. intelRenderFinish(struct gl_context * ctx)
  905. {
  906. struct intel_context *intel = intel_context(ctx);
  907. if (intel->RenderIndex & INTEL_FALLBACK_BIT)
  908. _swrast_flush(ctx);
  909. INTEL_FIREVERTICES(intel);
  910. }
  911. /* System to flush dma and emit state changes based on the rasterized
  912. * primitive.
  913. */
  914. static void
  915. intelRasterPrimitive(struct gl_context * ctx, GLenum rprim, GLuint hwprim)
  916. {
  917. struct intel_context *intel = intel_context(ctx);
  918. if (0)
  919. fprintf(stderr, "%s %s %x\n", __FUNCTION__,
  920. _mesa_lookup_enum_by_nr(rprim), hwprim);
  921. intel->vtbl.reduced_primitive_state(intel, rprim);
  922. /* Start a new primitive. Arrange to have it flushed later on.
  923. */
  924. if (hwprim != intel->prim.primitive) {
  925. INTEL_FIREVERTICES(intel);
  926. intel_set_prim(intel, hwprim);
  927. }
  928. }
  929. /*
  930. */
  931. static void
  932. intelRenderPrimitive(struct gl_context * ctx, GLenum prim)
  933. {
  934. struct intel_context *intel = intel_context(ctx);
  935. GLboolean unfilled = (ctx->Polygon.FrontMode != GL_FILL ||
  936. ctx->Polygon.BackMode != GL_FILL);
  937. if (0)
  938. fprintf(stderr, "%s %s\n", __FUNCTION__, _mesa_lookup_enum_by_nr(prim));
  939. /* Let some clipping routines know which primitive they're dealing
  940. * with.
  941. */
  942. intel->render_primitive = prim;
  943. /* Shortcircuit this when called for unfilled triangles. The rasterized
  944. * primitive will always be reset by lower level functions in that case,
  945. * potentially pingponging the state:
  946. */
  947. if (reduced_prim[prim] == GL_TRIANGLES && unfilled)
  948. return;
  949. /* Set some primitive-dependent state and Start? a new primitive.
  950. */
  951. intelRasterPrimitive(ctx, reduced_prim[prim], hw_prim[prim]);
  952. }
  953. /**********************************************************************/
  954. /* Transition to/from hardware rasterization. */
  955. /**********************************************************************/
  956. static char *fallbackStrings[] = {
  957. [0] = "Draw buffer",
  958. [1] = "Read buffer",
  959. [2] = "Depth buffer",
  960. [3] = "Stencil buffer",
  961. [4] = "User disable",
  962. [5] = "Render mode",
  963. [12] = "Texture",
  964. [13] = "Color mask",
  965. [14] = "Stencil",
  966. [15] = "Stipple",
  967. [16] = "Program",
  968. [17] = "Logic op",
  969. [18] = "Smooth polygon",
  970. [19] = "Smooth point",
  971. [20] = "point sprite coord origin",
  972. [21] = "depth/color drawing offset",
  973. [22] = "coord replace(SPRITE POINT ENABLE)",
  974. };
  975. static char *
  976. getFallbackString(GLuint bit)
  977. {
  978. int i = 0;
  979. while (bit > 1) {
  980. i++;
  981. bit >>= 1;
  982. }
  983. return fallbackStrings[i];
  984. }
  985. /**
  986. * Enable/disable a fallback flag.
  987. * \param bit one of INTEL_FALLBACK_x flags.
  988. */
  989. void
  990. intelFallback(struct intel_context *intel, GLbitfield bit, bool mode)
  991. {
  992. struct gl_context *ctx = &intel->ctx;
  993. TNLcontext *tnl = TNL_CONTEXT(ctx);
  994. const GLbitfield oldfallback = intel->Fallback;
  995. if (mode) {
  996. intel->Fallback |= bit;
  997. if (oldfallback == 0) {
  998. assert(!intel->tnl_pipeline_running);
  999. intel_flush(ctx);
  1000. if (INTEL_DEBUG & DEBUG_PERF)
  1001. fprintf(stderr, "ENTER FALLBACK %x: %s\n",
  1002. bit, getFallbackString(bit));
  1003. _swsetup_Wakeup(ctx);
  1004. intel->RenderIndex = ~0;
  1005. }
  1006. }
  1007. else {
  1008. intel->Fallback &= ~bit;
  1009. if (oldfallback == bit) {
  1010. assert(!intel->tnl_pipeline_running);
  1011. _swrast_flush(ctx);
  1012. if (INTEL_DEBUG & DEBUG_PERF)
  1013. fprintf(stderr, "LEAVE FALLBACK %s\n", getFallbackString(bit));
  1014. tnl->Driver.Render.Start = intelRenderStart;
  1015. tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
  1016. tnl->Driver.Render.Finish = intelRenderFinish;
  1017. tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
  1018. tnl->Driver.Render.CopyPV = _tnl_copy_pv;
  1019. tnl->Driver.Render.Interp = _tnl_interp;
  1020. _tnl_invalidate_vertex_state(ctx, ~0);
  1021. _tnl_invalidate_vertices(ctx, ~0);
  1022. _tnl_install_attrs(ctx,
  1023. intel->vertex_attrs,
  1024. intel->vertex_attr_count,
  1025. intel->ViewportMatrix.m, 0);
  1026. intel->NewGLState |= _INTEL_NEW_RENDERSTATE;
  1027. }
  1028. }
  1029. }
  1030. union fi
  1031. {
  1032. GLfloat f;
  1033. GLint i;
  1034. };
  1035. /**********************************************************************/
  1036. /* Initialization. */
  1037. /**********************************************************************/
  1038. void
  1039. intelInitTriFuncs(struct gl_context * ctx)
  1040. {
  1041. TNLcontext *tnl = TNL_CONTEXT(ctx);
  1042. static int firsttime = 1;
  1043. if (firsttime) {
  1044. init_rast_tab();
  1045. firsttime = 0;
  1046. }
  1047. tnl->Driver.RunPipeline = intelRunPipeline;
  1048. tnl->Driver.Render.Start = intelRenderStart;
  1049. tnl->Driver.Render.Finish = intelRenderFinish;
  1050. tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
  1051. tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
  1052. tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
  1053. tnl->Driver.Render.CopyPV = _tnl_copy_pv;
  1054. tnl->Driver.Render.Interp = _tnl_interp;
  1055. }