brw_clip.c revision a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307
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. 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: 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); 63a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke 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 73f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes c.has_flat_shading = 74f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes brw_any_flat_varyings(&key->interpolation_mode); 753f6fb5e1dd684434979ffca418184574e5c086f3Chris Forbes c.has_noperspective_shading = 763f6fb5e1dd684434979ffca418184574e5c086f3Chris Forbes brw_any_noperspective_varyings(&key->interpolation_mode); 77f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes 7871cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry /* nr_regs is the number of registers filled by reading data from the VUE. 7971cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry * This program accesses the entire VUE, so nr_regs needs to be the size of 8071cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry * the VUE (measured in pairs, since two slots are stored in each 8171cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry * register). 82e29cff62734b6aaf0b05dba0b3ed98fe78842a42Eric Anholt */ 8371cb82f63ab156599613f7555a62ad52d2e3dbd7Paul Berry c.nr_regs = (c.vue_map.num_slots + 1)/2; 842995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao 859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt c.prog_data.clip_mode = c.key.clip_mode; /* XXX */ 869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* For some reason the thread is spawned with only 4 channels 88a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke * unmasked. 899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw_set_mask_control(&c.func, BRW_MASK_DISABLE); 919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Would ideally have the option of producing a program which could 949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * do all three: 959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (key->primitive) { 97a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke case GL_TRIANGLES: 989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (key->do_unfilled) 999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw_emit_unfilled_clip( &c ); 1009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt else 1019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw_emit_tri_clip( &c ); 1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINES: 1049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw_emit_line_clip( &c ); 1059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_POINTS: 1079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw_emit_point_clip( &c ); 1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 1109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt assert(0); 1119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return; 1129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 114a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke 1159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* get the program 1179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 1189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt program = brw_get_program(&c.func, &program_size); 1199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 120bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt if (unlikely(INTEL_DEBUG & DEBUG_CLIP)) { 121562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt printf("clip:\n"); 122562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt for (i = 0; i < program_size / sizeof(struct brw_instruction); i++) 12336eda76fea02130d30be6a5f0d83f04698da2853Eric Anholt brw_disasm(stdout, &((struct brw_instruction *)program)[i], 12453631be4ebaa4fb13a7f129727c1cdd32fcc6f3dKenneth Graunke brw->gen); 125562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt printf("\n"); 126bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt } 127562e2d114ec0cba879463980522d1d54af9444e6Eric Anholt 128c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt brw_upload_cache(&brw->cache, 129c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt BRW_CLIP_PROG, 130c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt &c.key, sizeof(c.key), 131c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt program, program_size, 132c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt &c.prog_data, sizeof(c.prog_data), 133c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt &brw->clip.prog_offset, &brw->clip.prog_data); 134774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke ralloc_free(mem_ctx); 1359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 1369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Calculate interpolants for triangle and line rasterization. 1389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 139dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtstatic void 140dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtbrw_upload_clip_prog(struct brw_context *brw) 1419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 1428c9a54e7bcfc80295ad77097910d35958dfd3644Kenneth Graunke struct gl_context *ctx = &brw->ctx; 1439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_clip_prog_key key; 1449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt memset(&key, 0, sizeof(key)); 1469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Populate the key: 1489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 1499f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes 1509f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes /* BRW_NEW_INTERPOLATION_MAP */ 1519f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes key.interpolation_mode = brw->interpolation_mode; 1529f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes 1539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* BRW_NEW_REDUCED_PRIMITIVE */ 154fe0a8cb30dd53bed0d024b01e2c2b60911a3c526Kenneth Graunke key.primitive = brw->reduced_primitive; 155bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry /* BRW_NEW_VUE_MAP_GEOM_OUT */ 156bf9bfe838eba116cb63dac9a8998da475e1bd98bPaul Berry key.attrs = brw->vue_map_geom_out.slots_valid; 157f0feb32eaf8d4b35e5c3a47ef90aa876b231ada6Chris Forbes 1589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_LIGHT */ 159ab12e764ba3f57ad9f0d7252262cfc6e07839928Roland Scheidegger key.pv_first = (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION); 1609f3d3216cf25d8ffed4d72fbce6feacbc2990e4bEric Anholt /* _NEW_TRANSFORM (also part of VUE map)*/ 161ee0b8e0f063597c4f9dacaa3638ebd8875de151cChris Forbes if (ctx->Transform.ClipPlanesEnabled) 162ee0b8e0f063597c4f9dacaa3638ebd8875de151cChris Forbes key.nr_userclip = _mesa_logbase2(ctx->Transform.ClipPlanesEnabled) + 1; 1632995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao 16453631be4ebaa4fb13a7f129727c1cdd32fcc6f3dKenneth Graunke if (brw->gen == 5) 1652995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao key.clip_mode = BRW_CLIPMODE_KERNEL_CLIP; 1662995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao else 1672995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao key.clip_mode = BRW_CLIPMODE_NORMAL; 1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_POLYGON */ 1709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (key.primitive == GL_TRIANGLES) { 17181d555068408d4343d7627c8bedda5675f09bd21Eric Anholt if (ctx->Polygon.CullFlag && 17281d555068408d4343d7627c8bedda5675f09bd21Eric Anholt ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) 1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.clip_mode = BRW_CLIPMODE_REJECT_ALL; 1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt else { 1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint fill_front = CLIP_CULL; 1769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint fill_back = CLIP_CULL; 1779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint offset_front = 0; 1789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint offset_back = 0; 1799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 180052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (!ctx->Polygon.CullFlag || 181052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Polygon.CullFaceMode != GL_FRONT) { 182052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt switch (ctx->Polygon.FrontMode) { 183a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke case GL_FILL: 184a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke fill_front = CLIP_FILL; 1859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt offset_front = 0; 1869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINE: 1889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt fill_front = CLIP_LINE; 189052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt offset_front = ctx->Polygon.OffsetLine; 1909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_POINT: 1929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt fill_front = CLIP_POINT; 193052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt offset_front = ctx->Polygon.OffsetPoint; 1949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 198052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (!ctx->Polygon.CullFlag || 199052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Polygon.CullFaceMode != GL_BACK) { 200052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt switch (ctx->Polygon.BackMode) { 201a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke case GL_FILL: 202a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke fill_back = CLIP_FILL; 2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt offset_back = 0; 2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINE: 2069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt fill_back = CLIP_LINE; 207052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt offset_back = ctx->Polygon.OffsetLine; 2089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_POINT: 2109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt fill_back = CLIP_POINT; 211052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt offset_back = ctx->Polygon.OffsetPoint; 2129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 216052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Polygon.BackMode != GL_FILL || 217052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Polygon.FrontMode != GL_FILL) { 2185cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt key.do_unfilled = 1; 2193ee6a77e97f7d2996f8fffdbb4787a9589189b39Xiang, Haihao 2205cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt /* Most cases the fixed function units will handle. Cases where 2215cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt * one or more polygon faces are unfilled will require help: 2225cc56cbad89d8d1b15d0dc67d41732a8883ae7bcEric Anholt */ 2239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.clip_mode = BRW_CLIPMODE_CLIP_NON_REJECTED; 2249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (offset_back || offset_front) { 2269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_POLYGON, _NEW_BUFFERS */ 227c20f973c4f8fa2c275e445b5da8deefcba874d2eEric Anholt key.offset_units = ctx->Polygon.OffsetUnits * ctx->DrawBuffer->_MRD * 2; 228052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt key.offset_factor = ctx->Polygon.OffsetFactor * ctx->DrawBuffer->_MRD; 2299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 231052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt switch (ctx->Polygon.FrontFace) { 2329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_CCW: 2339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.fill_ccw = fill_front; 2349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.fill_cw = fill_back; 2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.offset_ccw = offset_front; 2369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.offset_cw = offset_back; 237052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Light.Model.TwoSide && 238a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke key.fill_cw != CLIP_CULL) 2399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.copy_bfc_cw = 1; 2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_CW: 2429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.fill_cw = fill_front; 2439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.fill_ccw = fill_back; 2449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.offset_cw = offset_front; 2459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.offset_ccw = offset_back; 246052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Light.Model.TwoSide && 247a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke key.fill_ccw != CLIP_CULL) 2489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key.copy_bfc_ccw = 1; 2499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 255c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt if (!brw_search_cache(&brw->cache, BRW_CLIP_PROG, 256c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt &key, sizeof(key), 257c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt &brw->clip.prog_offset, &brw->clip.prog_data)) { 258125bd4cae51c6deaacd2e90f14931c2052f146abEric Anholt compile_clip_prog( brw, &key ); 259c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt } 2609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 2619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_clip_prog = { 2649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .dirty = { 265a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke .mesa = (_NEW_LIGHT | 2669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_TRANSFORM | 267a7bdd4cba8ddcab8dff59ecaaa7efbd436c6c307Kenneth Graunke _NEW_POLYGON | 2689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_BUFFERS), 2699f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes .brw = (BRW_NEW_REDUCED_PRIMITIVE | 2709f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes BRW_NEW_VUE_MAP_GEOM_OUT | 2719f51499d28f80cbbafa4c1489637e1a6a68d9345Chris Forbes BRW_NEW_INTERPOLATION_MAP) 2729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt }, 273dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholt .emit = brw_upload_clip_prog 2749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 275