brw_clip.c revision 8c9a54e7bcfc80295ad77097910d35958dfd3644
19f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/*
29f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Copyright (C) Intel Corp.  2006.  All Rights Reserved.
39f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
49f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt develop this 3D driver.
59f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
69f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Permission is hereby granted, free of charge, to any person obtaining
79f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt a copy of this software and associated documentation files (the
89f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt "Software"), to deal in the Software without restriction, including
99f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt without limitation the rights to use, copy, modify, merge, publish,
109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt distribute, sublicense, and/or sell copies of the Software, and to
119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt permit persons to whom the Software is furnished to do so, subject to
129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt the following conditions:
139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt The above copyright notice and this permission notice (including the
159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt next paragraph) shall be included in all copies or substantial
169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt portions of the Software.
179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt **********************************************************************/
279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /*
289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  * Authors:
299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  *   Keith Whitwell <keith@tungstengraphics.com>
309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  */
319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
32ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/glheader.h"
33ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/macros.h"
34ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h"
359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "intel_batchbuffer.h"
379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_defines.h"
399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_context.h"
409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_eu.h"
419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_util.h"
429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_state.h"
439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_clip.h"
449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
452f0edc60f4bd2ae5999a6afa656e3bb3f181bf0fChad Versace#include "glsl/ralloc.h"
46774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke
479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#define FRONT_UNFILLED_BIT  0x1
489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#define BACK_UNFILLED_BIT   0x2
499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void compile_clip_prog( struct brw_context *brw,
529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt			     struct brw_clip_prog_key *key )
539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_clip_compile c;
559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   const GLuint *program;
56774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   void *mem_ctx;
579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint program_size;
589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint i;
599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   memset(&c, 0, sizeof(c));
61774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke
62774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   mem_ctx = ralloc_context(NULL);
639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Begin the compilation:
659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
66774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   brw_init_compile(brw, &c.func, mem_ctx);
679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
681b9f78195f62959601d440475a6cbba5e8046813Eric Anholt   c.func.single_program_flow = 1;
691b9f78195f62959601d440475a6cbba5e8046813Eric Anholt
709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.key = *key;
71bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry   c.vue_map = brw->vue_map_geom_out;
729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
7371cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry   /* nr_regs is the number of registers filled by reading data from the VUE.
7471cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry    * This program accesses the entire VUE, so nr_regs needs to be the size of
7571cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry    * the VUE (measured in pairs, since two slots are stored in each
7671cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry    * register).
77e29cff62734b6aaf0b05dba0b3ed98fe78842a42Eric Anholt    */
7871cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry   c.nr_regs = (c.vue_map.num_slots + 1)/2;
792995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.prog_data.clip_mode = c.key.clip_mode; /* XXX */
819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* For some reason the thread is spawned with only 4 channels
839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * unmasked.
849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw_set_mask_control(&c.func, BRW_MASK_DISABLE);
869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Would ideally have the option of producing a program which could
899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * do all three:
909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   switch (key->primitive) {
929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_TRIANGLES:
939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (key->do_unfilled)
949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_emit_unfilled_clip( &c );
959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      else
969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_emit_tri_clip( &c );
979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_LINES:
999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw_emit_line_clip( &c );
1009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_POINTS:
1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw_emit_point_clip( &c );
1039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   default:
1059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      assert(0);
1069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return;
1079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* get the program
1129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   program = brw_get_program(&c.func, &program_size);
1149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
115bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_CLIP)) {
116562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt      printf("clip:\n");
117562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt      for (i = 0; i < program_size / sizeof(struct brw_instruction); i++)
11836eda76fea02130d30be6a5f0d83f04698da2853Eric Anholt	 brw_disasm(stdout, &((struct brw_instruction *)program)[i],
11953631be4ebaa4fb13a7f129727c1cdd32fcc6f3dKenneth Graunke		    brw->gen);
120562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt      printf("\n");
121bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt   }
122562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt
123c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   brw_upload_cache(&brw->cache,
124c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    BRW_CLIP_PROG,
125c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &c.key, sizeof(c.key),
126c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    program, program_size,
127c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &c.prog_data, sizeof(c.prog_data),
128c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &brw->clip.prog_offset, &brw->clip.prog_data);
129774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   ralloc_free(mem_ctx);
1309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
1319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Calculate interpolants for triangle and line rasterization.
1339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */
134dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtstatic void
135dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtbrw_upload_clip_prog(struct brw_context *brw)
1369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
1378c9a54e7bcfc80295ad77097910d35958dfd3644Kenneth Graunke   struct gl_context *ctx = &brw->ctx;
1389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_clip_prog_key key;
1399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   memset(&key, 0, sizeof(key));
1419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Populate the key:
1439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* BRW_NEW_REDUCED_PRIMITIVE */
145fe0a8cb30dd53bed0d024b01e2c2b60911a3c526Kenneth Graunke   key.primitive = brw->reduced_primitive;
146bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry   /* BRW_NEW_VUE_MAP_GEOM_OUT */
147bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry   key.attrs = brw->vue_map_geom_out.slots_valid;
1489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_LIGHT */
149052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt   key.do_flat_shading = (ctx->Light.ShadeModel == GL_FLAT);
150ab12e764ba3f57ad9f0d7252262cfc6e07839928Roland Scheidegger   key.pv_first = (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION);
1519f3d3216cf25d8ffed4d72fbce6feacbc2990e4bEric Anholt   /* _NEW_TRANSFORM (also part of VUE map)*/
152c163072197b56e76b656cc472bbe6df650cf11baPaul Berry   key.nr_userclip = _mesa_bitcount_64(ctx->Transform.ClipPlanesEnabled);
1532995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
15453631be4ebaa4fb13a7f129727c1cdd32fcc6f3dKenneth Graunke   if (brw->gen == 5)
1552995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       key.clip_mode = BRW_CLIPMODE_KERNEL_CLIP;
1562995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   else
1572995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       key.clip_mode = BRW_CLIPMODE_NORMAL;
1589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_POLYGON */
1609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (key.primitive == GL_TRIANGLES) {
16181d555068408d4343d7627c8bedda5675f09bd21Eric Anholt      if (ctx->Polygon.CullFlag &&
16281d555068408d4343d7627c8bedda5675f09bd21Eric Anholt	  ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
1639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 key.clip_mode = BRW_CLIPMODE_REJECT_ALL;
1649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      else {
1659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint fill_front = CLIP_CULL;
1669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint fill_back = CLIP_CULL;
1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint offset_front = 0;
1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint offset_back = 0;
1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
170052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (!ctx->Polygon.CullFlag ||
171052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.CullFaceMode != GL_FRONT) {
172052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.FrontMode) {
1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_FILL:
1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_FILL;
1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       offset_front = 0;
1769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_LINE:
1789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_LINE;
179052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_front = ctx->Polygon.OffsetLine;
1809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_POINT:
1829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_POINT;
183052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_front = ctx->Polygon.OffsetPoint;
1849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
1869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
188052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (!ctx->Polygon.CullFlag ||
189052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.CullFaceMode != GL_BACK) {
190052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.BackMode) {
1919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_FILL:
1929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_FILL;
1939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       offset_back = 0;
1949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_LINE:
1969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_LINE;
197052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_back = ctx->Polygon.OffsetLine;
1989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_POINT:
2009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_POINT;
201052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_back = ctx->Polygon.OffsetPoint;
2029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
206052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (ctx->Polygon.BackMode != GL_FILL ||
207052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.FrontMode != GL_FILL) {
2085cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	    key.do_unfilled = 1;
2093ee6a77e97f7d2996f8fffdbb4787a9589189b39Xiang, Haihao
2105cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	    /* Most cases the fixed function units will handle.  Cases where
2115cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	     * one or more polygon faces are unfilled will require help:
2125cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	     */
2139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    key.clip_mode = BRW_CLIPMODE_CLIP_NON_REJECTED;
2149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    if (offset_back || offset_front) {
2169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       /* _NEW_POLYGON, _NEW_BUFFERS */
217c20f973c4f8fa2c275e445b5da8deefcba874d2eEric Anholt	       key.offset_units = ctx->Polygon.OffsetUnits * ctx->DrawBuffer->_MRD * 2;
218052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       key.offset_factor = ctx->Polygon.OffsetFactor * ctx->DrawBuffer->_MRD;
2199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
221052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.FrontFace) {
2229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_CCW:
2239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_ccw = fill_front;
2249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_cw = fill_back;
2259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_ccw = offset_front;
2269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_cw = offset_back;
227052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       if (ctx->Light.Model.TwoSide &&
2289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		   key.fill_cw != CLIP_CULL)
2299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		  key.copy_bfc_cw = 1;
2309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_CW:
2329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_cw = fill_front;
2339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_ccw = fill_back;
2349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_cw = offset_front;
2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_ccw = offset_back;
236052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       if (ctx->Light.Model.TwoSide &&
2379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		   key.fill_ccw != CLIP_CULL)
2389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		  key.copy_bfc_ccw = 1;
2399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
2429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
2439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
2449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
245c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   if (!brw_search_cache(&brw->cache, BRW_CLIP_PROG,
246c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			 &key, sizeof(key),
247c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			 &brw->clip.prog_offset, &brw->clip.prog_data)) {
248125bd4cae51c6deaacd2e90f14931c2052f146abEric Anholt      compile_clip_prog( brw, &key );
249c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   }
2509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_clip_prog = {
2549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
2559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .mesa  = (_NEW_LIGHT |
2569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_TRANSFORM |
2579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_POLYGON |
2589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_BUFFERS),
259bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry      .brw   = (BRW_NEW_REDUCED_PRIMITIVE | BRW_NEW_VUE_MAP_GEOM_OUT)
2609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
261dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholt   .emit = brw_upload_clip_prog
2629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
263