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 | /* |
| 82 | * Draw POINTLIST of (width - 1) vertices with only VS enabled. The |
| 83 | * vertex id is from 0 to (width - 1). |
| 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; |
| 120 | struct intel_ds_state *state; |
| 121 | } ds; |
| 122 | |
Chia-I Wu | c14d156 | 2014-10-17 09:49:22 +0800 | [diff] [blame] | 123 | uint32_t clear_val[4]; |
| 124 | |
| 125 | XGL_UINT width, height; |
| 126 | XGL_UINT samples; |
| 127 | }; |
| 128 | |
Chia-I Wu | 9f03986 | 2014-08-20 15:39:56 +0800 | [diff] [blame] | 129 | static inline int cmd_gen(const struct intel_cmd *cmd) |
| 130 | { |
| 131 | return intel_gpu_gen(cmd->dev->gpu); |
| 132 | } |
| 133 | |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 134 | static inline void cmd_reserve_reloc(struct intel_cmd *cmd, |
| 135 | XGL_UINT reloc_len) |
| 136 | { |
| 137 | /* fail silently */ |
| 138 | if (cmd->reloc_used + reloc_len > cmd->reloc_count) { |
| 139 | cmd->reloc_used = 0; |
| 140 | cmd->result = XGL_ERROR_TOO_MANY_MEMORY_REFERENCES; |
| 141 | } |
| 142 | assert(cmd->reloc_used + reloc_len <= cmd->reloc_count); |
| 143 | } |
| 144 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 145 | void cmd_writer_grow(struct intel_cmd *cmd, |
Chia-I Wu | 3c3edc0 | 2014-09-09 10:32:59 +0800 | [diff] [blame] | 146 | enum intel_cmd_writer_type which, |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 147 | XGL_SIZE new_size); |
| 148 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 149 | void cmd_writer_record(struct intel_cmd *cmd, |
| 150 | enum intel_cmd_writer_type which, |
| 151 | enum intel_cmd_item_type type, |
| 152 | XGL_SIZE offset, XGL_SIZE size); |
| 153 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 154 | /** |
| 155 | * Return an offset to a region that is aligned to \p alignment and has at |
| 156 | * least \p size bytes. |
| 157 | */ |
| 158 | static inline XGL_SIZE cmd_writer_reserve(struct intel_cmd *cmd, |
| 159 | enum intel_cmd_writer_type which, |
| 160 | XGL_SIZE alignment, XGL_SIZE size) |
| 161 | { |
| 162 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
| 163 | XGL_SIZE offset; |
| 164 | |
| 165 | assert(alignment && u_is_pow2(alignment)); |
| 166 | offset = u_align(writer->used, alignment); |
| 167 | |
| 168 | if (offset + size > writer->size) { |
| 169 | cmd_writer_grow(cmd, which, offset + size); |
| 170 | /* align again in case of errors */ |
| 171 | offset = u_align(writer->used, alignment); |
| 172 | |
| 173 | assert(offset + size <= writer->size); |
| 174 | } |
| 175 | |
| 176 | return offset; |
| 177 | } |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 178 | |
Chia-I Wu | 32710d7 | 2014-08-20 16:05:22 +0800 | [diff] [blame] | 179 | /** |
Chia-I Wu | bda55fd | 2014-08-25 12:46:10 +0800 | [diff] [blame] | 180 | * Add a reloc at \p pos. No error checking. |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 181 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 182 | static inline void cmd_writer_reloc(struct intel_cmd *cmd, |
| 183 | enum intel_cmd_writer_type which, |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 184 | XGL_SIZE offset, intptr_t target, |
| 185 | uint32_t target_offset, uint32_t flags) |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 186 | { |
| 187 | struct intel_cmd_reloc *reloc = &cmd->relocs[cmd->reloc_used]; |
| 188 | |
| 189 | assert(cmd->reloc_used < cmd->reloc_count); |
| 190 | |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 191 | reloc->which = which; |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 192 | reloc->offset = offset; |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 193 | reloc->target = target; |
| 194 | reloc->target_offset = target_offset; |
Chia-I Wu | 32a2246 | 2014-08-26 14:13:46 +0800 | [diff] [blame] | 195 | reloc->flags = flags; |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 196 | |
| 197 | cmd->reloc_used++; |
| 198 | } |
| 199 | |
| 200 | /** |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame^] | 201 | * Reserve a region from the state buffer. The offset, in bytes, to the |
| 202 | * reserved region is returned. |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 203 | * |
| 204 | * 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] | 205 | */ |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame^] | 206 | static inline uint32_t cmd_state_reserve(struct intel_cmd *cmd, |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 207 | enum intel_cmd_item_type item, |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame^] | 208 | XGL_SIZE alignment, XGL_UINT len) |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 209 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 210 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE; |
| 211 | const XGL_SIZE size = len << 2; |
| 212 | const XGL_SIZE offset = cmd_writer_reserve(cmd, which, alignment, size); |
| 213 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 214 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 215 | /* all states are at least aligned to 32-bytes */ |
| 216 | assert(alignment % 32 == 0); |
| 217 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 218 | writer->used = offset + size; |
| 219 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 220 | if (intel_debug & INTEL_DEBUG_BATCH) |
| 221 | cmd_writer_record(cmd, which, item, offset, size); |
| 222 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 223 | return offset; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /** |
Chia-I Wu | 5da476a | 2014-12-10 08:50:28 +0800 | [diff] [blame^] | 227 | * Get the pointer to a reserved region for updating. The pointer is only |
| 228 | * valid until the next reserve call. |
| 229 | */ |
| 230 | static inline void cmd_state_update(struct intel_cmd *cmd, |
| 231 | uint32_t offset, XGL_UINT len, |
| 232 | uint32_t **dw) |
| 233 | { |
| 234 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE; |
| 235 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
| 236 | |
| 237 | assert(offset + (len << 2) <= writer->used); |
| 238 | |
| 239 | *dw = (uint32_t *) ((char *) writer->ptr + offset); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Reserve a region from the state buffer. Both the offset, in bytes, and the |
| 244 | * pointer to the reserved region are returned. The pointer is only valid |
| 245 | * until the next reserve call. |
| 246 | * |
| 247 | * Note that \p alignment is in bytes and \p len is in DWords. |
| 248 | */ |
| 249 | static inline uint32_t cmd_state_pointer(struct intel_cmd *cmd, |
| 250 | enum intel_cmd_item_type item, |
| 251 | XGL_SIZE alignment, XGL_UINT len, |
| 252 | uint32_t **dw) |
| 253 | { |
| 254 | const uint32_t offset = cmd_state_reserve(cmd, item, alignment, len); |
| 255 | |
| 256 | cmd_state_update(cmd, offset, len, dw); |
| 257 | |
| 258 | return offset; |
| 259 | } |
| 260 | |
| 261 | /** |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 262 | * Write a dynamic state to the state buffer. |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 263 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 264 | static inline uint32_t cmd_state_write(struct intel_cmd *cmd, |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 265 | enum intel_cmd_item_type item, |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 266 | XGL_SIZE alignment, XGL_UINT len, |
| 267 | const uint32_t *dw) |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 268 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 269 | uint32_t offset, *dst; |
| 270 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 271 | offset = cmd_state_pointer(cmd, item, alignment, len, &dst); |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 272 | memcpy(dst, dw, len << 2); |
| 273 | |
| 274 | return offset; |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /** |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 278 | * Write a surface state to the surface buffer. The offset, in bytes, of the |
| 279 | * state is returned. |
| 280 | * |
| 281 | * 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] | 282 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 283 | static inline uint32_t cmd_surface_write(struct intel_cmd *cmd, |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 284 | enum intel_cmd_item_type item, |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 285 | XGL_SIZE alignment, XGL_UINT len, |
| 286 | const uint32_t *dw) |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 287 | { |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 288 | assert(item == INTEL_CMD_ITEM_SURFACE || |
| 289 | item == INTEL_CMD_ITEM_BINDING_TABLE); |
| 290 | |
| 291 | return cmd_state_write(cmd, item, alignment, len, dw); |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 295 | * Add a relocation entry for a DWord of a surface state. |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 296 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 297 | static inline void cmd_surface_reloc(struct intel_cmd *cmd, |
| 298 | uint32_t offset, XGL_UINT dw_index, |
| 299 | struct intel_bo *bo, |
| 300 | uint32_t bo_offset, uint32_t reloc_flags) |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 301 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 302 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE; |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 303 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 304 | cmd_writer_reloc(cmd, which, offset + (dw_index << 2), |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 305 | (intptr_t) bo, bo_offset, reloc_flags); |
| 306 | } |
| 307 | |
| 308 | static inline void cmd_surface_reloc_writer(struct intel_cmd *cmd, |
| 309 | uint32_t offset, XGL_UINT dw_index, |
| 310 | enum intel_cmd_writer_type writer, |
| 311 | uint32_t writer_offset) |
| 312 | { |
| 313 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE; |
| 314 | |
| 315 | cmd_writer_reloc(cmd, which, offset + (dw_index << 2), |
| 316 | (intptr_t) writer, writer_offset, |
| 317 | INTEL_CMD_RELOC_TARGET_IS_WRITER); |
Chia-I Wu | cdff059 | 2014-08-22 09:27:36 +0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /** |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 321 | * Write a kernel to the instruction buffer. The offset, in bytes, of the |
| 322 | * kernel is returned. |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 323 | */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 324 | static inline uint32_t cmd_instruction_write(struct intel_cmd *cmd, |
| 325 | XGL_SIZE size, |
| 326 | const void *kernel) |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 327 | { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 328 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_INSTRUCTION; |
| 329 | /* |
| 330 | * From the Sandy Bridge PRM, volume 4 part 2, page 112: |
| 331 | * |
| 332 | * "Due to prefetch of the instruction stream, the EUs may attempt to |
| 333 | * access up to 8 instructions (128 bytes) beyond the end of the |
| 334 | * kernel program - possibly into the next memory page. Although |
| 335 | * these instructions will not be executed, software must account for |
| 336 | * the prefetch in order to avoid invalid page access faults." |
| 337 | */ |
| 338 | const XGL_SIZE reserved_size = size + 128; |
| 339 | /* kernels are aligned to 64 bytes */ |
| 340 | const XGL_SIZE alignment = 64; |
| 341 | const XGL_SIZE offset = cmd_writer_reserve(cmd, |
| 342 | which, alignment, reserved_size); |
| 343 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 344 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 345 | memcpy((char *) writer->ptr + offset, kernel, size); |
Chia-I Wu | 5e25c27 | 2014-08-21 20:19:12 +0800 | [diff] [blame] | 346 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 347 | writer->used = offset + size; |
| 348 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 349 | if (intel_debug & INTEL_DEBUG_BATCH) |
| 350 | cmd_writer_record(cmd, which, INTEL_CMD_ITEM_KERNEL, offset, size); |
| 351 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 352 | return offset; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * 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^] | 357 | * the pointer to the reserved region are returned. The pointer is only valid |
| 358 | * until the next reserve call. |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 359 | * |
| 360 | * Note that \p len is in DWords. |
| 361 | */ |
| 362 | static inline XGL_UINT cmd_batch_pointer(struct intel_cmd *cmd, |
| 363 | XGL_UINT len, uint32_t **dw) |
| 364 | { |
| 365 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH; |
| 366 | /* |
| 367 | * We know the batch bo is always aligned. Using 1 here should allow the |
| 368 | * compiler to optimize away aligning. |
| 369 | */ |
| 370 | const XGL_SIZE alignment = 1; |
| 371 | const XGL_SIZE size = len << 2; |
| 372 | const XGL_SIZE offset = cmd_writer_reserve(cmd, which, alignment, size); |
| 373 | struct intel_cmd_writer *writer = &cmd->writers[which]; |
| 374 | |
| 375 | assert(offset % 4 == 0); |
| 376 | *dw = (uint32_t *) ((char *) writer->ptr + offset); |
| 377 | |
| 378 | writer->used = offset + size; |
| 379 | |
| 380 | return offset >> 2; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Write a command to the batch buffer. |
| 385 | */ |
| 386 | static inline XGL_UINT cmd_batch_write(struct intel_cmd *cmd, |
| 387 | XGL_UINT len, const uint32_t *dw) |
| 388 | { |
| 389 | XGL_UINT pos; |
| 390 | uint32_t *dst; |
| 391 | |
| 392 | pos = cmd_batch_pointer(cmd, len, &dst); |
| 393 | memcpy(dst, dw, len << 2); |
| 394 | |
| 395 | return pos; |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Add a relocation entry for a DWord of a command. |
| 400 | */ |
| 401 | static inline void cmd_batch_reloc(struct intel_cmd *cmd, XGL_UINT pos, |
| 402 | struct intel_bo *bo, |
| 403 | uint32_t bo_offset, uint32_t reloc_flags) |
| 404 | { |
| 405 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH; |
| 406 | |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 407 | cmd_writer_reloc(cmd, which, pos << 2, (intptr_t) bo, bo_offset, reloc_flags); |
| 408 | } |
| 409 | |
| 410 | static inline void cmd_batch_reloc_writer(struct intel_cmd *cmd, XGL_UINT pos, |
| 411 | enum intel_cmd_writer_type writer, |
| 412 | uint32_t writer_offset) |
| 413 | { |
| 414 | const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_BATCH; |
| 415 | |
| 416 | cmd_writer_reloc(cmd, which, pos << 2, (intptr_t) writer, writer_offset, |
| 417 | INTEL_CMD_RELOC_TARGET_IS_WRITER); |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /** |
Chia-I Wu | 48c283d | 2014-08-25 23:13:46 +0800 | [diff] [blame] | 421 | * Begin the batch buffer. |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 422 | */ |
| 423 | static inline void cmd_batch_begin(struct intel_cmd *cmd) |
| 424 | { |
Chia-I Wu | 48c283d | 2014-08-25 23:13:46 +0800 | [diff] [blame] | 425 | /* STATE_BASE_ADDRESS */ |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 426 | const uint8_t cmd_len = 10; |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 427 | const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) | |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 428 | (cmd_len - 2); |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 429 | XGL_UINT pos; |
| 430 | uint32_t *dw; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 431 | |
| 432 | CMD_ASSERT(cmd, 6, 7.5); |
| 433 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 434 | pos = cmd_batch_pointer(cmd, cmd_len, &dw); |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 435 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 436 | dw[0] = dw0; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 437 | /* start offsets */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 438 | dw[1] = 1; |
| 439 | dw[2] = 1; |
| 440 | dw[3] = 1; |
| 441 | dw[4] = 1; |
| 442 | dw[5] = 1; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 443 | /* end offsets */ |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 444 | dw[6] = 1; |
| 445 | dw[7] = 1 + 0xfffff000; |
| 446 | dw[8] = 1 + 0xfffff000; |
| 447 | dw[9] = 1; |
Chia-I Wu | d7d1e48 | 2014-10-18 13:25:10 +0800 | [diff] [blame] | 448 | |
| 449 | cmd_reserve_reloc(cmd, 3); |
| 450 | cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, 1); |
| 451 | cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, 1); |
| 452 | 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] | 453 | } |
| 454 | |
| 455 | /** |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 456 | * End the batch buffer. |
| 457 | */ |
| 458 | static inline void cmd_batch_end(struct intel_cmd *cmd) |
| 459 | { |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 460 | struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_BATCH]; |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 461 | uint32_t *dw; |
Chia-I Wu | 79dfbb3 | 2014-08-25 12:19:02 +0800 | [diff] [blame] | 462 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 463 | if (writer->used & 0x7) { |
| 464 | cmd_batch_pointer(cmd, 1, &dw); |
| 465 | dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END); |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 466 | } else { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 467 | cmd_batch_pointer(cmd, 2, &dw); |
| 468 | dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END); |
| 469 | dw[1] = GEN6_MI_CMD(MI_NOOP); |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 470 | } |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 471 | } |
| 472 | |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 473 | 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] | 474 | void cmd_batch_flush_all(struct intel_cmd *cmd); |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 475 | |
Chia-I Wu | 759fa2e | 2014-08-30 18:44:47 +0800 | [diff] [blame] | 476 | void cmd_batch_depth_count(struct intel_cmd *cmd, |
| 477 | struct intel_bo *bo, |
| 478 | XGL_GPU_SIZE offset); |
| 479 | |
Chia-I Wu | e8dbd5d | 2014-08-31 13:15:58 +0800 | [diff] [blame] | 480 | void cmd_batch_timestamp(struct intel_cmd *cmd, |
| 481 | struct intel_bo *bo, |
| 482 | XGL_GPU_SIZE offset); |
| 483 | |
| 484 | void cmd_batch_immediate(struct intel_cmd *cmd, |
| 485 | struct intel_bo *bo, |
| 486 | XGL_GPU_SIZE offset, |
| 487 | uint64_t val); |
Chia-I Wu | 1cbc005 | 2014-08-25 09:50:12 +0800 | [diff] [blame] | 488 | |
Chia-I Wu | c14d156 | 2014-10-17 09:49:22 +0800 | [diff] [blame] | 489 | void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta); |
| 490 | |
Chia-I Wu | 00a23b2 | 2014-08-20 15:28:08 +0800 | [diff] [blame] | 491 | #endif /* CMD_PRIV_H */ |