2 * Mesa 3-D graphics library
4 * Copyright (C) 2014 LunarG, Inc.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
25 * Chia-I Wu <olv@lunarg.com>
28 #ifndef ILO_BUILDER_3D_TOP_H
29 #define ILO_BUILDER_3D_TOP_H
31 #include "genhw/genhw.h"
32 #include "../ilo_resource.h"
33 #include "../ilo_shader.h"
34 #include "intel_winsys.h"
38 #include "ilo_state_3d.h"
39 #include "ilo_state_sampler.h"
40 #include "ilo_state_sol.h"
41 #include "ilo_state_urb.h"
42 #include "ilo_builder.h"
45 gen6_3DSTATE_URB(struct ilo_builder
*builder
,
46 const struct ilo_state_urb
*urb
)
48 const uint8_t cmd_len
= 3;
51 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
53 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_URB
) | (cmd_len
- 2);
54 /* see urb_set_gen6_3DSTATE_URB() */
60 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(struct ilo_builder
*builder
,
61 const struct ilo_state_urb
*urb
)
63 const uint8_t cmd_len
= 2;
66 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
68 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_PUSH_CONSTANT_ALLOC_VS
) |
70 /* see urb_set_gen7_3dstate_push_constant_alloc() */
75 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_HS(struct ilo_builder
*builder
,
76 const struct ilo_state_urb
*urb
)
78 const uint8_t cmd_len
= 2;
81 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
83 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_PUSH_CONSTANT_ALLOC_HS
) |
85 /* see urb_set_gen7_3dstate_push_constant_alloc() */
90 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_DS(struct ilo_builder
*builder
,
91 const struct ilo_state_urb
*urb
)
93 const uint8_t cmd_len
= 2;
96 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
98 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_PUSH_CONSTANT_ALLOC_DS
) |
100 /* see urb_set_gen7_3dstate_push_constant_alloc() */
105 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_GS(struct ilo_builder
*builder
,
106 const struct ilo_state_urb
*urb
)
108 const uint8_t cmd_len
= 2;
111 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
113 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_PUSH_CONSTANT_ALLOC_GS
) |
115 /* see urb_set_gen7_3dstate_push_constant_alloc() */
120 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(struct ilo_builder
*builder
,
121 const struct ilo_state_urb
*urb
)
123 const uint8_t cmd_len
= 2;
126 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
128 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_PUSH_CONSTANT_ALLOC_PS
) |
130 /* see urb_set_gen7_3dstate_push_constant_alloc() */
135 gen7_3DSTATE_URB_VS(struct ilo_builder
*builder
,
136 const struct ilo_state_urb
*urb
)
138 const uint8_t cmd_len
= 2;
141 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
143 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_URB_VS
) | (cmd_len
- 2);
144 /* see urb_set_gen7_3dstate_push_constant_alloc() */
149 gen7_3DSTATE_URB_HS(struct ilo_builder
*builder
,
150 const struct ilo_state_urb
*urb
)
152 const uint8_t cmd_len
= 2;
155 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
157 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_URB_HS
) | (cmd_len
- 2);
158 /* see urb_set_gen7_3dstate_push_constant_alloc() */
163 gen7_3DSTATE_URB_DS(struct ilo_builder
*builder
,
164 const struct ilo_state_urb
*urb
)
166 const uint8_t cmd_len
= 2;
169 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
171 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_URB_DS
) | (cmd_len
- 2);
172 /* see urb_set_gen7_3dstate_push_constant_alloc() */
177 gen7_3DSTATE_URB_GS(struct ilo_builder
*builder
,
178 const struct ilo_state_urb
*urb
)
180 const uint8_t cmd_len
= 2;
183 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
185 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_URB_GS
) | (cmd_len
- 2);
186 /* see urb_set_gen7_3dstate_push_constant_alloc() */
191 gen75_3DSTATE_VF(struct ilo_builder
*builder
,
192 bool enable_cut_index
,
195 const uint8_t cmd_len
= 2;
198 ILO_DEV_ASSERT(builder
->dev
, 7.5, 8);
200 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
202 dw
[0] = GEN75_RENDER_CMD(3D
, 3DSTATE_VF
) | (cmd_len
- 2);
203 if (enable_cut_index
)
204 dw
[0] |= GEN75_VF_DW0_CUT_INDEX_ENABLE
;
210 gen6_3DSTATE_VF_STATISTICS(struct ilo_builder
*builder
,
213 const uint8_t cmd_len
= 1;
214 const uint32_t dw0
= GEN6_RENDER_CMD(SINGLE_DW
, 3DSTATE_VF_STATISTICS
) |
217 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
219 ilo_builder_batch_write(builder
, cmd_len
, &dw0
);
223 * Translate a pipe primitive type to the matching hardware primitive type.
226 gen6_3d_translate_pipe_prim(unsigned prim
)
228 static const int prim_mapping
[ILO_PRIM_MAX
] = {
229 [PIPE_PRIM_POINTS
] = GEN6_3DPRIM_POINTLIST
,
230 [PIPE_PRIM_LINES
] = GEN6_3DPRIM_LINELIST
,
231 [PIPE_PRIM_LINE_LOOP
] = GEN6_3DPRIM_LINELOOP
,
232 [PIPE_PRIM_LINE_STRIP
] = GEN6_3DPRIM_LINESTRIP
,
233 [PIPE_PRIM_TRIANGLES
] = GEN6_3DPRIM_TRILIST
,
234 [PIPE_PRIM_TRIANGLE_STRIP
] = GEN6_3DPRIM_TRISTRIP
,
235 [PIPE_PRIM_TRIANGLE_FAN
] = GEN6_3DPRIM_TRIFAN
,
236 [PIPE_PRIM_QUADS
] = GEN6_3DPRIM_QUADLIST
,
237 [PIPE_PRIM_QUAD_STRIP
] = GEN6_3DPRIM_QUADSTRIP
,
238 [PIPE_PRIM_POLYGON
] = GEN6_3DPRIM_POLYGON
,
239 [PIPE_PRIM_LINES_ADJACENCY
] = GEN6_3DPRIM_LINELIST_ADJ
,
240 [PIPE_PRIM_LINE_STRIP_ADJACENCY
] = GEN6_3DPRIM_LINESTRIP_ADJ
,
241 [PIPE_PRIM_TRIANGLES_ADJACENCY
] = GEN6_3DPRIM_TRILIST_ADJ
,
242 [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
] = GEN6_3DPRIM_TRISTRIP_ADJ
,
243 [ILO_PRIM_RECTANGLES
] = GEN6_3DPRIM_RECTLIST
,
246 assert(prim_mapping
[prim
]);
248 return prim_mapping
[prim
];
252 gen8_3DSTATE_VF_TOPOLOGY(struct ilo_builder
*builder
, unsigned pipe_prim
)
254 const uint8_t cmd_len
= 2;
255 const int prim
= gen6_3d_translate_pipe_prim(pipe_prim
);
258 ILO_DEV_ASSERT(builder
->dev
, 8, 8);
260 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
262 dw
[0] = GEN8_RENDER_CMD(3D
, 3DSTATE_VF_TOPOLOGY
) | (cmd_len
- 2);
267 gen8_3DSTATE_VF_INSTANCING(struct ilo_builder
*builder
,
268 int vb_index
, uint32_t step_rate
)
270 const uint8_t cmd_len
= 3;
273 ILO_DEV_ASSERT(builder
->dev
, 8, 8);
275 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
277 dw
[0] = GEN8_RENDER_CMD(3D
, 3DSTATE_VF_INSTANCING
) | (cmd_len
- 2);
280 dw
[1] |= GEN8_INSTANCING_DW1_ENABLE
;
285 gen8_3DSTATE_VF_SGVS(struct ilo_builder
*builder
,
286 bool vid_enable
, int vid_ve
, int vid_comp
,
287 bool iid_enable
, int iid_ve
, int iid_comp
)
289 const uint8_t cmd_len
= 2;
292 ILO_DEV_ASSERT(builder
->dev
, 8, 8);
294 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
296 dw
[0] = GEN8_RENDER_CMD(3D
, 3DSTATE_VF_SGVS
) | (cmd_len
- 2);
300 dw
[1] |= GEN8_SGVS_DW1_IID_ENABLE
|
301 vid_comp
<< GEN8_SGVS_DW1_IID_VE_COMP__SHIFT
|
302 vid_ve
<< GEN8_SGVS_DW1_IID_VE_INDEX__SHIFT
;
306 dw
[1] |= GEN8_SGVS_DW1_VID_ENABLE
|
307 vid_comp
<< GEN8_SGVS_DW1_VID_VE_COMP__SHIFT
|
308 vid_ve
<< GEN8_SGVS_DW1_VID_VE_INDEX__SHIFT
;
313 gen6_3DSTATE_VERTEX_BUFFERS(struct ilo_builder
*builder
,
314 const struct ilo_ve_state
*ve
,
315 const struct ilo_vb_state
*vb
)
319 unsigned pos
, hw_idx
;
321 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
324 * From the Sandy Bridge PRM, volume 2 part 1, page 82:
326 * "From 1 to 33 VBs can be specified..."
328 assert(ve
->vb_count
<= 33);
333 cmd_len
= 1 + 4 * ve
->vb_count
;
334 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
336 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_VERTEX_BUFFERS
) | (cmd_len
- 2);
340 for (hw_idx
= 0; hw_idx
< ve
->vb_count
; hw_idx
++) {
341 const unsigned instance_divisor
= ve
->instance_divisors
[hw_idx
];
342 const unsigned pipe_idx
= ve
->vb_mapping
[hw_idx
];
343 const struct pipe_vertex_buffer
*cso
= &vb
->states
[pipe_idx
];
345 dw
[0] = hw_idx
<< GEN6_VB_DW0_INDEX__SHIFT
;
347 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8))
348 dw
[0] |= builder
->mocs
<< GEN8_VB_DW0_MOCS__SHIFT
;
350 dw
[0] |= builder
->mocs
<< GEN6_VB_DW0_MOCS__SHIFT
;
352 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(7))
353 dw
[0] |= GEN7_VB_DW0_ADDR_MODIFIED
;
355 if (instance_divisor
)
356 dw
[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA
;
358 dw
[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA
;
360 /* use null vb if there is no buffer or the stride is out of range */
361 if (!cso
->buffer
|| cso
->stride
> 2048) {
362 dw
[0] |= GEN6_VB_DW0_IS_NULL
;
365 dw
[3] = (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ?
366 0 : instance_divisor
;
371 dw
[0] |= cso
->stride
<< GEN6_VB_DW0_PITCH__SHIFT
;
373 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
374 const struct ilo_buffer
*buf
= ilo_buffer(cso
->buffer
);
375 const uint32_t start_offset
= cso
->buffer_offset
;
377 ilo_builder_batch_reloc64(builder
, pos
+ 1,
378 buf
->bo
, start_offset
, 0);
379 dw
[3] = buf
->bo_size
;
381 const struct ilo_buffer
*buf
= ilo_buffer(cso
->buffer
);
382 const uint32_t start_offset
= cso
->buffer_offset
;
383 const uint32_t end_offset
= buf
->bo_size
- 1;
385 dw
[3] = instance_divisor
;
387 ilo_builder_batch_reloc(builder
, pos
+ 1, buf
->bo
, start_offset
, 0);
388 ilo_builder_batch_reloc(builder
, pos
+ 2, buf
->bo
, end_offset
, 0);
396 /* the user vertex buffer must be uploaded with gen6_user_vertex_buffer() */
398 gen6_user_3DSTATE_VERTEX_BUFFERS(struct ilo_builder
*builder
,
399 uint32_t vb_begin
, uint32_t vb_end
,
402 const struct ilo_builder_writer
*bat
=
403 &builder
->writers
[ILO_BUILDER_WRITER_BATCH
];
404 const uint8_t cmd_len
= 1 + 4;
408 ILO_DEV_ASSERT(builder
->dev
, 6, 7.5);
410 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
412 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_VERTEX_BUFFERS
) | (cmd_len
- 2);
416 /* VERTEX_BUFFER_STATE */
417 dw
[0] = 0 << GEN6_VB_DW0_INDEX__SHIFT
|
418 GEN6_VB_DW0_ACCESS_VERTEXDATA
|
419 stride
<< GEN6_VB_DW0_PITCH__SHIFT
;
420 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(7))
421 dw
[0] |= GEN7_VB_DW0_ADDR_MODIFIED
;
425 ilo_builder_batch_reloc(builder
, pos
+ 1, bat
->bo
, vb_begin
, 0);
426 ilo_builder_batch_reloc(builder
, pos
+ 2, bat
->bo
, vb_end
, 0);
430 gen6_3DSTATE_VERTEX_ELEMENTS(struct ilo_builder
*builder
,
431 const struct ilo_ve_state
*ve
)
437 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
440 * From the Sandy Bridge PRM, volume 2 part 1, page 92:
442 * "At least one VERTEX_ELEMENT_STATE structure must be included."
444 * From the Sandy Bridge PRM, volume 2 part 1, page 93:
446 * "Up to 34 (DevSNB+) vertex elements are supported."
448 assert(ve
->count
+ ve
->prepend_nosrc_cso
>= 1);
449 assert(ve
->count
+ ve
->prepend_nosrc_cso
<= 34);
451 STATIC_ASSERT(Elements(ve
->cso
[0].payload
) == 2);
453 cmd_len
= 1 + 2 * (ve
->count
+ ve
->prepend_nosrc_cso
);
454 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
456 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_VERTEX_ELEMENTS
) | (cmd_len
- 2);
459 if (ve
->prepend_nosrc_cso
) {
460 memcpy(dw
, ve
->nosrc_cso
.payload
, sizeof(ve
->nosrc_cso
.payload
));
464 for (i
= 0; i
< ve
->count
- ve
->last_cso_edgeflag
; i
++) {
465 memcpy(dw
, ve
->cso
[i
].payload
, sizeof(ve
->cso
[i
].payload
));
469 if (ve
->last_cso_edgeflag
)
470 memcpy(dw
, ve
->edgeflag_cso
.payload
, sizeof(ve
->edgeflag_cso
.payload
));
474 gen6_3DSTATE_INDEX_BUFFER(struct ilo_builder
*builder
,
475 const struct ilo_ib_state
*ib
,
476 bool enable_cut_index
)
478 const uint8_t cmd_len
= 3;
479 struct ilo_buffer
*buf
= ilo_buffer(ib
->hw_resource
);
480 uint32_t start_offset
, end_offset
;
485 ILO_DEV_ASSERT(builder
->dev
, 6, 7.5);
490 /* this is moved to the new 3DSTATE_VF */
491 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(7.5))
492 assert(!enable_cut_index
);
494 switch (ib
->hw_index_size
) {
496 format
= GEN6_IB_DW0_FORMAT_DWORD
;
499 format
= GEN6_IB_DW0_FORMAT_WORD
;
502 format
= GEN6_IB_DW0_FORMAT_BYTE
;
505 assert(!"unknown index size");
506 format
= GEN6_IB_DW0_FORMAT_BYTE
;
511 * set start_offset to 0 here and adjust pipe_draw_info::start with
512 * ib->draw_start_offset in 3DPRIMITIVE
515 end_offset
= buf
->bo_size
;
517 /* end_offset must also be aligned and is inclusive */
518 end_offset
-= (end_offset
% ib
->hw_index_size
);
521 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
523 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_INDEX_BUFFER
) | (cmd_len
- 2) |
524 builder
->mocs
<< GEN6_IB_DW0_MOCS__SHIFT
|
526 if (enable_cut_index
)
527 dw
[0] |= GEN6_IB_DW0_CUT_INDEX_ENABLE
;
529 ilo_builder_batch_reloc(builder
, pos
+ 1, buf
->bo
, start_offset
, 0);
530 ilo_builder_batch_reloc(builder
, pos
+ 2, buf
->bo
, end_offset
, 0);
534 gen8_3DSTATE_INDEX_BUFFER(struct ilo_builder
*builder
,
535 const struct ilo_ib_state
*ib
)
537 const uint8_t cmd_len
= 5;
538 struct ilo_buffer
*buf
= ilo_buffer(ib
->hw_resource
);
543 ILO_DEV_ASSERT(builder
->dev
, 8, 8);
548 switch (ib
->hw_index_size
) {
550 format
= GEN8_IB_DW1_FORMAT_DWORD
;
553 format
= GEN8_IB_DW1_FORMAT_WORD
;
556 format
= GEN8_IB_DW1_FORMAT_BYTE
;
559 assert(!"unknown index size");
560 format
= GEN8_IB_DW1_FORMAT_BYTE
;
564 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
566 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_INDEX_BUFFER
) | (cmd_len
- 2);
568 builder
->mocs
<< GEN8_IB_DW1_MOCS__SHIFT
;
569 dw
[4] = buf
->bo_size
;
571 /* ignore ib->offset here in favor of adjusting 3DPRIMITIVE */
572 ilo_builder_batch_reloc64(builder
, pos
+ 2, buf
->bo
, 0, 0);
576 gen6_3DSTATE_VS(struct ilo_builder
*builder
,
577 const struct ilo_shader_state
*vs
)
579 const uint8_t cmd_len
= 6;
580 const struct ilo_shader_cso
*cso
;
581 uint32_t dw2
, dw4
, dw5
, *dw
;
583 ILO_DEV_ASSERT(builder
->dev
, 6, 7.5);
585 cso
= ilo_shader_get_kernel_cso(vs
);
586 dw2
= cso
->payload
[0];
587 dw4
= cso
->payload
[1];
588 dw5
= cso
->payload
[2];
590 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
592 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_VS
) | (cmd_len
- 2);
593 dw
[1] = ilo_shader_get_kernel_offset(vs
);
595 dw
[3] = 0; /* scratch */
601 gen8_3DSTATE_VS(struct ilo_builder
*builder
,
602 const struct ilo_shader_state
*vs
,
603 uint32_t clip_plane_enable
)
605 const uint8_t cmd_len
= 9;
606 const struct ilo_shader_cso
*cso
;
607 uint32_t dw3
, dw6
, dw7
, dw8
, *dw
;
609 ILO_DEV_ASSERT(builder
->dev
, 8, 8);
611 cso
= ilo_shader_get_kernel_cso(vs
);
612 dw3
= cso
->payload
[0];
613 dw6
= cso
->payload
[1];
614 dw7
= cso
->payload
[2];
615 dw8
= clip_plane_enable
<< GEN8_VS_DW8_UCP_CLIP_ENABLES__SHIFT
;
617 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
619 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_VS
) | (cmd_len
- 2);
620 dw
[1] = ilo_shader_get_kernel_offset(vs
);
623 dw
[4] = 0; /* scratch */
631 gen6_disable_3DSTATE_VS(struct ilo_builder
*builder
)
633 const uint8_t cmd_len
= 6;
636 ILO_DEV_ASSERT(builder
->dev
, 6, 7.5);
638 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
640 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_VS
) | (cmd_len
- 2);
649 gen7_disable_3DSTATE_HS(struct ilo_builder
*builder
)
651 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 9 : 7;
654 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
656 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
658 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_HS
) | (cmd_len
- 2);
665 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
672 gen7_3DSTATE_TE(struct ilo_builder
*builder
)
674 const uint8_t cmd_len
= 4;
677 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
679 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
681 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_TE
) | (cmd_len
- 2);
688 gen7_disable_3DSTATE_DS(struct ilo_builder
*builder
)
690 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 9 : 6;
693 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
695 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
697 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_DS
) | (cmd_len
- 2);
703 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
711 gen6_3DSTATE_GS(struct ilo_builder
*builder
,
712 const struct ilo_shader_state
*gs
)
714 const uint8_t cmd_len
= 7;
715 const struct ilo_shader_cso
*cso
;
716 uint32_t dw2
, dw4
, dw5
, dw6
, *dw
;
718 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
720 cso
= ilo_shader_get_kernel_cso(gs
);
721 dw2
= cso
->payload
[0];
722 dw4
= cso
->payload
[1];
723 dw5
= cso
->payload
[2];
724 dw6
= cso
->payload
[3];
726 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
728 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_GS
) | (cmd_len
- 2);
729 dw
[1] = ilo_shader_get_kernel_offset(gs
);
731 dw
[3] = 0; /* scratch */
738 gen6_so_3DSTATE_GS(struct ilo_builder
*builder
,
739 const struct ilo_shader_state
*vs
,
742 const uint8_t cmd_len
= 7;
743 struct ilo_shader_cso cso
;
744 enum ilo_kernel_param param
;
745 uint32_t dw2
, dw4
, dw5
, dw6
, *dw
;
747 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
749 assert(ilo_shader_get_kernel_param(vs
, ILO_KERNEL_VS_GEN6_SO
));
751 switch (verts_per_prim
) {
753 param
= ILO_KERNEL_VS_GEN6_SO_POINT_OFFSET
;
756 param
= ILO_KERNEL_VS_GEN6_SO_LINE_OFFSET
;
759 param
= ILO_KERNEL_VS_GEN6_SO_TRI_OFFSET
;
763 /* cannot use VS's CSO */
764 ilo_gpe_init_gs_cso(builder
->dev
, vs
, &cso
);
765 dw2
= cso
.payload
[0];
766 dw4
= cso
.payload
[1];
767 dw5
= cso
.payload
[2];
768 dw6
= cso
.payload
[3];
770 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
772 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_GS
) | (cmd_len
- 2);
773 dw
[1] = ilo_shader_get_kernel_offset(vs
) +
774 ilo_shader_get_kernel_param(vs
, param
);
783 gen6_disable_3DSTATE_GS(struct ilo_builder
*builder
)
785 const uint8_t cmd_len
= 7;
788 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
790 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
792 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_GS
) | (cmd_len
- 2);
796 /* honor the valid range of URB read length */
797 dw
[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT
;
798 dw
[5] = GEN6_GS_DW5_STATISTICS
;
803 gen6_3DSTATE_GS_SVB_INDEX(struct ilo_builder
*builder
,
804 int index
, unsigned svbi
,
806 bool load_vertex_count
)
808 const uint8_t cmd_len
= 4;
811 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
812 assert(index
>= 0 && index
< 4);
814 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
816 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_GS_SVB_INDEX
) | (cmd_len
- 2);
818 dw
[1] = index
<< GEN6_SVBI_DW1_INDEX__SHIFT
;
819 if (load_vertex_count
)
820 dw
[1] |= GEN6_SVBI_DW1_LOAD_INTERNAL_VERTEX_COUNT
;
827 gen7_3DSTATE_GS(struct ilo_builder
*builder
,
828 const struct ilo_shader_state
*gs
)
830 const uint8_t cmd_len
= 7;
831 const struct ilo_shader_cso
*cso
;
832 uint32_t dw2
, dw4
, dw5
, *dw
;
834 ILO_DEV_ASSERT(builder
->dev
, 7, 7.5);
836 cso
= ilo_shader_get_kernel_cso(gs
);
837 dw2
= cso
->payload
[0];
838 dw4
= cso
->payload
[1];
839 dw5
= cso
->payload
[2];
841 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
843 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_GS
) | (cmd_len
- 2);
844 dw
[1] = ilo_shader_get_kernel_offset(gs
);
846 dw
[3] = 0; /* scratch */
853 gen7_disable_3DSTATE_GS(struct ilo_builder
*builder
)
855 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 10 : 7;
858 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
860 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
862 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_GS
) | (cmd_len
- 2);
868 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
869 dw
[7] = GEN8_GS_DW7_STATISTICS
;
873 dw
[5] = GEN7_GS_DW5_STATISTICS
;
879 gen7_3DSTATE_STREAMOUT(struct ilo_builder
*builder
,
880 const struct ilo_state_sol
*sol
)
882 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 5 : 3;
885 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
887 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
889 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_STREAMOUT
) | (cmd_len
- 2);
890 /* see sol_set_gen7_3DSTATE_STREAMOUT() */
893 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
900 gen7_3DSTATE_SO_DECL_LIST(struct ilo_builder
*builder
,
901 const struct ilo_state_sol
*sol
)
904 * Note that "DWord Length" has 9 bits for this command and the type of
905 * cmd_len cannot be uint8_t.
911 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
913 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(7.5)) {
914 cmd_decl_count
= sol
->decl_count
;
917 * From the Ivy Bridge PRM, volume 2 part 1, page 201:
919 * "Errata: All 128 decls for all four streams must be included
920 * whenever this command is issued. The "Num Entries [n]" fields
921 * still contain the actual numbers of valid decls."
923 cmd_decl_count
= 128;
926 cmd_len
= 3 + 2 * cmd_decl_count
;
928 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
930 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_SO_DECL_LIST
) | (cmd_len
- 2);
931 /* see sol_set_gen7_3DSTATE_SO_DECL_LIST() */
934 memcpy(&dw
[3], sol
->decl
, sizeof(sol
->decl
[0]) * sol
->decl_count
);
936 if (sol
->decl_count
< cmd_decl_count
) {
937 memset(&dw
[3 + 2 * sol
->decl_count
], 0, sizeof(sol
->decl
[0]) *
938 cmd_decl_count
- sol
->decl_count
);
943 gen7_3DSTATE_SO_BUFFER(struct ilo_builder
*builder
, int index
, int stride
,
944 const struct pipe_stream_output_target
*so_target
)
946 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 8 : 4;
947 struct ilo_buffer
*buf
;
952 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
954 buf
= ilo_buffer(so_target
->buffer
);
957 assert(stride
% 4 == 0);
958 assert(so_target
->buffer_offset
% 4 == 0);
961 start
= so_target
->buffer_offset
& ~3;
962 end
= (start
+ so_target
->buffer_size
) & ~3;
964 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
966 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_SO_BUFFER
) | (cmd_len
- 2);
967 dw
[1] = index
<< GEN7_SO_BUF_DW1_INDEX__SHIFT
|
970 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
971 dw
[1] |= builder
->mocs
<< GEN8_SO_BUF_DW1_MOCS__SHIFT
;
978 ilo_builder_batch_reloc64(builder
, pos
+ 2,
979 buf
->bo
, start
, INTEL_RELOC_WRITE
);
981 dw
[1] |= builder
->mocs
<< GEN7_SO_BUF_DW1_MOCS__SHIFT
;
983 ilo_builder_batch_reloc(builder
, pos
+ 2,
984 buf
->bo
, start
, INTEL_RELOC_WRITE
);
985 ilo_builder_batch_reloc(builder
, pos
+ 3,
986 buf
->bo
, end
, INTEL_RELOC_WRITE
);
991 gen7_disable_3DSTATE_SO_BUFFER(struct ilo_builder
*builder
, int index
)
993 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 8 : 4;
996 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
998 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
1000 dw
[0] = GEN7_RENDER_CMD(3D
, 3DSTATE_SO_BUFFER
) | (cmd_len
- 2);
1001 dw
[1] = index
<< GEN7_SO_BUF_DW1_INDEX__SHIFT
;
1005 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
1014 gen6_3DSTATE_BINDING_TABLE_POINTERS(struct ilo_builder
*builder
,
1015 uint32_t vs_binding_table
,
1016 uint32_t gs_binding_table
,
1017 uint32_t ps_binding_table
)
1019 const uint8_t cmd_len
= 4;
1022 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
1024 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
1026 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_BINDING_TABLE_POINTERS
) |
1027 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED
|
1028 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED
|
1029 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED
|
1031 dw
[1] = vs_binding_table
;
1032 dw
[2] = gs_binding_table
;
1033 dw
[3] = ps_binding_table
;
1037 gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct ilo_builder
*builder
,
1038 uint32_t vs_sampler_state
,
1039 uint32_t gs_sampler_state
,
1040 uint32_t ps_sampler_state
)
1042 const uint8_t cmd_len
= 4;
1045 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
1047 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
1049 dw
[0] = GEN6_RENDER_CMD(3D
, 3DSTATE_SAMPLER_STATE_POINTERS
) |
1050 GEN6_SAMPLER_PTR_DW0_VS_CHANGED
|
1051 GEN6_SAMPLER_PTR_DW0_GS_CHANGED
|
1052 GEN6_SAMPLER_PTR_DW0_PS_CHANGED
|
1054 dw
[1] = vs_sampler_state
;
1055 dw
[2] = gs_sampler_state
;
1056 dw
[3] = ps_sampler_state
;
1060 gen7_3dstate_pointer(struct ilo_builder
*builder
,
1061 int subop
, uint32_t pointer
)
1063 const uint32_t cmd
= GEN6_RENDER_TYPE_RENDER
|
1064 GEN6_RENDER_SUBTYPE_3D
|
1066 const uint8_t cmd_len
= 2;
1069 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
1071 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
1073 dw
[0] = cmd
| (cmd_len
- 2);
1078 gen7_3DSTATE_BINDING_TABLE_POINTERS_VS(struct ilo_builder
*builder
,
1079 uint32_t binding_table
)
1081 gen7_3dstate_pointer(builder
,
1082 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS
,
1087 gen7_3DSTATE_BINDING_TABLE_POINTERS_HS(struct ilo_builder
*builder
,
1088 uint32_t binding_table
)
1090 gen7_3dstate_pointer(builder
,
1091 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS
,
1096 gen7_3DSTATE_BINDING_TABLE_POINTERS_DS(struct ilo_builder
*builder
,
1097 uint32_t binding_table
)
1099 gen7_3dstate_pointer(builder
,
1100 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS
,
1105 gen7_3DSTATE_BINDING_TABLE_POINTERS_GS(struct ilo_builder
*builder
,
1106 uint32_t binding_table
)
1108 gen7_3dstate_pointer(builder
,
1109 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS
,
1114 gen7_3DSTATE_SAMPLER_STATE_POINTERS_VS(struct ilo_builder
*builder
,
1115 uint32_t sampler_state
)
1117 gen7_3dstate_pointer(builder
,
1118 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS
,
1123 gen7_3DSTATE_SAMPLER_STATE_POINTERS_HS(struct ilo_builder
*builder
,
1124 uint32_t sampler_state
)
1126 gen7_3dstate_pointer(builder
,
1127 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS
,
1132 gen7_3DSTATE_SAMPLER_STATE_POINTERS_DS(struct ilo_builder
*builder
,
1133 uint32_t sampler_state
)
1135 gen7_3dstate_pointer(builder
,
1136 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS
,
1141 gen7_3DSTATE_SAMPLER_STATE_POINTERS_GS(struct ilo_builder
*builder
,
1142 uint32_t sampler_state
)
1144 gen7_3dstate_pointer(builder
,
1145 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS
,
1150 gen6_3dstate_constant(struct ilo_builder
*builder
, int subop
,
1151 const uint32_t *bufs
, const int *sizes
,
1154 const uint32_t cmd
= GEN6_RENDER_TYPE_RENDER
|
1155 GEN6_RENDER_SUBTYPE_3D
|
1157 const uint8_t cmd_len
= 5;
1158 unsigned buf_enabled
= 0x0;
1159 uint32_t buf_dw
[4], *dw
;
1160 int max_read_length
, total_read_length
;
1163 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
1165 assert(num_bufs
<= 4);
1168 * From the Sandy Bridge PRM, volume 2 part 1, page 138:
1170 * "(3DSTATE_CONSTANT_VS) The sum of all four read length fields (each
1171 * incremented to represent the actual read length) must be less than
1174 * From the Sandy Bridge PRM, volume 2 part 1, page 161:
1176 * "(3DSTATE_CONSTANT_GS) The sum of all four read length fields (each
1177 * incremented to represent the actual read length) must be less than
1180 * From the Sandy Bridge PRM, volume 2 part 1, page 287:
1182 * "(3DSTATE_CONSTANT_PS) The sum of all four read length fields (each
1183 * incremented to represent the actual read length) must be less than
1187 case GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS
:
1188 max_read_length
= 32;
1190 case GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS
:
1191 case GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS
:
1192 max_read_length
= 64;
1195 assert(!"unknown pcb subop");
1196 max_read_length
= 0;
1200 total_read_length
= 0;
1201 for (i
= 0; i
< 4; i
++) {
1202 if (i
< num_bufs
&& sizes
[i
]) {
1203 /* in 256-bit units */
1204 const int read_len
= (sizes
[i
] + 31) / 32;
1206 assert(bufs
[i
] % 32 == 0);
1207 assert(read_len
<= 32);
1209 buf_enabled
|= 1 << i
;
1210 buf_dw
[i
] = bufs
[i
] | (read_len
- 1);
1212 total_read_length
+= read_len
;
1218 assert(total_read_length
<= max_read_length
);
1220 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
1222 dw
[0] = cmd
| (cmd_len
- 2) |
1223 buf_enabled
<< GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT
|
1224 builder
->mocs
<< GEN6_CONSTANT_DW0_MOCS__SHIFT
;
1226 memcpy(&dw
[1], buf_dw
, sizeof(buf_dw
));
1230 gen6_3DSTATE_CONSTANT_VS(struct ilo_builder
*builder
,
1231 const uint32_t *bufs
, const int *sizes
,
1234 gen6_3dstate_constant(builder
, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS
,
1235 bufs
, sizes
, num_bufs
);
1239 gen6_3DSTATE_CONSTANT_GS(struct ilo_builder
*builder
,
1240 const uint32_t *bufs
, const int *sizes
,
1243 gen6_3dstate_constant(builder
, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS
,
1244 bufs
, sizes
, num_bufs
);
1248 gen7_3dstate_constant(struct ilo_builder
*builder
,
1250 const uint32_t *bufs
, const int *sizes
,
1253 const uint32_t cmd
= GEN6_RENDER_TYPE_RENDER
|
1254 GEN6_RENDER_SUBTYPE_3D
|
1256 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 11 : 7;
1257 uint32_t payload
[6], *dw
;
1258 int total_read_length
, i
;
1260 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
1262 /* VS, HS, DS, GS, and PS variants */
1263 assert(subop
>= GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS
&&
1264 subop
<= GEN7_RENDER_OPCODE_3DSTATE_CONSTANT_DS
&&
1265 subop
!= GEN6_RENDER_OPCODE_3DSTATE_SAMPLE_MASK
);
1267 assert(num_bufs
<= 4);
1272 total_read_length
= 0;
1273 for (i
= 0; i
< 4; i
++) {
1277 * From the Ivy Bridge PRM, volume 2 part 1, page 112:
1279 * "Constant buffers must be enabled in order from Constant Buffer 0
1280 * to Constant Buffer 3 within this command. For example, it is
1281 * not allowed to enable Constant Buffer 1 by programming a
1282 * non-zero value in the VS Constant Buffer 1 Read Length without a
1283 * non-zero value in VS Constant Buffer 0 Read Length."
1285 if (i
>= num_bufs
|| !sizes
[i
]) {
1286 for (; i
< 4; i
++) {
1287 assert(i
>= num_bufs
|| !sizes
[i
]);
1293 /* read lengths are in 256-bit units */
1294 read_len
= (sizes
[i
] + 31) / 32;
1295 /* the lower 5 bits are used for memory object control state */
1296 assert(bufs
[i
] % 32 == 0);
1298 payload
[i
/ 2] |= read_len
<< ((i
% 2) ? 16 : 0);
1299 payload
[2 + i
] = bufs
[i
];
1301 total_read_length
+= read_len
;
1305 * From the Ivy Bridge PRM, volume 2 part 1, page 113:
1307 * "The sum of all four read length fields must be less than or equal
1308 * to the size of 64"
1310 assert(total_read_length
<= 64);
1312 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
1314 dw
[0] = cmd
| (cmd_len
- 2);
1315 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
1327 payload
[2] |= builder
->mocs
<< GEN7_CONSTANT_DW_ADDR_MOCS__SHIFT
;
1329 memcpy(&dw
[1], payload
, sizeof(payload
));
1334 gen7_3DSTATE_CONSTANT_VS(struct ilo_builder
*builder
,
1335 const uint32_t *bufs
, const int *sizes
,
1338 gen7_3dstate_constant(builder
, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS
,
1339 bufs
, sizes
, num_bufs
);
1343 gen7_3DSTATE_CONSTANT_HS(struct ilo_builder
*builder
,
1344 const uint32_t *bufs
, const int *sizes
,
1347 gen7_3dstate_constant(builder
, GEN7_RENDER_OPCODE_3DSTATE_CONSTANT_HS
,
1348 bufs
, sizes
, num_bufs
);
1352 gen7_3DSTATE_CONSTANT_DS(struct ilo_builder
*builder
,
1353 const uint32_t *bufs
, const int *sizes
,
1356 gen7_3dstate_constant(builder
, GEN7_RENDER_OPCODE_3DSTATE_CONSTANT_DS
,
1357 bufs
, sizes
, num_bufs
);
1361 gen7_3DSTATE_CONSTANT_GS(struct ilo_builder
*builder
,
1362 const uint32_t *bufs
, const int *sizes
,
1365 gen7_3dstate_constant(builder
, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS
,
1366 bufs
, sizes
, num_bufs
);
1369 static inline uint32_t
1370 gen6_BINDING_TABLE_STATE(struct ilo_builder
*builder
,
1371 const uint32_t *surface_states
,
1372 int num_surface_states
)
1374 const int state_align
= 32;
1375 const int state_len
= num_surface_states
;
1376 uint32_t state_offset
, *dw
;
1378 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
1381 * From the Sandy Bridge PRM, volume 4 part 1, page 69:
1383 * "It is stored as an array of up to 256 elements..."
1385 assert(num_surface_states
<= 256);
1387 if (!num_surface_states
)
1390 state_offset
= ilo_builder_surface_pointer(builder
,
1391 ILO_BUILDER_ITEM_BINDING_TABLE
, state_align
, state_len
, &dw
);
1392 memcpy(dw
, surface_states
, state_len
<< 2);
1394 return state_offset
;
1397 static inline uint32_t
1398 gen6_SURFACE_STATE(struct ilo_builder
*builder
,
1399 const struct ilo_state_surface
*surf
)
1401 int state_align
, state_len
;
1402 uint32_t state_offset
, *dw
;
1404 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
1406 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
1410 state_offset
= ilo_builder_surface_pointer(builder
,
1411 ILO_BUILDER_ITEM_SURFACE
, state_align
, state_len
, &dw
);
1412 memcpy(dw
, surf
->surface
, state_len
<< 2);
1415 const uint32_t mocs
= (surf
->scanout
) ?
1416 (GEN8_MOCS_MT_PTE
| GEN8_MOCS_CT_L3
) : builder
->mocs
;
1418 dw
[1] |= mocs
<< GEN8_SURFACE_DW1_MOCS__SHIFT
;
1420 ilo_builder_surface_reloc64(builder
, state_offset
, 8, surf
->bo
,
1421 surf
->surface
[8], (surf
->readonly
) ? 0 : INTEL_RELOC_WRITE
);
1425 state_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(7)) ? 8 : 6;
1427 state_offset
= ilo_builder_surface_pointer(builder
,
1428 ILO_BUILDER_ITEM_SURFACE
, state_align
, state_len
, &dw
);
1429 memcpy(dw
, surf
->surface
, state_len
<< 2);
1433 * For scanouts, we should not enable caching in LLC. Since we only
1434 * enable that on Gen8+, we are fine here.
1436 dw
[5] |= builder
->mocs
<< GEN6_SURFACE_DW5_MOCS__SHIFT
;
1438 ilo_builder_surface_reloc(builder
, state_offset
, 1, surf
->bo
,
1439 surf
->surface
[1], (surf
->readonly
) ? 0 : INTEL_RELOC_WRITE
);
1443 return state_offset
;
1446 static inline uint32_t
1447 gen6_so_SURFACE_STATE(struct ilo_builder
*builder
,
1448 const struct pipe_stream_output_target
*so
,
1449 const struct pipe_stream_output_info
*so_info
,
1452 struct ilo_buffer
*buf
= ilo_buffer(so
->buffer
);
1453 struct ilo_state_surface_buffer_info info
;
1454 struct ilo_state_surface surf
;
1456 ILO_DEV_ASSERT(builder
->dev
, 6, 6);
1458 memset(&info
, 0, sizeof(info
));
1460 info
.access
= ILO_STATE_SURFACE_ACCESS_DP_SVB
;
1462 switch (so_info
->output
[so_index
].num_components
) {
1464 info
.format
= GEN6_FORMAT_R32_FLOAT
;
1465 info
.format_size
= 4;
1468 info
.format
= GEN6_FORMAT_R32G32_FLOAT
;
1469 info
.format_size
= 8;
1472 info
.format
= GEN6_FORMAT_R32G32B32_FLOAT
;
1473 info
.format_size
= 12;
1476 info
.format
= GEN6_FORMAT_R32G32B32A32_FLOAT
;
1477 info
.format_size
= 16;
1480 assert(!"unexpected SO components length");
1481 info
.format
= GEN6_FORMAT_R32_FLOAT
;
1482 info
.format_size
= 4;
1487 so_info
->stride
[so_info
->output
[so_index
].output_buffer
] * 4;
1488 info
.offset
= so
->buffer_offset
+ so_info
->output
[so_index
].dst_offset
* 4;
1489 info
.size
= so
->buffer_size
- so_info
->output
[so_index
].dst_offset
* 4;
1491 memset(&surf
, 0, sizeof(surf
));
1492 ilo_state_surface_init_for_buffer(&surf
, builder
->dev
, &info
);
1493 surf
.bo
= info
.buf
->bo
;
1495 return gen6_SURFACE_STATE(builder
, &surf
);
1498 static inline uint32_t
1499 gen6_SAMPLER_STATE(struct ilo_builder
*builder
,
1500 const struct ilo_state_sampler
*samplers
,
1501 const uint32_t *sampler_border_colors
,
1504 const int state_align
= 32;
1505 const int state_len
= 4 * sampler_count
;
1506 uint32_t state_offset
, *dw
;
1509 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
1512 * From the Sandy Bridge PRM, volume 4 part 1, page 101:
1514 * "The sampler state is stored as an array of up to 16 elements..."
1516 assert(sampler_count
<= 16);
1522 * From the Sandy Bridge PRM, volume 2 part 1, page 132:
1524 * "(Sampler Count of 3DSTATE_VS) Specifies how many samplers (in
1525 * multiples of 4) the vertex shader 0 kernel uses. Used only for
1526 * prefetching the associated sampler state entries.
1528 * It also applies to other shader stages.
1530 ilo_builder_dynamic_pad_top(builder
, 4 * (4 - (sampler_count
% 4)));
1532 state_offset
= ilo_builder_dynamic_pointer(builder
,
1533 ILO_BUILDER_ITEM_SAMPLER
, state_align
, state_len
, &dw
);
1535 for (i
= 0; i
< sampler_count
; i
++) {
1536 /* see sampler_set_gen6_SAMPLER_STATE() */
1537 dw
[0] = samplers
[i
].sampler
[0];
1538 dw
[1] = samplers
[i
].sampler
[1];
1539 dw
[3] = samplers
[i
].sampler
[2];
1541 assert(!(sampler_border_colors
[i
] & 0x1f));
1542 dw
[2] = sampler_border_colors
[i
];
1547 return state_offset
;
1550 static inline uint32_t
1551 gen6_SAMPLER_BORDER_COLOR_STATE(struct ilo_builder
*builder
,
1552 const struct ilo_state_sampler_border
*border
)
1554 const int state_align
=
1555 (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 64 : 32;
1556 const int state_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(7)) ? 4 : 12;
1558 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
1561 * see border_set_gen6_SAMPLER_BORDER_COLOR_STATE() and
1562 * border_set_gen7_SAMPLER_BORDER_COLOR_STATE()
1564 return ilo_builder_dynamic_write(builder
, ILO_BUILDER_ITEM_BLOB
,
1565 state_align
, state_len
, border
->color
);
1568 static inline uint32_t
1569 gen6_push_constant_buffer(struct ilo_builder
*builder
,
1570 int size
, void **pcb
)
1573 * For all VS, GS, FS, and CS push constant buffers, they must be aligned
1574 * to 32 bytes, and their sizes are specified in 256-bit units.
1576 const int state_align
= 32;
1577 const int state_len
= align(size
, 32) / 4;
1578 uint32_t state_offset
;
1581 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
1583 state_offset
= ilo_builder_dynamic_pointer(builder
,
1584 ILO_BUILDER_ITEM_BLOB
, state_align
, state_len
, (uint32_t **) &buf
);
1586 /* zero out the unused range */
1587 if (size
< state_len
* 4)
1588 memset(&buf
[size
], 0, state_len
* 4 - size
);
1593 return state_offset
;
1596 static inline uint32_t
1597 gen6_user_vertex_buffer(struct ilo_builder
*builder
,
1598 int size
, const void *vertices
)
1600 const int state_align
= 8;
1601 const int state_len
= size
/ 4;
1603 ILO_DEV_ASSERT(builder
->dev
, 6, 7.5);
1605 assert(size
% 4 == 0);
1607 return ilo_builder_dynamic_write(builder
, ILO_BUILDER_ITEM_BLOB
,
1608 state_align
, state_len
, vertices
);
1611 #endif /* ILO_BUILDER_3D_TOP_H */