cc1ece3ed140d4d021f117d7bc0262484d990b3d
[mesa.git] / src / gallium / drivers / ilo / core / ilo_builder_3d_bottom.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2014 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 #ifndef ILO_BUILDER_3D_BOTTOM_H
29 #define ILO_BUILDER_3D_BOTTOM_H
30
31 #include "genhw/genhw.h"
32 #include "intel_winsys.h"
33
34 #include "ilo_core.h"
35 #include "ilo_dev.h"
36 #include "ilo_format.h"
37 #include "ilo_state_cc.h"
38 #include "ilo_state_raster.h"
39 #include "ilo_state_sbe.h"
40 #include "ilo_state_shader.h"
41 #include "ilo_state_viewport.h"
42 #include "ilo_builder.h"
43 #include "ilo_builder_3d_top.h"
44
45 static inline void
46 gen6_3DSTATE_CLIP(struct ilo_builder *builder,
47 const struct ilo_state_raster *rs)
48 {
49 const uint8_t cmd_len = 4;
50 uint32_t *dw;
51
52 ILO_DEV_ASSERT(builder->dev, 6, 8);
53
54 ilo_builder_batch_pointer(builder, cmd_len, &dw);
55
56 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (cmd_len - 2);
57 /* see raster_set_gen6_3DSTATE_CLIP() */
58 dw[1] = rs->clip[0];
59 dw[2] = rs->clip[1];
60 dw[3] = rs->clip[2];
61 }
62
63 static inline void
64 gen6_3DSTATE_SF(struct ilo_builder *builder,
65 const struct ilo_state_raster *rs,
66 const struct ilo_state_sbe *sbe)
67 {
68 const uint8_t cmd_len = 20;
69 uint32_t *dw;
70
71 ILO_DEV_ASSERT(builder->dev, 6, 6);
72
73 ilo_builder_batch_pointer(builder, cmd_len, &dw);
74
75 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (cmd_len - 2);
76 /* see sbe_set_gen8_3DSTATE_SBE() */
77 dw[1] = sbe->sbe[0];
78
79 /* see raster_set_gen7_3DSTATE_SF() */
80 dw[2] = rs->sf[0];
81 dw[3] = rs->sf[1];
82 dw[4] = rs->sf[2];
83 dw[5] = rs->raster[1];
84 dw[6] = rs->raster[2];
85 dw[7] = rs->raster[3];
86
87 /* see sbe_set_gen8_3DSTATE_SBE_SWIZ() */
88 memcpy(&dw[8], sbe->swiz, sizeof(*dw) * 8);
89
90 dw[16] = sbe->sbe[1];
91 dw[17] = sbe->sbe[2];
92 /* WrapShortest enables */
93 dw[18] = 0;
94 dw[19] = 0;
95 }
96
97 static inline void
98 gen7_3DSTATE_SF(struct ilo_builder *builder,
99 const struct ilo_state_raster *rs)
100 {
101 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 4 : 7;
102 uint32_t *dw;
103
104 ILO_DEV_ASSERT(builder->dev, 7, 8);
105
106 ilo_builder_batch_pointer(builder, cmd_len, &dw);
107
108 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (cmd_len - 2);
109
110 /* see raster_set_gen7_3DSTATE_SF() or raster_set_gen8_3DSTATE_SF() */
111 dw[1] = rs->sf[0];
112 dw[2] = rs->sf[1];
113 dw[3] = rs->sf[2];
114 if (ilo_dev_gen(builder->dev) < ILO_GEN(8)) {
115 dw[4] = rs->raster[1];
116 dw[5] = rs->raster[2];
117 dw[6] = rs->raster[3];
118 }
119 }
120
121 static inline void
122 gen7_3DSTATE_SBE(struct ilo_builder *builder,
123 const struct ilo_state_sbe *sbe)
124 {
125 const uint8_t cmd_len = 14;
126 uint32_t *dw;
127
128 ILO_DEV_ASSERT(builder->dev, 7, 7.5);
129
130 ilo_builder_batch_pointer(builder, cmd_len, &dw);
131
132 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (cmd_len - 2);
133 /* see sbe_set_gen8_3DSTATE_SBE() and sbe_set_gen8_3DSTATE_SBE_SWIZ() */
134 dw[1] = sbe->sbe[0];
135 memcpy(&dw[2], sbe->swiz, sizeof(*dw) * 8);
136 dw[10] = sbe->sbe[1];
137 dw[11] = sbe->sbe[2];
138
139 /* WrapShortest enables */
140 dw[12] = 0;
141 dw[13] = 0;
142 }
143
144 static inline void
145 gen8_3DSTATE_SBE(struct ilo_builder *builder,
146 const struct ilo_state_sbe *sbe)
147 {
148 const uint8_t cmd_len = 4;
149 uint32_t *dw;
150
151 ILO_DEV_ASSERT(builder->dev, 8, 8);
152
153 ilo_builder_batch_pointer(builder, cmd_len, &dw);
154
155 /* see sbe_set_gen8_3DSTATE_SBE() */
156 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (cmd_len - 2);
157 dw[1] = sbe->sbe[0];
158 dw[2] = sbe->sbe[1];
159 dw[3] = sbe->sbe[2];
160 }
161
162 static inline void
163 gen8_3DSTATE_SBE_SWIZ(struct ilo_builder *builder,
164 const struct ilo_state_sbe *sbe)
165 {
166 const uint8_t cmd_len = 11;
167 uint32_t *dw;
168
169 ILO_DEV_ASSERT(builder->dev, 8, 8);
170
171 ilo_builder_batch_pointer(builder, cmd_len, &dw);
172
173 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_SBE_SWIZ) | (cmd_len - 2);
174 /* see sbe_set_gen8_3DSTATE_SBE_SWIZ() */
175 memcpy(&dw[1], sbe->swiz, sizeof(*dw) * 8);
176 /* WrapShortest enables */
177 dw[9] = 0;
178 dw[10] = 0;
179 }
180
181 static inline void
182 gen8_3DSTATE_RASTER(struct ilo_builder *builder,
183 const struct ilo_state_raster *rs)
184 {
185 const uint8_t cmd_len = 5;
186 uint32_t *dw;
187
188 ILO_DEV_ASSERT(builder->dev, 8, 8);
189
190 ilo_builder_batch_pointer(builder, cmd_len, &dw);
191
192 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_RASTER) | (cmd_len - 2);
193 /* see raster_set_gen8_3DSTATE_RASTER() */
194 dw[1] = rs->raster[0];
195 dw[2] = rs->raster[1];
196 dw[3] = rs->raster[2];
197 dw[4] = rs->raster[3];
198 }
199
200 static inline void
201 gen6_3DSTATE_WM(struct ilo_builder *builder,
202 const struct ilo_state_raster *rs,
203 const struct ilo_state_ps *ps,
204 uint32_t kernel_offset)
205 {
206 const uint8_t cmd_len = 9;
207 uint32_t *dw;
208
209 ILO_DEV_ASSERT(builder->dev, 6, 6);
210
211 ilo_builder_batch_pointer(builder, cmd_len, &dw);
212
213 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
214 dw[1] = kernel_offset;
215 /* see raster_set_gen6_3dstate_wm() and ps_set_gen6_3dstate_wm() */
216 dw[2] = ps->ps[0];
217 dw[3] = ps->ps[1];
218 dw[4] = rs->wm[0] | ps->ps[2];
219 dw[5] = rs->wm[1] | ps->ps[3];
220 dw[6] = rs->wm[2] | ps->ps[4];
221 dw[7] = 0; /* kernel 1 */
222 dw[8] = 0; /* kernel 2 */
223 }
224
225 static inline void
226 gen7_3DSTATE_WM(struct ilo_builder *builder,
227 const struct ilo_state_raster *rs,
228 const struct ilo_state_ps *ps)
229 {
230 const uint8_t cmd_len = 3;
231 uint32_t *dw;
232
233 ILO_DEV_ASSERT(builder->dev, 7, 7.5);
234
235 ilo_builder_batch_pointer(builder, cmd_len, &dw);
236
237 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
238 /* see raster_set_gen8_3DSTATE_WM() and ps_set_gen7_3dstate_wm() */
239 dw[1] = rs->wm[0] | ps->ps[0];
240 dw[2] = ps->ps[1];
241 }
242
243 static inline void
244 gen8_3DSTATE_WM(struct ilo_builder *builder,
245 const struct ilo_state_raster *rs)
246 {
247 const uint8_t cmd_len = 2;
248 uint32_t *dw;
249
250 ILO_DEV_ASSERT(builder->dev, 8, 8);
251
252 ilo_builder_batch_pointer(builder, cmd_len, &dw);
253
254 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
255 /* see raster_set_gen8_3DSTATE_WM() */
256 dw[1] = rs->wm[0];
257 }
258
259 static inline void
260 gen8_3DSTATE_WM_DEPTH_STENCIL(struct ilo_builder *builder,
261 const struct ilo_state_cc *cc)
262 {
263 const uint8_t cmd_len = 3;
264 uint32_t *dw;
265
266 ILO_DEV_ASSERT(builder->dev, 8, 8);
267
268 ilo_builder_batch_pointer(builder, cmd_len, &dw);
269
270 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_DEPTH_STENCIL) | (cmd_len - 2);
271 /* see cc_set_gen8_3DSTATE_WM_DEPTH_STENCIL() */
272 dw[1] = cc->ds[0];
273 dw[2] = cc->ds[1];
274 }
275
276 static inline void
277 gen8_3DSTATE_WM_HZ_OP(struct ilo_builder *builder,
278 const struct ilo_state_raster *rs,
279 uint16_t width, uint16_t height)
280 {
281 const uint8_t cmd_len = 5;
282 uint32_t *dw;
283
284 ILO_DEV_ASSERT(builder->dev, 8, 8);
285
286 ilo_builder_batch_pointer(builder, cmd_len, &dw);
287
288 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_HZ_OP) | (cmd_len - 2);
289 /* see raster_set_gen8_3dstate_wm_hz_op() */
290 dw[1] = rs->wm[1];
291 dw[2] = 0;
292 /* exclusive */
293 dw[3] = height << 16 | width;
294 dw[4] = rs->wm[2];
295 }
296
297 static inline void
298 gen8_disable_3DSTATE_WM_HZ_OP(struct ilo_builder *builder)
299 {
300 const uint8_t cmd_len = 5;
301 uint32_t *dw;
302
303 ILO_DEV_ASSERT(builder->dev, 8, 8);
304
305 ilo_builder_batch_pointer(builder, cmd_len, &dw);
306
307 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_HZ_OP) | (cmd_len - 2);
308 dw[1] = 0;
309 dw[2] = 0;
310 dw[3] = 0;
311 dw[4] = 0;
312 }
313
314 static inline void
315 gen8_3DSTATE_WM_CHROMAKEY(struct ilo_builder *builder)
316 {
317 const uint8_t cmd_len = 2;
318 uint32_t *dw;
319
320 ILO_DEV_ASSERT(builder->dev, 8, 8);
321
322 ilo_builder_batch_pointer(builder, cmd_len, &dw);
323
324 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_CHROMAKEY) | (cmd_len - 2);
325 dw[1] = 0;
326 }
327
328 static inline void
329 gen7_3DSTATE_PS(struct ilo_builder *builder,
330 const struct ilo_state_ps *ps,
331 uint32_t kernel_offset)
332 {
333 const uint8_t cmd_len = 8;
334 uint32_t *dw;
335
336 ILO_DEV_ASSERT(builder->dev, 7, 7.5);
337
338 ilo_builder_batch_pointer(builder, cmd_len, &dw);
339
340 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
341 dw[1] = kernel_offset;
342 /* see ps_set_gen7_3DSTATE_PS() */
343 dw[2] = ps->ps[2];
344 dw[3] = ps->ps[3];
345 dw[4] = ps->ps[4];
346 dw[5] = ps->ps[5];
347 dw[6] = 0; /* kernel 1 */
348 dw[7] = 0; /* kernel 2 */
349 }
350
351 static inline void
352 gen8_3DSTATE_PS(struct ilo_builder *builder,
353 const struct ilo_state_ps *ps,
354 uint32_t kernel_offset)
355 {
356 const uint8_t cmd_len = 12;
357 uint32_t *dw;
358
359 ILO_DEV_ASSERT(builder->dev, 8, 8);
360
361 ilo_builder_batch_pointer(builder, cmd_len, &dw);
362
363 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
364 dw[1] = kernel_offset;
365 dw[2] = 0;
366 /* see ps_set_gen8_3DSTATE_PS() */
367 dw[3] = ps->ps[0];
368 dw[4] = ps->ps[1];
369 dw[5] = 0;
370 dw[6] = ps->ps[2];
371 dw[7] = ps->ps[3];
372 dw[8] = 0; /* kernel 1 */
373 dw[9] = 0;
374 dw[10] = 0; /* kernel 2 */
375 dw[11] = 0;
376 }
377
378 static inline void
379 gen8_3DSTATE_PS_EXTRA(struct ilo_builder *builder,
380 const struct ilo_state_ps *ps)
381 {
382 const uint8_t cmd_len = 2;
383 uint32_t *dw;
384
385 ILO_DEV_ASSERT(builder->dev, 8, 8);
386
387 ilo_builder_batch_pointer(builder, cmd_len, &dw);
388
389 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_PS_EXTRA) | (cmd_len - 2);
390 /* see ps_set_gen8_3DSTATE_PS_EXTRA() */
391 dw[1] = ps->ps[4];
392 }
393
394 static inline void
395 gen8_3DSTATE_PS_BLEND(struct ilo_builder *builder,
396 const struct ilo_state_cc *cc)
397 {
398 const uint8_t cmd_len = 2;
399 uint32_t *dw;
400
401 ILO_DEV_ASSERT(builder->dev, 8, 8);
402
403 ilo_builder_batch_pointer(builder, cmd_len, &dw);
404
405 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_PS_BLEND) | (cmd_len - 2);
406 /* see cc_set_gen8_3DSTATE_PS_BLEND() */
407 dw[1] = cc->blend[0];
408 }
409
410 static inline void
411 gen6_3DSTATE_CONSTANT_PS(struct ilo_builder *builder,
412 const uint32_t *bufs, const int *sizes,
413 int num_bufs)
414 {
415 gen6_3dstate_constant(builder, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
416 bufs, sizes, num_bufs);
417 }
418
419 static inline void
420 gen7_3DSTATE_CONSTANT_PS(struct ilo_builder *builder,
421 const uint32_t *bufs, const int *sizes,
422 int num_bufs)
423 {
424 gen7_3dstate_constant(builder, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
425 bufs, sizes, num_bufs);
426 }
427
428 static inline void
429 gen7_3DSTATE_BINDING_TABLE_POINTERS_PS(struct ilo_builder *builder,
430 uint32_t binding_table)
431 {
432 ILO_DEV_ASSERT(builder->dev, 7, 8);
433
434 gen7_3dstate_pointer(builder,
435 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
436 binding_table);
437 }
438
439 static inline void
440 gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(struct ilo_builder *builder,
441 uint32_t sampler_state)
442 {
443 ILO_DEV_ASSERT(builder->dev, 7, 8);
444
445 gen7_3dstate_pointer(builder,
446 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
447 sampler_state);
448 }
449
450 static inline void
451 gen6_3DSTATE_MULTISAMPLE(struct ilo_builder *builder,
452 const struct ilo_state_raster *rs,
453 const struct ilo_state_sample_pattern *pattern,
454 uint8_t sample_count)
455 {
456 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ? 4 : 3;
457 const uint32_t *packed = (const uint32_t *)
458 ilo_state_sample_pattern_get_packed_offsets(pattern,
459 builder->dev, sample_count);
460 uint32_t *dw;
461
462 ILO_DEV_ASSERT(builder->dev, 6, 7.5);
463
464 ilo_builder_batch_pointer(builder, cmd_len, &dw);
465
466 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
467 /* see raster_set_gen8_3DSTATE_MULTISAMPLE() */
468 dw[1] = rs->sample[0];
469
470 /* see sample_pattern_set_gen8_3DSTATE_SAMPLE_PATTERN() */
471 dw[2] = (sample_count >= 4) ? packed[0] : 0;
472 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7))
473 dw[3] = (sample_count >= 8) ? packed[1] : 0;
474 }
475
476 static inline void
477 gen8_3DSTATE_MULTISAMPLE(struct ilo_builder *builder,
478 const struct ilo_state_raster *rs)
479 {
480 const uint8_t cmd_len = 2;
481 uint32_t *dw;
482
483 ILO_DEV_ASSERT(builder->dev, 8, 8);
484
485 ilo_builder_batch_pointer(builder, cmd_len, &dw);
486
487 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
488 /* see raster_set_gen8_3DSTATE_MULTISAMPLE() */
489 dw[1] = rs->sample[0];
490 }
491
492 static inline void
493 gen8_3DSTATE_SAMPLE_PATTERN(struct ilo_builder *builder,
494 const struct ilo_state_sample_pattern *pattern)
495 {
496 const uint8_t cmd_len = 9;
497 uint32_t *dw;
498
499 ILO_DEV_ASSERT(builder->dev, 8, 8);
500
501 ilo_builder_batch_pointer(builder, cmd_len, &dw);
502
503 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_SAMPLE_PATTERN) | (cmd_len - 2);
504 dw[1] = 0;
505 dw[2] = 0;
506 dw[3] = 0;
507 dw[4] = 0;
508 /* see sample_pattern_set_gen8_3DSTATE_SAMPLE_PATTERN() */
509 dw[5] = ((const uint32_t *) pattern->pattern_8x)[1];
510 dw[6] = ((const uint32_t *) pattern->pattern_8x)[0];
511 dw[7] = ((const uint32_t *) pattern->pattern_4x)[0];
512 dw[8] = pattern->pattern_1x[0] << 16 |
513 ((const uint16_t *) pattern->pattern_2x)[0];
514 }
515
516 static inline void
517 gen6_3DSTATE_SAMPLE_MASK(struct ilo_builder *builder,
518 const struct ilo_state_raster *rs)
519 {
520 const uint8_t cmd_len = 2;
521 uint32_t *dw;
522
523 ILO_DEV_ASSERT(builder->dev, 6, 8);
524
525 ilo_builder_batch_pointer(builder, cmd_len, &dw);
526
527 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (cmd_len - 2);
528 /* see raster_set_gen6_3DSTATE_SAMPLE_MASK() */
529 dw[1] = rs->sample[1];
530 }
531
532 static inline void
533 gen6_3DSTATE_DRAWING_RECTANGLE(struct ilo_builder *builder,
534 unsigned x, unsigned y,
535 unsigned width, unsigned height)
536 {
537 const uint8_t cmd_len = 4;
538 unsigned xmax = x + width - 1;
539 unsigned ymax = y + height - 1;
540 unsigned rect_limit;
541 uint32_t *dw;
542
543 ILO_DEV_ASSERT(builder->dev, 6, 8);
544
545 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) {
546 rect_limit = 16383;
547 }
548 else {
549 /*
550 * From the Sandy Bridge PRM, volume 2 part 1, page 230:
551 *
552 * "[DevSNB] Errata: This field (Clipped Drawing Rectangle Y Min)
553 * must be an even number"
554 */
555 assert(y % 2 == 0);
556
557 rect_limit = 8191;
558 }
559
560 if (x > rect_limit) x = rect_limit;
561 if (y > rect_limit) y = rect_limit;
562 if (xmax > rect_limit) xmax = rect_limit;
563 if (ymax > rect_limit) ymax = rect_limit;
564
565 ilo_builder_batch_pointer(builder, cmd_len, &dw);
566
567 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (cmd_len - 2);
568 dw[1] = y << 16 | x;
569 dw[2] = ymax << 16 | xmax;
570 /*
571 * There is no need to set the origin. It is intended to support front
572 * buffer rendering.
573 */
574 dw[3] = 0;
575 }
576
577 static inline void
578 gen6_3DSTATE_POLY_STIPPLE_OFFSET(struct ilo_builder *builder,
579 int x_offset, int y_offset)
580 {
581 const uint8_t cmd_len = 2;
582 uint32_t *dw;
583
584 ILO_DEV_ASSERT(builder->dev, 6, 8);
585
586 assert(x_offset >= 0 && x_offset <= 31);
587 assert(y_offset >= 0 && y_offset <= 31);
588
589 ilo_builder_batch_pointer(builder, cmd_len, &dw);
590
591 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_POLY_STIPPLE_OFFSET) | (cmd_len - 2);
592 dw[1] = x_offset << 8 | y_offset;
593 }
594
595 static inline void
596 gen6_3DSTATE_POLY_STIPPLE_PATTERN(struct ilo_builder *builder,
597 const struct pipe_poly_stipple *pattern)
598 {
599 const uint8_t cmd_len = 33;
600 uint32_t *dw;
601 int i;
602
603 ILO_DEV_ASSERT(builder->dev, 6, 8);
604
605 ilo_builder_batch_pointer(builder, cmd_len, &dw);
606
607 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_POLY_STIPPLE_PATTERN) | (cmd_len - 2);
608 dw++;
609
610 STATIC_ASSERT(Elements(pattern->stipple) == 32);
611 for (i = 0; i < 32; i++)
612 dw[i] = pattern->stipple[i];
613 }
614
615 static inline void
616 gen6_3DSTATE_LINE_STIPPLE(struct ilo_builder *builder,
617 unsigned pattern, unsigned factor)
618 {
619 const uint8_t cmd_len = 3;
620 unsigned inverse;
621 uint32_t *dw;
622
623 ILO_DEV_ASSERT(builder->dev, 6, 8);
624
625 assert((pattern & 0xffff) == pattern);
626 assert(factor >= 1 && factor <= 256);
627
628 ilo_builder_batch_pointer(builder, cmd_len, &dw);
629
630 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_LINE_STIPPLE) | (cmd_len - 2);
631 dw[1] = pattern;
632
633 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) {
634 /* in U1.16 */
635 inverse = 65536 / factor;
636
637 dw[2] = inverse << GEN7_LINE_STIPPLE_DW2_INVERSE_REPEAT_COUNT__SHIFT |
638 factor;
639 }
640 else {
641 /* in U1.13 */
642 inverse = 8192 / factor;
643
644 dw[2] = inverse << GEN6_LINE_STIPPLE_DW2_INVERSE_REPEAT_COUNT__SHIFT |
645 factor;
646 }
647 }
648
649 static inline void
650 gen6_3DSTATE_AA_LINE_PARAMETERS(struct ilo_builder *builder,
651 const struct ilo_state_raster *rs)
652 {
653 const uint8_t cmd_len = 3;
654 uint32_t *dw;
655
656 ILO_DEV_ASSERT(builder->dev, 6, 8);
657
658 ilo_builder_batch_pointer(builder, cmd_len, &dw);
659
660 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_AA_LINE_PARAMETERS) | (cmd_len - 2);
661 /* constant */
662 dw[1] = 0 << GEN6_AA_LINE_DW1_BIAS__SHIFT |
663 0 << GEN6_AA_LINE_DW1_SLOPE__SHIFT;
664 dw[2] = 0 << GEN6_AA_LINE_DW2_CAP_BIAS__SHIFT |
665 0 << GEN6_AA_LINE_DW2_CAP_SLOPE__SHIFT;
666 }
667
668 static inline void
669 gen6_3DSTATE_DEPTH_BUFFER(struct ilo_builder *builder,
670 const struct ilo_state_zs *zs)
671 {
672 const uint32_t cmd = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ?
673 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
674 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
675 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 8 : 7;
676 uint32_t *dw;
677 unsigned pos;
678
679 ILO_DEV_ASSERT(builder->dev, 6, 8);
680
681 pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
682
683 dw[0] = cmd | (cmd_len - 2);
684
685 /*
686 * see zs_set_gen6_3DSTATE_DEPTH_BUFFER() and
687 * zs_set_gen7_3DSTATE_DEPTH_BUFFER()
688 */
689 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
690 dw[1] = zs->depth[0];
691 dw[2] = 0;
692 dw[3] = 0;
693 dw[4] = zs->depth[2];
694 dw[5] = zs->depth[3];
695 dw[6] = 0;
696 dw[7] = zs->depth[4];
697
698 dw[5] |= builder->mocs << GEN8_DEPTH_DW5_MOCS__SHIFT;
699
700 if (zs->depth_bo) {
701 ilo_builder_batch_reloc64(builder, pos + 2, zs->depth_bo,
702 zs->depth[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
703 }
704 } else {
705 dw[1] = zs->depth[0];
706 dw[2] = 0;
707 dw[3] = zs->depth[2];
708 dw[4] = zs->depth[3];
709 dw[5] = 0;
710 dw[6] = zs->depth[4];
711
712 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7))
713 dw[4] |= builder->mocs << GEN7_DEPTH_DW4_MOCS__SHIFT;
714 else
715 dw[6] |= builder->mocs << GEN6_DEPTH_DW6_MOCS__SHIFT;
716
717 if (zs->depth_bo) {
718 ilo_builder_batch_reloc(builder, pos + 2, zs->depth_bo,
719 zs->depth[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
720 }
721 }
722 }
723
724 static inline void
725 gen6_3DSTATE_STENCIL_BUFFER(struct ilo_builder *builder,
726 const struct ilo_state_zs *zs)
727 {
728 const uint32_t cmd = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ?
729 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
730 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
731 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 5 : 3;
732 uint32_t *dw;
733 unsigned pos;
734
735 ILO_DEV_ASSERT(builder->dev, 6, 8);
736
737 pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
738
739 dw[0] = cmd | (cmd_len - 2);
740
741 /* see zs_set_gen6_3DSTATE_STENCIL_BUFFER() */
742 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
743 dw[1] = zs->stencil[0];
744 dw[2] = 0;
745 dw[3] = 0;
746 dw[4] = zs->stencil[2];
747
748 dw[1] |= builder->mocs << GEN8_STENCIL_DW1_MOCS__SHIFT;
749
750 if (zs->stencil_bo) {
751 ilo_builder_batch_reloc64(builder, pos + 2, zs->stencil_bo,
752 zs->stencil[1], (zs->s_readonly) ? 0 : INTEL_RELOC_WRITE);
753 }
754 } else {
755 dw[1] = zs->stencil[0];
756 dw[2] = 0;
757
758 dw[1] |= builder->mocs << GEN6_STENCIL_DW1_MOCS__SHIFT;
759
760 if (zs->stencil_bo) {
761 ilo_builder_batch_reloc(builder, pos + 2, zs->stencil_bo,
762 zs->stencil[1], (zs->s_readonly) ? 0 : INTEL_RELOC_WRITE);
763 }
764 }
765 }
766
767 static inline void
768 gen6_3DSTATE_HIER_DEPTH_BUFFER(struct ilo_builder *builder,
769 const struct ilo_state_zs *zs)
770 {
771 const uint32_t cmd = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ?
772 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
773 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
774 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 5 : 3;
775 uint32_t *dw;
776 unsigned pos;
777
778 ILO_DEV_ASSERT(builder->dev, 6, 8);
779
780 pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
781
782 dw[0] = cmd | (cmd_len - 2);
783
784 /* see zs_set_gen6_3DSTATE_HIER_DEPTH_BUFFER() */
785 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
786 dw[1] = zs->hiz[0];
787 dw[2] = 0;
788 dw[3] = 0;
789 dw[4] = zs->hiz[2];
790
791 dw[1] |= builder->mocs << GEN8_HIZ_DW1_MOCS__SHIFT;
792
793 if (zs->hiz_bo) {
794 ilo_builder_batch_reloc64(builder, pos + 2, zs->hiz_bo,
795 zs->hiz[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
796 }
797 } else {
798 dw[1] = zs->hiz[0];
799 dw[2] = 0;
800
801 dw[1] |= builder->mocs << GEN6_HIZ_DW1_MOCS__SHIFT;
802
803 if (zs->hiz_bo) {
804 ilo_builder_batch_reloc(builder, pos + 2, zs->hiz_bo,
805 zs->hiz[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
806 }
807 }
808 }
809
810 static inline void
811 gen6_3DSTATE_CLEAR_PARAMS(struct ilo_builder *builder,
812 uint32_t clear_val)
813 {
814 const uint8_t cmd_len = 2;
815 uint32_t *dw;
816
817 ILO_DEV_ASSERT(builder->dev, 6, 6);
818
819 ilo_builder_batch_pointer(builder, cmd_len, &dw);
820
821 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
822 GEN6_CLEAR_PARAMS_DW0_VALID |
823 (cmd_len - 2);
824 dw[1] = clear_val;
825 }
826
827 static inline void
828 gen7_3DSTATE_CLEAR_PARAMS(struct ilo_builder *builder,
829 uint32_t clear_val)
830 {
831 const uint8_t cmd_len = 3;
832 uint32_t *dw;
833
834 ILO_DEV_ASSERT(builder->dev, 7, 8);
835
836 ilo_builder_batch_pointer(builder, cmd_len, &dw);
837
838 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) | (cmd_len - 2);
839 dw[1] = clear_val;
840 dw[2] = GEN7_CLEAR_PARAMS_DW2_VALID;
841 }
842
843 static inline void
844 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct ilo_builder *builder,
845 uint32_t clip_viewport,
846 uint32_t sf_viewport,
847 uint32_t cc_viewport)
848 {
849 const uint8_t cmd_len = 4;
850 uint32_t *dw;
851
852 ILO_DEV_ASSERT(builder->dev, 6, 6);
853
854 ilo_builder_batch_pointer(builder, cmd_len, &dw);
855
856 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
857 GEN6_VP_PTR_DW0_CLIP_CHANGED |
858 GEN6_VP_PTR_DW0_SF_CHANGED |
859 GEN6_VP_PTR_DW0_CC_CHANGED |
860 (cmd_len - 2);
861 dw[1] = clip_viewport;
862 dw[2] = sf_viewport;
863 dw[3] = cc_viewport;
864 }
865
866 static inline void
867 gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct ilo_builder *builder,
868 uint32_t scissor_rect)
869 {
870 const uint8_t cmd_len = 2;
871 uint32_t *dw;
872
873 ILO_DEV_ASSERT(builder->dev, 6, 8);
874
875 ilo_builder_batch_pointer(builder, cmd_len, &dw);
876
877 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
878 (cmd_len - 2);
879 dw[1] = scissor_rect;
880 }
881
882 static inline void
883 gen6_3DSTATE_CC_STATE_POINTERS(struct ilo_builder *builder,
884 uint32_t blend_state,
885 uint32_t depth_stencil_state,
886 uint32_t color_calc_state)
887 {
888 const uint8_t cmd_len = 4;
889 uint32_t *dw;
890
891 ILO_DEV_ASSERT(builder->dev, 6, 6);
892
893 ilo_builder_batch_pointer(builder, cmd_len, &dw);
894
895 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) | (cmd_len - 2);
896 dw[1] = blend_state | GEN6_CC_PTR_DW1_BLEND_CHANGED;
897 dw[2] = depth_stencil_state | GEN6_CC_PTR_DW2_ZS_CHANGED;
898 dw[3] = color_calc_state | GEN6_CC_PTR_DW3_CC_CHANGED;
899 }
900
901 static inline void
902 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(struct ilo_builder *builder,
903 uint32_t sf_clip_viewport)
904 {
905 ILO_DEV_ASSERT(builder->dev, 7, 8);
906
907 gen7_3dstate_pointer(builder,
908 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
909 sf_clip_viewport);
910 }
911
912 static inline void
913 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(struct ilo_builder *builder,
914 uint32_t cc_viewport)
915 {
916 ILO_DEV_ASSERT(builder->dev, 7, 8);
917
918 gen7_3dstate_pointer(builder,
919 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
920 cc_viewport);
921 }
922
923 static inline void
924 gen7_3DSTATE_CC_STATE_POINTERS(struct ilo_builder *builder,
925 uint32_t color_calc_state)
926 {
927 ILO_DEV_ASSERT(builder->dev, 7, 8);
928
929 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8))
930 color_calc_state |= 1;
931
932 gen7_3dstate_pointer(builder,
933 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, color_calc_state);
934 }
935
936 static inline void
937 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(struct ilo_builder *builder,
938 uint32_t depth_stencil_state)
939 {
940 ILO_DEV_ASSERT(builder->dev, 7, 8);
941
942 gen7_3dstate_pointer(builder,
943 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
944 depth_stencil_state);
945 }
946
947 static inline void
948 gen7_3DSTATE_BLEND_STATE_POINTERS(struct ilo_builder *builder,
949 uint32_t blend_state)
950 {
951 ILO_DEV_ASSERT(builder->dev, 7, 8);
952
953 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8))
954 blend_state |= 1;
955
956 gen7_3dstate_pointer(builder,
957 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
958 blend_state);
959 }
960
961 static inline uint32_t
962 gen6_CLIP_VIEWPORT(struct ilo_builder *builder,
963 const struct ilo_state_viewport *vp)
964 {
965 const int state_align = 32;
966 const int state_len = 4 * vp->count;
967 uint32_t state_offset, *dw;
968 int i;
969
970 ILO_DEV_ASSERT(builder->dev, 6, 6);
971
972 state_offset = ilo_builder_dynamic_pointer(builder,
973 ILO_BUILDER_ITEM_CLIP_VIEWPORT, state_align, state_len, &dw);
974
975 for (i = 0; i < vp->count; i++) {
976 /* see viewport_matrix_set_gen7_SF_CLIP_VIEWPORT() */
977 dw[0] = vp->sf_clip[i][8];
978 dw[1] = vp->sf_clip[i][9];
979 dw[2] = vp->sf_clip[i][10];
980 dw[3] = vp->sf_clip[i][11];
981
982 dw += 4;
983 }
984
985 return state_offset;
986 }
987
988 static inline uint32_t
989 gen6_SF_VIEWPORT(struct ilo_builder *builder,
990 const struct ilo_state_viewport *vp)
991 {
992 const int state_align = 32;
993 const int state_len = 8 * vp->count;
994 uint32_t state_offset, *dw;
995 int i;
996
997 ILO_DEV_ASSERT(builder->dev, 6, 6);
998
999 state_offset = ilo_builder_dynamic_pointer(builder,
1000 ILO_BUILDER_ITEM_SF_VIEWPORT, state_align, state_len, &dw);
1001
1002 for (i = 0; i < vp->count; i++) {
1003 /* see viewport_matrix_set_gen7_SF_CLIP_VIEWPORT() */
1004 memcpy(dw, vp->sf_clip[i], sizeof(*dw) * 8);
1005
1006 dw += 8;
1007 }
1008
1009 return state_offset;
1010 }
1011
1012 static inline uint32_t
1013 gen7_SF_CLIP_VIEWPORT(struct ilo_builder *builder,
1014 const struct ilo_state_viewport *vp)
1015 {
1016 const int state_align = 64;
1017 const int state_len = 16 * vp->count;
1018
1019 ILO_DEV_ASSERT(builder->dev, 7, 8);
1020
1021 /* see viewport_matrix_set_gen7_SF_CLIP_VIEWPORT() */
1022 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_SF_VIEWPORT,
1023 state_align, state_len, (const uint32_t *) vp->sf_clip);
1024 }
1025
1026 static inline uint32_t
1027 gen6_CC_VIEWPORT(struct ilo_builder *builder,
1028 const struct ilo_state_viewport *vp)
1029 {
1030 const int state_align = 32;
1031 const int state_len = 2 * vp->count;
1032
1033 ILO_DEV_ASSERT(builder->dev, 6, 8);
1034
1035 /* see viewport_matrix_set_gen6_CC_VIEWPORT() */
1036 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_CC_VIEWPORT,
1037 state_align, state_len, (const uint32_t *) vp->cc);
1038 }
1039
1040 static inline uint32_t
1041 gen6_SCISSOR_RECT(struct ilo_builder *builder,
1042 const struct ilo_state_viewport *vp)
1043 {
1044 const int state_align = 32;
1045 const int state_len = 2 * vp->count;
1046
1047 ILO_DEV_ASSERT(builder->dev, 6, 8);
1048
1049 /* see viewport_scissor_set_gen6_SCISSOR_RECT() */
1050 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_SCISSOR_RECT,
1051 state_align, state_len, (const uint32_t *) vp->scissor);
1052 }
1053
1054 static inline uint32_t
1055 gen6_COLOR_CALC_STATE(struct ilo_builder *builder,
1056 const struct ilo_state_cc *cc)
1057 {
1058 const int state_align = 64;
1059 const int state_len = 6;
1060
1061 ILO_DEV_ASSERT(builder->dev, 6, 8);
1062
1063 /* see cc_params_set_gen6_COLOR_CALC_STATE() */
1064 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_COLOR_CALC,
1065 state_align, state_len, cc->cc);
1066 }
1067
1068 static inline uint32_t
1069 gen6_DEPTH_STENCIL_STATE(struct ilo_builder *builder,
1070 const struct ilo_state_cc *cc)
1071 {
1072 const int state_align = 64;
1073 const int state_len = 3;
1074
1075 ILO_DEV_ASSERT(builder->dev, 6, 7.5);
1076
1077 /* see cc_set_gen6_DEPTH_STENCIL_STATE() */
1078 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_DEPTH_STENCIL,
1079 state_align, state_len, cc->ds);
1080 }
1081
1082 static inline uint32_t
1083 gen6_BLEND_STATE(struct ilo_builder *builder,
1084 const struct ilo_state_cc *cc)
1085 {
1086 const int state_align = 64;
1087 const int state_len = 2 * cc->blend_state_count;
1088
1089 ILO_DEV_ASSERT(builder->dev, 6, 7.5);
1090
1091 if (!state_len)
1092 return 0;
1093
1094 /* see cc_set_gen6_BLEND_STATE() */
1095 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_BLEND,
1096 state_align, state_len, cc->blend);
1097 }
1098
1099 static inline uint32_t
1100 gen8_BLEND_STATE(struct ilo_builder *builder,
1101 const struct ilo_state_cc *cc)
1102 {
1103 const int state_align = 64;
1104 const int state_len = 1 + 2 * cc->blend_state_count;
1105
1106 ILO_DEV_ASSERT(builder->dev, 8, 8);
1107
1108 /* see cc_set_gen8_BLEND_STATE() */
1109 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_BLEND,
1110 state_align, state_len, &cc->blend[1]);
1111 }
1112
1113 #endif /* ILO_BUILDER_3D_BOTTOM_H */