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. |
| 23 | */ |
| 24 | |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 25 | #include "shader.h" |
Chia-I Wu | ed83387 | 2014-08-23 17:00:35 +0800 | [diff] [blame] | 26 | #include "pipeline_priv.h" |
Courtney Goeltzenleuchter | d85c1d6 | 2014-08-27 14:04:53 -0600 | [diff] [blame] | 27 | #include "genhw/genhw.h" |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 28 | #include "genhw/gen_render_3d.xml.h" |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 29 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 30 | struct intel_pipeline_builder { |
| 31 | const struct intel_gpu *gpu; |
| 32 | |
| 33 | XGL_GRAPHICS_PIPELINE_CREATE_INFO graphics; |
| 34 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia; |
| 35 | XGL_PIPELINE_DB_STATE_CREATE_INFO db; |
| 36 | XGL_PIPELINE_CB_STATE cb; |
| 37 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs; |
| 38 | XGL_PIPELINE_TESS_STATE_CREATE_INFO tess; |
| 39 | XGL_PIPELINE_SHADER vs; |
| 40 | XGL_PIPELINE_SHADER tcs; |
| 41 | XGL_PIPELINE_SHADER tes; |
| 42 | XGL_PIPELINE_SHADER gs; |
| 43 | XGL_PIPELINE_SHADER fs; |
| 44 | |
| 45 | XGL_COMPUTE_PIPELINE_CREATE_INFO compute; |
| 46 | XGL_PIPELINE_SHADER cs; |
| 47 | }; |
| 48 | |
| 49 | struct intel_pipeline_builder_create_info { |
| 50 | XGL_STRUCTURE_TYPE struct_type; |
| 51 | XGL_VOID *next; |
| 52 | }; |
| 53 | |
| 54 | static XGL_RESULT pipeline_ia_state(struct intel_pipeline *pipeline, |
| 55 | const XGL_PIPELINE_IA_STATE_CREATE_INFO* ia_state) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 56 | { |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 57 | pipeline->ia_state = *ia_state; |
| 58 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 59 | if (ia_state->provokingVertex == XGL_PROVOKING_VERTEX_FIRST) { |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 60 | pipeline->provoking_vertex_tri = 0; |
| 61 | pipeline->provoking_vertex_trifan = 1; |
| 62 | pipeline->provoking_vertex_line = 0; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 63 | } else { |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 64 | pipeline->provoking_vertex_tri = 2; |
| 65 | pipeline->provoking_vertex_trifan = 2; |
| 66 | pipeline->provoking_vertex_line = 1; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | switch (ia_state->topology) { |
| 70 | case XGL_TOPOLOGY_POINT_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 71 | pipeline->prim_type = GEN6_3DPRIM_POINTLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 72 | break; |
| 73 | case XGL_TOPOLOGY_LINE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 74 | pipeline->prim_type = GEN6_3DPRIM_LINELIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 75 | break; |
| 76 | case XGL_TOPOLOGY_LINE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 77 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 78 | break; |
| 79 | case XGL_TOPOLOGY_TRIANGLE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 80 | pipeline->prim_type = GEN6_3DPRIM_TRILIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 81 | break; |
| 82 | case XGL_TOPOLOGY_TRIANGLE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 83 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 84 | break; |
| 85 | case XGL_TOPOLOGY_RECT_LIST: |
| 86 | /* |
| 87 | * TODO: Rect lists are special in XGL, do we need to do |
| 88 | * something special here? |
| 89 | * XGL Guide: |
| 90 | * The rectangle list is a special geometry primitive type |
| 91 | * that can be used for implementing post-processing techniques |
| 92 | * or efficient copy operations. There are some special limitations |
| 93 | * for rectangle primitives. They cannot be clipped, must |
| 94 | * be axis aligned and cannot have depth gradient. |
| 95 | * Failure to comply with these restrictions results in |
| 96 | * undefined rendering results. |
| 97 | */ |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 98 | pipeline->prim_type = GEN6_3DPRIM_RECTLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 99 | break; |
| 100 | case XGL_TOPOLOGY_QUAD_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 101 | pipeline->prim_type = GEN6_3DPRIM_QUADLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 102 | break; |
| 103 | case XGL_TOPOLOGY_QUAD_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 104 | pipeline->prim_type = GEN6_3DPRIM_QUADSTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 105 | break; |
| 106 | case XGL_TOPOLOGY_LINE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 107 | pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 108 | break; |
| 109 | case XGL_TOPOLOGY_LINE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 110 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 111 | break; |
| 112 | case XGL_TOPOLOGY_TRIANGLE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 113 | pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 114 | break; |
| 115 | case XGL_TOPOLOGY_TRIANGLE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 116 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 117 | break; |
| 118 | case XGL_TOPOLOGY_PATCH: |
| 119 | // TODO: implement something here |
| 120 | break; |
| 121 | default: |
| 122 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 123 | } |
| 124 | |
| 125 | if (ia_state->primitiveRestartEnable) { |
| 126 | pipeline->primitive_restart = true; |
| 127 | pipeline->primitive_restart_index = ia_state->primitiveRestartIndex; |
| 128 | } else { |
| 129 | pipeline->primitive_restart = false; |
| 130 | } |
| 131 | |
| 132 | if (ia_state->disableVertexReuse) { |
| 133 | // TODO: What do we do to disable vertex reuse? |
| 134 | } |
| 135 | |
| 136 | return XGL_SUCCESS; |
| 137 | } |
| 138 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 139 | static XGL_RESULT pipeline_rs_state(struct intel_pipeline *pipeline, |
| 140 | const XGL_PIPELINE_RS_STATE_CREATE_INFO* rs_state) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 141 | { |
| 142 | pipeline->depthClipEnable = rs_state->depthClipEnable; |
| 143 | pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable; |
| 144 | pipeline->pointSize = rs_state->pointSize; |
| 145 | return XGL_SUCCESS; |
| 146 | } |
| 147 | |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 148 | static void pipeline_destroy(struct intel_obj *obj) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 149 | { |
| 150 | struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj); |
| 151 | |
Courtney Goeltzenleuchter | d85c1d6 | 2014-08-27 14:04:53 -0600 | [diff] [blame] | 152 | if (pipeline->active_shaders & SHADER_VERTEX_FLAG) { |
| 153 | icd_free(intel_shader(pipeline->intel_vs.pCode)); |
| 154 | } |
| 155 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
| 156 | icd_free(intel_shader(pipeline->gs.pCode)); |
| 157 | } |
| 158 | if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) { |
| 159 | icd_free(intel_shader(pipeline->intel_fs.pCode)); |
| 160 | } |
| 161 | if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) { |
| 162 | icd_free(intel_shader(pipeline->tess_control.pCode)); |
| 163 | } |
| 164 | if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) { |
| 165 | icd_free(intel_shader(pipeline->tess_eval.pCode)); |
| 166 | } |
| 167 | |
Chia-I Wu | ed83387 | 2014-08-23 17:00:35 +0800 | [diff] [blame] | 168 | if (pipeline->vs_rmap) |
| 169 | intel_rmap_destroy(pipeline->vs_rmap); |
| 170 | if (pipeline->fs_rmap) |
| 171 | intel_rmap_destroy(pipeline->fs_rmap); |
| 172 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 173 | intel_base_destroy(&pipeline->obj.base); |
| 174 | } |
| 175 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 176 | static XGL_RESULT pipeline_shader(struct intel_pipeline *pipeline, |
| 177 | const XGL_PIPELINE_SHADER *info) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 178 | { |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 179 | struct intel_shader *sh = intel_shader(info->shader); |
| 180 | void *kernel; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 181 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 182 | // TODO: process shader object and include in pipeline |
| 183 | // For now that processing is simply a copy so that the app |
| 184 | // can destroy the original shader object after pipeline creation. |
| 185 | kernel = icd_alloc(sh->ir->size, 0, XGL_SYSTEM_ALLOC_INTERNAL_SHADER); |
| 186 | if (!kernel) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 187 | return XGL_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 188 | |
| 189 | switch (info->stage) { |
| 190 | case XGL_SHADER_STAGE_VERTEX: |
| 191 | /* |
| 192 | * TODO: What should we do here? |
| 193 | * shader_state (XGL_PIPELINE_SHADER) contains links |
| 194 | * to application memory in the pLinkConstBufferInfo and |
| 195 | * it's pBufferData pointers. Do we need to bring all that |
| 196 | * into the driver or is it okay to rely on those references |
| 197 | * holding good data. In OpenGL we'd make a driver copy. Not |
| 198 | * as clear for XGL. |
| 199 | * For now, use the app pointers. |
| 200 | */ |
| 201 | pipeline->vs = *info; |
| 202 | pipeline->intel_vs.pCode = kernel; |
| 203 | pipeline->intel_vs.codeSize = sh->ir->size; |
| 204 | pipeline->active_shaders |= SHADER_VERTEX_FLAG; |
| 205 | pipeline->vs_rmap = intel_rmap_create(pipeline->dev, |
| 206 | &info->descriptorSetMapping[0], |
| 207 | &info->dynamicMemoryViewMapping, 0); |
| 208 | if (!pipeline->vs_rmap) { |
| 209 | icd_free(kernel); |
| 210 | return XGL_ERROR_OUT_OF_MEMORY; |
| 211 | } |
| 212 | break; |
| 213 | case XGL_SHADER_STAGE_GEOMETRY: |
| 214 | pipeline->gs.pCode = kernel; |
| 215 | pipeline->gs.codeSize = sh->ir->size; |
| 216 | pipeline->active_shaders |= SHADER_GEOMETRY_FLAG; |
| 217 | break; |
| 218 | case XGL_SHADER_STAGE_FRAGMENT: |
| 219 | pipeline->fs = *info; |
| 220 | pipeline->intel_fs.pCode = kernel; |
| 221 | pipeline->intel_fs.codeSize = sh->ir->size; |
| 222 | pipeline->active_shaders |= SHADER_FRAGMENT_FLAG; |
| 223 | /* assuming one RT; need to parse the shader */ |
| 224 | pipeline->fs_rmap = intel_rmap_create(pipeline->dev, |
| 225 | &info->descriptorSetMapping[0], |
| 226 | &info->dynamicMemoryViewMapping, 1); |
| 227 | if (!pipeline->fs_rmap) { |
| 228 | icd_free(kernel); |
| 229 | return XGL_ERROR_OUT_OF_MEMORY; |
| 230 | } |
| 231 | break; |
| 232 | case XGL_SHADER_STAGE_TESS_CONTROL: |
| 233 | pipeline->tess_control.pCode = kernel; |
| 234 | pipeline->tess_control.codeSize = sh->ir->size; |
| 235 | pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG; |
| 236 | break; |
| 237 | case XGL_SHADER_STAGE_TESS_EVALUATION: |
| 238 | pipeline->tess_eval.pCode = kernel; |
| 239 | pipeline->tess_eval.codeSize = sh->ir->size; |
| 240 | pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG; |
| 241 | break; |
| 242 | case XGL_SHADER_STAGE_COMPUTE: |
| 243 | pipeline->compute.pCode = kernel; |
| 244 | pipeline->compute.codeSize = sh->ir->size; |
| 245 | pipeline->active_shaders |= SHADER_COMPUTE_FLAG; |
| 246 | break; |
| 247 | default: |
| 248 | assert(!"unknown shader stage"); |
| 249 | break; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 250 | } |
| 251 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 252 | return XGL_SUCCESS; |
| 253 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 254 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 255 | static XGL_RESULT builder_validate(const struct intel_pipeline_builder *builder, |
| 256 | const struct intel_pipeline *pipeline) |
| 257 | { |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 258 | /* |
| 259 | * Validate required elements |
| 260 | */ |
| 261 | if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) { |
| 262 | // TODO: Log debug message: Vertex Shader required. |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 263 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Tessalation control and evaluation have to both have a shader defined or |
| 268 | * neither should have a shader defined. |
| 269 | */ |
| 270 | if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) != |
| 271 | ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) { |
| 272 | // 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^] | 273 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) && |
| 277 | (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG | |
| 278 | SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG | |
| 279 | SHADER_FRAGMENT_FLAG))) { |
| 280 | // 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^] | 281 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 285 | * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines. |
| 286 | * Mismatching primitive topology and tessellation fails graphics pipeline creation. |
| 287 | */ |
| 288 | if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) && |
| 289 | (pipeline->ia_state.topology != XGL_TOPOLOGY_PATCH)) { |
| 290 | // TODO: Log debug message: Invalid topology used with tessalation shader. |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 291 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | if ((pipeline->ia_state.topology == XGL_TOPOLOGY_PATCH) && |
| 295 | (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) { |
| 296 | // 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^] | 297 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 298 | } |
| 299 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 300 | return XGL_SUCCESS; |
| 301 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 302 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 303 | static XGL_RESULT builder_build(struct intel_pipeline_builder *builder, |
| 304 | struct intel_pipeline *pipeline) |
| 305 | { |
| 306 | XGL_RESULT ret; |
| 307 | |
| 308 | ret = pipeline_ia_state(pipeline, &builder->ia); |
| 309 | |
| 310 | if (ret == XGL_SUCCESS) |
| 311 | ret = pipeline_rs_state(pipeline, &builder->rs); |
| 312 | |
| 313 | if (ret == XGL_SUCCESS && builder->vs.shader) |
| 314 | ret = pipeline_shader(pipeline, &builder->vs); |
| 315 | if (ret == XGL_SUCCESS && builder->tcs.shader) |
| 316 | ret = pipeline_shader(pipeline, &builder->tcs); |
| 317 | if (ret == XGL_SUCCESS && builder->tes.shader) |
| 318 | ret = pipeline_shader(pipeline, &builder->tes); |
| 319 | if (ret == XGL_SUCCESS && builder->gs.shader) |
| 320 | ret = pipeline_shader(pipeline, &builder->gs); |
| 321 | if (ret == XGL_SUCCESS && builder->fs.shader) |
| 322 | ret = pipeline_shader(pipeline, &builder->fs); |
| 323 | |
| 324 | if (ret == XGL_SUCCESS) { |
| 325 | pipeline->db_format = builder->db.format; |
| 326 | pipeline->cb_state = builder->cb; |
| 327 | pipeline->tess_state = builder->tess; |
| 328 | } |
| 329 | |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | static XGL_RESULT builder_init(struct intel_pipeline_builder *builder, |
| 334 | const struct intel_gpu *gpu, |
| 335 | const struct intel_pipeline_builder_create_info *info) |
| 336 | { |
| 337 | memset(builder, 0, sizeof(*builder)); |
| 338 | |
| 339 | builder->gpu = gpu; |
| 340 | |
| 341 | while (info) { |
| 342 | const void *src = (const void *) info; |
| 343 | XGL_SIZE size; |
| 344 | void *dst; |
| 345 | |
| 346 | switch (info->struct_type) { |
| 347 | case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO: |
| 348 | size = sizeof(builder->graphics); |
| 349 | dst = &builder->graphics; |
| 350 | break; |
| 351 | case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO: |
| 352 | size = sizeof(builder->ia); |
| 353 | dst = &builder->ia; |
| 354 | break; |
| 355 | case XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO: |
| 356 | size = sizeof(builder->db); |
| 357 | dst = &builder->db; |
| 358 | break; |
| 359 | case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO: |
| 360 | size = sizeof(builder->cb); |
| 361 | dst = &builder->cb; |
| 362 | break; |
| 363 | case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO: |
| 364 | size = sizeof(builder->rs); |
| 365 | dst = &builder->rs; |
| 366 | break; |
| 367 | case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO: |
| 368 | size = sizeof(builder->tess); |
| 369 | dst = &builder->tess; |
| 370 | break; |
| 371 | case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO: |
| 372 | { |
| 373 | const XGL_PIPELINE_SHADER *shader = (const XGL_PIPELINE_SHADER *) (info + 1); |
| 374 | |
| 375 | src = (const void *) shader; |
| 376 | size = sizeof(*shader); |
| 377 | |
| 378 | switch (shader->stage) { |
| 379 | case XGL_SHADER_STAGE_VERTEX: |
| 380 | dst = &builder->vs; |
| 381 | break; |
| 382 | case XGL_SHADER_STAGE_TESS_CONTROL: |
| 383 | dst = &builder->tcs; |
| 384 | break; |
| 385 | case XGL_SHADER_STAGE_TESS_EVALUATION: |
| 386 | dst = &builder->tes; |
| 387 | break; |
| 388 | case XGL_SHADER_STAGE_GEOMETRY: |
| 389 | dst = &builder->gs; |
| 390 | break; |
| 391 | case XGL_SHADER_STAGE_FRAGMENT: |
| 392 | dst = &builder->fs; |
| 393 | break; |
| 394 | case XGL_SHADER_STAGE_COMPUTE: |
| 395 | dst = &builder->cs; |
| 396 | break; |
| 397 | default: |
| 398 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | break; |
| 403 | case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO: |
| 404 | size = sizeof(builder->compute); |
| 405 | dst = &builder->compute; |
| 406 | break; |
| 407 | default: |
| 408 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | memcpy(dst, src, size); |
| 413 | |
| 414 | info = info->next; |
| 415 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 416 | |
| 417 | return XGL_SUCCESS; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 418 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 419 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame^] | 420 | static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev, |
| 421 | const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info, |
| 422 | struct intel_pipeline **pipeline_ret) |
| 423 | { |
| 424 | struct intel_pipeline_builder builder; |
| 425 | struct intel_pipeline *pipeline; |
| 426 | XGL_RESULT ret; |
| 427 | |
| 428 | ret = builder_init(&builder, dev->gpu, |
| 429 | (const struct intel_pipeline_builder_create_info *) info); |
| 430 | if (ret != XGL_SUCCESS) |
| 431 | return ret; |
| 432 | |
| 433 | pipeline = (struct intel_pipeline *) |
| 434 | intel_base_create(dev, sizeof(*pipeline), dev->base.dbg, |
| 435 | XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info, 0); |
| 436 | if (!pipeline) |
| 437 | return XGL_ERROR_OUT_OF_MEMORY; |
| 438 | |
| 439 | pipeline->dev = dev; |
| 440 | pipeline->obj.destroy = pipeline_destroy; |
| 441 | pipeline->total_size = 0; |
| 442 | |
| 443 | ret = builder_build(&builder, pipeline); |
| 444 | if (ret == XGL_SUCCESS) |
| 445 | ret = builder_validate(&builder, pipeline); |
| 446 | if (ret != XGL_SUCCESS) { |
| 447 | pipeline_destroy(&pipeline->obj); |
| 448 | return ret; |
| 449 | } |
| 450 | |
| 451 | *pipeline_ret = pipeline; |
| 452 | |
| 453 | return XGL_SUCCESS; |
| 454 | } |
| 455 | |
| 456 | XGL_RESULT XGLAPI intelCreateGraphicsPipeline( |
| 457 | XGL_DEVICE device, |
| 458 | const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo, |
| 459 | XGL_PIPELINE* pPipeline) |
| 460 | { |
| 461 | struct intel_dev *dev = intel_dev(device); |
| 462 | |
| 463 | return graphics_pipeline_create(dev, pCreateInfo, |
| 464 | (struct intel_pipeline **) pPipeline); |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | XGL_RESULT XGLAPI intelCreateComputePipeline( |
| 468 | XGL_DEVICE device, |
| 469 | const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo, |
| 470 | XGL_PIPELINE* pPipeline) |
| 471 | { |
| 472 | return XGL_ERROR_UNAVAILABLE; |
| 473 | } |
| 474 | |
| 475 | XGL_RESULT XGLAPI intelStorePipeline( |
| 476 | XGL_PIPELINE pipeline, |
| 477 | XGL_SIZE* pDataSize, |
| 478 | XGL_VOID* pData) |
| 479 | { |
| 480 | return XGL_ERROR_UNAVAILABLE; |
| 481 | } |
| 482 | |
| 483 | XGL_RESULT XGLAPI intelLoadPipeline( |
| 484 | XGL_DEVICE device, |
| 485 | XGL_SIZE dataSize, |
| 486 | const XGL_VOID* pData, |
| 487 | XGL_PIPELINE* pPipeline) |
| 488 | { |
| 489 | return XGL_ERROR_UNAVAILABLE; |
| 490 | } |
| 491 | |
| 492 | XGL_RESULT XGLAPI intelCreatePipelineDelta( |
| 493 | XGL_DEVICE device, |
| 494 | XGL_PIPELINE p1, |
| 495 | XGL_PIPELINE p2, |
| 496 | XGL_PIPELINE_DELTA* delta) |
| 497 | { |
| 498 | return XGL_ERROR_UNAVAILABLE; |
| 499 | } |