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