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