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