brw_clip.c revision ab12e764ba3f57ad9f0d7252262cfc6e07839928
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
459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#define FRONT_UNFILLED_BIT  0x1
479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#define BACK_UNFILLED_BIT   0x2
489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void compile_clip_prog( struct brw_context *brw,
519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt			     struct brw_clip_prog_key *key )
529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_clip_compile c;
549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   const GLuint *program;
559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint program_size;
569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint delta;
579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint i;
589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   memset(&c, 0, sizeof(c));
609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Begin the compilation:
629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
638e444fb9e2685e3eac42beb848b08e91dc20c88aXiang, Haihao   brw_init_compile(brw, &c.func);
649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
651b9f78195f62959601d440475a6cbba5e8046813Eric Anholt   c.func.single_program_flow = 1;
661b9f78195f62959601d440475a6cbba5e8046813Eric Anholt
679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.key = *key;
682995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   c.need_ff_sync = BRW_IS_IGDNG(brw);
699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Need to locate the two positions present in vertex + header.
719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * These are currently hardcoded:
729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.header_position_offset = ATTR_SIZE;
749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
752995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   if (BRW_IS_IGDNG(brw))
762995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       delta = 3 * REG_SIZE;
772995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   else
782995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       delta = REG_SIZE;
792995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
802995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   for (i = 0; i < VERT_RESULT_MAX; i++)
819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (c.key.attrs & (1<<i)) {
829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 c.offset[i] = delta;
839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 delta += ATTR_SIZE;
849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.nr_attrs = brw_count_bits(c.key.attrs);
872995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
882995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   if (BRW_IS_IGDNG(brw))
892995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       c.nr_regs = (c.nr_attrs + 1) / 2 + 3;  /* are vertices packed, or reg-aligned? */
902995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   else
912995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       c.nr_regs = (c.nr_attrs + 1) / 2 + 1;  /* are vertices packed, or reg-aligned? */
922995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.nr_bytes = c.nr_regs * REG_SIZE;
949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.prog_data.clip_mode = c.key.clip_mode; /* XXX */
969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* For some reason the thread is spawned with only 4 channels
989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * unmasked.
999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw_set_mask_control(&c.func, BRW_MASK_DISABLE);
1019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Would ideally have the option of producing a program which could
1049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * do all three:
1059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   switch (key->primitive) {
1079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_TRIANGLES:
1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (key->do_unfilled)
1099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_emit_unfilled_clip( &c );
1109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      else
1119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_emit_tri_clip( &c );
1129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_LINES:
1149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw_emit_line_clip( &c );
1159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_POINTS:
1179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw_emit_point_clip( &c );
1189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   default:
1209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      assert(0);
1219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return;
1229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* get the program
1279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   program = brw_get_program(&c.func, &program_size);
1299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Upload
1319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
13238bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt   dri_bo_unreference(brw->clip.prog_bo);
13338bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt   brw->clip.prog_bo = brw_upload_cache( &brw->cache,
13438bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					 BRW_CLIP_PROG,
13538bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					 &c.key, sizeof(c.key),
13638bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					 NULL, 0,
13738bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					 program, program_size,
13838bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					 &c.prog_data,
13938bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					 &brw->clip.prog_data );
1409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
1419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Calculate interpolants for triangle and line rasterization.
1439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */
144f75843a517bd188639e6866db2a7b04de3524e16Dave Airliestatic void upload_clip_prog(struct brw_context *brw)
1459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
1469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLcontext *ctx = &brw->intel.ctx;
1479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_clip_prog_key key;
1489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   memset(&key, 0, sizeof(key));
1509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Populate the key:
1529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* BRW_NEW_REDUCED_PRIMITIVE */
1549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   key.primitive = brw->intel.reduced_primitive;
1559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* CACHE_NEW_VS_PROG */
1569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   key.attrs = brw->vs.prog_data->outputs_written;
1579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_LIGHT */
158052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt   key.do_flat_shading = (ctx->Light.ShadeModel == GL_FLAT);
159ab12e764ba3f57ad9f0d7252262cfc6e07839928Roland Scheidegger   key.pv_first = (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION);
1609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_TRANSFORM */
161052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt   key.nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
1622995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
1632995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   if (BRW_IS_IGDNG(brw))
1642995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       key.clip_mode = BRW_CLIPMODE_KERNEL_CLIP;
1652995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   else
1662995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       key.clip_mode = BRW_CLIPMODE_NORMAL;
1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_POLYGON */
1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (key.primitive == GL_TRIANGLES) {
17081d555068408d4343d7627c8bedda5675f09bd21Eric Anholt      if (ctx->Polygon.CullFlag &&
17181d555068408d4343d7627c8bedda5675f09bd21Eric Anholt	  ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
1729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 key.clip_mode = BRW_CLIPMODE_REJECT_ALL;
1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      else {
1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint fill_front = CLIP_CULL;
1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint fill_back = CLIP_CULL;
1769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint offset_front = 0;
1779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint offset_back = 0;
1789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
179052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (!ctx->Polygon.CullFlag ||
180052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.CullFaceMode != GL_FRONT) {
181052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.FrontMode) {
1829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_FILL:
1839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_FILL;
1849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       offset_front = 0;
1859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_LINE:
1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_LINE;
188052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_front = ctx->Polygon.OffsetLine;
1899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_POINT:
1919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_POINT;
192052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_front = ctx->Polygon.OffsetPoint;
1939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
1959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
1969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
197052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (!ctx->Polygon.CullFlag ||
198052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.CullFaceMode != GL_BACK) {
199052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.BackMode) {
2009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_FILL:
2019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_FILL;
2029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       offset_back = 0;
2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_LINE:
2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_LINE;
206052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_back = ctx->Polygon.OffsetLine;
2079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_POINT:
2099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_POINT;
210052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_back = ctx->Polygon.OffsetPoint;
2119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
2149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
215052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (ctx->Polygon.BackMode != GL_FILL ||
216052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.FrontMode != GL_FILL) {
2175cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	    key.do_unfilled = 1;
2183ee6a77e97f7d2996f8fffdbb4787a9589189b39Xiang, Haihao
2195cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	    /* Most cases the fixed function units will handle.  Cases where
2205cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	     * one or more polygon faces are unfilled will require help:
2215cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	     */
2229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    key.clip_mode = BRW_CLIPMODE_CLIP_NON_REJECTED;
2239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    if (offset_back || offset_front) {
2259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       /* _NEW_POLYGON, _NEW_BUFFERS */
226052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       key.offset_units = ctx->Polygon.OffsetUnits * brw->intel.polygon_offset_scale;
227052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       key.offset_factor = ctx->Polygon.OffsetFactor * ctx->DrawBuffer->_MRD;
2289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
230052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.FrontFace) {
2319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_CCW:
2329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_ccw = fill_front;
2339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_cw = fill_back;
2349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_ccw = offset_front;
2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_cw = offset_back;
236052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       if (ctx->Light.Model.TwoSide &&
2379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		   key.fill_cw != CLIP_CULL)
2389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		  key.copy_bfc_cw = 1;
2399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_CW:
2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_cw = fill_front;
2429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_ccw = fill_back;
2439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_cw = offset_front;
2449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_ccw = offset_back;
245052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       if (ctx->Light.Model.TwoSide &&
2469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		   key.fill_ccw != CLIP_CULL)
2479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		  key.copy_bfc_ccw = 1;
2489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
25438bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt   dri_bo_unreference(brw->clip.prog_bo);
25538bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt   brw->clip.prog_bo = brw_search_cache(&brw->cache, BRW_CLIP_PROG,
25638bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					&key, sizeof(key),
25738bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					NULL, 0,
25838bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt					&brw->clip.prog_data);
25938bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt   if (brw->clip.prog_bo == NULL)
260125bd4cae51c6deaacd2e90f14931c2052f146abEric Anholt      compile_clip_prog( brw, &key );
2619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
2629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_clip_prog = {
2659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
2669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .mesa  = (_NEW_LIGHT |
2679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_TRANSFORM |
2689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_POLYGON |
2699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_BUFFERS),
2709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .brw   = (BRW_NEW_REDUCED_PRIMITIVE),
2719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .cache = CACHE_NEW_VS_PROG
2729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
273008653ac55776d6b1c6d1627ad20937aa1c4dbdaDave Airlie   .prepare = upload_clip_prog
2749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
275