17 #include "intel_bufmgr.h"
18 #include "intel_batchbuffer.h"
20 #include "rendercopy.h"
21 #include "gen8_render.h"
22 #include "intel_reg.h"
25 #include <intel_aub.h>
27 #define VERTEX_SIZE (3*4)
30 static void dump_batch(struct intel_batchbuffer *batch) {
31 int fd = open("/tmp/i965-batchbuffers.dump", O_WRONLY | O_CREAT, 0666);
33 write(fd, batch->buffer, 4096);
38 #define dump_batch(x) do { } while(0)
48 uint32_t sf_clip_state;
51 /* see shaders/ps/blit.g7a */
52 static const uint32_t ps_kernel[][4] = {
54 { 0x0060005a, 0x21403ae8, 0x3a0000c0, 0x008d0040 },
55 { 0x0060005a, 0x21603ae8, 0x3a0000c0, 0x008d0080 },
56 { 0x0060005a, 0x21803ae8, 0x3a0000d0, 0x008d0040 },
57 { 0x0060005a, 0x21a03ae8, 0x3a0000d0, 0x008d0080 },
58 { 0x02800031, 0x2e0022e8, 0x0e000140, 0x08840001 },
59 { 0x05800031, 0x200022e0, 0x0e000e00, 0x90031000 },
62 { 0x00600001, 0x2e000608, 0x00000000, 0x3f800000 },
63 { 0x00600001, 0x2e200608, 0x00000000, 0x3f800000 },
64 { 0x00600001, 0x2e400608, 0x00000000, 0x3f800000 },
65 { 0x00600001, 0x2e600608, 0x00000000, 0x3f800000 },
66 { 0x00600001, 0x2e800608, 0x00000000, 0x3f800000 },
67 { 0x00600001, 0x2ea00608, 0x00000000, 0x3f800000 },
68 { 0x00600001, 0x2ec00608, 0x00000000, 0x3f800000 },
69 { 0x00600001, 0x2ee00608, 0x00000000, 0x3f800000 },
70 { 0x05800031, 0x200022e0, 0x0e000e00, 0x90031000 },
74 /* AUB annotation support */
75 #define MAX_ANNOTATIONS 33
76 struct annotations_context {
77 drm_intel_aub_annotation annotations[MAX_ANNOTATIONS];
82 static void annotation_init(struct annotations_context *ctx)
84 /* ctx->annotations is an array keeping a list of annotations of the
85 * batch buffer ordered by offset. ctx->annotations[0] is thus left
86 * for the command stream and will be filled just before executing
87 * the batch buffer with annotations_add_batch() */
91 static void add_annotation(drm_intel_aub_annotation *a,
92 uint32_t type, uint32_t subtype,
93 uint32_t ending_offset)
97 a->ending_offset = ending_offset;
100 static void annotation_add_batch(struct annotations_context *ctx, size_t size)
102 add_annotation(&ctx->annotations[0], AUB_TRACE_TYPE_BATCH, 0, size);
105 static void annotation_add_state(struct annotations_context *ctx,
107 uint32_t start_offset,
110 igt_assert(ctx->index < MAX_ANNOTATIONS);
112 add_annotation(&ctx->annotations[ctx->index++],
113 AUB_TRACE_TYPE_NOTYPE, 0,
115 add_annotation(&ctx->annotations[ctx->index++],
116 AUB_TRACE_TYPE(state_type),
117 AUB_TRACE_SUBTYPE(state_type),
118 start_offset + size);
121 static void annotation_flush(struct annotations_context *ctx,
122 struct intel_batchbuffer *batch)
124 if (!igt_aub_dump_enabled())
127 drm_intel_bufmgr_gem_set_aub_annotations(batch->bo,
133 batch_used(struct intel_batchbuffer *batch)
135 return batch->ptr - batch->buffer;
139 batch_align(struct intel_batchbuffer *batch, uint32_t align)
141 uint32_t offset = batch_used(batch);
142 offset = ALIGN(offset, align);
143 batch->ptr = batch->buffer + offset;
148 batch_alloc(struct intel_batchbuffer *batch, uint32_t size, uint32_t align)
150 uint32_t offset = batch_align(batch, align);
152 return memset(batch->buffer + offset, 0, size);
156 batch_offset(struct intel_batchbuffer *batch, void *ptr)
158 return (uint8_t *)ptr - batch->buffer;
162 batch_copy(struct intel_batchbuffer *batch, const void *ptr, uint32_t size, uint32_t align)
164 return batch_offset(batch, memcpy(batch_alloc(batch, size, align), ptr, size));
168 gen6_render_flush(struct intel_batchbuffer *batch,
169 drm_intel_context *context, uint32_t batch_end)
173 ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
175 ret = drm_intel_gem_bo_context_exec(batch->bo, context,
177 igt_assert(ret == 0);
180 /* Mostly copy+paste from gen6, except height, width, pitch moved */
182 gen8_bind_buf(struct intel_batchbuffer *batch, struct igt_buf *buf,
183 uint32_t format, int is_dst) {
184 struct gen8_surface_state *ss;
185 uint32_t write_domain, read_domain, offset;
189 write_domain = read_domain = I915_GEM_DOMAIN_RENDER;
192 read_domain = I915_GEM_DOMAIN_SAMPLER;
195 ss = batch_alloc(batch, sizeof(*ss), 64);
196 offset = batch_offset(batch, ss);
197 annotation_add_state(&aub_annotations, AUB_TRACE_SURFACE_STATE,
198 offset, sizeof(*ss));
200 ss->ss0.surface_type = GEN6_SURFACE_2D;
201 ss->ss0.surface_format = format;
202 ss->ss0.render_cache_read_write = 1;
203 ss->ss0.vertical_alignment = 1; /* align 4 */
204 ss->ss0.horizontal_alignment = 1; /* align 4 */
205 if (buf->tiling == I915_TILING_X)
206 ss->ss0.tiled_mode = 2;
207 else if (buf->tiling == I915_TILING_Y)
208 ss->ss0.tiled_mode = 3;
210 ss->ss8.base_addr = buf->bo->offset;
212 ret = drm_intel_bo_emit_reloc(batch->bo,
213 batch_offset(batch, ss) + 8 * 4,
215 read_domain, write_domain);
216 igt_assert(ret == 0);
218 ss->ss2.height = igt_buf_height(buf) - 1;
219 ss->ss2.width = igt_buf_width(buf) - 1;
220 ss->ss3.pitch = buf->stride - 1;
222 ss->ss7.shader_chanel_select_r = 4;
223 ss->ss7.shader_chanel_select_g = 5;
224 ss->ss7.shader_chanel_select_b = 6;
225 ss->ss7.shader_chanel_select_a = 7;
231 gen8_bind_surfaces(struct intel_batchbuffer *batch,
235 uint32_t *binding_table, offset;
237 binding_table = batch_alloc(batch, 8, 32);
238 offset = batch_offset(batch, binding_table);
239 annotation_add_state(&aub_annotations, AUB_TRACE_BINDING_TABLE,
243 gen8_bind_buf(batch, dst, GEN6_SURFACEFORMAT_B8G8R8A8_UNORM, 1);
245 gen8_bind_buf(batch, src, GEN6_SURFACEFORMAT_B8G8R8A8_UNORM, 0);
250 /* Mostly copy+paste from gen6, except wrap modes moved */
252 gen8_create_sampler(struct intel_batchbuffer *batch) {
253 struct gen8_sampler_state *ss;
256 ss = batch_alloc(batch, sizeof(*ss), 64);
257 offset = batch_offset(batch, ss);
258 annotation_add_state(&aub_annotations, AUB_TRACE_SAMPLER_STATE,
259 offset, sizeof(*ss));
261 ss->ss0.min_filter = GEN6_MAPFILTER_NEAREST;
262 ss->ss0.mag_filter = GEN6_MAPFILTER_NEAREST;
263 ss->ss3.r_wrap_mode = GEN6_TEXCOORDMODE_CLAMP;
264 ss->ss3.s_wrap_mode = GEN6_TEXCOORDMODE_CLAMP;
265 ss->ss3.t_wrap_mode = GEN6_TEXCOORDMODE_CLAMP;
267 /* I've experimented with non-normalized coordinates and using the LD
268 * sampler fetch, but couldn't make it work. */
269 ss->ss3.non_normalized_coord = 0;
275 gen8_fill_ps(struct intel_batchbuffer *batch,
276 const uint32_t kernel[][4],
281 offset = batch_copy(batch, kernel, size, 64);
282 annotation_add_state(&aub_annotations, AUB_TRACE_KERNEL_INSTRUCTIONS,
289 * gen7_fill_vertex_buffer_data populate vertex buffer with data.
291 * The vertex buffer consists of 3 vertices to construct a RECTLIST. The 4th
292 * vertex is implied (automatically derived by the HW). Each element has the
293 * destination offset, and the normalized texture offset (src). The rectangle
294 * itself will span the entire subsurface to be copied.
296 * see gen6_emit_vertex_elements
299 gen7_fill_vertex_buffer_data(struct intel_batchbuffer *batch,
301 uint32_t src_x, uint32_t src_y,
302 uint32_t dst_x, uint32_t dst_y,
303 uint32_t width, uint32_t height)
308 batch_align(batch, 8);
311 emit_vertex_2s(batch, dst_x + width, dst_y + height);
312 emit_vertex_normalized(batch, src_x + width, igt_buf_width(src));
313 emit_vertex_normalized(batch, src_y + height, igt_buf_height(src));
315 emit_vertex_2s(batch, dst_x, dst_y + height);
316 emit_vertex_normalized(batch, src_x, igt_buf_width(src));
317 emit_vertex_normalized(batch, src_y + height, igt_buf_height(src));
319 emit_vertex_2s(batch, dst_x, dst_y);
320 emit_vertex_normalized(batch, src_x, igt_buf_width(src));
321 emit_vertex_normalized(batch, src_y, igt_buf_height(src));
323 offset = batch_offset(batch, start);
324 annotation_add_state(&aub_annotations, AUB_TRACE_VERTEX_BUFFER,
325 offset, 3 * VERTEX_SIZE);
330 * gen6_emit_vertex_elements - The vertex elements describe the contents of the
331 * vertex buffer. We pack the vertex buffer in a semi weird way, conforming to
332 * what gen6_rendercopy did. The most straightforward would be to store
333 * everything as floats.
335 * see gen7_fill_vertex_buffer_data() for where the corresponding elements are
339 gen6_emit_vertex_elements(struct intel_batchbuffer *batch) {
342 * dword 0-3: pad (0, 0, 0. 0)
343 * dword 4-7: position (x, y, 0, 1.0),
344 * dword 8-11: texture coordinate 0 (u0, v0, 0, 1.0)
346 OUT_BATCH(GEN6_3DSTATE_VERTEX_ELEMENTS | (3 * 2 + 1 - 2));
348 /* Element state 0. These are 4 dwords of 0 required for the VUE format.
349 * We don't really know or care what they do.
351 OUT_BATCH(0 << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
352 GEN6_SURFACEFORMAT_R32G32B32A32_FLOAT << VE0_FORMAT_SHIFT |
353 0 << VE0_OFFSET_SHIFT); /* we specify 0, but it's really does not exist */
354 OUT_BATCH(GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_0_SHIFT |
355 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_1_SHIFT |
356 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
357 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_3_SHIFT);
359 /* Element state 1 - Our "destination" vertices. These are passed down
360 * through the pipeline, and eventually make it to the pixel shader as
361 * the offsets in the destination surface. It's packed as the 16
362 * signed/scaled because of gen6 rendercopy. I see no particular reason
363 * for doing this though.
365 OUT_BATCH(0 << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
366 GEN6_SURFACEFORMAT_R16G16_SSCALED << VE0_FORMAT_SHIFT |
367 0 << VE0_OFFSET_SHIFT); /* offsets vb in bytes */
368 OUT_BATCH(GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
369 GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
370 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
371 GEN6_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT);
373 /* Element state 2. Last but not least we store the U,V components as
374 * normalized floats. These will be used in the pixel shader to sample
375 * from the source buffer.
377 OUT_BATCH(0 << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
378 GEN6_SURFACEFORMAT_R32G32_FLOAT << VE0_FORMAT_SHIFT |
379 4 << VE0_OFFSET_SHIFT); /* offset vb in bytes */
380 OUT_BATCH(GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
381 GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
382 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
383 GEN6_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT);
387 * gen7_emit_vertex_buffer emit the vertex buffers command
390 * @offset - bytw offset within the @batch where the vertex buffer starts.
392 static void gen7_emit_vertex_buffer(struct intel_batchbuffer *batch,
394 OUT_BATCH(GEN6_3DSTATE_VERTEX_BUFFERS | (1 + (4 * 1) - 2));
395 OUT_BATCH(0 << VB0_BUFFER_INDEX_SHIFT | /* VB 0th index */
396 GEN7_VB0_BUFFER_ADDR_MOD_EN | /* Address Modify Enable */
397 VERTEX_SIZE << VB0_BUFFER_PITCH_SHIFT);
398 OUT_RELOC(batch->bo, I915_GEM_DOMAIN_VERTEX, 0, offset);
400 OUT_BATCH(3 * VERTEX_SIZE);
404 gen6_create_cc_state(struct intel_batchbuffer *batch)
406 struct gen6_color_calc_state *cc_state;
409 cc_state = batch_alloc(batch, sizeof(*cc_state), 64);
410 offset = batch_offset(batch, cc_state);
411 annotation_add_state(&aub_annotations, AUB_TRACE_CC_STATE,
412 offset, sizeof(*cc_state));
418 gen8_create_blend_state(struct intel_batchbuffer *batch)
420 struct gen8_blend_state *blend;
424 blend = batch_alloc(batch, sizeof(*blend), 64);
425 offset = batch_offset(batch, blend);
426 annotation_add_state(&aub_annotations, AUB_TRACE_BLEND_STATE,
427 offset, sizeof(*blend));
429 for (i = 0; i < 16; i++) {
430 blend->bs[i].dest_blend_factor = GEN6_BLENDFACTOR_ZERO;
431 blend->bs[i].source_blend_factor = GEN6_BLENDFACTOR_ONE;
432 blend->bs[i].color_blend_func = GEN6_BLENDFUNCTION_ADD;
433 blend->bs[i].pre_blend_color_clamp = 1;
434 blend->bs[i].color_buffer_blend = 0;
441 gen6_create_cc_viewport(struct intel_batchbuffer *batch)
443 struct gen6_cc_viewport *vp;
446 vp = batch_alloc(batch, sizeof(*vp), 32);
447 offset = batch_offset(batch, vp);
448 annotation_add_state(&aub_annotations, AUB_TRACE_CC_VP_STATE,
449 offset, sizeof(*vp));
451 /* XXX I don't understand this */
452 vp->min_depth = -1.e35;
453 vp->max_depth = 1.e35;
459 gen7_create_sf_clip_viewport(struct intel_batchbuffer *batch) {
460 /* XXX these are likely not needed */
461 struct gen7_sf_clip_viewport *scv_state;
464 scv_state = batch_alloc(batch, sizeof(*scv_state), 64);
465 offset = batch_offset(batch, scv_state);
466 annotation_add_state(&aub_annotations, AUB_TRACE_CLIP_VP_STATE,
467 offset, sizeof(*scv_state));
469 scv_state->guardband.xmin = 0;
470 scv_state->guardband.xmax = 1.0f;
471 scv_state->guardband.ymin = 0;
472 scv_state->guardband.ymax = 1.0f;
478 gen6_create_scissor_rect(struct intel_batchbuffer *batch)
480 struct gen6_scissor_rect *scissor;
483 scissor = batch_alloc(batch, sizeof(*scissor), 64);
484 offset = batch_offset(batch, scissor);
485 annotation_add_state(&aub_annotations, AUB_TRACE_SCISSOR_STATE,
486 offset, sizeof(*scissor));
492 gen8_emit_sip(struct intel_batchbuffer *batch) {
493 OUT_BATCH(GEN6_STATE_SIP | (3 - 2));
499 gen7_emit_push_constants(struct intel_batchbuffer *batch) {
500 OUT_BATCH(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_VS);
502 OUT_BATCH(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_HS);
504 OUT_BATCH(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_DS);
506 OUT_BATCH(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_GS);
508 OUT_BATCH(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS);
513 gen8_emit_state_base_address(struct intel_batchbuffer *batch) {
514 OUT_BATCH(GEN6_STATE_BASE_ADDRESS | (16 - 2));
517 OUT_BATCH(0 | BASE_ADDRESS_MODIFY);
520 /* stateless data port */
521 OUT_BATCH(0 | BASE_ADDRESS_MODIFY);
524 OUT_RELOC(batch->bo, I915_GEM_DOMAIN_SAMPLER, 0, BASE_ADDRESS_MODIFY);
528 OUT_RELOC(batch->bo, I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_INSTRUCTION,
529 0, BASE_ADDRESS_MODIFY);
537 OUT_RELOC(batch->bo, I915_GEM_DOMAIN_INSTRUCTION, 0, BASE_ADDRESS_MODIFY);
540 /* general state buffer size */
541 OUT_BATCH(0xfffff000 | 1);
542 /* dynamic state buffer size */
543 OUT_BATCH(1 << 12 | 1);
544 /* indirect object buffer size */
545 OUT_BATCH(0xfffff000 | 1);
546 /* intruction buffer size */
547 OUT_BATCH(1 << 12 | 1);
551 gen7_emit_urb(struct intel_batchbuffer *batch) {
552 /* XXX: Min valid values from mesa */
553 const int vs_entries = 64;
554 const int vs_size = 2;
555 const int vs_start = 2;
557 OUT_BATCH(GEN7_3DSTATE_URB_VS);
558 OUT_BATCH(vs_entries | ((vs_size - 1) << 16) | (vs_start << 25));
559 OUT_BATCH(GEN7_3DSTATE_URB_GS);
560 OUT_BATCH(vs_start << 25);
561 OUT_BATCH(GEN7_3DSTATE_URB_HS);
562 OUT_BATCH(vs_start << 25);
563 OUT_BATCH(GEN7_3DSTATE_URB_DS);
564 OUT_BATCH(vs_start << 25);
568 gen8_emit_cc(struct intel_batchbuffer *batch) {
569 OUT_BATCH(GEN7_3DSTATE_BLEND_STATE_POINTERS);
570 OUT_BATCH(cc.blend_state | 1);
572 OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS);
573 OUT_BATCH(cc.cc_state | 1);
577 gen8_emit_multisample(struct intel_batchbuffer *batch) {
578 OUT_BATCH(GEN8_3DSTATE_MULTISAMPLE);
581 OUT_BATCH(GEN6_3DSTATE_SAMPLE_MASK);
586 gen8_emit_vs(struct intel_batchbuffer *batch) {
587 OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_VS);
590 OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_VS);
593 OUT_BATCH(GEN6_3DSTATE_CONSTANT_VS | (11 - 2));
605 OUT_BATCH(GEN6_3DSTATE_VS | (9-2));
617 gen8_emit_hs(struct intel_batchbuffer *batch) {
618 OUT_BATCH(GEN7_3DSTATE_CONSTANT_HS | (11 - 2));
630 OUT_BATCH(GEN7_3DSTATE_HS | (9-2));
640 OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_HS);
643 OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_HS);
648 gen8_emit_gs(struct intel_batchbuffer *batch) {
649 OUT_BATCH(GEN7_3DSTATE_CONSTANT_GS | (11 - 2));
661 OUT_BATCH(GEN7_3DSTATE_GS | (10-2));
672 OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_GS);
675 OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_GS);
680 gen8_emit_ds(struct intel_batchbuffer *batch) {
681 OUT_BATCH(GEN7_3DSTATE_CONSTANT_DS | (11 - 2));
693 OUT_BATCH(GEN7_3DSTATE_DS | (9-2));
703 OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_DS);
706 OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_DS);
711 gen8_emit_wm_hz_op(struct intel_batchbuffer *batch) {
712 OUT_BATCH(GEN8_3DSTATE_WM_HZ_OP | (5-2));
720 gen8_emit_null_state(struct intel_batchbuffer *batch) {
721 gen8_emit_wm_hz_op(batch);
723 OUT_BATCH(GEN7_3DSTATE_TE | (4-2));
733 gen7_emit_clip(struct intel_batchbuffer *batch) {
734 OUT_BATCH(GEN6_3DSTATE_CLIP | (4 - 2));
736 OUT_BATCH(0); /* pass-through */
741 gen8_emit_sf(struct intel_batchbuffer *batch)
745 OUT_BATCH(GEN7_3DSTATE_SBE | (4 - 2));
746 OUT_BATCH(1 << GEN7_SBE_NUM_OUTPUTS_SHIFT |
747 GEN8_SBE_FORCE_URB_ENTRY_READ_LENGTH |
748 GEN8_SBE_FORCE_URB_ENTRY_READ_OFFSET |
749 1 << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT |
750 1 << GEN8_SBE_URB_ENTRY_READ_OFFSET_SHIFT);
754 OUT_BATCH(GEN8_3DSTATE_SBE_SWIZ | (11 - 2));
755 for (i = 0; i < 8; i++)
760 OUT_BATCH(GEN8_3DSTATE_RASTER | (5 - 2));
761 OUT_BATCH(GEN8_RASTER_FRONT_WINDING_CCW | GEN8_RASTER_CULL_NONE);
766 OUT_BATCH(GEN6_3DSTATE_SF | (4 - 2));
773 gen8_emit_ps(struct intel_batchbuffer *batch, uint32_t kernel) {
774 const int max_threads = 63;
776 OUT_BATCH(GEN6_3DSTATE_WM | (2 - 2));
777 OUT_BATCH(/* XXX: I don't understand the BARYCENTRIC stuff, but it
778 * appears we need it to put our setup data in the place we
779 * expect (g6, see below) */
780 GEN7_3DSTATE_PS_PERSPECTIVE_PIXEL_BARYCENTRIC);
782 OUT_BATCH(GEN6_3DSTATE_CONSTANT_PS | (11-2));
794 OUT_BATCH(GEN7_3DSTATE_PS | (12-2));
796 OUT_BATCH(0); /* kernel hi */
797 OUT_BATCH(1 << GEN6_3DSTATE_WM_SAMPLER_COUNT_SHITF |
798 2 << GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT);
799 OUT_BATCH(0); /* scratch space stuff */
800 OUT_BATCH(0); /* scratch hi */
801 OUT_BATCH((max_threads - 1) << GEN8_3DSTATE_PS_MAX_THREADS_SHIFT |
802 GEN6_3DSTATE_WM_16_DISPATCH_ENABLE);
803 OUT_BATCH(6 << GEN6_3DSTATE_WM_DISPATCH_START_GRF_0_SHIFT);
804 OUT_BATCH(0); // kernel 1
805 OUT_BATCH(0); /* kernel 1 hi */
806 OUT_BATCH(0); // kernel 2
807 OUT_BATCH(0); /* kernel 2 hi */
809 OUT_BATCH(GEN8_3DSTATE_PS_BLEND | (2 - 2));
810 OUT_BATCH(GEN8_PS_BLEND_HAS_WRITEABLE_RT);
812 OUT_BATCH(GEN8_3DSTATE_PS_EXTRA | (2 - 2));
813 OUT_BATCH(GEN8_PSX_PIXEL_SHADER_VALID | GEN8_PSX_ATTRIBUTE_ENABLE);
817 gen8_emit_depth(struct intel_batchbuffer *batch) {
818 OUT_BATCH(GEN8_3DSTATE_WM_DEPTH_STENCIL | (3 - 2));
822 OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER | (8-2));
831 OUT_BATCH(GEN7_3DSTATE_HIER_DEPTH_BUFFER | (5 - 2));
837 OUT_BATCH(GEN7_3DSTATE_STENCIL_BUFFER | (5 - 2));
845 gen7_emit_clear(struct intel_batchbuffer *batch) {
846 OUT_BATCH(GEN7_3DSTATE_CLEAR_PARAMS | (3-2));
848 OUT_BATCH(1); // clear valid
852 gen6_emit_drawing_rectangle(struct intel_batchbuffer *batch, struct igt_buf *dst)
854 OUT_BATCH(GEN6_3DSTATE_DRAWING_RECTANGLE | (4 - 2));
856 OUT_BATCH((igt_buf_height(dst) - 1) << 16 | (igt_buf_width(dst) - 1));
860 static void gen8_emit_vf_topology(struct intel_batchbuffer *batch)
862 OUT_BATCH(GEN8_3DSTATE_VF_TOPOLOGY);
863 OUT_BATCH(_3DPRIM_RECTLIST);
866 /* Vertex elements MUST be defined before this according to spec */
867 static void gen8_emit_primitive(struct intel_batchbuffer *batch, uint32_t offset)
869 OUT_BATCH(GEN8_3DSTATE_VF_INSTANCING | (3 - 2));
873 OUT_BATCH(GEN6_3DPRIMITIVE | (7-2));
874 OUT_BATCH(0); /* gen8+ ignore the topology type field */
875 OUT_BATCH(3); /* vertex count */
876 OUT_BATCH(0); /* We're specifying this instead with offset in GEN6_3DSTATE_VERTEX_BUFFERS */
877 OUT_BATCH(1); /* single instance */
878 OUT_BATCH(0); /* start instance location */
879 OUT_BATCH(0); /* index buffer offset, ignored */
882 /* The general rule is if it's named gen6 it is directly copied from
883 * gen6_render_copyfunc.
885 * This sets up most of the 3d pipeline, and most of that to NULL state. The
886 * docs aren't specific about exactly what must be set up NULL, but the general
887 * rule is we could be run at any time, and so the most state we set to NULL,
888 * the better our odds of success.
890 * +---------------+ <---- 4096
896 * |_______|_______| <---- 2048 + ?
903 * +---------------+ <---- 0 + ?
905 * The batch commands point to state within tthe batch, so all state offsets should be
906 * 0 < offset < 4096. Both commands and state build upwards, and are constructed
907 * in that order. This means too many batch commands can delete state if not
912 #define BATCH_STATE_SPLIT 2048
914 void gen8_render_copyfunc(struct intel_batchbuffer *batch,
915 drm_intel_context *context,
916 struct igt_buf *src, unsigned src_x, unsigned src_y,
917 unsigned width, unsigned height,
918 struct igt_buf *dst, unsigned dst_x, unsigned dst_y)
920 uint32_t ps_sampler_state, ps_kernel_off, ps_binding_table;
921 uint32_t scissor_state;
922 uint32_t vertex_buffer;
925 intel_batchbuffer_flush_with_context(batch, context);
927 batch_align(batch, 8);
929 batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];
931 annotation_init(&aub_annotations);
933 ps_binding_table = gen8_bind_surfaces(batch, src, dst);
934 ps_sampler_state = gen8_create_sampler(batch);
935 ps_kernel_off = gen8_fill_ps(batch, ps_kernel, sizeof(ps_kernel));
936 vertex_buffer = gen7_fill_vertex_buffer_data(batch, src,
940 cc.cc_state = gen6_create_cc_state(batch);
941 cc.blend_state = gen8_create_blend_state(batch);
942 viewport.cc_state = gen6_create_cc_viewport(batch);
943 viewport.sf_clip_state = gen7_create_sf_clip_viewport(batch);
944 scissor_state = gen6_create_scissor_rect(batch);
945 /* TODO: theree is other state which isn't setup */
947 igt_assert(batch->ptr < &batch->buffer[4095]);
949 batch->ptr = batch->buffer;
951 /* Start emitting the commands. The order roughly follows the mesa blorp
953 OUT_BATCH(GEN6_PIPELINE_SELECT | PIPELINE_SELECT_3D);
955 gen8_emit_sip(batch);
957 gen7_emit_push_constants(batch);
959 gen8_emit_state_base_address(batch);
961 OUT_BATCH(GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC);
962 OUT_BATCH(viewport.cc_state);
963 OUT_BATCH(GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP);
964 OUT_BATCH(viewport.sf_clip_state);
966 gen7_emit_urb(batch);
970 gen8_emit_multisample(batch);
972 gen8_emit_null_state(batch);
974 OUT_BATCH(GEN7_3DSTATE_STREAMOUT | (5-2));
980 gen7_emit_clip(batch);
984 OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_PS);
985 OUT_BATCH(ps_binding_table);
987 OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_PS);
988 OUT_BATCH(ps_sampler_state);
990 gen8_emit_ps(batch, ps_kernel_off);
992 OUT_BATCH(GEN6_3DSTATE_SCISSOR_STATE_POINTERS);
993 OUT_BATCH(scissor_state);
995 gen8_emit_depth(batch);
997 gen7_emit_clear(batch);
999 gen6_emit_drawing_rectangle(batch, dst);
1001 gen7_emit_vertex_buffer(batch, vertex_buffer);
1002 gen6_emit_vertex_elements(batch);
1004 gen8_emit_vf_topology(batch);
1005 gen8_emit_primitive(batch, vertex_buffer);
1007 OUT_BATCH(MI_BATCH_BUFFER_END);
1009 batch_end = batch_align(batch, 8);
1010 igt_assert(batch_end < BATCH_STATE_SPLIT);
1011 annotation_add_batch(&aub_annotations, batch_end);
1015 annotation_flush(&aub_annotations, batch);
1017 gen6_render_flush(batch, context, batch_end);
1018 intel_batchbuffer_reset(batch);