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;
18 uint8_t buffer[BATCH_SZ];
23 struct intel_batchbuffer *intel_batchbuffer_alloc(drm_intel_bufmgr *bufmgr,
26 void intel_batchbuffer_free(struct intel_batchbuffer *batch);
29 void intel_batchbuffer_flush(struct intel_batchbuffer *batch);
30 void intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring);
31 void intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch,
32 drm_intel_context *context);
34 void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
36 void intel_batchbuffer_data(struct intel_batchbuffer *batch,
37 const void *data, unsigned int bytes);
39 void intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
42 uint32_t read_domains,
43 uint32_t write_domain,
46 /* Inline functions - might actually be better off with these
47 * non-inlined. Certainly better off switching all command packets to
48 * be passed as structs rather than dwords, but that's a little bit of
51 #pragma GCC diagnostic ignored "-Winline"
52 static inline unsigned int
53 intel_batchbuffer_space(struct intel_batchbuffer *batch)
55 return (BATCH_SZ - BATCH_RESERVED) - (batch->ptr - batch->buffer);
60 intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, uint32_t dword)
62 igt_assert(intel_batchbuffer_space(batch) >= 4);
63 *(uint32_t *) (batch->ptr) = dword;
68 intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
71 igt_assert(sz < BATCH_SZ - BATCH_RESERVED);
72 if (intel_batchbuffer_space(batch) < sz)
73 intel_batchbuffer_flush(batch);
78 * @n: number of DWORDS to emit
80 * Prepares a batch to emit @n DWORDS, flushing it if there's not enough space
83 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
86 #define BEGIN_BATCH(n) do { \
87 intel_batchbuffer_require_space(batch, (n)*4); \
94 * Emits @d into a batch.
96 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
99 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(batch, d)
103 * @buf: relocation target libdrm buffer object
104 * @read_domains: gem domain bits for the relocation
105 * @write_domain: gem domain bit for the relocation
106 * @delta: delta value to add to @buffer's gpu address
108 * Emits a fenced relocation into a batch.
110 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
113 #define OUT_RELOC_FENCED(buf, read_domains, write_domain, delta) do { \
114 igt_assert((delta) >= 0); \
115 intel_batchbuffer_emit_reloc(batch, buf, delta, \
116 read_domains, write_domain, 1); \
121 * @buf: relocation target libdrm buffer object
122 * @read_domains: gem domain bits for the relocation
123 * @write_domain: gem domain bit for the relocation
124 * @delta: delta value to add to @buffer's gpu address
126 * Emits a normal, unfenced relocation into a batch.
128 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
131 #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
132 igt_assert((delta) >= 0); \
133 intel_batchbuffer_emit_reloc(batch, buf, delta, \
134 read_domains, write_domain, 0); \
140 * Completes the batch command emission sequence started with #BEGIN_BATCH.
142 * This macro needs a pointer to an #intel_batchbuffer structure called batch in
145 #define ADVANCE_BATCH() do { \
148 #define BLIT_COPY_BATCH_START(devid, flags) do { \
149 if (intel_gen(devid) >= 8) { \
151 OUT_BATCH(XY_SRC_COPY_BLT_CMD | \
152 XY_SRC_COPY_BLT_WRITE_ALPHA | \
153 XY_SRC_COPY_BLT_WRITE_RGB | \
157 OUT_BATCH(XY_SRC_COPY_BLT_CMD | \
158 XY_SRC_COPY_BLT_WRITE_ALPHA | \
159 XY_SRC_COPY_BLT_WRITE_RGB | \
164 #define COLOR_BLIT_COPY_BATCH_START(devid, flags) do { \
165 if (intel_gen(devid) >= 8) { \
167 OUT_BATCH(MI_NOOP); \
168 OUT_BATCH(XY_COLOR_BLT_CMD_NOLEN | 0x5 | \
169 COLOR_BLT_WRITE_ALPHA | \
170 XY_COLOR_BLT_WRITE_RGB); \
173 OUT_BATCH(XY_COLOR_BLT_CMD_NOLEN | 0x4 | \
174 COLOR_BLT_WRITE_ALPHA | \
175 XY_COLOR_BLT_WRITE_RGB); \
181 * @devid: pci device id of the drm device
183 * Emits the upper relocation DWORD on gen8+ and nothing on earlier generations.
185 #define BLIT_RELOC_UDW(devid) do { \
186 if (intel_gen(devid) >= 8) { \
192 intel_blt_copy(struct intel_batchbuffer *batch,
193 drm_intel_bo *src_bo, int src_x1, int src_y1, int src_pitch,
194 drm_intel_bo *dst_bo, int dst_x1, int dst_y1, int dst_pitch,
195 int width, int height, int bpp);
196 void intel_copy_bo(struct intel_batchbuffer *batch,
197 drm_intel_bo *dst_bo, drm_intel_bo *src_bo,
202 * @bo: underlying libdrm buffer object
203 * @stride: stride of the buffer
204 * @tiling: tiling mode bits
205 * @data: pointer to the memory mapping of the buffer
206 * @size: size of the buffer object
208 * This is a i-g-t buffer object wrapper structure which augments the baseline
209 * libdrm buffer object with suitable data needed by the render copy and the
210 * media fill functions.
222 unsigned igt_buf_width(struct igt_buf *buf);
223 unsigned igt_buf_height(struct igt_buf *buf);
226 * igt_render_copyfunc_t:
227 * @batch: batchbuffer object
228 * @context: libdrm hardware context to use
229 * @src: source i-g-t buffer object
230 * @src_x: source pixel x-coordination
231 * @src_y: source pixel y-coordination
232 * @width: width of the copied rectangle
233 * @height: height of the copied rectangle
234 * @dst: destination i-g-t buffer object
235 * @dst_x: destination pixel x-coordination
236 * @dst_y: destination pixel y-coordination
238 * This is the type of the per-platform render copy functions. The
239 * platform-specific implementation can be obtained by calling
240 * igt_get_render_copyfunc().
242 * A render copy function will emit a batchbuffer to the kernel which executes
243 * the specified blit copy operation using the render engine. @context is
244 * optional and can be NULL.
246 typedef void (*igt_render_copyfunc_t)(struct intel_batchbuffer *batch,
247 drm_intel_context *context,
248 struct igt_buf *src, unsigned src_x, unsigned src_y,
249 unsigned width, unsigned height,
250 struct igt_buf *dst, unsigned dst_x, unsigned dst_y);
252 igt_render_copyfunc_t igt_get_render_copyfunc(int devid);
255 * igt_media_fillfunc_t:
256 * @batch: batchbuffer object
257 * @dst: destination i-g-t buffer object
258 * @x: destination pixel x-coordination
259 * @y: destination pixel y-coordination
260 * @width: width of the filled rectangle
261 * @height: height of the filled rectangle
262 * @color: fill color to use
264 * This is the type of the per-platform media fill functions. The
265 * platform-specific implementation can be obtained by calling
266 * igt_get_media_fillfunc().
268 * A media fill function will emit a batchbuffer to the kernel which executes
269 * the specified blit fill operation using the media engine.
271 typedef void (*igt_media_fillfunc_t)(struct intel_batchbuffer *batch,
273 unsigned x, unsigned y,
274 unsigned width, unsigned height,
277 igt_media_fillfunc_t igt_get_media_fillfunc(int devid);