1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
11 #include "intel_allocator.h"
18 * Tiling mode in the I915_TILING_... namespace for new tiling modes which are
19 * defined in the kernel. (They are not fenceable so the kernel does not need
20 * to know about them.)
22 * They are to be used the the blitting routines below.
24 #define I915_TILING_4 (I915_TILING_LAST + 1)
25 #define I915_TILING_Yf (I915_TILING_LAST + 2)
26 #define I915_TILING_Ys (I915_TILING_LAST + 3)
27 #define I915_TILING_64 (I915_TILING_LAST + 4)
29 enum i915_compression
{
30 I915_COMPRESSION_NONE
,
31 I915_COMPRESSION_RENDER
,
32 I915_COMPRESSION_MEDIA
,
35 uint32_t fast_copy_dword0(unsigned int src_tiling
,
36 unsigned int dst_tiling
);
37 uint32_t fast_copy_dword1(int fd
, unsigned int src_tiling
,
38 unsigned int dst_tiling
,
40 void igt_blitter_copy(int fd
,
43 const intel_ctx_cfg_t
*cfg
,
49 uint32_t src_x
, uint32_t src_y
,
52 uint32_t width
, uint32_t height
,
60 uint32_t dst_x
, uint32_t dst_y
,
63 void igt_blitter_src_copy(int fd
,
66 const intel_ctx_cfg_t
*cfg
,
72 uint32_t src_x
, uint32_t src_y
,
76 uint32_t width
, uint32_t height
,
86 uint32_t dst_x
, uint32_t dst_y
,
89 void igt_blitter_fast_copy__raw(int fd
,
92 const intel_ctx_cfg_t
*cfg
,
95 unsigned int src_delta
,
96 unsigned int src_stride
,
97 unsigned int src_tiling
,
98 unsigned int src_x
, unsigned src_y
,
102 unsigned int width
, unsigned int height
,
109 unsigned int dst_delta
,
110 unsigned int dst_stride
,
111 unsigned int dst_tiling
,
112 unsigned int dst_x
, unsigned dst_y
,
116 * igt_render_copyfunc_t:
118 * @ctx: context to use
119 * @src: intel_buf source object
120 * @src_x: source pixel x-coordination
121 * @src_y: source pixel y-coordination
122 * @width: width of the copied rectangle
123 * @height: height of the copied rectangle
124 * @dst: intel_buf destination object
125 * @dst_x: destination pixel x-coordination
126 * @dst_y: destination pixel y-coordination
128 * This is the type of the per-platform render copy functions. The
129 * platform-specific implementation can be obtained by calling
130 * igt_get_render_copyfunc().
132 * A render copy function will emit a batchbuffer to the kernel which executes
133 * the specified blit copy operation using the render engine. @ctx is
134 * optional and can be 0.
139 typedef void (*igt_render_copyfunc_t
)(struct intel_bb
*ibb
,
140 struct intel_buf
*src
,
141 uint32_t src_x
, uint32_t src_y
,
142 uint32_t width
, uint32_t height
,
143 struct intel_buf
*dst
,
144 uint32_t dst_x
, uint32_t dst_y
);
146 igt_render_copyfunc_t
igt_get_render_copyfunc(int devid
);
150 * igt_vebox_copyfunc_t:
152 * @src: intel_buf source object
153 * @width: width of the copied rectangle
154 * @height: height of the copied rectangle
155 * @dst: intel_buf destination object
157 * This is the type of the per-platform vebox copy functions. The
158 * platform-specific implementation can be obtained by calling
159 * igt_get_vebox_copyfunc().
161 * A vebox copy function will emit a batchbuffer to the kernel which executes
162 * the specified blit copy operation using the vebox engine.
164 typedef void (*igt_vebox_copyfunc_t
)(struct intel_bb
*ibb
,
165 struct intel_buf
*src
,
166 unsigned int width
, unsigned int height
,
167 struct intel_buf
*dst
);
169 igt_vebox_copyfunc_t
igt_get_vebox_copyfunc(int devid
);
171 typedef void (*igt_render_clearfunc_t
)(struct intel_bb
*ibb
,
172 struct intel_buf
*dst
, unsigned int dst_x
, unsigned int dst_y
,
173 unsigned int width
, unsigned int height
,
174 const float cc_color
[4]);
175 igt_render_clearfunc_t
igt_get_render_clearfunc(int devid
);
180 * @buf: destination intel_buf object
181 * @x: destination pixel x-coordination
182 * @y: destination pixel y-coordination
183 * @width: width of the filled rectangle
184 * @height: height of the filled rectangle
185 * @color: fill color to use
187 * This is the type of the per-platform fill functions using media
188 * or gpgpu pipeline. The platform-specific implementation can be obtained
189 * by calling igt_get_media_fillfunc() or igt_get_gpgpu_fillfunc().
191 * A fill function will emit a batchbuffer to the kernel which executes
192 * the specified blit fill operation using the media/gpgpu engine.
194 typedef void (*igt_fillfunc_t
)(int i915
,
195 struct intel_buf
*buf
,
196 unsigned x
, unsigned y
,
197 unsigned width
, unsigned height
,
200 igt_fillfunc_t
igt_get_gpgpu_fillfunc(int devid
);
201 igt_fillfunc_t
igt_get_media_fillfunc(int devid
);
203 typedef void (*igt_vme_func_t
)(int i915
,
205 struct intel_buf
*src
,
206 unsigned int width
, unsigned int height
,
207 struct intel_buf
*dst
);
209 igt_vme_func_t
igt_get_media_vme_func(int devid
);
212 * igt_media_spinfunc_t:
214 * @buf: destination buffer object
215 * @spins: number of loops to execute
217 * This is the type of the per-platform media spin functions. The
218 * platform-specific implementation can be obtained by calling
219 * igt_get_media_spinfunc().
221 * The media spin function emits a batchbuffer for the render engine with
222 * the media pipeline selected. The workload consists of a single thread
223 * which spins in a tight loop the requested number of times. Each spin
224 * increments a counter whose final 32-bit value is written to the
225 * destination buffer on completion. This utility provides a simple way
226 * to keep the render engine busy for a set time for various tests.
228 typedef void (*igt_media_spinfunc_t
)(int i915
,
229 struct intel_buf
*buf
, uint32_t spins
);
231 igt_media_spinfunc_t
igt_get_media_spinfunc(int devid
);
240 * Batchbuffer without libdrm dependency
243 struct igt_list_head link
;
245 uint64_t allocator_handle
;
246 uint64_t allocator_start
, allocator_end
;
247 uint8_t allocator_type
;
248 enum allocator_strategy allocator_strategy
;
250 enum intel_driver driver
;
265 bool supports_48b_address
;
266 bool uses_full_ppgtt
;
267 bool allows_obj_alignment
;
274 uint32_t engine_syncobj
;
276 uint32_t last_engine
;
278 /* Context configuration */
279 intel_ctx_cfg_t
*cfg
;
284 /* Current objects for execbuf */
287 /* Objects for current execbuf */
288 struct drm_i915_gem_exec_object2
**objects
;
289 uint32_t num_objects
;
290 uint32_t allocated_objects
;
291 uint64_t batch_offset
;
293 struct drm_i915_gem_relocation_entry
*relocs
;
295 uint32_t allocated_relocs
;
297 /* Tracked intel_bufs */
298 struct igt_list_head intel_bufs
;
301 * BO recreate in reset path only when refcount == 0
302 * Currently we don't need to use atomics because intel_bb
303 * is not thread-safe.
307 /* long running mode */
309 int64_t user_fence_offset
;
310 uint64_t user_fence_value
;
314 intel_bb_create_full(int fd
, uint32_t ctx
, uint32_t vm
,
315 const intel_ctx_cfg_t
*cfg
, uint32_t size
, uint64_t start
,
316 uint64_t end
, uint64_t alignment
, uint8_t allocator_type
,
317 enum allocator_strategy strategy
, uint64_t region
);
319 intel_bb_create_with_allocator(int fd
, uint32_t ctx
, uint32_t vm
,
320 const intel_ctx_cfg_t
*cfg
, uint32_t size
,
321 uint8_t allocator_type
);
322 struct intel_bb
*intel_bb_create(int fd
, uint32_t size
);
324 intel_bb_create_with_context(int fd
, uint32_t ctx
, uint32_t vm
,
325 const intel_ctx_cfg_t
*cfg
, uint32_t size
);
327 intel_bb_create_with_context_in_region(int fd
, uint32_t ctx
, uint32_t vm
,
328 const intel_ctx_cfg_t
*cfg
, uint32_t size
, uint64_t region
);
329 struct intel_bb
*intel_bb_create_with_relocs(int fd
, uint32_t size
);
331 intel_bb_create_with_relocs_and_context(int fd
, uint32_t ctx
,
332 const intel_ctx_cfg_t
*cfg
, uint32_t size
);
333 struct intel_bb
*intel_bb_create_no_relocs(int fd
, uint32_t size
);
334 void intel_bb_destroy(struct intel_bb
*ibb
);
336 /* make it safe to use intel_allocator after failed test */
337 void intel_bb_reinit_allocator(void);
338 void intel_bb_track(bool do_tracking
);
340 static inline void intel_bb_ref(struct intel_bb
*ibb
)
345 static inline void intel_bb_unref(struct intel_bb
*ibb
)
347 igt_assert_f(ibb
->refcount
> 0, "intel_bb refcount is 0!");
351 void intel_bb_reset(struct intel_bb
*ibb
, bool purge_objects_cache
);
352 int intel_bb_sync(struct intel_bb
*ibb
);
354 void intel_bb_print(struct intel_bb
*ibb
);
355 void intel_bb_dump(struct intel_bb
*ibb
, const char *filename
, bool in_hex
);
356 void intel_bb_set_debug(struct intel_bb
*ibb
, bool debug
);
357 void intel_bb_set_dump_base64(struct intel_bb
*ibb
, bool dump
);
359 static inline uint32_t intel_bb_offset(struct intel_bb
*ibb
)
361 return (uint32_t) ((uint8_t *) ibb
->ptr
- (uint8_t *) ibb
->batch
);
364 static inline void *intel_bb_ptr_get(struct intel_bb
*ibb
, uint32_t offset
)
366 igt_assert(offset
< ibb
->size
);
368 return ((uint8_t *) ibb
->batch
+ offset
);
371 static inline void intel_bb_ptr_set(struct intel_bb
*ibb
, uint32_t offset
)
373 ibb
->ptr
= (void *) ((uint8_t *) ibb
->batch
+ offset
);
375 igt_assert(intel_bb_offset(ibb
) <= ibb
->size
);
378 static inline void intel_bb_ptr_add(struct intel_bb
*ibb
, uint32_t offset
)
380 intel_bb_ptr_set(ibb
, intel_bb_offset(ibb
) + offset
);
383 static inline uint32_t intel_bb_ptr_add_return_prev_offset(struct intel_bb
*ibb
,
386 uint32_t previous_offset
= intel_bb_offset(ibb
);
388 intel_bb_ptr_set(ibb
, previous_offset
+ offset
);
390 return previous_offset
;
393 static inline void *intel_bb_ptr_align(struct intel_bb
*ibb
, uint32_t alignment
)
395 intel_bb_ptr_set(ibb
, ALIGN(intel_bb_offset(ibb
), alignment
));
397 return (void *) ibb
->ptr
;
400 static inline void *intel_bb_ptr(struct intel_bb
*ibb
)
402 return (void *) ibb
->ptr
;
405 static inline void intel_bb_out(struct intel_bb
*ibb
, uint32_t dword
)
410 igt_assert(intel_bb_offset(ibb
) <= ibb
->size
);
413 void intel_bb_set_pxp(struct intel_bb
*ibb
, bool new_state
,
414 uint32_t apptype
, uint32_t appid
);
416 static inline bool intel_bb_pxp_enabled(struct intel_bb
*ibb
)
419 return ibb
->pxp
.enabled
;
422 static inline uint32_t intel_bb_pxp_apptype(struct intel_bb
*ibb
)
425 return ibb
->pxp
.apptype
;
428 static inline uint32_t intel_bb_pxp_appid(struct intel_bb
*ibb
)
431 return ibb
->pxp
.appid
;
434 static inline void intel_bb_set_lr_mode(struct intel_bb
*ibb
, bool lr_mode
)
437 ibb
->lr_mode
= lr_mode
;
440 static inline bool intel_bb_get_lr_mode(struct intel_bb
*ibb
)
446 struct drm_i915_gem_exec_object2
*
447 intel_bb_add_object(struct intel_bb
*ibb
, uint32_t handle
, uint64_t size
,
448 uint64_t offset
, uint64_t alignment
, bool write
);
449 bool intel_bb_remove_object(struct intel_bb
*ibb
, uint32_t handle
,
450 uint64_t offset
, uint64_t size
);
451 struct drm_i915_gem_exec_object2
*
452 intel_bb_add_intel_buf(struct intel_bb
*ibb
, struct intel_buf
*buf
, bool write
);
453 struct drm_i915_gem_exec_object2
*
454 intel_bb_add_intel_buf_with_alignment(struct intel_bb
*ibb
, struct intel_buf
*buf
,
455 uint64_t alignment
, bool write
);
456 bool intel_bb_remove_intel_buf(struct intel_bb
*ibb
, struct intel_buf
*buf
);
457 void intel_bb_print_intel_bufs(struct intel_bb
*ibb
);
458 struct drm_i915_gem_exec_object2
*
459 intel_bb_find_object(struct intel_bb
*ibb
, uint32_t handle
);
462 intel_bb_object_set_flag(struct intel_bb
*ibb
, uint32_t handle
, uint64_t flag
);
464 intel_bb_object_clear_flag(struct intel_bb
*ibb
, uint32_t handle
, uint64_t flag
);
466 uint64_t intel_bb_emit_reloc(struct intel_bb
*ibb
,
468 uint32_t read_domains
,
469 uint32_t write_domain
,
471 uint64_t presumed_offset
);
473 uint64_t intel_bb_emit_reloc_fenced(struct intel_bb
*ibb
,
475 uint32_t read_domains
,
476 uint32_t write_domain
,
478 uint64_t presumed_offset
);
480 uint64_t intel_bb_offset_reloc(struct intel_bb
*ibb
,
482 uint32_t read_domains
,
483 uint32_t write_domain
,
485 uint64_t presumed_offset
);
487 uint64_t intel_bb_offset_reloc_with_delta(struct intel_bb
*ibb
,
489 uint32_t read_domains
,
490 uint32_t write_domain
,
493 uint64_t presumed_offset
);
495 uint64_t intel_bb_offset_reloc_to_object(struct intel_bb
*ibb
,
498 uint32_t read_domains
,
499 uint32_t write_domain
,
502 uint64_t presumed_offset
);
504 int __intel_bb_exec(struct intel_bb
*ibb
, uint32_t end_offset
,
505 uint64_t flags
, bool sync
);
507 void intel_bb_dump_cache(struct intel_bb
*ibb
);
509 void intel_bb_exec(struct intel_bb
*ibb
, uint32_t end_offset
,
510 uint64_t flags
, bool sync
);
512 uint64_t intel_bb_get_object_offset(struct intel_bb
*ibb
, uint32_t handle
);
513 bool intel_bb_object_offset_to_buf(struct intel_bb
*ibb
, struct intel_buf
*buf
);
515 uint32_t intel_bb_emit_bbe(struct intel_bb
*ibb
);
516 uint32_t intel_bb_emit_flush_common(struct intel_bb
*ibb
);
517 void intel_bb_flush(struct intel_bb
*ibb
, uint32_t ring
);
518 void intel_bb_flush_render(struct intel_bb
*ibb
);
519 void intel_bb_flush_blit(struct intel_bb
*ibb
);
521 uint32_t intel_bb_copy_data(struct intel_bb
*ibb
,
522 const void *data
, unsigned int bytes
,
525 void intel_bb_blit_start(struct intel_bb
*ibb
, uint32_t flags
);
526 void intel_bb_emit_blt_copy(struct intel_bb
*ibb
,
527 struct intel_buf
*src
,
528 int src_x1
, int src_y1
, int src_pitch
,
529 struct intel_buf
*dst
,
530 int dst_x1
, int dst_y1
, int dst_pitch
,
531 int width
, int height
, int bpp
);
532 void intel_bb_blt_copy(struct intel_bb
*ibb
,
533 struct intel_buf
*src
,
534 int src_x1
, int src_y1
, int src_pitch
,
535 struct intel_buf
*dst
,
536 int dst_x1
, int dst_y1
, int dst_pitch
,
537 int width
, int height
, int bpp
);
538 void intel_bb_copy_intel_buf(struct intel_bb
*ibb
,
539 struct intel_buf
*dst
, struct intel_buf
*src
,
543 * igt_huc_copyfunc_t:
545 * @ahnd: allocator handle, if it is equal to 0 we use relocations
546 * @obj: drm_i915_gem_exec_object2 buffer array
547 * obj[0] is source buffer
548 * obj[1] is destination buffer
549 * obj[2] is execution buffer
550 * @objsize: corresponding buffer sizes to @obj
552 * This is the type of the per-platform huc copy functions.
554 * The huc copy function emits a batchbuffer to the VDBOX engine to
555 * invoke the HuC Copy kernel to copy 4K bytes from the source buffer
556 * to the destination buffer.
558 typedef void (*igt_huc_copyfunc_t
)(int fd
, uint64_t ahnd
,
559 struct drm_i915_gem_exec_object2
*obj
, uint64_t *objsize
);
561 igt_huc_copyfunc_t
igt_get_huc_copyfunc(int devid
);