ae0fd4cd7abc82a1634b3dd18f553ef42a1fac2b
[mesa.git] / src / mesa / drivers / dri / i965 / intel_batchbuffer.c
1 /*
2 * Copyright 2006 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "intel_batchbuffer.h"
27 #include "intel_buffer_objects.h"
28 #include "intel_bufmgr.h"
29 #include "intel_buffers.h"
30 #include "intel_fbo.h"
31 #include "brw_context.h"
32 #include "brw_defines.h"
33 #include "brw_state.h"
34
35 #include <xf86drm.h>
36 #include <i915_drm.h>
37
38 static void
39 intel_batchbuffer_reset(struct intel_batchbuffer *batch, dri_bufmgr *bufmgr,
40 bool has_llc);
41
42 void
43 intel_batchbuffer_init(struct intel_batchbuffer *batch, dri_bufmgr *bufmgr,
44 bool has_llc)
45 {
46 intel_batchbuffer_reset(batch, bufmgr, has_llc);
47
48 if (!has_llc) {
49 batch->cpu_map = malloc(BATCH_SZ);
50 batch->map = batch->cpu_map;
51 batch->map_next = batch->cpu_map;
52 }
53 }
54
55 static void
56 intel_batchbuffer_reset(struct intel_batchbuffer *batch, dri_bufmgr *bufmgr,
57 bool has_llc)
58 {
59 if (batch->last_bo != NULL) {
60 drm_intel_bo_unreference(batch->last_bo);
61 batch->last_bo = NULL;
62 }
63 batch->last_bo = batch->bo;
64
65 batch->bo = drm_intel_bo_alloc(bufmgr, "batchbuffer", BATCH_SZ, 4096);
66 if (has_llc) {
67 drm_intel_bo_map(batch->bo, true);
68 batch->map = batch->bo->virtual;
69 }
70 batch->map_next = batch->map;
71
72 batch->reserved_space = BATCH_RESERVED;
73 batch->state_batch_offset = batch->bo->size;
74 batch->needs_sol_reset = false;
75 batch->state_base_address_emitted = false;
76
77 /* We don't know what ring the new batch will be sent to until we see the
78 * first BEGIN_BATCH or BEGIN_BATCH_BLT. Mark it as unknown.
79 */
80 batch->ring = UNKNOWN_RING;
81 }
82
83 static void
84 intel_batchbuffer_reset_and_clear_render_cache(struct brw_context *brw)
85 {
86 intel_batchbuffer_reset(&brw->batch, brw->bufmgr, brw->has_llc);
87 brw_render_cache_set_clear(brw);
88 }
89
90 void
91 intel_batchbuffer_save_state(struct brw_context *brw)
92 {
93 brw->batch.saved.map_next = brw->batch.map_next;
94 brw->batch.saved.reloc_count =
95 drm_intel_gem_bo_get_reloc_count(brw->batch.bo);
96 }
97
98 void
99 intel_batchbuffer_reset_to_saved(struct brw_context *brw)
100 {
101 drm_intel_gem_bo_clear_relocs(brw->batch.bo, brw->batch.saved.reloc_count);
102
103 brw->batch.map_next = brw->batch.saved.map_next;
104 if (USED_BATCH(brw->batch) == 0)
105 brw->batch.ring = UNKNOWN_RING;
106 }
107
108 void
109 intel_batchbuffer_free(struct intel_batchbuffer *batch)
110 {
111 free(batch->cpu_map);
112 drm_intel_bo_unreference(batch->last_bo);
113 drm_intel_bo_unreference(batch->bo);
114 }
115
116 void
117 intel_batchbuffer_require_space(struct brw_context *brw, GLuint sz,
118 enum brw_gpu_ring ring)
119 {
120 /* If we're switching rings, implicitly flush the batch. */
121 if (unlikely(ring != brw->batch.ring) && brw->batch.ring != UNKNOWN_RING &&
122 brw->gen >= 6) {
123 intel_batchbuffer_flush(brw);
124 }
125
126 #ifdef DEBUG
127 assert(sz < BATCH_SZ - BATCH_RESERVED);
128 #endif
129 if (intel_batchbuffer_space(&brw->batch) < sz)
130 intel_batchbuffer_flush(brw);
131
132 enum brw_gpu_ring prev_ring = brw->batch.ring;
133 /* The intel_batchbuffer_flush() calls above might have changed
134 * brw->batch.ring to UNKNOWN_RING, so we need to set it here at the end.
135 */
136 brw->batch.ring = ring;
137
138 if (unlikely(prev_ring == UNKNOWN_RING && ring == RENDER_RING))
139 intel_batchbuffer_emit_render_ring_prelude(brw);
140 }
141
142 static void
143 do_batch_dump(struct brw_context *brw)
144 {
145 struct drm_intel_decode *decode;
146 struct intel_batchbuffer *batch = &brw->batch;
147 int ret;
148
149 decode = drm_intel_decode_context_alloc(brw->screen->deviceID);
150 if (!decode)
151 return;
152
153 ret = drm_intel_bo_map(batch->bo, false);
154 if (ret == 0) {
155 drm_intel_decode_set_batch_pointer(decode,
156 batch->bo->virtual,
157 batch->bo->offset64,
158 USED_BATCH(*batch));
159 } else {
160 fprintf(stderr,
161 "WARNING: failed to map batchbuffer (%s), "
162 "dumping uploaded data instead.\n", strerror(ret));
163
164 drm_intel_decode_set_batch_pointer(decode,
165 batch->map,
166 batch->bo->offset64,
167 USED_BATCH(*batch));
168 }
169
170 drm_intel_decode_set_output_file(decode, stderr);
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 /* Un-used currently */
186 }
187
188 /**
189 * Called when starting a new batch buffer.
190 */
191 static void
192 brw_new_batch(struct brw_context *brw)
193 {
194 /* Create a new batchbuffer and reset the associated state: */
195 drm_intel_gem_bo_clear_relocs(brw->batch.bo, 0);
196 intel_batchbuffer_reset_and_clear_render_cache(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->ctx.NewDriverState |= BRW_NEW_CONTEXT;
206
207 brw->ctx.NewDriverState |= BRW_NEW_BATCH;
208
209 brw->state_batch_count = 0;
210
211 brw->ib.type = -1;
212
213 /* We need to periodically reap the shader time results, because rollover
214 * happens every few seconds. We also want to see results every once in a
215 * while, because many programs won't cleanly destroy our context, so the
216 * end-of-run printout may not happen.
217 */
218 if (INTEL_DEBUG & DEBUG_SHADER_TIME)
219 brw_collect_and_report_shader_time(brw);
220 }
221
222 /**
223 * Called from intel_batchbuffer_flush before emitting MI_BATCHBUFFER_END and
224 * sending it off.
225 *
226 * This function can emit state (say, to preserve registers that aren't saved
227 * between batches). All of this state MUST fit in the reserved space at the
228 * end of the batchbuffer. If you add more GPU state, increase the reserved
229 * space by updating the BATCH_RESERVED macro.
230 */
231 static void
232 brw_finish_batch(struct brw_context *brw)
233 {
234 /* Capture the closing pipeline statistics register values necessary to
235 * support query objects (in the non-hardware context world).
236 */
237 brw_emit_query_end(brw);
238
239 if (brw->batch.ring == RENDER_RING) {
240 /* Work around L3 state leaks into contexts set MI_RESTORE_INHIBIT which
241 * assume that the L3 cache is configured according to the hardware
242 * defaults.
243 */
244 if (brw->gen >= 7)
245 gen7_restore_default_l3_config(brw);
246
247 if (brw->is_haswell) {
248 /* From the Haswell PRM, Volume 2b, Command Reference: Instructions,
249 * 3DSTATE_CC_STATE_POINTERS > "Note":
250 *
251 * "SW must program 3DSTATE_CC_STATE_POINTERS command at the end of every
252 * 3D batch buffer followed by a PIPE_CONTROL with RC flush and CS stall."
253 *
254 * From the example in the docs, it seems to expect a regular pipe control
255 * flush here as well. We may have done it already, but meh.
256 *
257 * See also WaAvoidRCZCounterRollover.
258 */
259 brw_emit_mi_flush(brw);
260 BEGIN_BATCH(2);
261 OUT_BATCH(_3DSTATE_CC_STATE_POINTERS << 16 | (2 - 2));
262 OUT_BATCH(brw->cc.state_offset | 1);
263 ADVANCE_BATCH();
264 brw_emit_pipe_control_flush(brw, PIPE_CONTROL_RENDER_TARGET_FLUSH |
265 PIPE_CONTROL_CS_STALL);
266 }
267 }
268
269 /* Mark that the current program cache BO has been used by the GPU.
270 * It will be reallocated if we need to put new programs in for the
271 * next batch.
272 */
273 brw->cache.bo_used_by_gpu = true;
274 }
275
276 static void
277 throttle(struct brw_context *brw)
278 {
279 /* Wait for the swapbuffers before the one we just emitted, so we
280 * don't get too many swaps outstanding for apps that are GPU-heavy
281 * but not CPU-heavy.
282 *
283 * We're using intelDRI2Flush (called from the loader before
284 * swapbuffer) and glFlush (for front buffer rendering) as the
285 * indicator that a frame is done and then throttle when we get
286 * here as we prepare to render the next frame. At this point for
287 * round trips for swap/copy and getting new buffers are done and
288 * we'll spend less time waiting on the GPU.
289 *
290 * Unfortunately, we don't have a handle to the batch containing
291 * the swap, and getting our hands on that doesn't seem worth it,
292 * so we just use the first batch we emitted after the last swap.
293 */
294 if (brw->need_swap_throttle && brw->throttle_batch[0]) {
295 if (brw->throttle_batch[1]) {
296 if (!brw->disable_throttling)
297 drm_intel_bo_wait_rendering(brw->throttle_batch[1]);
298 drm_intel_bo_unreference(brw->throttle_batch[1]);
299 }
300 brw->throttle_batch[1] = brw->throttle_batch[0];
301 brw->throttle_batch[0] = NULL;
302 brw->need_swap_throttle = false;
303 /* Throttling here is more precise than the throttle ioctl, so skip it */
304 brw->need_flush_throttle = false;
305 }
306
307 if (brw->need_flush_throttle) {
308 __DRIscreen *dri_screen = brw->screen->driScrnPriv;
309 drmCommandNone(dri_screen->fd, DRM_I915_GEM_THROTTLE);
310 brw->need_flush_throttle = false;
311 }
312 }
313
314 /* TODO: Push this whole function into bufmgr.
315 */
316 static int
317 do_flush_locked(struct brw_context *brw, int in_fence_fd, int *out_fence_fd)
318 {
319 struct intel_batchbuffer *batch = &brw->batch;
320 int ret = 0;
321
322 if (brw->has_llc) {
323 drm_intel_bo_unmap(batch->bo);
324 } else {
325 ret = drm_intel_bo_subdata(batch->bo, 0, 4 * USED_BATCH(*batch), batch->map);
326 if (ret == 0 && batch->state_batch_offset != batch->bo->size) {
327 ret = drm_intel_bo_subdata(batch->bo,
328 batch->state_batch_offset,
329 batch->bo->size - batch->state_batch_offset,
330 (char *)batch->map + batch->state_batch_offset);
331 }
332 }
333
334 if (!brw->screen->no_hw) {
335 int flags;
336
337 if (brw->gen >= 6 && batch->ring == BLT_RING) {
338 flags = I915_EXEC_BLT;
339 } else {
340 flags = I915_EXEC_RENDER;
341 }
342 if (batch->needs_sol_reset)
343 flags |= I915_EXEC_GEN7_SOL_RESET;
344
345 if (ret == 0) {
346 if (unlikely(INTEL_DEBUG & DEBUG_AUB))
347 brw_annotate_aub(brw);
348
349 if (brw->hw_ctx == NULL || batch->ring != RENDER_RING) {
350 assert(in_fence_fd == -1);
351 assert(out_fence_fd == NULL);
352 ret = drm_intel_bo_mrb_exec(batch->bo, 4 * USED_BATCH(*batch),
353 NULL, 0, 0, flags);
354 } else {
355 ret = drm_intel_gem_bo_fence_exec(batch->bo, brw->hw_ctx,
356 4 * USED_BATCH(*batch),
357 in_fence_fd, out_fence_fd,
358 flags);
359 }
360 }
361
362 throttle(brw);
363 }
364
365 if (unlikely(INTEL_DEBUG & DEBUG_BATCH))
366 do_batch_dump(brw);
367
368 if (brw->ctx.Const.ResetStrategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
369 brw_check_for_reset(brw);
370
371 if (ret != 0) {
372 fprintf(stderr, "intel_do_flush_locked failed: %s\n", strerror(-ret));
373 exit(1);
374 }
375
376 return ret;
377 }
378
379 /**
380 * The in_fence_fd is ignored if -1. Otherwise this function takes ownership
381 * of the fd.
382 *
383 * The out_fence_fd is ignored if NULL. Otherwise, the caller takes ownership
384 * of the returned fd.
385 */
386 int
387 _intel_batchbuffer_flush_fence(struct brw_context *brw,
388 int in_fence_fd, int *out_fence_fd,
389 const char *file, int line)
390 {
391 int ret;
392
393 if (USED_BATCH(brw->batch) == 0)
394 return 0;
395
396 if (brw->throttle_batch[0] == NULL) {
397 brw->throttle_batch[0] = brw->batch.bo;
398 drm_intel_bo_reference(brw->throttle_batch[0]);
399 }
400
401 if (unlikely(INTEL_DEBUG & DEBUG_BATCH)) {
402 int bytes_for_commands = 4 * USED_BATCH(brw->batch);
403 int bytes_for_state = brw->batch.bo->size - brw->batch.state_batch_offset;
404 int total_bytes = bytes_for_commands + bytes_for_state;
405 fprintf(stderr, "%s:%d: Batchbuffer flush with %4db (pkt) + "
406 "%4db (state) = %4db (%0.1f%%)\n", file, line,
407 bytes_for_commands, bytes_for_state,
408 total_bytes,
409 100.0f * total_bytes / BATCH_SZ);
410 }
411
412 brw->batch.reserved_space = 0;
413
414 brw_finish_batch(brw);
415
416 /* Mark the end of the buffer. */
417 intel_batchbuffer_emit_dword(&brw->batch, MI_BATCH_BUFFER_END);
418 if (USED_BATCH(brw->batch) & 1) {
419 /* Round batchbuffer usage to 2 DWORDs. */
420 intel_batchbuffer_emit_dword(&brw->batch, MI_NOOP);
421 }
422
423 intel_upload_finish(brw);
424
425 /* Check that we didn't just wrap our batchbuffer at a bad time. */
426 assert(!brw->no_batch_wrap);
427
428 ret = do_flush_locked(brw, in_fence_fd, out_fence_fd);
429
430 if (unlikely(INTEL_DEBUG & DEBUG_SYNC)) {
431 fprintf(stderr, "waiting for idle\n");
432 drm_intel_bo_wait_rendering(brw->batch.bo);
433 }
434
435 /* Start a new batch buffer. */
436 brw_new_batch(brw);
437
438 return ret;
439 }
440
441
442 /* This is the only way buffers get added to the validate list.
443 */
444 uint32_t
445 intel_batchbuffer_reloc(struct intel_batchbuffer *batch,
446 drm_intel_bo *buffer, uint32_t offset,
447 uint32_t read_domains, uint32_t write_domain,
448 uint32_t delta)
449 {
450 int ret;
451
452 ret = drm_intel_bo_emit_reloc(batch->bo, offset,
453 buffer, delta,
454 read_domains, write_domain);
455 assert(ret == 0);
456 (void)ret;
457
458 /* Using the old buffer offset, write in what the right data would be, in
459 * case the buffer doesn't move and we can short-circuit the relocation
460 * processing in the kernel
461 */
462 return buffer->offset64 + delta;
463 }
464
465 uint64_t
466 intel_batchbuffer_reloc64(struct intel_batchbuffer *batch,
467 drm_intel_bo *buffer, uint32_t offset,
468 uint32_t read_domains, uint32_t write_domain,
469 uint32_t delta)
470 {
471 int ret = drm_intel_bo_emit_reloc(batch->bo, offset,
472 buffer, delta,
473 read_domains, write_domain);
474 assert(ret == 0);
475 (void) ret;
476
477 /* Using the old buffer offset, write in what the right data would be, in
478 * case the buffer doesn't move and we can short-circuit the relocation
479 * processing in the kernel
480 */
481 return buffer->offset64 + delta;
482 }
483
484
485 void
486 intel_batchbuffer_data(struct brw_context *brw,
487 const void *data, GLuint bytes, enum brw_gpu_ring ring)
488 {
489 assert((bytes & 3) == 0);
490 intel_batchbuffer_require_space(brw, bytes, ring);
491 memcpy(brw->batch.map_next, data, bytes);
492 brw->batch.map_next += bytes >> 2;
493 }
494
495 static void
496 load_sized_register_mem(struct brw_context *brw,
497 uint32_t reg,
498 drm_intel_bo *bo,
499 uint32_t read_domains, uint32_t write_domain,
500 uint32_t offset,
501 int size)
502 {
503 int i;
504
505 /* MI_LOAD_REGISTER_MEM only exists on Gen7+. */
506 assert(brw->gen >= 7);
507
508 if (brw->gen >= 8) {
509 BEGIN_BATCH(4 * size);
510 for (i = 0; i < size; i++) {
511 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM | (4 - 2));
512 OUT_BATCH(reg + i * 4);
513 OUT_RELOC64(bo, read_domains, write_domain, offset + i * 4);
514 }
515 ADVANCE_BATCH();
516 } else {
517 BEGIN_BATCH(3 * size);
518 for (i = 0; i < size; i++) {
519 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM | (3 - 2));
520 OUT_BATCH(reg + i * 4);
521 OUT_RELOC(bo, read_domains, write_domain, offset + i * 4);
522 }
523 ADVANCE_BATCH();
524 }
525 }
526
527 void
528 brw_load_register_mem(struct brw_context *brw,
529 uint32_t reg,
530 drm_intel_bo *bo,
531 uint32_t read_domains, uint32_t write_domain,
532 uint32_t offset)
533 {
534 load_sized_register_mem(brw, reg, bo, read_domains, write_domain, offset, 1);
535 }
536
537 void
538 brw_load_register_mem64(struct brw_context *brw,
539 uint32_t reg,
540 drm_intel_bo *bo,
541 uint32_t read_domains, uint32_t write_domain,
542 uint32_t offset)
543 {
544 load_sized_register_mem(brw, reg, bo, read_domains, write_domain, offset, 2);
545 }
546
547 /*
548 * Write an arbitrary 32-bit register to a buffer via MI_STORE_REGISTER_MEM.
549 */
550 void
551 brw_store_register_mem32(struct brw_context *brw,
552 drm_intel_bo *bo, uint32_t reg, uint32_t offset)
553 {
554 assert(brw->gen >= 6);
555
556 if (brw->gen >= 8) {
557 BEGIN_BATCH(4);
558 OUT_BATCH(MI_STORE_REGISTER_MEM | (4 - 2));
559 OUT_BATCH(reg);
560 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
561 offset);
562 ADVANCE_BATCH();
563 } else {
564 BEGIN_BATCH(3);
565 OUT_BATCH(MI_STORE_REGISTER_MEM | (3 - 2));
566 OUT_BATCH(reg);
567 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
568 offset);
569 ADVANCE_BATCH();
570 }
571 }
572
573 /*
574 * Write an arbitrary 64-bit register to a buffer via MI_STORE_REGISTER_MEM.
575 */
576 void
577 brw_store_register_mem64(struct brw_context *brw,
578 drm_intel_bo *bo, uint32_t reg, uint32_t offset)
579 {
580 assert(brw->gen >= 6);
581
582 /* MI_STORE_REGISTER_MEM only stores a single 32-bit value, so to
583 * read a full 64-bit register, we need to do two of them.
584 */
585 if (brw->gen >= 8) {
586 BEGIN_BATCH(8);
587 OUT_BATCH(MI_STORE_REGISTER_MEM | (4 - 2));
588 OUT_BATCH(reg);
589 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
590 offset);
591 OUT_BATCH(MI_STORE_REGISTER_MEM | (4 - 2));
592 OUT_BATCH(reg + sizeof(uint32_t));
593 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
594 offset + sizeof(uint32_t));
595 ADVANCE_BATCH();
596 } else {
597 BEGIN_BATCH(6);
598 OUT_BATCH(MI_STORE_REGISTER_MEM | (3 - 2));
599 OUT_BATCH(reg);
600 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
601 offset);
602 OUT_BATCH(MI_STORE_REGISTER_MEM | (3 - 2));
603 OUT_BATCH(reg + sizeof(uint32_t));
604 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
605 offset + sizeof(uint32_t));
606 ADVANCE_BATCH();
607 }
608 }
609
610 /*
611 * Write a 32-bit register using immediate data.
612 */
613 void
614 brw_load_register_imm32(struct brw_context *brw, uint32_t reg, uint32_t imm)
615 {
616 assert(brw->gen >= 6);
617
618 BEGIN_BATCH(3);
619 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
620 OUT_BATCH(reg);
621 OUT_BATCH(imm);
622 ADVANCE_BATCH();
623 }
624
625 /*
626 * Write a 64-bit register using immediate data.
627 */
628 void
629 brw_load_register_imm64(struct brw_context *brw, uint32_t reg, uint64_t imm)
630 {
631 assert(brw->gen >= 6);
632
633 BEGIN_BATCH(5);
634 OUT_BATCH(MI_LOAD_REGISTER_IMM | (5 - 2));
635 OUT_BATCH(reg);
636 OUT_BATCH(imm & 0xffffffff);
637 OUT_BATCH(reg + 4);
638 OUT_BATCH(imm >> 32);
639 ADVANCE_BATCH();
640 }
641
642 /*
643 * Copies a 32-bit register.
644 */
645 void
646 brw_load_register_reg(struct brw_context *brw, uint32_t src, uint32_t dest)
647 {
648 assert(brw->gen >= 8 || brw->is_haswell);
649
650 BEGIN_BATCH(3);
651 OUT_BATCH(MI_LOAD_REGISTER_REG | (3 - 2));
652 OUT_BATCH(src);
653 OUT_BATCH(dest);
654 ADVANCE_BATCH();
655 }
656
657 /*
658 * Copies a 64-bit register.
659 */
660 void
661 brw_load_register_reg64(struct brw_context *brw, uint32_t src, uint32_t dest)
662 {
663 assert(brw->gen >= 8 || brw->is_haswell);
664
665 BEGIN_BATCH(6);
666 OUT_BATCH(MI_LOAD_REGISTER_REG | (3 - 2));
667 OUT_BATCH(src);
668 OUT_BATCH(dest);
669 OUT_BATCH(MI_LOAD_REGISTER_REG | (3 - 2));
670 OUT_BATCH(src + sizeof(uint32_t));
671 OUT_BATCH(dest + sizeof(uint32_t));
672 ADVANCE_BATCH();
673 }
674
675 /*
676 * Write 32-bits of immediate data to a GPU memory buffer.
677 */
678 void
679 brw_store_data_imm32(struct brw_context *brw, drm_intel_bo *bo,
680 uint32_t offset, uint32_t imm)
681 {
682 assert(brw->gen >= 6);
683
684 BEGIN_BATCH(4);
685 OUT_BATCH(MI_STORE_DATA_IMM | (4 - 2));
686 if (brw->gen >= 8)
687 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
688 offset);
689 else {
690 OUT_BATCH(0); /* MBZ */
691 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
692 offset);
693 }
694 OUT_BATCH(imm);
695 ADVANCE_BATCH();
696 }
697
698 /*
699 * Write 64-bits of immediate data to a GPU memory buffer.
700 */
701 void
702 brw_store_data_imm64(struct brw_context *brw, drm_intel_bo *bo,
703 uint32_t offset, uint64_t imm)
704 {
705 assert(brw->gen >= 6);
706
707 BEGIN_BATCH(5);
708 OUT_BATCH(MI_STORE_DATA_IMM | (5 - 2));
709 if (brw->gen >= 8)
710 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
711 offset);
712 else {
713 OUT_BATCH(0); /* MBZ */
714 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
715 offset);
716 }
717 OUT_BATCH(imm & 0xffffffffu);
718 OUT_BATCH(imm >> 32);
719 ADVANCE_BATCH();
720 }