887504273abe04503f8bb1b95c73a263254f8dcb
[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 /* The intel_batchbuffer_flush() calls above might have changed
133 * brw->batch.ring to UNKNOWN_RING, so we need to set it here at the end.
134 */
135 brw->batch.ring = ring;
136 }
137
138 static void
139 do_batch_dump(struct brw_context *brw)
140 {
141 struct drm_intel_decode *decode;
142 struct intel_batchbuffer *batch = &brw->batch;
143 int ret;
144
145 decode = drm_intel_decode_context_alloc(brw->screen->deviceID);
146 if (!decode)
147 return;
148
149 ret = drm_intel_bo_map(batch->bo, false);
150 if (ret == 0) {
151 drm_intel_decode_set_batch_pointer(decode,
152 batch->bo->virtual,
153 batch->bo->offset64,
154 USED_BATCH(*batch));
155 } else {
156 fprintf(stderr,
157 "WARNING: failed to map batchbuffer (%s), "
158 "dumping uploaded data instead.\n", strerror(ret));
159
160 drm_intel_decode_set_batch_pointer(decode,
161 batch->map,
162 batch->bo->offset64,
163 USED_BATCH(*batch));
164 }
165
166 drm_intel_decode_set_output_file(decode, stderr);
167 drm_intel_decode(decode);
168
169 drm_intel_decode_context_free(decode);
170
171 if (ret == 0) {
172 drm_intel_bo_unmap(batch->bo);
173
174 brw_debug_batch(brw);
175 }
176 }
177
178 /**
179 * Called when starting a new batch buffer.
180 */
181 static void
182 brw_new_batch(struct brw_context *brw)
183 {
184 /* Create a new batchbuffer and reset the associated state: */
185 drm_intel_gem_bo_clear_relocs(brw->batch.bo, 0);
186 intel_batchbuffer_reset_and_clear_render_cache(brw);
187
188 /* If the kernel supports hardware contexts, then most hardware state is
189 * preserved between batches; we only need to re-emit state that is required
190 * to be in every batch. Otherwise we need to re-emit all the state that
191 * would otherwise be stored in the context (which for all intents and
192 * purposes means everything).
193 */
194 if (brw->hw_ctx == NULL)
195 brw->ctx.NewDriverState |= BRW_NEW_CONTEXT;
196
197 brw->ctx.NewDriverState |= BRW_NEW_BATCH;
198
199 brw->state_batch_count = 0;
200
201 brw->ib.type = -1;
202
203 /* We need to periodically reap the shader time results, because rollover
204 * happens every few seconds. We also want to see results every once in a
205 * while, because many programs won't cleanly destroy our context, so the
206 * end-of-run printout may not happen.
207 */
208 if (INTEL_DEBUG & DEBUG_SHADER_TIME)
209 brw_collect_and_report_shader_time(brw);
210 }
211
212 /**
213 * Called from intel_batchbuffer_flush before emitting MI_BATCHBUFFER_END and
214 * sending it off.
215 *
216 * This function can emit state (say, to preserve registers that aren't saved
217 * between batches). All of this state MUST fit in the reserved space at the
218 * end of the batchbuffer. If you add more GPU state, increase the reserved
219 * space by updating the BATCH_RESERVED macro.
220 */
221 static void
222 brw_finish_batch(struct brw_context *brw)
223 {
224 /* Capture the closing pipeline statistics register values necessary to
225 * support query objects (in the non-hardware context world).
226 */
227 brw_emit_query_end(brw);
228
229 if (brw->batch.ring == RENDER_RING) {
230 /* Work around L3 state leaks into contexts set MI_RESTORE_INHIBIT which
231 * assume that the L3 cache is configured according to the hardware
232 * defaults.
233 */
234 if (brw->gen >= 7)
235 gen7_restore_default_l3_config(brw);
236
237 if (brw->is_haswell) {
238 /* From the Haswell PRM, Volume 2b, Command Reference: Instructions,
239 * 3DSTATE_CC_STATE_POINTERS > "Note":
240 *
241 * "SW must program 3DSTATE_CC_STATE_POINTERS command at the end of every
242 * 3D batch buffer followed by a PIPE_CONTROL with RC flush and CS stall."
243 *
244 * From the example in the docs, it seems to expect a regular pipe control
245 * flush here as well. We may have done it already, but meh.
246 *
247 * See also WaAvoidRCZCounterRollover.
248 */
249 brw_emit_mi_flush(brw);
250 BEGIN_BATCH(2);
251 OUT_BATCH(_3DSTATE_CC_STATE_POINTERS << 16 | (2 - 2));
252 OUT_BATCH(brw->cc.state_offset | 1);
253 ADVANCE_BATCH();
254 brw_emit_pipe_control_flush(brw, PIPE_CONTROL_RENDER_TARGET_FLUSH |
255 PIPE_CONTROL_CS_STALL);
256 }
257 }
258
259 /* Mark that the current program cache BO has been used by the GPU.
260 * It will be reallocated if we need to put new programs in for the
261 * next batch.
262 */
263 brw->cache.bo_used_by_gpu = true;
264 }
265
266 static void
267 throttle(struct brw_context *brw)
268 {
269 /* Wait for the swapbuffers before the one we just emitted, so we
270 * don't get too many swaps outstanding for apps that are GPU-heavy
271 * but not CPU-heavy.
272 *
273 * We're using intelDRI2Flush (called from the loader before
274 * swapbuffer) and glFlush (for front buffer rendering) as the
275 * indicator that a frame is done and then throttle when we get
276 * here as we prepare to render the next frame. At this point for
277 * round trips for swap/copy and getting new buffers are done and
278 * we'll spend less time waiting on the GPU.
279 *
280 * Unfortunately, we don't have a handle to the batch containing
281 * the swap, and getting our hands on that doesn't seem worth it,
282 * so we just use the first batch we emitted after the last swap.
283 */
284 if (brw->need_swap_throttle && brw->throttle_batch[0]) {
285 if (brw->throttle_batch[1]) {
286 if (!brw->disable_throttling)
287 drm_intel_bo_wait_rendering(brw->throttle_batch[1]);
288 drm_intel_bo_unreference(brw->throttle_batch[1]);
289 }
290 brw->throttle_batch[1] = brw->throttle_batch[0];
291 brw->throttle_batch[0] = NULL;
292 brw->need_swap_throttle = false;
293 /* Throttling here is more precise than the throttle ioctl, so skip it */
294 brw->need_flush_throttle = false;
295 }
296
297 if (brw->need_flush_throttle) {
298 __DRIscreen *dri_screen = brw->screen->driScrnPriv;
299 drmCommandNone(dri_screen->fd, DRM_I915_GEM_THROTTLE);
300 brw->need_flush_throttle = false;
301 }
302 }
303
304 /* TODO: Push this whole function into bufmgr.
305 */
306 static int
307 do_flush_locked(struct brw_context *brw, int in_fence_fd, int *out_fence_fd)
308 {
309 struct intel_batchbuffer *batch = &brw->batch;
310 int ret = 0;
311
312 if (brw->has_llc) {
313 drm_intel_bo_unmap(batch->bo);
314 } else {
315 ret = drm_intel_bo_subdata(batch->bo, 0, 4 * USED_BATCH(*batch), batch->map);
316 if (ret == 0 && batch->state_batch_offset != batch->bo->size) {
317 ret = drm_intel_bo_subdata(batch->bo,
318 batch->state_batch_offset,
319 batch->bo->size - batch->state_batch_offset,
320 (char *)batch->map + batch->state_batch_offset);
321 }
322 }
323
324 if (!brw->screen->no_hw) {
325 int flags;
326
327 if (brw->gen >= 6 && batch->ring == BLT_RING) {
328 flags = I915_EXEC_BLT;
329 } else {
330 flags = I915_EXEC_RENDER;
331 }
332 if (batch->needs_sol_reset)
333 flags |= I915_EXEC_GEN7_SOL_RESET;
334
335 if (ret == 0) {
336 if (brw->hw_ctx == NULL || batch->ring != RENDER_RING) {
337 assert(in_fence_fd == -1);
338 assert(out_fence_fd == NULL);
339 ret = drm_intel_bo_mrb_exec(batch->bo, 4 * USED_BATCH(*batch),
340 NULL, 0, 0, flags);
341 } else {
342 ret = drm_intel_gem_bo_fence_exec(batch->bo, brw->hw_ctx,
343 4 * USED_BATCH(*batch),
344 in_fence_fd, out_fence_fd,
345 flags);
346 }
347 }
348
349 throttle(brw);
350 }
351
352 if (unlikely(INTEL_DEBUG & DEBUG_BATCH))
353 do_batch_dump(brw);
354
355 if (brw->ctx.Const.ResetStrategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
356 brw_check_for_reset(brw);
357
358 if (ret != 0) {
359 fprintf(stderr, "intel_do_flush_locked failed: %s\n", strerror(-ret));
360 exit(1);
361 }
362
363 return ret;
364 }
365
366 /**
367 * The in_fence_fd is ignored if -1. Otherwise this function takes ownership
368 * of the fd.
369 *
370 * The out_fence_fd is ignored if NULL. Otherwise, the caller takes ownership
371 * of the returned fd.
372 */
373 int
374 _intel_batchbuffer_flush_fence(struct brw_context *brw,
375 int in_fence_fd, int *out_fence_fd,
376 const char *file, int line)
377 {
378 int ret;
379
380 if (USED_BATCH(brw->batch) == 0)
381 return 0;
382
383 if (brw->throttle_batch[0] == NULL) {
384 brw->throttle_batch[0] = brw->batch.bo;
385 drm_intel_bo_reference(brw->throttle_batch[0]);
386 }
387
388 if (unlikely(INTEL_DEBUG & DEBUG_BATCH)) {
389 int bytes_for_commands = 4 * USED_BATCH(brw->batch);
390 int bytes_for_state = brw->batch.bo->size - brw->batch.state_batch_offset;
391 int total_bytes = bytes_for_commands + bytes_for_state;
392 fprintf(stderr, "%s:%d: Batchbuffer flush with %4db (pkt) + "
393 "%4db (state) = %4db (%0.1f%%)\n", file, line,
394 bytes_for_commands, bytes_for_state,
395 total_bytes,
396 100.0f * total_bytes / BATCH_SZ);
397 }
398
399 brw->batch.reserved_space = 0;
400
401 brw_finish_batch(brw);
402
403 /* Mark the end of the buffer. */
404 intel_batchbuffer_emit_dword(&brw->batch, MI_BATCH_BUFFER_END);
405 if (USED_BATCH(brw->batch) & 1) {
406 /* Round batchbuffer usage to 2 DWORDs. */
407 intel_batchbuffer_emit_dword(&brw->batch, MI_NOOP);
408 }
409
410 intel_upload_finish(brw);
411
412 /* Check that we didn't just wrap our batchbuffer at a bad time. */
413 assert(!brw->no_batch_wrap);
414
415 ret = do_flush_locked(brw, in_fence_fd, out_fence_fd);
416
417 if (unlikely(INTEL_DEBUG & DEBUG_SYNC)) {
418 fprintf(stderr, "waiting for idle\n");
419 drm_intel_bo_wait_rendering(brw->batch.bo);
420 }
421
422 /* Start a new batch buffer. */
423 brw_new_batch(brw);
424
425 return ret;
426 }
427
428
429 /* This is the only way buffers get added to the validate list.
430 */
431 uint32_t
432 intel_batchbuffer_reloc(struct intel_batchbuffer *batch,
433 drm_intel_bo *buffer, uint32_t offset,
434 uint32_t read_domains, uint32_t write_domain,
435 uint32_t delta)
436 {
437 int ret;
438
439 ret = drm_intel_bo_emit_reloc(batch->bo, offset,
440 buffer, delta,
441 read_domains, write_domain);
442 assert(ret == 0);
443 (void)ret;
444
445 /* Using the old buffer offset, write in what the right data would be, in
446 * case the buffer doesn't move and we can short-circuit the relocation
447 * processing in the kernel
448 */
449 return buffer->offset64 + delta;
450 }
451
452 uint64_t
453 intel_batchbuffer_reloc64(struct intel_batchbuffer *batch,
454 drm_intel_bo *buffer, uint32_t offset,
455 uint32_t read_domains, uint32_t write_domain,
456 uint32_t delta)
457 {
458 int ret = drm_intel_bo_emit_reloc(batch->bo, offset,
459 buffer, delta,
460 read_domains, write_domain);
461 assert(ret == 0);
462 (void) ret;
463
464 /* Using the old buffer offset, write in what the right data would be, in
465 * case the buffer doesn't move and we can short-circuit the relocation
466 * processing in the kernel
467 */
468 return buffer->offset64 + delta;
469 }
470
471
472 void
473 intel_batchbuffer_data(struct brw_context *brw,
474 const void *data, GLuint bytes, enum brw_gpu_ring ring)
475 {
476 assert((bytes & 3) == 0);
477 intel_batchbuffer_require_space(brw, bytes, ring);
478 memcpy(brw->batch.map_next, data, bytes);
479 brw->batch.map_next += bytes >> 2;
480 }
481
482 static void
483 load_sized_register_mem(struct brw_context *brw,
484 uint32_t reg,
485 drm_intel_bo *bo,
486 uint32_t read_domains, uint32_t write_domain,
487 uint32_t offset,
488 int size)
489 {
490 int i;
491
492 /* MI_LOAD_REGISTER_MEM only exists on Gen7+. */
493 assert(brw->gen >= 7);
494
495 if (brw->gen >= 8) {
496 BEGIN_BATCH(4 * size);
497 for (i = 0; i < size; i++) {
498 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM | (4 - 2));
499 OUT_BATCH(reg + i * 4);
500 OUT_RELOC64(bo, read_domains, write_domain, offset + i * 4);
501 }
502 ADVANCE_BATCH();
503 } else {
504 BEGIN_BATCH(3 * size);
505 for (i = 0; i < size; i++) {
506 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM | (3 - 2));
507 OUT_BATCH(reg + i * 4);
508 OUT_RELOC(bo, read_domains, write_domain, offset + i * 4);
509 }
510 ADVANCE_BATCH();
511 }
512 }
513
514 void
515 brw_load_register_mem(struct brw_context *brw,
516 uint32_t reg,
517 drm_intel_bo *bo,
518 uint32_t read_domains, uint32_t write_domain,
519 uint32_t offset)
520 {
521 load_sized_register_mem(brw, reg, bo, read_domains, write_domain, offset, 1);
522 }
523
524 void
525 brw_load_register_mem64(struct brw_context *brw,
526 uint32_t reg,
527 drm_intel_bo *bo,
528 uint32_t read_domains, uint32_t write_domain,
529 uint32_t offset)
530 {
531 load_sized_register_mem(brw, reg, bo, read_domains, write_domain, offset, 2);
532 }
533
534 /*
535 * Write an arbitrary 32-bit register to a buffer via MI_STORE_REGISTER_MEM.
536 */
537 void
538 brw_store_register_mem32(struct brw_context *brw,
539 drm_intel_bo *bo, uint32_t reg, uint32_t offset)
540 {
541 assert(brw->gen >= 6);
542
543 if (brw->gen >= 8) {
544 BEGIN_BATCH(4);
545 OUT_BATCH(MI_STORE_REGISTER_MEM | (4 - 2));
546 OUT_BATCH(reg);
547 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
548 offset);
549 ADVANCE_BATCH();
550 } else {
551 BEGIN_BATCH(3);
552 OUT_BATCH(MI_STORE_REGISTER_MEM | (3 - 2));
553 OUT_BATCH(reg);
554 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
555 offset);
556 ADVANCE_BATCH();
557 }
558 }
559
560 /*
561 * Write an arbitrary 64-bit register to a buffer via MI_STORE_REGISTER_MEM.
562 */
563 void
564 brw_store_register_mem64(struct brw_context *brw,
565 drm_intel_bo *bo, uint32_t reg, uint32_t offset)
566 {
567 assert(brw->gen >= 6);
568
569 /* MI_STORE_REGISTER_MEM only stores a single 32-bit value, so to
570 * read a full 64-bit register, we need to do two of them.
571 */
572 if (brw->gen >= 8) {
573 BEGIN_BATCH(8);
574 OUT_BATCH(MI_STORE_REGISTER_MEM | (4 - 2));
575 OUT_BATCH(reg);
576 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
577 offset);
578 OUT_BATCH(MI_STORE_REGISTER_MEM | (4 - 2));
579 OUT_BATCH(reg + sizeof(uint32_t));
580 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
581 offset + sizeof(uint32_t));
582 ADVANCE_BATCH();
583 } else {
584 BEGIN_BATCH(6);
585 OUT_BATCH(MI_STORE_REGISTER_MEM | (3 - 2));
586 OUT_BATCH(reg);
587 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
588 offset);
589 OUT_BATCH(MI_STORE_REGISTER_MEM | (3 - 2));
590 OUT_BATCH(reg + sizeof(uint32_t));
591 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
592 offset + sizeof(uint32_t));
593 ADVANCE_BATCH();
594 }
595 }
596
597 /*
598 * Write a 32-bit register using immediate data.
599 */
600 void
601 brw_load_register_imm32(struct brw_context *brw, uint32_t reg, uint32_t imm)
602 {
603 assert(brw->gen >= 6);
604
605 BEGIN_BATCH(3);
606 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
607 OUT_BATCH(reg);
608 OUT_BATCH(imm);
609 ADVANCE_BATCH();
610 }
611
612 /*
613 * Write a 64-bit register using immediate data.
614 */
615 void
616 brw_load_register_imm64(struct brw_context *brw, uint32_t reg, uint64_t imm)
617 {
618 assert(brw->gen >= 6);
619
620 BEGIN_BATCH(5);
621 OUT_BATCH(MI_LOAD_REGISTER_IMM | (5 - 2));
622 OUT_BATCH(reg);
623 OUT_BATCH(imm & 0xffffffff);
624 OUT_BATCH(reg + 4);
625 OUT_BATCH(imm >> 32);
626 ADVANCE_BATCH();
627 }
628
629 /*
630 * Copies a 32-bit register.
631 */
632 void
633 brw_load_register_reg(struct brw_context *brw, uint32_t src, uint32_t dest)
634 {
635 assert(brw->gen >= 8 || brw->is_haswell);
636
637 BEGIN_BATCH(3);
638 OUT_BATCH(MI_LOAD_REGISTER_REG | (3 - 2));
639 OUT_BATCH(src);
640 OUT_BATCH(dest);
641 ADVANCE_BATCH();
642 }
643
644 /*
645 * Copies a 64-bit register.
646 */
647 void
648 brw_load_register_reg64(struct brw_context *brw, uint32_t src, uint32_t dest)
649 {
650 assert(brw->gen >= 8 || brw->is_haswell);
651
652 BEGIN_BATCH(6);
653 OUT_BATCH(MI_LOAD_REGISTER_REG | (3 - 2));
654 OUT_BATCH(src);
655 OUT_BATCH(dest);
656 OUT_BATCH(MI_LOAD_REGISTER_REG | (3 - 2));
657 OUT_BATCH(src + sizeof(uint32_t));
658 OUT_BATCH(dest + sizeof(uint32_t));
659 ADVANCE_BATCH();
660 }
661
662 /*
663 * Write 32-bits of immediate data to a GPU memory buffer.
664 */
665 void
666 brw_store_data_imm32(struct brw_context *brw, drm_intel_bo *bo,
667 uint32_t offset, uint32_t imm)
668 {
669 assert(brw->gen >= 6);
670
671 BEGIN_BATCH(4);
672 OUT_BATCH(MI_STORE_DATA_IMM | (4 - 2));
673 if (brw->gen >= 8)
674 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
675 offset);
676 else {
677 OUT_BATCH(0); /* MBZ */
678 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
679 offset);
680 }
681 OUT_BATCH(imm);
682 ADVANCE_BATCH();
683 }
684
685 /*
686 * Write 64-bits of immediate data to a GPU memory buffer.
687 */
688 void
689 brw_store_data_imm64(struct brw_context *brw, drm_intel_bo *bo,
690 uint32_t offset, uint64_t imm)
691 {
692 assert(brw->gen >= 6);
693
694 BEGIN_BATCH(5);
695 OUT_BATCH(MI_STORE_DATA_IMM | (5 - 2));
696 if (brw->gen >= 8)
697 OUT_RELOC64(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
698 offset);
699 else {
700 OUT_BATCH(0); /* MBZ */
701 OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
702 offset);
703 }
704 OUT_BATCH(imm & 0xffffffffu);
705 OUT_BATCH(imm >> 32);
706 ADVANCE_BATCH();
707 }