ilo: embed ilo_state_cc in ilo_blend_state
[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 "../ilo_shader.h"
33 #include "intel_winsys.h"
34
35 #include "ilo_core.h"
36 #include "ilo_dev.h"
37 #include "ilo_format.h"
38 #include "ilo_state_cc.h"
39 #include "ilo_state_raster.h"
40 #include "ilo_state_viewport.h"
41 #include "ilo_builder.h"
42 #include "ilo_builder_3d_top.h"
43
44 static inline void
45 gen6_3DSTATE_CLIP(struct ilo_builder *builder,
46 const struct ilo_state_raster *rs)
47 {
48 const uint8_t cmd_len = 4;
49 uint32_t *dw;
50
51 ILO_DEV_ASSERT(builder->dev, 6, 8);
52
53 ilo_builder_batch_pointer(builder, cmd_len, &dw);
54
55 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (cmd_len - 2);
56 /* see raster_set_gen6_3DSTATE_CLIP() */
57 dw[1] = rs->clip[0];
58 dw[2] = rs->clip[1];
59 dw[3] = rs->clip[2];
60 }
61
62 static inline void
63 gen8_internal_3dstate_sbe(struct ilo_builder *builder,
64 uint8_t cmd_len, uint32_t *dw,
65 const struct ilo_shader_state *fs,
66 int sprite_coord_mode)
67 {
68 const struct ilo_kernel_routing *routing;
69 int vue_offset, vue_len, out_count;
70
71 ILO_DEV_ASSERT(builder->dev, 6, 8);
72
73 assert(cmd_len == 4);
74
75 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (cmd_len - 2);
76
77 if (!fs) {
78 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
79 dw[2] = 0;
80 dw[3] = 0;
81 return;
82 }
83
84 routing = ilo_shader_get_kernel_routing(fs);
85
86 vue_offset = routing->source_skip;
87 assert(vue_offset % 2 == 0);
88 vue_offset /= 2;
89
90 vue_len = (routing->source_len + 1) / 2;
91 if (!vue_len)
92 vue_len = 1;
93
94 out_count = ilo_shader_get_kernel_param(fs, ILO_KERNEL_INPUT_COUNT);
95 assert(out_count <= 32);
96
97 dw[1] = out_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
98 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
99
100 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
101 dw[1] |= GEN8_SBE_DW1_USE_URB_READ_LEN |
102 GEN8_SBE_DW1_USE_URB_READ_OFFSET |
103 vue_offset << GEN8_SBE_DW1_URB_READ_OFFSET__SHIFT;
104 } else {
105 dw[1] |= vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
106 }
107
108 if (routing->swizzle_enable)
109 dw[1] |= GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE;
110
111 switch (sprite_coord_mode) {
112 case PIPE_SPRITE_COORD_UPPER_LEFT:
113 dw[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT;
114 break;
115 case PIPE_SPRITE_COORD_LOWER_LEFT:
116 dw[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_LOWERLEFT;
117 break;
118 }
119
120 /*
121 * From the Ivy Bridge PRM, volume 2 part 1, page 268:
122 *
123 * "This field (Point Sprite Texture Coordinate Enable) must be
124 * programmed to 0 when non-point primitives are rendered."
125 *
126 * TODO We do not check that yet.
127 */
128 dw[2] = routing->point_sprite_enable;
129
130 dw[3] = routing->const_interp_enable;
131 }
132
133 static inline void
134 gen8_internal_3dstate_sbe_swiz(struct ilo_builder *builder,
135 uint8_t cmd_len, uint32_t *dw,
136 const struct ilo_shader_state *fs)
137 {
138 const struct ilo_kernel_routing *routing;
139
140 ILO_DEV_ASSERT(builder->dev, 6, 8);
141
142 assert(cmd_len == 11);
143
144 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_SBE_SWIZ) | (cmd_len - 2);
145
146 if (!fs) {
147 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
148 return;
149 }
150
151 routing = ilo_shader_get_kernel_routing(fs);
152
153 STATIC_ASSERT(sizeof(routing->swizzles) >= sizeof(*dw) * 8);
154 memcpy(&dw[1], routing->swizzles, sizeof(*dw) * 8);
155
156 /* WrapShortest enables */
157 dw[9] = 0;
158 dw[10] = 0;
159 }
160
161 static inline void
162 gen6_3DSTATE_SF(struct ilo_builder *builder,
163 const struct ilo_state_raster *rs,
164 unsigned sprite_coord_mode,
165 const struct ilo_shader_state *fs)
166 {
167 const uint8_t cmd_len = 20;
168 uint32_t gen8_3dstate_sbe[4], gen8_3dstate_sbe_swiz[11];
169 uint32_t *dw;
170
171 ILO_DEV_ASSERT(builder->dev, 6, 6);
172
173 gen8_internal_3dstate_sbe(builder, Elements(gen8_3dstate_sbe),
174 gen8_3dstate_sbe, fs, sprite_coord_mode);
175 gen8_internal_3dstate_sbe_swiz(builder, Elements(gen8_3dstate_sbe_swiz),
176 gen8_3dstate_sbe_swiz, fs);
177
178 ilo_builder_batch_pointer(builder, cmd_len, &dw);
179
180 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (cmd_len - 2);
181 dw[1] = gen8_3dstate_sbe[1];
182
183 /* see raster_set_gen7_3DSTATE_SF() */
184 dw[2] = rs->sf[0];
185 dw[3] = rs->sf[1];
186 dw[4] = rs->sf[2];
187 dw[5] = rs->raster[1];
188 dw[6] = rs->raster[2];
189 dw[7] = rs->raster[3];
190
191 memcpy(&dw[8], &gen8_3dstate_sbe_swiz[1], sizeof(*dw) * 8);
192 dw[16] = gen8_3dstate_sbe[2];
193 dw[17] = gen8_3dstate_sbe[3];
194 dw[18] = gen8_3dstate_sbe_swiz[9];
195 dw[19] = gen8_3dstate_sbe_swiz[10];
196 }
197
198 static inline void
199 gen7_3DSTATE_SF(struct ilo_builder *builder,
200 const struct ilo_state_raster *rs)
201 {
202 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 4 : 7;
203 uint32_t *dw;
204
205 ILO_DEV_ASSERT(builder->dev, 7, 8);
206
207 ilo_builder_batch_pointer(builder, cmd_len, &dw);
208
209 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (cmd_len - 2);
210
211 /* see raster_set_gen7_3DSTATE_SF() or raster_set_gen8_3DSTATE_SF() */
212 dw[1] = rs->sf[0];
213 dw[2] = rs->sf[1];
214 dw[3] = rs->sf[2];
215 if (ilo_dev_gen(builder->dev) < ILO_GEN(8)) {
216 dw[4] = rs->raster[1];
217 dw[5] = rs->raster[2];
218 dw[6] = rs->raster[3];
219 }
220 }
221
222 static inline void
223 gen7_3DSTATE_SBE(struct ilo_builder *builder,
224 const struct ilo_shader_state *fs,
225 int sprite_coord_mode)
226 {
227 const uint8_t cmd_len = 14;
228 uint32_t gen8_3dstate_sbe[4], gen8_3dstate_sbe_swiz[11];
229 uint32_t *dw;
230
231 ILO_DEV_ASSERT(builder->dev, 7, 7.5);
232
233 gen8_internal_3dstate_sbe(builder, Elements(gen8_3dstate_sbe),
234 gen8_3dstate_sbe, fs, sprite_coord_mode);
235 gen8_internal_3dstate_sbe_swiz(builder, Elements(gen8_3dstate_sbe_swiz),
236 gen8_3dstate_sbe_swiz, fs);
237
238 ilo_builder_batch_pointer(builder, cmd_len, &dw);
239
240 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (cmd_len - 2);
241 dw[1] = gen8_3dstate_sbe[1];
242 memcpy(&dw[2], &gen8_3dstate_sbe_swiz[1], sizeof(*dw) * 8);
243 dw[10] = gen8_3dstate_sbe[2];
244 dw[11] = gen8_3dstate_sbe[3];
245 dw[12] = gen8_3dstate_sbe_swiz[9];
246 dw[13] = gen8_3dstate_sbe_swiz[10];
247 }
248
249 static inline void
250 gen8_3DSTATE_SBE(struct ilo_builder *builder,
251 const struct ilo_shader_state *fs,
252 int sprite_coord_mode)
253 {
254 const uint8_t cmd_len = 4;
255 uint32_t *dw;
256
257 ILO_DEV_ASSERT(builder->dev, 8, 8);
258
259 ilo_builder_batch_pointer(builder, cmd_len, &dw);
260
261 gen8_internal_3dstate_sbe(builder, cmd_len, dw, fs, sprite_coord_mode);
262 }
263
264 static inline void
265 gen8_3DSTATE_SBE_SWIZ(struct ilo_builder *builder,
266 const struct ilo_shader_state *fs)
267 {
268 const uint8_t cmd_len = 11;
269 uint32_t *dw;
270
271 ILO_DEV_ASSERT(builder->dev, 8, 8);
272
273 ilo_builder_batch_pointer(builder, cmd_len, &dw);
274
275 gen8_internal_3dstate_sbe_swiz(builder, cmd_len, dw, fs);
276 }
277
278 static inline void
279 gen8_3DSTATE_RASTER(struct ilo_builder *builder,
280 const struct ilo_state_raster *rs)
281 {
282 const uint8_t cmd_len = 5;
283 uint32_t *dw;
284
285 ILO_DEV_ASSERT(builder->dev, 8, 8);
286
287 ilo_builder_batch_pointer(builder, cmd_len, &dw);
288
289 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_RASTER) | (cmd_len - 2);
290 /* see raster_set_gen8_3DSTATE_RASTER() */
291 dw[1] = rs->raster[0];
292 dw[2] = rs->raster[1];
293 dw[3] = rs->raster[2];
294 dw[4] = rs->raster[3];
295 }
296
297 static inline void
298 gen6_3DSTATE_WM(struct ilo_builder *builder,
299 const struct ilo_state_raster *rs,
300 const struct ilo_shader_state *fs,
301 bool dual_blend, bool cc_may_kill)
302 {
303 const uint8_t cmd_len = 9;
304 const bool multisample = false;
305 const int num_samples = 1;
306 uint32_t dw2, dw4, dw5, dw6, *dw;
307
308 ILO_DEV_ASSERT(builder->dev, 6, 6);
309
310 dw2 = 0;
311 /* see raster_set_gen6_3dstate_wm() */
312 dw4 = rs->raster[0];
313 dw5 = rs->raster[1];
314 dw6 = rs->raster[2];
315
316 if (fs) {
317 const struct ilo_shader_cso *cso;
318
319 cso = ilo_shader_get_kernel_cso(fs);
320 /* see fs_init_cso_gen6() */
321 dw2 |= cso->payload[0];
322 dw4 |= cso->payload[1];
323 dw5 |= cso->payload[2];
324 dw6 |= cso->payload[3];
325 } else {
326 const int max_threads = (builder->dev->gt == 2) ? 80 : 40;
327
328 /* honor the valid range even if dispatching is disabled */
329 dw5 |= (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
330 }
331
332 if (cc_may_kill)
333 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL | GEN6_WM_DW5_PS_DISPATCH_ENABLE;
334
335 if (dual_blend)
336 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
337
338 if (multisample && num_samples > 1)
339 dw6 |= GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
340
341 ilo_builder_batch_pointer(builder, cmd_len, &dw);
342
343 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
344 dw[1] = ilo_shader_get_kernel_offset(fs);
345 dw[2] = dw2;
346 dw[3] = 0; /* scratch */
347 dw[4] = dw4;
348 dw[5] = dw5;
349 dw[6] = dw6;
350 dw[7] = 0; /* kernel 1 */
351 dw[8] = 0; /* kernel 2 */
352 }
353
354 static inline void
355 gen7_3DSTATE_WM(struct ilo_builder *builder,
356 const struct ilo_state_raster *rs,
357 const struct ilo_shader_state *fs,
358 bool cc_may_kill)
359 {
360 const uint8_t cmd_len = 3;
361 const bool multisample = false;
362 const int num_samples = 1;
363 uint32_t dw1, dw2, *dw;
364
365 ILO_DEV_ASSERT(builder->dev, 7, 7.5);
366
367 /* see raster_set_gen8_3DSTATE_WM() */
368 dw1 = rs->wm[0];
369
370 if (fs) {
371 const struct ilo_shader_cso *cso;
372
373 cso = ilo_shader_get_kernel_cso(fs);
374 /* see fs_init_cso_gen7() */
375 dw1 |= cso->payload[3];
376 }
377
378 if (cc_may_kill)
379 dw1 |= GEN7_WM_DW1_PS_DISPATCH_ENABLE | GEN7_WM_DW1_PS_KILL_PIXEL;
380
381 dw2 = 0;
382 if (multisample && num_samples > 1)
383 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
384
385 ilo_builder_batch_pointer(builder, cmd_len, &dw);
386
387 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
388 dw[1] = dw1;
389 dw[2] = dw2;
390 }
391
392 static inline void
393 gen8_3DSTATE_WM(struct ilo_builder *builder,
394 const struct ilo_state_raster *rs)
395 {
396 const uint8_t cmd_len = 2;
397 uint32_t *dw;
398
399 ILO_DEV_ASSERT(builder->dev, 8, 8);
400
401 ilo_builder_batch_pointer(builder, cmd_len, &dw);
402
403 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
404 /* see raster_set_gen8_3DSTATE_WM() */
405 dw[1] = rs->wm[0];
406 }
407
408 static inline void
409 gen8_3DSTATE_WM_DEPTH_STENCIL(struct ilo_builder *builder,
410 const struct ilo_state_cc *cc)
411 {
412 const uint8_t cmd_len = 3;
413 uint32_t *dw;
414
415 ILO_DEV_ASSERT(builder->dev, 8, 8);
416
417 ilo_builder_batch_pointer(builder, cmd_len, &dw);
418
419 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_DEPTH_STENCIL) | (cmd_len - 2);
420 /* see cc_set_gen8_3DSTATE_WM_DEPTH_STENCIL() */
421 dw[1] = cc->ds[0];
422 dw[2] = cc->ds[1];
423 }
424
425 static inline void
426 gen8_3DSTATE_WM_HZ_OP(struct ilo_builder *builder,
427 const struct ilo_state_raster *rs,
428 uint16_t width, uint16_t height)
429 {
430 const uint8_t cmd_len = 5;
431 uint32_t *dw;
432
433 ILO_DEV_ASSERT(builder->dev, 8, 8);
434
435 ilo_builder_batch_pointer(builder, cmd_len, &dw);
436
437 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_HZ_OP) | (cmd_len - 2);
438 /* see raster_set_gen8_3dstate_wm_hz_op() */
439 dw[1] = rs->wm[1];
440 dw[2] = 0;
441 /* exclusive */
442 dw[3] = height << 16 | width;
443 dw[4] = rs->wm[2];
444 }
445
446 static inline void
447 gen8_disable_3DSTATE_WM_HZ_OP(struct ilo_builder *builder)
448 {
449 const uint8_t cmd_len = 5;
450 uint32_t *dw;
451
452 ILO_DEV_ASSERT(builder->dev, 8, 8);
453
454 ilo_builder_batch_pointer(builder, cmd_len, &dw);
455
456 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_HZ_OP) | (cmd_len - 2);
457 dw[1] = 0;
458 dw[2] = 0;
459 dw[3] = 0;
460 dw[4] = 0;
461 }
462
463 static inline void
464 gen8_3DSTATE_WM_CHROMAKEY(struct ilo_builder *builder)
465 {
466 const uint8_t cmd_len = 2;
467 uint32_t *dw;
468
469 ILO_DEV_ASSERT(builder->dev, 8, 8);
470
471 ilo_builder_batch_pointer(builder, cmd_len, &dw);
472
473 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_WM_CHROMAKEY) | (cmd_len - 2);
474 dw[1] = 0;
475 }
476
477 static inline void
478 gen7_3DSTATE_PS(struct ilo_builder *builder,
479 const struct ilo_shader_state *fs,
480 bool dual_blend)
481 {
482 const uint8_t cmd_len = 8;
483 const struct ilo_shader_cso *cso;
484 uint32_t dw2, dw4, dw5, *dw;
485
486 ILO_DEV_ASSERT(builder->dev, 7, 7.5);
487
488 /* see fs_init_cso_gen7() */
489 cso = ilo_shader_get_kernel_cso(fs);
490 dw2 = cso->payload[0];
491 dw4 = cso->payload[1];
492 dw5 = cso->payload[2];
493
494 if (dual_blend)
495 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
496
497 ilo_builder_batch_pointer(builder, cmd_len, &dw);
498
499 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
500 dw[1] = ilo_shader_get_kernel_offset(fs);
501 dw[2] = dw2;
502 dw[3] = 0; /* scratch */
503 dw[4] = dw4;
504 dw[5] = dw5;
505 dw[6] = 0; /* kernel 1 */
506 dw[7] = 0; /* kernel 2 */
507 }
508
509 static inline void
510 gen7_disable_3DSTATE_PS(struct ilo_builder *builder)
511 {
512 const uint8_t cmd_len = 8;
513 int max_threads;
514 uint32_t dw4, *dw;
515
516 ILO_DEV_ASSERT(builder->dev, 7, 7.5);
517
518 /* GPU hangs if none of the dispatch enable bits is set */
519 dw4 = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
520
521 /* see brwCreateContext() */
522 switch (ilo_dev_gen(builder->dev)) {
523 case ILO_GEN(7.5):
524 max_threads = (builder->dev->gt == 3) ? 408 :
525 (builder->dev->gt == 2) ? 204 : 102;
526 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
527 break;
528 case ILO_GEN(7):
529 default:
530 max_threads = (builder->dev->gt == 2) ? 172 : 48;
531 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
532 break;
533 }
534
535 ilo_builder_batch_pointer(builder, cmd_len, &dw);
536
537 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
538 dw[1] = 0;
539 dw[2] = 0;
540 dw[3] = 0;
541 dw[4] = dw4;
542 dw[5] = 0;
543 dw[6] = 0;
544 dw[7] = 0;
545 }
546
547 static inline void
548 gen8_3DSTATE_PS(struct ilo_builder *builder,
549 const struct ilo_shader_state *fs)
550 {
551 const uint8_t cmd_len = 12;
552 const struct ilo_shader_cso *cso;
553 uint32_t dw3, dw6, dw7, *dw;
554
555 ILO_DEV_ASSERT(builder->dev, 8, 8);
556
557 /* see fs_init_cso_gen8() */
558 cso = ilo_shader_get_kernel_cso(fs);
559 dw3 = cso->payload[0];
560 dw6 = cso->payload[1];
561 dw7 = cso->payload[2];
562
563 ilo_builder_batch_pointer(builder, cmd_len, &dw);
564
565 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
566 dw[1] = ilo_shader_get_kernel_offset(fs);
567 dw[2] = 0;
568 dw[3] = dw3;
569 dw[4] = 0; /* scratch */
570 dw[5] = 0;
571 dw[6] = dw6;
572 dw[7] = dw7;
573 dw[8] = 0; /* kernel 1 */
574 dw[9] = 0;
575 dw[10] = 0; /* kernel 2 */
576 dw[11] = 0;
577 }
578
579 static inline void
580 gen8_3DSTATE_PS_EXTRA(struct ilo_builder *builder,
581 const struct ilo_shader_state *fs,
582 bool cc_may_kill, bool per_sample)
583 {
584 const uint8_t cmd_len = 2;
585 const struct ilo_shader_cso *cso;
586 uint32_t dw1, *dw;
587
588 ILO_DEV_ASSERT(builder->dev, 8, 8);
589
590 /* see fs_init_cso_gen8() */
591 cso = ilo_shader_get_kernel_cso(fs);
592 dw1 = cso->payload[3];
593
594 if (cc_may_kill)
595 dw1 |= GEN8_PSX_DW1_VALID | GEN8_PSX_DW1_KILL_PIXEL;
596 if (per_sample)
597 dw1 |= GEN8_PSX_DW1_PER_SAMPLE;
598
599 ilo_builder_batch_pointer(builder, cmd_len, &dw);
600
601 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_PS_EXTRA) | (cmd_len - 2);
602 dw[1] = dw1;
603 }
604
605 static inline void
606 gen8_3DSTATE_PS_BLEND(struct ilo_builder *builder,
607 const struct ilo_state_cc *cc)
608 {
609 const uint8_t cmd_len = 2;
610 uint32_t *dw;
611
612 ILO_DEV_ASSERT(builder->dev, 8, 8);
613
614 ilo_builder_batch_pointer(builder, cmd_len, &dw);
615
616 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_PS_BLEND) | (cmd_len - 2);
617 /* see cc_set_gen8_3DSTATE_PS_BLEND() */
618 dw[1] = cc->blend[0];
619 }
620
621 static inline void
622 gen6_3DSTATE_CONSTANT_PS(struct ilo_builder *builder,
623 const uint32_t *bufs, const int *sizes,
624 int num_bufs)
625 {
626 gen6_3dstate_constant(builder, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
627 bufs, sizes, num_bufs);
628 }
629
630 static inline void
631 gen7_3DSTATE_CONSTANT_PS(struct ilo_builder *builder,
632 const uint32_t *bufs, const int *sizes,
633 int num_bufs)
634 {
635 gen7_3dstate_constant(builder, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
636 bufs, sizes, num_bufs);
637 }
638
639 static inline void
640 gen7_3DSTATE_BINDING_TABLE_POINTERS_PS(struct ilo_builder *builder,
641 uint32_t binding_table)
642 {
643 ILO_DEV_ASSERT(builder->dev, 7, 8);
644
645 gen7_3dstate_pointer(builder,
646 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
647 binding_table);
648 }
649
650 static inline void
651 gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(struct ilo_builder *builder,
652 uint32_t sampler_state)
653 {
654 ILO_DEV_ASSERT(builder->dev, 7, 8);
655
656 gen7_3dstate_pointer(builder,
657 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
658 sampler_state);
659 }
660
661 static inline void
662 gen6_3DSTATE_MULTISAMPLE(struct ilo_builder *builder,
663 const struct ilo_state_raster *rs,
664 const uint32_t *pattern, int pattern_len)
665 {
666 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ? 4 : 3;
667 uint32_t *dw;
668
669 ILO_DEV_ASSERT(builder->dev, 6, 7.5);
670
671 ilo_builder_batch_pointer(builder, cmd_len, &dw);
672
673 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
674 /* see raster_set_gen8_3DSTATE_MULTISAMPLE() */
675 dw[1] = rs->sample[0];
676
677 assert(pattern_len == 1 || pattern_len == 2);
678 dw[2] = pattern[0];
679 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7))
680 dw[3] = (pattern_len == 2) ? pattern[1] : 0;
681 }
682
683 static inline void
684 gen8_3DSTATE_MULTISAMPLE(struct ilo_builder *builder,
685 const struct ilo_state_raster *rs)
686 {
687 const uint8_t cmd_len = 2;
688 uint32_t *dw;
689
690 ILO_DEV_ASSERT(builder->dev, 8, 8);
691
692 ilo_builder_batch_pointer(builder, cmd_len, &dw);
693
694 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
695 /* see raster_set_gen8_3DSTATE_MULTISAMPLE() */
696 dw[1] = rs->sample[0];
697 }
698
699 static inline void
700 gen8_3DSTATE_SAMPLE_PATTERN(struct ilo_builder *builder,
701 const uint32_t *pattern_1x,
702 const uint32_t *pattern_2x,
703 const uint32_t *pattern_4x,
704 const uint32_t *pattern_8x,
705 const uint32_t *pattern_16x)
706 {
707 const uint8_t cmd_len = 9;
708 uint32_t *dw;
709
710 ILO_DEV_ASSERT(builder->dev, 8, 8);
711
712 ilo_builder_batch_pointer(builder, cmd_len, &dw);
713
714 dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_SAMPLE_PATTERN) | (cmd_len - 2);
715 dw[1] = pattern_16x[3];
716 dw[2] = pattern_16x[2];
717 dw[3] = pattern_16x[1];
718 dw[4] = pattern_16x[0];
719 dw[5] = pattern_8x[1];
720 dw[6] = pattern_8x[0];
721 dw[7] = pattern_4x[0];
722 dw[8] = pattern_1x[0] << 16 |
723 pattern_2x[0];
724 }
725
726 static inline void
727 gen6_3DSTATE_SAMPLE_MASK(struct ilo_builder *builder,
728 const struct ilo_state_raster *rs)
729 {
730 const uint8_t cmd_len = 2;
731 uint32_t *dw;
732
733 ILO_DEV_ASSERT(builder->dev, 6, 8);
734
735 ilo_builder_batch_pointer(builder, cmd_len, &dw);
736
737 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (cmd_len - 2);
738 /* see raster_set_gen6_3DSTATE_SAMPLE_MASK() */
739 dw[1] = rs->sample[1];
740 }
741
742 static inline void
743 gen6_3DSTATE_DRAWING_RECTANGLE(struct ilo_builder *builder,
744 unsigned x, unsigned y,
745 unsigned width, unsigned height)
746 {
747 const uint8_t cmd_len = 4;
748 unsigned xmax = x + width - 1;
749 unsigned ymax = y + height - 1;
750 unsigned rect_limit;
751 uint32_t *dw;
752
753 ILO_DEV_ASSERT(builder->dev, 6, 8);
754
755 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) {
756 rect_limit = 16383;
757 }
758 else {
759 /*
760 * From the Sandy Bridge PRM, volume 2 part 1, page 230:
761 *
762 * "[DevSNB] Errata: This field (Clipped Drawing Rectangle Y Min)
763 * must be an even number"
764 */
765 assert(y % 2 == 0);
766
767 rect_limit = 8191;
768 }
769
770 if (x > rect_limit) x = rect_limit;
771 if (y > rect_limit) y = rect_limit;
772 if (xmax > rect_limit) xmax = rect_limit;
773 if (ymax > rect_limit) ymax = rect_limit;
774
775 ilo_builder_batch_pointer(builder, cmd_len, &dw);
776
777 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (cmd_len - 2);
778 dw[1] = y << 16 | x;
779 dw[2] = ymax << 16 | xmax;
780 /*
781 * There is no need to set the origin. It is intended to support front
782 * buffer rendering.
783 */
784 dw[3] = 0;
785 }
786
787 static inline void
788 gen6_3DSTATE_POLY_STIPPLE_OFFSET(struct ilo_builder *builder,
789 int x_offset, int y_offset)
790 {
791 const uint8_t cmd_len = 2;
792 uint32_t *dw;
793
794 ILO_DEV_ASSERT(builder->dev, 6, 8);
795
796 assert(x_offset >= 0 && x_offset <= 31);
797 assert(y_offset >= 0 && y_offset <= 31);
798
799 ilo_builder_batch_pointer(builder, cmd_len, &dw);
800
801 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_POLY_STIPPLE_OFFSET) | (cmd_len - 2);
802 dw[1] = x_offset << 8 | y_offset;
803 }
804
805 static inline void
806 gen6_3DSTATE_POLY_STIPPLE_PATTERN(struct ilo_builder *builder,
807 const struct pipe_poly_stipple *pattern)
808 {
809 const uint8_t cmd_len = 33;
810 uint32_t *dw;
811 int i;
812
813 ILO_DEV_ASSERT(builder->dev, 6, 8);
814
815 ilo_builder_batch_pointer(builder, cmd_len, &dw);
816
817 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_POLY_STIPPLE_PATTERN) | (cmd_len - 2);
818 dw++;
819
820 STATIC_ASSERT(Elements(pattern->stipple) == 32);
821 for (i = 0; i < 32; i++)
822 dw[i] = pattern->stipple[i];
823 }
824
825 static inline void
826 gen6_3DSTATE_LINE_STIPPLE(struct ilo_builder *builder,
827 unsigned pattern, unsigned factor)
828 {
829 const uint8_t cmd_len = 3;
830 unsigned inverse;
831 uint32_t *dw;
832
833 ILO_DEV_ASSERT(builder->dev, 6, 8);
834
835 assert((pattern & 0xffff) == pattern);
836 assert(factor >= 1 && factor <= 256);
837
838 ilo_builder_batch_pointer(builder, cmd_len, &dw);
839
840 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_LINE_STIPPLE) | (cmd_len - 2);
841 dw[1] = pattern;
842
843 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) {
844 /* in U1.16 */
845 inverse = 65536 / factor;
846
847 dw[2] = inverse << GEN7_LINE_STIPPLE_DW2_INVERSE_REPEAT_COUNT__SHIFT |
848 factor;
849 }
850 else {
851 /* in U1.13 */
852 inverse = 8192 / factor;
853
854 dw[2] = inverse << GEN6_LINE_STIPPLE_DW2_INVERSE_REPEAT_COUNT__SHIFT |
855 factor;
856 }
857 }
858
859 static inline void
860 gen6_3DSTATE_AA_LINE_PARAMETERS(struct ilo_builder *builder)
861 {
862 const uint8_t cmd_len = 3;
863 const uint32_t dw[3] = {
864 GEN6_RENDER_CMD(3D, 3DSTATE_AA_LINE_PARAMETERS) | (cmd_len - 2),
865 0 << GEN6_AA_LINE_DW1_BIAS__SHIFT | 0,
866 0 << GEN6_AA_LINE_DW2_CAP_BIAS__SHIFT | 0,
867 };
868
869 ILO_DEV_ASSERT(builder->dev, 6, 8);
870
871 ilo_builder_batch_write(builder, cmd_len, dw);
872 }
873
874 static inline void
875 gen6_3DSTATE_DEPTH_BUFFER(struct ilo_builder *builder,
876 const struct ilo_state_zs *zs)
877 {
878 const uint32_t cmd = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ?
879 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
880 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
881 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 8 : 7;
882 uint32_t *dw;
883 unsigned pos;
884
885 ILO_DEV_ASSERT(builder->dev, 6, 8);
886
887 pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
888
889 dw[0] = cmd | (cmd_len - 2);
890
891 /*
892 * see zs_set_gen6_3DSTATE_DEPTH_BUFFER() and
893 * zs_set_gen7_3DSTATE_DEPTH_BUFFER()
894 */
895 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
896 dw[1] = zs->depth[0];
897 dw[2] = 0;
898 dw[3] = 0;
899 dw[4] = zs->depth[2];
900 dw[5] = zs->depth[3];
901 dw[6] = 0;
902 dw[7] = zs->depth[4];
903
904 dw[5] |= builder->mocs << GEN8_DEPTH_DW5_MOCS__SHIFT;
905
906 if (zs->depth_bo) {
907 ilo_builder_batch_reloc64(builder, pos + 2, zs->depth_bo,
908 zs->depth[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
909 }
910 } else {
911 dw[1] = zs->depth[0];
912 dw[2] = 0;
913 dw[3] = zs->depth[2];
914 dw[4] = zs->depth[3];
915 dw[5] = 0;
916 dw[6] = zs->depth[4];
917
918 if (ilo_dev_gen(builder->dev) >= ILO_GEN(7))
919 dw[4] |= builder->mocs << GEN7_DEPTH_DW4_MOCS__SHIFT;
920 else
921 dw[6] |= builder->mocs << GEN6_DEPTH_DW6_MOCS__SHIFT;
922
923 if (zs->depth_bo) {
924 ilo_builder_batch_reloc(builder, pos + 2, zs->depth_bo,
925 zs->depth[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
926 }
927 }
928 }
929
930 static inline void
931 gen6_3DSTATE_STENCIL_BUFFER(struct ilo_builder *builder,
932 const struct ilo_state_zs *zs)
933 {
934 const uint32_t cmd = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ?
935 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
936 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
937 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 5 : 3;
938 uint32_t *dw;
939 unsigned pos;
940
941 ILO_DEV_ASSERT(builder->dev, 6, 8);
942
943 pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
944
945 dw[0] = cmd | (cmd_len - 2);
946
947 /* see zs_set_gen6_3DSTATE_STENCIL_BUFFER() */
948 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
949 dw[1] = zs->stencil[0];
950 dw[2] = 0;
951 dw[3] = 0;
952 dw[4] = zs->stencil[2];
953
954 dw[1] |= builder->mocs << GEN8_STENCIL_DW1_MOCS__SHIFT;
955
956 if (zs->stencil_bo) {
957 ilo_builder_batch_reloc64(builder, pos + 2, zs->stencil_bo,
958 zs->stencil[1], (zs->s_readonly) ? 0 : INTEL_RELOC_WRITE);
959 }
960 } else {
961 dw[1] = zs->stencil[0];
962 dw[2] = 0;
963
964 dw[1] |= builder->mocs << GEN6_STENCIL_DW1_MOCS__SHIFT;
965
966 if (zs->stencil_bo) {
967 ilo_builder_batch_reloc(builder, pos + 2, zs->stencil_bo,
968 zs->stencil[1], (zs->s_readonly) ? 0 : INTEL_RELOC_WRITE);
969 }
970 }
971 }
972
973 static inline void
974 gen6_3DSTATE_HIER_DEPTH_BUFFER(struct ilo_builder *builder,
975 const struct ilo_state_zs *zs)
976 {
977 const uint32_t cmd = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ?
978 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
979 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
980 const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 5 : 3;
981 uint32_t *dw;
982 unsigned pos;
983
984 ILO_DEV_ASSERT(builder->dev, 6, 8);
985
986 pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
987
988 dw[0] = cmd | (cmd_len - 2);
989
990 /* see zs_set_gen6_3DSTATE_HIER_DEPTH_BUFFER() */
991 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
992 dw[1] = zs->hiz[0];
993 dw[2] = 0;
994 dw[3] = 0;
995 dw[4] = zs->hiz[2];
996
997 dw[1] |= builder->mocs << GEN8_HIZ_DW1_MOCS__SHIFT;
998
999 if (zs->hiz_bo) {
1000 ilo_builder_batch_reloc64(builder, pos + 2, zs->hiz_bo,
1001 zs->hiz[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
1002 }
1003 } else {
1004 dw[1] = zs->hiz[0];
1005 dw[2] = 0;
1006
1007 dw[1] |= builder->mocs << GEN6_HIZ_DW1_MOCS__SHIFT;
1008
1009 if (zs->hiz_bo) {
1010 ilo_builder_batch_reloc(builder, pos + 2, zs->hiz_bo,
1011 zs->hiz[1], (zs->z_readonly) ? 0 : INTEL_RELOC_WRITE);
1012 }
1013 }
1014 }
1015
1016 static inline void
1017 gen6_3DSTATE_CLEAR_PARAMS(struct ilo_builder *builder,
1018 uint32_t clear_val)
1019 {
1020 const uint8_t cmd_len = 2;
1021 uint32_t *dw;
1022
1023 ILO_DEV_ASSERT(builder->dev, 6, 6);
1024
1025 ilo_builder_batch_pointer(builder, cmd_len, &dw);
1026
1027 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
1028 GEN6_CLEAR_PARAMS_DW0_VALID |
1029 (cmd_len - 2);
1030 dw[1] = clear_val;
1031 }
1032
1033 static inline void
1034 gen7_3DSTATE_CLEAR_PARAMS(struct ilo_builder *builder,
1035 uint32_t clear_val)
1036 {
1037 const uint8_t cmd_len = 3;
1038 uint32_t *dw;
1039
1040 ILO_DEV_ASSERT(builder->dev, 7, 8);
1041
1042 ilo_builder_batch_pointer(builder, cmd_len, &dw);
1043
1044 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) | (cmd_len - 2);
1045 dw[1] = clear_val;
1046 dw[2] = GEN7_CLEAR_PARAMS_DW2_VALID;
1047 }
1048
1049 static inline void
1050 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct ilo_builder *builder,
1051 uint32_t clip_viewport,
1052 uint32_t sf_viewport,
1053 uint32_t cc_viewport)
1054 {
1055 const uint8_t cmd_len = 4;
1056 uint32_t *dw;
1057
1058 ILO_DEV_ASSERT(builder->dev, 6, 6);
1059
1060 ilo_builder_batch_pointer(builder, cmd_len, &dw);
1061
1062 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
1063 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1064 GEN6_VP_PTR_DW0_SF_CHANGED |
1065 GEN6_VP_PTR_DW0_CC_CHANGED |
1066 (cmd_len - 2);
1067 dw[1] = clip_viewport;
1068 dw[2] = sf_viewport;
1069 dw[3] = cc_viewport;
1070 }
1071
1072 static inline void
1073 gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct ilo_builder *builder,
1074 uint32_t scissor_rect)
1075 {
1076 const uint8_t cmd_len = 2;
1077 uint32_t *dw;
1078
1079 ILO_DEV_ASSERT(builder->dev, 6, 8);
1080
1081 ilo_builder_batch_pointer(builder, cmd_len, &dw);
1082
1083 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
1084 (cmd_len - 2);
1085 dw[1] = scissor_rect;
1086 }
1087
1088 static inline void
1089 gen6_3DSTATE_CC_STATE_POINTERS(struct ilo_builder *builder,
1090 uint32_t blend_state,
1091 uint32_t depth_stencil_state,
1092 uint32_t color_calc_state)
1093 {
1094 const uint8_t cmd_len = 4;
1095 uint32_t *dw;
1096
1097 ILO_DEV_ASSERT(builder->dev, 6, 6);
1098
1099 ilo_builder_batch_pointer(builder, cmd_len, &dw);
1100
1101 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) | (cmd_len - 2);
1102 dw[1] = blend_state | GEN6_CC_PTR_DW1_BLEND_CHANGED;
1103 dw[2] = depth_stencil_state | GEN6_CC_PTR_DW2_ZS_CHANGED;
1104 dw[3] = color_calc_state | GEN6_CC_PTR_DW3_CC_CHANGED;
1105 }
1106
1107 static inline void
1108 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(struct ilo_builder *builder,
1109 uint32_t sf_clip_viewport)
1110 {
1111 ILO_DEV_ASSERT(builder->dev, 7, 8);
1112
1113 gen7_3dstate_pointer(builder,
1114 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1115 sf_clip_viewport);
1116 }
1117
1118 static inline void
1119 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(struct ilo_builder *builder,
1120 uint32_t cc_viewport)
1121 {
1122 ILO_DEV_ASSERT(builder->dev, 7, 8);
1123
1124 gen7_3dstate_pointer(builder,
1125 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
1126 cc_viewport);
1127 }
1128
1129 static inline void
1130 gen7_3DSTATE_CC_STATE_POINTERS(struct ilo_builder *builder,
1131 uint32_t color_calc_state)
1132 {
1133 ILO_DEV_ASSERT(builder->dev, 7, 8);
1134
1135 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8))
1136 color_calc_state |= 1;
1137
1138 gen7_3dstate_pointer(builder,
1139 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, color_calc_state);
1140 }
1141
1142 static inline void
1143 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(struct ilo_builder *builder,
1144 uint32_t depth_stencil_state)
1145 {
1146 ILO_DEV_ASSERT(builder->dev, 7, 8);
1147
1148 gen7_3dstate_pointer(builder,
1149 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1150 depth_stencil_state);
1151 }
1152
1153 static inline void
1154 gen7_3DSTATE_BLEND_STATE_POINTERS(struct ilo_builder *builder,
1155 uint32_t blend_state)
1156 {
1157 ILO_DEV_ASSERT(builder->dev, 7, 8);
1158
1159 if (ilo_dev_gen(builder->dev) >= ILO_GEN(8))
1160 blend_state |= 1;
1161
1162 gen7_3dstate_pointer(builder,
1163 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
1164 blend_state);
1165 }
1166
1167 static inline uint32_t
1168 gen6_CLIP_VIEWPORT(struct ilo_builder *builder,
1169 const struct ilo_state_viewport *vp)
1170 {
1171 const int state_align = 32;
1172 const int state_len = 4 * vp->count;
1173 uint32_t state_offset, *dw;
1174 int i;
1175
1176 ILO_DEV_ASSERT(builder->dev, 6, 6);
1177
1178 state_offset = ilo_builder_dynamic_pointer(builder,
1179 ILO_BUILDER_ITEM_CLIP_VIEWPORT, state_align, state_len, &dw);
1180
1181 for (i = 0; i < vp->count; i++) {
1182 /* see viewport_matrix_set_gen7_SF_CLIP_VIEWPORT() */
1183 dw[0] = vp->sf_clip[i][8];
1184 dw[1] = vp->sf_clip[i][9];
1185 dw[2] = vp->sf_clip[i][10];
1186 dw[3] = vp->sf_clip[i][11];
1187
1188 dw += 4;
1189 }
1190
1191 return state_offset;
1192 }
1193
1194 static inline uint32_t
1195 gen6_SF_VIEWPORT(struct ilo_builder *builder,
1196 const struct ilo_state_viewport *vp)
1197 {
1198 const int state_align = 32;
1199 const int state_len = 8 * vp->count;
1200 uint32_t state_offset, *dw;
1201 int i;
1202
1203 ILO_DEV_ASSERT(builder->dev, 6, 6);
1204
1205 state_offset = ilo_builder_dynamic_pointer(builder,
1206 ILO_BUILDER_ITEM_SF_VIEWPORT, state_align, state_len, &dw);
1207
1208 for (i = 0; i < vp->count; i++) {
1209 /* see viewport_matrix_set_gen7_SF_CLIP_VIEWPORT() */
1210 memcpy(dw, vp->sf_clip[i], sizeof(*dw) * 8);
1211
1212 dw += 8;
1213 }
1214
1215 return state_offset;
1216 }
1217
1218 static inline uint32_t
1219 gen7_SF_CLIP_VIEWPORT(struct ilo_builder *builder,
1220 const struct ilo_state_viewport *vp)
1221 {
1222 const int state_align = 64;
1223 const int state_len = 16 * vp->count;
1224
1225 ILO_DEV_ASSERT(builder->dev, 7, 8);
1226
1227 /* see viewport_matrix_set_gen7_SF_CLIP_VIEWPORT() */
1228 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_SF_VIEWPORT,
1229 state_align, state_len, (const uint32_t *) vp->sf_clip);
1230 }
1231
1232 static inline uint32_t
1233 gen6_CC_VIEWPORT(struct ilo_builder *builder,
1234 const struct ilo_state_viewport *vp)
1235 {
1236 const int state_align = 32;
1237 const int state_len = 2 * vp->count;
1238
1239 ILO_DEV_ASSERT(builder->dev, 6, 8);
1240
1241 /* see viewport_matrix_set_gen6_CC_VIEWPORT() */
1242 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_CC_VIEWPORT,
1243 state_align, state_len, (const uint32_t *) vp->cc);
1244 }
1245
1246 static inline uint32_t
1247 gen6_SCISSOR_RECT(struct ilo_builder *builder,
1248 const struct ilo_state_viewport *vp)
1249 {
1250 const int state_align = 32;
1251 const int state_len = 2 * vp->count;
1252
1253 ILO_DEV_ASSERT(builder->dev, 6, 8);
1254
1255 /* see viewport_scissor_set_gen6_SCISSOR_RECT() */
1256 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_SCISSOR_RECT,
1257 state_align, state_len, (const uint32_t *) vp->scissor);
1258 }
1259
1260 static inline uint32_t
1261 gen6_COLOR_CALC_STATE(struct ilo_builder *builder,
1262 const struct ilo_state_cc *cc)
1263 {
1264 const int state_align = 64;
1265 const int state_len = 6;
1266
1267 ILO_DEV_ASSERT(builder->dev, 6, 8);
1268
1269 /* see cc_params_set_gen6_COLOR_CALC_STATE() */
1270 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_COLOR_CALC,
1271 state_align, state_len, cc->cc);
1272 }
1273
1274 static inline uint32_t
1275 gen6_DEPTH_STENCIL_STATE(struct ilo_builder *builder,
1276 const struct ilo_state_cc *cc)
1277 {
1278 const int state_align = 64;
1279 const int state_len = 3;
1280
1281 ILO_DEV_ASSERT(builder->dev, 6, 7.5);
1282
1283 /* see cc_set_gen6_DEPTH_STENCIL_STATE() */
1284 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_DEPTH_STENCIL,
1285 state_align, state_len, cc->ds);
1286 }
1287
1288 static inline uint32_t
1289 gen6_BLEND_STATE(struct ilo_builder *builder,
1290 const struct ilo_state_cc *cc)
1291 {
1292 const int state_align = 64;
1293 const int state_len = 2 * cc->blend_state_count;
1294
1295 ILO_DEV_ASSERT(builder->dev, 6, 7.5);
1296
1297 if (!state_len)
1298 return 0;
1299
1300 /* see cc_set_gen6_BLEND_STATE() */
1301 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_BLEND,
1302 state_align, state_len, cc->blend);
1303 }
1304
1305 static inline uint32_t
1306 gen8_BLEND_STATE(struct ilo_builder *builder,
1307 const struct ilo_state_cc *cc)
1308 {
1309 const int state_align = 64;
1310 const int state_len = 1 + 2 * cc->blend_state_count;
1311
1312 ILO_DEV_ASSERT(builder->dev, 8, 8);
1313
1314 /* see cc_set_gen8_BLEND_STATE() */
1315 return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_BLEND,
1316 state_align, state_len, &cc->blend[1]);
1317 }
1318
1319 #endif /* ILO_BUILDER_3D_BOTTOM_H */