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
339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_context.h"
359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_state.h"
369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_defines.h"
379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
383149119cad6137fee967054c38c1060a30bfc52dEric Anholtstatic void
39c4aaf85285fc9484e95e9cda89db9cc6923259f4Eric Anholtbrw_upload_gs_unit(struct brw_context *brw)
403149119cad6137fee967054c38c1060a30bfc52dEric Anholt{
411c96e85c9d6b8c636b0636f3320d1057ab5357b3Eric Anholt   struct intel_context *intel = &brw->intel;
42acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt   struct brw_gs_unit_state *gs;
439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
44d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt   gs = brw_state_batch(brw, AUB_TRACE_GS_STATE,
45d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt			sizeof(*gs), 32, &brw->gs.state_offset);
463149119cad6137fee967054c38c1060a30bfc52dEric Anholt
47acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt   memset(gs, 0, sizeof(*gs));
483149119cad6137fee967054c38c1060a30bfc52dEric Anholt
49c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   /* BRW_NEW_PROGRAM_CACHE | CACHE_NEW_GS_PROG */
50acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt   if (brw->gs.prog_active) {
51acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread0.grf_reg_count = (ALIGN(brw->gs.prog_data->total_grf, 16) /
52acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt				   16 - 1);
53c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt
54c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt      gs->thread0.kernel_start_pointer =
55c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt	 brw_program_reloc(brw,
56c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			   brw->gs.state_offset +
57c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			   offsetof(struct brw_gs_unit_state, thread0),
58c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			   brw->gs.prog_offset +
59c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			   (gs->thread0.grf_reg_count << 1)) >> 6;
60acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt
61acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754;
62acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread1.single_program_flow = 1;
63acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt
64acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread3.dispatch_grf_start_reg = 1;
65acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread3.const_urb_entry_read_offset = 0;
66acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread3.const_urb_entry_read_length = 0;
67acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread3.urb_entry_read_offset = 0;
68acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread3.urb_entry_read_length = brw->gs.prog_data->urb_read_length;
69acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt
70acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      /* BRW_NEW_URB_FENCE */
71acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread4.nr_urb_entries = brw->urb.nr_gs_entries;
72acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread4.urb_entry_allocation_size = brw->urb.vsize - 1;
73acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt
74acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      if (brw->urb.nr_gs_entries >= 8)
75acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt	 gs->thread4.max_threads = 1;
76acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      else
77acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt	 gs->thread4.max_threads = 0;
788abffada70fcd62e3c2dcbcdc6d00d258805326bEric Anholt   }
798abffada70fcd62e3c2dcbcdc6d00d258805326bEric Anholt
80acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt   if (intel->gen == 5)
81acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread4.rendering_enable = 1;
823149119cad6137fee967054c38c1060a30bfc52dEric Anholt
83acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_STATS))
84acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      gs->thread4.stats_enable = 1;
8538bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt
86acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt   brw->state.dirty.cache |= CACHE_NEW_GS_UNIT;
879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_gs_unit = {
909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .mesa  = 0,
92acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt      .brw   = (BRW_NEW_BATCH |
93c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		BRW_NEW_PROGRAM_CACHE |
94acb4d5cd96d91320b8e5edb727ff3a268f04587fEric Anholt		BRW_NEW_CURBE_OFFSETS |
959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		BRW_NEW_URB_FENCE),
969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .cache = CACHE_NEW_GS_PROG
979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
98c4aaf85285fc9484e95e9cda89db9cc6923259f4Eric Anholt   .emit = brw_upload_gs_unit,
999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
100