Chia-I Wu | 0914213 | 2014-08-11 15:42:55 +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> |
| 26 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
Chia-I Wu | 0914213 | 2014-08-11 15:42:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #ifndef CMD_H |
| 30 | #define CMD_H |
| 31 | |
| 32 | #include "intel.h" |
| 33 | #include "obj.h" |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 34 | #include "view.h" |
| 35 | |
| 36 | struct intel_pipeline; |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 37 | struct intel_pipeline_shader; |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 38 | struct intel_pipeline_delta; |
| 39 | struct intel_viewport_state; |
| 40 | struct intel_raster_state; |
| 41 | struct intel_msaa_state; |
| 42 | struct intel_blend_state; |
| 43 | struct intel_ds_state; |
| 44 | struct intel_dset; |
| 45 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 46 | struct intel_cmd_item; |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 47 | struct intel_cmd_reloc; |
Chia-I Wu | 6032b89 | 2014-10-17 14:47:18 +0800 | [diff] [blame] | 48 | struct intel_cmd_meta; |
Chia-I Wu | 958d1b7 | 2014-08-21 11:28:11 +0800 | [diff] [blame] | 49 | |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 50 | /* |
| 51 | * We know what workarounds are needed for intel_pipeline. These are mostly |
| 52 | * for intel_pipeline_delta. |
| 53 | */ |
| 54 | enum intel_cmd_wa_flags { |
| 55 | /* |
| 56 | * From the Sandy Bridge PRM, volume 2 part 1, page 60: |
| 57 | * |
| 58 | * "Before any depth stall flush (including those produced by |
| 59 | * non-pipelined state commands), software needs to first send a |
| 60 | * PIPE_CONTROL with no bits set except Post-Sync Operation != 0." |
| 61 | */ |
| 62 | INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE = 1 << 0, |
| 63 | |
| 64 | /* |
| 65 | * From the Sandy Bridge PRM, volume 2 part 1, page 274: |
| 66 | * |
| 67 | * "A PIPE_CONTROL command, with only the Stall At Pixel Scoreboard |
| 68 | * field set (DW1 Bit 1), must be issued prior to any change to the |
| 69 | * value in this field (Maximum Number of Threads in 3DSTATE_WM)" |
| 70 | * |
| 71 | * From the Ivy Bridge PRM, volume 2 part 1, page 286: |
| 72 | * |
| 73 | * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed |
| 74 | * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at |
| 75 | * Pixel Scoreboard set is required to be issued." |
| 76 | */ |
| 77 | INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL = 1 << 1, |
| 78 | |
| 79 | /* |
| 80 | * From the Ivy Bridge PRM, volume 2 part 1, page 106: |
| 81 | * |
| 82 | * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth |
| 83 | * stall needs to be sent just prior to any 3DSTATE_VS, |
| 84 | * 3DSTATE_URB_VS, 3DSTATE_CONSTANT_VS, |
| 85 | * 3DSTATE_BINDING_TABLE_POINTER_VS, 3DSTATE_SAMPLER_STATE_POINTER_VS |
| 86 | * command. Only one PIPE_CONTROL needs to be sent before any |
| 87 | * combination of VS associated 3DSTATE." |
| 88 | */ |
| 89 | INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE = 1 << 2, |
| 90 | |
| 91 | /* |
| 92 | * From the Ivy Bridge PRM, volume 2 part 1, page 258: |
| 93 | * |
| 94 | * "Due to an HW issue driver needs to send a pipe control with stall |
| 95 | * when ever there is state change in depth bias related state" |
| 96 | * |
| 97 | * From the Ivy Bridge PRM, volume 2 part 1, page 292: |
| 98 | * |
| 99 | * "A PIPE_CONTOL command with the CS Stall bit set must be programmed |
| 100 | * in the ring after this instruction |
| 101 | * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)." |
| 102 | */ |
| 103 | INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL = 1 << 3, |
| 104 | |
| 105 | /* |
| 106 | * From the Ivy Bridge PRM, volume 2 part 1, page 276: |
| 107 | * |
| 108 | * "The driver must make sure a PIPE_CONTROL with the Depth Stall |
| 109 | * Enable bit set after all the following states are programmed: |
| 110 | * |
| 111 | * - 3DSTATE_PS |
| 112 | * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC |
| 113 | * - 3DSTATE_CONSTANT_PS |
| 114 | * - 3DSTATE_BINDING_TABLE_POINTERS_PS |
| 115 | * - 3DSTATE_SAMPLER_STATE_POINTERS_PS |
| 116 | * - 3DSTATE_CC_STATE_POINTERS |
| 117 | * - 3DSTATE_BLEND_STATE_POINTERS |
| 118 | * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS" |
| 119 | */ |
| 120 | INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL = 1 << 4, |
| 121 | }; |
| 122 | |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 123 | enum intel_cmd_writer_type { |
| 124 | INTEL_CMD_WRITER_BATCH, |
| 125 | INTEL_CMD_WRITER_STATE, |
| 126 | INTEL_CMD_WRITER_INSTRUCTION, |
| 127 | |
| 128 | INTEL_CMD_WRITER_COUNT, |
| 129 | }; |
| 130 | |
Chia-I Wu | a57761b | 2014-10-14 14:27:44 +0800 | [diff] [blame] | 131 | struct intel_cmd_shader_cache { |
| 132 | struct { |
| 133 | const void *shader; |
| 134 | uint32_t kernel_offset; |
| 135 | } *entries; |
| 136 | |
| 137 | XGL_UINT count; |
| 138 | XGL_UINT used; |
Courtney Goeltzenleuchter | d85c1d6 | 2014-08-27 14:04:53 -0600 | [diff] [blame] | 139 | }; |
| 140 | |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 141 | /* |
| 142 | * States bounded to the command buffer. We want to write states directly to |
| 143 | * the command buffer when possible, and reduce this struct. |
| 144 | */ |
| 145 | struct intel_cmd_bind { |
Chia-I Wu | 6032b89 | 2014-10-17 14:47:18 +0800 | [diff] [blame] | 146 | const struct intel_cmd_meta *meta; |
| 147 | |
Chia-I Wu | a57761b | 2014-10-14 14:27:44 +0800 | [diff] [blame] | 148 | struct intel_cmd_shader_cache shader_cache; |
| 149 | |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 150 | struct { |
| 151 | const struct intel_pipeline *graphics; |
| 152 | const struct intel_pipeline *compute; |
| 153 | const struct intel_pipeline_delta *graphics_delta; |
| 154 | const struct intel_pipeline_delta *compute_delta; |
Chia-I Wu | a57761b | 2014-10-14 14:27:44 +0800 | [diff] [blame] | 155 | |
| 156 | uint32_t vs_offset; |
| 157 | uint32_t tcs_offset; |
| 158 | uint32_t tes_offset; |
| 159 | uint32_t gs_offset; |
| 160 | uint32_t fs_offset; |
| 161 | uint32_t cs_offset; |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 162 | } pipeline; |
| 163 | |
Courtney Goeltzenleuchter | d85c1d6 | 2014-08-27 14:04:53 -0600 | [diff] [blame] | 164 | struct { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 165 | const struct intel_dynamic_vp *viewport; |
| 166 | const struct intel_dynamic_rs *raster; |
| 167 | const struct intel_dynamic_cb *blend; |
| 168 | const struct intel_dynamic_ds *ds; |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 169 | } state; |
| 170 | |
| 171 | struct { |
| 172 | const struct intel_dset *graphics; |
| 173 | XGL_UINT graphics_offset; |
| 174 | const struct intel_dset *compute; |
| 175 | XGL_UINT compute_offset; |
| 176 | } dset; |
| 177 | |
| 178 | struct { |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 179 | struct intel_buf_view *graphics; |
| 180 | struct intel_buf_view *compute; |
Chia-I Wu | 9f1722c | 2014-08-25 10:17:58 +0800 | [diff] [blame] | 181 | } dyn_view; |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 182 | |
| 183 | struct { |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 184 | const struct intel_buf *buf[INTEL_MAX_VERTEX_BINDING_COUNT]; |
Chia-I Wu | 2469371 | 2014-11-08 11:54:47 +0800 | [diff] [blame] | 185 | XGL_GPU_SIZE offset[INTEL_MAX_VERTEX_BINDING_COUNT]; |
Chia-I Wu | 3b04af5 | 2014-11-08 10:48:20 +0800 | [diff] [blame] | 186 | } vertex; |
| 187 | |
| 188 | struct { |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 189 | const struct intel_buf *buf; |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 190 | XGL_GPU_SIZE offset; |
| 191 | XGL_INDEX_TYPE type; |
| 192 | } index; |
| 193 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 194 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 195 | struct intel_render_pass *render_pass; |
Chia-I Wu | 48c283d | 2014-08-25 23:13:46 +0800 | [diff] [blame] | 196 | |
Chia-I Wu | 707a29e | 2014-08-27 12:51:47 +0800 | [diff] [blame] | 197 | XGL_UINT draw_count; |
Chia-I Wu | 48c283d | 2014-08-25 23:13:46 +0800 | [diff] [blame] | 198 | uint32_t wa_flags; |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 199 | }; |
Chia-I Wu | 0914213 | 2014-08-11 15:42:55 +0800 | [diff] [blame] | 200 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 201 | struct intel_cmd_writer { |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 202 | XGL_SIZE size; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 203 | struct intel_bo *bo; |
Chia-I Wu | 0f50ba8 | 2014-09-09 10:25:46 +0800 | [diff] [blame] | 204 | void *ptr; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 205 | |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 206 | XGL_SIZE used; |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 207 | |
| 208 | /* for decoding */ |
| 209 | struct intel_cmd_item *items; |
| 210 | XGL_UINT item_alloc; |
| 211 | XGL_UINT item_used; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 212 | }; |
| 213 | |
Chia-I Wu | 730e536 | 2014-08-19 12:15:09 +0800 | [diff] [blame] | 214 | struct intel_cmd { |
| 215 | struct intel_obj obj; |
| 216 | |
| 217 | struct intel_dev *dev; |
Chia-I Wu | 0b78444 | 2014-08-25 22:54:16 +0800 | [diff] [blame] | 218 | struct intel_bo *scratch_bo; |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 219 | int pipeline_select; |
Chia-I Wu | 730e536 | 2014-08-19 12:15:09 +0800 | [diff] [blame] | 220 | |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 221 | struct intel_cmd_reloc *relocs; |
| 222 | XGL_UINT reloc_count; |
| 223 | |
Chia-I Wu | 730e536 | 2014-08-19 12:15:09 +0800 | [diff] [blame] | 224 | XGL_FLAGS flags; |
| 225 | |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 226 | struct intel_cmd_writer writers[INTEL_CMD_WRITER_COUNT]; |
Chia-I Wu | 730e536 | 2014-08-19 12:15:09 +0800 | [diff] [blame] | 227 | |
Chia-I Wu | 343b137 | 2014-08-20 16:39:20 +0800 | [diff] [blame] | 228 | XGL_UINT reloc_used; |
Chia-I Wu | 0496670 | 2014-08-20 15:05:03 +0800 | [diff] [blame] | 229 | XGL_RESULT result; |
Chia-I Wu | b275556 | 2014-08-20 13:38:52 +0800 | [diff] [blame] | 230 | |
| 231 | struct intel_cmd_bind bind; |
Chia-I Wu | 730e536 | 2014-08-19 12:15:09 +0800 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | static inline struct intel_cmd *intel_cmd(XGL_CMD_BUFFER cmd) |
| 235 | { |
| 236 | return (struct intel_cmd *) cmd; |
| 237 | } |
| 238 | |
| 239 | static inline struct intel_cmd *intel_cmd_from_obj(struct intel_obj *obj) |
| 240 | { |
| 241 | return (struct intel_cmd *) obj; |
| 242 | } |
| 243 | |
| 244 | XGL_RESULT intel_cmd_create(struct intel_dev *dev, |
| 245 | const XGL_CMD_BUFFER_CREATE_INFO *info, |
| 246 | struct intel_cmd **cmd_ret); |
| 247 | void intel_cmd_destroy(struct intel_cmd *cmd); |
| 248 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 249 | XGL_RESULT intel_cmd_begin(struct intel_cmd *cmd, const XGL_CMD_BUFFER_BEGIN_INFO* pBeginInfo); |
Chia-I Wu | 730e536 | 2014-08-19 12:15:09 +0800 | [diff] [blame] | 250 | XGL_RESULT intel_cmd_end(struct intel_cmd *cmd); |
| 251 | |
Chia-I Wu | 00b51a8 | 2014-09-09 12:07:37 +0800 | [diff] [blame] | 252 | void intel_cmd_decode(struct intel_cmd *cmd); |
| 253 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 254 | static inline struct intel_bo *intel_cmd_get_batch(const struct intel_cmd *cmd, |
| 255 | XGL_GPU_SIZE *used) |
| 256 | { |
Chia-I Wu | 68f319d | 2014-09-09 09:43:21 +0800 | [diff] [blame] | 257 | const struct intel_cmd_writer *writer = |
| 258 | &cmd->writers[INTEL_CMD_WRITER_BATCH]; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 259 | |
| 260 | if (used) |
Chia-I Wu | 72292b7 | 2014-09-09 10:48:33 +0800 | [diff] [blame] | 261 | *used = writer->used; |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 262 | |
| 263 | return writer->bo; |
| 264 | } |
| 265 | |
Chia-I Wu | 0914213 | 2014-08-11 15:42:55 +0800 | [diff] [blame] | 266 | #endif /* CMD_H */ |