2 * Copyright 2006 VMware, Inc.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
26 #include "intel_batchbuffer.h"
27 #include "intel_buffer_objects.h"
28 #include "brw_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 #include "common/gen_decoder.h"
36 #include "util/hash_table.h"
41 #define FILE_DEBUG_FLAG DEBUG_BUFMGR
44 * Target sizes of the batch and state buffers. We create the initial
45 * buffers at these sizes, and flush when they're nearly full. If we
46 * underestimate how close we are to the end, and suddenly need more space
47 * in the middle of a draw, we can grow the buffers, and finish the draw.
48 * At that point, we'll be over our target size, so the next operation
49 * should flush. Each time we flush the batch, we recreate both buffers
50 * at the original target size, so it doesn't grow without bound.
52 #define BATCH_SZ (20 * 1024)
53 #define STATE_SZ (16 * 1024)
56 intel_batchbuffer_reset(struct brw_context
*brw
);
59 uint_key_compare(const void *a
, const void *b
)
65 uint_key_hash(const void *key
)
67 return (uintptr_t) key
;
71 init_reloc_list(struct brw_reloc_list
*rlist
, int count
)
73 rlist
->reloc_count
= 0;
74 rlist
->reloc_array_size
= count
;
75 rlist
->relocs
= malloc(rlist
->reloc_array_size
*
76 sizeof(struct drm_i915_gem_relocation_entry
));
80 intel_batchbuffer_init(struct brw_context
*brw
)
82 struct intel_screen
*screen
= brw
->screen
;
83 struct intel_batchbuffer
*batch
= &brw
->batch
;
84 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
86 if (!devinfo
->has_llc
) {
87 batch
->batch
.cpu_map
= malloc(BATCH_SZ
);
88 batch
->batch
.map
= batch
->batch
.cpu_map
;
89 batch
->map_next
= batch
->batch
.map
;
90 batch
->state
.cpu_map
= malloc(STATE_SZ
);
91 batch
->state
.map
= batch
->state
.cpu_map
;
94 init_reloc_list(&batch
->batch_relocs
, 250);
95 init_reloc_list(&batch
->state_relocs
, 250);
97 batch
->exec_count
= 0;
98 batch
->exec_array_size
= 100;
100 malloc(batch
->exec_array_size
* sizeof(batch
->exec_bos
[0]));
101 batch
->validation_list
=
102 malloc(batch
->exec_array_size
* sizeof(batch
->validation_list
[0]));
104 if (INTEL_DEBUG
& DEBUG_BATCH
) {
105 batch
->state_batch_sizes
=
106 _mesa_hash_table_create(NULL
, uint_key_hash
, uint_key_compare
);
109 batch
->use_batch_first
=
110 screen
->kernel_features
& KERNEL_ALLOWS_EXEC_BATCH_FIRST
;
112 /* PIPE_CONTROL needs a w/a but only on gen6 */
113 batch
->valid_reloc_flags
= EXEC_OBJECT_WRITE
;
114 if (devinfo
->gen
== 6)
115 batch
->valid_reloc_flags
|= EXEC_OBJECT_NEEDS_GTT
;
117 intel_batchbuffer_reset(brw
);
120 #define READ_ONCE(x) (*(volatile __typeof__(x) *)&(x))
123 add_exec_bo(struct intel_batchbuffer
*batch
, struct brw_bo
*bo
)
125 unsigned index
= READ_ONCE(bo
->index
);
127 if (index
< batch
->exec_count
&& batch
->exec_bos
[index
] == bo
)
130 /* May have been shared between multiple active batches */
131 for (index
= 0; index
< batch
->exec_count
; index
++) {
132 if (batch
->exec_bos
[index
] == bo
)
136 brw_bo_reference(bo
);
138 if (batch
->exec_count
== batch
->exec_array_size
) {
139 batch
->exec_array_size
*= 2;
141 realloc(batch
->exec_bos
,
142 batch
->exec_array_size
* sizeof(batch
->exec_bos
[0]));
143 batch
->validation_list
=
144 realloc(batch
->validation_list
,
145 batch
->exec_array_size
* sizeof(batch
->validation_list
[0]));
148 batch
->validation_list
[batch
->exec_count
] =
149 (struct drm_i915_gem_exec_object2
) {
150 .handle
= bo
->gem_handle
,
151 .alignment
= bo
->align
,
152 .offset
= bo
->gtt_offset
,
156 bo
->index
= batch
->exec_count
;
157 batch
->exec_bos
[batch
->exec_count
] = bo
;
158 batch
->aperture_space
+= bo
->size
;
160 return batch
->exec_count
++;
164 intel_batchbuffer_reset(struct brw_context
*brw
)
166 struct intel_screen
*screen
= brw
->screen
;
167 struct intel_batchbuffer
*batch
= &brw
->batch
;
168 struct brw_bufmgr
*bufmgr
= screen
->bufmgr
;
170 if (batch
->last_bo
!= NULL
) {
171 brw_bo_unreference(batch
->last_bo
);
172 batch
->last_bo
= NULL
;
174 batch
->last_bo
= batch
->batch
.bo
;
176 batch
->batch
.bo
= brw_bo_alloc(bufmgr
, "batchbuffer", BATCH_SZ
, 4096);
177 if (!batch
->batch
.cpu_map
) {
179 brw_bo_map(brw
, batch
->batch
.bo
, MAP_READ
| MAP_WRITE
);
181 batch
->map_next
= batch
->batch
.map
;
183 batch
->state
.bo
= brw_bo_alloc(bufmgr
, "statebuffer", STATE_SZ
, 4096);
184 batch
->state
.bo
->kflags
=
185 can_do_exec_capture(screen
) ? EXEC_OBJECT_CAPTURE
: 0;
186 if (!batch
->state
.cpu_map
) {
188 brw_bo_map(brw
, batch
->state
.bo
, MAP_READ
| MAP_WRITE
);
191 /* Avoid making 0 a valid state offset - otherwise the decoder will try
192 * and decode data when we use offset 0 as a null pointer.
194 batch
->state_used
= 1;
196 add_exec_bo(batch
, batch
->batch
.bo
);
197 assert(batch
->batch
.bo
->index
== 0);
199 batch
->needs_sol_reset
= false;
200 batch
->state_base_address_emitted
= false;
202 /* We don't know what ring the new batch will be sent to until we see the
203 * first BEGIN_BATCH or BEGIN_BATCH_BLT. Mark it as unknown.
205 batch
->ring
= UNKNOWN_RING
;
207 if (batch
->state_batch_sizes
)
208 _mesa_hash_table_clear(batch
->state_batch_sizes
, NULL
);
212 intel_batchbuffer_reset_and_clear_render_cache(struct brw_context
*brw
)
214 intel_batchbuffer_reset(brw
);
215 brw_cache_sets_clear(brw
);
219 intel_batchbuffer_save_state(struct brw_context
*brw
)
221 brw
->batch
.saved
.map_next
= brw
->batch
.map_next
;
222 brw
->batch
.saved
.batch_reloc_count
= brw
->batch
.batch_relocs
.reloc_count
;
223 brw
->batch
.saved
.state_reloc_count
= brw
->batch
.state_relocs
.reloc_count
;
224 brw
->batch
.saved
.exec_count
= brw
->batch
.exec_count
;
228 intel_batchbuffer_reset_to_saved(struct brw_context
*brw
)
230 for (int i
= brw
->batch
.saved
.exec_count
;
231 i
< brw
->batch
.exec_count
; i
++) {
232 brw_bo_unreference(brw
->batch
.exec_bos
[i
]);
234 brw
->batch
.batch_relocs
.reloc_count
= brw
->batch
.saved
.batch_reloc_count
;
235 brw
->batch
.state_relocs
.reloc_count
= brw
->batch
.saved
.state_reloc_count
;
236 brw
->batch
.exec_count
= brw
->batch
.saved
.exec_count
;
238 brw
->batch
.map_next
= brw
->batch
.saved
.map_next
;
239 if (USED_BATCH(brw
->batch
) == 0)
240 brw
->batch
.ring
= UNKNOWN_RING
;
244 intel_batchbuffer_free(struct intel_batchbuffer
*batch
)
246 free(batch
->batch
.cpu_map
);
247 free(batch
->state
.cpu_map
);
249 for (int i
= 0; i
< batch
->exec_count
; i
++) {
250 brw_bo_unreference(batch
->exec_bos
[i
]);
252 free(batch
->batch_relocs
.relocs
);
253 free(batch
->state_relocs
.relocs
);
254 free(batch
->exec_bos
);
255 free(batch
->validation_list
);
257 brw_bo_unreference(batch
->last_bo
);
258 brw_bo_unreference(batch
->batch
.bo
);
259 brw_bo_unreference(batch
->state
.bo
);
260 if (batch
->state_batch_sizes
)
261 _mesa_hash_table_destroy(batch
->state_batch_sizes
, NULL
);
265 replace_bo_in_reloc_list(struct brw_reloc_list
*rlist
,
266 uint32_t old_handle
, uint32_t new_handle
)
268 for (int i
= 0; i
< rlist
->reloc_count
; i
++) {
269 if (rlist
->relocs
[i
].target_handle
== old_handle
)
270 rlist
->relocs
[i
].target_handle
= new_handle
;
275 * Grow either the batch or state buffer to a new larger size.
277 * We can't actually grow buffers, so we allocate a new one, copy over
278 * the existing contents, and update our lists to refer to the new one.
280 * Note that this is only temporary - each new batch recreates the buffers
281 * at their original target size (BATCH_SZ or STATE_SZ).
284 grow_buffer(struct brw_context
*brw
,
285 struct brw_bo
**bo_ptr
,
287 uint32_t **cpu_map_ptr
,
288 unsigned existing_bytes
,
291 struct intel_batchbuffer
*batch
= &brw
->batch
;
292 struct brw_bufmgr
*bufmgr
= brw
->bufmgr
;
294 uint32_t *old_map
= *map_ptr
;
295 struct brw_bo
*old_bo
= *bo_ptr
;
297 struct brw_bo
*new_bo
=
298 brw_bo_alloc(bufmgr
, old_bo
->name
, new_size
, old_bo
->align
);
301 perf_debug("Growing %s - ran out of space\n", old_bo
->name
);
303 /* Copy existing data to the new larger buffer */
305 *cpu_map_ptr
= new_map
= realloc(*cpu_map_ptr
, new_size
);
307 new_map
= brw_bo_map(brw
, new_bo
, MAP_READ
| MAP_WRITE
);
308 memcpy(new_map
, old_map
, existing_bytes
);
311 /* Try to put the new BO at the same GTT offset as the old BO (which
312 * we're throwing away, so it doesn't need to be there).
314 * This guarantees that our relocations continue to work: values we've
315 * already written into the buffer, values we're going to write into the
316 * buffer, and the validation/relocation lists all will match.
318 * Also preserve kflags for EXEC_OBJECT_CAPTURE.
320 new_bo
->gtt_offset
= old_bo
->gtt_offset
;
321 new_bo
->index
= old_bo
->index
;
322 new_bo
->kflags
= old_bo
->kflags
;
324 /* Batch/state buffers are per-context, and if we've run out of space,
325 * we must have actually used them before, so...they will be in the list.
327 assert(old_bo
->index
< batch
->exec_count
);
328 assert(batch
->exec_bos
[old_bo
->index
] == old_bo
);
330 /* Update the validation list to use the new BO. */
331 batch
->exec_bos
[old_bo
->index
] = new_bo
;
332 batch
->validation_list
[old_bo
->index
].handle
= new_bo
->gem_handle
;
333 brw_bo_reference(new_bo
);
334 brw_bo_unreference(old_bo
);
336 if (!batch
->use_batch_first
) {
337 /* We're not using I915_EXEC_HANDLE_LUT, which means we need to go
338 * update the relocation list entries to point at the new BO as well.
339 * (With newer kernels, the "handle" is an offset into the validation
340 * list, which remains unchanged, so we can skip this.)
342 replace_bo_in_reloc_list(&batch
->batch_relocs
,
343 old_bo
->gem_handle
, new_bo
->gem_handle
);
344 replace_bo_in_reloc_list(&batch
->state_relocs
,
345 old_bo
->gem_handle
, new_bo
->gem_handle
);
348 /* Drop the *bo_ptr reference. This should free the old BO. */
349 brw_bo_unreference(old_bo
);
356 intel_batchbuffer_require_space(struct brw_context
*brw
, GLuint sz
,
357 enum brw_gpu_ring ring
)
359 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
360 struct intel_batchbuffer
*batch
= &brw
->batch
;
362 /* If we're switching rings, implicitly flush the batch. */
363 if (unlikely(ring
!= brw
->batch
.ring
) && brw
->batch
.ring
!= UNKNOWN_RING
&&
365 intel_batchbuffer_flush(brw
);
368 const unsigned batch_used
= USED_BATCH(*batch
) * 4;
369 if (batch_used
+ sz
>= BATCH_SZ
&& !batch
->no_wrap
) {
370 intel_batchbuffer_flush(brw
);
371 } else if (batch_used
+ sz
>= batch
->batch
.bo
->size
) {
372 const unsigned new_size
=
373 MIN2(batch
->batch
.bo
->size
+ batch
->batch
.bo
->size
/ 2,
375 grow_buffer(brw
, &batch
->batch
.bo
, &batch
->batch
.map
,
376 &batch
->batch
.cpu_map
, batch_used
, new_size
);
377 batch
->map_next
= (void *) batch
->batch
.map
+ batch_used
;
378 assert(batch_used
+ sz
< batch
->batch
.bo
->size
);
381 /* The intel_batchbuffer_flush() calls above might have changed
382 * brw->batch.ring to UNKNOWN_RING, so we need to set it here at the end.
384 brw
->batch
.ring
= ring
;
389 #define BLUE_HEADER CSI "0;44m"
390 #define NORMAL CSI "0m"
394 decode_struct(struct brw_context
*brw
, struct gen_spec
*spec
,
395 const char *struct_name
, uint32_t *data
,
396 uint32_t gtt_offset
, uint32_t offset
, bool color
)
398 struct gen_group
*group
= gen_spec_find_struct(spec
, struct_name
);
402 fprintf(stderr
, "%s\n", struct_name
);
403 gen_print_group(stderr
, group
, gtt_offset
+ offset
,
404 &data
[offset
/ 4], color
);
408 decode_structs(struct brw_context
*brw
, struct gen_spec
*spec
,
409 const char *struct_name
,
410 uint32_t *data
, uint32_t gtt_offset
, uint32_t offset
,
411 int struct_size
, bool color
)
413 struct gen_group
*group
= gen_spec_find_struct(spec
, struct_name
);
417 int entries
= brw_state_batch_size(brw
, offset
) / struct_size
;
418 for (int i
= 0; i
< entries
; i
++) {
419 fprintf(stderr
, "%s %d\n", struct_name
, i
);
420 gen_print_group(stderr
, group
, gtt_offset
+ offset
,
421 &data
[(offset
+ i
* struct_size
) / 4], color
);
426 do_batch_dump(struct brw_context
*brw
)
428 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
429 struct intel_batchbuffer
*batch
= &brw
->batch
;
430 struct gen_spec
*spec
= gen_spec_load(&brw
->screen
->devinfo
);
432 if (batch
->ring
!= RENDER_RING
)
435 uint32_t *batch_data
= brw_bo_map(brw
, batch
->batch
.bo
, MAP_READ
);
436 uint32_t *state
= brw_bo_map(brw
, batch
->state
.bo
, MAP_READ
);
437 if (batch_data
== NULL
|| state
== NULL
) {
438 fprintf(stderr
, "WARNING: failed to map batchbuffer/statebuffer\n");
442 uint32_t *end
= batch_data
+ USED_BATCH(*batch
);
443 uint32_t batch_gtt_offset
= batch
->batch
.bo
->gtt_offset
;
444 uint32_t state_gtt_offset
= batch
->state
.bo
->gtt_offset
;
447 bool color
= INTEL_DEBUG
& DEBUG_COLOR
;
448 const char *header_color
= color
? BLUE_HEADER
: "";
449 const char *reset_color
= color
? NORMAL
: "";
451 for (uint32_t *p
= batch_data
; p
< end
; p
+= length
) {
452 struct gen_group
*inst
= gen_spec_find_instruction(spec
, p
);
453 length
= gen_group_get_length(inst
, p
);
454 assert(inst
== NULL
|| length
> 0);
455 length
= MAX2(1, length
);
457 fprintf(stderr
, "unknown instruction %08x\n", p
[0]);
461 uint64_t offset
= batch_gtt_offset
+ 4 * (p
- batch_data
);
463 fprintf(stderr
, "%s0x%08"PRIx64
": 0x%08x: %-80s%s\n", header_color
,
464 offset
, p
[0], gen_group_get_name(inst
), reset_color
);
466 gen_print_group(stderr
, inst
, offset
, p
, color
);
468 switch (gen_group_get_opcode(inst
) >> 16) {
469 case _3DSTATE_PIPELINED_POINTERS
:
470 /* Note: these Gen4-5 pointers are full relocations rather than
471 * offsets from the start of the statebuffer. So we need to subtract
472 * gtt_offset (the start of the statebuffer) to obtain an offset we
473 * can add to the map and get at the data.
475 decode_struct(brw
, spec
, "VS_STATE", state
, state_gtt_offset
,
476 (p
[1] & ~0x1fu
) - state_gtt_offset
, color
);
478 decode_struct(brw
, spec
, "GS_STATE", state
, state_gtt_offset
,
479 (p
[2] & ~0x1fu
) - state_gtt_offset
, color
);
482 decode_struct(brw
, spec
, "CLIP_STATE", state
, state_gtt_offset
,
483 (p
[3] & ~0x1fu
) - state_gtt_offset
, color
);
485 decode_struct(brw
, spec
, "SF_STATE", state
, state_gtt_offset
,
486 (p
[4] & ~0x1fu
) - state_gtt_offset
, color
);
487 decode_struct(brw
, spec
, "WM_STATE", state
, state_gtt_offset
,
488 (p
[5] & ~0x1fu
) - state_gtt_offset
, color
);
489 decode_struct(brw
, spec
, "COLOR_CALC_STATE", state
, state_gtt_offset
,
490 (p
[6] & ~0x3fu
) - state_gtt_offset
, color
);
492 case _3DSTATE_BINDING_TABLE_POINTERS_VS
:
493 case _3DSTATE_BINDING_TABLE_POINTERS_HS
:
494 case _3DSTATE_BINDING_TABLE_POINTERS_DS
:
495 case _3DSTATE_BINDING_TABLE_POINTERS_GS
:
496 case _3DSTATE_BINDING_TABLE_POINTERS_PS
: {
497 struct gen_group
*group
=
498 gen_spec_find_struct(spec
, "RENDER_SURFACE_STATE");
502 uint32_t bt_offset
= p
[1] & ~0x1fu
;
503 int bt_entries
= brw_state_batch_size(brw
, bt_offset
) / 4;
504 uint32_t *bt_pointers
= &state
[bt_offset
/ 4];
505 for (int i
= 0; i
< bt_entries
; i
++) {
506 fprintf(stderr
, "SURFACE_STATE - BTI = %d\n", i
);
507 gen_print_group(stderr
, group
, state_gtt_offset
+ bt_pointers
[i
],
508 &state
[bt_pointers
[i
] / 4], color
);
512 case _3DSTATE_SAMPLER_STATE_POINTERS_VS
:
513 case _3DSTATE_SAMPLER_STATE_POINTERS_HS
:
514 case _3DSTATE_SAMPLER_STATE_POINTERS_DS
:
515 case _3DSTATE_SAMPLER_STATE_POINTERS_GS
:
516 case _3DSTATE_SAMPLER_STATE_POINTERS_PS
:
517 decode_structs(brw
, spec
, "SAMPLER_STATE", state
,
518 state_gtt_offset
, p
[1] & ~0x1fu
, 4 * 4, color
);
520 case _3DSTATE_VIEWPORT_STATE_POINTERS
:
521 decode_structs(brw
, spec
, "CLIP_VIEWPORT", state
,
522 state_gtt_offset
, p
[1] & ~0x3fu
, 4 * 4, color
);
523 decode_structs(brw
, spec
, "SF_VIEWPORT", state
,
524 state_gtt_offset
, p
[1] & ~0x3fu
, 8 * 4, color
);
525 decode_structs(brw
, spec
, "CC_VIEWPORT", state
,
526 state_gtt_offset
, p
[3] & ~0x3fu
, 2 * 4, color
);
528 case _3DSTATE_VIEWPORT_STATE_POINTERS_CC
:
529 decode_structs(brw
, spec
, "CC_VIEWPORT", state
,
530 state_gtt_offset
, p
[1] & ~0x3fu
, 2 * 4, color
);
532 case _3DSTATE_VIEWPORT_STATE_POINTERS_SF_CL
:
533 decode_structs(brw
, spec
, "SF_CLIP_VIEWPORT", state
,
534 state_gtt_offset
, p
[1] & ~0x3fu
, 16 * 4, color
);
536 case _3DSTATE_SCISSOR_STATE_POINTERS
:
537 decode_structs(brw
, spec
, "SCISSOR_RECT", state
,
538 state_gtt_offset
, p
[1] & ~0x1fu
, 2 * 4, color
);
540 case _3DSTATE_BLEND_STATE_POINTERS
:
541 /* TODO: handle Gen8+ extra dword at the beginning */
542 decode_structs(brw
, spec
, "BLEND_STATE", state
,
543 state_gtt_offset
, p
[1] & ~0x3fu
, 8 * 4, color
);
545 case _3DSTATE_CC_STATE_POINTERS
:
546 if (devinfo
->gen
>= 7) {
547 decode_struct(brw
, spec
, "COLOR_CALC_STATE", state
,
548 state_gtt_offset
, p
[1] & ~0x3fu
, color
);
549 } else if (devinfo
->gen
== 6) {
550 decode_structs(brw
, spec
, "BLEND_STATE", state
,
551 state_gtt_offset
, p
[1] & ~0x3fu
, 2 * 4, color
);
552 decode_struct(brw
, spec
, "DEPTH_STENCIL_STATE", state
,
553 state_gtt_offset
, p
[2] & ~0x3fu
, color
);
554 decode_struct(brw
, spec
, "COLOR_CALC_STATE", state
,
555 state_gtt_offset
, p
[3] & ~0x3fu
, color
);
558 case _3DSTATE_DEPTH_STENCIL_STATE_POINTERS
:
559 decode_struct(brw
, spec
, "DEPTH_STENCIL_STATE", state
,
560 state_gtt_offset
, p
[1] & ~0x3fu
, color
);
562 case MEDIA_INTERFACE_DESCRIPTOR_LOAD
: {
563 struct gen_group
*group
=
564 gen_spec_find_struct(spec
, "RENDER_SURFACE_STATE");
568 uint32_t idd_offset
= p
[3] & ~0x1fu
;
569 decode_struct(brw
, spec
, "INTERFACE_DESCRIPTOR_DATA", state
,
570 state_gtt_offset
, idd_offset
, color
);
572 uint32_t ss_offset
= state
[idd_offset
/ 4 + 3] & ~0x1fu
;
573 decode_structs(brw
, spec
, "SAMPLER_STATE", state
,
574 state_gtt_offset
, ss_offset
, 4 * 4, color
);
576 uint32_t bt_offset
= state
[idd_offset
/ 4 + 4] & ~0x1fu
;
577 int bt_entries
= brw_state_batch_size(brw
, bt_offset
) / 4;
578 uint32_t *bt_pointers
= &state
[bt_offset
/ 4];
579 for (int i
= 0; i
< bt_entries
; i
++) {
580 fprintf(stderr
, "SURFACE_STATE - BTI = %d\n", i
);
581 gen_print_group(stderr
, group
, state_gtt_offset
+ bt_pointers
[i
],
582 &state
[bt_pointers
[i
] / 4], color
);
589 brw_bo_unmap(batch
->batch
.bo
);
590 brw_bo_unmap(batch
->state
.bo
);
593 static void do_batch_dump(struct brw_context
*brw
) { }
597 * Called when starting a new batch buffer.
600 brw_new_batch(struct brw_context
*brw
)
602 /* Unreference any BOs held by the previous batch, and reset counts. */
603 for (int i
= 0; i
< brw
->batch
.exec_count
; i
++) {
604 brw_bo_unreference(brw
->batch
.exec_bos
[i
]);
605 brw
->batch
.exec_bos
[i
] = NULL
;
607 brw
->batch
.batch_relocs
.reloc_count
= 0;
608 brw
->batch
.state_relocs
.reloc_count
= 0;
609 brw
->batch
.exec_count
= 0;
610 brw
->batch
.aperture_space
= 0;
612 brw_bo_unreference(brw
->batch
.state
.bo
);
614 /* Create a new batchbuffer and reset the associated state: */
615 intel_batchbuffer_reset_and_clear_render_cache(brw
);
617 /* If the kernel supports hardware contexts, then most hardware state is
618 * preserved between batches; we only need to re-emit state that is required
619 * to be in every batch. Otherwise we need to re-emit all the state that
620 * would otherwise be stored in the context (which for all intents and
621 * purposes means everything).
623 if (brw
->hw_ctx
== 0) {
624 brw
->ctx
.NewDriverState
|= BRW_NEW_CONTEXT
;
625 brw_upload_invariant_state(brw
);
628 brw
->ctx
.NewDriverState
|= BRW_NEW_BATCH
;
630 brw
->ib
.index_size
= -1;
632 /* We need to periodically reap the shader time results, because rollover
633 * happens every few seconds. We also want to see results every once in a
634 * while, because many programs won't cleanly destroy our context, so the
635 * end-of-run printout may not happen.
637 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
638 brw_collect_and_report_shader_time(brw
);
642 * Called from intel_batchbuffer_flush before emitting MI_BATCHBUFFER_END and
645 * This function can emit state (say, to preserve registers that aren't saved
649 brw_finish_batch(struct brw_context
*brw
)
651 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
653 brw
->batch
.no_wrap
= true;
655 /* Capture the closing pipeline statistics register values necessary to
656 * support query objects (in the non-hardware context world).
658 brw_emit_query_end(brw
);
660 if (brw
->batch
.ring
== RENDER_RING
) {
661 /* Work around L3 state leaks into contexts set MI_RESTORE_INHIBIT which
662 * assume that the L3 cache is configured according to the hardware
665 if (devinfo
->gen
>= 7)
666 gen7_restore_default_l3_config(brw
);
668 if (devinfo
->is_haswell
) {
669 /* From the Haswell PRM, Volume 2b, Command Reference: Instructions,
670 * 3DSTATE_CC_STATE_POINTERS > "Note":
672 * "SW must program 3DSTATE_CC_STATE_POINTERS command at the end of every
673 * 3D batch buffer followed by a PIPE_CONTROL with RC flush and CS stall."
675 * From the example in the docs, it seems to expect a regular pipe control
676 * flush here as well. We may have done it already, but meh.
678 * See also WaAvoidRCZCounterRollover.
680 brw_emit_mi_flush(brw
);
682 OUT_BATCH(_3DSTATE_CC_STATE_POINTERS
<< 16 | (2 - 2));
683 OUT_BATCH(brw
->cc
.state_offset
| 1);
685 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_RENDER_TARGET_FLUSH
|
686 PIPE_CONTROL_CS_STALL
);
690 /* Mark the end of the buffer. */
691 intel_batchbuffer_emit_dword(&brw
->batch
, MI_BATCH_BUFFER_END
);
692 if (USED_BATCH(brw
->batch
) & 1) {
693 /* Round batchbuffer usage to 2 DWORDs. */
694 intel_batchbuffer_emit_dword(&brw
->batch
, MI_NOOP
);
697 brw
->batch
.no_wrap
= false;
701 throttle(struct brw_context
*brw
)
703 /* Wait for the swapbuffers before the one we just emitted, so we
704 * don't get too many swaps outstanding for apps that are GPU-heavy
707 * We're using intelDRI2Flush (called from the loader before
708 * swapbuffer) and glFlush (for front buffer rendering) as the
709 * indicator that a frame is done and then throttle when we get
710 * here as we prepare to render the next frame. At this point for
711 * round trips for swap/copy and getting new buffers are done and
712 * we'll spend less time waiting on the GPU.
714 * Unfortunately, we don't have a handle to the batch containing
715 * the swap, and getting our hands on that doesn't seem worth it,
716 * so we just use the first batch we emitted after the last swap.
718 if (brw
->need_swap_throttle
&& brw
->throttle_batch
[0]) {
719 if (brw
->throttle_batch
[1]) {
720 if (!brw
->disable_throttling
) {
721 /* Pass NULL rather than brw so we avoid perf_debug warnings;
722 * stalling is common and expected here...
724 brw_bo_wait_rendering(brw
->throttle_batch
[1]);
726 brw_bo_unreference(brw
->throttle_batch
[1]);
728 brw
->throttle_batch
[1] = brw
->throttle_batch
[0];
729 brw
->throttle_batch
[0] = NULL
;
730 brw
->need_swap_throttle
= false;
731 /* Throttling here is more precise than the throttle ioctl, so skip it */
732 brw
->need_flush_throttle
= false;
735 if (brw
->need_flush_throttle
) {
736 __DRIscreen
*dri_screen
= brw
->screen
->driScrnPriv
;
737 drmCommandNone(dri_screen
->fd
, DRM_I915_GEM_THROTTLE
);
738 brw
->need_flush_throttle
= false;
744 struct intel_batchbuffer
*batch
,
751 struct drm_i915_gem_execbuffer2 execbuf
= {
752 .buffers_ptr
= (uintptr_t) batch
->validation_list
,
753 .buffer_count
= batch
->exec_count
,
754 .batch_start_offset
= 0,
757 .rsvd1
= ctx_id
, /* rsvd1 is actually the context ID */
760 unsigned long cmd
= DRM_IOCTL_I915_GEM_EXECBUFFER2
;
762 if (in_fence
!= -1) {
763 execbuf
.rsvd2
= in_fence
;
764 execbuf
.flags
|= I915_EXEC_FENCE_IN
;
767 if (out_fence
!= NULL
) {
768 cmd
= DRM_IOCTL_I915_GEM_EXECBUFFER2_WR
;
770 execbuf
.flags
|= I915_EXEC_FENCE_OUT
;
773 int ret
= drmIoctl(fd
, cmd
, &execbuf
);
777 for (int i
= 0; i
< batch
->exec_count
; i
++) {
778 struct brw_bo
*bo
= batch
->exec_bos
[i
];
783 /* Update brw_bo::gtt_offset */
784 if (batch
->validation_list
[i
].offset
!= bo
->gtt_offset
) {
785 DBG("BO %d migrated: 0x%" PRIx64
" -> 0x%llx\n",
786 bo
->gem_handle
, bo
->gtt_offset
,
787 batch
->validation_list
[i
].offset
);
788 bo
->gtt_offset
= batch
->validation_list
[i
].offset
;
792 if (ret
== 0 && out_fence
!= NULL
)
793 *out_fence
= execbuf
.rsvd2
>> 32;
799 submit_batch(struct brw_context
*brw
, int in_fence_fd
, int *out_fence_fd
)
801 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
802 __DRIscreen
*dri_screen
= brw
->screen
->driScrnPriv
;
803 struct intel_batchbuffer
*batch
= &brw
->batch
;
806 if (batch
->batch
.cpu_map
) {
807 void *bo_map
= brw_bo_map(brw
, batch
->batch
.bo
, MAP_WRITE
);
808 memcpy(bo_map
, batch
->batch
.cpu_map
, 4 * USED_BATCH(*batch
));
811 if (batch
->state
.cpu_map
) {
812 void *bo_map
= brw_bo_map(brw
, batch
->state
.bo
, MAP_WRITE
);
813 memcpy(bo_map
, batch
->state
.cpu_map
, batch
->state_used
);
816 brw_bo_unmap(batch
->batch
.bo
);
817 brw_bo_unmap(batch
->state
.bo
);
819 if (!brw
->screen
->no_hw
) {
820 /* The requirement for using I915_EXEC_NO_RELOC are:
822 * The addresses written in the objects must match the corresponding
823 * reloc.gtt_offset which in turn must match the corresponding
826 * Any render targets written to in the batch must be flagged with
829 * To avoid stalling, execobject.offset should match the current
830 * address of that object within the active context.
832 int flags
= I915_EXEC_NO_RELOC
;
834 if (devinfo
->gen
>= 6 && batch
->ring
== BLT_RING
) {
835 flags
|= I915_EXEC_BLT
;
837 flags
|= I915_EXEC_RENDER
;
839 if (batch
->needs_sol_reset
)
840 flags
|= I915_EXEC_GEN7_SOL_RESET
;
842 uint32_t hw_ctx
= batch
->ring
== RENDER_RING
? brw
->hw_ctx
: 0;
844 /* Set statebuffer relocations */
845 const unsigned state_index
= batch
->state
.bo
->index
;
846 if (state_index
< batch
->exec_count
&&
847 batch
->exec_bos
[state_index
] == batch
->state
.bo
) {
848 struct drm_i915_gem_exec_object2
*entry
=
849 &batch
->validation_list
[state_index
];
850 assert(entry
->handle
== batch
->state
.bo
->gem_handle
);
851 entry
->relocation_count
= batch
->state_relocs
.reloc_count
;
852 entry
->relocs_ptr
= (uintptr_t) batch
->state_relocs
.relocs
;
855 /* Set batchbuffer relocations */
856 struct drm_i915_gem_exec_object2
*entry
= &batch
->validation_list
[0];
857 assert(entry
->handle
== batch
->batch
.bo
->gem_handle
);
858 entry
->relocation_count
= batch
->batch_relocs
.reloc_count
;
859 entry
->relocs_ptr
= (uintptr_t) batch
->batch_relocs
.relocs
;
861 if (batch
->use_batch_first
) {
862 flags
|= I915_EXEC_BATCH_FIRST
| I915_EXEC_HANDLE_LUT
;
864 /* Move the batch to the end of the validation list */
865 struct drm_i915_gem_exec_object2 tmp
;
866 const unsigned index
= batch
->exec_count
- 1;
869 *entry
= batch
->validation_list
[index
];
870 batch
->validation_list
[index
] = tmp
;
873 ret
= execbuffer(dri_screen
->fd
, batch
, hw_ctx
,
874 4 * USED_BATCH(*batch
),
875 in_fence_fd
, out_fence_fd
, flags
);
880 if (unlikely(INTEL_DEBUG
& DEBUG_BATCH
))
883 if (brw
->ctx
.Const
.ResetStrategy
== GL_LOSE_CONTEXT_ON_RESET_ARB
)
884 brw_check_for_reset(brw
);
887 fprintf(stderr
, "i965: Failed to submit batchbuffer: %s\n",
896 * The in_fence_fd is ignored if -1. Otherwise this function takes ownership
899 * The out_fence_fd is ignored if NULL. Otherwise, the caller takes ownership
900 * of the returned fd.
903 _intel_batchbuffer_flush_fence(struct brw_context
*brw
,
904 int in_fence_fd
, int *out_fence_fd
,
905 const char *file
, int line
)
909 if (USED_BATCH(brw
->batch
) == 0)
912 /* Check that we didn't just wrap our batchbuffer at a bad time. */
913 assert(!brw
->batch
.no_wrap
);
915 brw_finish_batch(brw
);
916 intel_upload_finish(brw
);
918 if (brw
->throttle_batch
[0] == NULL
) {
919 brw
->throttle_batch
[0] = brw
->batch
.batch
.bo
;
920 brw_bo_reference(brw
->throttle_batch
[0]);
923 if (unlikely(INTEL_DEBUG
& (DEBUG_BATCH
| DEBUG_SUBMIT
))) {
924 int bytes_for_commands
= 4 * USED_BATCH(brw
->batch
);
925 int bytes_for_state
= brw
->batch
.state_used
;
926 fprintf(stderr
, "%19s:%-3d: Batchbuffer flush with %5db (%0.1f%%) (pkt),"
927 " %5db (%0.1f%%) (state), %4d BOs (%0.1fMb aperture),"
928 " %4d batch relocs, %4d state relocs\n", file
, line
,
929 bytes_for_commands
, 100.0f
* bytes_for_commands
/ BATCH_SZ
,
930 bytes_for_state
, 100.0f
* bytes_for_state
/ STATE_SZ
,
931 brw
->batch
.exec_count
,
932 (float) brw
->batch
.aperture_space
/ (1024 * 1024),
933 brw
->batch
.batch_relocs
.reloc_count
,
934 brw
->batch
.state_relocs
.reloc_count
);
937 ret
= submit_batch(brw
, in_fence_fd
, out_fence_fd
);
939 if (unlikely(INTEL_DEBUG
& DEBUG_SYNC
)) {
940 fprintf(stderr
, "waiting for idle\n");
941 brw_bo_wait_rendering(brw
->batch
.batch
.bo
);
944 /* Start a new batch buffer. */
951 brw_batch_has_aperture_space(struct brw_context
*brw
, unsigned extra_space
)
953 return brw
->batch
.aperture_space
+ extra_space
<=
954 brw
->screen
->aperture_threshold
;
958 brw_batch_references(struct intel_batchbuffer
*batch
, struct brw_bo
*bo
)
960 unsigned index
= READ_ONCE(bo
->index
);
961 if (index
< batch
->exec_count
&& batch
->exec_bos
[index
] == bo
)
964 for (int i
= 0; i
< batch
->exec_count
; i
++) {
965 if (batch
->exec_bos
[i
] == bo
)
971 /* This is the only way buffers get added to the validate list.
974 emit_reloc(struct intel_batchbuffer
*batch
,
975 struct brw_reloc_list
*rlist
, uint32_t offset
,
976 struct brw_bo
*target
, uint32_t target_offset
,
977 unsigned int reloc_flags
)
979 assert(target
!= NULL
);
981 if (rlist
->reloc_count
== rlist
->reloc_array_size
) {
982 rlist
->reloc_array_size
*= 2;
983 rlist
->relocs
= realloc(rlist
->relocs
,
984 rlist
->reloc_array_size
*
985 sizeof(struct drm_i915_gem_relocation_entry
));
988 unsigned int index
= add_exec_bo(batch
, target
);
989 struct drm_i915_gem_exec_object2
*entry
= &batch
->validation_list
[index
];
992 entry
->flags
|= reloc_flags
& batch
->valid_reloc_flags
;
994 rlist
->relocs
[rlist
->reloc_count
++] =
995 (struct drm_i915_gem_relocation_entry
) {
997 .delta
= target_offset
,
998 .target_handle
= batch
->use_batch_first
? index
: target
->gem_handle
,
999 .presumed_offset
= entry
->offset
,
1002 /* Using the old buffer offset, write in what the right data would be, in
1003 * case the buffer doesn't move and we can short-circuit the relocation
1004 * processing in the kernel
1006 return entry
->offset
+ target_offset
;
1010 brw_batch_reloc(struct intel_batchbuffer
*batch
, uint32_t batch_offset
,
1011 struct brw_bo
*target
, uint32_t target_offset
,
1012 unsigned int reloc_flags
)
1014 assert(batch_offset
<= batch
->batch
.bo
->size
- sizeof(uint32_t));
1016 return emit_reloc(batch
, &batch
->batch_relocs
, batch_offset
,
1017 target
, target_offset
, reloc_flags
);
1021 brw_state_reloc(struct intel_batchbuffer
*batch
, uint32_t state_offset
,
1022 struct brw_bo
*target
, uint32_t target_offset
,
1023 unsigned int reloc_flags
)
1025 assert(state_offset
<= batch
->state
.bo
->size
- sizeof(uint32_t));
1027 return emit_reloc(batch
, &batch
->state_relocs
, state_offset
,
1028 target
, target_offset
, reloc_flags
);
1033 brw_state_batch_size(struct brw_context
*brw
, uint32_t offset
)
1035 struct hash_entry
*entry
=
1036 _mesa_hash_table_search(brw
->batch
.state_batch_sizes
,
1037 (void *) (uintptr_t) offset
);
1038 return entry
? (uintptr_t) entry
->data
: 0;
1042 * Reserve some space in the statebuffer, or flush.
1044 * This is used to estimate when we're near the end of the batch,
1045 * so we can flush early.
1048 brw_require_statebuffer_space(struct brw_context
*brw
, int size
)
1050 if (brw
->batch
.state_used
+ size
>= STATE_SZ
)
1051 intel_batchbuffer_flush(brw
);
1055 * Allocates a block of space in the batchbuffer for indirect state.
1058 brw_state_batch(struct brw_context
*brw
,
1061 uint32_t *out_offset
)
1063 struct intel_batchbuffer
*batch
= &brw
->batch
;
1065 assert(size
< batch
->state
.bo
->size
);
1067 uint32_t offset
= ALIGN(batch
->state_used
, alignment
);
1069 if (offset
+ size
>= STATE_SZ
&& !batch
->no_wrap
) {
1070 intel_batchbuffer_flush(brw
);
1071 offset
= ALIGN(batch
->state_used
, alignment
);
1072 } else if (offset
+ size
>= batch
->state
.bo
->size
) {
1073 const unsigned new_size
=
1074 MIN2(batch
->state
.bo
->size
+ batch
->state
.bo
->size
/ 2,
1076 grow_buffer(brw
, &batch
->state
.bo
, &batch
->state
.map
,
1077 &batch
->state
.cpu_map
, batch
->state_used
, new_size
);
1078 assert(offset
+ size
< batch
->state
.bo
->size
);
1081 if (unlikely(INTEL_DEBUG
& DEBUG_BATCH
)) {
1082 _mesa_hash_table_insert(batch
->state_batch_sizes
,
1083 (void *) (uintptr_t) offset
,
1084 (void *) (uintptr_t) size
);
1087 batch
->state_used
= offset
+ size
;
1089 *out_offset
= offset
;
1090 return batch
->state
.map
+ (offset
>> 2);
1094 intel_batchbuffer_data(struct brw_context
*brw
,
1095 const void *data
, GLuint bytes
, enum brw_gpu_ring ring
)
1097 assert((bytes
& 3) == 0);
1098 intel_batchbuffer_require_space(brw
, bytes
, ring
);
1099 memcpy(brw
->batch
.map_next
, data
, bytes
);
1100 brw
->batch
.map_next
+= bytes
>> 2;
1104 load_sized_register_mem(struct brw_context
*brw
,
1110 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1113 /* MI_LOAD_REGISTER_MEM only exists on Gen7+. */
1114 assert(devinfo
->gen
>= 7);
1116 if (devinfo
->gen
>= 8) {
1117 BEGIN_BATCH(4 * size
);
1118 for (i
= 0; i
< size
; i
++) {
1119 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM
| (4 - 2));
1120 OUT_BATCH(reg
+ i
* 4);
1121 OUT_RELOC64(bo
, 0, offset
+ i
* 4);
1125 BEGIN_BATCH(3 * size
);
1126 for (i
= 0; i
< size
; i
++) {
1127 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM
| (3 - 2));
1128 OUT_BATCH(reg
+ i
* 4);
1129 OUT_RELOC(bo
, 0, offset
+ i
* 4);
1136 brw_load_register_mem(struct brw_context
*brw
,
1141 load_sized_register_mem(brw
, reg
, bo
, offset
, 1);
1145 brw_load_register_mem64(struct brw_context
*brw
,
1150 load_sized_register_mem(brw
, reg
, bo
, offset
, 2);
1154 * Write an arbitrary 32-bit register to a buffer via MI_STORE_REGISTER_MEM.
1157 brw_store_register_mem32(struct brw_context
*brw
,
1158 struct brw_bo
*bo
, uint32_t reg
, uint32_t offset
)
1160 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1162 assert(devinfo
->gen
>= 6);
1164 if (devinfo
->gen
>= 8) {
1166 OUT_BATCH(MI_STORE_REGISTER_MEM
| (4 - 2));
1168 OUT_RELOC64(bo
, RELOC_WRITE
, offset
);
1172 OUT_BATCH(MI_STORE_REGISTER_MEM
| (3 - 2));
1174 OUT_RELOC(bo
, RELOC_WRITE
| RELOC_NEEDS_GGTT
, offset
);
1180 * Write an arbitrary 64-bit register to a buffer via MI_STORE_REGISTER_MEM.
1183 brw_store_register_mem64(struct brw_context
*brw
,
1184 struct brw_bo
*bo
, uint32_t reg
, uint32_t offset
)
1186 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1188 assert(devinfo
->gen
>= 6);
1190 /* MI_STORE_REGISTER_MEM only stores a single 32-bit value, so to
1191 * read a full 64-bit register, we need to do two of them.
1193 if (devinfo
->gen
>= 8) {
1195 OUT_BATCH(MI_STORE_REGISTER_MEM
| (4 - 2));
1197 OUT_RELOC64(bo
, RELOC_WRITE
, offset
);
1198 OUT_BATCH(MI_STORE_REGISTER_MEM
| (4 - 2));
1199 OUT_BATCH(reg
+ sizeof(uint32_t));
1200 OUT_RELOC64(bo
, RELOC_WRITE
, offset
+ sizeof(uint32_t));
1204 OUT_BATCH(MI_STORE_REGISTER_MEM
| (3 - 2));
1206 OUT_RELOC(bo
, RELOC_WRITE
| RELOC_NEEDS_GGTT
, offset
);
1207 OUT_BATCH(MI_STORE_REGISTER_MEM
| (3 - 2));
1208 OUT_BATCH(reg
+ sizeof(uint32_t));
1209 OUT_RELOC(bo
, RELOC_WRITE
| RELOC_NEEDS_GGTT
, offset
+ sizeof(uint32_t));
1215 * Write a 32-bit register using immediate data.
1218 brw_load_register_imm32(struct brw_context
*brw
, uint32_t reg
, uint32_t imm
)
1220 assert(brw
->screen
->devinfo
.gen
>= 6);
1223 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
1230 * Write a 64-bit register using immediate data.
1233 brw_load_register_imm64(struct brw_context
*brw
, uint32_t reg
, uint64_t imm
)
1235 assert(brw
->screen
->devinfo
.gen
>= 6);
1238 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (5 - 2));
1240 OUT_BATCH(imm
& 0xffffffff);
1242 OUT_BATCH(imm
>> 32);
1247 * Copies a 32-bit register.
1250 brw_load_register_reg(struct brw_context
*brw
, uint32_t src
, uint32_t dest
)
1252 assert(brw
->screen
->devinfo
.gen
>= 8 || brw
->screen
->devinfo
.is_haswell
);
1255 OUT_BATCH(MI_LOAD_REGISTER_REG
| (3 - 2));
1262 * Copies a 64-bit register.
1265 brw_load_register_reg64(struct brw_context
*brw
, uint32_t src
, uint32_t dest
)
1267 assert(brw
->screen
->devinfo
.gen
>= 8 || brw
->screen
->devinfo
.is_haswell
);
1270 OUT_BATCH(MI_LOAD_REGISTER_REG
| (3 - 2));
1273 OUT_BATCH(MI_LOAD_REGISTER_REG
| (3 - 2));
1274 OUT_BATCH(src
+ sizeof(uint32_t));
1275 OUT_BATCH(dest
+ sizeof(uint32_t));
1280 * Write 32-bits of immediate data to a GPU memory buffer.
1283 brw_store_data_imm32(struct brw_context
*brw
, struct brw_bo
*bo
,
1284 uint32_t offset
, uint32_t imm
)
1286 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1288 assert(devinfo
->gen
>= 6);
1291 OUT_BATCH(MI_STORE_DATA_IMM
| (4 - 2));
1292 if (devinfo
->gen
>= 8)
1293 OUT_RELOC64(bo
, RELOC_WRITE
, offset
);
1295 OUT_BATCH(0); /* MBZ */
1296 OUT_RELOC(bo
, RELOC_WRITE
, offset
);
1303 * Write 64-bits of immediate data to a GPU memory buffer.
1306 brw_store_data_imm64(struct brw_context
*brw
, struct brw_bo
*bo
,
1307 uint32_t offset
, uint64_t imm
)
1309 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1311 assert(devinfo
->gen
>= 6);
1314 OUT_BATCH(MI_STORE_DATA_IMM
| (5 - 2));
1315 if (devinfo
->gen
>= 8)
1316 OUT_RELOC64(bo
, 0, offset
);
1318 OUT_BATCH(0); /* MBZ */
1319 OUT_RELOC(bo
, RELOC_WRITE
, offset
);
1321 OUT_BATCH(imm
& 0xffffffffu
);
1322 OUT_BATCH(imm
>> 32);