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