Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 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 | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 36 | static int translate_blend_func(VkBlendOp func) |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 37 | { |
| 38 | switch (func) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 39 | case VK_BLEND_OP_ADD: return GEN6_BLENDFUNCTION_ADD; |
| 40 | case VK_BLEND_OP_SUBTRACT: return GEN6_BLENDFUNCTION_SUBTRACT; |
| 41 | case VK_BLEND_OP_REVERSE_SUBTRACT: return GEN6_BLENDFUNCTION_REVERSE_SUBTRACT; |
| 42 | case VK_BLEND_OP_MIN: return GEN6_BLENDFUNCTION_MIN; |
| 43 | case VK_BLEND_OP_MAX: return GEN6_BLENDFUNCTION_MAX; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 44 | default: |
| 45 | assert(!"unknown blend func"); |
| 46 | return GEN6_BLENDFUNCTION_ADD; |
| 47 | }; |
| 48 | } |
| 49 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 50 | static int translate_blend(VkBlend blend) |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 51 | { |
| 52 | switch (blend) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 53 | case VK_BLEND_ZERO: return GEN6_BLENDFACTOR_ZERO; |
| 54 | case VK_BLEND_ONE: return GEN6_BLENDFACTOR_ONE; |
| 55 | case VK_BLEND_SRC_COLOR: return GEN6_BLENDFACTOR_SRC_COLOR; |
| 56 | case VK_BLEND_ONE_MINUS_SRC_COLOR: return GEN6_BLENDFACTOR_INV_SRC_COLOR; |
| 57 | case VK_BLEND_DEST_COLOR: return GEN6_BLENDFACTOR_DST_COLOR; |
| 58 | case VK_BLEND_ONE_MINUS_DEST_COLOR: return GEN6_BLENDFACTOR_INV_DST_COLOR; |
| 59 | case VK_BLEND_SRC_ALPHA: return GEN6_BLENDFACTOR_SRC_ALPHA; |
| 60 | case VK_BLEND_ONE_MINUS_SRC_ALPHA: return GEN6_BLENDFACTOR_INV_SRC_ALPHA; |
| 61 | case VK_BLEND_DEST_ALPHA: return GEN6_BLENDFACTOR_DST_ALPHA; |
| 62 | case VK_BLEND_ONE_MINUS_DEST_ALPHA: return GEN6_BLENDFACTOR_INV_DST_ALPHA; |
| 63 | case VK_BLEND_CONSTANT_COLOR: return GEN6_BLENDFACTOR_CONST_COLOR; |
| 64 | case VK_BLEND_ONE_MINUS_CONSTANT_COLOR: return GEN6_BLENDFACTOR_INV_CONST_COLOR; |
| 65 | case VK_BLEND_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_CONST_ALPHA; |
| 66 | case VK_BLEND_ONE_MINUS_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_INV_CONST_ALPHA; |
| 67 | case VK_BLEND_SRC_ALPHA_SATURATE: return GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE; |
| 68 | case VK_BLEND_SRC1_COLOR: return GEN6_BLENDFACTOR_SRC1_COLOR; |
| 69 | case VK_BLEND_ONE_MINUS_SRC1_COLOR: return GEN6_BLENDFACTOR_INV_SRC1_COLOR; |
| 70 | case VK_BLEND_SRC1_ALPHA: return GEN6_BLENDFACTOR_SRC1_ALPHA; |
| 71 | case VK_BLEND_ONE_MINUS_SRC1_ALPHA: return GEN6_BLENDFACTOR_INV_SRC1_ALPHA; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 72 | default: |
| 73 | assert(!"unknown blend factor"); |
| 74 | return GEN6_BLENDFACTOR_ONE; |
| 75 | }; |
| 76 | } |
| 77 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 78 | static int translate_compare_func(VkCompareOp func) |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 79 | { |
| 80 | switch (func) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 81 | case VK_COMPARE_OP_NEVER: return GEN6_COMPAREFUNCTION_NEVER; |
| 82 | case VK_COMPARE_OP_LESS: return GEN6_COMPAREFUNCTION_LESS; |
| 83 | case VK_COMPARE_OP_EQUAL: return GEN6_COMPAREFUNCTION_EQUAL; |
| 84 | case VK_COMPARE_OP_LESS_EQUAL: return GEN6_COMPAREFUNCTION_LEQUAL; |
| 85 | case VK_COMPARE_OP_GREATER: return GEN6_COMPAREFUNCTION_GREATER; |
| 86 | case VK_COMPARE_OP_NOT_EQUAL: return GEN6_COMPAREFUNCTION_NOTEQUAL; |
| 87 | case VK_COMPARE_OP_GREATER_EQUAL: return GEN6_COMPAREFUNCTION_GEQUAL; |
| 88 | case VK_COMPARE_OP_ALWAYS: return GEN6_COMPAREFUNCTION_ALWAYS; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 89 | default: |
| 90 | assert(!"unknown compare_func"); |
| 91 | return GEN6_COMPAREFUNCTION_NEVER; |
| 92 | } |
| 93 | } |
| 94 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 95 | static int translate_stencil_op(VkStencilOp op) |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 96 | { |
| 97 | switch (op) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 98 | case VK_STENCIL_OP_KEEP: return GEN6_STENCILOP_KEEP; |
| 99 | case VK_STENCIL_OP_ZERO: return GEN6_STENCILOP_ZERO; |
| 100 | case VK_STENCIL_OP_REPLACE: return GEN6_STENCILOP_REPLACE; |
| 101 | case VK_STENCIL_OP_INC_CLAMP: return GEN6_STENCILOP_INCRSAT; |
| 102 | case VK_STENCIL_OP_DEC_CLAMP: return GEN6_STENCILOP_DECRSAT; |
| 103 | case VK_STENCIL_OP_INVERT: return GEN6_STENCILOP_INVERT; |
| 104 | case VK_STENCIL_OP_INC_WRAP: return GEN6_STENCILOP_INCR; |
| 105 | case VK_STENCIL_OP_DEC_WRAP: return GEN6_STENCILOP_DECR; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 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 { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 113 | VkGraphicsPipelineCreateInfo graphics; |
| 114 | VkPipelineVertexInputCreateInfo vi; |
| 115 | VkPipelineIaStateCreateInfo ia; |
| 116 | VkPipelineDsStateCreateInfo db; |
| 117 | VkPipelineCbStateCreateInfo cb; |
| 118 | VkPipelineRsStateCreateInfo rs; |
| 119 | VkPipelineTessStateCreateInfo tess; |
| 120 | VkPipelineMsStateCreateInfo ms; |
| 121 | VkPipelineVpStateCreateInfo vp; |
| 122 | VkPipelineShader vs; |
| 123 | VkPipelineShader tcs; |
| 124 | VkPipelineShader tes; |
| 125 | VkPipelineShader gs; |
| 126 | VkPipelineShader fs; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 127 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 128 | VkComputePipelineCreateInfo compute; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 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; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 205 | VkResult ret; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 206 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 207 | sh = intel_alloc(dev, sizeof(*sh), 0, VK_SYSTEM_ALLOC_TYPE_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); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 213 | if (ret != VK_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, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 223 | VK_SHADER_STAGE_VERTEX); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 224 | break; |
| 225 | default: |
| 226 | sh->max_threads = intel_gpu_get_max_threads(dev->gpu, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 227 | VK_SHADER_STAGE_FRAGMENT); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 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 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 241 | static VkResult pipeline_build_shader(struct intel_pipeline *pipeline, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 242 | const VkPipelineShader *sh_info, |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 243 | struct intel_pipeline_shader *sh) |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 244 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 245 | VkResult ret; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 246 | |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 247 | ret = intel_pipeline_shader_compile(sh, |
Mark Lobodzinski | 556f721 | 2015-04-17 14:11:39 -0500 | [diff] [blame^] | 248 | pipeline->dev->gpu, pipeline->pipeline_layout, sh_info); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 249 | if (ret != VK_SUCCESS) |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 250 | return ret; |
| 251 | |
| 252 | sh->max_threads = |
| 253 | intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage); |
| 254 | |
| 255 | /* 1KB aligned */ |
| 256 | sh->scratch_offset = u_align(pipeline->scratch_size, 1024); |
| 257 | pipeline->scratch_size = sh->scratch_offset + |
| 258 | sh->per_thread_scratch_size * sh->max_threads; |
| 259 | |
| 260 | pipeline->active_shaders |= 1 << sh_info->stage; |
| 261 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 262 | return VK_SUCCESS; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 263 | } |
| 264 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 265 | static VkResult pipeline_build_shaders(struct intel_pipeline *pipeline, |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 266 | const struct intel_pipeline_create_info *info) |
| 267 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 268 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 269 | |
Chia-I Wu | df601c4 | 2015-04-17 01:58:07 +0800 | [diff] [blame] | 270 | if (ret == VK_SUCCESS && info->vs.shader) |
| 271 | ret = pipeline_build_shader(pipeline, &info->vs, &pipeline->vs); |
| 272 | if (ret == VK_SUCCESS && info->tcs.shader) |
| 273 | ret = pipeline_build_shader(pipeline, &info->tcs,&pipeline->tcs); |
| 274 | if (ret == VK_SUCCESS && info->tes.shader) |
| 275 | ret = pipeline_build_shader(pipeline, &info->tes,&pipeline->tes); |
| 276 | if (ret == VK_SUCCESS && info->gs.shader) |
| 277 | ret = pipeline_build_shader(pipeline, &info->gs, &pipeline->gs); |
| 278 | if (ret == VK_SUCCESS && info->fs.shader) |
| 279 | ret = pipeline_build_shader(pipeline, &info->fs, &pipeline->fs); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 280 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 281 | if (ret == VK_SUCCESS && info->compute.cs.shader) { |
Chia-I Wu | df601c4 | 2015-04-17 01:58:07 +0800 | [diff] [blame] | 282 | ret = pipeline_build_shader(pipeline, |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 283 | &info->compute.cs, &pipeline->cs); |
| 284 | } |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 285 | |
| 286 | return ret; |
| 287 | } |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 288 | static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len) |
| 289 | { |
| 290 | uint32_t *ptr; |
| 291 | |
| 292 | assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES); |
| 293 | ptr = &pipeline->cmds[pipeline->cmd_len]; |
| 294 | pipeline->cmd_len += cmd_len; |
| 295 | return ptr; |
| 296 | } |
| 297 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 298 | static VkResult pipeline_build_ia(struct intel_pipeline *pipeline, |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 299 | const struct intel_pipeline_create_info* info) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 300 | { |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 301 | pipeline->topology = info->ia.topology; |
| 302 | pipeline->disable_vs_cache = info->ia.disableVertexReuse; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 303 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 304 | switch (info->ia.topology) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 305 | case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 306 | pipeline->prim_type = GEN6_3DPRIM_POINTLIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 307 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 308 | case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 309 | pipeline->prim_type = GEN6_3DPRIM_LINELIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 310 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 311 | case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 312 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 313 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 314 | case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 315 | pipeline->prim_type = GEN6_3DPRIM_TRILIST; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 316 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 317 | case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 318 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 319 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 320 | case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: |
Courtney Goeltzenleuchter | 528781d | 2015-03-03 11:38:12 -0700 | [diff] [blame] | 321 | pipeline->prim_type = GEN6_3DPRIM_TRIFAN; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 322 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 323 | case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 324 | pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 325 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 326 | case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 327 | pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 328 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 329 | case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 330 | pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 331 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 332 | case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_ADJ: |
Courtney Goeltzenleuchter | 8a3de59 | 2014-08-22 09:09:46 -0600 | [diff] [blame] | 333 | pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 334 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 335 | case VK_PRIMITIVE_TOPOLOGY_PATCH: |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 336 | if (!info->tess.patchControlPoints || |
| 337 | info->tess.patchControlPoints > 32) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 338 | return VK_ERROR_BAD_PIPELINE_DATA; |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 339 | pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 + |
| 340 | info->tess.patchControlPoints - 1; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 341 | break; |
| 342 | default: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 343 | return VK_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 344 | } |
| 345 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 346 | if (info->ia.primitiveRestartEnable) { |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 347 | pipeline->primitive_restart = true; |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 348 | pipeline->primitive_restart_index = info->ia.primitiveRestartIndex; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 349 | } else { |
| 350 | pipeline->primitive_restart = false; |
| 351 | } |
| 352 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 353 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 354 | } |
| 355 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 356 | static VkResult pipeline_build_rs_state(struct intel_pipeline *pipeline, |
Chia-I Wu | 6abcb0e | 2015-03-24 14:38:14 +0800 | [diff] [blame] | 357 | const struct intel_pipeline_create_info* info) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 358 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 359 | const VkPipelineRsStateCreateInfo *rs_state = &info->rs; |
Chia-I Wu | 6abcb0e | 2015-03-24 14:38:14 +0800 | [diff] [blame] | 360 | bool ccw; |
| 361 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 362 | pipeline->depthClipEnable = rs_state->depthClipEnable; |
| 363 | pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable; |
Chia-I Wu | db3fbc4 | 2015-03-24 10:55:40 +0800 | [diff] [blame] | 364 | pipeline->use_rs_point_size = !rs_state->programPointSize; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 365 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 366 | if (rs_state->provokingVertex == VK_PROVOKING_VERTEX_FIRST) { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 367 | pipeline->provoking_vertex_tri = 0; |
| 368 | pipeline->provoking_vertex_trifan = 1; |
| 369 | pipeline->provoking_vertex_line = 0; |
| 370 | } else { |
| 371 | pipeline->provoking_vertex_tri = 2; |
| 372 | pipeline->provoking_vertex_trifan = 2; |
| 373 | pipeline->provoking_vertex_line = 1; |
| 374 | } |
| 375 | |
| 376 | switch (rs_state->fillMode) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 377 | case VK_FILL_MODE_POINTS: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 378 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT | |
| 379 | GEN7_SF_DW1_BACKFACE_POINT; |
| 380 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 381 | case VK_FILL_MODE_WIREFRAME: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 382 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME | |
| 383 | GEN7_SF_DW1_BACKFACE_WIREFRAME; |
| 384 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 385 | case VK_FILL_MODE_SOLID: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 386 | default: |
| 387 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID | |
| 388 | GEN7_SF_DW1_BACKFACE_SOLID; |
| 389 | break; |
| 390 | } |
| 391 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 392 | ccw = (rs_state->frontFace == VK_FRONT_FACE_CCW); |
Chia-I Wu | 6abcb0e | 2015-03-24 14:38:14 +0800 | [diff] [blame] | 393 | /* flip the winding order */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 394 | if (info->vp.clipOrigin == VK_COORDINATE_ORIGIN_LOWER_LEFT) |
Chia-I Wu | 6abcb0e | 2015-03-24 14:38:14 +0800 | [diff] [blame] | 395 | ccw = !ccw; |
| 396 | |
| 397 | if (ccw) { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 398 | pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW; |
| 399 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW; |
| 400 | } |
| 401 | |
| 402 | switch (rs_state->cullMode) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 403 | case VK_CULL_MODE_NONE: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 404 | default: |
| 405 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE; |
| 406 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE; |
| 407 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 408 | case VK_CULL_MODE_FRONT: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 409 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT; |
| 410 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT; |
| 411 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 412 | case VK_CULL_MODE_BACK: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 413 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK; |
| 414 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK; |
| 415 | break; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 416 | case VK_CULL_MODE_FRONT_AND_BACK: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 417 | pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH; |
| 418 | pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH; |
| 419 | break; |
| 420 | } |
| 421 | |
| 422 | /* only GEN7+ needs cull mode in 3DSTATE_CLIP */ |
| 423 | if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6)) |
| 424 | pipeline->cmd_clip_cull = 0; |
| 425 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 426 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 427 | } |
| 428 | |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 429 | static void pipeline_destroy(struct intel_obj *obj) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 430 | { |
| 431 | struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj); |
| 432 | |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 433 | if (pipeline->active_shaders & SHADER_VERTEX_FLAG) { |
Chia-I Wu | f13ed3c | 2015-02-22 14:09:00 +0800 | [diff] [blame] | 434 | intel_pipeline_shader_cleanup(&pipeline->vs, pipeline->dev->gpu); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) { |
Chia-I Wu | f13ed3c | 2015-02-22 14:09:00 +0800 | [diff] [blame] | 438 | intel_pipeline_shader_cleanup(&pipeline->tcs, pipeline->dev->gpu); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) { |
Chia-I Wu | f13ed3c | 2015-02-22 14:09:00 +0800 | [diff] [blame] | 442 | intel_pipeline_shader_cleanup(&pipeline->tes, pipeline->dev->gpu); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
Chia-I Wu | f13ed3c | 2015-02-22 14:09:00 +0800 | [diff] [blame] | 446 | intel_pipeline_shader_cleanup(&pipeline->gs, pipeline->dev->gpu); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) { |
Chia-I Wu | f13ed3c | 2015-02-22 14:09:00 +0800 | [diff] [blame] | 450 | intel_pipeline_shader_cleanup(&pipeline->fs, pipeline->dev->gpu); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) { |
Chia-I Wu | f13ed3c | 2015-02-22 14:09:00 +0800 | [diff] [blame] | 454 | intel_pipeline_shader_cleanup(&pipeline->cs, pipeline->dev->gpu); |
Chia-I Wu | 3f23983 | 2014-12-11 22:57:18 +0800 | [diff] [blame] | 455 | } |
Chia-I Wu | ed83387 | 2014-08-23 17:00:35 +0800 | [diff] [blame] | 456 | |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 457 | intel_base_destroy(&pipeline->obj.base); |
| 458 | } |
| 459 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 460 | static VkResult pipeline_get_info(struct intel_base *base, int type, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 461 | size_t *size, void *data) |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 462 | { |
| 463 | struct intel_pipeline *pipeline = intel_pipeline_from_base(base); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 464 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 465 | |
| 466 | switch (type) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 467 | case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS: |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 468 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 469 | VkMemoryRequirements *mem_req = data; |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 470 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 471 | *size = sizeof(VkMemoryRequirements); |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 472 | if (data) { |
| 473 | mem_req->size = pipeline->scratch_size; |
| 474 | mem_req->alignment = 1024; |
Jeremy Hayes | d02809a | 2015-04-15 14:17:56 -0600 | [diff] [blame] | 475 | mem_req->memPropsAllowed = INTEL_MEMORY_PROPERTY_ALL; |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | break; |
| 479 | default: |
| 480 | ret = intel_base_get_info(base, type, size, data); |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | return ret; |
| 485 | } |
| 486 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 487 | static VkResult pipeline_validate(struct intel_pipeline *pipeline) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 488 | { |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 489 | /* |
| 490 | * Validate required elements |
| 491 | */ |
| 492 | if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) { |
| 493 | // TODO: Log debug message: Vertex Shader required. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 494 | return VK_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /* |
| 498 | * Tessalation control and evaluation have to both have a shader defined or |
| 499 | * neither should have a shader defined. |
| 500 | */ |
| 501 | if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) != |
| 502 | ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) { |
| 503 | // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 504 | return VK_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) && |
| 508 | (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG | |
| 509 | SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG | |
| 510 | SHADER_FRAGMENT_FLAG))) { |
| 511 | // TODO: Log debug message: Can only specify compute shader when doing compute |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 512 | return VK_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /* |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 516 | * VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines. |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 517 | * Mismatching primitive topology and tessellation fails graphics pipeline creation. |
| 518 | */ |
| 519 | if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) && |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 520 | (pipeline->topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) { |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 521 | // TODO: Log debug message: Invalid topology used with tessalation shader. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 522 | return VK_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 523 | } |
| 524 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 525 | if ((pipeline->topology == VK_PRIMITIVE_TOPOLOGY_PATCH) && |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 526 | (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) { |
| 527 | // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 528 | return VK_ERROR_BAD_PIPELINE_DATA; |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 529 | } |
| 530 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 531 | return VK_SUCCESS; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 532 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 533 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 534 | static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline, |
| 535 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 536 | { |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 537 | const struct intel_gpu *gpu = pipeline->dev->gpu; |
| 538 | const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024; |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 539 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
| 540 | const struct intel_pipeline_shader *gs = &pipeline->gs; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 541 | int vs_entry_size, gs_entry_size; |
| 542 | int vs_size, gs_size; |
| 543 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 544 | INTEL_GPU_ASSERT(gpu, 6, 6); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 545 | |
| 546 | vs_entry_size = ((vs->in_count >= vs->out_count) ? |
| 547 | vs->in_count : vs->out_count); |
| 548 | gs_entry_size = (gs) ? gs->out_count : 0; |
| 549 | |
| 550 | /* in bytes */ |
| 551 | vs_entry_size *= sizeof(float) * 4; |
| 552 | gs_entry_size *= sizeof(float) * 4; |
| 553 | |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 554 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 555 | vs_size = urb_size / 2; |
| 556 | gs_size = vs_size; |
| 557 | } else { |
| 558 | vs_size = urb_size; |
| 559 | gs_size = 0; |
| 560 | } |
| 561 | |
| 562 | /* 3DSTATE_URB */ |
| 563 | { |
| 564 | const uint8_t cmd_len = 3; |
| 565 | const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | |
| 566 | (cmd_len - 2); |
| 567 | int vs_alloc_size, gs_alloc_size; |
| 568 | int vs_entry_count, gs_entry_count; |
| 569 | uint32_t *dw; |
| 570 | |
| 571 | /* in 1024-bit rows */ |
| 572 | vs_alloc_size = (vs_entry_size + 128 - 1) / 128; |
| 573 | gs_alloc_size = (gs_entry_size + 128 - 1) / 128; |
| 574 | |
| 575 | /* valid range is [1, 5] */ |
| 576 | if (!vs_alloc_size) |
| 577 | vs_alloc_size = 1; |
| 578 | if (!gs_alloc_size) |
| 579 | gs_alloc_size = 1; |
| 580 | assert(vs_alloc_size <= 5 && gs_alloc_size <= 5); |
| 581 | |
| 582 | /* valid range is [24, 256], multiples of 4 */ |
| 583 | vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3; |
| 584 | if (vs_entry_count > 256) |
| 585 | vs_entry_count = 256; |
| 586 | assert(vs_entry_count >= 24); |
| 587 | |
| 588 | /* valid range is [0, 256], multiples of 4 */ |
| 589 | gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3; |
| 590 | if (gs_entry_count > 256) |
| 591 | gs_entry_count = 256; |
| 592 | |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 593 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 594 | |
| 595 | dw[0] = dw0; |
| 596 | dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT | |
| 597 | vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT; |
| 598 | dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT | |
| 599 | (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT; |
| 600 | } |
| 601 | } |
| 602 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 603 | static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline, |
| 604 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 605 | { |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 606 | const struct intel_gpu *gpu = pipeline->dev->gpu; |
| 607 | const int urb_size = ((gpu->gt == 3) ? 512 : |
| 608 | (gpu->gt == 2) ? 256 : 128) * 1024; |
Cody Northrop | 306ec35 | 2014-10-06 15:11:45 -0600 | [diff] [blame] | 609 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
| 610 | const struct intel_pipeline_shader *gs = &pipeline->gs; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 611 | /* some space is reserved for PCBs */ |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 612 | int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 613 | int vs_entry_size, gs_entry_size; |
| 614 | int vs_size, gs_size; |
| 615 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 616 | INTEL_GPU_ASSERT(gpu, 7, 7.5); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 617 | |
| 618 | vs_entry_size = ((vs->in_count >= vs->out_count) ? |
| 619 | vs->in_count : vs->out_count); |
| 620 | gs_entry_size = (gs) ? gs->out_count : 0; |
| 621 | |
| 622 | /* in bytes */ |
| 623 | vs_entry_size *= sizeof(float) * 4; |
| 624 | gs_entry_size *= sizeof(float) * 4; |
| 625 | |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 626 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 627 | vs_size = (urb_size - urb_offset) / 2; |
| 628 | gs_size = vs_size; |
| 629 | } else { |
| 630 | vs_size = urb_size - urb_offset; |
| 631 | gs_size = 0; |
| 632 | } |
| 633 | |
| 634 | /* 3DSTATE_URB_* */ |
| 635 | { |
| 636 | const uint8_t cmd_len = 2; |
| 637 | int vs_alloc_size, gs_alloc_size; |
| 638 | int vs_entry_count, gs_entry_count; |
| 639 | uint32_t *dw; |
| 640 | |
| 641 | /* in 512-bit rows */ |
| 642 | vs_alloc_size = (vs_entry_size + 64 - 1) / 64; |
| 643 | gs_alloc_size = (gs_entry_size + 64 - 1) / 64; |
| 644 | |
| 645 | if (!vs_alloc_size) |
| 646 | vs_alloc_size = 1; |
| 647 | if (!gs_alloc_size) |
| 648 | gs_alloc_size = 1; |
| 649 | |
| 650 | /* avoid performance decrease due to banking */ |
| 651 | if (vs_alloc_size == 5) |
| 652 | vs_alloc_size = 6; |
| 653 | |
| 654 | /* in multiples of 8 */ |
| 655 | vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7; |
| 656 | assert(vs_entry_count >= 32); |
| 657 | |
| 658 | gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7; |
| 659 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 660 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) { |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 661 | const int max_vs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 662 | (gpu->gt >= 2) ? 1664 : 640; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 663 | const int max_gs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 664 | (gpu->gt >= 2) ? 640 : 256; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 665 | if (vs_entry_count >= max_vs_entry_count) |
| 666 | vs_entry_count = max_vs_entry_count; |
| 667 | if (gs_entry_count >= max_gs_entry_count) |
| 668 | gs_entry_count = max_gs_entry_count; |
| 669 | } else { |
| 670 | const int max_vs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 671 | (gpu->gt == 2) ? 704 : 512; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 672 | const int max_gs_entry_count = |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 673 | (gpu->gt == 2) ? 320 : 192; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 674 | if (vs_entry_count >= max_vs_entry_count) |
| 675 | vs_entry_count = max_vs_entry_count; |
| 676 | if (gs_entry_count >= max_gs_entry_count) |
| 677 | gs_entry_count = max_gs_entry_count; |
| 678 | } |
| 679 | |
Courtney Goeltzenleuchter | 814cd29 | 2014-08-28 13:16:27 -0600 | [diff] [blame] | 680 | dw = pipeline_cmd_ptr(pipeline, cmd_len*4); |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 681 | 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] | 682 | dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT | |
| 683 | (vs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT | |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 684 | vs_entry_count; |
| 685 | |
| 686 | dw += 2; |
| 687 | if (gs_size) |
| 688 | urb_offset += vs_size; |
| 689 | 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] | 690 | dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT | |
| 691 | (gs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT | |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 692 | gs_entry_count; |
| 693 | |
| 694 | dw += 2; |
| 695 | 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] | 696 | dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 697 | |
| 698 | dw += 2; |
| 699 | 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] | 700 | dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 704 | static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline, |
| 705 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 706 | { |
Cody Northrop | 306ec35 | 2014-10-06 15:11:45 -0600 | [diff] [blame] | 707 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 708 | uint8_t cmd_len; |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 709 | uint32_t *dw; |
Courtney Goeltzenleuchter | f5cdad0 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 710 | uint32_t i, j; |
| 711 | uint32_t attr_count; |
| 712 | uint32_t attrs_processed; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 713 | int comps[4]; |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 714 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 715 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 716 | |
Courtney Goeltzenleuchter | f5cdad0 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 717 | attr_count = u_popcountll(vs->inputs_read); |
| 718 | cmd_len = 1 + 2 * attr_count; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 719 | if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) |
| 720 | cmd_len += 2; |
| 721 | |
| 722 | if (cmd_len == 1) |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 723 | return; |
| 724 | |
| 725 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 726 | |
| 727 | dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | |
| 728 | (cmd_len - 2); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 729 | dw++; |
| 730 | |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 731 | /* VERTEX_ELEMENT_STATE */ |
Courtney Goeltzenleuchter | f5cdad0 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 732 | for (i = 0, attrs_processed = 0; attrs_processed < attr_count; i++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 733 | VkVertexInputAttributeDescription *attr = NULL; |
Courtney Goeltzenleuchter | f5cdad0 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 734 | |
| 735 | /* |
| 736 | * The compiler will pack the shader references and then |
| 737 | * indicate which locations are used via the bitmask in |
| 738 | * vs->inputs_read. |
| 739 | */ |
| 740 | if (!(vs->inputs_read & (1L << i))) { |
GregF | 2dc4021 | 2014-10-31 17:31:47 -0600 | [diff] [blame] | 741 | continue; |
Courtney Goeltzenleuchter | f5cdad0 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /* |
| 745 | * For each bit set in the vs->inputs_read we'll need |
| 746 | * to find the corresponding attribute record and then |
| 747 | * set up the next HW vertex element based on that attribute. |
| 748 | */ |
| 749 | for (j = 0; j < info->vi.attributeCount; j++) { |
| 750 | if (info->vi.pVertexAttributeDescriptions[j].location == i) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 751 | attr = (VkVertexInputAttributeDescription *) &info->vi.pVertexAttributeDescriptions[j]; |
Courtney Goeltzenleuchter | f5cdad0 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 752 | attrs_processed++; |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | assert(attr != NULL); |
| 757 | |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 758 | const int format = |
| 759 | intel_format_translate_color(pipeline->dev->gpu, attr->format); |
| 760 | |
| 761 | comps[0] = GEN6_VFCOMP_STORE_0; |
| 762 | comps[1] = GEN6_VFCOMP_STORE_0; |
| 763 | comps[2] = GEN6_VFCOMP_STORE_0; |
| 764 | comps[3] = icd_format_is_int(attr->format) ? |
| 765 | GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP; |
| 766 | |
| 767 | switch (icd_format_get_channel_count(attr->format)) { |
| 768 | case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */ |
| 769 | case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */ |
| 770 | case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */ |
| 771 | case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break; |
| 772 | default: |
| 773 | break; |
| 774 | } |
| 775 | |
| 776 | assert(attr->offsetInBytes <= 2047); |
| 777 | |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 778 | dw[0] = attr->binding << GEN6_VE_DW0_VB_INDEX__SHIFT | |
| 779 | GEN6_VE_DW0_VALID | |
| 780 | format << GEN6_VE_DW0_FORMAT__SHIFT | |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 781 | attr->offsetInBytes; |
| 782 | |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 783 | dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT | |
| 784 | comps[1] << GEN6_VE_DW1_COMP1__SHIFT | |
| 785 | comps[2] << GEN6_VE_DW1_COMP2__SHIFT | |
| 786 | comps[3] << GEN6_VE_DW1_COMP3__SHIFT; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 787 | |
| 788 | dw += 2; |
| 789 | } |
GregF | 932fcf5 | 2014-10-29 17:02:11 -0600 | [diff] [blame] | 790 | |
| 791 | if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) { |
| 792 | comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ? |
| 793 | GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0; |
| 794 | comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ? |
| 795 | GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE; |
| 796 | comps[2] = GEN6_VFCOMP_NOSTORE; |
| 797 | comps[3] = GEN6_VFCOMP_NOSTORE; |
| 798 | |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 799 | dw[0] = GEN6_VE_DW0_VALID; |
| 800 | dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT | |
| 801 | comps[1] << GEN6_VE_DW1_COMP1__SHIFT | |
| 802 | comps[2] << GEN6_VE_DW1_COMP2__SHIFT | |
| 803 | comps[3] << GEN6_VE_DW1_COMP3__SHIFT; |
GregF | 932fcf5 | 2014-10-29 17:02:11 -0600 | [diff] [blame] | 804 | |
| 805 | dw += 2; |
| 806 | } |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 807 | } |
| 808 | |
Chia-I Wu | b638620 | 2015-03-24 11:13:06 +0800 | [diff] [blame] | 809 | static void pipeline_build_viewport(struct intel_pipeline *pipeline, |
| 810 | const struct intel_pipeline_create_info *info) |
| 811 | { |
| 812 | switch (info->vp.depthMode) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 813 | case VK_DEPTH_MODE_ZERO_TO_ONE: |
Chia-I Wu | b638620 | 2015-03-24 11:13:06 +0800 | [diff] [blame] | 814 | pipeline->depth_zero_to_one = true; |
| 815 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 816 | case VK_DEPTH_MODE_NEGATIVE_ONE_TO_ONE: |
Chia-I Wu | b638620 | 2015-03-24 11:13:06 +0800 | [diff] [blame] | 817 | default: |
| 818 | pipeline->depth_zero_to_one = false; |
| 819 | break; |
| 820 | } |
| 821 | } |
| 822 | |
Chia-I Wu | 86a5e0c | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 823 | static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline, |
| 824 | const struct intel_pipeline_create_info *info) |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 825 | { |
| 826 | const struct intel_pipeline_shader *fs = &pipeline->fs; |
| 827 | const struct intel_pipeline_shader *vs = &pipeline->vs; |
| 828 | uint8_t cmd_len; |
| 829 | uint32_t *body; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 830 | uint32_t attr_skip, attr_count; |
| 831 | uint32_t vue_offset, vue_len; |
| 832 | uint32_t i; |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 833 | |
| 834 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
| 835 | |
| 836 | cmd_len = 14; |
| 837 | |
Chia-I Wu | f85def4 | 2015-01-29 00:34:24 +0800 | [diff] [blame] | 838 | if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) |
| 839 | body = pipeline_cmd_ptr(pipeline, cmd_len); |
| 840 | else |
| 841 | body = pipeline->cmd_3dstate_sbe; |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 842 | |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 843 | assert(!fs->reads_user_clip || vs->enable_user_clip); |
| 844 | attr_skip = vs->outputs_offset; |
| 845 | if (vs->enable_user_clip != fs->reads_user_clip) { |
| 846 | attr_skip += 2; |
| 847 | } |
| 848 | assert(vs->out_count >= attr_skip); |
| 849 | attr_count = vs->out_count - attr_skip; |
| 850 | |
| 851 | // LUNARG TODO: We currently are only handling 16 attrs; |
| 852 | // ultimately, we need to handle 32 |
| 853 | assert(fs->in_count <= 16); |
| 854 | assert(attr_count <= 16); |
| 855 | |
| 856 | vue_offset = attr_skip / 2; |
| 857 | vue_len = (attr_count + 1) / 2; |
| 858 | if (!vue_len) |
| 859 | vue_len = 1; |
| 860 | |
| 861 | body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | |
| 862 | (cmd_len - 2); |
| 863 | |
| 864 | // LUNARG TODO: If the attrs needed by the FS are exactly |
| 865 | // what is written by the VS, we don't need to enable |
| 866 | // swizzling, improving performance. Even if we swizzle, |
| 867 | // we can improve performance by reducing vue_len to |
| 868 | // just include the values needed by the FS: |
| 869 | // vue_len = ceiling((max_vs_out + 1)/2) |
| 870 | |
| 871 | body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE | |
| 872 | fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT | |
| 873 | vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT | |
| 874 | vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT; |
| 875 | |
Chia-I Wu | 86a5e0c | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 876 | switch (info->rs.pointOrigin) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 877 | case VK_COORDINATE_ORIGIN_UPPER_LEFT: |
Chia-I Wu | 86a5e0c | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 878 | body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT; |
| 879 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 880 | case VK_COORDINATE_ORIGIN_LOWER_LEFT: |
Chia-I Wu | 86a5e0c | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 881 | body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_LOWERLEFT; |
| 882 | break; |
| 883 | default: |
| 884 | assert(!"unknown point origin"); |
| 885 | break; |
| 886 | } |
| 887 | |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 888 | uint16_t vs_slot[fs->in_count]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 889 | int32_t fs_in = 0; |
| 890 | int32_t vs_out = - (vue_offset * 2 - vs->outputs_offset); |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 891 | for (i=0; i < 64; i++) { |
Cody Northrop | d75c13e | 2015-01-02 14:07:20 -0700 | [diff] [blame] | 892 | bool vsWrites = vs->outputs_written & (1L << i); |
| 893 | bool fsReads = fs->inputs_read & (1L << i); |
| 894 | |
| 895 | if (fsReads) { |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 896 | assert(vs_out >= 0); |
| 897 | assert(fs_in < fs->in_count); |
| 898 | vs_slot[fs_in] = vs_out; |
Cody Northrop | d75c13e | 2015-01-02 14:07:20 -0700 | [diff] [blame] | 899 | |
| 900 | if (!vsWrites) { |
| 901 | // If the vertex shader did not write this input, we cannot |
| 902 | // program the SBE to read it. Our choices are to allow it to |
| 903 | // read junk from a GRF, or get zero. We're choosing zero. |
| 904 | if (i >= fs->generic_input_start) { |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 905 | vs_slot[fs_in] = GEN8_SBE_SWIZ_CONST_0000 | |
| 906 | GEN8_SBE_SWIZ_OVERRIDE_X | |
| 907 | GEN8_SBE_SWIZ_OVERRIDE_Y | |
| 908 | GEN8_SBE_SWIZ_OVERRIDE_Z | |
| 909 | GEN8_SBE_SWIZ_OVERRIDE_W; |
Cody Northrop | d75c13e | 2015-01-02 14:07:20 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 913 | fs_in += 1; |
| 914 | } |
Cody Northrop | d75c13e | 2015-01-02 14:07:20 -0700 | [diff] [blame] | 915 | if (vsWrites) { |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 916 | vs_out += 1; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | for (i = 0; i < 8; i++) { |
| 921 | uint16_t hi, lo; |
| 922 | |
| 923 | /* no attr swizzles */ |
| 924 | if (i * 2 + 1 < fs->in_count) { |
| 925 | lo = vs_slot[i * 2]; |
| 926 | hi = vs_slot[i * 2 + 1]; |
| 927 | } else if (i * 2 < fs->in_count) { |
| 928 | lo = vs_slot[i * 2]; |
| 929 | hi = 0; |
| 930 | } else { |
| 931 | hi = 0; |
| 932 | lo = 0; |
| 933 | } |
| 934 | |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 935 | body[2 + i] = hi << GEN8_SBE_SWIZ_HIGH__SHIFT | lo; |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 938 | if (info->ia.topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST) |
Chia-I Wu | 7f39056 | 2015-03-25 08:47:18 +0800 | [diff] [blame] | 939 | body[10] = fs->point_sprite_enables; |
| 940 | else |
| 941 | body[10] = 0; |
Chia-I Wu | 86a5e0c | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 942 | |
GregF | 8cd8183 | 2014-11-18 18:01:01 -0700 | [diff] [blame] | 943 | body[11] = 0; /* constant interpolation enables */ |
| 944 | body[12] = 0; /* WrapShortest enables */ |
| 945 | body[13] = 0; |
| 946 | } |
| 947 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 948 | static void pipeline_build_gs(struct intel_pipeline *pipeline, |
| 949 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 950 | { |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 951 | // gen7_emit_3DSTATE_GS done by cmd_pipeline |
Courtney Goeltzenleuchter | b286770 | 2014-08-28 17:44:05 -0600 | [diff] [blame] | 952 | } |
| 953 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 954 | static void pipeline_build_hs(struct intel_pipeline *pipeline, |
| 955 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 956 | { |
| 957 | const uint8_t cmd_len = 7; |
| 958 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2); |
| 959 | uint32_t *dw; |
| 960 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 961 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 962 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 963 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 964 | dw[0] = dw0; |
| 965 | dw[1] = 0; |
| 966 | dw[2] = 0; |
| 967 | dw[3] = 0; |
| 968 | dw[4] = 0; |
| 969 | dw[5] = 0; |
| 970 | dw[6] = 0; |
| 971 | } |
| 972 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 973 | static void pipeline_build_te(struct intel_pipeline *pipeline, |
| 974 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 975 | { |
| 976 | const uint8_t cmd_len = 4; |
| 977 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2); |
| 978 | uint32_t *dw; |
| 979 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 980 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 981 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 982 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 983 | dw[0] = dw0; |
| 984 | dw[1] = 0; |
| 985 | dw[2] = 0; |
| 986 | dw[3] = 0; |
| 987 | } |
| 988 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 989 | static void pipeline_build_ds(struct intel_pipeline *pipeline, |
| 990 | const struct intel_pipeline_create_info *info) |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 991 | { |
| 992 | const uint8_t cmd_len = 6; |
| 993 | const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2); |
| 994 | uint32_t *dw; |
| 995 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 996 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 997 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 998 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Courtney Goeltzenleuchter | dee81a6 | 2014-08-28 18:05:24 -0600 | [diff] [blame] | 999 | dw[0] = dw0; |
| 1000 | dw[1] = 0; |
| 1001 | dw[2] = 0; |
| 1002 | dw[3] = 0; |
| 1003 | dw[4] = 0; |
| 1004 | dw[5] = 0; |
| 1005 | } |
| 1006 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1007 | static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline, |
| 1008 | const struct intel_pipeline_create_info *info) |
| 1009 | { |
| 1010 | pipeline->cmd_depth_stencil = 0; |
| 1011 | |
| 1012 | if (info->db.stencilTestEnable) { |
| 1013 | pipeline->cmd_depth_stencil = 1 << 31 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1014 | translate_compare_func(info->db.front.stencilCompareOp) << 28 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1015 | translate_stencil_op(info->db.front.stencilFailOp) << 25 | |
| 1016 | translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 | |
| 1017 | translate_stencil_op(info->db.front.stencilPassOp) << 19 | |
| 1018 | 1 << 15 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1019 | translate_compare_func(info->db.back.stencilCompareOp) << 12 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1020 | translate_stencil_op(info->db.back.stencilFailOp) << 9 | |
| 1021 | translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 | |
| 1022 | translate_stencil_op(info->db.back.stencilPassOp) << 3; |
| 1023 | } |
| 1024 | |
| 1025 | pipeline->stencilTestEnable = info->db.stencilTestEnable; |
| 1026 | |
| 1027 | /* |
| 1028 | * From the Sandy Bridge PRM, volume 2 part 1, page 360: |
| 1029 | * |
| 1030 | * "Enabling the Depth Test function without defining a Depth Buffer is |
| 1031 | * UNDEFINED." |
| 1032 | * |
| 1033 | * From the Sandy Bridge PRM, volume 2 part 1, page 375: |
| 1034 | * |
| 1035 | * "A Depth Buffer must be defined before enabling writes to it, or |
| 1036 | * operation is UNDEFINED." |
| 1037 | * |
| 1038 | * TODO We do not check these yet. |
| 1039 | */ |
| 1040 | if (info->db.depthTestEnable) { |
| 1041 | pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1042 | translate_compare_func(info->db.depthCompareOp) << 27; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1043 | } else { |
| 1044 | pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27; |
| 1045 | } |
| 1046 | |
| 1047 | if (info->db.depthWriteEnable) |
| 1048 | pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE; |
| 1049 | } |
| 1050 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1051 | static void pipeline_build_msaa(struct intel_pipeline *pipeline, |
| 1052 | const struct intel_pipeline_create_info *info) |
| 1053 | { |
| 1054 | uint32_t cmd, cmd_len; |
| 1055 | uint32_t *dw; |
| 1056 | |
| 1057 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
| 1058 | |
Chia-I Wu | 8ada424 | 2015-03-02 11:19:33 -0700 | [diff] [blame] | 1059 | pipeline->sample_count = (info->ms.samples <= 1) ? 1 : info->ms.samples; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1060 | |
| 1061 | /* 3DSTATE_SAMPLE_MASK */ |
| 1062 | cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK); |
| 1063 | cmd_len = 2; |
| 1064 | |
Chia-I Wu | 8ada424 | 2015-03-02 11:19:33 -0700 | [diff] [blame] | 1065 | dw = pipeline_cmd_ptr(pipeline, cmd_len); |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1066 | dw[0] = cmd | (cmd_len - 2); |
| 1067 | dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1); |
| 1068 | pipeline->cmd_sample_mask = dw[1]; |
| 1069 | } |
| 1070 | |
| 1071 | static void pipeline_build_cb(struct intel_pipeline *pipeline, |
| 1072 | const struct intel_pipeline_create_info *info) |
| 1073 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1074 | uint32_t i; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1075 | |
| 1076 | INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5); |
| 1077 | STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2); |
| 1078 | assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS); |
| 1079 | |
| 1080 | uint32_t *dw = pipeline->cmd_cb; |
| 1081 | |
| 1082 | for (i = 0; i < info->cb.attachmentCount; i++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1083 | const VkPipelineCbAttachmentState *att = &info->cb.pAttachments[i]; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1084 | uint32_t dw0, dw1; |
| 1085 | |
| 1086 | |
| 1087 | dw0 = 0; |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 1088 | dw1 = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | |
| 1089 | GEN6_RT_DW1_PRE_BLEND_CLAMP | |
| 1090 | GEN6_RT_DW1_POST_BLEND_CLAMP; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1091 | |
| 1092 | if (att->blendEnable) { |
| 1093 | dw0 = 1 << 31 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1094 | translate_blend_func(att->blendOpAlpha) << 26 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1095 | translate_blend(att->srcBlendAlpha) << 20 | |
| 1096 | translate_blend(att->destBlendAlpha) << 15 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1097 | translate_blend_func(att->blendOpColor) << 11 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1098 | translate_blend(att->srcBlendColor) << 5 | |
| 1099 | translate_blend(att->destBlendColor); |
| 1100 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1101 | if (att->blendOpAlpha != att->blendOpColor || |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1102 | att->srcBlendAlpha != att->srcBlendColor || |
| 1103 | att->destBlendAlpha != att->destBlendColor) |
| 1104 | dw0 |= 1 << 30; |
Courtney Goeltzenleuchter | df13a4d | 2015-02-11 14:14:45 -0700 | [diff] [blame] | 1105 | |
| 1106 | 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] | 1107 | } |
| 1108 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1109 | if (info->cb.logicOp != VK_LOGIC_OP_COPY) { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1110 | int logicop; |
| 1111 | |
| 1112 | switch (info->cb.logicOp) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1113 | case VK_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break; |
| 1114 | case VK_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break; |
| 1115 | case VK_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break; |
| 1116 | case VK_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break; |
| 1117 | case VK_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break; |
| 1118 | case VK_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break; |
| 1119 | case VK_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break; |
| 1120 | case VK_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break; |
| 1121 | case VK_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break; |
| 1122 | case VK_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break; |
| 1123 | case VK_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break; |
| 1124 | case VK_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break; |
| 1125 | case VK_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break; |
| 1126 | case VK_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break; |
| 1127 | case VK_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1128 | default: |
| 1129 | assert(!"unknown logic op"); |
| 1130 | logicop = GEN6_LOGICOP_CLEAR; |
| 1131 | break; |
| 1132 | } |
| 1133 | |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 1134 | dw1 |= GEN6_RT_DW1_LOGICOP_ENABLE | |
| 1135 | logicop << GEN6_RT_DW1_LOGICOP_FUNC__SHIFT; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | if (!(att->channelWriteMask & 0x1)) |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 1139 | dw1 |= GEN6_RT_DW1_WRITE_DISABLE_R; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1140 | if (!(att->channelWriteMask & 0x2)) |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 1141 | dw1 |= GEN6_RT_DW1_WRITE_DISABLE_G; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1142 | if (!(att->channelWriteMask & 0x4)) |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 1143 | dw1 |= GEN6_RT_DW1_WRITE_DISABLE_B; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1144 | if (!(att->channelWriteMask & 0x8)) |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 1145 | dw1 |= GEN6_RT_DW1_WRITE_DISABLE_A; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1146 | |
| 1147 | dw[2 * i] = dw0; |
| 1148 | dw[2 * i + 1] = dw1; |
| 1149 | } |
| 1150 | |
| 1151 | for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++) |
| 1152 | { |
| 1153 | dw[2 * i] = 0; |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 1154 | dw[2 * i + 1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | |
| 1155 | GEN6_RT_DW1_PRE_BLEND_CLAMP | |
| 1156 | GEN6_RT_DW1_POST_BLEND_CLAMP | |
| 1157 | GEN6_RT_DW1_WRITE_DISABLE_R | |
| 1158 | GEN6_RT_DW1_WRITE_DISABLE_G | |
| 1159 | GEN6_RT_DW1_WRITE_DISABLE_B | |
| 1160 | GEN6_RT_DW1_WRITE_DISABLE_A; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | } |
| 1164 | |
| 1165 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1166 | static VkResult pipeline_build_all(struct intel_pipeline *pipeline, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1167 | const struct intel_pipeline_create_info *info) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1168 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1169 | VkResult ret; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1170 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 1171 | ret = pipeline_build_shaders(pipeline, info); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1172 | if (ret != VK_SUCCESS) |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 1173 | return ret; |
| 1174 | |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 1175 | if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) || |
| 1176 | info->vi.attributeCount > ARRAY_SIZE(pipeline->vb)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1177 | return VK_ERROR_BAD_PIPELINE_DATA; |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 1178 | |
| 1179 | pipeline->vb_count = info->vi.bindingCount; |
| 1180 | memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions, |
| 1181 | sizeof(pipeline->vb[0]) * pipeline->vb_count); |
| 1182 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1183 | pipeline_build_vertex_elements(pipeline, info); |
Chia-I Wu | b638620 | 2015-03-24 11:13:06 +0800 | [diff] [blame] | 1184 | pipeline_build_viewport(pipeline, info); |
Chia-I Wu | 86a5e0c | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 1185 | pipeline_build_fragment_SBE(pipeline, info); |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1186 | pipeline_build_msaa(pipeline, info); |
Chia-I Wu | 5bdb096 | 2015-01-24 12:49:28 +0800 | [diff] [blame] | 1187 | pipeline_build_depth_stencil(pipeline, info); |
Chia-I Wu | 4d9ad91 | 2014-08-29 14:20:36 +0800 | [diff] [blame] | 1188 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 1189 | if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1190 | pipeline_build_urb_alloc_gen7(pipeline, info); |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1191 | pipeline_build_gs(pipeline, info); |
| 1192 | pipeline_build_hs(pipeline, info); |
| 1193 | pipeline_build_te(pipeline, info); |
| 1194 | pipeline_build_ds(pipeline, info); |
Chia-I Wu | 8370b40 | 2014-08-29 12:28:37 +0800 | [diff] [blame] | 1195 | |
| 1196 | pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE | |
| 1197 | INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL | |
| 1198 | INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE | |
| 1199 | INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL | |
| 1200 | INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 1201 | } else { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1202 | pipeline_build_urb_alloc_gen6(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; |
Chia-I Wu | bb2d8ca | 2014-08-28 23:15:48 +0800 | [diff] [blame] | 1206 | } |
| 1207 | |
Chia-I Wu | be0a3d9 | 2014-09-02 13:20:59 +0800 | [diff] [blame] | 1208 | ret = pipeline_build_ia(pipeline, info); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1209 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1210 | if (ret == VK_SUCCESS) |
Chia-I Wu | 6abcb0e | 2015-03-24 14:38:14 +0800 | [diff] [blame] | 1211 | ret = pipeline_build_rs_state(pipeline, info); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1212 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1213 | if (ret == VK_SUCCESS) { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1214 | pipeline->db_format = info->db.format; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1215 | pipeline_build_cb(pipeline, info); |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1216 | pipeline->cb_state = info->cb; |
| 1217 | pipeline->tess_state = info->tess; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | return ret; |
| 1221 | } |
| 1222 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1223 | struct intel_pipeline_create_info_header { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1224 | VkStructureType struct_type; |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1225 | const struct intel_pipeline_create_info_header *next; |
| 1226 | }; |
| 1227 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1228 | static VkResult pipeline_create_info_init(struct intel_pipeline_create_info *info, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1229 | const struct intel_pipeline_create_info_header *header) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1230 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1231 | memset(info, 0, sizeof(*info)); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1232 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1233 | |
| 1234 | /* |
| 1235 | * Do we need to set safe defaults in case the app doesn't provide all of |
| 1236 | * the necessary create infos? |
| 1237 | */ |
| 1238 | info->ms.samples = 1; |
| 1239 | info->ms.sampleMask = 1; |
| 1240 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1241 | while (header) { |
| 1242 | const void *src = (const void *) header; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1243 | size_t size; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1244 | void *dst; |
| 1245 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1246 | switch (header->struct_type) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1247 | case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1248 | size = sizeof(info->graphics); |
| 1249 | dst = &info->graphics; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1250 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1251 | case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO: |
Chia-I Wu | 1d12509 | 2014-10-08 08:49:38 +0800 | [diff] [blame] | 1252 | size = sizeof(info->vi); |
| 1253 | dst = &info->vi; |
| 1254 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1255 | case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1256 | size = sizeof(info->ia); |
| 1257 | dst = &info->ia; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1258 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1259 | case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1260 | size = sizeof(info->db); |
| 1261 | dst = &info->db; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1262 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1263 | case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1264 | size = sizeof(info->cb); |
| 1265 | dst = &info->cb; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1266 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1267 | case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1268 | size = sizeof(info->rs); |
| 1269 | dst = &info->rs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1270 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1271 | case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1272 | size = sizeof(info->tess); |
| 1273 | dst = &info->tess; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1274 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1275 | case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1276 | size = sizeof(info->ms); |
| 1277 | dst = &info->ms; |
| 1278 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1279 | case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO: |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1280 | size = sizeof(info->vp); |
| 1281 | dst = &info->vp; |
| 1282 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1283 | case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO: |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1284 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1285 | const VkPipelineShader *shader = |
| 1286 | (const VkPipelineShader *) (header + 1); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1287 | |
| 1288 | src = (const void *) shader; |
| 1289 | size = sizeof(*shader); |
| 1290 | |
| 1291 | switch (shader->stage) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1292 | case VK_SHADER_STAGE_VERTEX: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1293 | dst = &info->vs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1294 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1295 | case VK_SHADER_STAGE_TESS_CONTROL: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1296 | dst = &info->tcs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1297 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1298 | case VK_SHADER_STAGE_TESS_EVALUATION: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1299 | dst = &info->tes; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1300 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1301 | case VK_SHADER_STAGE_GEOMETRY: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1302 | dst = &info->gs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1303 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1304 | case VK_SHADER_STAGE_FRAGMENT: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1305 | dst = &info->fs; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1306 | break; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1307 | default: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1308 | return VK_ERROR_BAD_PIPELINE_DATA; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1313 | case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO: |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1314 | size = sizeof(info->compute); |
| 1315 | dst = &info->compute; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1316 | break; |
| 1317 | default: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1318 | return VK_ERROR_BAD_PIPELINE_DATA; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1319 | break; |
| 1320 | } |
| 1321 | |
| 1322 | memcpy(dst, src, size); |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1323 | header = header->next; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1324 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1325 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1326 | return VK_SUCCESS; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1327 | } |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1328 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1329 | static VkResult graphics_pipeline_create(struct intel_dev *dev, |
| 1330 | const VkGraphicsPipelineCreateInfo *info_, |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1331 | struct intel_pipeline **pipeline_ret) |
| 1332 | { |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1333 | struct intel_pipeline_create_info info; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1334 | struct intel_pipeline *pipeline; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1335 | VkResult ret; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1336 | |
Chia-I Wu | 509b3f2 | 2014-09-02 10:24:05 +0800 | [diff] [blame] | 1337 | ret = pipeline_create_info_init(&info, |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1338 | (const struct intel_pipeline_create_info_header *) info_); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1339 | if (ret != VK_SUCCESS) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1340 | return ret; |
| 1341 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 1342 | pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle, |
| 1343 | sizeof(*pipeline), dev->base.dbg, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1344 | VK_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0); |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1345 | if (!pipeline) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1346 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1347 | |
| 1348 | pipeline->dev = dev; |
Mark Lobodzinski | 556f721 | 2015-04-17 14:11:39 -0500 | [diff] [blame^] | 1349 | pipeline->pipeline_layout = |
| 1350 | intel_pipeline_layout(info.graphics.layout); |
Chia-I Wu | df601c4 | 2015-04-17 01:58:07 +0800 | [diff] [blame] | 1351 | |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 1352 | pipeline->obj.base.get_info = pipeline_get_info; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1353 | pipeline->obj.destroy = pipeline_destroy; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1354 | |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1355 | ret = pipeline_build_all(pipeline, &info); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1356 | if (ret == VK_SUCCESS) |
Chia-I Wu | f90ff0c | 2014-09-02 09:32:46 +0800 | [diff] [blame] | 1357 | ret = pipeline_validate(pipeline); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1358 | if (ret != VK_SUCCESS) { |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1359 | pipeline_destroy(&pipeline->obj); |
| 1360 | return ret; |
| 1361 | } |
| 1362 | |
| 1363 | *pipeline_ret = pipeline; |
| 1364 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1365 | return VK_SUCCESS; |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1366 | } |
| 1367 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1368 | ICD_EXPORT VkResult VKAPI vkCreateGraphicsPipeline( |
| 1369 | VkDevice device, |
| 1370 | const VkGraphicsPipelineCreateInfo* pCreateInfo, |
| 1371 | VkPipeline* pPipeline) |
Chia-I Wu | 3efef43 | 2014-08-28 15:00:16 +0800 | [diff] [blame] | 1372 | { |
| 1373 | struct intel_dev *dev = intel_dev(device); |
| 1374 | |
| 1375 | return graphics_pipeline_create(dev, pCreateInfo, |
| 1376 | (struct intel_pipeline **) pPipeline); |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1377 | } |
| 1378 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1379 | ICD_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative( |
| 1380 | VkDevice device, |
| 1381 | const VkGraphicsPipelineCreateInfo* pCreateInfo, |
| 1382 | VkPipeline basePipeline, |
| 1383 | VkPipeline* pPipeline) |
Courtney Goeltzenleuchter | 32876a1 | 2015-03-25 15:37:49 -0600 | [diff] [blame] | 1384 | { |
| 1385 | struct intel_dev *dev = intel_dev(device); |
| 1386 | |
| 1387 | /* TODO: Use basePipeline to optimize creation of derivative */ |
| 1388 | |
| 1389 | return graphics_pipeline_create(dev, pCreateInfo, |
| 1390 | (struct intel_pipeline **) pPipeline); |
| 1391 | } |
| 1392 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1393 | ICD_EXPORT VkResult VKAPI vkCreateComputePipeline( |
| 1394 | VkDevice device, |
| 1395 | const VkComputePipelineCreateInfo* pCreateInfo, |
| 1396 | VkPipeline* pPipeline) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1397 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1398 | return VK_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1399 | } |
| 1400 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1401 | ICD_EXPORT VkResult VKAPI vkStorePipeline( |
| 1402 | VkPipeline pipeline, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1403 | size_t* pDataSize, |
| 1404 | void* pData) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1405 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1406 | return VK_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1407 | } |
| 1408 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1409 | ICD_EXPORT VkResult VKAPI vkLoadPipeline( |
| 1410 | VkDevice device, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1411 | size_t dataSize, |
| 1412 | const void* pData, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1413 | VkPipeline* pPipeline) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1414 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1415 | return VK_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1416 | } |
| 1417 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1418 | ICD_EXPORT VkResult VKAPI vkLoadPipelineDerivative( |
| 1419 | VkDevice device, |
Courtney Goeltzenleuchter | 32876a1 | 2015-03-25 15:37:49 -0600 | [diff] [blame] | 1420 | size_t dataSize, |
| 1421 | const void* pData, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1422 | VkPipeline basePipeline, |
| 1423 | VkPipeline* pPipeline) |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1424 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1425 | return VK_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | 05a6054 | 2014-08-15 14:54:34 -0600 | [diff] [blame] | 1426 | } |