Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 1 | /* |
| 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #ifndef CMD_PRIV_H |
| 29 | #define CMD_PRIV_H |
| 30 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 31 | #include "genhw/genhw.h" |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 32 | #include "dev.h" |
| 33 | #include "gpu.h" |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 34 | #include "cmd.h" |
| 35 | |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 36 | #define CMD_ASSERT(cmd, min_gen, max_gen) \ |
| 37 | INTEL_GPU_ASSERT((cmd)->dev->gpu, (min_gen), (max_gen)) |
| 38 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 39 | enum 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 | |
| 61 | struct intel_cmd_item { |
| 62 | enum intel_cmd_item_type type; |
| 63 | XGL_SIZE offset; |
| 64 | XGL_SIZE size; |
| 65 | }; |
| 66 | |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 67 | #define INTEL_CMD_RELOC_TARGET_IS_WRITER (1u << 31) |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 68 | struct intel_cmd_reloc { |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 69 | enum intel_cmd_writer_type which; |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 70 | XGL_SIZE offset; |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 71 | |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 72 | intptr_t target; |
| 73 | uint32_t target_offset; |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 74 | |
Chia-I Wu | 32a2246 | 2014-08-26 14:13:46 +0800 | [diff] [blame] | 75 | uint32_t flags; |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 76 | }; |
| 77 | |
Chia-I Wu | c14d156 | 2014-10-17 09:49:22 +0800 | [diff] [blame] | 78 | struct intel_ds_view; |
| 79 | |
Chia-I Wu | 29e6f50 | 2014-11-24 14:27:29 +0800 | [diff] [blame] | 80 | enum intel_cmd_meta_mode { |
| 81 | /* |
Chia-I Wu | 4d344e6 | 2014-12-20 21:06:04 +0800 | [diff] [blame] | 82 | * Draw POINTLIST of (width * height) vertices with only VS enabled. The |
| 83 | * vertex id is from 0 to (width * height - 1). |
Chia-I Wu | 29e6f50 | 2014-11-24 14:27:29 +0800 | [diff] [blame] | 84 | */ |
| 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 Wu | c14d156 | 2014-10-17 09:49:22 +0800 | [diff] [blame] | 100 | struct intel_cmd_meta { |
Chia-I Wu | 29e6f50 | 2014-11-24 14:27:29 +0800 | [diff] [blame] | 101 | enum intel_cmd_meta_mode mode; |
Chia-I Wu | c14d156 | 2014-10-17 09:49:22 +0800 | [diff] [blame] | 102 | enum intel_dev_meta_shader shader_id; |
| 103 | |
| 104 | struct { |
| 105 | bool valid; |
| 106 | |
| 107 | uint32_t surface[8]; |
| 108 | XGL_UINT surface_len; |
| 109 | |
| 110 | intptr_t reloc_target; |
| 111 | uint32_t reloc_offset; |
| 112 | uint32_t reloc_flags; |
| 113 | |
| 114 | XGL_UINT lod, layer; |
| 115 | XGL_UINT x, y; |
| 116 | } src, dst; |
| 117 | |
Chia-I Wu | 429a0aa | 2014-10-24 11:57:51 +0800 | [diff] [blame] | 118 | struct { |
| 119 | struct intel_ds_view *view; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 120 | uint32_t stencil_ref; |
| 121 | XGL_IMAGE_ASPECT aspect; |
Chia-I Wu | 429a0aa | 2014-10-24 11:57:51 +0800 | [diff] [blame] | 122 | } ds; |
| 123 | |
Chia-I Wu | c14d156 | 2014-10-17 09:49:22 +0800 | [diff] [blame] | 124 | uint32_t clear_val[4]; |
| 125 | |
| 126 | XGL_UINT width, height; |
| 127 | XGL_UINT samples; |
| 128 | }; |
| 129 | |
Chia-I Wu | 9f03986 | 2014-08-20 15:39:56 +0800 | [diff] [blame] | 130 | static inline int cmd_gen(const struct intel_cmd *cmd) |
| 131 | { |
| 132 | return intel_gpu_gen(cmd->dev->gpu); |
| 133 | } |
| 134 | |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 135 | static inline void cmd_reserve_reloc(struct intel_cmd *cmd, |
| 136 | XGL_UINT reloc_len) |
| 137 | { |
| 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 Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 146 | void cmd_writer_grow(struct intel_cmd *cmd, |
Chia-I Wu | 3c3edc0 | 2014-09-09 10:32:59 +0800 | [diff] [blame] | 147 | enum intel_cmd_writer_type which, |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 148 | XGL_SIZE new_size); |
| 149 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 150 | void cmd_writer_record(struct intel_cmd *cmd, |
| 151 | enum intel_cmd_writer_type which, |
| 152 | enum intel_cmd_item_type type, |
| 153 | XGL_SIZE offset, XGL_SIZE size); |
| 154 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 155 | /** |
| 156 | * Return an offset to a region that is aligned to \p alignment and has at |
| 157 | * least \p size bytes. |
| 158 | */ |
| 159 | static inline XGL_SIZE cmd_writer_reserve(struct intel_cmd *cmd, |
| 160 | enum intel_cmd_writer_type which, |
| 161 | XGL_SIZE alignment, XGL_SIZE size) |
| 162 | { |
| 163 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
| 164 | XGL_SIZE offset; |
| 165 | |
| 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 Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 179 | |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 180 | /** |
Chia-I Wu | bda55fd | 2014-08-25 12:46:10 +0800 | [diff] [blame] | 181 | * Add a reloc at \p pos. No error checking. |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 182 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 183 | static inline void cmd_writer_reloc(struct intel_cmd *cmd, |
| 184 | enum intel_cmd_writer_type which, |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 185 | XGL_SIZE offset, intptr_t target, |
| 186 | uint32_t target_offset, uint32_t flags) |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 187 | { |
| 188 | struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used]; |
| 189 | |
| 190 | assert(cmd->reloc_used < cmd->reloc_count); |
| 191 | |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 192 | reloc->which = which; |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 193 | reloc->offset = offset; |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 194 | reloc->target = target; |
| 195 | reloc->target_offset = target_offset; |
Chia-I Wu | 32a2246 | 2014-08-26 14:13:46 +0800 | [diff] [blame] | 196 | reloc->flags = flags; |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 197 | |
| 198 | cmd->reloc_used++; |
| 199 | } |
| 200 | |
| 201 | /** |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame] | 202 | * Reserve a region from the state buffer. The offset, in bytes, to the |
| 203 | * reserved region is returned. |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 204 | * |
| 205 | * Note that \p alignment is in bytes and \p len is in DWords. |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 206 | */ |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame] | 207 | static inline uint32_t cmd_state_reserve(struct intel_cmd *cmd, |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 208 | enum intel_cmd_item_type item, |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame] | 209 | XGL_SIZE alignment, XGL_UINT len) |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 210 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 211 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE; |
| 212 | const XGL_SIZE size = len << 2; |
| 213 | const XGL_SIZE offset = cmd_writer_reserve(cmd, which, alignment, size); |
| 214 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 215 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 216 | /* all states are at least aligned to 32-bytes */ |
| 217 | assert(alignment % 32 == 0); |
| 218 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 219 | writer->used = offset + size; |
| 220 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 221 | if (intel_debug & INTEL_DEBUG_BATCH) |
| 222 | cmd_writer_record(cmd, which, item, offset, size); |
| 223 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 224 | return offset; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame] | 228 | * Get the pointer to a reserved region for updating. The pointer is only |
| 229 | * valid until the next reserve call. |
| 230 | */ |
| 231 | static inline void cmd_state_update(struct intel_cmd *cmd, |
| 232 | uint32_t offset, XGL_UINT len, |
| 233 | 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 | */ |
| 250 | static inline uint32_t cmd_state_pointer(struct intel_cmd *cmd, |
| 251 | enum intel_cmd_item_type item, |
| 252 | XGL_SIZE alignment, XGL_UINT len, |
| 253 | 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 Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 263 | * Write a dynamic state to the state buffer. |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 264 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 265 | static inline uint32_t cmd_state_write(struct intel_cmd *cmd, |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 266 | enum intel_cmd_item_type item, |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 267 | XGL_SIZE alignment, XGL_UINT len, |
| 268 | const uint32_t *dw) |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 269 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 270 | uint32_t offset, *dst; |
| 271 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 272 | offset = cmd_state_pointer(cmd, item, alignment, len, &dst); |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 273 | memcpy(dst, dw, len << 2); |
| 274 | |
| 275 | return offset; |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /** |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 279 | * 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 Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 283 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 284 | static inline uint32_t cmd_surface_write(struct intel_cmd *cmd, |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 285 | enum intel_cmd_item_type item, |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 286 | XGL_SIZE alignment, XGL_UINT len, |
| 287 | const uint32_t *dw) |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 288 | { |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 289 | 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 Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 296 | * Add a relocation entry for a DWord of a surface state. |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 297 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 298 | static inline void cmd_surface_reloc(struct intel_cmd *cmd, |
| 299 | uint32_t offset, XGL_UINT dw_index, |
| 300 | struct intel_bo *bo, |
| 301 | uint32_t bo_offset, uint32_t reloc_flags) |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 302 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 303 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE; |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 304 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 305 | cmd_writer_reloc(cmd, which, offset + (dw_index << 2), |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 306 | (intptr_t) bo, bo_offset, reloc_flags); |
| 307 | } |
| 308 | |
| 309 | static inline void cmd_surface_reloc_writer(struct intel_cmd *cmd, |
| 310 | uint32_t offset, XGL_UINT dw_index, |
| 311 | 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 Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /** |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 322 | * Write a kernel to the instruction buffer. The offset, in bytes, of the |
| 323 | * kernel is returned. |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 324 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 325 | static inline uint32_t cmd_instruction_write(struct intel_cmd *cmd, |
| 326 | XGL_SIZE size, |
| 327 | const void *kernel) |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 328 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 329 | 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 | */ |
| 339 | const XGL_SIZE reserved_size = size + 128; |
| 340 | /* kernels are aligned to 64 bytes */ |
| 341 | const XGL_SIZE alignment = 64; |
| 342 | const XGL_SIZE offset = cmd_writer_reserve(cmd, |
| 343 | which, alignment, reserved_size); |
| 344 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 345 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 346 | memcpy((char *) writer->ptr + offset, kernel, size); |
Chia-I Wu | 5e25c27 | 2014-08-21 20:19:12 +0800 | [diff] [blame] | 347 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 348 | writer->used = offset + size; |
| 349 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 350 | if (intel_debug & INTEL_DEBUG_BATCH) |
| 351 | cmd_writer_record(cmd, which, INTEL_CMD_ITEM_KERNEL, offset, size); |
| 352 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 353 | return offset; |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Reserve a region from the batch buffer. Both the offset, in DWords, and |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame] | 358 | * the pointer to the reserved region are returned. The pointer is only valid |
| 359 | * until the next reserve call. |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 360 | * |
| 361 | * Note that \p len is in DWords. |
| 362 | */ |
| 363 | static inline XGL_UINT cmd_batch_pointer(struct intel_cmd *cmd, |
| 364 | XGL_UINT len, uint32_t **dw) |
| 365 | { |
| 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 | */ |
| 371 | const XGL_SIZE alignment = 1; |
| 372 | const XGL_SIZE size = len << 2; |
| 373 | const XGL_SIZE offset = cmd_writer_reserve(cmd, which, alignment, size); |
| 374 | 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 | */ |
| 387 | static inline XGL_UINT cmd_batch_write(struct intel_cmd *cmd, |
| 388 | XGL_UINT len, const uint32_t *dw) |
| 389 | { |
| 390 | XGL_UINT pos; |
| 391 | 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 | */ |
| 402 | static inline void cmd_batch_reloc(struct intel_cmd *cmd, XGL_UINT pos, |
| 403 | 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 Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 408 | cmd_writer_reloc(cmd, which, pos << 2, (intptr_t) bo, bo_offset, reloc_flags); |
| 409 | } |
| 410 | |
| 411 | static inline void cmd_batch_reloc_writer(struct intel_cmd *cmd, XGL_UINT pos, |
| 412 | 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 Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /** |
Chia-I Wu | 48c283d | 2014-08-25 23:13:46 +0800 | [diff] [blame] | 422 | * Begin the batch buffer. |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 423 | */ |
| 424 | static inline void cmd_batch_begin(struct intel_cmd *cmd) |
| 425 | { |
Chia-I Wu | 48c283d | 2014-08-25 23:13:46 +0800 | [diff] [blame] | 426 | /* STATE_BASE_ADDRESS */ |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 427 | const uint8_t cmd_len = 10; |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 428 | const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) | |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 429 | (cmd_len - 2); |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 430 | XGL_UINT pos; |
| 431 | uint32_t *dw; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 432 | |
| 433 | CMD_ASSERT(cmd, 6, 7.5); |
| 434 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 435 | pos = cmd_batch_pointer(cmd, cmd_len, &dw); |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 436 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 437 | dw[0] = dw0; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 438 | /* start offsets */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 439 | dw[1] = 1; |
| 440 | dw[2] = 1; |
| 441 | dw[3] = 1; |
| 442 | dw[4] = 1; |
| 443 | dw[5] = 1; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 444 | /* end offsets */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 445 | dw[6] = 1; |
| 446 | dw[7] = 1 + 0xfffff000; |
| 447 | dw[8] = 1 + 0xfffff000; |
| 448 | dw[9] = 1; |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 449 | |
| 450 | cmd_reserve_reloc(cmd, 3); |
| 451 | cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, 1); |
| 452 | cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, 1); |
| 453 | cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION, 1); |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 457 | * End the batch buffer. |
| 458 | */ |
| 459 | static inline void cmd_batch_end(struct intel_cmd *cmd) |
| 460 | { |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 461 | struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_BATCH]; |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 462 | uint32_t *dw; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 463 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 464 | if (writer->used & 0x7) { |
| 465 | cmd_batch_pointer(cmd, 1, &dw); |
| 466 | dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END); |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 467 | } else { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 468 | cmd_batch_pointer(cmd, 2, &dw); |
| 469 | dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END); |
| 470 | dw[1] = GEN6_MI_CMD(MI_NOOP); |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 471 | } |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 472 | } |
| 473 | |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 474 | void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0); |
Chia-I Wu | 3fb47ce | 2014-10-28 11:19:36 +0800 | [diff] [blame] | 475 | void cmd_batch_flush_all(struct intel_cmd *cmd); |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 476 | |
Chia-I Wu | 759fa2e | 2014-08-30 18:44:47 +0800 | [diff] [blame] | 477 | void cmd_batch_depth_count(struct intel_cmd *cmd, |
| 478 | struct intel_bo *bo, |
| 479 | XGL_GPU_SIZE offset); |
| 480 | |
Chia-I Wu | e8dbd5d | 2014-08-31 13:15:58 +0800 | [diff] [blame] | 481 | void cmd_batch_timestamp(struct intel_cmd *cmd, |
| 482 | struct intel_bo *bo, |
| 483 | XGL_GPU_SIZE offset); |
| 484 | |
| 485 | void cmd_batch_immediate(struct intel_cmd *cmd, |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame^] | 486 | uint32_t pipe_control_flags, |
Chia-I Wu | e8dbd5d | 2014-08-31 13:15:58 +0800 | [diff] [blame] | 487 | struct intel_bo *bo, |
| 488 | XGL_GPU_SIZE offset, |
| 489 | uint64_t val); |
Chia-I Wu | 1cbc005 | 2014-08-25 09:50:12 +0800 | [diff] [blame] | 490 | |
Chia-I Wu | c14d156 | 2014-10-17 09:49:22 +0800 | [diff] [blame] | 491 | void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta); |
| 492 | |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 493 | #endif /* CMD_PRIV_H */ |