i965: Periodically dump the list of monitors if INTEL_DEBUG=perfmon.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_batchbuffer.c
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "intel_batchbuffer.h"
29 #include "intel_buffer_objects.h"
30 #include "intel_reg.h"
31 #include "intel_bufmgr.h"
32 #include "intel_buffers.h"
33 #include "brw_context.h"
34
35 static void
36 intel_batchbuffer_reset(struct brw_context *brw);
37
38 struct cached_batch_item {
39 struct cached_batch_item *next;
40 uint16_t header;
41 uint16_t size;
42 };
43
44 void
45 intel_batchbuffer_clear_cache(struct brw_context *brw)
46 {
47 struct cached_batch_item *item = brw->batch.cached_items;
48
49 while (item) {
50 struct cached_batch_item *next = item->next;
51 free(item);
52 item = next;
53 }
54
55 brw->batch.cached_items = NULL;
56 }
57
58 void
59 intel_batchbuffer_init(struct brw_context *brw)
60 {
61 intel_batchbuffer_reset(brw);
62
63 if (brw->gen >= 6) {
64 /* We can't just use brw_state_batch to get a chunk of space for
65 * the gen6 workaround because it involves actually writing to
66 * the buffer, and the kernel doesn't let us write to the batch.
67 */
68 brw->batch.workaround_bo = drm_intel_bo_alloc(brw->bufmgr,
69 "pipe_control workaround",
70 4096, 4096);
71 }
72
73 brw->batch.need_workaround_flush = true;
74
75 if (!brw->has_llc) {
76 brw->batch.cpu_map = malloc(BATCH_SZ);
77 brw->batch.map = brw->batch.cpu_map;
78 }
79 }
80
81 static void
82 intel_batchbuffer_reset(struct brw_context *brw)
83 {
84 if (brw->batch.last_bo != NULL) {
85 drm_intel_bo_unreference(brw->batch.last_bo);
86 brw->batch.last_bo = NULL;
87 }
88 brw->batch.last_bo = brw->batch.bo;
89
90 intel_batchbuffer_clear_cache(brw);
91
92 brw->batch.bo = drm_intel_bo_alloc(brw->bufmgr, "batchbuffer",
93 BATCH_SZ, 4096);
94 if (brw->has_llc) {
95 drm_intel_bo_map(brw->batch.bo, true);
96 brw->batch.map = brw->batch.bo->virtual;
97 }
98
99 brw->batch.reserved_space = BATCH_RESERVED;
100 brw->batch.state_batch_offset = brw->batch.bo->size;
101 brw->batch.used = 0;
102 brw->batch.needs_sol_reset = false;
103
104 /* We don't know what ring the new batch will be sent to until we see the
105 * first BEGIN_BATCH or BEGIN_BATCH_BLT. Mark it as unknown.
106 */
107 brw->batch.ring = UNKNOWN_RING;
108 }
109
110 void
111 intel_batchbuffer_save_state(struct brw_context *brw)
112 {
113 brw->batch.saved.used = brw->batch.used;
114 brw->batch.saved.reloc_count =
115 drm_intel_gem_bo_get_reloc_count(brw->batch.bo);
116 }
117
118 void
119 intel_batchbuffer_reset_to_saved(struct brw_context *brw)
120 {
121 drm_intel_gem_bo_clear_relocs(brw->batch.bo, brw->batch.saved.reloc_count);
122
123 brw->batch.used = brw->batch.saved.used;
124 if (brw->batch.used == 0)
125 brw->batch.ring = UNKNOWN_RING;
126
127 /* Cached batch state is dead, since we just cleared some unknown part of the
128 * batchbuffer. Assume that the caller resets any other state necessary.
129 */
130 intel_batchbuffer_clear_cache(brw);
131 }
132
133 void
134 intel_batchbuffer_free(struct brw_context *brw)
135 {
136 free(brw->batch.cpu_map);
137 drm_intel_bo_unreference(brw->batch.last_bo);
138 drm_intel_bo_unreference(brw->batch.bo);
139 drm_intel_bo_unreference(brw->batch.workaround_bo);
140 intel_batchbuffer_clear_cache(brw);
141 }
142
143 static void
144 do_batch_dump(struct brw_context *brw)
145 {
146 struct drm_intel_decode *decode;
147 struct intel_batchbuffer *batch = &brw->batch;
148 int ret;
149
150 decode = drm_intel_decode_context_alloc(brw->intelScreen->deviceID);
151 if (!decode)
152 return;
153
154 ret = drm_intel_bo_map(batch->bo, false);
155 if (ret == 0) {
156 drm_intel_decode_set_batch_pointer(decode,
157 batch->bo->virtual,
158 batch->bo->offset,
159 batch->used);
160 } else {
161 fprintf(stderr,
162 "WARNING: failed to map batchbuffer (%s), "
163 "dumping uploaded data instead.\n", strerror(ret));
164
165 drm_intel_decode_set_batch_pointer(decode,
166 batch->map,
167 batch->bo->offset,
168 batch->used);
169 }
170
171 drm_intel_decode(decode);
172
173 drm_intel_decode_context_free(decode);
174
175 if (ret == 0) {
176 drm_intel_bo_unmap(batch->bo);
177
178 brw_debug_batch(brw);
179 }
180 }
181
182 void
183 intel_batchbuffer_emit_render_ring_prelude(struct brw_context *brw)
184 {
185 /* Without hardware contexts, we need to capture the pipeline statistics
186 * registers at the start and end of each render ring batch, so we can see
187 * what that batch contributed. Emit state packets to write them to a BO.
188 */
189 brw_emit_query_begin(brw);
190 }
191
192 /**
193 * Called when starting a new batch buffer.
194 */
195 static void
196 brw_new_batch(struct brw_context *brw)
197 {
198 /* Create a new batchbuffer and reset the associated state: */
199 intel_batchbuffer_reset(brw);
200
201 /* If the kernel supports hardware contexts, then most hardware state is
202 * preserved between batches; we only need to re-emit state that is required
203 * to be in every batch. Otherwise we need to re-emit all the state that
204 * would otherwise be stored in the context (which for all intents and
205 * purposes means everything).
206 */
207 if (brw->hw_ctx == NULL)
208 brw->state.dirty.brw |= BRW_NEW_CONTEXT;
209
210 brw->state.dirty.brw |= BRW_NEW_BATCH;
211
212 /* Assume that the last command before the start of our batch was a
213 * primitive, for safety.
214 */
215 brw->batch.need_workaround_flush = true;
216
217 brw->state_batch_count = 0;
218
219 brw->ib.type = -1;
220
221 /* We need to periodically reap the shader time results, because rollover
222 * happens every few seconds. We also want to see results every once in a
223 * while, because many programs won't cleanly destroy our context, so the
224 * end-of-run printout may not happen.
225 */
226 if (INTEL_DEBUG & DEBUG_SHADER_TIME)
227 brw_collect_and_report_shader_time(brw);
228
229 if (INTEL_DEBUG & DEBUG_PERFMON)
230 brw_dump_perf_monitors(brw);
231 }
232
233 /**
234 * Called from intel_batchbuffer_flush before emitting MI_BATCHBUFFER_END and
235 * sending it off.
236 *
237 * This function can emit state (say, to preserve registers that aren't saved
238 * between batches). All of this state MUST fit in the reserved space at the
239 * end of the batchbuffer. If you add more GPU state, increase the reserved
240 * space by updating the BATCH_RESERVED macro.
241 */
242 static void
243 brw_finish_batch(struct brw_context *brw)
244 {
245 /* Capture the closing pipeline statistics register values necessary to
246 * support query objects (in the non-hardware context world).
247 */
248 brw_emit_query_end(brw);
249
250 if (brw->curbe.curbe_bo) {
251 drm_intel_gem_bo_unmap_gtt(brw->curbe.curbe_bo);
252 drm_intel_bo_unreference(brw->curbe.curbe_bo);
253 brw->curbe.curbe_bo = NULL;
254 }
255
256 /* Mark that the current program cache BO has been used by the GPU.
257 * It will be reallocated if we need to put new programs in for the
258 * next batch.
259 */
260 brw->cache.bo_used_by_gpu = true;
261 }
262
263 /* TODO: Push this whole function into bufmgr.
264 */
265 static int
266 do_flush_locked(struct brw_context *brw)
267 {
268 struct intel_batchbuffer *batch = &brw->batch;
269 int ret = 0;
270
271 if (brw->has_llc) {
272 drm_intel_bo_unmap(batch->bo);
273 } else {
274 ret = drm_intel_bo_subdata(batch->bo, 0, 4*batch->used, batch->map);
275 if (ret == 0 && batch->state_batch_offset != batch->bo->size) {
276 ret = drm_intel_bo_subdata(batch->bo,
277 batch->state_batch_offset,
278 batch->bo->size - batch->state_batch_offset,
279 (char *)batch->map + batch->state_batch_offset);
280 }
281 }
282
283 if (!brw->intelScreen->no_hw) {
284 int flags;
285
286 if (brw->gen >= 6 && batch->ring == BLT_RING) {
287 flags = I915_EXEC_BLT;
288 } else {
289 flags = I915_EXEC_RENDER;
290 }
291 if (batch->needs_sol_reset)
292 flags |= I915_EXEC_GEN7_SOL_RESET;
293
294 if (ret == 0) {
295 if (unlikely(INTEL_DEBUG & DEBUG_AUB))
296 brw_annotate_aub(brw);
297 if (brw->hw_ctx == NULL || batch->ring != RENDER_RING) {
298 ret = drm_intel_bo_mrb_exec(batch->bo, 4 * batch->used, NULL, 0, 0,
299 flags);
300 } else {
301 ret = drm_intel_gem_bo_context_exec(batch->bo, brw->hw_ctx,
302 4 * batch->used, flags);
303 }
304 }
305 }
306
307 if (unlikely(INTEL_DEBUG & DEBUG_BATCH))
308 do_batch_dump(brw);
309
310 if (ret != 0) {
311 fprintf(stderr, "intel_do_flush_locked failed: %s\n", strerror(-ret));
312 exit(1);
313 }
314
315 return ret;
316 }
317
318 int
319 _intel_batchbuffer_flush(struct brw_context *brw,
320 const char *file, int line)
321 {
322 int ret;
323
324 if (brw->batch.used == 0)
325 return 0;
326
327 if (brw->first_post_swapbuffers_batch == NULL) {
328 brw->first_post_swapbuffers_batch = brw->batch.bo;
329 drm_intel_bo_reference(brw->first_post_swapbuffers_batch);
330 }
331
332 if (unlikely(INTEL_DEBUG & DEBUG_BATCH)) {
333 int bytes_for_commands = 4 * brw->batch.used;
334 int bytes_for_state = brw->batch.bo->size - brw->batch.state_batch_offset;
335 int total_bytes = bytes_for_commands + bytes_for_state;
336 fprintf(stderr, "%s:%d: Batchbuffer flush with %4db (pkt) + "
337 "%4db (state) = %4db (%0.1f%%)\n", file, line,
338 bytes_for_commands, bytes_for_state,
339 total_bytes,
340 100.0f * total_bytes / BATCH_SZ);
341 }
342
343 brw->batch.reserved_space = 0;
344
345 brw_finish_batch(brw);
346
347 /* Mark the end of the buffer. */
348 intel_batchbuffer_emit_dword(brw, MI_BATCH_BUFFER_END);
349 if (brw->batch.used & 1) {
350 /* Round batchbuffer usage to 2 DWORDs. */
351 intel_batchbuffer_emit_dword(brw, MI_NOOP);
352 }
353
354 intel_upload_finish(brw);
355
356 /* Check that we didn't just wrap our batchbuffer at a bad time. */
357 assert(!brw->no_batch_wrap);
358
359 ret = do_flush_locked(brw);
360
361 if (unlikely(INTEL_DEBUG & DEBUG_SYNC)) {
362 fprintf(stderr, "waiting for idle\n");
363 drm_intel_bo_wait_rendering(brw->batch.bo);
364 }
365
366 /* Start a new batch buffer. */
367 brw_new_batch(brw);
368
369 return ret;
370 }
371
372
373 /* This is the only way buffers get added to the validate list.
374 */
375 bool
376 intel_batchbuffer_emit_reloc(struct brw_context *brw,
377 drm_intel_bo *buffer,
378 uint32_t read_domains, uint32_t write_domain,
379 uint32_t delta)
380 {
381 int ret;
382
383 ret = drm_intel_bo_emit_reloc(brw->batch.bo, 4*brw->batch.used,
384 buffer, delta,
385 read_domains, write_domain);
386 assert(ret == 0);
387 (void)ret;
388
389 /*
390 * Using the old buffer offset, write in what the right data would be, in case
391 * the buffer doesn't move and we can short-circuit the relocation processing
392 * in the kernel
393 */
394 intel_batchbuffer_emit_dword(brw, buffer->offset + delta);
395
396 return true;
397 }
398
399 bool
400 intel_batchbuffer_emit_reloc_fenced(struct brw_context *brw,
401 drm_intel_bo *buffer,
402 uint32_t read_domains,
403 uint32_t write_domain,
404 uint32_t delta)
405 {
406 int ret;
407
408 ret = drm_intel_bo_emit_reloc_fence(brw->batch.bo, 4*brw->batch.used,
409 buffer, delta,
410 read_domains, write_domain);
411 assert(ret == 0);
412 (void)ret;
413
414 /*
415 * Using the old buffer offset, write in what the right data would
416 * be, in case the buffer doesn't move and we can short-circuit the
417 * relocation processing in the kernel
418 */
419 intel_batchbuffer_emit_dword(brw, buffer->offset + delta);
420
421 return true;
422 }
423
424 void
425 intel_batchbuffer_data(struct brw_context *brw,
426 const void *data, GLuint bytes, enum brw_gpu_ring ring)
427 {
428 assert((bytes & 3) == 0);
429 intel_batchbuffer_require_space(brw, bytes, ring);
430 __memcpy(brw->batch.map + brw->batch.used, data, bytes);
431 brw->batch.used += bytes >> 2;
432 }
433
434 void
435 intel_batchbuffer_cached_advance(struct brw_context *brw)
436 {
437 struct cached_batch_item **prev = &brw->batch.cached_items, *item;
438 uint32_t sz = (brw->batch.used - brw->batch.emit) * sizeof(uint32_t);
439 uint32_t *start = brw->batch.map + brw->batch.emit;
440 uint16_t op = *start >> 16;
441
442 while (*prev) {
443 uint32_t *old;
444
445 item = *prev;
446 old = brw->batch.map + item->header;
447 if (op == *old >> 16) {
448 if (item->size == sz && memcmp(old, start, sz) == 0) {
449 if (prev != &brw->batch.cached_items) {
450 *prev = item->next;
451 item->next = brw->batch.cached_items;
452 brw->batch.cached_items = item;
453 }
454 brw->batch.used = brw->batch.emit;
455 assert(brw->batch.used > 0);
456 return;
457 }
458
459 goto emit;
460 }
461 prev = &item->next;
462 }
463
464 item = malloc(sizeof(struct cached_batch_item));
465 if (item == NULL)
466 return;
467
468 item->next = brw->batch.cached_items;
469 brw->batch.cached_items = item;
470
471 emit:
472 item->size = sz;
473 item->header = brw->batch.emit;
474 }
475
476 /**
477 * Restriction [DevSNB, DevIVB]:
478 *
479 * Prior to changing Depth/Stencil Buffer state (i.e. any combination of
480 * 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS, 3DSTATE_STENCIL_BUFFER,
481 * 3DSTATE_HIER_DEPTH_BUFFER) SW must first issue a pipelined depth stall
482 * (PIPE_CONTROL with Depth Stall bit set), followed by a pipelined depth
483 * cache flush (PIPE_CONTROL with Depth Flush Bit set), followed by
484 * another pipelined depth stall (PIPE_CONTROL with Depth Stall bit set),
485 * unless SW can otherwise guarantee that the pipeline from WM onwards is
486 * already flushed (e.g., via a preceding MI_FLUSH).
487 */
488 void
489 intel_emit_depth_stall_flushes(struct brw_context *brw)
490 {
491 assert(brw->gen >= 6 && brw->gen <= 7);
492
493 BEGIN_BATCH(4);
494 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
495 OUT_BATCH(PIPE_CONTROL_DEPTH_STALL);
496 OUT_BATCH(0); /* address */
497 OUT_BATCH(0); /* write data */
498 ADVANCE_BATCH()
499
500 BEGIN_BATCH(4);
501 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
502 OUT_BATCH(PIPE_CONTROL_DEPTH_CACHE_FLUSH);
503 OUT_BATCH(0); /* address */
504 OUT_BATCH(0); /* write data */
505 ADVANCE_BATCH();
506
507 BEGIN_BATCH(4);
508 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
509 OUT_BATCH(PIPE_CONTROL_DEPTH_STALL);
510 OUT_BATCH(0); /* address */
511 OUT_BATCH(0); /* write data */
512 ADVANCE_BATCH();
513 }
514
515 /**
516 * From the Ivybridge PRM, Volume 2 Part 1, Section 3.2 (VS Stage Input):
517 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
518 * stall needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
519 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
520 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL needs
521 * to be sent before any combination of VS associated 3DSTATE."
522 */
523 void
524 gen7_emit_vs_workaround_flush(struct brw_context *brw)
525 {
526 assert(brw->gen == 7);
527
528 BEGIN_BATCH(4);
529 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
530 OUT_BATCH(PIPE_CONTROL_DEPTH_STALL | PIPE_CONTROL_WRITE_IMMEDIATE);
531 OUT_RELOC(brw->batch.workaround_bo,
532 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION, 0);
533 OUT_BATCH(0); /* write data */
534 ADVANCE_BATCH();
535 }
536
537
538 /**
539 * Emit a PIPE_CONTROL command for gen7 with the CS Stall bit set.
540 */
541 void
542 gen7_emit_cs_stall_flush(struct brw_context *brw)
543 {
544 BEGIN_BATCH(4);
545 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
546 /* From p61 of the Ivy Bridge PRM (1.10.4 PIPE_CONTROL Command: DW1[20]
547 * CS Stall):
548 *
549 * One of the following must also be set:
550 * - Render Target Cache Flush Enable ([12] of DW1)
551 * - Depth Cache Flush Enable ([0] of DW1)
552 * - Stall at Pixel Scoreboard ([1] of DW1)
553 * - Depth Stall ([13] of DW1)
554 * - Post-Sync Operation ([13] of DW1)
555 *
556 * We choose to do a Post-Sync Operation (Write Immediate Data), since
557 * it seems like it will incur the least additional performance penalty.
558 */
559 OUT_BATCH(PIPE_CONTROL_CS_STALL | PIPE_CONTROL_WRITE_IMMEDIATE);
560 OUT_RELOC(brw->batch.workaround_bo,
561 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION, 0);
562 OUT_BATCH(0);
563 ADVANCE_BATCH();
564 }
565
566
567 /**
568 * Emits a PIPE_CONTROL with a non-zero post-sync operation, for
569 * implementing two workarounds on gen6. From section 1.4.7.1
570 * "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1:
571 *
572 * [DevSNB-C+{W/A}] Before any depth stall flush (including those
573 * produced by non-pipelined state commands), software needs to first
574 * send a PIPE_CONTROL with no bits set except Post-Sync Operation !=
575 * 0.
576 *
577 * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache Flush Enable
578 * =1, a PIPE_CONTROL with any non-zero post-sync-op is required.
579 *
580 * And the workaround for these two requires this workaround first:
581 *
582 * [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent
583 * BEFORE the pipe-control with a post-sync op and no write-cache
584 * flushes.
585 *
586 * And this last workaround is tricky because of the requirements on
587 * that bit. From section 1.4.7.2.3 "Stall" of the Sandy Bridge PRM
588 * volume 2 part 1:
589 *
590 * "1 of the following must also be set:
591 * - Render Target Cache Flush Enable ([12] of DW1)
592 * - Depth Cache Flush Enable ([0] of DW1)
593 * - Stall at Pixel Scoreboard ([1] of DW1)
594 * - Depth Stall ([13] of DW1)
595 * - Post-Sync Operation ([13] of DW1)
596 * - Notify Enable ([8] of DW1)"
597 *
598 * The cache flushes require the workaround flush that triggered this
599 * one, so we can't use it. Depth stall would trigger the same.
600 * Post-sync nonzero is what triggered this second workaround, so we
601 * can't use that one either. Notify enable is IRQs, which aren't
602 * really our business. That leaves only stall at scoreboard.
603 */
604 void
605 intel_emit_post_sync_nonzero_flush(struct brw_context *brw)
606 {
607 if (!brw->batch.need_workaround_flush)
608 return;
609
610 BEGIN_BATCH(4);
611 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
612 OUT_BATCH(PIPE_CONTROL_CS_STALL |
613 PIPE_CONTROL_STALL_AT_SCOREBOARD);
614 OUT_BATCH(0); /* address */
615 OUT_BATCH(0); /* write data */
616 ADVANCE_BATCH();
617
618 BEGIN_BATCH(4);
619 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
620 OUT_BATCH(PIPE_CONTROL_WRITE_IMMEDIATE);
621 OUT_RELOC(brw->batch.workaround_bo,
622 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION, 0);
623 OUT_BATCH(0); /* write data */
624 ADVANCE_BATCH();
625
626 brw->batch.need_workaround_flush = false;
627 }
628
629 /* Emit a pipelined flush to either flush render and texture cache for
630 * reading from a FBO-drawn texture, or flush so that frontbuffer
631 * render appears on the screen in DRI1.
632 *
633 * This is also used for the always_flush_cache driconf debug option.
634 */
635 void
636 intel_batchbuffer_emit_mi_flush(struct brw_context *brw)
637 {
638 if (brw->gen >= 6) {
639 if (brw->batch.ring == BLT_RING) {
640 BEGIN_BATCH_BLT(4);
641 OUT_BATCH(MI_FLUSH_DW);
642 OUT_BATCH(0);
643 OUT_BATCH(0);
644 OUT_BATCH(0);
645 ADVANCE_BATCH();
646 } else {
647 if (brw->gen == 6) {
648 /* Hardware workaround: SNB B-Spec says:
649 *
650 * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache
651 * Flush Enable =1, a PIPE_CONTROL with any non-zero
652 * post-sync-op is required.
653 */
654 intel_emit_post_sync_nonzero_flush(brw);
655 }
656
657 BEGIN_BATCH(4);
658 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));
659 OUT_BATCH(PIPE_CONTROL_INSTRUCTION_FLUSH |
660 PIPE_CONTROL_WRITE_FLUSH |
661 PIPE_CONTROL_DEPTH_CACHE_FLUSH |
662 PIPE_CONTROL_VF_CACHE_INVALIDATE |
663 PIPE_CONTROL_TC_FLUSH |
664 PIPE_CONTROL_NO_WRITE |
665 PIPE_CONTROL_CS_STALL);
666 OUT_BATCH(0); /* write address */
667 OUT_BATCH(0); /* write data */
668 ADVANCE_BATCH();
669 }
670 } else {
671 BEGIN_BATCH(4);
672 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2) |
673 PIPE_CONTROL_WRITE_FLUSH |
674 PIPE_CONTROL_NO_WRITE);
675 OUT_BATCH(0); /* write address */
676 OUT_BATCH(0); /* write data */
677 OUT_BATCH(0); /* write data */
678 ADVANCE_BATCH();
679 }
680 }