brw_clip_state.c revision a56a732c6991f47d63f5ccbb27a45467541c43f8
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
329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_context.h"
339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_state.h"
349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_defines.h"
359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
36114b802e87bca5edbc2c59fc2c5caad3ec90bca6Eric Anholtstatic void
37c4aaf85285fc9484e95e9cda89db9cc6923259f4Eric Anholtbrw_upload_clip_unit(struct brw_context *brw)
38114b802e87bca5edbc2c59fc2c5caad3ec90bca6Eric Anholt{
391c96e85c9d6b8c636b0636f3320d1057ab5357b3Eric Anholt   struct intel_context *intel = &brw->intel;
408ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   struct gl_context *ctx = &intel->ctx;
418ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   struct brw_clip_unit_state *clip;
42114b802e87bca5edbc2c59fc2c5caad3ec90bca6Eric Anholt
43d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt   clip = brw_state_batch(brw, AUB_TRACE_CLIP_STATE,
44d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt			  sizeof(*clip), 32, &brw->clip.state_offset);
458ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   memset(clip, 0, sizeof(*clip));
46114b802e87bca5edbc2c59fc2c5caad3ec90bca6Eric Anholt
47c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   /* BRW_NEW_PROGRAM_CACHE | CACHE_NEW_CLIP_PROG */
488ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread0.grf_reg_count = (ALIGN(brw->clip.prog_data->total_grf, 16) /
498ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt				 16 - 1);
50c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   clip->thread0.kernel_start_pointer =
51c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt      brw_program_reloc(brw,
52c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			brw->clip.state_offset +
53c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			offsetof(struct brw_clip_unit_state, thread0),
54c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			brw->clip.prog_offset +
55c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			(clip->thread0.grf_reg_count << 1)) >> 6;
569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
578ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754;
588ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread1.single_program_flow = 1;
59114b802e87bca5edbc2c59fc2c5caad3ec90bca6Eric Anholt
608ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread3.urb_entry_read_length = brw->clip.prog_data->urb_read_length;
618ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread3.const_urb_entry_read_length =
628ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      brw->clip.prog_data->curb_read_length;
638ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt
648ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   /* BRW_NEW_CURBE_OFFSETS */
658ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread3.const_urb_entry_read_offset = brw->curbe.clip_start * 2;
668ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread3.dispatch_grf_start_reg = 1;
678ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread3.urb_entry_read_offset = 0;
68114b802e87bca5edbc2c59fc2c5caad3ec90bca6Eric Anholt
698ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   /* BRW_NEW_URB_FENCE */
708ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread4.nr_urb_entries = brw->urb.nr_clip_entries;
718ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->thread4.urb_entry_allocation_size = brw->urb.vsize - 1;
7282eb7c235db9939d067c4d64e32df96caef939abEric Anholt   /* If we have enough clip URB entries to run two threads, do so.
7382eb7c235db9939d067c4d64e32df96caef939abEric Anholt    */
748ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   if (brw->urb.nr_clip_entries >= 10) {
7582eb7c235db9939d067c4d64e32df96caef939abEric Anholt      /* Half of the URB entries go to each thread, and it has to be an
7682eb7c235db9939d067c4d64e32df96caef939abEric Anholt       * even number.
7782eb7c235db9939d067c4d64e32df96caef939abEric Anholt       */
788ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      assert(brw->urb.nr_clip_entries % 2 == 0);
792995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao
80cdcef6cbf4dd80047819e9098e34a3b98bd502a4Zhenyu Wang      /* Although up to 16 concurrent Clip threads are allowed on Ironlake,
812995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       * only 2 threads can output VUEs at a time.
822995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao       */
83cdcef6cbf4dd80047819e9098e34a3b98bd502a4Zhenyu Wang      if (intel->gen == 5)
848ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt         clip->thread4.max_threads = 16 - 1;
852995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihao      else
868ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt         clip->thread4.max_threads = 2 - 1;
8782eb7c235db9939d067c4d64e32df96caef939abEric Anholt   } else {
888ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      assert(brw->urb.nr_clip_entries >= 5);
898ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      clip->thread4.max_threads = 1 - 1;
9082eb7c235db9939d067c4d64e32df96caef939abEric Anholt   }
9182eb7c235db9939d067c4d64e32df96caef939abEric Anholt
92bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_STATS))
938ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      clip->thread4.stats_enable = 1;
948e444fb9e2685e3eac42beb848b08e91dc20c88aXiang, Haihao
958ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip5.userclip_enable_flags = 0x7f;
968ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip5.userclip_must_clip = 1;
978ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip5.guard_band_enable = 0;
98a56a732c6991f47d63f5ccbb27a45467541c43f8Kenneth Graunke   /* _NEW_TRANSFORM */
998ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   if (!ctx->Transform.DepthClamp)
1008ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      clip->clip5.viewport_z_clip_enable = 1;
1018ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip5.viewport_xy_clip_enable = 1;
1028ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip5.vertex_position_space = BRW_CLIP_NDCSPACE;
1038ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip5.api_mode = BRW_CLIP_API_OGL;
1048ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip5.clip_mode = brw->clip.prog_data->clip_mode;
1058e444fb9e2685e3eac42beb848b08e91dc20c88aXiang, Haihao
1068ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   if (intel->is_g4x)
1078ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      clip->clip5.negative_w_clip_test = 1;
1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1098ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->clip6.clipper_viewport_state_ptr = 0;
1108ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->viewport_xmin = -1;
1118ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->viewport_xmax = 1;
1128ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->viewport_ymin = -1;
1138ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   clip->viewport_ymax = 1;
1148abffada70fcd62e3c2dcbcdc6d00d258805326bEric Anholt
1158ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt   brw->state.dirty.cache |= CACHE_NEW_CLIP_UNIT;
1169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
1179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_clip_unit = {
1199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
1200310aafd9ea502e07a86b355cfca902102b9117cEric Anholt      .mesa  = _NEW_TRANSFORM,
1218ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt      .brw   = (BRW_NEW_BATCH |
122c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		BRW_NEW_PROGRAM_CACHE |
1238ba0c025a4e0aba97ae596e2121416cf04c0c300Eric Anholt		BRW_NEW_CURBE_OFFSETS |
1249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		BRW_NEW_URB_FENCE),
1259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .cache = CACHE_NEW_CLIP_PROG
1269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
127c4aaf85285fc9484e95e9cda89db9cc6923259f4Eric Anholt   .emit = brw_upload_clip_unit,
1289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
129