ilo: embed ilo_state_vf in ilo_ve_state
[mesa.git] / src / gallium / drivers / ilo / ilo_render_gen8.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "genhw/genhw.h"
29 #include "core/ilo_builder_3d.h"
30 #include "core/ilo_builder_render.h"
31
32 #include "ilo_blitter.h"
33 #include "ilo_shader.h"
34 #include "ilo_state.h"
35 #include "ilo_render_gen.h"
36
37 static void
38 gen8_wa_pre_depth(struct ilo_render *r)
39 {
40 ILO_DEV_ASSERT(r->dev, 8, 8);
41
42 /*
43 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
44 *
45 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
46 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
47 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
48 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
49 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
50 * Depth Flush Bit set, followed by another pipelined depth stall
51 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
52 * guarantee that the pipeline from WM onwards is already flushed
53 * (e.g., via a preceding MI_FLUSH)."
54 */
55 ilo_render_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_STALL);
56 ilo_render_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH);
57 ilo_render_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_STALL);
58 }
59
60 #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
61
62 static void
63 gen8_draw_sf(struct ilo_render *r,
64 const struct ilo_state_vector *vec,
65 struct ilo_render_draw_session *session)
66 {
67 /* 3DSTATE_RASTER */
68 if (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_RASTER)
69 gen8_3DSTATE_RASTER(r->builder, &vec->rasterizer->rs);
70
71 /* 3DSTATE_SBE */
72 if (DIRTY(RASTERIZER) || DIRTY(FS)) {
73 gen8_3DSTATE_SBE(r->builder, vec->fs, (vec->rasterizer) ?
74 vec->rasterizer->state.sprite_coord_mode : 0);
75 }
76
77 /* 3DSTATE_SBE_SWIZ */
78 if (DIRTY(FS))
79 gen8_3DSTATE_SBE_SWIZ(r->builder, vec->fs);
80
81 /* 3DSTATE_SF */
82 if (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_SF)
83 gen7_3DSTATE_SF(r->builder, &vec->rasterizer->rs);
84 }
85
86 static void
87 gen8_draw_wm(struct ilo_render *r,
88 const struct ilo_state_vector *vec,
89 struct ilo_render_draw_session *session)
90 {
91 /* 3DSTATE_WM */
92 if (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_WM)
93 gen8_3DSTATE_WM(r->builder, &vec->rasterizer->rs);
94
95 if (session->cc_delta.dirty & ILO_STATE_CC_3DSTATE_WM_DEPTH_STENCIL)
96 gen8_3DSTATE_WM_DEPTH_STENCIL(r->builder, &vec->blend->cc);
97
98 /* 3DSTATE_WM_HZ_OP and 3DSTATE_WM_CHROMAKEY */
99 if (r->hw_ctx_changed) {
100 gen8_disable_3DSTATE_WM_HZ_OP(r->builder);
101 gen8_3DSTATE_WM_CHROMAKEY(r->builder);
102 }
103
104 /* 3DSTATE_BINDING_TABLE_POINTERS_PS */
105 if (session->binding_table_fs_changed) {
106 gen7_3DSTATE_BINDING_TABLE_POINTERS_PS(r->builder,
107 r->state.wm.BINDING_TABLE_STATE);
108 }
109
110 /* 3DSTATE_SAMPLER_STATE_POINTERS_PS */
111 if (session->sampler_fs_changed) {
112 gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(r->builder,
113 r->state.wm.SAMPLER_STATE);
114 }
115
116 /* 3DSTATE_CONSTANT_PS */
117 if (session->pcb_fs_changed) {
118 gen7_3DSTATE_CONSTANT_PS(r->builder,
119 &r->state.wm.PUSH_CONSTANT_BUFFER,
120 &r->state.wm.PUSH_CONSTANT_BUFFER_size,
121 1);
122 }
123
124 /* 3DSTATE_PS */
125 if (DIRTY(FS) || r->instruction_bo_changed)
126 gen8_3DSTATE_PS(r->builder, vec->fs);
127
128 /* 3DSTATE_PS_EXTRA */
129 if (DIRTY(FS) || DIRTY(BLEND)) {
130 gen8_3DSTATE_PS_EXTRA(r->builder, vec->fs,
131 vec->blend->alpha_may_kill, false);
132 }
133
134 /* 3DSTATE_PS_BLEND */
135 if (session->cc_delta.dirty & ILO_STATE_CC_3DSTATE_PS_BLEND)
136 gen8_3DSTATE_PS_BLEND(r->builder, &vec->blend->cc);
137
138 /* 3DSTATE_SCISSOR_STATE_POINTERS */
139 if (session->scissor_changed) {
140 gen6_3DSTATE_SCISSOR_STATE_POINTERS(r->builder,
141 r->state.SCISSOR_RECT);
142 }
143
144 /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
145 if (DIRTY(FB) || r->batch_bo_changed) {
146 const struct ilo_state_zs *zs;
147 uint32_t clear_params;
148
149 if (vec->fb.state.zsbuf) {
150 const struct ilo_surface_cso *surface =
151 (const struct ilo_surface_cso *) vec->fb.state.zsbuf;
152 const struct ilo_texture_slice *slice =
153 ilo_texture_get_slice(ilo_texture(surface->base.texture),
154 surface->base.u.tex.level, surface->base.u.tex.first_layer);
155
156 assert(!surface->is_rt);
157 zs = &surface->u.zs;
158 clear_params = slice->clear_value;
159 }
160 else {
161 zs = &vec->fb.null_zs;
162 clear_params = 0;
163 }
164
165 gen8_wa_pre_depth(r);
166
167 gen6_3DSTATE_DEPTH_BUFFER(r->builder, zs);
168 gen6_3DSTATE_HIER_DEPTH_BUFFER(r->builder, zs);
169 gen6_3DSTATE_STENCIL_BUFFER(r->builder, zs);
170 gen7_3DSTATE_CLEAR_PARAMS(r->builder, clear_params);
171 }
172 }
173
174 static void
175 gen8_draw_wm_sample_pattern(struct ilo_render *r,
176 const struct ilo_state_vector *vec,
177 struct ilo_render_draw_session *session)
178 {
179 /* 3DSTATE_SAMPLE_PATTERN */
180 if (r->hw_ctx_changed) {
181 gen8_3DSTATE_SAMPLE_PATTERN(r->builder,
182 &r->sample_pattern_1x,
183 &r->sample_pattern_2x,
184 &r->sample_pattern_4x,
185 r->sample_pattern_8x,
186 r->sample_pattern_16x);
187 }
188 }
189
190 static void
191 gen8_draw_wm_multisample(struct ilo_render *r,
192 const struct ilo_state_vector *vec,
193 struct ilo_render_draw_session *session)
194 {
195 /* 3DSTATE_MULTISAMPLE */
196 if (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_MULTISAMPLE)
197 gen8_3DSTATE_MULTISAMPLE(r->builder, &vec->rasterizer->rs);
198
199 /* 3DSTATE_SAMPLE_MASK */
200 if (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_SAMPLE_MASK)
201 gen6_3DSTATE_SAMPLE_MASK(r->builder, &vec->rasterizer->rs);
202 }
203
204 static void
205 gen8_draw_vf(struct ilo_render *r,
206 const struct ilo_state_vector *vec,
207 struct ilo_render_draw_session *session)
208 {
209 int i;
210
211 /* 3DSTATE_INDEX_BUFFER */
212 if (DIRTY(IB) || r->batch_bo_changed)
213 gen8_3DSTATE_INDEX_BUFFER(r->builder, &vec->ib);
214
215 /* 3DSTATE_VF */
216 if (session->primitive_restart_changed) {
217 gen75_3DSTATE_VF(r->builder, vec->draw->primitive_restart,
218 vec->draw->restart_index);
219 }
220
221 /* 3DSTATE_VERTEX_BUFFERS */
222 if (DIRTY(VB) || DIRTY(VE) || r->batch_bo_changed) {
223 gen6_3DSTATE_VERTEX_BUFFERS(r->builder, &vec->vb, vec->ve->vb_mapping,
224 vec->ve->instance_divisors, vec->ve->vb_count);
225 }
226
227 /* 3DSTATE_VERTEX_ELEMENTS */
228 if (session->vf_delta.dirty & ILO_STATE_VF_3DSTATE_VERTEX_ELEMENTS)
229 gen6_3DSTATE_VERTEX_ELEMENTS(r->builder, &vec->ve->vf);
230
231 gen8_3DSTATE_VF_TOPOLOGY(r->builder,
232 gen6_3d_translate_pipe_prim(vec->draw->mode));
233
234 for (i = 0; i < vec->ve->vb_count; i++) {
235 gen8_3DSTATE_VF_INSTANCING(r->builder, i,
236 vec->ve->instance_divisors[i]);
237 }
238
239 if (session->vf_delta.dirty & ILO_STATE_VF_3DSTATE_VF_SGVS)
240 gen8_3DSTATE_VF_SGVS(r->builder, &vec->ve->vf);
241 }
242
243 void
244 ilo_render_emit_draw_commands_gen8(struct ilo_render *render,
245 const struct ilo_state_vector *vec,
246 struct ilo_render_draw_session *session)
247 {
248 ILO_DEV_ASSERT(render->dev, 8, 8);
249
250 /*
251 * We try to keep the order of the commands match, as closely as possible,
252 * that of the classic i965 driver. It allows us to compare the command
253 * streams easily.
254 */
255 gen6_draw_common_select(render, vec, session);
256 gen6_draw_common_sip(render, vec, session);
257 gen6_draw_vf_statistics(render, vec, session);
258 gen8_draw_wm_sample_pattern(render, vec, session);
259 gen6_draw_common_base_address(render, vec, session);
260 gen7_draw_common_pointers_1(render, vec, session);
261 gen7_draw_common_pcb_alloc(render, vec, session);
262 gen7_draw_common_urb(render, vec, session);
263 gen7_draw_common_pointers_2(render, vec, session);
264 gen8_draw_wm_multisample(render, vec, session);
265 gen7_draw_gs(render, vec, session);
266 gen7_draw_hs(render, vec, session);
267 gen7_draw_te(render, vec, session);
268 gen7_draw_ds(render, vec, session);
269 gen7_draw_vs(render, vec, session);
270 gen7_draw_sol(render, vec, session);
271 gen6_draw_clip(render, vec, session);
272 gen8_draw_sf(render, vec, session);
273 gen8_draw_wm(render, vec, session);
274 gen6_draw_wm_raster(render, vec, session);
275 gen6_draw_sf_rect(render, vec, session);
276 gen8_draw_vf(render, vec, session);
277
278 ilo_render_3dprimitive(render, vec->draw, &vec->ib);
279 }
280
281 int
282 ilo_render_get_draw_commands_len_gen8(const struct ilo_render *render,
283 const struct ilo_state_vector *vec)
284 {
285 static int len;
286
287 ILO_DEV_ASSERT(render->dev, 8, 8);
288
289 if (!len) {
290 len += GEN7_3DSTATE_URB_ANY__SIZE * 4;
291 len += GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_ANY__SIZE * 5;
292 len += GEN6_3DSTATE_CONSTANT_ANY__SIZE * 5;
293 len += GEN7_3DSTATE_POINTERS_ANY__SIZE * (5 + 5 + 4);
294 len += GEN7_3DSTATE_SO_BUFFER__SIZE * 4;
295 len += GEN6_PIPE_CONTROL__SIZE * 5;
296
297 len +=
298 GEN6_STATE_BASE_ADDRESS__SIZE +
299 GEN6_STATE_SIP__SIZE +
300 GEN6_3DSTATE_VF_STATISTICS__SIZE +
301 GEN6_PIPELINE_SELECT__SIZE +
302 GEN6_3DSTATE_CLEAR_PARAMS__SIZE +
303 GEN6_3DSTATE_DEPTH_BUFFER__SIZE +
304 GEN6_3DSTATE_STENCIL_BUFFER__SIZE +
305 GEN6_3DSTATE_HIER_DEPTH_BUFFER__SIZE +
306 GEN6_3DSTATE_VERTEX_BUFFERS__SIZE +
307 GEN6_3DSTATE_VERTEX_ELEMENTS__SIZE +
308 GEN6_3DSTATE_INDEX_BUFFER__SIZE +
309 GEN75_3DSTATE_VF__SIZE +
310 GEN6_3DSTATE_VS__SIZE +
311 GEN6_3DSTATE_GS__SIZE +
312 GEN6_3DSTATE_CLIP__SIZE +
313 GEN6_3DSTATE_SF__SIZE +
314 GEN6_3DSTATE_WM__SIZE +
315 GEN6_3DSTATE_SAMPLE_MASK__SIZE +
316 GEN7_3DSTATE_HS__SIZE +
317 GEN7_3DSTATE_TE__SIZE +
318 GEN7_3DSTATE_DS__SIZE +
319 GEN7_3DSTATE_STREAMOUT__SIZE +
320 GEN7_3DSTATE_SBE__SIZE +
321 GEN7_3DSTATE_PS__SIZE +
322 GEN6_3DSTATE_DRAWING_RECTANGLE__SIZE +
323 GEN6_3DSTATE_POLY_STIPPLE_OFFSET__SIZE +
324 GEN6_3DSTATE_POLY_STIPPLE_PATTERN__SIZE +
325 GEN6_3DSTATE_LINE_STIPPLE__SIZE +
326 GEN6_3DSTATE_AA_LINE_PARAMETERS__SIZE +
327 GEN6_3DSTATE_MULTISAMPLE__SIZE +
328 GEN7_3DSTATE_SO_DECL_LIST__SIZE +
329 GEN6_3DPRIMITIVE__SIZE;
330
331 len +=
332 GEN8_3DSTATE_VF_INSTANCING__SIZE * 33 +
333 GEN8_3DSTATE_VF_SGVS__SIZE +
334 GEN8_3DSTATE_VF_TOPOLOGY__SIZE +
335 GEN8_3DSTATE_SBE_SWIZ__SIZE +
336 GEN8_3DSTATE_RASTER__SIZE +
337 GEN8_3DSTATE_WM_CHROMAKEY__SIZE +
338 GEN8_3DSTATE_WM_DEPTH_STENCIL__SIZE +
339 GEN8_3DSTATE_WM_HZ_OP__SIZE +
340 GEN8_3DSTATE_PS_EXTRA__SIZE +
341 GEN8_3DSTATE_PS_BLEND__SIZE +
342 GEN8_3DSTATE_SAMPLE_PATTERN__SIZE;
343 }
344
345 return len;
346 }
347
348 int
349 ilo_render_get_rectlist_commands_len_gen8(const struct ilo_render *render,
350 const struct ilo_blitter *blitter)
351 {
352 ILO_DEV_ASSERT(render->dev, 8, 8);
353
354 return 96;
355 }
356
357 void
358 ilo_render_emit_rectlist_commands_gen8(struct ilo_render *r,
359 const struct ilo_blitter *blitter,
360 const struct ilo_render_rectlist_session *session)
361 {
362 ILO_DEV_ASSERT(r->dev, 8, 8);
363
364 gen8_wa_pre_depth(r);
365
366 if (blitter->uses & (ILO_BLITTER_USE_FB_DEPTH |
367 ILO_BLITTER_USE_FB_STENCIL))
368 gen6_3DSTATE_DEPTH_BUFFER(r->builder, &blitter->fb.dst.u.zs);
369
370 if (blitter->uses & ILO_BLITTER_USE_FB_DEPTH) {
371 gen6_3DSTATE_HIER_DEPTH_BUFFER(r->builder,
372 &blitter->fb.dst.u.zs);
373 }
374
375 if (blitter->uses & ILO_BLITTER_USE_FB_STENCIL) {
376 gen6_3DSTATE_STENCIL_BUFFER(r->builder,
377 &blitter->fb.dst.u.zs);
378 }
379
380 gen7_3DSTATE_CLEAR_PARAMS(r->builder,
381 blitter->depth_clear_value);
382
383 gen6_3DSTATE_DRAWING_RECTANGLE(r->builder, 0, 0,
384 blitter->fb.width, blitter->fb.height);
385
386 gen8_3DSTATE_WM_HZ_OP(r->builder, &blitter->fb.rs,
387 blitter->fb.width, blitter->fb.height);
388
389 ilo_render_pipe_control(r, GEN6_PIPE_CONTROL_WRITE_IMM);
390
391 gen8_disable_3DSTATE_WM_HZ_OP(r->builder);
392 }