blob: dda45e10fb3d454a59151c0b6c91a928b3304588 [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 Wu00b51a82014-09-09 12:07:37 +0800289 assert(item == INTEL_CMD_ITEM_SURFACE ||
290 item == INTEL_CMD_ITEM_BINDING_TABLE);
291
292 return cmd_state_write(cmd, item, alignment, len, dw);
Chia-I Wue24c3292014-08-21 14:05:23 +0800293}
294
295/**
Chia-I Wu72292b72014-09-09 10:48:33 +0800296 * Add a relocation entry for a DWord of a surface state.
Chia-I Wucdff0592014-08-22 09:27:36 +0800297 */
Chia-I Wu72292b72014-09-09 10:48:33 +0800298static inline void cmd_surface_reloc(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600299 uint32_t offset, uint32_t dw_index,
Chia-I Wu72292b72014-09-09 10:48:33 +0800300 struct intel_bo *bo,
301 uint32_t bo_offset, uint32_t reloc_flags)
Chia-I Wucdff0592014-08-22 09:27:36 +0800302{
Chia-I Wu72292b72014-09-09 10:48:33 +0800303 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE;
Chia-I Wucdff0592014-08-22 09:27:36 +0800304
Chia-I Wu72292b72014-09-09 10:48:33 +0800305 cmd_writer_reloc(cmd, which, offset + (dw_index << 2),
Chia-I Wud7d1e482014-10-18 13:25:10 +0800306 (intptr_t) bo, bo_offset, reloc_flags);
307}
308
309static inline void cmd_surface_reloc_writer(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600310 uint32_t offset, uint32_t dw_index,
Chia-I Wud7d1e482014-10-18 13:25:10 +0800311 enum intel_cmd_writer_type writer,
312 uint32_t writer_offset)
313{
314 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE;
315
316 cmd_writer_reloc(cmd, which, offset + (dw_index << 2),
317 (intptr_t) writer, writer_offset,
318 INTEL_CMD_RELOC_TARGET_IS_WRITER);
Chia-I Wucdff0592014-08-22 09:27:36 +0800319}
320
321/**
Chia-I Wu72292b72014-09-09 10:48:33 +0800322 * Write a kernel to the instruction buffer. The offset, in bytes, of the
323 * kernel is returned.
Chia-I Wue24c3292014-08-21 14:05:23 +0800324 */
Chia-I Wu72292b72014-09-09 10:48:33 +0800325static inline uint32_t cmd_instruction_write(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600326 size_t size,
Chia-I Wu72292b72014-09-09 10:48:33 +0800327 const void *kernel)
Chia-I Wue24c3292014-08-21 14:05:23 +0800328{
Chia-I Wu72292b72014-09-09 10:48:33 +0800329 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_INSTRUCTION;
330 /*
331 * From the Sandy Bridge PRM, volume 4 part 2, page 112:
332 *
333 * "Due to prefetch of the instruction stream, the EUs may attempt to
334 * access up to 8 instructions (128 bytes) beyond the end of the
335 * kernel program - possibly into the next memory page. Although
336 * these instructions will not be executed, software must account for
337 * the prefetch in order to avoid invalid page access faults."
338 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600339 const size_t reserved_size = size + 128;
Chia-I Wu72292b72014-09-09 10:48:33 +0800340 /* kernels are aligned to 64 bytes */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600341 const size_t alignment = 64;
342 const size_t offset = cmd_writer_reserve(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800343 which, alignment, reserved_size);
344 struct intel_cmd_writer *writer = &cmd->writers[which];
Chia-I Wue24c3292014-08-21 14:05:23 +0800345
Chia-I Wu72292b72014-09-09 10:48:33 +0800346 memcpy((char *) writer->ptr + offset, kernel, size);
Chia-I Wu5e25c272014-08-21 20:19:12 +0800347
Chia-I Wu72292b72014-09-09 10:48:33 +0800348 writer->used = offset + size;
349
Chia-I Wu00b51a82014-09-09 12:07:37 +0800350 if (intel_debug & INTEL_DEBUG_BATCH)
351 cmd_writer_record(cmd, which, INTEL_CMD_ITEM_KERNEL, offset, size);
352
Chia-I Wu72292b72014-09-09 10:48:33 +0800353 return offset;
354}
355
356/**
357 * Reserve a region from the batch buffer. Both the offset, in DWords, and
Chia-I Wu5da476a2014-12-10 08:50:28 +0800358 * the pointer to the reserved region are returned. The pointer is only valid
359 * until the next reserve call.
Chia-I Wu72292b72014-09-09 10:48:33 +0800360 *
361 * Note that \p len is in DWords.
362 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600363static inline uint32_t cmd_batch_pointer(struct intel_cmd *cmd,
364 uint32_t len, uint32_t **dw)
Chia-I Wu72292b72014-09-09 10:48:33 +0800365{
366 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH;
367 /*
368 * We know the batch bo is always aligned. Using 1 here should allow the
369 * compiler to optimize away aligning.
370 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600371 const size_t alignment = 1;
372 const size_t size = len << 2;
373 const size_t offset = cmd_writer_reserve(cmd, which, alignment, size);
Chia-I Wu72292b72014-09-09 10:48:33 +0800374 struct intel_cmd_writer *writer = &cmd->writers[which];
375
376 assert(offset % 4 == 0);
377 *dw = (uint32_t *) ((char *) writer->ptr + offset);
378
379 writer->used = offset + size;
380
381 return offset >> 2;
382}
383
384/**
385 * Write a command to the batch buffer.
386 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600387static inline uint32_t cmd_batch_write(struct intel_cmd *cmd,
388 uint32_t len, const uint32_t *dw)
Chia-I Wu72292b72014-09-09 10:48:33 +0800389{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600390 uint32_t pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800391 uint32_t *dst;
392
393 pos = cmd_batch_pointer(cmd, len, &dst);
394 memcpy(dst, dw, len << 2);
395
396 return pos;
397}
398
399/**
400 * Add a relocation entry for a DWord of a command.
401 */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600402static inline void cmd_batch_reloc(struct intel_cmd *cmd, uint32_t pos,
Chia-I Wu72292b72014-09-09 10:48:33 +0800403 struct intel_bo *bo,
404 uint32_t bo_offset, uint32_t reloc_flags)
405{
406 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH;
407
Chia-I Wud7d1e482014-10-18 13:25:10 +0800408 cmd_writer_reloc(cmd, which, pos << 2, (intptr_t) bo, bo_offset, reloc_flags);
409}
410
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411static inline void cmd_batch_reloc_writer(struct intel_cmd *cmd, uint32_t pos,
Chia-I Wud7d1e482014-10-18 13:25:10 +0800412 enum intel_cmd_writer_type writer,
413 uint32_t writer_offset)
414{
415 const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH;
416
417 cmd_writer_reloc(cmd, which, pos << 2, (intptr_t) writer, writer_offset,
418 INTEL_CMD_RELOC_TARGET_IS_WRITER);
Chia-I Wue24c3292014-08-21 14:05:23 +0800419}
420
Chia-I Wu66bdcd72015-02-10 04:11:31 +0800421void cmd_batch_state_base_address(struct intel_cmd *cmd);
422
Chia-I Wue24c3292014-08-21 14:05:23 +0800423/**
Chia-I Wu48c283d2014-08-25 23:13:46 +0800424 * Begin the batch buffer.
Chia-I Wu79dfbb32014-08-25 12:19:02 +0800425 */
426static inline void cmd_batch_begin(struct intel_cmd *cmd)
427{
Chia-I Wu66bdcd72015-02-10 04:11:31 +0800428 cmd_batch_state_base_address(cmd);
Chia-I Wu79dfbb32014-08-25 12:19:02 +0800429}
430
431/**
Chia-I Wue24c3292014-08-21 14:05:23 +0800432 * End the batch buffer.
433 */
434static inline void cmd_batch_end(struct intel_cmd *cmd)
435{
Chia-I Wu68f319d2014-09-09 09:43:21 +0800436 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_BATCH];
Chia-I Wu72292b72014-09-09 10:48:33 +0800437 uint32_t *dw;
Chia-I Wu79dfbb32014-08-25 12:19:02 +0800438
Chia-I Wu72292b72014-09-09 10:48:33 +0800439 if (writer->used & 0x7) {
440 cmd_batch_pointer(cmd, 1, &dw);
441 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END);
Chia-I Wue24c3292014-08-21 14:05:23 +0800442 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800443 cmd_batch_pointer(cmd, 2, &dw);
444 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END);
445 dw[1] = GEN6_MI_CMD(MI_NOOP);
Chia-I Wue24c3292014-08-21 14:05:23 +0800446 }
Chia-I Wu343b1372014-08-20 16:39:20 +0800447}
448
Chia-I Wu525c6602014-08-27 10:22:34 +0800449void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0);
Chia-I Wu3fb47ce2014-10-28 11:19:36 +0800450void cmd_batch_flush_all(struct intel_cmd *cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +0800451
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800452void cmd_batch_depth_count(struct intel_cmd *cmd,
453 struct intel_bo *bo,
454 XGL_GPU_SIZE offset);
455
Chia-I Wue8dbd5d2014-08-31 13:15:58 +0800456void cmd_batch_timestamp(struct intel_cmd *cmd,
457 struct intel_bo *bo,
458 XGL_GPU_SIZE offset);
459
460void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +0000461 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +0800462 struct intel_bo *bo,
463 XGL_GPU_SIZE offset,
464 uint64_t val);
Chia-I Wu1cbc0052014-08-25 09:50:12 +0800465
Chia-I Wuc14d1562014-10-17 09:49:22 +0800466void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta);
467
Chia-I Wu00a23b22014-08-20 15:28:08 +0800468#endif /* CMD_PRIV_H */