Merge branch 'master' of ../mesa into vulkan
[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(brw->geometry_program->VerticesIn |
52 ((ALIGN(stage_state->sampler_count, 4)/4) <<
53 GEN6_GS_SAMPLER_COUNT_SHIFT) |
54 ((prog_data->base.binding_table.size_bytes / 4) <<
55 GEN6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT) |
56 (prog_data->base.nr_image_params ?
57 HSW_GS_UAV_ACCESS_ENABLE : 0));
58
59 if (brw->gs.prog_data->base.base.total_scratch) {
60 OUT_RELOC64(stage_state->scratch_bo,
61 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
62 ffs(brw->gs.prog_data->base.base.total_scratch) - 11);
63 } else {
64 OUT_BATCH(0);
65 OUT_BATCH(0);
66 }
67
68 /* DW6 */
69 OUT_BATCH(((brw->gs.prog_data->output_vertex_size_hwords * 2 - 1) <<
70 GEN7_GS_OUTPUT_VERTEX_SIZE_SHIFT) |
71 (brw->gs.prog_data->output_topology <<
72 GEN7_GS_OUTPUT_TOPOLOGY_SHIFT) |
73 (prog_data->urb_read_length <<
74 GEN6_GS_URB_READ_LENGTH_SHIFT) |
75 (0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT) |
76 (prog_data->base.dispatch_grf_start_reg <<
77 GEN6_GS_DISPATCH_START_GRF_SHIFT));
78
79 uint32_t dw7 = (brw->gs.prog_data->control_data_header_size_hwords <<
80 GEN7_GS_CONTROL_DATA_HEADER_SIZE_SHIFT) |
81 SET_FIELD(prog_data->dispatch_mode,
82 GEN7_GS_DISPATCH_MODE) |
83 ((brw->gs.prog_data->invocations - 1) <<
84 GEN7_GS_INSTANCE_CONTROL_SHIFT) |
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->gs.prog_data->static_vertex_count != -1) {
94 dw8 |= GEN8_GS_STATIC_OUTPUT |
95 SET_FIELD(brw->gs.prog_data->static_vertex_count,
96 GEN8_GS_STATIC_VERTEX_COUNT);
97 }
98
99 if (brw->gen < 9)
100 dw7 |= (brw->max_gs_threads / 2 - 1) << HSW_GS_MAX_THREADS_SHIFT;
101 else
102 dw8 |= brw->max_gs_threads - 1;
103
104 /* DW7 */
105 OUT_BATCH(dw7);
106
107 /* DW8 */
108 OUT_BATCH(dw8);
109
110 /* DW9 / _NEW_TRANSFORM */
111 OUT_BATCH((ctx->Transform.ClipPlanesEnabled <<
112 GEN8_GS_USER_CLIP_DISTANCE_SHIFT) |
113 (urb_entry_output_length << GEN8_GS_URB_OUTPUT_LENGTH_SHIFT) |
114 (urb_entry_write_offset <<
115 GEN8_GS_URB_ENTRY_OUTPUT_OFFSET_SHIFT));
116 ADVANCE_BATCH();
117 } else {
118 BEGIN_BATCH(10);
119 OUT_BATCH(_3DSTATE_GS << 16 | (10 - 2));
120 OUT_BATCH(0); /* prog_bo */
121 OUT_BATCH(0);
122 OUT_BATCH(0);
123 OUT_BATCH(0); /* scratch space base offset */
124 OUT_BATCH(0);
125 OUT_BATCH(0);
126 OUT_BATCH(GEN6_GS_STATISTICS_ENABLE);
127 OUT_BATCH(0);
128 OUT_BATCH(0);
129 ADVANCE_BATCH();
130 }
131 }
132
133 const struct brw_tracked_state gen8_gs_state = {
134 .dirty = {
135 .mesa = _NEW_TRANSFORM,
136 .brw = BRW_NEW_BATCH |
137 BRW_NEW_CONTEXT |
138 BRW_NEW_GEOMETRY_PROGRAM |
139 BRW_NEW_GS_PROG_DATA,
140 },
141 .emit = gen8_upload_gs_state,
142 };