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