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 intel_batchbuffer_require_space(batch, (n)*4); \
95 * Emits @d into a batch.
97 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
100 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(batch, d)
104 * @buf: relocation target libdrm buffer object
105 * @read_domains: gem domain bits for the relocation
106 * @write_domain: gem domain bit for the relocation
107 * @delta: delta value to add to @buffer's gpu address
109 * Emits a fenced relocation into a batch.
111 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
114 #define OUT_RELOC_FENCED(buf, read_domains, write_domain, delta) do { \
115 igt_assert((delta) >= 0); \
116 intel_batchbuffer_emit_reloc(batch, buf, delta, \
117 read_domains, write_domain, 1); \
122 * @buf: relocation target libdrm buffer object
123 * @read_domains: gem domain bits for the relocation
124 * @write_domain: gem domain bit for the relocation
125 * @delta: delta value to add to @buffer's gpu address
127 * Emits a normal, unfenced relocation into a batch.
129 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
132 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
133 igt_assert((delta) >= 0); \
134 intel_batchbuffer_emit_reloc(batch, buf, delta, \
135 read_domains, write_domain, 0); \
141 * Completes the batch command emission sequence started with #BEGIN_BATCH.
143 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
146 #define ADVANCE_BATCH() do { \
149 #define BLIT_COPY_BATCH_START(devid, flags) do { \
150 if (intel_gen(devid) >= 8) { \
152 OUT_BATCH(XY_SRC_COPY_BLT_CMD | \
153 XY_SRC_COPY_BLT_WRITE_ALPHA | \
154 XY_SRC_COPY_BLT_WRITE_RGB | \
158 OUT_BATCH(XY_SRC_COPY_BLT_CMD | \
159 XY_SRC_COPY_BLT_WRITE_ALPHA | \
160 XY_SRC_COPY_BLT_WRITE_RGB | \
165 #define COLOR_BLIT_COPY_BATCH_START(devid, flags) do { \
166 if (intel_gen(devid) >= 8) { \
168 OUT_BATCH(MI_NOOP); \
169 OUT_BATCH(XY_COLOR_BLT_CMD_NOLEN | 0x5 | \
170 COLOR_BLT_WRITE_ALPHA | \
171 XY_COLOR_BLT_WRITE_RGB); \
174 OUT_BATCH(XY_COLOR_BLT_CMD_NOLEN | 0x4 | \
175 COLOR_BLT_WRITE_ALPHA | \
176 XY_COLOR_BLT_WRITE_RGB); \
182 * @devid: pci device id of the drm device
184 * Emits the upper relocation DWORD on gen8+ and nothing on earlier generations.
186 #define BLIT_RELOC_UDW(devid) do { \
187 if (intel_gen(devid) >= 8) { \
193 intel_blt_copy(struct intel_batchbuffer *batch,
194 drm_intel_bo *src_bo, int src_x1, int src_y1, int src_pitch,
195 drm_intel_bo *dst_bo, int dst_x1, int dst_y1, int dst_pitch,
196 int width, int height, int bpp);
197 void intel_copy_bo(struct intel_batchbuffer *batch,
198 drm_intel_bo *dst_bo, drm_intel_bo *src_bo,
203 * @bo: underlying libdrm buffer object
204 * @stride: stride of the buffer
205 * @tiling: tiling mode bits
206 * @data: pointer to the memory mapping of the buffer
207 * @size: size of the buffer object
209 * This is a i-g-t buffer object wrapper structure which augments the baseline
210 * libdrm buffer object with suitable data needed by the render copy and the
211 * media fill functions.
223 unsigned igt_buf_width(struct igt_buf *buf);
224 unsigned igt_buf_height(struct igt_buf *buf);
227 * igt_render_copyfunc_t:
228 * @batch: batchbuffer object
229 * @context: libdrm hardware context to use
230 * @src: source i-g-t buffer object
231 * @src_x: source pixel x-coordination
232 * @src_y: source pixel y-coordination
233 * @width: width of the copied rectangle
234 * @height: height of the copied rectangle
235 * @dst: destination i-g-t buffer object
236 * @dst_x: destination pixel x-coordination
237 * @dst_y: destination pixel y-coordination
239 * This is the type of the per-platform render copy functions. The
240 * platform-specific implementation can be obtained by calling
241 * igt_get_render_copyfunc().
243 * A render copy function will emit a batchbuffer to the kernel which executes
244 * the specified blit copy operation using the render engine. @context is
245 * optional and can be NULL.
247 typedef void (*igt_render_copyfunc_t)(struct intel_batchbuffer *batch,
248 drm_intel_context *context,
249 struct igt_buf *src, unsigned src_x, unsigned src_y,
250 unsigned width, unsigned height,
251 struct igt_buf *dst, unsigned dst_x, unsigned dst_y);
253 igt_render_copyfunc_t igt_get_render_copyfunc(int devid);
256 * igt_media_fillfunc_t:
257 * @batch: batchbuffer object
258 * @dst: destination i-g-t buffer object
259 * @x: destination pixel x-coordination
260 * @y: destination pixel y-coordination
261 * @width: width of the filled rectangle
262 * @height: height of the filled rectangle
263 * @color: fill color to use
265 * This is the type of the per-platform media fill functions. The
266 * platform-specific implementation can be obtained by calling
267 * igt_get_media_fillfunc().
269 * A media fill function will emit a batchbuffer to the kernel which executes
270 * the specified blit fill operation using the media engine.
272 typedef void (*igt_media_fillfunc_t)(struct intel_batchbuffer *batch,
274 unsigned x, unsigned y,
275 unsigned width, unsigned height,
278 igt_media_fillfunc_t igt_get_media_fillfunc(int devid);