i965: Implement a brw_load_register_mem helper function.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_batchbuffer.c
1 /**************************************************************************
2 *
3 * Copyright 2006 VMware, Inc.
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 VMWARE 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->offset64,
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->offset64,
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 /* We may need to enable and snapshot OA counters. */
186 brw_perf_monitor_new_batch(brw);
187 }
188
189 /**
190 * Called when starting a new batch buffer.
191 */
192 static void
193 brw_new_batch(struct brw_context *brw)
194 {
195 /* Create a new batchbuffer and reset the associated state: */
196 intel_batchbuffer_reset(brw);
197
198 /* If the kernel supports hardware contexts, then most hardware state is
199 * preserved between batches; we only need to re-emit state that is required
200 * to be in every batch. Otherwise we need to re-emit all the state that
201 * would otherwise be stored in the context (which for all intents and
202 * purposes means everything).
203 */
204 if (brw->hw_ctx == NULL)
205 brw->state.dirty.brw |= BRW_NEW_CONTEXT;
206
207 brw->state.dirty.brw |= BRW_NEW_BATCH;
208
209 /* Assume that the last command before the start of our batch was a
210 * primitive, for safety.
211 */
212 brw->batch.need_workaround_flush = true;
213
214 brw->state_batch_count = 0;
215
216 brw->ib.type = -1;
217
218 /* We need to periodically reap the shader time results, because rollover
219 * happens every few seconds. We also want to see results every once in a
220 * while, because many programs won't cleanly destroy our context, so the
221 * end-of-run printout may not happen.
222 */
223 if (INTEL_DEBUG & DEBUG_SHADER_TIME)
224 brw_collect_and_report_shader_time(brw);
225
226 if (INTEL_DEBUG & DEBUG_PERFMON)
227 brw_dump_perf_monitors(brw);
228 }
229
230 /**
231 * Called from intel_batchbuffer_flush before emitting MI_BATCHBUFFER_END and
232 * sending it off.
233 *
234 * This function can emit state (say, to preserve registers that aren't saved
235 * between batches). All of this state MUST fit in the reserved space at the
236 * end of the batchbuffer. If you add more GPU state, increase the reserved
237 * space by updating the BATCH_RESERVED macro.
238 */
239 static void
240 brw_finish_batch(struct brw_context *brw)
241 {
242 /* Capture the closing pipeline statistics register values necessary to
243 * support query objects (in the non-hardware context world).
244 */
245 brw_emit_query_end(brw);
246
247 /* We may also need to snapshot and disable OA counters. */
248 if (brw->batch.ring == RENDER_RING)
249 brw_perf_monitor_finish_batch(brw);
250
251 if (brw->curbe.curbe_bo) {
252 drm_intel_gem_bo_unmap_gtt(brw->curbe.curbe_bo);
253 drm_intel_bo_unreference(brw->curbe.curbe_bo);
254 brw->curbe.curbe_bo = NULL;
255 }
256
257 /* Mark that the current program cache BO has been used by the GPU.
258 * It will be reallocated if we need to put new programs in for the
259 * next batch.
260 */
261 brw->cache.bo_used_by_gpu = true;
262 }
263
264 /* TODO: Push this whole function into bufmgr.
265 */
266 static int
267 do_flush_locked(struct brw_context *brw)
268 {
269 struct intel_batchbuffer *batch = &brw->batch;
270 int ret = 0;
271
272 if (brw->has_llc) {
273 drm_intel_bo_unmap(batch->bo);
274 } else {
275 ret = drm_intel_bo_subdata(batch->bo, 0, 4*batch->used, batch->map);
276 if (ret == 0 && batch->state_batch_offset != batch->bo->size) {
277 ret = drm_intel_bo_subdata(batch->bo,
278 batch->state_batch_offset,
279 batch->bo->size - batch->state_batch_offset,
280 (char *)batch->map + batch->state_batch_offset);
281 }
282 }
283
284 if (!brw->intelScreen->no_hw) {
285 int flags;
286
287 if (brw->gen >= 6 && batch->ring == BLT_RING) {
288 flags = I915_EXEC_BLT;
289 } else {
290 flags = I915_EXEC_RENDER;
291 }
292 if (batch->needs_sol_reset)
293 flags |= I915_EXEC_GEN7_SOL_RESET;
294
295 if (ret == 0) {
296 if (unlikely(INTEL_DEBUG & DEBUG_AUB))
297 brw_annotate_aub(brw);
298 if (brw->hw_ctx == NULL || batch->ring != RENDER_RING) {
299 ret = drm_intel_bo_mrb_exec(batch->bo, 4 * batch->used, NULL, 0, 0,
300 flags);
301 } else {
302 ret = drm_intel_gem_bo_context_exec(batch->bo, brw->hw_ctx,
303 4 * batch->used, flags);
304 }
305 }
306 }
307
308 if (unlikely(INTEL_DEBUG & DEBUG_BATCH))
309 do_batch_dump(brw);
310
311 if (ret != 0) {
312 fprintf(stderr, "intel_do_flush_locked failed: %s\n", strerror(-ret));
313 exit(1);
314 }
315
316 return ret;
317 }
318
319 int
320 _intel_batchbuffer_flush(struct brw_context *brw,
321 const char *file, int line)
322 {
323 int ret;
324
325 if (brw->batch.used == 0)
326 return 0;
327
328 if (brw->first_post_swapbuffers_batch == NULL) {
329 brw->first_post_swapbuffers_batch = brw->batch.bo;
330 drm_intel_bo_reference(brw->first_post_swapbuffers_batch);
331 }
332
333 if (unlikely(INTEL_DEBUG & DEBUG_BATCH)) {
334 int bytes_for_commands = 4 * brw->batch.used;
335 int bytes_for_state = brw->batch.bo->size - brw->batch.state_batch_offset;
336 int total_bytes = bytes_for_commands + bytes_for_state;
337 fprintf(stderr, "%s:%d: Batchbuffer flush with %4db (pkt) + "
338 "%4db (state) = %4db (%0.1f%%)\n", file, line,
339 bytes_for_commands, bytes_for_state,
340 total_bytes,
341 100.0f * total_bytes / BATCH_SZ);
342 }
343
344 brw->batch.reserved_space = 0;
345
346 brw_finish_batch(brw);
347
348 /* Mark the end of the buffer. */
349 intel_batchbuffer_emit_dword(brw, MI_BATCH_BUFFER_END);
350 if (brw->batch.used & 1) {
351 /* Round batchbuffer usage to 2 DWORDs. */
352 intel_batchbuffer_emit_dword(brw, MI_NOOP);
353 }
354
355 intel_upload_finish(brw);
356
357 /* Check that we didn't just wrap our batchbuffer at a bad time. */
358 assert(!brw->no_batch_wrap);
359
360 ret = do_flush_locked(brw);
361
362 if (unlikely(INTEL_DEBUG & DEBUG_SYNC)) {
363 fprintf(stderr, "waiting for idle\n");
364 drm_intel_bo_wait_rendering(brw->batch.bo);
365 }
366
367 /* Start a new batch buffer. */
368 brw_new_batch(brw);
369
370 return ret;
371 }
372
373
374 /* This is the only way buffers get added to the validate list.
375 */
376 bool
377 intel_batchbuffer_emit_reloc(struct brw_context *brw,
378 drm_intel_bo *buffer,
379 uint32_t read_domains, uint32_t write_domain,
380 uint32_t delta)
381 {
382 int ret;
383
384 ret = drm_intel_bo_emit_reloc(brw->batch.bo, 4*brw->batch.used,
385 buffer, delta,
386 read_domains, write_domain);
387 assert(ret == 0);
388 (void)ret;
389
390 /*
391 * Using the old buffer offset, write in what the right data would be, in case
392 * the buffer doesn't move and we can short-circuit the relocation processing
393 * in the kernel
394 */
395 intel_batchbuffer_emit_dword(brw, buffer->offset64 + delta);
396
397 return true;
398 }
399
400 bool
401 intel_batchbuffer_emit_reloc64(struct brw_context *brw,
402 drm_intel_bo *buffer,
403 uint32_t read_domains, uint32_t write_domain,
404 uint32_t delta)
405 {
406 int ret = drm_intel_bo_emit_reloc(brw->batch.bo, 4*brw->batch.used,
407 buffer, delta,
408 read_domains, write_domain);
409 assert(ret == 0);
410 (void) ret;
411
412 /* Using the old buffer offset, write in what the right data would be, in
413 * case the buffer doesn't move and we can short-circuit the relocation
414 * processing in the kernel
415 */
416 uint64_t offset = buffer->offset64 + delta;
417 intel_batchbuffer_emit_dword(brw, offset);
418 intel_batchbuffer_emit_dword(brw, offset >> 32);
419
420 return true;
421 }
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 /**
435 * Emit a PIPE_CONTROL with various flushing flags.
436 *
437 * The caller is responsible for deciding what flags are appropriate for the
438 * given generation.
439 */
440 void
441 brw_emit_pipe_control_flush(struct brw_context *brw, uint32_t flags)
442 {
443 if (brw->gen >= 8) {
444 BEGIN_BATCH(6);
445 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (6 - 2));
446 OUT_BATCH(flags);
447 OUT_BATCH(0);
448 OUT_BATCH(0);
449 OUT_BATCH(0);
450 OUT_BATCH(0);
451 ADVANCE_BATCH();
452 } else if (brw->gen >= 6) {
453 BEGIN_BATCH(5);
454 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (5 - 2));
455 OUT_BATCH(flags);
456 OUT_BATCH(0);
457 OUT_BATCH(0);
458 OUT_BATCH(0);
459 ADVANCE_BATCH();
460 } else {
461 BEGIN_BATCH(4);
462 OUT_BATCH(_3DSTATE_PIPE_CONTROL | flags | (4 - 2));
463 OUT_BATCH(0);
464 OUT_BATCH(0);
465 OUT_BATCH(0);
466 ADVANCE_BATCH();
467 }
468 }
469
470 /**
471 * Emit a PIPE_CONTROL that writes to a buffer object.
472 *
473 * \p flags should contain one of the following items:
474 * - PIPE_CONTROL_WRITE_IMMEDIATE
475 * - PIPE_CONTROL_WRITE_TIMESTAMP
476 * - PIPE_CONTROL_WRITE_DEPTH_COUNT
477 */
478 void
479 brw_emit_pipe_control_write(struct brw_context *brw, uint32_t flags,
480 drm_intel_bo *bo, uint32_t offset,
481 uint32_t imm_lower, uint32_t imm_upper)
482 {
483 if (brw->gen >= 8) {
484 BEGIN_BATCH(6);
485 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (6 - 2));
486 OUT_BATCH(flags);
487 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
488 offset);
489 OUT_BATCH(imm_lower);
490 OUT_BATCH(imm_upper);
491 ADVANCE_BATCH();
492 } else if (brw->gen >= 6) {
493 /* PPGTT/GGTT is selected by DW2 bit 2 on Sandybridge, but DW1 bit 24
494 * on later platforms. We always use PPGTT on Gen7+.
495 */
496 unsigned gen6_gtt = brw->gen == 6 ? PIPE_CONTROL_GLOBAL_GTT_WRITE : 0;
497
498 BEGIN_BATCH(5);
499 OUT_BATCH(_3DSTATE_PIPE_CONTROL | (5 - 2));
500 OUT_BATCH(flags);
501 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
502 gen6_gtt | offset);
503 OUT_BATCH(imm_lower);
504 OUT_BATCH(imm_upper);
505 ADVANCE_BATCH();
506 } else {
507 BEGIN_BATCH(4);
508 OUT_BATCH(_3DSTATE_PIPE_CONTROL | flags | (4 - 2));
509 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
510 PIPE_CONTROL_GLOBAL_GTT_WRITE | offset);
511 OUT_BATCH(imm_lower);
512 OUT_BATCH(imm_upper);
513 ADVANCE_BATCH();
514 }
515 }
516
517 /**
518 * Restriction [DevSNB, DevIVB]:
519 *
520 * Prior to changing Depth/Stencil Buffer state (i.e. any combination of
521 * 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS, 3DSTATE_STENCIL_BUFFER,
522 * 3DSTATE_HIER_DEPTH_BUFFER) SW must first issue a pipelined depth stall
523 * (PIPE_CONTROL with Depth Stall bit set), followed by a pipelined depth
524 * cache flush (PIPE_CONTROL with Depth Flush Bit set), followed by
525 * another pipelined depth stall (PIPE_CONTROL with Depth Stall bit set),
526 * unless SW can otherwise guarantee that the pipeline from WM onwards is
527 * already flushed (e.g., via a preceding MI_FLUSH).
528 */
529 void
530 intel_emit_depth_stall_flushes(struct brw_context *brw)
531 {
532 assert(brw->gen >= 6 && brw->gen <= 8);
533
534 brw_emit_pipe_control_flush(brw, PIPE_CONTROL_DEPTH_STALL);
535 brw_emit_pipe_control_flush(brw, PIPE_CONTROL_DEPTH_CACHE_FLUSH);
536 brw_emit_pipe_control_flush(brw, PIPE_CONTROL_DEPTH_STALL);
537 }
538
539 /**
540 * From the Ivybridge PRM, Volume 2 Part 1, Section 3.2 (VS Stage Input):
541 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
542 * stall needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
543 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
544 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL needs
545 * to be sent before any combination of VS associated 3DSTATE."
546 */
547 void
548 gen7_emit_vs_workaround_flush(struct brw_context *brw)
549 {
550 assert(brw->gen >= 7 && brw->gen <= 8);
551 brw_emit_pipe_control_write(brw,
552 PIPE_CONTROL_WRITE_IMMEDIATE
553 | PIPE_CONTROL_DEPTH_STALL,
554 brw->batch.workaround_bo, 0,
555 0, 0);
556 }
557
558
559 /**
560 * Emit a PIPE_CONTROL command for gen7 with the CS Stall bit set.
561 */
562 void
563 gen7_emit_cs_stall_flush(struct brw_context *brw)
564 {
565 brw_emit_pipe_control_write(brw,
566 PIPE_CONTROL_CS_STALL
567 | PIPE_CONTROL_WRITE_IMMEDIATE,
568 brw->batch.workaround_bo, 0,
569 0, 0);
570 }
571
572
573 /**
574 * Emits a PIPE_CONTROL with a non-zero post-sync operation, for
575 * implementing two workarounds on gen6. From section 1.4.7.1
576 * "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1:
577 *
578 * [DevSNB-C+{W/A}] Before any depth stall flush (including those
579 * produced by non-pipelined state commands), software needs to first
580 * send a PIPE_CONTROL with no bits set except Post-Sync Operation !=
581 * 0.
582 *
583 * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache Flush Enable
584 * =1, a PIPE_CONTROL with any non-zero post-sync-op is required.
585 *
586 * And the workaround for these two requires this workaround first:
587 *
588 * [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent
589 * BEFORE the pipe-control with a post-sync op and no write-cache
590 * flushes.
591 *
592 * And this last workaround is tricky because of the requirements on
593 * that bit. From section 1.4.7.2.3 "Stall" of the Sandy Bridge PRM
594 * volume 2 part 1:
595 *
596 * "1 of the following must also be set:
597 * - Render Target Cache Flush Enable ([12] of DW1)
598 * - Depth Cache Flush Enable ([0] of DW1)
599 * - Stall at Pixel Scoreboard ([1] of DW1)
600 * - Depth Stall ([13] of DW1)
601 * - Post-Sync Operation ([13] of DW1)
602 * - Notify Enable ([8] of DW1)"
603 *
604 * The cache flushes require the workaround flush that triggered this
605 * one, so we can't use it. Depth stall would trigger the same.
606 * Post-sync nonzero is what triggered this second workaround, so we
607 * can't use that one either. Notify enable is IRQs, which aren't
608 * really our business. That leaves only stall at scoreboard.
609 */
610 void
611 intel_emit_post_sync_nonzero_flush(struct brw_context *brw)
612 {
613 if (!brw->batch.need_workaround_flush)
614 return;
615
616 brw_emit_pipe_control_flush(brw,
617 PIPE_CONTROL_CS_STALL |
618 PIPE_CONTROL_STALL_AT_SCOREBOARD);
619
620 brw_emit_pipe_control_write(brw, PIPE_CONTROL_WRITE_IMMEDIATE,
621 brw->batch.workaround_bo, 0, 0, 0);
622
623 brw->batch.need_workaround_flush = false;
624 }
625
626 /* Emit a pipelined flush to either flush render and texture cache for
627 * reading from a FBO-drawn texture, or flush so that frontbuffer
628 * render appears on the screen in DRI1.
629 *
630 * This is also used for the always_flush_cache driconf debug option.
631 */
632 void
633 intel_batchbuffer_emit_mi_flush(struct brw_context *brw)
634 {
635 if (brw->batch.ring == BLT_RING && brw->gen >= 6) {
636 BEGIN_BATCH_BLT(4);
637 OUT_BATCH(MI_FLUSH_DW);
638 OUT_BATCH(0);
639 OUT_BATCH(0);
640 OUT_BATCH(0);
641 ADVANCE_BATCH();
642 } else {
643 int flags = PIPE_CONTROL_NO_WRITE | PIPE_CONTROL_WRITE_FLUSH;
644 if (brw->gen >= 6) {
645 flags |= PIPE_CONTROL_INSTRUCTION_FLUSH |
646 PIPE_CONTROL_DEPTH_CACHE_FLUSH |
647 PIPE_CONTROL_VF_CACHE_INVALIDATE |
648 PIPE_CONTROL_TC_FLUSH |
649 PIPE_CONTROL_CS_STALL;
650
651 if (brw->gen == 6) {
652 /* Hardware workaround: SNB B-Spec says:
653 *
654 * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache
655 * Flush Enable =1, a PIPE_CONTROL with any non-zero
656 * post-sync-op is required.
657 */
658 intel_emit_post_sync_nonzero_flush(brw);
659 }
660 }
661 brw_emit_pipe_control_flush(brw, flags);
662 }
663 }
664
665 void
666 brw_load_register_mem(struct brw_context *brw,
667 uint32_t reg,
668 drm_intel_bo *bo,
669 uint32_t read_domains, uint32_t write_domain,
670 uint32_t offset)
671 {
672 /* MI_LOAD_REGISTER_MEM only exists on Gen7+. */
673 assert(brw->gen >= 7);
674
675 if (brw->gen >= 8) {
676 BEGIN_BATCH(4);
677 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM | (4 - 2));
678 OUT_BATCH(reg);
679 OUT_RELOC64(bo, read_domains, write_domain, offset);
680 ADVANCE_BATCH();
681 } else {
682 BEGIN_BATCH(3);
683 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM | (3 - 2));
684 OUT_BATCH(reg);
685 OUT_RELOC(bo, read_domains, write_domain, offset);
686 ADVANCE_BATCH();
687 }
688 }