Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [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 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | * Chia-I Wu <olv@lunarg.com> |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 27 | */ |
| 28 | |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 29 | #include "genhw/genhw.h" |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 30 | #include "cmd.h" |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 31 | #include "shader.h" |
Chia-I Wu | ed83387 | 2014-08-23 17:00:35 +0800 | [diff] [blame] | 32 | #include "pipeline_priv.h" |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 33 | |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 34 | static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len) |
| 35 | { |
| 36 | uint32_t *ptr; |
| 37 | |
| 38 | assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES); |
| 39 | ptr = &pipeline->cmds[pipeline->cmd_len]; |
| 40 | pipeline->cmd_len += cmd_len; |
| 41 | return ptr; |
| 42 | } |
| 43 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 44 | static XGL_RESULT pipeline_ia_state(struct intel_pipeline *pipeline, |
| 45 | const XGL_PIPELINE_IA_STATE_CREATE_INFO* ia_state) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 46 | { |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 47 | pipeline->ia_state = *ia_state; |
| 48 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 49 | if (ia_state->provokingVertex == XGL_PROVOKING_VERTEX_FIRST) { |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 50 | pipeline->provoking_vertex_tri = 0; |
| 51 | pipeline->provoking_vertex_trifan = 1; |
| 52 | pipeline->provoking_vertex_line = 0; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 53 | } else { |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 54 | pipeline->provoking_vertex_tri = 2; |
| 55 | pipeline->provoking_vertex_trifan = 2; |
| 56 | pipeline->provoking_vertex_line = 1; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | switch (ia_state->topology) { |
| 60 | case XGL_TOPOLOGY_POINT_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 61 | pipeline->prim_type = GEN6_3DPRIM_POINTLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 62 | break; |
| 63 | case XGL_TOPOLOGY_LINE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 64 | pipeline->prim_type = GEN6_3DPRIM_LINELIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 65 | break; |
| 66 | case XGL_TOPOLOGY_LINE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 67 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 68 | break; |
| 69 | case XGL_TOPOLOGY_TRIANGLE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 70 | pipeline->prim_type = GEN6_3DPRIM_TRILIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 71 | break; |
| 72 | case XGL_TOPOLOGY_TRIANGLE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 73 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 74 | break; |
| 75 | case XGL_TOPOLOGY_RECT_LIST: |
| 76 | /* |
| 77 | * TODO: Rect lists are special in XGL, do we need to do |
| 78 | * something special here? |
| 79 | * XGL Guide: |
| 80 | * The rectangle list is a special geometry primitive type |
| 81 | * that can be used for implementing post-processing techniques |
| 82 | * or efficient copy operations. There are some special limitations |
| 83 | * for rectangle primitives. They cannot be clipped, must |
| 84 | * be axis aligned and cannot have depth gradient. |
| 85 | * Failure to comply with these restrictions results in |
| 86 | * undefined rendering results. |
| 87 | */ |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 88 | pipeline->prim_type = GEN6_3DPRIM_RECTLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 89 | break; |
| 90 | case XGL_TOPOLOGY_QUAD_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 91 | pipeline->prim_type = GEN6_3DPRIM_QUADLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 92 | break; |
| 93 | case XGL_TOPOLOGY_QUAD_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 94 | pipeline->prim_type = GEN6_3DPRIM_QUADSTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 95 | break; |
| 96 | case XGL_TOPOLOGY_LINE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 97 | pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 98 | break; |
| 99 | case XGL_TOPOLOGY_LINE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 100 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 101 | break; |
| 102 | case XGL_TOPOLOGY_TRIANGLE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 103 | pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 104 | break; |
| 105 | case XGL_TOPOLOGY_TRIANGLE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 106 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 107 | break; |
| 108 | case XGL_TOPOLOGY_PATCH: |
| 109 | // TODO: implement something here |
| 110 | break; |
| 111 | default: |
| 112 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 113 | } |
| 114 | |
| 115 | if (ia_state->primitiveRestartEnable) { |
| 116 | pipeline->primitive_restart = true; |
| 117 | pipeline->primitive_restart_index = ia_state->primitiveRestartIndex; |
| 118 | } else { |
| 119 | pipeline->primitive_restart = false; |
| 120 | } |
| 121 | |
| 122 | if (ia_state->disableVertexReuse) { |
| 123 | // TODO: What do we do to disable vertex reuse? |
| 124 | } |
| 125 | |
| 126 | return XGL_SUCCESS; |
| 127 | } |
| 128 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 129 | static XGL_RESULT pipeline_rs_state(struct intel_pipeline *pipeline, |
| 130 | const XGL_PIPELINE_RS_STATE_CREATE_INFO* rs_state) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 131 | { |
| 132 | pipeline->depthClipEnable = rs_state->depthClipEnable; |
| 133 | pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable; |
| 134 | pipeline->pointSize = rs_state->pointSize; |
| 135 | return XGL_SUCCESS; |
| 136 | } |
| 137 | |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 138 | static void pipeline_destroy(struct intel_obj *obj) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 139 | { |
| 140 | struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj); |
| 141 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 142 | pipeline_tear_shaders(pipeline); |
Chia-I Wu | ed83387 | 2014-08-23 17:00:35 +0800 | [diff] [blame] | 143 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 144 | intel_base_destroy(&pipeline->obj.base); |
| 145 | } |
| 146 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 147 | static XGL_RESULT pipeline_validate(struct intel_pipeline *pipeline) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 148 | { |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 149 | /* |
| 150 | * Validate required elements |
| 151 | */ |
| 152 | if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) { |
| 153 | // TODO: Log debug message: Vertex Shader required. |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 154 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Tessalation control and evaluation have to both have a shader defined or |
| 159 | * neither should have a shader defined. |
| 160 | */ |
| 161 | if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) != |
| 162 | ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) { |
| 163 | // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 164 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) && |
| 168 | (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG | |
| 169 | SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG | |
| 170 | SHADER_FRAGMENT_FLAG))) { |
| 171 | // TODO: Log debug message: Can only specify compute shader when doing compute |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 172 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 176 | * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines. |
| 177 | * Mismatching primitive topology and tessellation fails graphics pipeline creation. |
| 178 | */ |
| 179 | if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) && |
| 180 | (pipeline->ia_state.topology != XGL_TOPOLOGY_PATCH)) { |
| 181 | // TODO: Log debug message: Invalid topology used with tessalation shader. |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 182 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | if ((pipeline->ia_state.topology == XGL_TOPOLOGY_PATCH) && |
| 186 | (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) { |
| 187 | // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader. |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 188 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 189 | } |
| 190 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 191 | return XGL_SUCCESS; |
| 192 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 193 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 194 | static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline, |
| 195 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 196 | { |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 197 | const struct intel_gpu *gpu = pipeline->dev->gpu; |
| 198 | const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024; |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 199 | const struct intel_shader *vs = intel_shader(info->vs.shader); |
| 200 | const struct intel_shader *gs = intel_shader(info->gs.shader); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 201 | int vs_entry_size, gs_entry_size; |
| 202 | int vs_size, gs_size; |
| 203 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 204 | INTEL_GPU_ASSERT(gpu, 6, 6); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 205 | |
| 206 | vs_entry_size = ((vs->in_count >= vs->out_count) ? |
| 207 | vs->in_count : vs->out_count); |
| 208 | gs_entry_size = (gs) ? gs->out_count : 0; |
| 209 | |
| 210 | /* in bytes */ |
| 211 | vs_entry_size *= sizeof(float) * 4; |
| 212 | gs_entry_size *= sizeof(float) * 4; |
| 213 | |
| 214 | if (gs) { |
| 215 | vs_size = urb_size / 2; |
| 216 | gs_size = vs_size; |
| 217 | } else { |
| 218 | vs_size = urb_size; |
| 219 | gs_size = 0; |
| 220 | } |
| 221 | |
| 222 | /* 3DSTATE_URB */ |
| 223 | { |
| 224 | const uint8_t cmd_len = 3; |
| 225 | const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | |
| 226 | (cmd_len - 2); |
| 227 | int vs_alloc_size, gs_alloc_size; |
| 228 | int vs_entry_count, gs_entry_count; |
| 229 | uint32_t *dw; |
| 230 | |
| 231 | /* in 1024-bit rows */ |
| 232 | vs_alloc_size = (vs_entry_size + 128 - 1) / 128; |
| 233 | gs_alloc_size = (gs_entry_size + 128 - 1) / 128; |
| 234 | |
| 235 | /* valid range is [1, 5] */ |
| 236 | if (!vs_alloc_size) |
| 237 | vs_alloc_size = 1; |
| 238 | if (!gs_alloc_size) |
| 239 | gs_alloc_size = 1; |
| 240 | assert(vs_alloc_size <= 5 && gs_alloc_size <= 5); |
| 241 | |
| 242 | /* valid range is [24, 256], multiples of 4 */ |
| 243 | vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3; |
| 244 | if (vs_entry_count > 256) |
| 245 | vs_entry_count = 256; |
| 246 | assert(vs_entry_count >= 24); |
| 247 | |
| 248 | /* valid range is [0, 256], multiples of 4 */ |
| 249 | gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3; |
| 250 | if (gs_entry_count > 256) |
| 251 | gs_entry_count = 256; |
| 252 | |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 253 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 254 | |
| 255 | dw[0] = dw0; |
| 256 | dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT | |
| 257 | vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT; |
| 258 | dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT | |
| 259 | (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT; |
| 260 | } |
| 261 | } |
| 262 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 263 | static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline, |
| 264 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 265 | { |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 266 | const struct intel_gpu *gpu = pipeline->dev->gpu; |
| 267 | const int urb_size = ((gpu->gt == 3) ? 512 : |
| 268 | (gpu->gt == 2) ? 256 : 128) * 1024; |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 269 | const struct intel_shader *vs = intel_shader(info->vs.shader); |
| 270 | const struct intel_shader *gs = intel_shader(info->gs.shader); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 271 | /* some space is reserved for PCBs */ |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 272 | int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 273 | int vs_entry_size, gs_entry_size; |
| 274 | int vs_size, gs_size; |
| 275 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 276 | INTEL_GPU_ASSERT(gpu, 7, 7.5); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 277 | |
| 278 | vs_entry_size = ((vs->in_count >= vs->out_count) ? |
| 279 | vs->in_count : vs->out_count); |
| 280 | gs_entry_size = (gs) ? gs->out_count : 0; |
| 281 | |
| 282 | /* in bytes */ |
| 283 | vs_entry_size *= sizeof(float) * 4; |
| 284 | gs_entry_size *= sizeof(float) * 4; |
| 285 | |
| 286 | if (gs) { |
| 287 | vs_size = (urb_size - urb_offset) / 2; |
| 288 | gs_size = vs_size; |
| 289 | } else { |
| 290 | vs_size = urb_size - urb_offset; |
| 291 | gs_size = 0; |
| 292 | } |
| 293 | |
| 294 | /* 3DSTATE_URB_* */ |
| 295 | { |
| 296 | const uint8_t cmd_len = 2; |
| 297 | int vs_alloc_size, gs_alloc_size; |
| 298 | int vs_entry_count, gs_entry_count; |
| 299 | uint32_t *dw; |
| 300 | |
| 301 | /* in 512-bit rows */ |
| 302 | vs_alloc_size = (vs_entry_size + 64 - 1) / 64; |
| 303 | gs_alloc_size = (gs_entry_size + 64 - 1) / 64; |
| 304 | |
| 305 | if (!vs_alloc_size) |
| 306 | vs_alloc_size = 1; |
| 307 | if (!gs_alloc_size) |
| 308 | gs_alloc_size = 1; |
| 309 | |
| 310 | /* avoid performance decrease due to banking */ |
| 311 | if (vs_alloc_size == 5) |
| 312 | vs_alloc_size = 6; |
| 313 | |
| 314 | /* in multiples of 8 */ |
| 315 | vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7; |
| 316 | assert(vs_entry_count >= 32); |
| 317 | |
| 318 | gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7; |
| 319 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 320 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) { |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 321 | const int max_vs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 322 | (gpu->gt >= 2) ? 1664 : 640; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 323 | const int max_gs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 324 | (gpu->gt >= 2) ? 640 : 256; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 325 | if (vs_entry_count >= max_vs_entry_count) |
| 326 | vs_entry_count = max_vs_entry_count; |
| 327 | if (gs_entry_count >= max_gs_entry_count) |
| 328 | gs_entry_count = max_gs_entry_count; |
| 329 | } else { |
| 330 | const int max_vs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 331 | (gpu->gt == 2) ? 704 : 512; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 332 | const int max_gs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 333 | (gpu->gt == 2) ? 320 : 192; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 334 | if (vs_entry_count >= max_vs_entry_count) |
| 335 | vs_entry_count = max_vs_entry_count; |
| 336 | if (gs_entry_count >= max_gs_entry_count) |
| 337 | gs_entry_count = max_gs_entry_count; |
| 338 | } |
| 339 | |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 340 | dw = pipeline_cmd_ptr(pipeline, cmd_len*4); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 341 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2); |
| 342 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT | |
| 343 | (vs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT | |
| 344 | vs_entry_count; |
| 345 | |
| 346 | dw += 2; |
| 347 | if (gs_size) |
| 348 | urb_offset += vs_size; |
| 349 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2); |
| 350 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT | |
| 351 | (gs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT | |
| 352 | gs_entry_count; |
| 353 | |
| 354 | dw += 2; |
| 355 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2); |
| 356 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT; |
| 357 | |
| 358 | dw += 2; |
| 359 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2); |
| 360 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT; |
| 361 | } |
| 362 | } |
| 363 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 364 | static void pipeline_build_push_const_alloc_gen7(struct intel_pipeline *pipeline, |
| 365 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 366 | { |
| 367 | const uint8_t cmd_len = 2; |
| 368 | uint32_t offset = 0; |
| 369 | uint32_t size = 8192; |
| 370 | uint32_t *dw; |
| 371 | int end; |
| 372 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 373 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 374 | |
| 375 | /* |
| 376 | * From the Ivy Bridge PRM, volume 2 part 1, page 68: |
| 377 | * |
| 378 | * "(A table that says the maximum size of each constant buffer is |
| 379 | * 16KB") |
| 380 | * |
| 381 | * From the Ivy Bridge PRM, volume 2 part 1, page 115: |
| 382 | * |
| 383 | * "The sum of the Constant Buffer Offset and the Constant Buffer Size |
| 384 | * may not exceed the maximum value of the Constant Buffer Size." |
| 385 | * |
| 386 | * Thus, the valid range of buffer end is [0KB, 16KB]. |
| 387 | */ |
| 388 | end = (offset + size) / 1024; |
| 389 | if (end > 16) { |
| 390 | assert(!"invalid constant buffer end"); |
| 391 | end = 16; |
| 392 | } |
| 393 | |
| 394 | /* the valid range of buffer offset is [0KB, 15KB] */ |
| 395 | offset = (offset + 1023) / 1024; |
| 396 | if (offset > 15) { |
| 397 | assert(!"invalid constant buffer offset"); |
| 398 | offset = 15; |
| 399 | } |
| 400 | |
| 401 | if (offset > end) { |
| 402 | assert(!size); |
| 403 | offset = end; |
| 404 | } |
| 405 | |
| 406 | /* the valid range of buffer size is [0KB, 15KB] */ |
| 407 | size = end - offset; |
| 408 | if (size > 15) { |
| 409 | assert(!"invalid constant buffer size"); |
| 410 | size = 15; |
| 411 | } |
| 412 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 413 | dw = pipeline_cmd_ptr(pipeline, cmd_len * 5); |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 414 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2); |
| 415 | dw[1] = offset << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 416 | size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 417 | |
| 418 | dw += 2; |
| 419 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2); |
| 420 | dw[1] = size << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 421 | size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 422 | |
| 423 | dw += 2; |
| 424 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2); |
| 425 | dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 426 | 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 427 | |
| 428 | dw += 2; |
| 429 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2); |
| 430 | dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 431 | 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 432 | |
| 433 | dw += 2; |
| 434 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2); |
| 435 | dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 436 | 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 437 | |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 438 | // gen7_wa_pipe_control_cs_stall(p, true, true); |
| 439 | // looks equivalent to: gen6_wa_wm_multisample_flush - this does more |
| 440 | // than the documentation seems to imply |
| 441 | } |
| 442 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 443 | static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline, |
| 444 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 445 | { |
| 446 | const uint8_t cmd_len = 3; |
| 447 | const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | |
| 448 | (cmd_len - 2); |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 449 | const struct intel_shader *vs = intel_shader(info->vs.shader); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 450 | int comps[4] = { GEN6_VFCOMP_NOSTORE, GEN6_VFCOMP_NOSTORE, |
| 451 | GEN6_VFCOMP_NOSTORE, GEN6_VFCOMP_NOSTORE }; |
| 452 | uint32_t *dw; |
| 453 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 454 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 455 | |
| 456 | if (!(vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))) |
| 457 | return; |
| 458 | |
| 459 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
| 460 | dw[0] = dw0; |
| 461 | dw++; |
| 462 | |
| 463 | comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ? |
| 464 | GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0; |
| 465 | if (vs->uses & INTEL_SHADER_USE_IID) |
| 466 | comps[1] = GEN6_VFCOMP_STORE_IID; |
| 467 | |
| 468 | /* VERTEX_ELEMENT_STATE */ |
| 469 | dw[0] = GEN6_VE_STATE_DW0_VALID; |
| 470 | dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT | |
| 471 | comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT | |
| 472 | comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT | |
| 473 | comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT; |
| 474 | } |
| 475 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 476 | static void pipeline_build_gs(struct intel_pipeline *pipeline, |
| 477 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 478 | { |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 479 | // gen7_emit_3DSTATE_GS done by cmd_pipeline |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 480 | } |
| 481 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 482 | static void pipeline_build_hs(struct intel_pipeline *pipeline, |
| 483 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 484 | { |
| 485 | const uint8_t cmd_len = 7; |
| 486 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2); |
| 487 | uint32_t *dw; |
| 488 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 489 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 490 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 491 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 492 | dw[0] = dw0; |
| 493 | dw[1] = 0; |
| 494 | dw[2] = 0; |
| 495 | dw[3] = 0; |
| 496 | dw[4] = 0; |
| 497 | dw[5] = 0; |
| 498 | dw[6] = 0; |
| 499 | } |
| 500 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 501 | static void pipeline_build_te(struct intel_pipeline *pipeline, |
| 502 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 503 | { |
| 504 | const uint8_t cmd_len = 4; |
| 505 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2); |
| 506 | uint32_t *dw; |
| 507 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 508 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 509 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 510 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 511 | dw[0] = dw0; |
| 512 | dw[1] = 0; |
| 513 | dw[2] = 0; |
| 514 | dw[3] = 0; |
| 515 | } |
| 516 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 517 | static void pipeline_build_ds(struct intel_pipeline *pipeline, |
| 518 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 519 | { |
| 520 | const uint8_t cmd_len = 6; |
| 521 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2); |
| 522 | uint32_t *dw; |
| 523 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 524 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 525 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 526 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 527 | dw[0] = dw0; |
| 528 | dw[1] = 0; |
| 529 | dw[2] = 0; |
| 530 | dw[3] = 0; |
| 531 | dw[4] = 0; |
| 532 | dw[5] = 0; |
| 533 | } |
| 534 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 535 | static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline, |
| 536 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 537 | { |
| 538 | XGL_RESULT ret; |
| 539 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 540 | ret = pipeline_build_shaders(pipeline, info); |
| 541 | if (ret != XGL_SUCCESS) |
| 542 | return ret; |
| 543 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 544 | pipeline_build_vertex_elements(pipeline, info); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 545 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 546 | if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 547 | pipeline_build_urb_alloc_gen7(pipeline, info); |
| 548 | pipeline_build_push_const_alloc_gen7(pipeline, info); |
| 549 | pipeline_build_gs(pipeline, info); |
| 550 | pipeline_build_hs(pipeline, info); |
| 551 | pipeline_build_te(pipeline, info); |
| 552 | pipeline_build_ds(pipeline, info); |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 553 | |
| 554 | pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE | |
| 555 | INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL | |
| 556 | INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE | |
| 557 | INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL | |
| 558 | INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 559 | } else { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 560 | pipeline_build_urb_alloc_gen6(pipeline, info); |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 561 | |
| 562 | pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE | |
| 563 | INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 564 | } |
| 565 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 566 | ret = pipeline_ia_state(pipeline, &info->ia); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 567 | |
| 568 | if (ret == XGL_SUCCESS) |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 569 | ret = pipeline_rs_state(pipeline, &info->rs); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 570 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 571 | if (ret == XGL_SUCCESS) { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 572 | pipeline->db_format = info->db.format; |
| 573 | pipeline->cb_state = info->cb; |
| 574 | pipeline->tess_state = info->tess; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | return ret; |
| 578 | } |
| 579 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 580 | struct intel_pipeline_create_info_header { |
| 581 | XGL_STRUCTURE_TYPE struct_type; |
| 582 | const struct intel_pipeline_create_info_header *next; |
| 583 | }; |
| 584 | |
| 585 | static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 586 | const struct intel_pipeline_create_info_header *header) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 587 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 588 | memset(info, 0, sizeof(*info)); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 589 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 590 | while (header) { |
| 591 | const void *src = (const void *) header; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 592 | XGL_SIZE size; |
| 593 | void *dst; |
| 594 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 595 | switch (header->struct_type) { |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 596 | case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 597 | size = sizeof(info->graphics); |
| 598 | dst = &info->graphics; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 599 | break; |
| 600 | case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 601 | size = sizeof(info->ia); |
| 602 | dst = &info->ia; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 603 | break; |
| 604 | case XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 605 | size = sizeof(info->db); |
| 606 | dst = &info->db; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 607 | break; |
| 608 | case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 609 | size = sizeof(info->cb); |
| 610 | dst = &info->cb; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 611 | break; |
| 612 | case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 613 | size = sizeof(info->rs); |
| 614 | dst = &info->rs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 615 | break; |
| 616 | case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 617 | size = sizeof(info->tess); |
| 618 | dst = &info->tess; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 619 | break; |
| 620 | case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO: |
| 621 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 622 | const XGL_PIPELINE_SHADER *shader = |
| 623 | (const XGL_PIPELINE_SHADER *) (header + 1); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 624 | |
| 625 | src = (const void *) shader; |
| 626 | size = sizeof(*shader); |
| 627 | |
| 628 | switch (shader->stage) { |
| 629 | case XGL_SHADER_STAGE_VERTEX: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 630 | dst = &info->vs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 631 | break; |
| 632 | case XGL_SHADER_STAGE_TESS_CONTROL: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 633 | dst = &info->tcs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 634 | break; |
| 635 | case XGL_SHADER_STAGE_TESS_EVALUATION: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 636 | dst = &info->tes; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 637 | break; |
| 638 | case XGL_SHADER_STAGE_GEOMETRY: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 639 | dst = &info->gs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 640 | break; |
| 641 | case XGL_SHADER_STAGE_FRAGMENT: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 642 | dst = &info->fs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 643 | break; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 644 | default: |
| 645 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 646 | break; |
| 647 | } |
| 648 | } |
| 649 | break; |
| 650 | case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 651 | size = sizeof(info->compute); |
| 652 | dst = &info->compute; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 653 | break; |
| 654 | default: |
| 655 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 656 | break; |
| 657 | } |
| 658 | |
| 659 | memcpy(dst, src, size); |
| 660 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 661 | header = header->next; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 662 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 663 | |
| 664 | return XGL_SUCCESS; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 665 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 666 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 667 | static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 668 | const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_, |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 669 | struct intel_pipeline **pipeline_ret) |
| 670 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 671 | struct intel_pipeline_create_info info; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 672 | struct intel_pipeline *pipeline; |
| 673 | XGL_RESULT ret; |
| 674 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 675 | ret = pipeline_create_info_init(&info, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 676 | (const struct intel_pipeline_create_info_header *) info_); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 677 | if (ret != XGL_SUCCESS) |
| 678 | return ret; |
| 679 | |
| 680 | pipeline = (struct intel_pipeline *) |
| 681 | intel_base_create(dev, sizeof(*pipeline), dev->base.dbg, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 682 | XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 683 | if (!pipeline) |
| 684 | return XGL_ERROR_OUT_OF_MEMORY; |
| 685 | |
| 686 | pipeline->dev = dev; |
| 687 | pipeline->obj.destroy = pipeline_destroy; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 688 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 689 | ret = pipeline_build_all(pipeline, &info); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 690 | if (ret == XGL_SUCCESS) |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 691 | ret = pipeline_validate(pipeline); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 692 | if (ret != XGL_SUCCESS) { |
| 693 | pipeline_destroy(&pipeline->obj); |
| 694 | return ret; |
| 695 | } |
| 696 | |
| 697 | *pipeline_ret = pipeline; |
| 698 | |
| 699 | return XGL_SUCCESS; |
| 700 | } |
| 701 | |
| 702 | XGL_RESULT XGLAPI intelCreateGraphicsPipeline( |
| 703 | XGL_DEVICE device, |
| 704 | const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo, |
| 705 | XGL_PIPELINE* pPipeline) |
| 706 | { |
| 707 | struct intel_dev *dev = intel_dev(device); |
| 708 | |
| 709 | return graphics_pipeline_create(dev, pCreateInfo, |
| 710 | (struct intel_pipeline **) pPipeline); |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | XGL_RESULT XGLAPI intelCreateComputePipeline( |
| 714 | XGL_DEVICE device, |
| 715 | const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo, |
| 716 | XGL_PIPELINE* pPipeline) |
| 717 | { |
| 718 | return XGL_ERROR_UNAVAILABLE; |
| 719 | } |
| 720 | |
| 721 | XGL_RESULT XGLAPI intelStorePipeline( |
| 722 | XGL_PIPELINE pipeline, |
| 723 | XGL_SIZE* pDataSize, |
| 724 | XGL_VOID* pData) |
| 725 | { |
| 726 | return XGL_ERROR_UNAVAILABLE; |
| 727 | } |
| 728 | |
| 729 | XGL_RESULT XGLAPI intelLoadPipeline( |
| 730 | XGL_DEVICE device, |
| 731 | XGL_SIZE dataSize, |
| 732 | const XGL_VOID* pData, |
| 733 | XGL_PIPELINE* pPipeline) |
| 734 | { |
| 735 | return XGL_ERROR_UNAVAILABLE; |
| 736 | } |
| 737 | |
| 738 | XGL_RESULT XGLAPI intelCreatePipelineDelta( |
| 739 | XGL_DEVICE device, |
| 740 | XGL_PIPELINE p1, |
| 741 | XGL_PIPELINE p2, |
| 742 | XGL_PIPELINE_DELTA* delta) |
| 743 | { |
| 744 | return XGL_ERROR_UNAVAILABLE; |
| 745 | } |