i965: Remove unused structures for command packets.
[mesa.git] / src / mesa / drivers / dri / i965 / gen7_wm_state.c
1 /*
2 * Copyright © 2011 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 DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <stdbool.h>
25 #include "brw_context.h"
26 #include "brw_state.h"
27 #include "brw_defines.h"
28 #include "brw_util.h"
29 #include "brw_wm.h"
30 #include "program/prog_parameter.h"
31 #include "program/prog_statevars.h"
32 #include "intel_batchbuffer.h"
33
34 static void
35 gen7_prepare_wm_constants(struct brw_context *brw)
36 {
37 struct intel_context *intel = &brw->intel;
38 struct gl_context *ctx = &intel->ctx;
39 /* BRW_NEW_FRAGMENT_PROGRAM */
40 const struct brw_fragment_program *fp =
41 brw_fragment_program_const(brw->fragment_program);
42
43 /* Updates the ParameterValues[i] pointers for all parameters of the
44 * basic type of PROGRAM_STATE_VAR.
45 */
46 /* XXX: Should this happen somewhere before to get our state flag set? */
47 _mesa_load_state_parameters(ctx, fp->program.Base.Parameters);
48
49 /* CACHE_NEW_WM_PROG */
50 if (brw->wm.prog_data->nr_params != 0) {
51 float *constants;
52 unsigned int i;
53
54 constants = brw_state_batch(brw,
55 brw->wm.prog_data->nr_params *
56 sizeof(float),
57 32, &brw->wm.push_const_offset);
58
59 for (i = 0; i < brw->wm.prog_data->nr_params; i++) {
60 constants[i] = convert_param(brw->wm.prog_data->param_convert[i],
61 *brw->wm.prog_data->param[i]);
62 }
63
64 if (0) {
65 printf("WM constants:\n");
66 for (i = 0; i < brw->wm.prog_data->nr_params; i++) {
67 if ((i & 7) == 0)
68 printf("g%d: ", brw->wm.prog_data->first_curbe_grf + i / 8);
69 printf("%8f ", constants[i]);
70 if ((i & 7) == 7)
71 printf("\n");
72 }
73 if ((i & 7) != 0)
74 printf("\n");
75 printf("\n");
76 }
77 }
78 }
79
80 const struct brw_tracked_state gen7_wm_constants = {
81 .dirty = {
82 .mesa = _NEW_PROGRAM_CONSTANTS,
83 .brw = (BRW_NEW_BATCH | BRW_NEW_FRAGMENT_PROGRAM),
84 .cache = CACHE_NEW_WM_PROG,
85 },
86 .prepare = gen7_prepare_wm_constants,
87 };
88
89 static void
90 upload_wm_state(struct brw_context *brw)
91 {
92 struct intel_context *intel = &brw->intel;
93 struct gl_context *ctx = &intel->ctx;
94 const struct brw_fragment_program *fp =
95 brw_fragment_program_const(brw->fragment_program);
96 bool writes_depth = false;
97 uint32_t dw1;
98
99 dw1 = 0;
100 dw1 |= GEN7_WM_STATISTICS_ENABLE;
101 dw1 |= GEN7_WM_LINE_AA_WIDTH_1_0;
102 dw1 |= GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5;
103
104 /* _NEW_LINE */
105 if (ctx->Line.StippleFlag)
106 dw1 |= GEN7_WM_LINE_STIPPLE_ENABLE;
107
108 /* _NEW_POLYGON */
109 if (ctx->Polygon.StippleFlag)
110 dw1 |= GEN7_WM_POLYGON_STIPPLE_ENABLE;
111
112 /* BRW_NEW_FRAGMENT_PROGRAM */
113 if (fp->program.Base.InputsRead & (1 << FRAG_ATTRIB_WPOS))
114 dw1 |= GEN7_WM_USES_SOURCE_DEPTH | GEN7_WM_USES_SOURCE_W;
115 if (fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
116 writes_depth = true;
117 dw1 |= GEN7_WM_PSCDEPTH_ON;
118 }
119
120 /* _NEW_COLOR */
121 if (fp->program.UsesKill || ctx->Color.AlphaEnabled)
122 dw1 |= GEN7_WM_KILL_ENABLE;
123
124 /* _NEW_BUFFERS */
125 if (brw_color_buffer_write_enabled(brw) || writes_depth ||
126 dw1 & GEN7_WM_KILL_ENABLE) {
127 dw1 |= GEN7_WM_DISPATCH_ENABLE;
128 }
129
130 dw1 |= GEN7_WM_PERSPECTIVE_PIXEL_BARYCENTRIC;
131
132 BEGIN_BATCH(3);
133 OUT_BATCH(_3DSTATE_WM << 16 | (3 - 2));
134 OUT_BATCH(dw1);
135 OUT_BATCH(0);
136 ADVANCE_BATCH();
137 }
138
139 const struct brw_tracked_state gen7_wm_state = {
140 .dirty = {
141 .mesa = (_NEW_LINE | _NEW_POLYGON | _NEW_POLYGONSTIPPLE |
142 _NEW_COLOR | _NEW_BUFFERS),
143 .brw = (BRW_NEW_CURBE_OFFSETS |
144 BRW_NEW_FRAGMENT_PROGRAM |
145 BRW_NEW_NR_WM_SURFACES |
146 BRW_NEW_URB_FENCE |
147 BRW_NEW_BATCH),
148 .cache = 0,
149 },
150 .emit = upload_wm_state,
151 };
152
153 static void
154 upload_ps_state(struct brw_context *brw)
155 {
156 struct intel_context *intel = &brw->intel;
157 uint32_t dw2, dw4, dw5;
158
159 BEGIN_BATCH(2);
160 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS_PS << 16 | (2 - 2));
161 OUT_BATCH(brw->wm.bind_bo_offset);
162 ADVANCE_BATCH();
163
164 /* CACHE_NEW_SAMPLER */
165 BEGIN_BATCH(2);
166 OUT_BATCH(_3DSTATE_SAMPLER_STATE_POINTERS_PS << 16 | (2 - 2));
167 OUT_BATCH(brw->wm.sampler_offset);
168 ADVANCE_BATCH();
169
170 /* CACHE_NEW_WM_PROG */
171 if (brw->wm.prog_data->nr_params == 0) {
172 /* Disable the push constant buffers. */
173 BEGIN_BATCH(7);
174 OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (7 - 2));
175 OUT_BATCH(0);
176 OUT_BATCH(0);
177 OUT_BATCH(0);
178 OUT_BATCH(0);
179 OUT_BATCH(0);
180 OUT_BATCH(0);
181 ADVANCE_BATCH();
182 } else {
183 BEGIN_BATCH(7);
184 OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (7 - 2));
185
186 OUT_BATCH(ALIGN(brw->wm.prog_data->nr_params,
187 brw->wm.prog_data->dispatch_width) / 8);
188 OUT_BATCH(0);
189 /* Pointer to the WM constant buffer. Covered by the set of
190 * state flags from gen7_prepare_wm_constants
191 */
192 OUT_BATCH(brw->wm.push_const_offset);
193 OUT_BATCH(0);
194 OUT_BATCH(0);
195 OUT_BATCH(0);
196 ADVANCE_BATCH();
197 }
198
199 dw2 = dw4 = dw5 = 0;
200
201 dw2 |= (ALIGN(brw->wm.sampler_count, 4) / 4) << GEN7_PS_SAMPLER_COUNT_SHIFT;
202
203 /* BRW_NEW_NR_WM_SURFACES */
204 dw2 |= brw->wm.nr_surfaces << GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT;
205
206 /* OpenGL non-ieee floating point mode */
207 dw2 |= GEN7_PS_FLOATING_POINT_MODE_ALT;
208
209 /* CACHE_NEW_SAMPLER */
210 dw4 |= (brw->wm_max_threads - 1) << GEN7_PS_MAX_THREADS_SHIFT;
211
212 /* CACHE_NEW_WM_PROG */
213 if (brw->wm.prog_data->nr_params > 0)
214 dw4 |= GEN7_PS_PUSH_CONSTANT_ENABLE;
215
216 /* BRW_NEW_FRAGMENT_PROGRAM */
217 if (brw->fragment_program->Base.InputsRead != 0)
218 dw4 |= GEN7_PS_ATTRIBUTE_ENABLE;
219
220 if (brw->wm.prog_data->dispatch_width == 8)
221 dw4 |= GEN7_PS_8_DISPATCH_ENABLE;
222 else
223 dw4 |= GEN7_PS_16_DISPATCH_ENABLE;
224
225 /* BRW_NEW_CURBE_OFFSETS */
226 dw5 |= (brw->wm.prog_data->first_curbe_grf <<
227 GEN7_PS_DISPATCH_START_GRF_SHIFT_0);
228
229 BEGIN_BATCH(8);
230 OUT_BATCH(_3DSTATE_PS << 16 | (8 - 2));
231 OUT_BATCH(brw->wm.prog_offset);
232 OUT_BATCH(dw2);
233 OUT_BATCH(0); /* scratch space base offset */
234 OUT_BATCH(dw4);
235 OUT_BATCH(dw5);
236 OUT_BATCH(0); /* kernel 1 pointer */
237 OUT_BATCH(brw->wm.prog_offset + brw->wm.prog_data->prog_offset_16);
238 ADVANCE_BATCH();
239 }
240
241 const struct brw_tracked_state gen7_ps_state = {
242 .dirty = {
243 .mesa = (_NEW_LINE |
244 _NEW_POLYGON |
245 _NEW_POLYGONSTIPPLE |
246 _NEW_PROGRAM_CONSTANTS),
247 .brw = (BRW_NEW_CURBE_OFFSETS |
248 BRW_NEW_FRAGMENT_PROGRAM |
249 BRW_NEW_NR_WM_SURFACES |
250 BRW_NEW_PS_BINDING_TABLE |
251 BRW_NEW_URB_FENCE |
252 BRW_NEW_BATCH),
253 .cache = (CACHE_NEW_SAMPLER |
254 CACHE_NEW_WM_PROG)
255 },
256 .emit = upload_ps_state,
257 };