i965: Rename brw_vec4_prog_data/key to brw_bue_prog_data/key
[mesa.git] / src / mesa / drivers / dri / i965 / gen8_gs_state.c
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "brw_context.h"
25 #include "brw_state.h"
26 #include "brw_defines.h"
27 #include "intel_batchbuffer.h"
28
29 static void
30 gen8_upload_gs_state(struct brw_context *brw)
31 {
32 struct gl_context *ctx = &brw->ctx;
33 const struct brw_stage_state *stage_state = &brw->gs.base;
34 /* BRW_NEW_GEOMETRY_PROGRAM */
35 bool active = brw->geometry_program;
36 /* BRW_NEW_GS_PROG_DATA */
37 const struct brw_vue_prog_data *prog_data = &brw->gs.prog_data->base;
38
39 if (active) {
40 int urb_entry_write_offset = 1;
41 uint32_t urb_entry_output_length =
42 ((prog_data->vue_map.num_slots + 1) / 2 - urb_entry_write_offset);
43
44 if (urb_entry_output_length == 0)
45 urb_entry_output_length = 1;
46
47 BEGIN_BATCH(10);
48 OUT_BATCH(_3DSTATE_GS << 16 | (10 - 2));
49 OUT_BATCH(stage_state->prog_offset);
50 OUT_BATCH(0);
51 OUT_BATCH(GEN6_GS_VECTOR_MASK_ENABLE |
52 brw->geometry_program->VerticesIn |
53 ((ALIGN(stage_state->sampler_count, 4)/4) <<
54 GEN6_GS_SAMPLER_COUNT_SHIFT) |
55 ((prog_data->base.binding_table.size_bytes / 4) <<
56 GEN6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
57
58 if (brw->gs.prog_data->base.base.total_scratch) {
59 OUT_RELOC64(stage_state->scratch_bo,
60 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
61 ffs(brw->gs.prog_data->base.base.total_scratch) - 11);
62 WARN_ONCE(true,
63 "May need to implement a temporary workaround: GS Number of "
64 "URB Entries must be less than or equal to the GS Maximum "
65 "Number of Threads.\n");
66 } else {
67 OUT_BATCH(0);
68 OUT_BATCH(0);
69 }
70
71 /* DW6 */
72 OUT_BATCH(((brw->gs.prog_data->output_vertex_size_hwords * 2 - 1) <<
73 GEN7_GS_OUTPUT_VERTEX_SIZE_SHIFT) |
74 (brw->gs.prog_data->output_topology <<
75 GEN7_GS_OUTPUT_TOPOLOGY_SHIFT) |
76 (prog_data->urb_read_length <<
77 GEN6_GS_URB_READ_LENGTH_SHIFT) |
78 (0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT) |
79 (prog_data->base.dispatch_grf_start_reg <<
80 GEN6_GS_DISPATCH_START_GRF_SHIFT));
81
82 uint32_t dw7 = (brw->gs.prog_data->control_data_header_size_hwords <<
83 GEN7_GS_CONTROL_DATA_HEADER_SIZE_SHIFT) |
84 brw->gs.prog_data->dispatch_mode |
85 GEN6_GS_STATISTICS_ENABLE |
86 (brw->gs.prog_data->include_primitive_id ?
87 GEN7_GS_INCLUDE_PRIMITIVE_ID : 0) |
88 GEN7_GS_REORDER_TRAILING |
89 GEN7_GS_ENABLE;
90 uint32_t dw8 = brw->gs.prog_data->control_data_format <<
91 HSW_GS_CONTROL_DATA_FORMAT_SHIFT;
92
93 if (brw->gen < 9)
94 dw7 |= (brw->max_gs_threads / 2 - 1) << HSW_GS_MAX_THREADS_SHIFT;
95 else
96 dw8 |= brw->max_gs_threads - 1;
97
98 /* DW7 */
99 OUT_BATCH(dw7);
100
101 /* DW8 */
102 OUT_BATCH(dw8);
103
104 /* DW9 / _NEW_TRANSFORM */
105 OUT_BATCH((ctx->Transform.ClipPlanesEnabled <<
106 GEN8_GS_USER_CLIP_DISTANCE_SHIFT) |
107 (urb_entry_output_length << GEN8_GS_URB_OUTPUT_LENGTH_SHIFT) |
108 (urb_entry_write_offset <<
109 GEN8_GS_URB_ENTRY_OUTPUT_OFFSET_SHIFT));
110 ADVANCE_BATCH();
111 } else {
112 BEGIN_BATCH(10);
113 OUT_BATCH(_3DSTATE_GS << 16 | (10 - 2));
114 OUT_BATCH(0); /* prog_bo */
115 OUT_BATCH(0);
116 OUT_BATCH(0);
117 OUT_BATCH(0); /* scratch space base offset */
118 OUT_BATCH(0);
119 OUT_BATCH(0);
120 OUT_BATCH(GEN6_GS_STATISTICS_ENABLE);
121 OUT_BATCH(0);
122 OUT_BATCH(0);
123 ADVANCE_BATCH();
124 }
125 }
126
127 const struct brw_tracked_state gen8_gs_state = {
128 .dirty = {
129 .mesa = _NEW_TRANSFORM,
130 .brw = BRW_NEW_BATCH |
131 BRW_NEW_CONTEXT |
132 BRW_NEW_GEOMETRY_PROGRAM |
133 BRW_NEW_GS_PROG_DATA,
134 },
135 .emit = gen8_upload_gs_state,
136 };