Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | * Chia-I Wu <olv@lunarg.com> |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 27 | */ |
| 28 | |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 29 | #include "genhw/genhw.h" |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 30 | #include "compiler/pipeline/pipeline_compiler_interface.h" |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 31 | #include "cmd.h" |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 32 | #include "format.h" |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 33 | #include "shader.h" |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 34 | #include "pipeline.h" |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 35 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 36 | static int translate_blend_func(XGL_BLEND_FUNC func) |
| 37 | { |
| 38 | switch (func) { |
| 39 | case XGL_BLEND_FUNC_ADD: return GEN6_BLENDFUNCTION_ADD; |
| 40 | case XGL_BLEND_FUNC_SUBTRACT: return GEN6_BLENDFUNCTION_SUBTRACT; |
| 41 | case XGL_BLEND_FUNC_REVERSE_SUBTRACT: return GEN6_BLENDFUNCTION_REVERSE_SUBTRACT; |
| 42 | case XGL_BLEND_FUNC_MIN: return GEN6_BLENDFUNCTION_MIN; |
| 43 | case XGL_BLEND_FUNC_MAX: return GEN6_BLENDFUNCTION_MAX; |
| 44 | default: |
| 45 | assert(!"unknown blend func"); |
| 46 | return GEN6_BLENDFUNCTION_ADD; |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | static int translate_blend(XGL_BLEND blend) |
| 51 | { |
| 52 | switch (blend) { |
| 53 | case XGL_BLEND_ZERO: return GEN6_BLENDFACTOR_ZERO; |
| 54 | case XGL_BLEND_ONE: return GEN6_BLENDFACTOR_ONE; |
| 55 | case XGL_BLEND_SRC_COLOR: return GEN6_BLENDFACTOR_SRC_COLOR; |
| 56 | case XGL_BLEND_ONE_MINUS_SRC_COLOR: return GEN6_BLENDFACTOR_INV_SRC_COLOR; |
| 57 | case XGL_BLEND_DEST_COLOR: return GEN6_BLENDFACTOR_DST_COLOR; |
| 58 | case XGL_BLEND_ONE_MINUS_DEST_COLOR: return GEN6_BLENDFACTOR_INV_DST_COLOR; |
| 59 | case XGL_BLEND_SRC_ALPHA: return GEN6_BLENDFACTOR_SRC_ALPHA; |
| 60 | case XGL_BLEND_ONE_MINUS_SRC_ALPHA: return GEN6_BLENDFACTOR_INV_SRC_ALPHA; |
| 61 | case XGL_BLEND_DEST_ALPHA: return GEN6_BLENDFACTOR_DST_ALPHA; |
| 62 | case XGL_BLEND_ONE_MINUS_DEST_ALPHA: return GEN6_BLENDFACTOR_INV_DST_ALPHA; |
| 63 | case XGL_BLEND_CONSTANT_COLOR: return GEN6_BLENDFACTOR_CONST_COLOR; |
| 64 | case XGL_BLEND_ONE_MINUS_CONSTANT_COLOR: return GEN6_BLENDFACTOR_INV_CONST_COLOR; |
| 65 | case XGL_BLEND_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_CONST_ALPHA; |
| 66 | case XGL_BLEND_ONE_MINUS_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_INV_CONST_ALPHA; |
| 67 | case XGL_BLEND_SRC_ALPHA_SATURATE: return GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE; |
| 68 | case XGL_BLEND_SRC1_COLOR: return GEN6_BLENDFACTOR_SRC1_COLOR; |
| 69 | case XGL_BLEND_ONE_MINUS_SRC1_COLOR: return GEN6_BLENDFACTOR_INV_SRC1_COLOR; |
| 70 | case XGL_BLEND_SRC1_ALPHA: return GEN6_BLENDFACTOR_SRC1_ALPHA; |
| 71 | case XGL_BLEND_ONE_MINUS_SRC1_ALPHA: return GEN6_BLENDFACTOR_INV_SRC1_ALPHA; |
| 72 | default: |
| 73 | assert(!"unknown blend factor"); |
| 74 | return GEN6_BLENDFACTOR_ONE; |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | static int translate_compare_func(XGL_COMPARE_FUNC func) |
| 79 | { |
| 80 | switch (func) { |
| 81 | case XGL_COMPARE_NEVER: return GEN6_COMPAREFUNCTION_NEVER; |
| 82 | case XGL_COMPARE_LESS: return GEN6_COMPAREFUNCTION_LESS; |
| 83 | case XGL_COMPARE_EQUAL: return GEN6_COMPAREFUNCTION_EQUAL; |
| 84 | case XGL_COMPARE_LESS_EQUAL: return GEN6_COMPAREFUNCTION_LEQUAL; |
| 85 | case XGL_COMPARE_GREATER: return GEN6_COMPAREFUNCTION_GREATER; |
| 86 | case XGL_COMPARE_NOT_EQUAL: return GEN6_COMPAREFUNCTION_NOTEQUAL; |
| 87 | case XGL_COMPARE_GREATER_EQUAL: return GEN6_COMPAREFUNCTION_GEQUAL; |
| 88 | case XGL_COMPARE_ALWAYS: return GEN6_COMPAREFUNCTION_ALWAYS; |
| 89 | default: |
| 90 | assert(!"unknown compare_func"); |
| 91 | return GEN6_COMPAREFUNCTION_NEVER; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | static int translate_stencil_op(XGL_STENCIL_OP op) |
| 96 | { |
| 97 | switch (op) { |
| 98 | case XGL_STENCIL_OP_KEEP: return GEN6_STENCILOP_KEEP; |
| 99 | case XGL_STENCIL_OP_ZERO: return GEN6_STENCILOP_ZERO; |
| 100 | case XGL_STENCIL_OP_REPLACE: return GEN6_STENCILOP_REPLACE; |
| 101 | case XGL_STENCIL_OP_INC_CLAMP: return GEN6_STENCILOP_INCRSAT; |
| 102 | case XGL_STENCIL_OP_DEC_CLAMP: return GEN6_STENCILOP_DECRSAT; |
| 103 | case XGL_STENCIL_OP_INVERT: return GEN6_STENCILOP_INVERT; |
| 104 | case XGL_STENCIL_OP_INC_WRAP: return GEN6_STENCILOP_INCR; |
| 105 | case XGL_STENCIL_OP_DEC_WRAP: return GEN6_STENCILOP_DECR; |
| 106 | default: |
| 107 | assert(!"unknown stencil op"); |
| 108 | return GEN6_STENCILOP_KEEP; |
| 109 | } |
| 110 | } |
| 111 | |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 112 | struct intel_pipeline_create_info { |
| 113 | XGL_GRAPHICS_PIPELINE_CREATE_INFO graphics; |
| 114 | XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi; |
| 115 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 116 | XGL_PIPELINE_DS_STATE_CREATE_INFO db; |
| 117 | XGL_PIPELINE_CB_STATE_CREATE_INFO cb; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 118 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs; |
| 119 | XGL_PIPELINE_TESS_STATE_CREATE_INFO tess; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 120 | XGL_PIPELINE_MS_STATE_CREATE_INFO ms; |
| 121 | XGL_PIPELINE_VP_STATE_CREATE_INFO vp; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 122 | XGL_PIPELINE_SHADER vs; |
| 123 | XGL_PIPELINE_SHADER tcs; |
| 124 | XGL_PIPELINE_SHADER tes; |
| 125 | XGL_PIPELINE_SHADER gs; |
| 126 | XGL_PIPELINE_SHADER fs; |
| 127 | |
| 128 | XGL_COMPUTE_PIPELINE_CREATE_INFO compute; |
| 129 | }; |
| 130 | struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev, |
| 131 | enum intel_dev_meta_shader id) |
| 132 | { |
| 133 | struct intel_pipeline_shader *sh; |
| 134 | XGL_RESULT ret; |
| 135 | |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame^] | 136 | sh = intel_alloc(dev, sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 137 | if (!sh) |
| 138 | return NULL; |
| 139 | memset(sh, 0, sizeof(*sh)); |
| 140 | |
| 141 | ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id); |
| 142 | if (ret != XGL_SUCCESS) { |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame^] | 143 | intel_free(dev, sh); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 144 | return NULL; |
| 145 | } |
| 146 | |
| 147 | switch (id) { |
| 148 | case INTEL_DEV_META_VS_FILL_MEM: |
| 149 | case INTEL_DEV_META_VS_COPY_MEM: |
| 150 | case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED: |
| 151 | sh->max_threads = intel_gpu_get_max_threads(dev->gpu, |
| 152 | XGL_SHADER_STAGE_VERTEX); |
| 153 | break; |
| 154 | default: |
| 155 | sh->max_threads = intel_gpu_get_max_threads(dev->gpu, |
| 156 | XGL_SHADER_STAGE_FRAGMENT); |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | return sh; |
| 161 | } |
| 162 | |
| 163 | void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh) |
| 164 | { |
| 165 | intel_pipeline_shader_cleanup(sh); |
| 166 | icd_free(sh); |
| 167 | } |
| 168 | |
| 169 | static XGL_RESULT pipeline_build_shader(struct intel_pipeline *pipeline, |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 170 | const struct intel_desc_layout *layout, |
| 171 | const XGL_PIPELINE_SHADER *sh_info, |
| 172 | struct intel_pipeline_shader *sh) |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 173 | { |
| 174 | XGL_RESULT ret; |
| 175 | |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 176 | ret = intel_pipeline_shader_compile(sh, |
| 177 | pipeline->dev->gpu, layout, sh_info); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 178 | if (ret != XGL_SUCCESS) |
| 179 | return ret; |
| 180 | |
| 181 | sh->max_threads = |
| 182 | intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage); |
| 183 | |
| 184 | /* 1KB aligned */ |
| 185 | sh->scratch_offset = u_align(pipeline->scratch_size, 1024); |
| 186 | pipeline->scratch_size = sh->scratch_offset + |
| 187 | sh->per_thread_scratch_size * sh->max_threads; |
| 188 | |
| 189 | pipeline->active_shaders |= 1 << sh_info->stage; |
| 190 | |
| 191 | return XGL_SUCCESS; |
| 192 | } |
| 193 | |
| 194 | static XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline, |
| 195 | const struct intel_pipeline_create_info *info) |
| 196 | { |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 197 | const struct intel_desc_layout *layout = |
| 198 | intel_desc_layout(info->graphics.lastSetLayout); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 199 | XGL_RESULT ret = XGL_SUCCESS; |
| 200 | |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 201 | if (ret == XGL_SUCCESS && info->vs.shader) { |
| 202 | ret = pipeline_build_shader(pipeline, layout, |
| 203 | &info->vs, &pipeline->vs); |
| 204 | } |
| 205 | if (ret == XGL_SUCCESS && info->tcs.shader) { |
| 206 | ret = pipeline_build_shader(pipeline, layout, |
| 207 | &info->tcs,&pipeline->tcs); |
| 208 | } |
| 209 | if (ret == XGL_SUCCESS && info->tes.shader) { |
| 210 | ret = pipeline_build_shader(pipeline, layout, |
| 211 | &info->tes,&pipeline->tes); |
| 212 | } |
| 213 | if (ret == XGL_SUCCESS && info->gs.shader) { |
| 214 | ret = pipeline_build_shader(pipeline, layout, |
| 215 | &info->gs, &pipeline->gs); |
| 216 | } |
| 217 | if (ret == XGL_SUCCESS && info->fs.shader) { |
| 218 | ret = pipeline_build_shader(pipeline, layout, |
| 219 | &info->fs, &pipeline->fs); |
| 220 | } |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 221 | |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 222 | if (ret == XGL_SUCCESS && info->compute.cs.shader) { |
| 223 | layout = intel_desc_layout(info->compute.lastSetLayout); |
| 224 | ret = pipeline_build_shader(pipeline, layout, |
| 225 | &info->compute.cs, &pipeline->cs); |
| 226 | } |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 227 | |
| 228 | return ret; |
| 229 | } |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 230 | static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len) |
| 231 | { |
| 232 | uint32_t *ptr; |
| 233 | |
| 234 | assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES); |
| 235 | ptr = &pipeline->cmds[pipeline->cmd_len]; |
| 236 | pipeline->cmd_len += cmd_len; |
| 237 | return ptr; |
| 238 | } |
| 239 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 240 | static XGL_RESULT pipeline_build_ia(struct intel_pipeline *pipeline, |
| 241 | const struct intel_pipeline_create_info* info) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 242 | { |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 243 | pipeline->topology = info->ia.topology; |
| 244 | pipeline->disable_vs_cache = info->ia.disableVertexReuse; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 245 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 246 | switch (info->ia.topology) { |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 247 | case XGL_TOPOLOGY_POINT_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 248 | pipeline->prim_type = GEN6_3DPRIM_POINTLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 249 | break; |
| 250 | case XGL_TOPOLOGY_LINE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 251 | pipeline->prim_type = GEN6_3DPRIM_LINELIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 252 | break; |
| 253 | case XGL_TOPOLOGY_LINE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 254 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 255 | break; |
| 256 | case XGL_TOPOLOGY_TRIANGLE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 257 | pipeline->prim_type = GEN6_3DPRIM_TRILIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 258 | break; |
| 259 | case XGL_TOPOLOGY_TRIANGLE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 260 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 261 | break; |
| 262 | case XGL_TOPOLOGY_RECT_LIST: |
| 263 | /* |
| 264 | * TODO: Rect lists are special in XGL, do we need to do |
| 265 | * something special here? |
| 266 | * XGL Guide: |
| 267 | * The rectangle list is a special geometry primitive type |
| 268 | * that can be used for implementing post-processing techniques |
| 269 | * or efficient copy operations. There are some special limitations |
| 270 | * for rectangle primitives. They cannot be clipped, must |
| 271 | * be axis aligned and cannot have depth gradient. |
| 272 | * Failure to comply with these restrictions results in |
| 273 | * undefined rendering results. |
| 274 | */ |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 275 | pipeline->prim_type = GEN6_3DPRIM_RECTLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 276 | break; |
| 277 | case XGL_TOPOLOGY_QUAD_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 278 | pipeline->prim_type = GEN6_3DPRIM_QUADLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 279 | break; |
| 280 | case XGL_TOPOLOGY_QUAD_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 281 | pipeline->prim_type = GEN6_3DPRIM_QUADSTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 282 | break; |
| 283 | case XGL_TOPOLOGY_LINE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 284 | pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 285 | break; |
| 286 | case XGL_TOPOLOGY_LINE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 287 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 288 | break; |
| 289 | case XGL_TOPOLOGY_TRIANGLE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 290 | pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 291 | break; |
| 292 | case XGL_TOPOLOGY_TRIANGLE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 293 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 294 | break; |
| 295 | case XGL_TOPOLOGY_PATCH: |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 296 | if (!info->tess.patchControlPoints || |
| 297 | info->tess.patchControlPoints > 32) |
| 298 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 299 | pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 + |
| 300 | info->tess.patchControlPoints - 1; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 301 | break; |
| 302 | default: |
| 303 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 304 | } |
| 305 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 306 | if (info->ia.primitiveRestartEnable) { |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 307 | pipeline->primitive_restart = true; |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 308 | pipeline->primitive_restart_index = info->ia.primitiveRestartIndex; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 309 | } else { |
| 310 | pipeline->primitive_restart = false; |
| 311 | } |
| 312 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 313 | return XGL_SUCCESS; |
| 314 | } |
| 315 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 316 | static XGL_RESULT pipeline_rs_state(struct intel_pipeline *pipeline, |
| 317 | const XGL_PIPELINE_RS_STATE_CREATE_INFO* rs_state) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 318 | { |
| 319 | pipeline->depthClipEnable = rs_state->depthClipEnable; |
| 320 | pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 321 | |
| 322 | if (rs_state->provokingVertex == XGL_PROVOKING_VERTEX_FIRST) { |
| 323 | pipeline->provoking_vertex_tri = 0; |
| 324 | pipeline->provoking_vertex_trifan = 1; |
| 325 | pipeline->provoking_vertex_line = 0; |
| 326 | } else { |
| 327 | pipeline->provoking_vertex_tri = 2; |
| 328 | pipeline->provoking_vertex_trifan = 2; |
| 329 | pipeline->provoking_vertex_line = 1; |
| 330 | } |
| 331 | |
| 332 | switch (rs_state->fillMode) { |
| 333 | case XGL_FILL_POINTS: |
| 334 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT | |
| 335 | GEN7_SF_DW1_BACKFACE_POINT; |
| 336 | break; |
| 337 | case XGL_FILL_WIREFRAME: |
| 338 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME | |
| 339 | GEN7_SF_DW1_BACKFACE_WIREFRAME; |
| 340 | break; |
| 341 | case XGL_FILL_SOLID: |
| 342 | default: |
| 343 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID | |
| 344 | GEN7_SF_DW1_BACKFACE_SOLID; |
| 345 | break; |
| 346 | } |
| 347 | |
| 348 | if (rs_state->frontFace == XGL_FRONT_FACE_CCW) { |
| 349 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW; |
| 350 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW; |
| 351 | } |
| 352 | |
| 353 | switch (rs_state->cullMode) { |
| 354 | case XGL_CULL_NONE: |
| 355 | default: |
| 356 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE; |
| 357 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE; |
| 358 | break; |
| 359 | case XGL_CULL_FRONT: |
| 360 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT; |
| 361 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT; |
| 362 | break; |
| 363 | case XGL_CULL_BACK: |
| 364 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK; |
| 365 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK; |
| 366 | break; |
| 367 | case XGL_CULL_FRONT_AND_BACK: |
| 368 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH; |
| 369 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH; |
| 370 | break; |
| 371 | } |
| 372 | |
| 373 | /* only GEN7+ needs cull mode in 3DSTATE_CLIP */ |
| 374 | if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6)) |
| 375 | pipeline->cmd_clip_cull = 0; |
| 376 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 377 | return XGL_SUCCESS; |
| 378 | } |
| 379 | |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 380 | static void pipeline_destroy(struct intel_obj *obj) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 381 | { |
| 382 | struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj); |
| 383 | |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 384 | if (pipeline->active_shaders & SHADER_VERTEX_FLAG) { |
| 385 | intel_pipeline_shader_cleanup(&pipeline->vs); |
| 386 | } |
| 387 | |
| 388 | if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) { |
| 389 | intel_pipeline_shader_cleanup(&pipeline->tcs); |
| 390 | } |
| 391 | |
| 392 | if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) { |
| 393 | intel_pipeline_shader_cleanup(&pipeline->tes); |
| 394 | } |
| 395 | |
| 396 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
| 397 | intel_pipeline_shader_cleanup(&pipeline->gs); |
| 398 | } |
| 399 | |
| 400 | if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) { |
| 401 | intel_pipeline_shader_cleanup(&pipeline->fs); |
| 402 | } |
| 403 | |
| 404 | if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) { |
| 405 | intel_pipeline_shader_cleanup(&pipeline->cs); |
| 406 | } |
Chia-I Wu | ed83387 | 2014-08-23 17:00:35 +0800 | [diff] [blame] | 407 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 408 | intel_base_destroy(&pipeline->obj.base); |
| 409 | } |
| 410 | |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 411 | static XGL_RESULT pipeline_get_info(struct intel_base *base, int type, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 412 | size_t *size, void *data) |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 413 | { |
| 414 | struct intel_pipeline *pipeline = intel_pipeline_from_base(base); |
| 415 | XGL_RESULT ret = XGL_SUCCESS; |
| 416 | |
| 417 | switch (type) { |
| 418 | case XGL_INFO_TYPE_MEMORY_REQUIREMENTS: |
| 419 | { |
| 420 | XGL_MEMORY_REQUIREMENTS *mem_req = data; |
| 421 | |
| 422 | *size = sizeof(XGL_MEMORY_REQUIREMENTS); |
| 423 | if (data) { |
| 424 | mem_req->size = pipeline->scratch_size; |
| 425 | mem_req->alignment = 1024; |
Jon Ashburn | d803133 | 2015-01-22 10:52:13 -0700 | [diff] [blame] | 426 | mem_req->memType = XGL_MEMORY_TYPE_OTHER; |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | break; |
| 430 | default: |
| 431 | ret = intel_base_get_info(base, type, size, data); |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | return ret; |
| 436 | } |
| 437 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 438 | static XGL_RESULT pipeline_validate(struct intel_pipeline *pipeline) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 439 | { |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 440 | /* |
| 441 | * Validate required elements |
| 442 | */ |
| 443 | if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) { |
| 444 | // TODO: Log debug message: Vertex Shader required. |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 445 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* |
| 449 | * Tessalation control and evaluation have to both have a shader defined or |
| 450 | * neither should have a shader defined. |
| 451 | */ |
| 452 | if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) != |
| 453 | ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) { |
| 454 | // 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] | 455 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) && |
| 459 | (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG | |
| 460 | SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG | |
| 461 | SHADER_FRAGMENT_FLAG))) { |
| 462 | // 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] | 463 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /* |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 467 | * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines. |
| 468 | * Mismatching primitive topology and tessellation fails graphics pipeline creation. |
| 469 | */ |
| 470 | if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) && |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 471 | (pipeline->topology != XGL_TOPOLOGY_PATCH)) { |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 472 | // TODO: Log debug message: Invalid topology used with tessalation shader. |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 473 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 474 | } |
| 475 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 476 | if ((pipeline->topology == XGL_TOPOLOGY_PATCH) && |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 477 | (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) { |
| 478 | // 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] | 479 | return XGL_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 480 | } |
| 481 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 482 | return XGL_SUCCESS; |
| 483 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 484 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 485 | static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline, |
| 486 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 487 | { |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 488 | const struct intel_gpu *gpu = pipeline->dev->gpu; |
| 489 | const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024; |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 490 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
| 491 | const struct intel_pipeline_shader *gs = &pipeline->gs; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 492 | int vs_entry_size, gs_entry_size; |
| 493 | int vs_size, gs_size; |
| 494 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 495 | INTEL_GPU_ASSERT(gpu, 6, 6); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 496 | |
| 497 | vs_entry_size = ((vs->in_count >= vs->out_count) ? |
| 498 | vs->in_count : vs->out_count); |
| 499 | gs_entry_size = (gs) ? gs->out_count : 0; |
| 500 | |
| 501 | /* in bytes */ |
| 502 | vs_entry_size *= sizeof(float) * 4; |
| 503 | gs_entry_size *= sizeof(float) * 4; |
| 504 | |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 505 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 506 | vs_size = urb_size / 2; |
| 507 | gs_size = vs_size; |
| 508 | } else { |
| 509 | vs_size = urb_size; |
| 510 | gs_size = 0; |
| 511 | } |
| 512 | |
| 513 | /* 3DSTATE_URB */ |
| 514 | { |
| 515 | const uint8_t cmd_len = 3; |
| 516 | const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | |
| 517 | (cmd_len - 2); |
| 518 | int vs_alloc_size, gs_alloc_size; |
| 519 | int vs_entry_count, gs_entry_count; |
| 520 | uint32_t *dw; |
| 521 | |
| 522 | /* in 1024-bit rows */ |
| 523 | vs_alloc_size = (vs_entry_size + 128 - 1) / 128; |
| 524 | gs_alloc_size = (gs_entry_size + 128 - 1) / 128; |
| 525 | |
| 526 | /* valid range is [1, 5] */ |
| 527 | if (!vs_alloc_size) |
| 528 | vs_alloc_size = 1; |
| 529 | if (!gs_alloc_size) |
| 530 | gs_alloc_size = 1; |
| 531 | assert(vs_alloc_size <= 5 && gs_alloc_size <= 5); |
| 532 | |
| 533 | /* valid range is [24, 256], multiples of 4 */ |
| 534 | vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3; |
| 535 | if (vs_entry_count > 256) |
| 536 | vs_entry_count = 256; |
| 537 | assert(vs_entry_count >= 24); |
| 538 | |
| 539 | /* valid range is [0, 256], multiples of 4 */ |
| 540 | gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3; |
| 541 | if (gs_entry_count > 256) |
| 542 | gs_entry_count = 256; |
| 543 | |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 544 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 545 | |
| 546 | dw[0] = dw0; |
| 547 | dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT | |
| 548 | vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT; |
| 549 | dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT | |
| 550 | (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT; |
| 551 | } |
| 552 | } |
| 553 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 554 | static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline, |
| 555 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 556 | { |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 557 | const struct intel_gpu *gpu = pipeline->dev->gpu; |
| 558 | const int urb_size = ((gpu->gt == 3) ? 512 : |
| 559 | (gpu->gt == 2) ? 256 : 128) * 1024; |
Cody Northrop | 306ec35 | 2014-10-06 15:11:45 -0600 | [diff] [blame] | 560 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
| 561 | const struct intel_pipeline_shader *gs = &pipeline->gs; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 562 | /* some space is reserved for PCBs */ |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 563 | int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 564 | int vs_entry_size, gs_entry_size; |
| 565 | int vs_size, gs_size; |
| 566 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 567 | INTEL_GPU_ASSERT(gpu, 7, 7.5); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 568 | |
| 569 | vs_entry_size = ((vs->in_count >= vs->out_count) ? |
| 570 | vs->in_count : vs->out_count); |
| 571 | gs_entry_size = (gs) ? gs->out_count : 0; |
| 572 | |
| 573 | /* in bytes */ |
| 574 | vs_entry_size *= sizeof(float) * 4; |
| 575 | gs_entry_size *= sizeof(float) * 4; |
| 576 | |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 577 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 578 | vs_size = (urb_size - urb_offset) / 2; |
| 579 | gs_size = vs_size; |
| 580 | } else { |
| 581 | vs_size = urb_size - urb_offset; |
| 582 | gs_size = 0; |
| 583 | } |
| 584 | |
| 585 | /* 3DSTATE_URB_* */ |
| 586 | { |
| 587 | const uint8_t cmd_len = 2; |
| 588 | int vs_alloc_size, gs_alloc_size; |
| 589 | int vs_entry_count, gs_entry_count; |
| 590 | uint32_t *dw; |
| 591 | |
| 592 | /* in 512-bit rows */ |
| 593 | vs_alloc_size = (vs_entry_size + 64 - 1) / 64; |
| 594 | gs_alloc_size = (gs_entry_size + 64 - 1) / 64; |
| 595 | |
| 596 | if (!vs_alloc_size) |
| 597 | vs_alloc_size = 1; |
| 598 | if (!gs_alloc_size) |
| 599 | gs_alloc_size = 1; |
| 600 | |
| 601 | /* avoid performance decrease due to banking */ |
| 602 | if (vs_alloc_size == 5) |
| 603 | vs_alloc_size = 6; |
| 604 | |
| 605 | /* in multiples of 8 */ |
| 606 | vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7; |
| 607 | assert(vs_entry_count >= 32); |
| 608 | |
| 609 | gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7; |
| 610 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 611 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) { |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 612 | const int max_vs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 613 | (gpu->gt >= 2) ? 1664 : 640; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 614 | const int max_gs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 615 | (gpu->gt >= 2) ? 640 : 256; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 616 | if (vs_entry_count >= max_vs_entry_count) |
| 617 | vs_entry_count = max_vs_entry_count; |
| 618 | if (gs_entry_count >= max_gs_entry_count) |
| 619 | gs_entry_count = max_gs_entry_count; |
| 620 | } else { |
| 621 | const int max_vs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 622 | (gpu->gt == 2) ? 704 : 512; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 623 | const int max_gs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 624 | (gpu->gt == 2) ? 320 : 192; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 625 | if (vs_entry_count >= max_vs_entry_count) |
| 626 | vs_entry_count = max_vs_entry_count; |
| 627 | if (gs_entry_count >= max_gs_entry_count) |
| 628 | gs_entry_count = max_gs_entry_count; |
| 629 | } |
| 630 | |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 631 | dw = pipeline_cmd_ptr(pipeline, cmd_len*4); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 632 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2); |
| 633 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT | |
| 634 | (vs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT | |
| 635 | vs_entry_count; |
| 636 | |
| 637 | dw += 2; |
| 638 | if (gs_size) |
| 639 | urb_offset += vs_size; |
| 640 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2); |
| 641 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT | |
| 642 | (gs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT | |
| 643 | gs_entry_count; |
| 644 | |
| 645 | dw += 2; |
| 646 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2); |
| 647 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT; |
| 648 | |
| 649 | dw += 2; |
| 650 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2); |
| 651 | dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT; |
| 652 | } |
| 653 | } |
| 654 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 655 | static void pipeline_build_push_const_alloc_gen7(struct intel_pipeline *pipeline, |
| 656 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 657 | { |
Chia-I Wu | 2919375 | 2015-02-11 11:04:05 -0700 | [diff] [blame] | 658 | const struct intel_gpu *gpu = pipeline->dev->gpu; |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 659 | const uint8_t cmd_len = 2; |
| 660 | uint32_t offset = 0; |
| 661 | uint32_t size = 8192; |
| 662 | uint32_t *dw; |
| 663 | int end; |
| 664 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 665 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 666 | |
| 667 | /* |
| 668 | * From the Ivy Bridge PRM, volume 2 part 1, page 68: |
| 669 | * |
| 670 | * "(A table that says the maximum size of each constant buffer is |
| 671 | * 16KB") |
| 672 | * |
| 673 | * From the Ivy Bridge PRM, volume 2 part 1, page 115: |
| 674 | * |
| 675 | * "The sum of the Constant Buffer Offset and the Constant Buffer Size |
| 676 | * may not exceed the maximum value of the Constant Buffer Size." |
| 677 | * |
| 678 | * Thus, the valid range of buffer end is [0KB, 16KB]. |
| 679 | */ |
| 680 | end = (offset + size) / 1024; |
| 681 | if (end > 16) { |
| 682 | assert(!"invalid constant buffer end"); |
| 683 | end = 16; |
| 684 | } |
| 685 | |
| 686 | /* the valid range of buffer offset is [0KB, 15KB] */ |
| 687 | offset = (offset + 1023) / 1024; |
| 688 | if (offset > 15) { |
| 689 | assert(!"invalid constant buffer offset"); |
| 690 | offset = 15; |
| 691 | } |
| 692 | |
| 693 | if (offset > end) { |
| 694 | assert(!size); |
| 695 | offset = end; |
| 696 | } |
| 697 | |
| 698 | /* the valid range of buffer size is [0KB, 15KB] */ |
| 699 | size = end - offset; |
| 700 | if (size > 15) { |
| 701 | assert(!"invalid constant buffer size"); |
| 702 | size = 15; |
| 703 | } |
| 704 | |
Chia-I Wu | 2919375 | 2015-02-11 11:04:05 -0700 | [diff] [blame] | 705 | if (gpu->gt == 3) |
| 706 | size *= 2; |
| 707 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 708 | dw = pipeline_cmd_ptr(pipeline, cmd_len * 5); |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 709 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2); |
| 710 | dw[1] = offset << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 711 | size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 712 | |
| 713 | dw += 2; |
| 714 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2); |
| 715 | dw[1] = size << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 716 | size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 717 | |
| 718 | dw += 2; |
| 719 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2); |
| 720 | dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 721 | 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 722 | |
| 723 | dw += 2; |
| 724 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2); |
| 725 | dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 726 | 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
| 727 | |
| 728 | dw += 2; |
| 729 | dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2); |
| 730 | dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT | |
| 731 | 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT; |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 732 | |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 733 | // gen7_wa_pipe_control_cs_stall(p, true, true); |
| 734 | // looks equivalent to: gen6_wa_wm_multisample_flush - this does more |
| 735 | // than the documentation seems to imply |
| 736 | } |
| 737 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 738 | static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline, |
| 739 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 740 | { |
Cody Northrop | 306ec35 | 2014-10-06 15:11:45 -0600 | [diff] [blame] | 741 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 742 | uint8_t cmd_len; |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 743 | uint32_t *dw; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 744 | uint32_t i; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 745 | int comps[4]; |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 746 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 747 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 748 | |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 749 | cmd_len = 1 + 2 * u_popcountll(vs->inputs_read); |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 750 | if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) |
| 751 | cmd_len += 2; |
| 752 | |
| 753 | if (cmd_len == 1) |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 754 | return; |
| 755 | |
| 756 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 757 | |
| 758 | dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | |
| 759 | (cmd_len - 2); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 760 | dw++; |
| 761 | |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 762 | /* VERTEX_ELEMENT_STATE */ |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 763 | for (i = 0; i < info->vi.attributeCount; i++) { |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 764 | if (!(vs->inputs_read & (1L << i))) |
GregF | 2dc4021 | 2014-10-31 17:31:47 -0600 | [diff] [blame] | 765 | continue; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 766 | const XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION *attr = |
| 767 | &info->vi.pVertexAttributeDescriptions[i]; |
| 768 | const int format = |
| 769 | intel_format_translate_color(pipeline->dev->gpu, attr->format); |
| 770 | |
| 771 | comps[0] = GEN6_VFCOMP_STORE_0; |
| 772 | comps[1] = GEN6_VFCOMP_STORE_0; |
| 773 | comps[2] = GEN6_VFCOMP_STORE_0; |
| 774 | comps[3] = icd_format_is_int(attr->format) ? |
| 775 | GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP; |
| 776 | |
| 777 | switch (icd_format_get_channel_count(attr->format)) { |
| 778 | case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */ |
| 779 | case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */ |
| 780 | case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */ |
| 781 | case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break; |
| 782 | default: |
| 783 | break; |
| 784 | } |
| 785 | |
| 786 | assert(attr->offsetInBytes <= 2047); |
| 787 | |
| 788 | dw[0] = attr->binding << GEN6_VE_STATE_DW0_VB_INDEX__SHIFT | |
| 789 | GEN6_VE_STATE_DW0_VALID | |
| 790 | format << GEN6_VE_STATE_DW0_FORMAT__SHIFT | |
| 791 | attr->offsetInBytes; |
| 792 | |
| 793 | dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT | |
| 794 | comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT | |
| 795 | comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT | |
| 796 | comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT; |
| 797 | |
| 798 | dw += 2; |
| 799 | } |
GregF | 932fcf5 | 2014-10-29 17:02:11 -0600 | [diff] [blame] | 800 | |
| 801 | if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) { |
| 802 | comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ? |
| 803 | GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0; |
| 804 | comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ? |
| 805 | GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE; |
| 806 | comps[2] = GEN6_VFCOMP_NOSTORE; |
| 807 | comps[3] = GEN6_VFCOMP_NOSTORE; |
| 808 | |
| 809 | dw[0] = GEN6_VE_STATE_DW0_VALID; |
| 810 | dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT | |
| 811 | comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT | |
| 812 | comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT | |
| 813 | comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT; |
| 814 | |
| 815 | dw += 2; |
| 816 | } |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 817 | } |
| 818 | |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 819 | static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline) |
| 820 | { |
| 821 | const struct intel_pipeline_shader *fs = &pipeline->fs; |
| 822 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
| 823 | uint8_t cmd_len; |
| 824 | uint32_t *body; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 825 | uint32_t attr_skip, attr_count; |
| 826 | uint32_t vue_offset, vue_len; |
| 827 | uint32_t i; |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 828 | |
| 829 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
| 830 | |
| 831 | cmd_len = 14; |
| 832 | |
Chia-I Wu | f85def4 | 2015-01-29 00:34:24 +0800 | [diff] [blame] | 833 | if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) |
| 834 | body = pipeline_cmd_ptr(pipeline, cmd_len); |
| 835 | else |
| 836 | body = pipeline->cmd_3dstate_sbe; |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 837 | |
| 838 | /* VS outputs VUE header and position additionally */ |
| 839 | assert(vs->out_count >= fs->in_count + 2); |
| 840 | assert(!fs->reads_user_clip || vs->enable_user_clip); |
| 841 | attr_skip = vs->outputs_offset; |
| 842 | if (vs->enable_user_clip != fs->reads_user_clip) { |
| 843 | attr_skip += 2; |
| 844 | } |
| 845 | assert(vs->out_count >= attr_skip); |
| 846 | attr_count = vs->out_count - attr_skip; |
| 847 | |
| 848 | // LUNARG TODO: We currently are only handling 16 attrs; |
| 849 | // ultimately, we need to handle 32 |
| 850 | assert(fs->in_count <= 16); |
| 851 | assert(attr_count <= 16); |
| 852 | |
| 853 | vue_offset = attr_skip / 2; |
| 854 | vue_len = (attr_count + 1) / 2; |
| 855 | if (!vue_len) |
| 856 | vue_len = 1; |
| 857 | |
| 858 | body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | |
| 859 | (cmd_len - 2); |
| 860 | |
| 861 | // LUNARG TODO: If the attrs needed by the FS are exactly |
| 862 | // what is written by the VS, we don't need to enable |
| 863 | // swizzling, improving performance. Even if we swizzle, |
| 864 | // we can improve performance by reducing vue_len to |
| 865 | // just include the values needed by the FS: |
| 866 | // vue_len = ceiling((max_vs_out + 1)/2) |
| 867 | |
| 868 | body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE | |
| 869 | fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT | |
| 870 | vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT | |
| 871 | vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT; |
| 872 | |
| 873 | uint16_t vs_slot[fs->in_count]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 874 | int32_t fs_in = 0; |
| 875 | int32_t vs_out = - (vue_offset * 2 - vs->outputs_offset); |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 876 | for (i=0; i < 64; i++) { |
Cody Northrop | d75c13e | 2015-01-02 14:07:20 -0700 | [diff] [blame] | 877 | bool vsWrites = vs->outputs_written & (1L << i); |
| 878 | bool fsReads = fs->inputs_read & (1L << i); |
| 879 | |
| 880 | if (fsReads) { |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 881 | assert(vs_out >= 0); |
| 882 | assert(fs_in < fs->in_count); |
| 883 | vs_slot[fs_in] = vs_out; |
Cody Northrop | d75c13e | 2015-01-02 14:07:20 -0700 | [diff] [blame] | 884 | |
| 885 | if (!vsWrites) { |
| 886 | // If the vertex shader did not write this input, we cannot |
| 887 | // program the SBE to read it. Our choices are to allow it to |
| 888 | // read junk from a GRF, or get zero. We're choosing zero. |
| 889 | if (i >= fs->generic_input_start) { |
| 890 | vs_slot[fs_in] = GEN7_SBE_ATTR_CONST_0000 | |
| 891 | GEN7_SBE_ATTR_OVERRIDE_X | |
| 892 | GEN7_SBE_ATTR_OVERRIDE_Y | |
| 893 | GEN7_SBE_ATTR_OVERRIDE_Z | |
| 894 | GEN7_SBE_ATTR_OVERRIDE_W; |
| 895 | } |
| 896 | } |
| 897 | |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 898 | fs_in += 1; |
| 899 | } |
Cody Northrop | d75c13e | 2015-01-02 14:07:20 -0700 | [diff] [blame] | 900 | if (vsWrites) { |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 901 | vs_out += 1; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | for (i = 0; i < 8; i++) { |
| 906 | uint16_t hi, lo; |
| 907 | |
| 908 | /* no attr swizzles */ |
| 909 | if (i * 2 + 1 < fs->in_count) { |
| 910 | lo = vs_slot[i * 2]; |
| 911 | hi = vs_slot[i * 2 + 1]; |
| 912 | } else if (i * 2 < fs->in_count) { |
| 913 | lo = vs_slot[i * 2]; |
| 914 | hi = 0; |
| 915 | } else { |
| 916 | hi = 0; |
| 917 | lo = 0; |
| 918 | } |
| 919 | |
| 920 | body[2 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo; |
| 921 | } |
| 922 | |
| 923 | body[10] = 0; /* point sprite enables */ |
| 924 | body[11] = 0; /* constant interpolation enables */ |
| 925 | body[12] = 0; /* WrapShortest enables */ |
| 926 | body[13] = 0; |
| 927 | } |
| 928 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 929 | static void pipeline_build_gs(struct intel_pipeline *pipeline, |
| 930 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 931 | { |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 932 | // gen7_emit_3DSTATE_GS done by cmd_pipeline |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 933 | } |
| 934 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 935 | static void pipeline_build_hs(struct intel_pipeline *pipeline, |
| 936 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 937 | { |
| 938 | const uint8_t cmd_len = 7; |
| 939 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2); |
| 940 | uint32_t *dw; |
| 941 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 942 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 943 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 944 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 945 | dw[0] = dw0; |
| 946 | dw[1] = 0; |
| 947 | dw[2] = 0; |
| 948 | dw[3] = 0; |
| 949 | dw[4] = 0; |
| 950 | dw[5] = 0; |
| 951 | dw[6] = 0; |
| 952 | } |
| 953 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 954 | static void pipeline_build_te(struct intel_pipeline *pipeline, |
| 955 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 956 | { |
| 957 | const uint8_t cmd_len = 4; |
| 958 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2); |
| 959 | uint32_t *dw; |
| 960 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 961 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 962 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 963 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 964 | dw[0] = dw0; |
| 965 | dw[1] = 0; |
| 966 | dw[2] = 0; |
| 967 | dw[3] = 0; |
| 968 | } |
| 969 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 970 | static void pipeline_build_ds(struct intel_pipeline *pipeline, |
| 971 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 972 | { |
| 973 | const uint8_t cmd_len = 6; |
| 974 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2); |
| 975 | uint32_t *dw; |
| 976 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 977 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 978 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 979 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 980 | dw[0] = dw0; |
| 981 | dw[1] = 0; |
| 982 | dw[2] = 0; |
| 983 | dw[3] = 0; |
| 984 | dw[4] = 0; |
| 985 | dw[5] = 0; |
| 986 | } |
| 987 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 988 | static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline, |
| 989 | const struct intel_pipeline_create_info *info) |
| 990 | { |
| 991 | pipeline->cmd_depth_stencil = 0; |
| 992 | |
| 993 | if (info->db.stencilTestEnable) { |
| 994 | pipeline->cmd_depth_stencil = 1 << 31 | |
| 995 | translate_compare_func(info->db.front.stencilFunc) << 28 | |
| 996 | translate_stencil_op(info->db.front.stencilFailOp) << 25 | |
| 997 | translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 | |
| 998 | translate_stencil_op(info->db.front.stencilPassOp) << 19 | |
| 999 | 1 << 15 | |
| 1000 | translate_compare_func(info->db.back.stencilFunc) << 12 | |
| 1001 | translate_stencil_op(info->db.back.stencilFailOp) << 9 | |
| 1002 | translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 | |
| 1003 | translate_stencil_op(info->db.back.stencilPassOp) << 3; |
| 1004 | } |
| 1005 | |
| 1006 | pipeline->stencilTestEnable = info->db.stencilTestEnable; |
| 1007 | |
| 1008 | /* |
| 1009 | * From the Sandy Bridge PRM, volume 2 part 1, page 360: |
| 1010 | * |
| 1011 | * "Enabling the Depth Test function without defining a Depth Buffer is |
| 1012 | * UNDEFINED." |
| 1013 | * |
| 1014 | * From the Sandy Bridge PRM, volume 2 part 1, page 375: |
| 1015 | * |
| 1016 | * "A Depth Buffer must be defined before enabling writes to it, or |
| 1017 | * operation is UNDEFINED." |
| 1018 | * |
| 1019 | * TODO We do not check these yet. |
| 1020 | */ |
| 1021 | if (info->db.depthTestEnable) { |
| 1022 | pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE | |
| 1023 | translate_compare_func(info->db.depthFunc) << 27; |
| 1024 | } else { |
| 1025 | pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27; |
| 1026 | } |
| 1027 | |
| 1028 | if (info->db.depthWriteEnable) |
| 1029 | pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE; |
| 1030 | } |
| 1031 | |
| 1032 | static void pipeline_init_sample_pattern(struct intel_pipeline *pipeline, |
| 1033 | uint8_t *samples) |
| 1034 | { |
| 1035 | struct sample { |
| 1036 | int x, y; |
| 1037 | }; |
| 1038 | static const struct sample default_pattern_2x[2] = { |
| 1039 | { -4, -4 }, |
| 1040 | { 4, 4 }, |
| 1041 | }; |
| 1042 | static const struct sample default_pattern_4x[4] = { |
| 1043 | { -2, -6 }, |
| 1044 | { 6, -2 }, |
| 1045 | { -6, 2 }, |
| 1046 | { 2, 6 }, |
| 1047 | }; |
| 1048 | static const struct sample default_pattern_8x[8] = { |
| 1049 | { 1, -3 }, |
| 1050 | { -1, 3 }, |
| 1051 | { 5, 1 }, |
| 1052 | { -3, -5 }, |
| 1053 | { -5, 5 }, |
| 1054 | { -7, -1 }, |
| 1055 | { 3, 7 }, |
| 1056 | { 7, -7 }, |
| 1057 | }; |
| 1058 | |
| 1059 | const struct sample *pattern; |
| 1060 | int i; |
| 1061 | |
| 1062 | switch (pipeline->sample_count) { |
| 1063 | case 2: |
| 1064 | pattern = default_pattern_2x; |
| 1065 | break; |
| 1066 | case 4: |
| 1067 | pattern = default_pattern_4x; |
| 1068 | break; |
| 1069 | case 8: |
| 1070 | pattern = default_pattern_8x; |
| 1071 | break; |
| 1072 | default: |
| 1073 | memset(samples, 0, pipeline->sample_count); |
| 1074 | return; |
| 1075 | break; |
| 1076 | } |
| 1077 | |
| 1078 | for (i = 0; i < pipeline->sample_count; i++) |
| 1079 | samples[i] = (pattern[i].x + 8) << 4 | (pattern[i].y + 8); |
| 1080 | } |
| 1081 | |
| 1082 | static void pipeline_build_msaa(struct intel_pipeline *pipeline, |
| 1083 | const struct intel_pipeline_create_info *info) |
| 1084 | { |
| 1085 | uint32_t cmd, cmd_len; |
| 1086 | uint32_t *dw; |
| 1087 | |
| 1088 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
| 1089 | |
| 1090 | |
| 1091 | pipeline->sample_count = (info->ms.samples <= 1)?1:info->ms.samples; |
| 1092 | |
| 1093 | /* 3DSTATE_MULTISAMPLE */ |
| 1094 | cmd = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE); |
| 1095 | cmd_len = (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) ? 4 : 3; |
| 1096 | dw = pipeline_cmd_ptr(pipeline, cmd_len + 2); |
| 1097 | dw[0] = cmd | (cmd_len - 2); |
| 1098 | if (pipeline->sample_count <= 1) |
| 1099 | dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1; |
| 1100 | else if (pipeline->sample_count <= 4 || intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6)) |
| 1101 | dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4; |
| 1102 | else |
| 1103 | dw[1] = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8; |
| 1104 | |
| 1105 | pipeline_init_sample_pattern(pipeline, (uint8_t *) &dw[2]); |
| 1106 | |
| 1107 | dw += cmd_len; |
| 1108 | |
| 1109 | /* 3DSTATE_SAMPLE_MASK */ |
| 1110 | cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK); |
| 1111 | cmd_len = 2; |
| 1112 | |
| 1113 | dw[0] = cmd | (cmd_len - 2); |
| 1114 | dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1); |
| 1115 | pipeline->cmd_sample_mask = dw[1]; |
| 1116 | } |
| 1117 | |
| 1118 | static void pipeline_build_cb(struct intel_pipeline *pipeline, |
| 1119 | const struct intel_pipeline_create_info *info) |
| 1120 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1121 | uint32_t i; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1122 | |
| 1123 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
| 1124 | STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2); |
| 1125 | assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS); |
| 1126 | |
| 1127 | uint32_t *dw = pipeline->cmd_cb; |
| 1128 | |
| 1129 | for (i = 0; i < info->cb.attachmentCount; i++) { |
| 1130 | const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &info->cb.pAttachments[i]; |
| 1131 | uint32_t dw0, dw1; |
| 1132 | |
| 1133 | |
| 1134 | dw0 = 0; |
| 1135 | dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | |
| 1136 | GEN6_BLEND_DW1_PRE_BLEND_CLAMP | |
| 1137 | GEN6_BLEND_DW1_POST_BLEND_CLAMP; |
| 1138 | |
| 1139 | if (att->blendEnable) { |
| 1140 | dw0 = 1 << 31 | |
| 1141 | translate_blend_func(att->blendFuncAlpha) << 26 | |
| 1142 | translate_blend(att->srcBlendAlpha) << 20 | |
| 1143 | translate_blend(att->destBlendAlpha) << 15 | |
| 1144 | translate_blend_func(att->blendFuncColor) << 11 | |
| 1145 | translate_blend(att->srcBlendColor) << 5 | |
| 1146 | translate_blend(att->destBlendColor); |
| 1147 | |
| 1148 | if (att->blendFuncAlpha != att->blendFuncColor || |
| 1149 | att->srcBlendAlpha != att->srcBlendColor || |
| 1150 | att->destBlendAlpha != att->destBlendColor) |
| 1151 | dw0 |= 1 << 30; |
Courtney Goeltzenleuchter | df13a4d | 2015-02-11 14:14:45 -0700 | [diff] [blame] | 1152 | |
| 1153 | pipeline->dual_source_blend_enable = icd_pipeline_cb_att_needs_dual_source_blending(att); |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | if (info->cb.logicOp != XGL_LOGIC_OP_COPY) { |
| 1157 | int logicop; |
| 1158 | |
| 1159 | switch (info->cb.logicOp) { |
| 1160 | case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break; |
| 1161 | case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break; |
| 1162 | case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break; |
| 1163 | case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break; |
| 1164 | case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break; |
| 1165 | case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break; |
| 1166 | case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break; |
| 1167 | case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break; |
| 1168 | case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break; |
| 1169 | case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break; |
| 1170 | case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break; |
| 1171 | case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break; |
| 1172 | case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break; |
| 1173 | case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break; |
| 1174 | case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break; |
| 1175 | default: |
| 1176 | assert(!"unknown logic op"); |
| 1177 | logicop = GEN6_LOGICOP_CLEAR; |
| 1178 | break; |
| 1179 | } |
| 1180 | |
| 1181 | dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE | |
| 1182 | logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT; |
| 1183 | } |
| 1184 | |
| 1185 | if (!(att->channelWriteMask & 0x1)) |
| 1186 | dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R; |
| 1187 | if (!(att->channelWriteMask & 0x2)) |
| 1188 | dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G; |
| 1189 | if (!(att->channelWriteMask & 0x4)) |
| 1190 | dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B; |
| 1191 | if (!(att->channelWriteMask & 0x8)) |
| 1192 | dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A; |
| 1193 | |
| 1194 | dw[2 * i] = dw0; |
| 1195 | dw[2 * i + 1] = dw1; |
| 1196 | } |
| 1197 | |
| 1198 | for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++) |
| 1199 | { |
| 1200 | dw[2 * i] = 0; |
| 1201 | dw[2 * i + 1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | |
| 1202 | GEN6_BLEND_DW1_PRE_BLEND_CLAMP | |
| 1203 | GEN6_BLEND_DW1_POST_BLEND_CLAMP | |
| 1204 | GEN6_BLEND_DW1_WRITE_DISABLE_R | |
| 1205 | GEN6_BLEND_DW1_WRITE_DISABLE_G | |
| 1206 | GEN6_BLEND_DW1_WRITE_DISABLE_B | |
| 1207 | GEN6_BLEND_DW1_WRITE_DISABLE_A; |
| 1208 | } |
| 1209 | |
| 1210 | } |
| 1211 | |
| 1212 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1213 | static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline, |
| 1214 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1215 | { |
| 1216 | XGL_RESULT ret; |
| 1217 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 1218 | ret = pipeline_build_shaders(pipeline, info); |
| 1219 | if (ret != XGL_SUCCESS) |
| 1220 | return ret; |
| 1221 | |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 1222 | if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) || |
| 1223 | info->vi.attributeCount > ARRAY_SIZE(pipeline->vb)) |
| 1224 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 1225 | |
| 1226 | pipeline->vb_count = info->vi.bindingCount; |
| 1227 | memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions, |
| 1228 | sizeof(pipeline->vb[0]) * pipeline->vb_count); |
| 1229 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1230 | pipeline_build_vertex_elements(pipeline, info); |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 1231 | pipeline_build_fragment_SBE(pipeline); |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1232 | pipeline_build_msaa(pipeline, info); |
Chia-I Wu | 5bdb096 | 2015-01-24 12:49:28 +0800 | [diff] [blame] | 1233 | pipeline_build_depth_stencil(pipeline, info); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 1234 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 1235 | if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1236 | pipeline_build_urb_alloc_gen7(pipeline, info); |
| 1237 | pipeline_build_push_const_alloc_gen7(pipeline, info); |
| 1238 | pipeline_build_gs(pipeline, info); |
| 1239 | pipeline_build_hs(pipeline, info); |
| 1240 | pipeline_build_te(pipeline, info); |
| 1241 | pipeline_build_ds(pipeline, info); |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 1242 | |
| 1243 | pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE | |
| 1244 | INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL | |
| 1245 | INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE | |
| 1246 | INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL | |
| 1247 | INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 1248 | } else { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1249 | pipeline_build_urb_alloc_gen6(pipeline, info); |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 1250 | |
| 1251 | pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE | |
| 1252 | INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 1253 | } |
| 1254 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 1255 | ret = pipeline_build_ia(pipeline, info); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1256 | |
| 1257 | if (ret == XGL_SUCCESS) |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1258 | ret = pipeline_rs_state(pipeline, &info->rs); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1259 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1260 | if (ret == XGL_SUCCESS) { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1261 | pipeline->db_format = info->db.format; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1262 | pipeline_build_cb(pipeline, info); |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1263 | pipeline->cb_state = info->cb; |
| 1264 | pipeline->tess_state = info->tess; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | return ret; |
| 1268 | } |
| 1269 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1270 | struct intel_pipeline_create_info_header { |
| 1271 | XGL_STRUCTURE_TYPE struct_type; |
| 1272 | const struct intel_pipeline_create_info_header *next; |
| 1273 | }; |
| 1274 | |
| 1275 | static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1276 | const struct intel_pipeline_create_info_header *header) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1277 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1278 | memset(info, 0, sizeof(*info)); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1279 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1280 | |
| 1281 | /* |
| 1282 | * Do we need to set safe defaults in case the app doesn't provide all of |
| 1283 | * the necessary create infos? |
| 1284 | */ |
| 1285 | info->ms.samples = 1; |
| 1286 | info->ms.sampleMask = 1; |
| 1287 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1288 | while (header) { |
| 1289 | const void *src = (const void *) header; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1290 | size_t size; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1291 | void *dst; |
| 1292 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1293 | switch (header->struct_type) { |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1294 | case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1295 | size = sizeof(info->graphics); |
| 1296 | dst = &info->graphics; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1297 | break; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 1298 | case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO: |
| 1299 | size = sizeof(info->vi); |
| 1300 | dst = &info->vi; |
| 1301 | break; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1302 | case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1303 | size = sizeof(info->ia); |
| 1304 | dst = &info->ia; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1305 | break; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1306 | case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1307 | size = sizeof(info->db); |
| 1308 | dst = &info->db; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1309 | break; |
| 1310 | case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1311 | size = sizeof(info->cb); |
| 1312 | dst = &info->cb; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1313 | break; |
| 1314 | case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1315 | size = sizeof(info->rs); |
| 1316 | dst = &info->rs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1317 | break; |
| 1318 | case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1319 | size = sizeof(info->tess); |
| 1320 | dst = &info->tess; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1321 | break; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1322 | case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO: |
| 1323 | size = sizeof(info->ms); |
| 1324 | dst = &info->ms; |
| 1325 | break; |
| 1326 | case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO: |
| 1327 | size = sizeof(info->vp); |
| 1328 | dst = &info->vp; |
| 1329 | break; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1330 | case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO: |
| 1331 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1332 | const XGL_PIPELINE_SHADER *shader = |
| 1333 | (const XGL_PIPELINE_SHADER *) (header + 1); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1334 | |
| 1335 | src = (const void *) shader; |
| 1336 | size = sizeof(*shader); |
| 1337 | |
| 1338 | switch (shader->stage) { |
| 1339 | case XGL_SHADER_STAGE_VERTEX: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1340 | dst = &info->vs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1341 | break; |
| 1342 | case XGL_SHADER_STAGE_TESS_CONTROL: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1343 | dst = &info->tcs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1344 | break; |
| 1345 | case XGL_SHADER_STAGE_TESS_EVALUATION: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1346 | dst = &info->tes; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1347 | break; |
| 1348 | case XGL_SHADER_STAGE_GEOMETRY: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1349 | dst = &info->gs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1350 | break; |
| 1351 | case XGL_SHADER_STAGE_FRAGMENT: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1352 | dst = &info->fs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1353 | break; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1354 | default: |
| 1355 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 1356 | break; |
| 1357 | } |
| 1358 | } |
| 1359 | break; |
| 1360 | case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1361 | size = sizeof(info->compute); |
| 1362 | dst = &info->compute; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1363 | break; |
| 1364 | default: |
| 1365 | return XGL_ERROR_BAD_PIPELINE_DATA; |
| 1366 | break; |
| 1367 | } |
| 1368 | |
| 1369 | memcpy(dst, src, size); |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1370 | header = header->next; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1371 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1372 | |
| 1373 | return XGL_SUCCESS; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1374 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1375 | |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1376 | static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1377 | const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_, |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1378 | struct intel_pipeline **pipeline_ret) |
| 1379 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1380 | struct intel_pipeline_create_info info; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1381 | struct intel_pipeline *pipeline; |
| 1382 | XGL_RESULT ret; |
| 1383 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 1384 | ret = pipeline_create_info_init(&info, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1385 | (const struct intel_pipeline_create_info_header *) info_); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1386 | if (ret != XGL_SUCCESS) |
| 1387 | return ret; |
| 1388 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 1389 | pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle, |
| 1390 | sizeof(*pipeline), dev->base.dbg, |
| 1391 | XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1392 | if (!pipeline) |
| 1393 | return XGL_ERROR_OUT_OF_MEMORY; |
| 1394 | |
| 1395 | pipeline->dev = dev; |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 1396 | pipeline->obj.base.get_info = pipeline_get_info; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1397 | pipeline->obj.destroy = pipeline_destroy; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1398 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1399 | ret = pipeline_build_all(pipeline, &info); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1400 | if (ret == XGL_SUCCESS) |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1401 | ret = pipeline_validate(pipeline); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1402 | if (ret != XGL_SUCCESS) { |
| 1403 | pipeline_destroy(&pipeline->obj); |
| 1404 | return ret; |
| 1405 | } |
| 1406 | |
| 1407 | *pipeline_ret = pipeline; |
| 1408 | |
| 1409 | return XGL_SUCCESS; |
| 1410 | } |
| 1411 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 1412 | ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipeline( |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1413 | XGL_DEVICE device, |
| 1414 | const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo, |
| 1415 | XGL_PIPELINE* pPipeline) |
| 1416 | { |
| 1417 | struct intel_dev *dev = intel_dev(device); |
| 1418 | |
| 1419 | return graphics_pipeline_create(dev, pCreateInfo, |
| 1420 | (struct intel_pipeline **) pPipeline); |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1421 | } |
| 1422 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 1423 | ICD_EXPORT XGL_RESULT XGLAPI xglCreateComputePipeline( |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1424 | XGL_DEVICE device, |
| 1425 | const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo, |
| 1426 | XGL_PIPELINE* pPipeline) |
| 1427 | { |
| 1428 | return XGL_ERROR_UNAVAILABLE; |
| 1429 | } |
| 1430 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 1431 | ICD_EXPORT XGL_RESULT XGLAPI xglStorePipeline( |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1432 | XGL_PIPELINE pipeline, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1433 | size_t* pDataSize, |
| 1434 | void* pData) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1435 | { |
| 1436 | return XGL_ERROR_UNAVAILABLE; |
| 1437 | } |
| 1438 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 1439 | ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipeline( |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1440 | XGL_DEVICE device, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1441 | size_t dataSize, |
| 1442 | const void* pData, |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1443 | XGL_PIPELINE* pPipeline) |
| 1444 | { |
| 1445 | return XGL_ERROR_UNAVAILABLE; |
| 1446 | } |
| 1447 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 1448 | ICD_EXPORT XGL_RESULT XGLAPI xglCreatePipelineDelta( |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1449 | XGL_DEVICE device, |
| 1450 | XGL_PIPELINE p1, |
| 1451 | XGL_PIPELINE p2, |
| 1452 | XGL_PIPELINE_DELTA* delta) |
| 1453 | { |
| 1454 | return XGL_ERROR_UNAVAILABLE; |
| 1455 | } |