blob: 50ba4e946e82f991ca880aa0a7308c40757a3edd [file] [log] [blame]
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06003 *
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 Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Courtney Goeltzenleuchter <courtney@lunarg.com>
26 * Chia-I Wu <olv@lunarg.com>
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060027 */
28
Chia-I Wu8370b402014-08-29 12:28:37 +080029#include "genhw/genhw.h"
Chia-I Wu3f239832014-12-11 22:57:18 +080030#include "compiler/pipeline/pipeline_compiler_interface.h"
Chia-I Wu8370b402014-08-29 12:28:37 +080031#include "cmd.h"
Chia-I Wu1d125092014-10-08 08:49:38 +080032#include "format.h"
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -060033#include "shader.h"
Chia-I Wu3f239832014-12-11 22:57:18 +080034#include "pipeline.h"
Tony Barbour2094dc72015-07-09 15:26:32 -060035#include "mem.h"
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060036
Tony Barbour8205d902015-04-16 15:59:00 -060037static int translate_blend_func(VkBlendOp func)
Tony Barbourfa6cac72015-01-16 14:27:35 -070038{
39 switch (func) {
Tony Barbour8205d902015-04-16 15:59:00 -060040 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 Barbourfa6cac72015-01-16 14:27:35 -070045 default:
46 assert(!"unknown blend func");
47 return GEN6_BLENDFUNCTION_ADD;
48 };
49}
50
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060051static int translate_blend(VkBlend blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -070052{
53 switch (blend) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060054 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 Barbourfa6cac72015-01-16 14:27:35 -070073 default:
74 assert(!"unknown blend factor");
75 return GEN6_BLENDFACTOR_ONE;
76 };
77}
78
Tony Barbour8205d902015-04-16 15:59:00 -060079static int translate_compare_func(VkCompareOp func)
Tony Barbourfa6cac72015-01-16 14:27:35 -070080{
81 switch (func) {
Tony Barbour8205d902015-04-16 15:59:00 -060082 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 Barbourfa6cac72015-01-16 14:27:35 -070090 default:
91 assert(!"unknown compare_func");
92 return GEN6_COMPAREFUNCTION_NEVER;
93 }
94}
95
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060096static int translate_stencil_op(VkStencilOp op)
Tony Barbourfa6cac72015-01-16 14:27:35 -070097{
98 switch (op) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060099 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 Barbourfa6cac72015-01-16 14:27:35 -0700107 default:
108 assert(!"unknown stencil op");
109 return GEN6_STENCILOP_KEEP;
110 }
111}
112
Chia-I Wu3f239832014-12-11 22:57:18 +0800113struct intel_pipeline_create_info {
Tony Barboure307f582015-07-10 15:29:03 -0600114 VkGraphicsPipelineCreateInfo graphics;
115 VkPipelineVertexInputStateCreateInfo vi;
116 VkPipelineInputAssemblyStateCreateInfo ia;
117 VkPipelineDepthStencilStateCreateInfo db;
118 VkPipelineColorBlendStateCreateInfo cb;
119 VkPipelineRasterStateCreateInfo rs;
120 VkPipelineTessellationStateCreateInfo tess;
121 VkPipelineMultisampleStateCreateInfo ms;
122 VkPipelineViewportStateCreateInfo vp;
Chia-I Wu3f239832014-12-11 22:57:18 +0800123
Tony Barboure307f582015-07-10 15:29:03 -0600124 VkComputePipelineCreateInfo compute;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600125
Tony Barboure307f582015-07-10 15:29:03 -0600126 VkPipelineShaderStageCreateInfo vs;
127 VkPipelineShaderStageCreateInfo tcs;
128 VkPipelineShaderStageCreateInfo tes;
129 VkPipelineShaderStageCreateInfo gs;
130 VkPipelineShaderStageCreateInfo fs;
Chia-I Wu3f239832014-12-11 22:57:18 +0800131};
Chia-I Wu38d1ddf2015-03-02 10:51:39 -0700132
133/* in S1.3 */
134struct intel_pipeline_sample_position {
135 int8_t x, y;
136};
137
138static uint8_t pack_sample_position(const struct intel_dev *dev,
139 const struct intel_pipeline_sample_position *pos)
140{
141 return (pos->x + 8) << 4 | (pos->y + 8);
142}
143
144void intel_pipeline_init_default_sample_patterns(const struct intel_dev *dev,
145 uint8_t *pat_1x, uint8_t *pat_2x,
146 uint8_t *pat_4x, uint8_t *pat_8x,
147 uint8_t *pat_16x)
148{
149 static const struct intel_pipeline_sample_position default_1x[1] = {
150 { 0, 0 },
151 };
152 static const struct intel_pipeline_sample_position default_2x[2] = {
153 { -4, -4 },
154 { 4, 4 },
155 };
156 static const struct intel_pipeline_sample_position default_4x[4] = {
157 { -2, -6 },
158 { 6, -2 },
159 { -6, 2 },
160 { 2, 6 },
161 };
162 static const struct intel_pipeline_sample_position default_8x[8] = {
163 { -1, 1 },
164 { 1, 5 },
165 { 3, -5 },
166 { 5, 3 },
167 { -7, -1 },
168 { -3, -7 },
169 { 7, -3 },
170 { -5, 7 },
171 };
172 static const struct intel_pipeline_sample_position default_16x[16] = {
173 { 0, 2 },
174 { 3, 0 },
175 { -3, -2 },
176 { -2, -4 },
177 { 4, 3 },
178 { 5, 1 },
179 { 6, -1 },
180 { 2, -6 },
181 { -4, 5 },
182 { -5, -5 },
183 { -1, -7 },
184 { 7, -3 },
185 { -7, 4 },
186 { 1, -8 },
187 { -6, 6 },
188 { -8, 7 },
189 };
190 int i;
191
192 pat_1x[0] = pack_sample_position(dev, default_1x);
193 for (i = 0; i < 2; i++)
194 pat_2x[i] = pack_sample_position(dev, &default_2x[i]);
195 for (i = 0; i < 4; i++)
196 pat_4x[i] = pack_sample_position(dev, &default_4x[i]);
197 for (i = 0; i < 8; i++)
198 pat_8x[i] = pack_sample_position(dev, &default_8x[i]);
199 for (i = 0; i < 16; i++)
200 pat_16x[i] = pack_sample_position(dev, &default_16x[i]);
201}
202
Chia-I Wu3f239832014-12-11 22:57:18 +0800203struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
204 enum intel_dev_meta_shader id)
205{
206 struct intel_pipeline_shader *sh;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600207 VkResult ret;
Chia-I Wu3f239832014-12-11 22:57:18 +0800208
Tony Barbour8205d902015-04-16 15:59:00 -0600209 sh = intel_alloc(dev, sizeof(*sh), 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu3f239832014-12-11 22:57:18 +0800210 if (!sh)
211 return NULL;
212 memset(sh, 0, sizeof(*sh));
213
214 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600215 if (ret != VK_SUCCESS) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800216 intel_free(dev, sh);
Chia-I Wu3f239832014-12-11 22:57:18 +0800217 return NULL;
218 }
219
220 switch (id) {
221 case INTEL_DEV_META_VS_FILL_MEM:
222 case INTEL_DEV_META_VS_COPY_MEM:
223 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
224 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600225 VK_SHADER_STAGE_VERTEX);
Chia-I Wu3f239832014-12-11 22:57:18 +0800226 break;
227 default:
228 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600229 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu3f239832014-12-11 22:57:18 +0800230 break;
231 }
232
233 return sh;
234}
235
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800236void intel_pipeline_shader_destroy(struct intel_dev *dev,
237 struct intel_pipeline_shader *sh)
Chia-I Wu3f239832014-12-11 22:57:18 +0800238{
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800239 intel_pipeline_shader_cleanup(sh, dev->gpu);
240 intel_free(dev, sh);
Chia-I Wu3f239832014-12-11 22:57:18 +0800241}
242
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600243static VkResult pipeline_build_shader(struct intel_pipeline *pipeline,
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600244 const VkPipelineShaderStageCreateInfo *sh_info,
Chia-I Wuf8385062015-01-04 16:27:24 +0800245 struct intel_pipeline_shader *sh)
Chia-I Wu3f239832014-12-11 22:57:18 +0800246{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600247 VkResult ret;
Chia-I Wu3f239832014-12-11 22:57:18 +0800248
Cody Northropbc12f872015-04-29 13:22:07 -0600249 const struct intel_ir* ir = intel_shader(sh_info->shader)->ir;
250
Chia-I Wuf8385062015-01-04 16:27:24 +0800251 ret = intel_pipeline_shader_compile(sh,
Cody Northropbc12f872015-04-29 13:22:07 -0600252 pipeline->dev->gpu, pipeline->pipeline_layout, sh_info, ir);
253
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600254 if (ret != VK_SUCCESS)
Chia-I Wu3f239832014-12-11 22:57:18 +0800255 return ret;
256
257 sh->max_threads =
258 intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage);
259
260 /* 1KB aligned */
261 sh->scratch_offset = u_align(pipeline->scratch_size, 1024);
262 pipeline->scratch_size = sh->scratch_offset +
263 sh->per_thread_scratch_size * sh->max_threads;
264
265 pipeline->active_shaders |= 1 << sh_info->stage;
266
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600267 return VK_SUCCESS;
Chia-I Wu3f239832014-12-11 22:57:18 +0800268}
269
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600270static VkResult pipeline_build_shaders(struct intel_pipeline *pipeline,
Chia-I Wu3f239832014-12-11 22:57:18 +0800271 const struct intel_pipeline_create_info *info)
272{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600273 VkResult ret = VK_SUCCESS;
Chia-I Wu3f239832014-12-11 22:57:18 +0800274
Tony Barbourde4124d2015-07-03 10:33:54 -0600275 if (ret == VK_SUCCESS && info->vs.shader.handle)
Chia-I Wudf601c42015-04-17 01:58:07 +0800276 ret = pipeline_build_shader(pipeline, &info->vs, &pipeline->vs);
Tony Barbourde4124d2015-07-03 10:33:54 -0600277 if (ret == VK_SUCCESS && info->tcs.shader.handle)
Chia-I Wudf601c42015-04-17 01:58:07 +0800278 ret = pipeline_build_shader(pipeline, &info->tcs,&pipeline->tcs);
Tony Barbourde4124d2015-07-03 10:33:54 -0600279 if (ret == VK_SUCCESS && info->tes.shader.handle)
Chia-I Wudf601c42015-04-17 01:58:07 +0800280 ret = pipeline_build_shader(pipeline, &info->tes,&pipeline->tes);
Tony Barbourde4124d2015-07-03 10:33:54 -0600281 if (ret == VK_SUCCESS && info->gs.shader.handle)
Chia-I Wudf601c42015-04-17 01:58:07 +0800282 ret = pipeline_build_shader(pipeline, &info->gs, &pipeline->gs);
Tony Barbourde4124d2015-07-03 10:33:54 -0600283 if (ret == VK_SUCCESS && info->fs.shader.handle)
Chia-I Wudf601c42015-04-17 01:58:07 +0800284 ret = pipeline_build_shader(pipeline, &info->fs, &pipeline->fs);
Chia-I Wu3f239832014-12-11 22:57:18 +0800285
Tony Barbourde4124d2015-07-03 10:33:54 -0600286 if (ret == VK_SUCCESS && info->compute.cs.shader.handle) {
Chia-I Wudf601c42015-04-17 01:58:07 +0800287 ret = pipeline_build_shader(pipeline,
Chia-I Wuf8385062015-01-04 16:27:24 +0800288 &info->compute.cs, &pipeline->cs);
289 }
Chia-I Wu3f239832014-12-11 22:57:18 +0800290
291 return ret;
292}
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600293static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len)
294{
295 uint32_t *ptr;
296
297 assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES);
298 ptr = &pipeline->cmds[pipeline->cmd_len];
299 pipeline->cmd_len += cmd_len;
300 return ptr;
301}
302
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600303static VkResult pipeline_build_ia(struct intel_pipeline *pipeline,
Chia-I Wube0a3d92014-09-02 13:20:59 +0800304 const struct intel_pipeline_create_info* info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600305{
Chia-I Wube0a3d92014-09-02 13:20:59 +0800306 pipeline->topology = info->ia.topology;
307 pipeline->disable_vs_cache = info->ia.disableVertexReuse;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600308
Chia-I Wube0a3d92014-09-02 13:20:59 +0800309 switch (info->ia.topology) {
Tony Barbour8205d902015-04-16 15:59:00 -0600310 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600311 pipeline->prim_type = GEN6_3DPRIM_POINTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600312 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600313 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600314 pipeline->prim_type = GEN6_3DPRIM_LINELIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600315 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600316 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600317 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600318 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600319 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600320 pipeline->prim_type = GEN6_3DPRIM_TRILIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600321 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600322 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600323 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600324 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600325 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
Courtney Goeltzenleuchter528781d2015-03-03 11:38:12 -0700326 pipeline->prim_type = GEN6_3DPRIM_TRIFAN;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600327 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600328 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600329 pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600330 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600331 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600332 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600333 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600334 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600335 pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600336 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600337 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600338 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600339 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600340 case VK_PRIMITIVE_TOPOLOGY_PATCH:
Chia-I Wube0a3d92014-09-02 13:20:59 +0800341 if (!info->tess.patchControlPoints ||
342 info->tess.patchControlPoints > 32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600343 return VK_ERROR_BAD_PIPELINE_DATA;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800344 pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 +
345 info->tess.patchControlPoints - 1;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600346 break;
347 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600348 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600349 }
350
Chia-I Wube0a3d92014-09-02 13:20:59 +0800351 if (info->ia.primitiveRestartEnable) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600352 pipeline->primitive_restart = true;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800353 pipeline->primitive_restart_index = info->ia.primitiveRestartIndex;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600354 } else {
355 pipeline->primitive_restart = false;
356 }
357
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600358 return VK_SUCCESS;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600359}
360
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600361static VkResult pipeline_build_rs_state(struct intel_pipeline *pipeline,
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800362 const struct intel_pipeline_create_info* info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600363{
Tony Barboure307f582015-07-10 15:29:03 -0600364 const VkPipelineRasterStateCreateInfo *rs_state = &info->rs;
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800365 bool ccw;
366
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600367 pipeline->depthClipEnable = rs_state->depthClipEnable;
368 pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700369
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600370 if (rs_state->provokingVertex == VK_PROVOKING_VERTEX_FIRST) {
Tony Barbourfa6cac72015-01-16 14:27:35 -0700371 pipeline->provoking_vertex_tri = 0;
372 pipeline->provoking_vertex_trifan = 1;
373 pipeline->provoking_vertex_line = 0;
374 } else {
375 pipeline->provoking_vertex_tri = 2;
376 pipeline->provoking_vertex_trifan = 2;
377 pipeline->provoking_vertex_line = 1;
378 }
379
380 switch (rs_state->fillMode) {
Tony Barbour8205d902015-04-16 15:59:00 -0600381 case VK_FILL_MODE_POINTS:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700382 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT |
383 GEN7_SF_DW1_BACKFACE_POINT;
384 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600385 case VK_FILL_MODE_WIREFRAME:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700386 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME |
387 GEN7_SF_DW1_BACKFACE_WIREFRAME;
388 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600389 case VK_FILL_MODE_SOLID:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700390 default:
391 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID |
392 GEN7_SF_DW1_BACKFACE_SOLID;
393 break;
394 }
395
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600396 ccw = (rs_state->frontFace == VK_FRONT_FACE_CCW);
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800397 /* flip the winding order */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398 if (info->vp.clipOrigin == VK_COORDINATE_ORIGIN_LOWER_LEFT)
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800399 ccw = !ccw;
400
401 if (ccw) {
Tony Barbourfa6cac72015-01-16 14:27:35 -0700402 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW;
403 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW;
404 }
405
406 switch (rs_state->cullMode) {
Tony Barbour8205d902015-04-16 15:59:00 -0600407 case VK_CULL_MODE_NONE:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700408 default:
409 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE;
410 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE;
411 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600412 case VK_CULL_MODE_FRONT:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT;
414 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT;
415 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600416 case VK_CULL_MODE_BACK:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700417 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK;
418 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK;
419 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600420 case VK_CULL_MODE_FRONT_AND_BACK:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH;
422 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH;
423 break;
424 }
425
426 /* only GEN7+ needs cull mode in 3DSTATE_CLIP */
427 if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
428 pipeline->cmd_clip_cull = 0;
429
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 return VK_SUCCESS;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600431}
432
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600433static void pipeline_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600434{
435 struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj);
436
Chia-I Wu3f239832014-12-11 22:57:18 +0800437 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800438 intel_pipeline_shader_cleanup(&pipeline->vs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800439 }
440
441 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800442 intel_pipeline_shader_cleanup(&pipeline->tcs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800443 }
444
445 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800446 intel_pipeline_shader_cleanup(&pipeline->tes, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800447 }
448
449 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800450 intel_pipeline_shader_cleanup(&pipeline->gs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800451 }
452
453 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800454 intel_pipeline_shader_cleanup(&pipeline->fs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800455 }
456
457 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800458 intel_pipeline_shader_cleanup(&pipeline->cs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800459 }
Chia-I Wued833872014-08-23 17:00:35 +0800460
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600461 intel_base_destroy(&pipeline->obj.base);
462}
463
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600464static VkResult pipeline_validate(struct intel_pipeline *pipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +0800465{
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600466 /*
467 * Validate required elements
468 */
469 if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) {
470 // TODO: Log debug message: Vertex Shader required.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600471 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600472 }
473
474 /*
475 * Tessalation control and evaluation have to both have a shader defined or
476 * neither should have a shader defined.
477 */
478 if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) !=
479 ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) {
480 // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600481 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600482 }
483
484 if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) &&
485 (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG |
486 SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG |
487 SHADER_FRAGMENT_FLAG))) {
488 // TODO: Log debug message: Can only specify compute shader when doing compute
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600489 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600490 }
491
492 /*
Tony Barbour8205d902015-04-16 15:59:00 -0600493 * VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600494 * Mismatching primitive topology and tessellation fails graphics pipeline creation.
495 */
496 if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) &&
Tony Barbour8205d902015-04-16 15:59:00 -0600497 (pipeline->topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis43c973b2015-06-22 11:31:09 -0600498 // TODO: Log debug message: Invalid topology used with tessellation shader.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600499 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600500 }
501
Tony Barbour8205d902015-04-16 15:59:00 -0600502 if ((pipeline->topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
Tobin Ehlis43c973b2015-06-22 11:31:09 -0600503 (~pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) {
504 // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessellation shader.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600506 }
507
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600508 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +0800509}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600510
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800511static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
512 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800513{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800514 const struct intel_gpu *gpu = pipeline->dev->gpu;
515 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wua4d1b392014-10-10 13:57:29 +0800516 const struct intel_pipeline_shader *vs = &pipeline->vs;
517 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800518 int vs_entry_size, gs_entry_size;
519 int vs_size, gs_size;
520
Chia-I Wu509b3f22014-09-02 10:24:05 +0800521 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800522
523 vs_entry_size = ((vs->in_count >= vs->out_count) ?
524 vs->in_count : vs->out_count);
525 gs_entry_size = (gs) ? gs->out_count : 0;
526
527 /* in bytes */
528 vs_entry_size *= sizeof(float) * 4;
529 gs_entry_size *= sizeof(float) * 4;
530
Chia-I Wua4d1b392014-10-10 13:57:29 +0800531 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800532 vs_size = urb_size / 2;
533 gs_size = vs_size;
534 } else {
535 vs_size = urb_size;
536 gs_size = 0;
537 }
538
539 /* 3DSTATE_URB */
540 {
541 const uint8_t cmd_len = 3;
542 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
543 (cmd_len - 2);
544 int vs_alloc_size, gs_alloc_size;
545 int vs_entry_count, gs_entry_count;
546 uint32_t *dw;
547
548 /* in 1024-bit rows */
549 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
550 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
551
552 /* valid range is [1, 5] */
553 if (!vs_alloc_size)
554 vs_alloc_size = 1;
555 if (!gs_alloc_size)
556 gs_alloc_size = 1;
557 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
558
559 /* valid range is [24, 256], multiples of 4 */
560 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
561 if (vs_entry_count > 256)
562 vs_entry_count = 256;
563 assert(vs_entry_count >= 24);
564
565 /* valid range is [0, 256], multiples of 4 */
566 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
567 if (gs_entry_count > 256)
568 gs_entry_count = 256;
569
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600570 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800571
572 dw[0] = dw0;
573 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
574 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
575 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
576 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
577 }
578}
579
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800580static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
581 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800582{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800583 const struct intel_gpu *gpu = pipeline->dev->gpu;
584 const int urb_size = ((gpu->gt == 3) ? 512 :
585 (gpu->gt == 2) ? 256 : 128) * 1024;
Cody Northrop306ec352014-10-06 15:11:45 -0600586 const struct intel_pipeline_shader *vs = &pipeline->vs;
587 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800588 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800589 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800590 int vs_entry_size, gs_entry_size;
591 int vs_size, gs_size;
592
Chia-I Wu509b3f22014-09-02 10:24:05 +0800593 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800594
595 vs_entry_size = ((vs->in_count >= vs->out_count) ?
596 vs->in_count : vs->out_count);
597 gs_entry_size = (gs) ? gs->out_count : 0;
598
599 /* in bytes */
600 vs_entry_size *= sizeof(float) * 4;
601 gs_entry_size *= sizeof(float) * 4;
602
Chia-I Wua4d1b392014-10-10 13:57:29 +0800603 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800604 vs_size = (urb_size - urb_offset) / 2;
605 gs_size = vs_size;
606 } else {
607 vs_size = urb_size - urb_offset;
608 gs_size = 0;
609 }
610
611 /* 3DSTATE_URB_* */
612 {
613 const uint8_t cmd_len = 2;
614 int vs_alloc_size, gs_alloc_size;
615 int vs_entry_count, gs_entry_count;
616 uint32_t *dw;
617
618 /* in 512-bit rows */
619 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
620 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
621
622 if (!vs_alloc_size)
623 vs_alloc_size = 1;
624 if (!gs_alloc_size)
625 gs_alloc_size = 1;
626
627 /* avoid performance decrease due to banking */
628 if (vs_alloc_size == 5)
629 vs_alloc_size = 6;
630
631 /* in multiples of 8 */
632 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
633 assert(vs_entry_count >= 32);
634
635 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
636
Chia-I Wu509b3f22014-09-02 10:24:05 +0800637 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800638 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800639 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800640 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800641 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800642 if (vs_entry_count >= max_vs_entry_count)
643 vs_entry_count = max_vs_entry_count;
644 if (gs_entry_count >= max_gs_entry_count)
645 gs_entry_count = max_gs_entry_count;
646 } else {
647 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800648 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800649 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800650 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800651 if (vs_entry_count >= max_vs_entry_count)
652 vs_entry_count = max_vs_entry_count;
653 if (gs_entry_count >= max_gs_entry_count)
654 gs_entry_count = max_gs_entry_count;
655 }
656
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600657 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800658 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700659 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
660 (vs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800661 vs_entry_count;
662
663 dw += 2;
664 if (gs_size)
665 urb_offset += vs_size;
666 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700667 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
668 (gs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800669 gs_entry_count;
670
671 dw += 2;
672 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700673 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800674
675 dw += 2;
676 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700677 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800678 }
679}
680
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800681static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
682 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800683{
Cody Northrop306ec352014-10-06 15:11:45 -0600684 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu1d125092014-10-08 08:49:38 +0800685 uint8_t cmd_len;
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800686 uint32_t *dw;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600687 uint32_t i, j;
688 uint32_t attr_count;
689 uint32_t attrs_processed;
Chia-I Wu1d125092014-10-08 08:49:38 +0800690 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800691
Chia-I Wu509b3f22014-09-02 10:24:05 +0800692 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800693
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600694 attr_count = u_popcountll(vs->inputs_read);
695 cmd_len = 1 + 2 * attr_count;
Chia-I Wu1d125092014-10-08 08:49:38 +0800696 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
697 cmd_len += 2;
698
699 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800700 return;
701
702 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800703
704 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
705 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800706 dw++;
707
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800708 /* VERTEX_ELEMENT_STATE */
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600709 for (i = 0, attrs_processed = 0; attrs_processed < attr_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600710 VkVertexInputAttributeDescription *attr = NULL;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600711
712 /*
713 * The compiler will pack the shader references and then
714 * indicate which locations are used via the bitmask in
715 * vs->inputs_read.
716 */
717 if (!(vs->inputs_read & (1L << i))) {
GregF2dc40212014-10-31 17:31:47 -0600718 continue;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600719 }
720
721 /*
722 * For each bit set in the vs->inputs_read we'll need
723 * to find the corresponding attribute record and then
724 * set up the next HW vertex element based on that attribute.
725 */
726 for (j = 0; j < info->vi.attributeCount; j++) {
727 if (info->vi.pVertexAttributeDescriptions[j].location == i) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600728 attr = (VkVertexInputAttributeDescription *) &info->vi.pVertexAttributeDescriptions[j];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600729 attrs_processed++;
730 break;
731 }
732 }
733 assert(attr != NULL);
734
Chia-I Wu1d125092014-10-08 08:49:38 +0800735 const int format =
736 intel_format_translate_color(pipeline->dev->gpu, attr->format);
737
738 comps[0] = GEN6_VFCOMP_STORE_0;
739 comps[1] = GEN6_VFCOMP_STORE_0;
740 comps[2] = GEN6_VFCOMP_STORE_0;
741 comps[3] = icd_format_is_int(attr->format) ?
742 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
743
744 switch (icd_format_get_channel_count(attr->format)) {
745 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
746 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
747 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
748 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
749 default:
750 break;
751 }
752
753 assert(attr->offsetInBytes <= 2047);
754
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700755 dw[0] = attr->binding << GEN6_VE_DW0_VB_INDEX__SHIFT |
756 GEN6_VE_DW0_VALID |
757 format << GEN6_VE_DW0_FORMAT__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +0800758 attr->offsetInBytes;
759
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700760 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
761 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
762 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
763 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu1d125092014-10-08 08:49:38 +0800764
765 dw += 2;
766 }
GregF932fcf52014-10-29 17:02:11 -0600767
768 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
769 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
770 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
771 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
772 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
773 comps[2] = GEN6_VFCOMP_NOSTORE;
774 comps[3] = GEN6_VFCOMP_NOSTORE;
775
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700776 dw[0] = GEN6_VE_DW0_VALID;
777 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
778 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
779 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
780 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
GregF932fcf52014-10-29 17:02:11 -0600781
782 dw += 2;
783 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800784}
785
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800786static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline,
787 const struct intel_pipeline_create_info *info)
GregF8cd81832014-11-18 18:01:01 -0700788{
789 const struct intel_pipeline_shader *fs = &pipeline->fs;
GregF8cd81832014-11-18 18:01:01 -0700790 uint8_t cmd_len;
791 uint32_t *body;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600792 uint32_t attr_skip, attr_count;
793 uint32_t vue_offset, vue_len;
794 uint32_t i;
GregF8cd81832014-11-18 18:01:01 -0700795
Cody Northrop293d4502015-05-05 09:38:03 -0600796 // If GS is active, use its outputs
797 const struct intel_pipeline_shader *src =
798 (pipeline->active_shaders & SHADER_GEOMETRY_FLAG)
799 ? &pipeline->gs
800 : &pipeline->vs;
801
GregF8cd81832014-11-18 18:01:01 -0700802 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
803
804 cmd_len = 14;
805
Chia-I Wuf85def42015-01-29 00:34:24 +0800806 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7))
807 body = pipeline_cmd_ptr(pipeline, cmd_len);
808 else
809 body = pipeline->cmd_3dstate_sbe;
GregF8cd81832014-11-18 18:01:01 -0700810
Cody Northrop293d4502015-05-05 09:38:03 -0600811 assert(!fs->reads_user_clip || src->enable_user_clip);
812 attr_skip = src->outputs_offset;
813 if (src->enable_user_clip != fs->reads_user_clip) {
GregF8cd81832014-11-18 18:01:01 -0700814 attr_skip += 2;
815 }
Cody Northrop293d4502015-05-05 09:38:03 -0600816 assert(src->out_count >= attr_skip);
817 attr_count = src->out_count - attr_skip;
GregF8cd81832014-11-18 18:01:01 -0700818
819 // LUNARG TODO: We currently are only handling 16 attrs;
820 // ultimately, we need to handle 32
821 assert(fs->in_count <= 16);
822 assert(attr_count <= 16);
823
824 vue_offset = attr_skip / 2;
825 vue_len = (attr_count + 1) / 2;
826 if (!vue_len)
827 vue_len = 1;
828
829 body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
830 (cmd_len - 2);
831
832 // LUNARG TODO: If the attrs needed by the FS are exactly
833 // what is written by the VS, we don't need to enable
834 // swizzling, improving performance. Even if we swizzle,
835 // we can improve performance by reducing vue_len to
836 // just include the values needed by the FS:
837 // vue_len = ceiling((max_vs_out + 1)/2)
838
839 body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE |
840 fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
841 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
842 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
843
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800844 switch (info->rs.pointOrigin) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600845 case VK_COORDINATE_ORIGIN_UPPER_LEFT:
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800846 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT;
847 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600848 case VK_COORDINATE_ORIGIN_LOWER_LEFT:
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800849 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_LOWERLEFT;
850 break;
851 default:
852 assert(!"unknown point origin");
853 break;
854 }
855
Cody Northrop293d4502015-05-05 09:38:03 -0600856 uint16_t src_slot[fs->in_count];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600857 int32_t fs_in = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600858 int32_t src_out = - (vue_offset * 2 - src->outputs_offset);
GregF8cd81832014-11-18 18:01:01 -0700859 for (i=0; i < 64; i++) {
Cody Northrop293d4502015-05-05 09:38:03 -0600860 bool srcWrites = src->outputs_written & (1L << i);
861 bool fsReads = fs->inputs_read & (1L << i);
Cody Northropd75c13e2015-01-02 14:07:20 -0700862
863 if (fsReads) {
Cody Northrop293d4502015-05-05 09:38:03 -0600864 assert(src_out >= 0);
GregF8cd81832014-11-18 18:01:01 -0700865 assert(fs_in < fs->in_count);
Cody Northrop293d4502015-05-05 09:38:03 -0600866 src_slot[fs_in] = src_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700867
Cody Northrop293d4502015-05-05 09:38:03 -0600868 if (!srcWrites) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700869 // If the vertex shader did not write this input, we cannot
870 // program the SBE to read it. Our choices are to allow it to
871 // read junk from a GRF, or get zero. We're choosing zero.
872 if (i >= fs->generic_input_start) {
Cody Northrop293d4502015-05-05 09:38:03 -0600873 src_slot[fs_in] = GEN8_SBE_SWIZ_CONST_0000 |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700874 GEN8_SBE_SWIZ_OVERRIDE_X |
875 GEN8_SBE_SWIZ_OVERRIDE_Y |
876 GEN8_SBE_SWIZ_OVERRIDE_Z |
877 GEN8_SBE_SWIZ_OVERRIDE_W;
Cody Northropd75c13e2015-01-02 14:07:20 -0700878 }
879 }
880
GregF8cd81832014-11-18 18:01:01 -0700881 fs_in += 1;
882 }
Cody Northrop293d4502015-05-05 09:38:03 -0600883 if (srcWrites) {
884 src_out += 1;
GregF8cd81832014-11-18 18:01:01 -0700885 }
886 }
887
888 for (i = 0; i < 8; i++) {
889 uint16_t hi, lo;
890
891 /* no attr swizzles */
892 if (i * 2 + 1 < fs->in_count) {
Cody Northrop293d4502015-05-05 09:38:03 -0600893 lo = src_slot[i * 2];
894 hi = src_slot[i * 2 + 1];
GregF8cd81832014-11-18 18:01:01 -0700895 } else if (i * 2 < fs->in_count) {
Cody Northrop293d4502015-05-05 09:38:03 -0600896 lo = src_slot[i * 2];
GregF8cd81832014-11-18 18:01:01 -0700897 hi = 0;
898 } else {
899 hi = 0;
900 lo = 0;
901 }
902
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700903 body[2 + i] = hi << GEN8_SBE_SWIZ_HIGH__SHIFT | lo;
GregF8cd81832014-11-18 18:01:01 -0700904 }
905
Tony Barbour8205d902015-04-16 15:59:00 -0600906 if (info->ia.topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
Chia-I Wu7f390562015-03-25 08:47:18 +0800907 body[10] = fs->point_sprite_enables;
908 else
909 body[10] = 0;
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800910
GregF8cd81832014-11-18 18:01:01 -0700911 body[11] = 0; /* constant interpolation enables */
912 body[12] = 0; /* WrapShortest enables */
913 body[13] = 0;
914}
915
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800916static void pipeline_build_gs(struct intel_pipeline *pipeline,
917 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600918{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600919 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600920}
921
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800922static void pipeline_build_hs(struct intel_pipeline *pipeline,
923 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600924{
925 const uint8_t cmd_len = 7;
926 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
927 uint32_t *dw;
928
Chia-I Wu509b3f22014-09-02 10:24:05 +0800929 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600930
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800931 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600932 dw[0] = dw0;
933 dw[1] = 0;
934 dw[2] = 0;
935 dw[3] = 0;
936 dw[4] = 0;
937 dw[5] = 0;
938 dw[6] = 0;
939}
940
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800941static void pipeline_build_te(struct intel_pipeline *pipeline,
942 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600943{
944 const uint8_t cmd_len = 4;
945 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
946 uint32_t *dw;
947
Chia-I Wu509b3f22014-09-02 10:24:05 +0800948 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600949
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800950 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600951 dw[0] = dw0;
952 dw[1] = 0;
953 dw[2] = 0;
954 dw[3] = 0;
955}
956
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800957static void pipeline_build_ds(struct intel_pipeline *pipeline,
958 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600959{
960 const uint8_t cmd_len = 6;
961 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
962 uint32_t *dw;
963
Chia-I Wu509b3f22014-09-02 10:24:05 +0800964 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600965
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800966 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600967 dw[0] = dw0;
968 dw[1] = 0;
969 dw[2] = 0;
970 dw[3] = 0;
971 dw[4] = 0;
972 dw[5] = 0;
973}
974
Tony Barbourfa6cac72015-01-16 14:27:35 -0700975static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
976 const struct intel_pipeline_create_info *info)
977{
978 pipeline->cmd_depth_stencil = 0;
979
980 if (info->db.stencilTestEnable) {
981 pipeline->cmd_depth_stencil = 1 << 31 |
Tony Barbour8205d902015-04-16 15:59:00 -0600982 translate_compare_func(info->db.front.stencilCompareOp) << 28 |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700983 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
984 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
985 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
986 1 << 15 |
Tony Barbour8205d902015-04-16 15:59:00 -0600987 translate_compare_func(info->db.back.stencilCompareOp) << 12 |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700988 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
989 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
990 translate_stencil_op(info->db.back.stencilPassOp) << 3;
991 }
992
993 pipeline->stencilTestEnable = info->db.stencilTestEnable;
994
995 /*
996 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
997 *
998 * "Enabling the Depth Test function without defining a Depth Buffer is
999 * UNDEFINED."
1000 *
1001 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
1002 *
1003 * "A Depth Buffer must be defined before enabling writes to it, or
1004 * operation is UNDEFINED."
1005 *
1006 * TODO We do not check these yet.
1007 */
1008 if (info->db.depthTestEnable) {
1009 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
Tony Barbour8205d902015-04-16 15:59:00 -06001010 translate_compare_func(info->db.depthCompareOp) << 27;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001011 } else {
1012 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
1013 }
1014
1015 if (info->db.depthWriteEnable)
1016 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1017}
1018
Tony Barbourfa6cac72015-01-16 14:27:35 -07001019static void pipeline_build_msaa(struct intel_pipeline *pipeline,
1020 const struct intel_pipeline_create_info *info)
1021{
1022 uint32_t cmd, cmd_len;
1023 uint32_t *dw;
1024
1025 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1026
Tony Barboure094edf2015-06-26 10:18:34 -06001027 pipeline->sample_count = (info->ms.rasterSamples <= 1) ? 1 : info->ms.rasterSamples;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001028
1029 /* 3DSTATE_SAMPLE_MASK */
1030 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
1031 cmd_len = 2;
1032
Chia-I Wu8ada4242015-03-02 11:19:33 -07001033 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001034 dw[0] = cmd | (cmd_len - 2);
1035 dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1);
1036 pipeline->cmd_sample_mask = dw[1];
1037}
1038
1039static void pipeline_build_cb(struct intel_pipeline *pipeline,
1040 const struct intel_pipeline_create_info *info)
1041{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001042 uint32_t i;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001043
1044 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1045 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
1046 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
1047
1048 uint32_t *dw = pipeline->cmd_cb;
1049
1050 for (i = 0; i < info->cb.attachmentCount; i++) {
Tony Barboure307f582015-07-10 15:29:03 -06001051 const VkPipelineColorBlendAttachmentState *att = &info->cb.pAttachments[i];
Tony Barbourfa6cac72015-01-16 14:27:35 -07001052 uint32_t dw0, dw1;
1053
1054
1055 dw0 = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001056 dw1 = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1057 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1058 GEN6_RT_DW1_POST_BLEND_CLAMP;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001059
1060 if (att->blendEnable) {
1061 dw0 = 1 << 31 |
Tony Barbour8205d902015-04-16 15:59:00 -06001062 translate_blend_func(att->blendOpAlpha) << 26 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001063 translate_blend(att->srcBlendAlpha) << 20 |
1064 translate_blend(att->destBlendAlpha) << 15 |
Tony Barbour8205d902015-04-16 15:59:00 -06001065 translate_blend_func(att->blendOpColor) << 11 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001066 translate_blend(att->srcBlendColor) << 5 |
1067 translate_blend(att->destBlendColor);
1068
Tony Barbour8205d902015-04-16 15:59:00 -06001069 if (att->blendOpAlpha != att->blendOpColor ||
Tony Barbourfa6cac72015-01-16 14:27:35 -07001070 att->srcBlendAlpha != att->srcBlendColor ||
1071 att->destBlendAlpha != att->destBlendColor)
1072 dw0 |= 1 << 30;
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -07001073
1074 pipeline->dual_source_blend_enable = icd_pipeline_cb_att_needs_dual_source_blending(att);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001075 }
1076
Courtney Goeltzenleuchter72af13a2015-06-26 17:45:23 -06001077 if (info->cb.logicOpEnable && info->cb.logicOp != VK_LOGIC_OP_COPY) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07001078 int logicop;
1079
1080 switch (info->cb.logicOp) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001081 case VK_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1082 case VK_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1083 case VK_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1084 case VK_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1085 case VK_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1086 case VK_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1087 case VK_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1088 case VK_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1089 case VK_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1090 case VK_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1091 case VK_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1092 case VK_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1093 case VK_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1094 case VK_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1095 case VK_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001096 default:
1097 assert(!"unknown logic op");
1098 logicop = GEN6_LOGICOP_CLEAR;
1099 break;
1100 }
1101
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001102 dw1 |= GEN6_RT_DW1_LOGICOP_ENABLE |
1103 logicop << GEN6_RT_DW1_LOGICOP_FUNC__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001104 }
1105
1106 if (!(att->channelWriteMask & 0x1))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001107 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_R;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 if (!(att->channelWriteMask & 0x2))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001109 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_G;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001110 if (!(att->channelWriteMask & 0x4))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001111 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_B;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001112 if (!(att->channelWriteMask & 0x8))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001113 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001114
1115 dw[2 * i] = dw0;
1116 dw[2 * i + 1] = dw1;
1117 }
1118
1119 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1120 {
1121 dw[2 * i] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001122 dw[2 * i + 1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1123 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1124 GEN6_RT_DW1_POST_BLEND_CLAMP |
1125 GEN6_RT_DW1_WRITE_DISABLE_R |
1126 GEN6_RT_DW1_WRITE_DISABLE_G |
1127 GEN6_RT_DW1_WRITE_DISABLE_B |
1128 GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001129 }
1130
1131}
1132
1133
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001134static VkResult pipeline_build_all(struct intel_pipeline *pipeline,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001135 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001136{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001137 VkResult ret;
Chia-I Wu3efef432014-08-28 15:00:16 +08001138
Chia-I Wu98824592014-09-02 09:42:46 +08001139 ret = pipeline_build_shaders(pipeline, info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001140 if (ret != VK_SUCCESS)
Chia-I Wu98824592014-09-02 09:42:46 +08001141 return ret;
1142
Chia-I Wu1d125092014-10-08 08:49:38 +08001143 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
1144 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001145 return VK_ERROR_BAD_PIPELINE_DATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001146
Chia-I Wu2f455af2015-04-22 15:54:06 +08001147 if (info->vp.clipOrigin != VK_COORDINATE_ORIGIN_UPPER_LEFT) {
1148 assert(!"only VK_COORDINATE_ORIGIN_UPPER_LEFT is supported");
1149 return VK_ERROR_INVALID_VALUE;
1150 }
1151
Chia-I Wue2504cb2015-04-22 14:20:52 +08001152 if (info->vp.depthMode != VK_DEPTH_MODE_ZERO_TO_ONE) {
1153 assert(!"only VK_DEPTH_MODE_ZERO_TO_ONE is supported");
1154 return VK_ERROR_INVALID_VALUE;
1155 }
1156
Chia-I Wu1d125092014-10-08 08:49:38 +08001157 pipeline->vb_count = info->vi.bindingCount;
1158 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1159 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1160
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001161 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wu86a5e0c2015-03-24 11:01:50 +08001162 pipeline_build_fragment_SBE(pipeline, info);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001163 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001164 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001165
Chia-I Wu509b3f22014-09-02 10:24:05 +08001166 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001167 pipeline_build_urb_alloc_gen7(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001168 pipeline_build_gs(pipeline, info);
1169 pipeline_build_hs(pipeline, info);
1170 pipeline_build_te(pipeline, info);
1171 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001172
1173 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1174 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1175 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1176 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1177 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001178 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001179 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001180
1181 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1182 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001183 }
1184
Chia-I Wube0a3d92014-09-02 13:20:59 +08001185 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001186
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001187 if (ret == VK_SUCCESS)
Chia-I Wu6abcb0e2015-03-24 14:38:14 +08001188 ret = pipeline_build_rs_state(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001189
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001190 if (ret == VK_SUCCESS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07001191 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001192 pipeline->cb_state = info->cb;
1193 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001194 }
1195
1196 return ret;
1197}
1198
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001199static VkResult pipeline_create_info_init(struct intel_pipeline_create_info *info,
1200 const VkGraphicsPipelineCreateInfo *vkinfo)
Chia-I Wu3efef432014-08-28 15:00:16 +08001201{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001202 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001203
Tony Barbourfa6cac72015-01-16 14:27:35 -07001204 /*
1205 * Do we need to set safe defaults in case the app doesn't provide all of
1206 * the necessary create infos?
1207 */
Tony Barboure094edf2015-06-26 10:18:34 -06001208 info->ms.rasterSamples = 1;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001209 info->ms.sampleMask = 1;
1210
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001211 memcpy(&info->graphics, vkinfo, sizeof (info->graphics));
Chia-I Wu3efef432014-08-28 15:00:16 +08001212
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001213 void *dst;
1214 for (uint32_t i = 0; i < vkinfo->stageCount; i++) {
1215 const VkPipelineShaderStageCreateInfo *thisStage = &vkinfo->pStages[i];
1216 switch (thisStage->stage) {
1217 case VK_SHADER_STAGE_VERTEX:
1218 dst = &info->vs;
1219 break;
1220 case VK_SHADER_STAGE_TESS_CONTROL:
1221 dst = &info->tcs;
1222 break;
1223 case VK_SHADER_STAGE_TESS_EVALUATION:
1224 dst = &info->tes;
1225 break;
1226 case VK_SHADER_STAGE_GEOMETRY:
1227 dst = &info->gs;
1228 break;
1229 case VK_SHADER_STAGE_FRAGMENT:
1230 dst = &info->fs;
1231 break;
1232 case VK_SHADER_STAGE_COMPUTE:
1233 dst = &info->compute;
1234 break;
1235 default:
1236 return VK_ERROR_BAD_PIPELINE_DATA;
1237 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001238 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001239 memcpy(dst, thisStage, sizeof(VkPipelineShaderStageCreateInfo));
1240 }
Chia-I Wu3efef432014-08-28 15:00:16 +08001241
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001242 if (vkinfo->pVertexInputState != NULL) {
1243 memcpy(&info->vi, vkinfo->pVertexInputState, sizeof (info->vi));
1244 }
Tony Barboure307f582015-07-10 15:29:03 -06001245 if (vkinfo->pInputAssemblyState != NULL) {
1246 memcpy(&info->ia, vkinfo->pInputAssemblyState, sizeof (info->ia));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001247 }
Tony Barboure307f582015-07-10 15:29:03 -06001248 if (vkinfo->pDepthStencilState != NULL) {
1249 memcpy(&info->db, vkinfo->pDepthStencilState, sizeof (info->db));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001250 }
Tony Barboure307f582015-07-10 15:29:03 -06001251 if (vkinfo->pColorBlendState != NULL) {
1252 memcpy(&info->cb, vkinfo->pColorBlendState, sizeof (info->cb));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001253 }
Tony Barboure307f582015-07-10 15:29:03 -06001254 if (vkinfo->pRasterState != NULL) {
1255 memcpy(&info->rs, vkinfo->pRasterState, sizeof (info->rs));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001256 }
Tony Barboure307f582015-07-10 15:29:03 -06001257 if (vkinfo->pTessellationState != NULL) {
1258 memcpy(&info->tess, vkinfo->pTessellationState, sizeof (info->tess));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001259 }
Tony Barboure307f582015-07-10 15:29:03 -06001260 if (vkinfo->pMultisampleState != NULL) {
1261 memcpy(&info->ms, vkinfo->pMultisampleState, sizeof (info->ms));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001262 }
Tony Barboure307f582015-07-10 15:29:03 -06001263 if (vkinfo->pViewportState != NULL) {
1264 memcpy(&info->vp, vkinfo->pViewportState, sizeof (info->vp));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001265 }
Tony Barboure307f582015-07-10 15:29:03 -06001266 if (vkinfo->pViewportState != NULL) {
1267 memcpy(&info->vp, vkinfo->pViewportState, sizeof (info->vp));
Chia-I Wu3efef432014-08-28 15:00:16 +08001268 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001269
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001270 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001271}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001272
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001273static VkResult graphics_pipeline_create(struct intel_dev *dev,
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001274 const VkGraphicsPipelineCreateInfo *info_,
1275 struct intel_pipeline **pipeline_ret)
Chia-I Wu3efef432014-08-28 15:00:16 +08001276{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001277 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001278 struct intel_pipeline *pipeline;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001279 VkResult ret;
Chia-I Wu3efef432014-08-28 15:00:16 +08001280
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001281 ret = pipeline_create_info_init(&info, info_);
1282
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001283 if (ret != VK_SUCCESS)
Chia-I Wu3efef432014-08-28 15:00:16 +08001284 return ret;
1285
Chia-I Wu545c2e12015-02-22 13:19:54 +08001286 pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle,
Jon Ashburn0d60d272015-07-09 15:02:25 -06001287 sizeof (*pipeline), dev->base.dbg,
1288 VK_OBJECT_TYPE_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001289 if (!pipeline)
Tony Barbour8205d902015-04-16 15:59:00 -06001290 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu3efef432014-08-28 15:00:16 +08001291
1292 pipeline->dev = dev;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001293 pipeline->pipeline_layout = intel_pipeline_layout(info.graphics.layout);
Chia-I Wudf601c42015-04-17 01:58:07 +08001294
Chia-I Wu3efef432014-08-28 15:00:16 +08001295 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001296
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001297 ret = pipeline_build_all(pipeline, &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001298 if (ret == VK_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001299 ret = pipeline_validate(pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001300 if (ret != VK_SUCCESS) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001301 pipeline_destroy(&pipeline->obj);
1302 return ret;
1303 }
1304
Tony Barbour2094dc72015-07-09 15:26:32 -06001305 VkMemoryAllocInfo mem_reqs;
1306 mem_reqs.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1307 mem_reqs.allocationSize = pipeline->scratch_size;
1308 mem_reqs.pNext = NULL;
1309 mem_reqs.memoryTypeIndex = 0;
1310 intel_mem_alloc(dev, &mem_reqs, &pipeline->obj.mem);
1311
Chia-I Wu3efef432014-08-28 15:00:16 +08001312 *pipeline_ret = pipeline;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001313 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001314}
1315
Jon Ashburn0d60d272015-07-09 15:02:25 -06001316ICD_EXPORT VkResult VKAPI vkCreatePipelineCache(
1317 VkDevice device,
1318 const VkPipelineCacheCreateInfo* pCreateInfo,
1319 VkPipelineCache* pPipelineCache)
Chia-I Wu3efef432014-08-28 15:00:16 +08001320{
Chia-I Wu3efef432014-08-28 15:00:16 +08001321
Jon Ashburn0d60d272015-07-09 15:02:25 -06001322 // non-dispatchable objects only need to be 64 bits currently
1323 *((uint64_t *)pPipelineCache) = 1;
1324 return VK_SUCCESS;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001325}
1326
Jon Ashburn0d60d272015-07-09 15:02:25 -06001327VkResult VKAPI vkDestroyPipelineCache(
1328 VkDevice device,
1329 VkPipelineCache pipelineCache)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001330{
Jon Ashburn0d60d272015-07-09 15:02:25 -06001331 return VK_SUCCESS;
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001332}
1333
Jon Ashburn0d60d272015-07-09 15:02:25 -06001334ICD_EXPORT size_t VKAPI vkGetPipelineCacheSize(
1335 VkDevice device,
1336 VkPipelineCache pipelineCache)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001337{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001338 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001339}
1340
Jon Ashburn0d60d272015-07-09 15:02:25 -06001341ICD_EXPORT VkResult VKAPI vkGetPipelineCacheData(
1342 VkDevice device,
1343 VkPipelineCache pipelineCache,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001344 void* pData)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001345{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001346 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001347}
1348
Jon Ashburn0d60d272015-07-09 15:02:25 -06001349ICD_EXPORT VkResult VKAPI vkMergePipelineCaches(
1350 VkDevice device,
1351 VkPipelineCache destCache,
1352 uint32_t srcCacheCount,
1353 const VkPipelineCache* pSrcCaches)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001354{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001355 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001356}
1357
Jon Ashburn0d60d272015-07-09 15:02:25 -06001358ICD_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001359 VkDevice device,
Jon Ashburn0d60d272015-07-09 15:02:25 -06001360 VkPipelineCache pipelineCache,
1361 uint32_t count,
1362 const VkGraphicsPipelineCreateInfo* pCreateInfos,
1363 VkPipeline* pPipelines)
1364{
1365 struct intel_dev *dev = intel_dev(device);
1366 uint32_t i;
1367 VkResult res;
1368 bool one_succeeded = false;
1369
1370 for (i = 0; i < count; i++) {
1371 res = graphics_pipeline_create(dev, &(pCreateInfos[i]),
1372 (struct intel_pipeline **) &(pPipelines[i]));
1373 //return NULL handle for unsuccessful creates
1374 if (res != VK_SUCCESS)
Tony Barbourde4124d2015-07-03 10:33:54 -06001375 pPipelines[i].handle = 0;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001376 else
1377 one_succeeded = true;
1378 }
1379 //return VK_SUCCESS if any of count creates succeeded
1380 if (one_succeeded)
1381 return VK_SUCCESS;
1382 else
1383 return res;
1384}
1385
1386ICD_EXPORT VkResult VKAPI vkCreateComputePipelines(
1387 VkDevice device,
1388 VkPipelineCache pipelineCache,
1389 uint32_t count,
1390 const VkComputePipelineCreateInfo* pCreateInfos,
1391 VkPipeline* pPipelines)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001392{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001393 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001394}
Tony Barbourde4124d2015-07-03 10:33:54 -06001395
1396ICD_EXPORT VkResult VKAPI vkDestroyPipeline(
1397 VkDevice device,
1398 VkPipeline pipeline)
1399
1400 {
1401 struct intel_obj *obj = intel_obj(pipeline.handle);
1402
Tony Barbour2094dc72015-07-09 15:26:32 -06001403 intel_mem_free(obj->mem);
Tony Barbourde4124d2015-07-03 10:33:54 -06001404 obj->destroy(obj);
1405 return VK_SUCCESS;
1406 }