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