blob: bb21fcdea09bf9f983739a835adf618b5c7f4fe1 [file] [log] [blame]
Chia-I Wu00a23b22014-08-20 15:28:08 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wu00a23b22014-08-20 15:28:08 +080026 */
27
28#ifndef CMD_PRIV_H
29#define CMD_PRIV_H
30
Chia-I Wue24c3292014-08-21 14:05:23 +080031#include "genhw/genhw.h"
Chia-I Wu32710d72014-08-20 16:05:22 +080032#include "dev.h"
33#include "gpu.h"
Chia-I Wu00a23b22014-08-20 15:28:08 +080034#include "cmd.h"
35
Chia-I Wu32710d72014-08-20 16:05:22 +080036#define CMD_ASSERT(cmd, min_gen, max_gen) \
37 INTEL_GPU_ASSERT((cmd)->dev->gpu, (min_gen), (max_gen))
38
Chia-I Wu00b51a82014-09-09 12:07:37 +080039enum intel_cmd_item_type {
40 /* for state buffer */
41 INTEL_CMD_ITEM_BLOB,
42 INTEL_CMD_ITEM_CLIP_VIEWPORT,
43 INTEL_CMD_ITEM_SF_VIEWPORT,
44 INTEL_CMD_ITEM_SCISSOR_RECT,
45 INTEL_CMD_ITEM_CC_VIEWPORT,
46 INTEL_CMD_ITEM_COLOR_CALC,
47 INTEL_CMD_ITEM_DEPTH_STENCIL,
48 INTEL_CMD_ITEM_BLEND,
49 INTEL_CMD_ITEM_SAMPLER,
50
51 /* for surface buffer */
52 INTEL_CMD_ITEM_SURFACE,
53 INTEL_CMD_ITEM_BINDING_TABLE,
54
55 /* for instruction buffer */
56 INTEL_CMD_ITEM_KERNEL,
57
58 INTEL_CMD_ITEM_COUNT,
59};
60
61struct intel_cmd_item {
62 enum intel_cmd_item_type type;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060063 size_t offset;
64 size_t size;
Chia-I Wu00b51a82014-09-09 12:07:37 +080065};
66
Chia-I Wud7d1e482014-10-18 13:25:10 +080067#define INTEL_CMD_RELOC_TARGET_IS_WRITER (1u << 31)
Chia-I Wu958d1b72014-08-21 11:28:11 +080068struct intel_cmd_reloc {
Chia-I Wu68f319d2014-09-09 09:43:21 +080069 enum intel_cmd_writer_type which;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060070 size_t offset;
Chia-I Wu958d1b72014-08-21 11:28:11 +080071
Chia-I Wud7d1e482014-10-18 13:25:10 +080072 intptr_t target;
73 uint32_t target_offset;
Chia-I Wu958d1b72014-08-21 11:28:11 +080074
Chia-I Wu32a22462014-08-26 14:13:46 +080075 uint32_t flags;
Chia-I Wu958d1b72014-08-21 11:28:11 +080076};
77
Chia-I Wuc14d1562014-10-17 09:49:22 +080078struct intel_ds_view;
79
Chia-I Wu29e6f502014-11-24 14:27:29 +080080enum intel_cmd_meta_mode {
81 /*
Chia-I Wu4d344e62014-12-20 21:06:04 +080082 * Draw POINTLIST of (width * height) vertices with only VS enabled. The
83 * vertex id is from 0 to (width * height - 1).
Chia-I Wu29e6f502014-11-24 14:27:29 +080084 */
85 INTEL_CMD_META_VS_POINTS,
86
87 /*
88 * Draw a RECTLIST from (dst.x, dst.y) to (dst.x + width, dst.y + height)
89 * with only FS enabled.
90 */
91 INTEL_CMD_META_FS_RECT,
92
93 /*
94 * Draw a RECTLIST from (dst.x, dst.y) to (dst.x + width, dst.y + height)
95 * with only depth/stencil enabled.
96 */
97 INTEL_CMD_META_DEPTH_STENCIL_RECT,
98};
99
Chia-I Wuc14d1562014-10-17 09:49:22 +0800100struct intel_cmd_meta {
Chia-I Wu29e6f502014-11-24 14:27:29 +0800101 enum intel_cmd_meta_mode mode;
Chia-I Wuc14d1562014-10-17 09:49:22 +0800102 enum intel_dev_meta_shader shader_id;
103
104 struct {
105 bool valid;
106
107 uint32_t surface[8];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600108 uint32_t surface_len;
Chia-I Wuc14d1562014-10-17 09:49:22 +0800109
110 intptr_t reloc_target;
111 uint32_t reloc_offset;
112 uint32_t reloc_flags;
113
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600114 uint32_t lod, layer;
115 uint32_t x, y;
Chia-I Wuc14d1562014-10-17 09:49:22 +0800116 } src, dst;
117
Chia-I Wu429a0aa2014-10-24 11:57:51 +0800118 struct {
119 struct intel_ds_view *view;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700120 uint32_t stencil_ref;
121 XGL_IMAGE_ASPECT aspect;
Chia-I Wu429a0aa2014-10-24 11:57:51 +0800122 } ds;
123
Chia-I Wuc14d1562014-10-17 09:49:22 +0800124 uint32_t clear_val[4];
125
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600126 uint32_t width, height;
127 uint32_t samples;
Chia-I Wuc14d1562014-10-17 09:49:22 +0800128};
129
Chia-I Wu9f039862014-08-20 15:39:56 +0800130static inline int cmd_gen(const struct intel_cmd *cmd)
131{
132 return intel_gpu_gen(cmd->dev->gpu);
133}
134
Chia-I Wucdff0592014-08-22 09:27:36 +0800135static inline void cmd_reserve_reloc(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600136 uint32_t reloc_len)
Chia-I Wucdff0592014-08-22 09:27:36 +0800137{
138 /* fail silently */
139 if (cmd->reloc_used + reloc_len > cmd->reloc_count) {
140 cmd->reloc_used = 0;
141 cmd->result = XGL_ERROR_TOO_MANY_MEMORY_REFERENCES;
142 }
143 assert(cmd->reloc_used + reloc_len <= cmd->reloc_count);
144}
145
Chia-I Wue24c3292014-08-21 14:05:23 +0800146void cmd_writer_grow(struct intel_cmd *cmd,
Chia-I Wu3c3edc02014-09-09 10:32:59 +0800147 enum intel_cmd_writer_type which,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600148 size_t new_size);
Chia-I Wu72292b72014-09-09 10:48:33 +0800149
Chia-I Wu00b51a82014-09-09 12:07:37 +0800150void cmd_writer_record(struct intel_cmd *cmd,
151 enum intel_cmd_writer_type which,
152 enum intel_cmd_item_type type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600153 size_t offset, size_t size);
Chia-I Wu00b51a82014-09-09 12:07:37 +0800154
Chia-I Wu72292b72014-09-09 10:48:33 +0800155/**
156 * Return an offset to a region that is aligned to \p alignment and has at
157 * least \p size bytes.
158 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600159static inline size_t cmd_writer_reserve(struct intel_cmd *cmd,
160 enum intel_cmd_writer_type which,
161 size_t alignment, size_t size)
Chia-I Wu72292b72014-09-09 10:48:33 +0800162{
163 struct intel_cmd_writer *writer = &cmd->writers[which];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600164 size_t offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800165
166 assert(alignment && u_is_pow2(alignment));
167 offset = u_align(writer->used, alignment);
168
169 if (offset + size > writer->size) {
170 cmd_writer_grow(cmd, which, offset + size);
171 /* align again in case of errors */
172 offset = u_align(writer->used, alignment);
173
174 assert(offset + size <= writer->size);
175 }
176
177 return offset;
178}
Chia-I Wu00a23b22014-08-20 15:28:08 +0800179
Chia-I Wu32710d72014-08-20 16:05:22 +0800180/**
Chia-I Wubda55fd2014-08-25 12:46:10 +0800181 * Add a reloc at \p pos. No error checking.
Chia-I Wucdff0592014-08-22 09:27:36 +0800182 */
Chia-I Wu72292b72014-09-09 10:48:33 +0800183static inline void cmd_writer_reloc(struct intel_cmd *cmd,
184 enum intel_cmd_writer_type which,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600185 size_t offset, intptr_t target,
Chia-I Wud7d1e482014-10-18 13:25:10 +0800186 uint32_t target_offset, uint32_t flags)
Chia-I Wucdff0592014-08-22 09:27:36 +0800187{
188 struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used];
189
190 assert(cmd->reloc_used < cmd->reloc_count);
191
Chia-I Wu68f319d2014-09-09 09:43:21 +0800192 reloc->which = which;
Chia-I Wu72292b72014-09-09 10:48:33 +0800193 reloc->offset = offset;
Chia-I Wud7d1e482014-10-18 13:25:10 +0800194 reloc->target = target;
195 reloc->target_offset = target_offset;
Chia-I Wu32a22462014-08-26 14:13:46 +0800196 reloc->flags = flags;
Chia-I Wucdff0592014-08-22 09:27:36 +0800197
198 cmd->reloc_used++;
199}
200
201/**
Chia-I Wu5da476a2014-12-10 08:50:28 +0800202 * Reserve a region from the state buffer. The offset, in bytes, to the
203 * reserved region is returned.
Chia-I Wu72292b72014-09-09 10:48:33 +0800204 *
205 * Note that \p alignment is in bytes and \p len is in DWords.
Chia-I Wue24c3292014-08-21 14:05:23 +0800206 */
Chia-I Wu5da476a2014-12-10 08:50:28 +0800207static inline uint32_t cmd_state_reserve(struct intel_cmd *cmd,
Chia-I Wu00b51a82014-09-09 12:07:37 +0800208 enum intel_cmd_item_type item,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600209 size_t alignment, uint32_t len)
Chia-I Wue24c3292014-08-21 14:05:23 +0800210{
Chia-I Wu72292b72014-09-09 10:48:33 +0800211 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600212 const size_t size = len << 2;
213 const size_t offset = cmd_writer_reserve(cmd, which, alignment, size);
Chia-I Wu72292b72014-09-09 10:48:33 +0800214 struct intel_cmd_writer *writer = &cmd->writers[which];
Chia-I Wue24c3292014-08-21 14:05:23 +0800215
Chia-I Wu72292b72014-09-09 10:48:33 +0800216 /* all states are at least aligned to 32-bytes */
217 assert(alignment % 32 == 0);
218
Chia-I Wu72292b72014-09-09 10:48:33 +0800219 writer->used = offset + size;
220
Chia-I Wu00b51a82014-09-09 12:07:37 +0800221 if (intel_debug & INTEL_DEBUG_BATCH)
222 cmd_writer_record(cmd, which, item, offset, size);
223
Chia-I Wu72292b72014-09-09 10:48:33 +0800224 return offset;
Chia-I Wue24c3292014-08-21 14:05:23 +0800225}
226
227/**
Chia-I Wu5da476a2014-12-10 08:50:28 +0800228 * Get the pointer to a reserved region for updating. The pointer is only
229 * valid until the next reserve call.
230 */
231static inline void cmd_state_update(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600232 uint32_t offset, uint32_t len,
Chia-I Wu5da476a2014-12-10 08:50:28 +0800233 uint32_t **dw)
234{
235 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE;
236 struct intel_cmd_writer *writer = &cmd->writers[which];
237
238 assert(offset + (len << 2) <= writer->used);
239
240 *dw = (uint32_t *) ((char *) writer->ptr + offset);
241}
242
243/**
244 * Reserve a region from the state buffer. Both the offset, in bytes, and the
245 * pointer to the reserved region are returned. The pointer is only valid
246 * until the next reserve call.
247 *
248 * Note that \p alignment is in bytes and \p len is in DWords.
249 */
250static inline uint32_t cmd_state_pointer(struct intel_cmd *cmd,
251 enum intel_cmd_item_type item,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600252 size_t alignment, uint32_t len,
Chia-I Wu5da476a2014-12-10 08:50:28 +0800253 uint32_t **dw)
254{
255 const uint32_t offset = cmd_state_reserve(cmd, item, alignment, len);
256
257 cmd_state_update(cmd, offset, len, dw);
258
259 return offset;
260}
261
262/**
Chia-I Wu72292b72014-09-09 10:48:33 +0800263 * Write a dynamic state to the state buffer.
Chia-I Wucdff0592014-08-22 09:27:36 +0800264 */
Chia-I Wu72292b72014-09-09 10:48:33 +0800265static inline uint32_t cmd_state_write(struct intel_cmd *cmd,
Chia-I Wu00b51a82014-09-09 12:07:37 +0800266 enum intel_cmd_item_type item,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600267 size_t alignment, uint32_t len,
Chia-I Wu72292b72014-09-09 10:48:33 +0800268 const uint32_t *dw)
Chia-I Wucdff0592014-08-22 09:27:36 +0800269{
Chia-I Wu72292b72014-09-09 10:48:33 +0800270 uint32_t offset, *dst;
271
Chia-I Wu00b51a82014-09-09 12:07:37 +0800272 offset = cmd_state_pointer(cmd, item, alignment, len, &dst);
Chia-I Wu72292b72014-09-09 10:48:33 +0800273 memcpy(dst, dw, len << 2);
274
275 return offset;
Chia-I Wucdff0592014-08-22 09:27:36 +0800276}
277
278/**
Chia-I Wu72292b72014-09-09 10:48:33 +0800279 * Write a surface state to the surface buffer. The offset, in bytes, of the
280 * state is returned.
281 *
282 * Note that \p alignment is in bytes and \p len is in DWords.
Chia-I Wue24c3292014-08-21 14:05:23 +0800283 */
Chia-I Wu72292b72014-09-09 10:48:33 +0800284static inline uint32_t cmd_surface_write(struct intel_cmd *cmd,
Chia-I Wu00b51a82014-09-09 12:07:37 +0800285 enum intel_cmd_item_type item,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600286 size_t alignment, uint32_t len,
Chia-I Wu72292b72014-09-09 10:48:33 +0800287 const uint32_t *dw)
Chia-I Wue24c3292014-08-21 14:05:23 +0800288{
Chia-I Wu15cccf72015-02-10 04:07:40 +0800289 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_SURFACE;
Chia-I Wuf98dd882015-02-10 04:17:47 +0800290 const size_t size = len << 2;
Chia-I Wu15cccf72015-02-10 04:07:40 +0800291 const uint32_t offset = cmd_writer_reserve(cmd, which, alignment, size);
292 struct intel_cmd_writer *writer = &cmd->writers[which];
293 uint32_t *dst;
294
Chia-I Wu00b51a82014-09-09 12:07:37 +0800295 assert(item == INTEL_CMD_ITEM_SURFACE ||
296 item == INTEL_CMD_ITEM_BINDING_TABLE);
297
Chia-I Wu15cccf72015-02-10 04:07:40 +0800298 /* all states are at least aligned to 32-bytes */
299 assert(alignment % 32 == 0);
300
301 writer->used = offset + size;
302
303 if (intel_debug & INTEL_DEBUG_BATCH)
304 cmd_writer_record(cmd, which, item, offset, size);
305
306 dst = (uint32_t *) ((char *) writer->ptr + offset);
307 memcpy(dst, dw, size);
308
309 return offset;
Chia-I Wue24c3292014-08-21 14:05:23 +0800310}
311
312/**
Chia-I Wu72292b72014-09-09 10:48:33 +0800313 * Add a relocation entry for a DWord of a surface state.
Chia-I Wucdff0592014-08-22 09:27:36 +0800314 */
Chia-I Wu72292b72014-09-09 10:48:33 +0800315static inline void cmd_surface_reloc(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600316 uint32_t offset, uint32_t dw_index,
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 struct intel_bo *bo,
318 uint32_t bo_offset, uint32_t reloc_flags)
Chia-I Wucdff0592014-08-22 09:27:36 +0800319{
Chia-I Wu15cccf72015-02-10 04:07:40 +0800320 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_SURFACE;
Chia-I Wucdff0592014-08-22 09:27:36 +0800321
Chia-I Wu72292b72014-09-09 10:48:33 +0800322 cmd_writer_reloc(cmd, which, offset + (dw_index << 2),
Chia-I Wud7d1e482014-10-18 13:25:10 +0800323 (intptr_t) bo, bo_offset, reloc_flags);
324}
325
326static inline void cmd_surface_reloc_writer(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600327 uint32_t offset, uint32_t dw_index,
Chia-I Wud7d1e482014-10-18 13:25:10 +0800328 enum intel_cmd_writer_type writer,
329 uint32_t writer_offset)
330{
Chia-I Wu15cccf72015-02-10 04:07:40 +0800331 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_SURFACE;
Chia-I Wud7d1e482014-10-18 13:25:10 +0800332
333 cmd_writer_reloc(cmd, which, offset + (dw_index << 2),
334 (intptr_t) writer, writer_offset,
335 INTEL_CMD_RELOC_TARGET_IS_WRITER);
Chia-I Wucdff0592014-08-22 09:27:36 +0800336}
337
338/**
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 * Write a kernel to the instruction buffer. The offset, in bytes, of the
340 * kernel is returned.
Chia-I Wue24c3292014-08-21 14:05:23 +0800341 */
Chia-I Wu72292b72014-09-09 10:48:33 +0800342static inline uint32_t cmd_instruction_write(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600343 size_t size,
Chia-I Wu72292b72014-09-09 10:48:33 +0800344 const void *kernel)
Chia-I Wue24c3292014-08-21 14:05:23 +0800345{
Chia-I Wu72292b72014-09-09 10:48:33 +0800346 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_INSTRUCTION;
347 /*
348 * From the Sandy Bridge PRM, volume 4 part 2, page 112:
349 *
350 * "Due to prefetch of the instruction stream, the EUs may attempt to
351 * access up to 8 instructions (128 bytes) beyond the end of the
352 * kernel program - possibly into the next memory page. Although
353 * these instructions will not be executed, software must account for
354 * the prefetch in order to avoid invalid page access faults."
355 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600356 const size_t reserved_size = size + 128;
Chia-I Wu72292b72014-09-09 10:48:33 +0800357 /* kernels are aligned to 64 bytes */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600358 const size_t alignment = 64;
359 const size_t offset = cmd_writer_reserve(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800360 which, alignment, reserved_size);
361 struct intel_cmd_writer *writer = &cmd->writers[which];
Chia-I Wue24c3292014-08-21 14:05:23 +0800362
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 memcpy((char *) writer->ptr + offset, kernel, size);
Chia-I Wu5e25c272014-08-21 20:19:12 +0800364
Chia-I Wu72292b72014-09-09 10:48:33 +0800365 writer->used = offset + size;
366
Chia-I Wu00b51a82014-09-09 12:07:37 +0800367 if (intel_debug & INTEL_DEBUG_BATCH)
368 cmd_writer_record(cmd, which, INTEL_CMD_ITEM_KERNEL, offset, size);
369
Chia-I Wu72292b72014-09-09 10:48:33 +0800370 return offset;
371}
372
373/**
374 * Reserve a region from the batch buffer. Both the offset, in DWords, and
Chia-I Wu5da476a2014-12-10 08:50:28 +0800375 * the pointer to the reserved region are returned. The pointer is only valid
376 * until the next reserve call.
Chia-I Wu72292b72014-09-09 10:48:33 +0800377 *
378 * Note that \p len is in DWords.
379 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600380static inline uint32_t cmd_batch_pointer(struct intel_cmd *cmd,
381 uint32_t len, uint32_t **dw)
Chia-I Wu72292b72014-09-09 10:48:33 +0800382{
383 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH;
384 /*
385 * We know the batch bo is always aligned. Using 1 here should allow the
386 * compiler to optimize away aligning.
387 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600388 const size_t alignment = 1;
389 const size_t size = len << 2;
390 const size_t offset = cmd_writer_reserve(cmd, which, alignment, size);
Chia-I Wu72292b72014-09-09 10:48:33 +0800391 struct intel_cmd_writer *writer = &cmd->writers[which];
392
393 assert(offset % 4 == 0);
394 *dw = (uint32_t *) ((char *) writer->ptr + offset);
395
396 writer->used = offset + size;
397
398 return offset >> 2;
399}
400
401/**
402 * Write a command to the batch buffer.
403 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600404static inline uint32_t cmd_batch_write(struct intel_cmd *cmd,
405 uint32_t len, const uint32_t *dw)
Chia-I Wu72292b72014-09-09 10:48:33 +0800406{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600407 uint32_t pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800408 uint32_t *dst;
409
410 pos = cmd_batch_pointer(cmd, len, &dst);
411 memcpy(dst, dw, len << 2);
412
413 return pos;
414}
415
416/**
417 * Add a relocation entry for a DWord of a command.
418 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600419static inline void cmd_batch_reloc(struct intel_cmd *cmd, uint32_t pos,
Chia-I Wu72292b72014-09-09 10:48:33 +0800420 struct intel_bo *bo,
421 uint32_t bo_offset, uint32_t reloc_flags)
422{
423 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH;
424
Chia-I Wud7d1e482014-10-18 13:25:10 +0800425 cmd_writer_reloc(cmd, which, pos << 2, (intptr_t) bo, bo_offset, reloc_flags);
426}
427
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600428static inline void cmd_batch_reloc_writer(struct intel_cmd *cmd, uint32_t pos,
Chia-I Wud7d1e482014-10-18 13:25:10 +0800429 enum intel_cmd_writer_type writer,
430 uint32_t writer_offset)
431{
432 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH;
433
434 cmd_writer_reloc(cmd, which, pos << 2, (intptr_t) writer, writer_offset,
435 INTEL_CMD_RELOC_TARGET_IS_WRITER);
Chia-I Wue24c3292014-08-21 14:05:23 +0800436}
437
Chia-I Wu66bdcd72015-02-10 04:11:31 +0800438void cmd_batch_state_base_address(struct intel_cmd *cmd);
439
Chia-I Wue24c3292014-08-21 14:05:23 +0800440/**
Chia-I Wu48c283d2014-08-25 23:13:46 +0800441 * Begin the batch buffer.
Chia-I Wu79dfbb32014-08-25 12:19:02 +0800442 */
443static inline void cmd_batch_begin(struct intel_cmd *cmd)
444{
Chia-I Wu66bdcd72015-02-10 04:11:31 +0800445 cmd_batch_state_base_address(cmd);
Chia-I Wu79dfbb32014-08-25 12:19:02 +0800446}
447
448/**
Chia-I Wue24c3292014-08-21 14:05:23 +0800449 * End the batch buffer.
450 */
451static inline void cmd_batch_end(struct intel_cmd *cmd)
452{
Chia-I Wu68f319d2014-09-09 09:43:21 +0800453 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_BATCH];
Chia-I Wu72292b72014-09-09 10:48:33 +0800454 uint32_t *dw;
Chia-I Wu79dfbb32014-08-25 12:19:02 +0800455
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 if (writer->used & 0x7) {
457 cmd_batch_pointer(cmd, 1, &dw);
458 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END);
Chia-I Wue24c3292014-08-21 14:05:23 +0800459 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800460 cmd_batch_pointer(cmd, 2, &dw);
461 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END);
462 dw[1] = GEN6_MI_CMD(MI_NOOP);
Chia-I Wue24c3292014-08-21 14:05:23 +0800463 }
Chia-I Wu343b1372014-08-20 16:39:20 +0800464}
465
Chia-I Wu525c6602014-08-27 10:22:34 +0800466void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0);
Chia-I Wu3fb47ce2014-10-28 11:19:36 +0800467void cmd_batch_flush_all(struct intel_cmd *cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +0800468
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800469void cmd_batch_depth_count(struct intel_cmd *cmd,
470 struct intel_bo *bo,
471 XGL_GPU_SIZE offset);
472
Chia-I Wue8dbd5d2014-08-31 13:15:58 +0800473void cmd_batch_timestamp(struct intel_cmd *cmd,
474 struct intel_bo *bo,
475 XGL_GPU_SIZE offset);
476
477void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +0000478 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +0800479 struct intel_bo *bo,
480 XGL_GPU_SIZE offset,
481 uint64_t val);
Chia-I Wu1cbc0052014-08-25 09:50:12 +0800482
Chia-I Wuc14d1562014-10-17 09:49:22 +0800483void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta);
484
Chia-I Wu00a23b22014-08-20 15:28:08 +0800485#endif /* CMD_PRIV_H */