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