1520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt/*
2520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * Copyright © 2009 Intel Corporation
3520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt *
4520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
5520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * copy of this software and associated documentation files (the "Software"),
6520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * to deal in the Software without restriction, including without limitation
7520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * and/or sell copies of the Software, and to permit persons to whom the
9520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * Software is furnished to do so, subject to the following conditions:
10520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt *
11520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * The above copyright notice and this permission notice (including the next
12520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * paragraph) shall be included in all copies or substantial portions of the
13520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * Software.
14520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt *
15520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * IN THE SOFTWARE.
22520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt *
23520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt * Authors:
24520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt *    Eric Anholt <eric@anholt.net>
25520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt *
26520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt */
27520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt
28520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt#include "brw_context.h"
29520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt#include "brw_state.h"
30520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt#include "brw_defines.h"
31520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt#include "intel_batchbuffer.h"
32520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt
33520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholtstatic void
34520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholtupload_gs_state(struct brw_context *brw)
35520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt{
36520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt   struct intel_context *intel = &brw->intel;
37520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt
38078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt   /* Disable all the constant buffers. */
39078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt   BEGIN_BATCH(5);
40e31defc825ee94f1d1092e277954abad7097c552Kenneth Graunke   OUT_BATCH(_3DSTATE_CONSTANT_GS << 16 | (5 - 2));
41078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt   OUT_BATCH(0);
42078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt   OUT_BATCH(0);
43078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt   OUT_BATCH(0);
44078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt   OUT_BATCH(0);
45078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt   ADVANCE_BATCH();
46078e7b62f69658e40aedea59cf6f005162a29f83Eric Anholt
47d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry   if (brw->gs.prog_active) {
48d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      BEGIN_BATCH(7);
49d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
50d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(brw->gs.prog_offset);
51d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(GEN6_GS_SPF_MODE | GEN6_GS_VECTOR_MASK_ENABLE);
52d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(0); /* no scratch space */
539308f298300beaa757194a0db8ed50924754c011Paul Berry      OUT_BATCH((2 << GEN6_GS_DISPATCH_START_GRF_SHIFT) |
54d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry	        (brw->gs.prog_data->urb_read_length << GEN6_GS_URB_READ_LENGTH_SHIFT));
55d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(((brw->max_gs_threads - 1) << GEN6_GS_MAX_THREADS_SHIFT) |
56d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry	        GEN6_GS_STATISTICS_ENABLE |
57d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry		GEN6_GS_SO_STATISTICS_ENABLE |
58d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry		GEN6_GS_RENDERING_ENABLE);
599308f298300beaa757194a0db8ed50924754c011Paul Berry      OUT_BATCH(GEN6_GS_SVBI_PAYLOAD_ENABLE |
609308f298300beaa757194a0db8ed50924754c011Paul Berry                GEN6_GS_SVBI_POSTINCREMENT_ENABLE |
619308f298300beaa757194a0db8ed50924754c011Paul Berry                (brw->gs.prog_data->svbi_postincrement_value <<
629308f298300beaa757194a0db8ed50924754c011Paul Berry                 GEN6_GS_SVBI_POSTINCREMENT_VALUE_SHIFT) |
639308f298300beaa757194a0db8ed50924754c011Paul Berry                GEN6_GS_ENABLE);
64d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      ADVANCE_BATCH();
65d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry   } else {
66d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      BEGIN_BATCH(7);
67d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
68d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(0); /* prog_bo */
69d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH((0 << GEN6_GS_SAMPLER_COUNT_SHIFT) |
70d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry		(0 << GEN6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
71d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(0); /* scratch space base offset */
72d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH((1 << GEN6_GS_DISPATCH_START_GRF_SHIFT) |
73d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry		(0 << GEN6_GS_URB_READ_LENGTH_SHIFT) |
74d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry		(0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT));
75d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH((0 << GEN6_GS_MAX_THREADS_SHIFT) |
76d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry		GEN6_GS_STATISTICS_ENABLE |
77d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry		GEN6_GS_RENDERING_ENABLE);
78d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      OUT_BATCH(0);
79d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry      ADVANCE_BATCH();
80d4976158c7f32705b48c773c3abd1b22bebe9c16Paul Berry   }
81520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt}
82520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt
83520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholtconst struct brw_tracked_state gen6_gs_state = {
84520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt   .dirty = {
85520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt      .mesa  = _NEW_TRANSFORM,
8674d7ef0961b3aace03aea88944155272ac341b59Kenneth Graunke      .brw   = BRW_NEW_CONTEXT,
87520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt      .cache = CACHE_NEW_GS_PROG
88520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt   },
89520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt   .emit = upload_gs_state,
90520b64ddfb4c2efa742bc2217fef96fdec5eea9bEric Anholt};
91