1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
5 #include <intel_bufmgr.h>
10 #define BATCH_RESERVED 16
12 struct intel_batchbuffer {
13 drm_intel_bufmgr *bufmgr;
19 uint8_t buffer[BATCH_SZ];
24 struct intel_batchbuffer *intel_batchbuffer_alloc(drm_intel_bufmgr *bufmgr,
27 void intel_batchbuffer_free(struct intel_batchbuffer *batch);
30 void intel_batchbuffer_flush(struct intel_batchbuffer *batch);
31 void intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring);
32 void intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch,
33 drm_intel_context *context);
35 void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
37 void intel_batchbuffer_data(struct intel_batchbuffer *batch,
38 const void *data, unsigned int bytes);
40 void intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
43 uint32_t read_domains,
44 uint32_t write_domain,
47 /* Inline functions - might actually be better off with these
48 * non-inlined. Certainly better off switching all command packets to
49 * be passed as structs rather than dwords, but that's a little bit of
52 #pragma GCC diagnostic ignored "-Winline"
53 static inline unsigned int
54 intel_batchbuffer_space(struct intel_batchbuffer *batch)
56 return (BATCH_SZ - BATCH_RESERVED) - (batch->ptr - batch->buffer);
61 intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, uint32_t dword)
63 igt_assert(intel_batchbuffer_space(batch) >= 4);
64 *(uint32_t *) (batch->ptr) = dword;
69 intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
72 igt_assert(sz < BATCH_SZ - BATCH_RESERVED);
73 if (intel_batchbuffer_space(batch) < sz)
74 intel_batchbuffer_flush(batch);
79 * @n: number of DWORDS to emit
81 * Prepares a batch to emit @n DWORDS, flushing it if there's not enough space
84 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
87 #define BEGIN_BATCH(n) do { \
88 igt_assert(batch->end == NULL); \
89 intel_batchbuffer_require_space(batch, (n)*4); \
90 batch->end = batch->ptr + (n) * 4; \
97 * Emits @d into a batch.
99 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
102 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(batch, d)
106 * @buf: relocation target libdrm buffer object
107 * @read_domains: gem domain bits for the relocation
108 * @write_domain: gem domain bit for the relocation
109 * @delta: delta value to add to @buffer's gpu address
111 * Emits a fenced relocation into a batch.
113 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
116 #define OUT_RELOC_FENCED(buf, read_domains, write_domain, delta) do { \
117 igt_assert((delta) >= 0); \
118 intel_batchbuffer_emit_reloc(batch, buf, delta, \
119 read_domains, write_domain, 1); \
124 * @buf: relocation target libdrm buffer object
125 * @read_domains: gem domain bits for the relocation
126 * @write_domain: gem domain bit for the relocation
127 * @delta: delta value to add to @buffer's gpu address
129 * Emits a normal, unfenced relocation into a batch.
131 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
134 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
135 igt_assert((delta) >= 0); \
136 intel_batchbuffer_emit_reloc(batch, buf, delta, \
137 read_domains, write_domain, 0); \
143 * Completes the batch command emission sequence started with #BEGIN_BATCH.
145 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
148 #define ADVANCE_BATCH() do { \
149 igt_assert(batch->ptr == batch->end); \
153 #define BLIT_COPY_BATCH_START(devid, flags) do { \
154 if (intel_gen(devid) >= 8) { \
156 OUT_BATCH(XY_SRC_COPY_BLT_CMD | \
157 XY_SRC_COPY_BLT_WRITE_ALPHA | \
158 XY_SRC_COPY_BLT_WRITE_RGB | \
162 OUT_BATCH(XY_SRC_COPY_BLT_CMD | \
163 XY_SRC_COPY_BLT_WRITE_ALPHA | \
164 XY_SRC_COPY_BLT_WRITE_RGB | \
169 #define COLOR_BLIT_COPY_BATCH_START(devid, flags) do { \
170 if (intel_gen(devid) >= 8) { \
172 OUT_BATCH(MI_NOOP); \
173 OUT_BATCH(XY_COLOR_BLT_CMD_NOLEN | 0x5 | \
174 COLOR_BLT_WRITE_ALPHA | \
175 XY_COLOR_BLT_WRITE_RGB); \
178 OUT_BATCH(XY_COLOR_BLT_CMD_NOLEN | 0x4 | \
179 COLOR_BLT_WRITE_ALPHA | \
180 XY_COLOR_BLT_WRITE_RGB); \
185 intel_blt_copy(struct intel_batchbuffer *batch,
186 drm_intel_bo *src_bo, int src_x1, int src_y1, int src_pitch,
187 drm_intel_bo *dst_bo, int dst_x1, int dst_y1, int dst_pitch,
188 int width, int height, int bpp);
189 void intel_copy_bo(struct intel_batchbuffer *batch,
190 drm_intel_bo *dst_bo, drm_intel_bo *src_bo,
195 * @bo: underlying libdrm buffer object
196 * @stride: stride of the buffer
197 * @tiling: tiling mode bits
198 * @data: pointer to the memory mapping of the buffer
199 * @size: size of the buffer object
201 * This is a i-g-t buffer object wrapper structure which augments the baseline
202 * libdrm buffer object with suitable data needed by the render copy and the
203 * media fill functions.
215 unsigned igt_buf_width(struct igt_buf *buf);
216 unsigned igt_buf_height(struct igt_buf *buf);
219 * igt_render_copyfunc_t:
220 * @batch: batchbuffer object
221 * @context: libdrm hardware context to use
222 * @src: source i-g-t buffer object
223 * @src_x: source pixel x-coordination
224 * @src_y: source pixel y-coordination
225 * @width: width of the copied rectangle
226 * @height: height of the copied rectangle
227 * @dst: destination i-g-t buffer object
228 * @dst_x: destination pixel x-coordination
229 * @dst_y: destination pixel y-coordination
231 * This is the type of the per-platform render copy functions. The
232 * platform-specific implementation can be obtained by calling
233 * igt_get_render_copyfunc().
235 * A render copy function will emit a batchbuffer to the kernel which executes
236 * the specified blit copy operation using the render engine. @context is
237 * optional and can be NULL.
239 typedef void (*igt_render_copyfunc_t)(struct intel_batchbuffer *batch,
240 drm_intel_context *context,
241 struct igt_buf *src, unsigned src_x, unsigned src_y,
242 unsigned width, unsigned height,
243 struct igt_buf *dst, unsigned dst_x, unsigned dst_y);
245 igt_render_copyfunc_t igt_get_render_copyfunc(int devid);
248 * igt_media_fillfunc_t:
249 * @batch: batchbuffer object
250 * @dst: destination i-g-t buffer object
251 * @x: destination pixel x-coordination
252 * @y: destination pixel y-coordination
253 * @width: width of the filled rectangle
254 * @height: height of the filled rectangle
255 * @color: fill color to use
257 * This is the type of the per-platform media fill functions. The
258 * platform-specific implementation can be obtained by calling
259 * igt_get_media_fillfunc().
261 * A media fill function will emit a batchbuffer to the kernel which executes
262 * the specified blit fill operation using the media engine.
264 typedef void (*igt_media_fillfunc_t)(struct intel_batchbuffer *batch,
266 unsigned x, unsigned y,
267 unsigned width, unsigned height,
270 igt_media_fillfunc_t igt_get_media_fillfunc(int devid);