brw_clip.c revision 1e0da6233be6e5fb0143615d5e3d3642ddb7964f
19f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/*
29f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Copyright (C) Intel Corp.  2006.  All Rights Reserved.
3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca Intel funded Tungsten Graphics to
49f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt develop this 3D driver.
5a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke
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:
13a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke
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.
17a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke
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.
25a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke
269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt **********************************************************************/
279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /*
289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  * Authors:
29877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca  *   Keith Whitwell <keithw@vmware.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
451e0da6233be6e5fb0143615d5e3d3642ddb7964fKenneth Graunke#include "util/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
599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   memset(&c, 0, sizeof(c));
60774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke
61774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   mem_ctx = ralloc_context(NULL);
62a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke
639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Begin the compilation:
649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
65774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   brw_init_compile(brw, &c.func, mem_ctx);
669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
671b9f78195f62959601d440475a6cbba5e8046813Eric Anholt   c.func.single_program_flow = 1;
681b9f78195f62959601d440475a6cbba5e8046813Eric Anholt
699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.key = *key;
70bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry   c.vue_map = brw->vue_map_geom_out;
719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
72f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes   c.has_flat_shading =
73f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes      brw_any_flat_varyings(&key->interpolation_mode);
743f6fb5e1dd684434979ffca418184574e5c086f3Chris Forbes   c.has_noperspective_shading =
753f6fb5e1dd684434979ffca418184574e5c086f3Chris Forbes      brw_any_noperspective_varyings(&key->interpolation_mode);
76f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes
7771cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry   /* nr_regs is the number of registers filled by reading data from the VUE.
7871cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry    * This program accesses the entire VUE, so nr_regs needs to be the size of
7971cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry    * the VUE (measured in pairs, since two slots are stored in each
8071cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry    * register).
81e29cff62734b6aaf0b05dba0b3ed98fe78842a42Eric Anholt    */
8271cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry   c.nr_regs = (c.vue_map.num_slots + 1)/2;
832995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   c.prog_data.clip_mode = c.key.clip_mode; /* XXX */
859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* For some reason the thread is spawned with only 4 channels
87a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke    * unmasked.
889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
89e374809819d82f2e3e946fe809c4d46061ddc5b5Kenneth Graunke   brw_set_default_mask_control(&c.func, BRW_MASK_DISABLE);
909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Would ideally have the option of producing a program which could
939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * do all three:
949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   switch (key->primitive) {
96a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke   case GL_TRIANGLES:
979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (key->do_unfilled)
989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_emit_unfilled_clip( &c );
999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      else
1009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_emit_tri_clip( &c );
1019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_LINES:
1039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw_emit_line_clip( &c );
1049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_POINTS:
1069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw_emit_point_clip( &c );
1079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   default:
1093d826729dabab53896cdbb1f453c76fab1c7e696Matt Turner      unreachable("not reached");
1109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
112a35b9cb625495e51a42b56cd1d8d2cb019abe243Matt Turner   brw_compact_instructions(&c.func, 0, 0, NULL);
1139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* get the program
1159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   program = brw_get_program(&c.func, &program_size);
1179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
118bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_CLIP)) {
119a76e5dce4fc8d50f8699c108833f24e80167d706Eric Anholt      fprintf(stderr, "clip:\n");
120db1449b7005af190d2ef1f2ad94f96c4b29943dbKenneth Graunke      brw_disassemble(brw, c.func.store, 0, program_size, stderr);
121a76e5dce4fc8d50f8699c108833f24e80167d706Eric Anholt      fprintf(stderr, "\n");
122bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt   }
123562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt
124c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   brw_upload_cache(&brw->cache,
125c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    BRW_CLIP_PROG,
126c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &c.key, sizeof(c.key),
127c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    program, program_size,
128c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &c.prog_data, sizeof(c.prog_data),
129c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &brw->clip.prog_offset, &brw->clip.prog_data);
130774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   ralloc_free(mem_ctx);
1319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
1329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Calculate interpolants for triangle and line rasterization.
1349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */
135dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtstatic void
136dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtbrw_upload_clip_prog(struct brw_context *brw)
1379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
1388c9a54e7bcfc80295ad77097910d35958dfd3644Kenneth Graunke   struct gl_context *ctx = &brw->ctx;
1399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_clip_prog_key key;
1409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   memset(&key, 0, sizeof(key));
1429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Populate the key:
1449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1459f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes
1469f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes   /* BRW_NEW_INTERPOLATION_MAP */
1479f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes   key.interpolation_mode = brw->interpolation_mode;
1489f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes
1499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* BRW_NEW_REDUCED_PRIMITIVE */
150fe0a8cb30dd53bed0d024b01e2c2b60911a3c526Kenneth Graunke   key.primitive = brw->reduced_primitive;
151bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry   /* BRW_NEW_VUE_MAP_GEOM_OUT */
152bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry   key.attrs = brw->vue_map_geom_out.slots_valid;
153f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes
1549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_LIGHT */
155ab12e764ba3f57ad9f0d7252262cfc6e07839928Roland Scheidegger   key.pv_first = (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION);
1569f3d3216cf25d8ffed4d72fbce6feacbc2990e4bEric Anholt   /* _NEW_TRANSFORM (also part of VUE map)*/
157ee0b8e0f063597c4f9dacaa3638ebd8875de151cChris Forbes   if (ctx->Transform.ClipPlanesEnabled)
158ee0b8e0f063597c4f9dacaa3638ebd8875de151cChris Forbes      key.nr_userclip = _mesa_logbase2(ctx->Transform.ClipPlanesEnabled) + 1;
1592995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
16053631be4ebaa4fb13a7f129727c1cdd32fcc6f3dKenneth Graunke   if (brw->gen == 5)
1612995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       key.clip_mode = BRW_CLIPMODE_KERNEL_CLIP;
1622995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao   else
1632995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       key.clip_mode = BRW_CLIPMODE_NORMAL;
1649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_POLYGON */
1669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (key.primitive == GL_TRIANGLES) {
16781d555068408d4343d7627c8bedda5675f09bd21Eric Anholt      if (ctx->Polygon.CullFlag &&
16881d555068408d4343d7627c8bedda5675f09bd21Eric Anholt	  ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 key.clip_mode = BRW_CLIPMODE_REJECT_ALL;
1709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      else {
1719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint fill_front = CLIP_CULL;
1729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint fill_back = CLIP_CULL;
1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint offset_front = 0;
1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint offset_back = 0;
1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
176052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (!ctx->Polygon.CullFlag ||
177052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.CullFaceMode != GL_FRONT) {
178052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.FrontMode) {
179a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke	    case GL_FILL:
180a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke	       fill_front = CLIP_FILL;
1819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       offset_front = 0;
1829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_LINE:
1849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_LINE;
185052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_front = ctx->Polygon.OffsetLine;
1869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_POINT:
1889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_front = CLIP_POINT;
189052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_front = ctx->Polygon.OffsetPoint;
1909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
1919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
1929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
1939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
194052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (!ctx->Polygon.CullFlag ||
195052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.CullFaceMode != GL_BACK) {
196052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.BackMode) {
197a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke	    case GL_FILL:
198a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke	       fill_back = CLIP_FILL;
1999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       offset_back = 0;
2009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_LINE:
2029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_LINE;
203052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_back = ctx->Polygon.OffsetLine;
2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_POINT:
2069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       fill_back = CLIP_POINT;
207052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       offset_back = ctx->Polygon.OffsetPoint;
2089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
2119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
212052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (ctx->Polygon.BackMode != GL_FILL ||
213052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	     ctx->Polygon.FrontMode != GL_FILL) {
2145cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	    key.do_unfilled = 1;
2153ee6a77e97f7d2996f8fffdbb4787a9589189b39Xiang, Haihao
2165cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	    /* Most cases the fixed function units will handle.  Cases where
2175cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	     * one or more polygon faces are unfilled will require help:
2185cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt	     */
2199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    key.clip_mode = BRW_CLIPMODE_CLIP_NON_REJECTED;
2209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    if (offset_back || offset_front) {
2229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       /* _NEW_POLYGON, _NEW_BUFFERS */
223c20f973c4f8fa2c275e445b5da8deefcba874d2eEric Anholt	       key.offset_units = ctx->Polygon.OffsetUnits * ctx->DrawBuffer->_MRD * 2;
224052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       key.offset_factor = ctx->Polygon.OffsetFactor * ctx->DrawBuffer->_MRD;
2259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
227052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    switch (ctx->Polygon.FrontFace) {
2289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_CCW:
2299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_ccw = fill_front;
2309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_cw = fill_back;
2319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_ccw = offset_front;
2329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_cw = offset_back;
233052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       if (ctx->Light.Model.TwoSide &&
234a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke		   key.fill_cw != CLIP_CULL)
2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		  key.copy_bfc_cw = 1;
2369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    case GL_CW:
2389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_cw = fill_front;
2399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.fill_ccw = fill_back;
2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_cw = offset_front;
2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       key.offset_ccw = offset_back;
242052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	       if (ctx->Light.Model.TwoSide &&
243a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke		   key.fill_ccw != CLIP_CULL)
2449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		  key.copy_bfc_ccw = 1;
2459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       break;
2469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    }
2479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
2489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
2499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
2509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
251c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   if (!brw_search_cache(&brw->cache, BRW_CLIP_PROG,
252c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			 &key, sizeof(key),
253c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			 &brw->clip.prog_offset, &brw->clip.prog_data)) {
254125bd4cae51c6deaacd2e90f14931c2052f146abEric Anholt      compile_clip_prog( brw, &key );
255c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   }
2569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
2579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_clip_prog = {
2609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
261a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke      .mesa  = (_NEW_LIGHT |
2629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_TRANSFORM |
263a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke		_NEW_POLYGON |
2649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_BUFFERS),
2659f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes      .brw   = (BRW_NEW_REDUCED_PRIMITIVE |
2669f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes                BRW_NEW_VUE_MAP_GEOM_OUT |
2679f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes                BRW_NEW_INTERPOLATION_MAP)
2689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
269dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholt   .emit = brw_upload_clip_prog
2709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
271