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