blob: dd5ffda202278e48ff4caac34a9d4883b6e31dd3 [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"
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060035
Tony Barbour8205d902015-04-16 15:59:00 -060036static int translate_blend_func(VkBlendOp func)
Tony Barbourfa6cac72015-01-16 14:27:35 -070037{
38 switch (func) {
Tony Barbour8205d902015-04-16 15:59:00 -060039 case VK_BLEND_OP_ADD: return GEN6_BLENDFUNCTION_ADD;
40 case VK_BLEND_OP_SUBTRACT: return GEN6_BLENDFUNCTION_SUBTRACT;
41 case VK_BLEND_OP_REVERSE_SUBTRACT: return GEN6_BLENDFUNCTION_REVERSE_SUBTRACT;
42 case VK_BLEND_OP_MIN: return GEN6_BLENDFUNCTION_MIN;
43 case VK_BLEND_OP_MAX: return GEN6_BLENDFUNCTION_MAX;
Tony Barbourfa6cac72015-01-16 14:27:35 -070044 default:
45 assert(!"unknown blend func");
46 return GEN6_BLENDFUNCTION_ADD;
47 };
48}
49
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060050static int translate_blend(VkBlend blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -070051{
52 switch (blend) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060053 case VK_BLEND_ZERO: return GEN6_BLENDFACTOR_ZERO;
54 case VK_BLEND_ONE: return GEN6_BLENDFACTOR_ONE;
55 case VK_BLEND_SRC_COLOR: return GEN6_BLENDFACTOR_SRC_COLOR;
56 case VK_BLEND_ONE_MINUS_SRC_COLOR: return GEN6_BLENDFACTOR_INV_SRC_COLOR;
57 case VK_BLEND_DEST_COLOR: return GEN6_BLENDFACTOR_DST_COLOR;
58 case VK_BLEND_ONE_MINUS_DEST_COLOR: return GEN6_BLENDFACTOR_INV_DST_COLOR;
59 case VK_BLEND_SRC_ALPHA: return GEN6_BLENDFACTOR_SRC_ALPHA;
60 case VK_BLEND_ONE_MINUS_SRC_ALPHA: return GEN6_BLENDFACTOR_INV_SRC_ALPHA;
61 case VK_BLEND_DEST_ALPHA: return GEN6_BLENDFACTOR_DST_ALPHA;
62 case VK_BLEND_ONE_MINUS_DEST_ALPHA: return GEN6_BLENDFACTOR_INV_DST_ALPHA;
63 case VK_BLEND_CONSTANT_COLOR: return GEN6_BLENDFACTOR_CONST_COLOR;
64 case VK_BLEND_ONE_MINUS_CONSTANT_COLOR: return GEN6_BLENDFACTOR_INV_CONST_COLOR;
65 case VK_BLEND_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_CONST_ALPHA;
66 case VK_BLEND_ONE_MINUS_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_INV_CONST_ALPHA;
67 case VK_BLEND_SRC_ALPHA_SATURATE: return GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE;
68 case VK_BLEND_SRC1_COLOR: return GEN6_BLENDFACTOR_SRC1_COLOR;
69 case VK_BLEND_ONE_MINUS_SRC1_COLOR: return GEN6_BLENDFACTOR_INV_SRC1_COLOR;
70 case VK_BLEND_SRC1_ALPHA: return GEN6_BLENDFACTOR_SRC1_ALPHA;
71 case VK_BLEND_ONE_MINUS_SRC1_ALPHA: return GEN6_BLENDFACTOR_INV_SRC1_ALPHA;
Tony Barbourfa6cac72015-01-16 14:27:35 -070072 default:
73 assert(!"unknown blend factor");
74 return GEN6_BLENDFACTOR_ONE;
75 };
76}
77
Tony Barbour8205d902015-04-16 15:59:00 -060078static int translate_compare_func(VkCompareOp func)
Tony Barbourfa6cac72015-01-16 14:27:35 -070079{
80 switch (func) {
Tony Barbour8205d902015-04-16 15:59:00 -060081 case VK_COMPARE_OP_NEVER: return GEN6_COMPAREFUNCTION_NEVER;
82 case VK_COMPARE_OP_LESS: return GEN6_COMPAREFUNCTION_LESS;
83 case VK_COMPARE_OP_EQUAL: return GEN6_COMPAREFUNCTION_EQUAL;
84 case VK_COMPARE_OP_LESS_EQUAL: return GEN6_COMPAREFUNCTION_LEQUAL;
85 case VK_COMPARE_OP_GREATER: return GEN6_COMPAREFUNCTION_GREATER;
86 case VK_COMPARE_OP_NOT_EQUAL: return GEN6_COMPAREFUNCTION_NOTEQUAL;
87 case VK_COMPARE_OP_GREATER_EQUAL: return GEN6_COMPAREFUNCTION_GEQUAL;
88 case VK_COMPARE_OP_ALWAYS: return GEN6_COMPAREFUNCTION_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -070089 default:
90 assert(!"unknown compare_func");
91 return GEN6_COMPAREFUNCTION_NEVER;
92 }
93}
94
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060095static int translate_stencil_op(VkStencilOp op)
Tony Barbourfa6cac72015-01-16 14:27:35 -070096{
97 switch (op) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060098 case VK_STENCIL_OP_KEEP: return GEN6_STENCILOP_KEEP;
99 case VK_STENCIL_OP_ZERO: return GEN6_STENCILOP_ZERO;
100 case VK_STENCIL_OP_REPLACE: return GEN6_STENCILOP_REPLACE;
101 case VK_STENCIL_OP_INC_CLAMP: return GEN6_STENCILOP_INCRSAT;
102 case VK_STENCIL_OP_DEC_CLAMP: return GEN6_STENCILOP_DECRSAT;
103 case VK_STENCIL_OP_INVERT: return GEN6_STENCILOP_INVERT;
104 case VK_STENCIL_OP_INC_WRAP: return GEN6_STENCILOP_INCR;
105 case VK_STENCIL_OP_DEC_WRAP: return GEN6_STENCILOP_DECR;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700106 default:
107 assert(!"unknown stencil op");
108 return GEN6_STENCILOP_KEEP;
109 }
110}
111
Chia-I Wu3f239832014-12-11 22:57:18 +0800112struct intel_pipeline_create_info {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600113 VkGraphicsPipelineCreateInfo graphics;
114 VkPipelineVertexInputCreateInfo vi;
115 VkPipelineIaStateCreateInfo ia;
116 VkPipelineDsStateCreateInfo db;
117 VkPipelineCbStateCreateInfo cb;
118 VkPipelineRsStateCreateInfo rs;
119 VkPipelineTessStateCreateInfo tess;
120 VkPipelineMsStateCreateInfo ms;
121 VkPipelineVpStateCreateInfo vp;
122 VkPipelineShader vs;
123 VkPipelineShader tcs;
124 VkPipelineShader tes;
125 VkPipelineShader gs;
126 VkPipelineShader fs;
Chia-I Wu3f239832014-12-11 22:57:18 +0800127
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600128 VkComputePipelineCreateInfo compute;
Chia-I Wu3f239832014-12-11 22:57:18 +0800129};
Chia-I Wu38d1ddf2015-03-02 10:51:39 -0700130
131/* in S1.3 */
132struct intel_pipeline_sample_position {
133 int8_t x, y;
134};
135
136static uint8_t pack_sample_position(const struct intel_dev *dev,
137 const struct intel_pipeline_sample_position *pos)
138{
139 return (pos->x + 8) << 4 | (pos->y + 8);
140}
141
142void intel_pipeline_init_default_sample_patterns(const struct intel_dev *dev,
143 uint8_t *pat_1x, uint8_t *pat_2x,
144 uint8_t *pat_4x, uint8_t *pat_8x,
145 uint8_t *pat_16x)
146{
147 static const struct intel_pipeline_sample_position default_1x[1] = {
148 { 0, 0 },
149 };
150 static const struct intel_pipeline_sample_position default_2x[2] = {
151 { -4, -4 },
152 { 4, 4 },
153 };
154 static const struct intel_pipeline_sample_position default_4x[4] = {
155 { -2, -6 },
156 { 6, -2 },
157 { -6, 2 },
158 { 2, 6 },
159 };
160 static const struct intel_pipeline_sample_position default_8x[8] = {
161 { -1, 1 },
162 { 1, 5 },
163 { 3, -5 },
164 { 5, 3 },
165 { -7, -1 },
166 { -3, -7 },
167 { 7, -3 },
168 { -5, 7 },
169 };
170 static const struct intel_pipeline_sample_position default_16x[16] = {
171 { 0, 2 },
172 { 3, 0 },
173 { -3, -2 },
174 { -2, -4 },
175 { 4, 3 },
176 { 5, 1 },
177 { 6, -1 },
178 { 2, -6 },
179 { -4, 5 },
180 { -5, -5 },
181 { -1, -7 },
182 { 7, -3 },
183 { -7, 4 },
184 { 1, -8 },
185 { -6, 6 },
186 { -8, 7 },
187 };
188 int i;
189
190 pat_1x[0] = pack_sample_position(dev, default_1x);
191 for (i = 0; i < 2; i++)
192 pat_2x[i] = pack_sample_position(dev, &default_2x[i]);
193 for (i = 0; i < 4; i++)
194 pat_4x[i] = pack_sample_position(dev, &default_4x[i]);
195 for (i = 0; i < 8; i++)
196 pat_8x[i] = pack_sample_position(dev, &default_8x[i]);
197 for (i = 0; i < 16; i++)
198 pat_16x[i] = pack_sample_position(dev, &default_16x[i]);
199}
200
Chia-I Wu3f239832014-12-11 22:57:18 +0800201struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
202 enum intel_dev_meta_shader id)
203{
204 struct intel_pipeline_shader *sh;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600205 VkResult ret;
Chia-I Wu3f239832014-12-11 22:57:18 +0800206
Tony Barbour8205d902015-04-16 15:59:00 -0600207 sh = intel_alloc(dev, sizeof(*sh), 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu3f239832014-12-11 22:57:18 +0800208 if (!sh)
209 return NULL;
210 memset(sh, 0, sizeof(*sh));
211
212 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600213 if (ret != VK_SUCCESS) {
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800214 intel_free(dev, sh);
Chia-I Wu3f239832014-12-11 22:57:18 +0800215 return NULL;
216 }
217
218 switch (id) {
219 case INTEL_DEV_META_VS_FILL_MEM:
220 case INTEL_DEV_META_VS_COPY_MEM:
221 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
222 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600223 VK_SHADER_STAGE_VERTEX);
Chia-I Wu3f239832014-12-11 22:57:18 +0800224 break;
225 default:
226 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600227 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu3f239832014-12-11 22:57:18 +0800228 break;
229 }
230
231 return sh;
232}
233
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800234void intel_pipeline_shader_destroy(struct intel_dev *dev,
235 struct intel_pipeline_shader *sh)
Chia-I Wu3f239832014-12-11 22:57:18 +0800236{
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800237 intel_pipeline_shader_cleanup(sh, dev->gpu);
238 intel_free(dev, sh);
Chia-I Wu3f239832014-12-11 22:57:18 +0800239}
240
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600241static VkResult pipeline_build_shader(struct intel_pipeline *pipeline,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 const VkPipelineShader *sh_info,
Chia-I Wuf8385062015-01-04 16:27:24 +0800243 struct intel_pipeline_shader *sh)
Chia-I Wu3f239832014-12-11 22:57:18 +0800244{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600245 VkResult ret;
Chia-I Wu3f239832014-12-11 22:57:18 +0800246
Cody Northropbc12f872015-04-29 13:22:07 -0600247 const struct intel_ir* ir = intel_shader(sh_info->shader)->ir;
248
Chia-I Wuf8385062015-01-04 16:27:24 +0800249 ret = intel_pipeline_shader_compile(sh,
Cody Northropbc12f872015-04-29 13:22:07 -0600250 pipeline->dev->gpu, pipeline->pipeline_layout, sh_info, ir);
251
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600252 if (ret != VK_SUCCESS)
Chia-I Wu3f239832014-12-11 22:57:18 +0800253 return ret;
254
255 sh->max_threads =
256 intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage);
257
258 /* 1KB aligned */
259 sh->scratch_offset = u_align(pipeline->scratch_size, 1024);
260 pipeline->scratch_size = sh->scratch_offset +
261 sh->per_thread_scratch_size * sh->max_threads;
262
263 pipeline->active_shaders |= 1 << sh_info->stage;
264
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600265 return VK_SUCCESS;
Chia-I Wu3f239832014-12-11 22:57:18 +0800266}
267
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600268static VkResult pipeline_build_shaders(struct intel_pipeline *pipeline,
Chia-I Wu3f239832014-12-11 22:57:18 +0800269 const struct intel_pipeline_create_info *info)
270{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600271 VkResult ret = VK_SUCCESS;
Chia-I Wu3f239832014-12-11 22:57:18 +0800272
Chia-I Wudf601c42015-04-17 01:58:07 +0800273 if (ret == VK_SUCCESS && info->vs.shader)
274 ret = pipeline_build_shader(pipeline, &info->vs, &pipeline->vs);
275 if (ret == VK_SUCCESS && info->tcs.shader)
276 ret = pipeline_build_shader(pipeline, &info->tcs,&pipeline->tcs);
277 if (ret == VK_SUCCESS && info->tes.shader)
278 ret = pipeline_build_shader(pipeline, &info->tes,&pipeline->tes);
279 if (ret == VK_SUCCESS && info->gs.shader)
280 ret = pipeline_build_shader(pipeline, &info->gs, &pipeline->gs);
281 if (ret == VK_SUCCESS && info->fs.shader)
282 ret = pipeline_build_shader(pipeline, &info->fs, &pipeline->fs);
Chia-I Wu3f239832014-12-11 22:57:18 +0800283
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600284 if (ret == VK_SUCCESS && info->compute.cs.shader) {
Chia-I Wudf601c42015-04-17 01:58:07 +0800285 ret = pipeline_build_shader(pipeline,
Chia-I Wuf8385062015-01-04 16:27:24 +0800286 &info->compute.cs, &pipeline->cs);
287 }
Chia-I Wu3f239832014-12-11 22:57:18 +0800288
289 return ret;
290}
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600291static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len)
292{
293 uint32_t *ptr;
294
295 assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES);
296 ptr = &pipeline->cmds[pipeline->cmd_len];
297 pipeline->cmd_len += cmd_len;
298 return ptr;
299}
300
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600301static VkResult pipeline_build_ia(struct intel_pipeline *pipeline,
Chia-I Wube0a3d92014-09-02 13:20:59 +0800302 const struct intel_pipeline_create_info* info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600303{
Chia-I Wube0a3d92014-09-02 13:20:59 +0800304 pipeline->topology = info->ia.topology;
305 pipeline->disable_vs_cache = info->ia.disableVertexReuse;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600306
Chia-I Wube0a3d92014-09-02 13:20:59 +0800307 switch (info->ia.topology) {
Tony Barbour8205d902015-04-16 15:59:00 -0600308 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600309 pipeline->prim_type = GEN6_3DPRIM_POINTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600310 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600311 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600312 pipeline->prim_type = GEN6_3DPRIM_LINELIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600313 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600314 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600315 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600316 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600317 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600318 pipeline->prim_type = GEN6_3DPRIM_TRILIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600319 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600320 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600321 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600322 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600323 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
Courtney Goeltzenleuchter528781d2015-03-03 11:38:12 -0700324 pipeline->prim_type = GEN6_3DPRIM_TRIFAN;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600325 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600326 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600327 pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600328 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600329 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600330 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600331 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600332 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600333 pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600334 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600335 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600336 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600337 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600338 case VK_PRIMITIVE_TOPOLOGY_PATCH:
Chia-I Wube0a3d92014-09-02 13:20:59 +0800339 if (!info->tess.patchControlPoints ||
340 info->tess.patchControlPoints > 32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600341 return VK_ERROR_BAD_PIPELINE_DATA;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800342 pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 +
343 info->tess.patchControlPoints - 1;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600344 break;
345 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600346 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600347 }
348
Chia-I Wube0a3d92014-09-02 13:20:59 +0800349 if (info->ia.primitiveRestartEnable) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600350 pipeline->primitive_restart = true;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800351 pipeline->primitive_restart_index = info->ia.primitiveRestartIndex;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600352 } else {
353 pipeline->primitive_restart = false;
354 }
355
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600356 return VK_SUCCESS;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600357}
358
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600359static VkResult pipeline_build_rs_state(struct intel_pipeline *pipeline,
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800360 const struct intel_pipeline_create_info* info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600361{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600362 const VkPipelineRsStateCreateInfo *rs_state = &info->rs;
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800363 bool ccw;
364
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600365 pipeline->depthClipEnable = rs_state->depthClipEnable;
366 pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700367
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600368 if (rs_state->provokingVertex == VK_PROVOKING_VERTEX_FIRST) {
Tony Barbourfa6cac72015-01-16 14:27:35 -0700369 pipeline->provoking_vertex_tri = 0;
370 pipeline->provoking_vertex_trifan = 1;
371 pipeline->provoking_vertex_line = 0;
372 } else {
373 pipeline->provoking_vertex_tri = 2;
374 pipeline->provoking_vertex_trifan = 2;
375 pipeline->provoking_vertex_line = 1;
376 }
377
378 switch (rs_state->fillMode) {
Tony Barbour8205d902015-04-16 15:59:00 -0600379 case VK_FILL_MODE_POINTS:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700380 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT |
381 GEN7_SF_DW1_BACKFACE_POINT;
382 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600383 case VK_FILL_MODE_WIREFRAME:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700384 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME |
385 GEN7_SF_DW1_BACKFACE_WIREFRAME;
386 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600387 case VK_FILL_MODE_SOLID:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700388 default:
389 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID |
390 GEN7_SF_DW1_BACKFACE_SOLID;
391 break;
392 }
393
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600394 ccw = (rs_state->frontFace == VK_FRONT_FACE_CCW);
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800395 /* flip the winding order */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600396 if (info->vp.clipOrigin == VK_COORDINATE_ORIGIN_LOWER_LEFT)
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800397 ccw = !ccw;
398
399 if (ccw) {
Tony Barbourfa6cac72015-01-16 14:27:35 -0700400 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW;
401 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW;
402 }
403
404 switch (rs_state->cullMode) {
Tony Barbour8205d902015-04-16 15:59:00 -0600405 case VK_CULL_MODE_NONE:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700406 default:
407 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE;
408 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE;
409 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600410 case VK_CULL_MODE_FRONT:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT;
412 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT;
413 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600414 case VK_CULL_MODE_BACK:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700415 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK;
416 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK;
417 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600418 case VK_CULL_MODE_FRONT_AND_BACK:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700419 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH;
420 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH;
421 break;
422 }
423
424 /* only GEN7+ needs cull mode in 3DSTATE_CLIP */
425 if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
426 pipeline->cmd_clip_cull = 0;
427
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428 return VK_SUCCESS;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600429}
430
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600431static void pipeline_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600432{
433 struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj);
434
Chia-I Wu3f239832014-12-11 22:57:18 +0800435 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800436 intel_pipeline_shader_cleanup(&pipeline->vs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800437 }
438
439 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800440 intel_pipeline_shader_cleanup(&pipeline->tcs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800441 }
442
443 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800444 intel_pipeline_shader_cleanup(&pipeline->tes, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800445 }
446
447 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800448 intel_pipeline_shader_cleanup(&pipeline->gs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800449 }
450
451 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800452 intel_pipeline_shader_cleanup(&pipeline->fs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800453 }
454
455 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800456 intel_pipeline_shader_cleanup(&pipeline->cs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800457 }
Chia-I Wued833872014-08-23 17:00:35 +0800458
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600459 intel_base_destroy(&pipeline->obj.base);
460}
461
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600462static VkResult pipeline_get_info(struct intel_base *base, int type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600463 size_t *size, void *data)
Chia-I Wub1024732014-12-19 13:00:29 +0800464{
465 struct intel_pipeline *pipeline = intel_pipeline_from_base(base);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466 VkResult ret = VK_SUCCESS;
Chia-I Wub1024732014-12-19 13:00:29 +0800467
468 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600469 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS:
Chia-I Wub1024732014-12-19 13:00:29 +0800470 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600471 VkMemoryRequirements *mem_req = data;
Chia-I Wub1024732014-12-19 13:00:29 +0800472
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600473 *size = sizeof(VkMemoryRequirements);
Chia-I Wub1024732014-12-19 13:00:29 +0800474 if (data) {
475 mem_req->size = pipeline->scratch_size;
476 mem_req->alignment = 1024;
Jeremy Hayesd02809a2015-04-15 14:17:56 -0600477 mem_req->memPropsAllowed = INTEL_MEMORY_PROPERTY_ALL;
Chia-I Wub1024732014-12-19 13:00:29 +0800478 }
479 }
480 break;
481 default:
482 ret = intel_base_get_info(base, type, size, data);
483 break;
484 }
485
486 return ret;
487}
488
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600489static VkResult pipeline_validate(struct intel_pipeline *pipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +0800490{
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600491 /*
492 * Validate required elements
493 */
494 if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) {
495 // TODO: Log debug message: Vertex Shader required.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600497 }
498
499 /*
500 * Tessalation control and evaluation have to both have a shader defined or
501 * neither should have a shader defined.
502 */
503 if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) !=
504 ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) {
505 // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600506 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600507 }
508
509 if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) &&
510 (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG |
511 SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG |
512 SHADER_FRAGMENT_FLAG))) {
513 // TODO: Log debug message: Can only specify compute shader when doing compute
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600514 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600515 }
516
517 /*
Tony Barbour8205d902015-04-16 15:59:00 -0600518 * VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600519 * Mismatching primitive topology and tessellation fails graphics pipeline creation.
520 */
521 if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) &&
Tony Barbour8205d902015-04-16 15:59:00 -0600522 (pipeline->topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600523 // TODO: Log debug message: Invalid topology used with tessalation shader.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600524 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600525 }
526
Tony Barbour8205d902015-04-16 15:59:00 -0600527 if ((pipeline->topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600528 (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) {
529 // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600530 return VK_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600531 }
532
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600533 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +0800534}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600535
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800536static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
537 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800538{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800539 const struct intel_gpu *gpu = pipeline->dev->gpu;
540 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wua4d1b392014-10-10 13:57:29 +0800541 const struct intel_pipeline_shader *vs = &pipeline->vs;
542 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800543 int vs_entry_size, gs_entry_size;
544 int vs_size, gs_size;
545
Chia-I Wu509b3f22014-09-02 10:24:05 +0800546 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800547
548 vs_entry_size = ((vs->in_count >= vs->out_count) ?
549 vs->in_count : vs->out_count);
550 gs_entry_size = (gs) ? gs->out_count : 0;
551
552 /* in bytes */
553 vs_entry_size *= sizeof(float) * 4;
554 gs_entry_size *= sizeof(float) * 4;
555
Chia-I Wua4d1b392014-10-10 13:57:29 +0800556 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800557 vs_size = urb_size / 2;
558 gs_size = vs_size;
559 } else {
560 vs_size = urb_size;
561 gs_size = 0;
562 }
563
564 /* 3DSTATE_URB */
565 {
566 const uint8_t cmd_len = 3;
567 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
568 (cmd_len - 2);
569 int vs_alloc_size, gs_alloc_size;
570 int vs_entry_count, gs_entry_count;
571 uint32_t *dw;
572
573 /* in 1024-bit rows */
574 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
575 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
576
577 /* valid range is [1, 5] */
578 if (!vs_alloc_size)
579 vs_alloc_size = 1;
580 if (!gs_alloc_size)
581 gs_alloc_size = 1;
582 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
583
584 /* valid range is [24, 256], multiples of 4 */
585 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
586 if (vs_entry_count > 256)
587 vs_entry_count = 256;
588 assert(vs_entry_count >= 24);
589
590 /* valid range is [0, 256], multiples of 4 */
591 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
592 if (gs_entry_count > 256)
593 gs_entry_count = 256;
594
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600595 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800596
597 dw[0] = dw0;
598 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
599 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
600 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
601 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
602 }
603}
604
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800605static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
606 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800607{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800608 const struct intel_gpu *gpu = pipeline->dev->gpu;
609 const int urb_size = ((gpu->gt == 3) ? 512 :
610 (gpu->gt == 2) ? 256 : 128) * 1024;
Cody Northrop306ec352014-10-06 15:11:45 -0600611 const struct intel_pipeline_shader *vs = &pipeline->vs;
612 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800613 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800614 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800615 int vs_entry_size, gs_entry_size;
616 int vs_size, gs_size;
617
Chia-I Wu509b3f22014-09-02 10:24:05 +0800618 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800619
620 vs_entry_size = ((vs->in_count >= vs->out_count) ?
621 vs->in_count : vs->out_count);
622 gs_entry_size = (gs) ? gs->out_count : 0;
623
624 /* in bytes */
625 vs_entry_size *= sizeof(float) * 4;
626 gs_entry_size *= sizeof(float) * 4;
627
Chia-I Wua4d1b392014-10-10 13:57:29 +0800628 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800629 vs_size = (urb_size - urb_offset) / 2;
630 gs_size = vs_size;
631 } else {
632 vs_size = urb_size - urb_offset;
633 gs_size = 0;
634 }
635
636 /* 3DSTATE_URB_* */
637 {
638 const uint8_t cmd_len = 2;
639 int vs_alloc_size, gs_alloc_size;
640 int vs_entry_count, gs_entry_count;
641 uint32_t *dw;
642
643 /* in 512-bit rows */
644 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
645 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
646
647 if (!vs_alloc_size)
648 vs_alloc_size = 1;
649 if (!gs_alloc_size)
650 gs_alloc_size = 1;
651
652 /* avoid performance decrease due to banking */
653 if (vs_alloc_size == 5)
654 vs_alloc_size = 6;
655
656 /* in multiples of 8 */
657 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
658 assert(vs_entry_count >= 32);
659
660 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
661
Chia-I Wu509b3f22014-09-02 10:24:05 +0800662 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800663 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800664 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800665 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800666 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800667 if (vs_entry_count >= max_vs_entry_count)
668 vs_entry_count = max_vs_entry_count;
669 if (gs_entry_count >= max_gs_entry_count)
670 gs_entry_count = max_gs_entry_count;
671 } else {
672 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800673 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800674 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800675 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800676 if (vs_entry_count >= max_vs_entry_count)
677 vs_entry_count = max_vs_entry_count;
678 if (gs_entry_count >= max_gs_entry_count)
679 gs_entry_count = max_gs_entry_count;
680 }
681
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600682 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800683 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700684 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
685 (vs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800686 vs_entry_count;
687
688 dw += 2;
689 if (gs_size)
690 urb_offset += vs_size;
691 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700692 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
693 (gs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800694 gs_entry_count;
695
696 dw += 2;
697 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700698 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800699
700 dw += 2;
701 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700702 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800703 }
704}
705
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800706static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
707 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800708{
Cody Northrop306ec352014-10-06 15:11:45 -0600709 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu1d125092014-10-08 08:49:38 +0800710 uint8_t cmd_len;
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800711 uint32_t *dw;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600712 uint32_t i, j;
713 uint32_t attr_count;
714 uint32_t attrs_processed;
Chia-I Wu1d125092014-10-08 08:49:38 +0800715 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800716
Chia-I Wu509b3f22014-09-02 10:24:05 +0800717 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800718
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600719 attr_count = u_popcountll(vs->inputs_read);
720 cmd_len = 1 + 2 * attr_count;
Chia-I Wu1d125092014-10-08 08:49:38 +0800721 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
722 cmd_len += 2;
723
724 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800725 return;
726
727 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800728
729 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
730 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800731 dw++;
732
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800733 /* VERTEX_ELEMENT_STATE */
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600734 for (i = 0, attrs_processed = 0; attrs_processed < attr_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600735 VkVertexInputAttributeDescription *attr = NULL;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600736
737 /*
738 * The compiler will pack the shader references and then
739 * indicate which locations are used via the bitmask in
740 * vs->inputs_read.
741 */
742 if (!(vs->inputs_read & (1L << i))) {
GregF2dc40212014-10-31 17:31:47 -0600743 continue;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600744 }
745
746 /*
747 * For each bit set in the vs->inputs_read we'll need
748 * to find the corresponding attribute record and then
749 * set up the next HW vertex element based on that attribute.
750 */
751 for (j = 0; j < info->vi.attributeCount; j++) {
752 if (info->vi.pVertexAttributeDescriptions[j].location == i) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600753 attr = (VkVertexInputAttributeDescription *) &info->vi.pVertexAttributeDescriptions[j];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600754 attrs_processed++;
755 break;
756 }
757 }
758 assert(attr != NULL);
759
Chia-I Wu1d125092014-10-08 08:49:38 +0800760 const int format =
761 intel_format_translate_color(pipeline->dev->gpu, attr->format);
762
763 comps[0] = GEN6_VFCOMP_STORE_0;
764 comps[1] = GEN6_VFCOMP_STORE_0;
765 comps[2] = GEN6_VFCOMP_STORE_0;
766 comps[3] = icd_format_is_int(attr->format) ?
767 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
768
769 switch (icd_format_get_channel_count(attr->format)) {
770 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
771 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
772 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
773 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
774 default:
775 break;
776 }
777
778 assert(attr->offsetInBytes <= 2047);
779
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700780 dw[0] = attr->binding << GEN6_VE_DW0_VB_INDEX__SHIFT |
781 GEN6_VE_DW0_VALID |
782 format << GEN6_VE_DW0_FORMAT__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +0800783 attr->offsetInBytes;
784
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700785 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
786 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
787 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
788 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu1d125092014-10-08 08:49:38 +0800789
790 dw += 2;
791 }
GregF932fcf52014-10-29 17:02:11 -0600792
793 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
794 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
795 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
796 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
797 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
798 comps[2] = GEN6_VFCOMP_NOSTORE;
799 comps[3] = GEN6_VFCOMP_NOSTORE;
800
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700801 dw[0] = GEN6_VE_DW0_VALID;
802 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
803 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
804 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
805 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
GregF932fcf52014-10-29 17:02:11 -0600806
807 dw += 2;
808 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800809}
810
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800811static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline,
812 const struct intel_pipeline_create_info *info)
GregF8cd81832014-11-18 18:01:01 -0700813{
814 const struct intel_pipeline_shader *fs = &pipeline->fs;
GregF8cd81832014-11-18 18:01:01 -0700815 uint8_t cmd_len;
816 uint32_t *body;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600817 uint32_t attr_skip, attr_count;
818 uint32_t vue_offset, vue_len;
819 uint32_t i;
GregF8cd81832014-11-18 18:01:01 -0700820
Cody Northrop293d4502015-05-05 09:38:03 -0600821 // If GS is active, use its outputs
822 const struct intel_pipeline_shader *src =
823 (pipeline->active_shaders & SHADER_GEOMETRY_FLAG)
824 ? &pipeline->gs
825 : &pipeline->vs;
826
GregF8cd81832014-11-18 18:01:01 -0700827 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
828
829 cmd_len = 14;
830
Chia-I Wuf85def42015-01-29 00:34:24 +0800831 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7))
832 body = pipeline_cmd_ptr(pipeline, cmd_len);
833 else
834 body = pipeline->cmd_3dstate_sbe;
GregF8cd81832014-11-18 18:01:01 -0700835
Cody Northrop293d4502015-05-05 09:38:03 -0600836 assert(!fs->reads_user_clip || src->enable_user_clip);
837 attr_skip = src->outputs_offset;
838 if (src->enable_user_clip != fs->reads_user_clip) {
GregF8cd81832014-11-18 18:01:01 -0700839 attr_skip += 2;
840 }
Cody Northrop293d4502015-05-05 09:38:03 -0600841 assert(src->out_count >= attr_skip);
842 attr_count = src->out_count - attr_skip;
GregF8cd81832014-11-18 18:01:01 -0700843
844 // LUNARG TODO: We currently are only handling 16 attrs;
845 // ultimately, we need to handle 32
846 assert(fs->in_count <= 16);
847 assert(attr_count <= 16);
848
849 vue_offset = attr_skip / 2;
850 vue_len = (attr_count + 1) / 2;
851 if (!vue_len)
852 vue_len = 1;
853
854 body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
855 (cmd_len - 2);
856
857 // LUNARG TODO: If the attrs needed by the FS are exactly
858 // what is written by the VS, we don't need to enable
859 // swizzling, improving performance. Even if we swizzle,
860 // we can improve performance by reducing vue_len to
861 // just include the values needed by the FS:
862 // vue_len = ceiling((max_vs_out + 1)/2)
863
864 body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE |
865 fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
866 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
867 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
868
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800869 switch (info->rs.pointOrigin) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600870 case VK_COORDINATE_ORIGIN_UPPER_LEFT:
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800871 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT;
872 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600873 case VK_COORDINATE_ORIGIN_LOWER_LEFT:
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800874 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_LOWERLEFT;
875 break;
876 default:
877 assert(!"unknown point origin");
878 break;
879 }
880
Cody Northrop293d4502015-05-05 09:38:03 -0600881 uint16_t src_slot[fs->in_count];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600882 int32_t fs_in = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600883 int32_t src_out = - (vue_offset * 2 - src->outputs_offset);
GregF8cd81832014-11-18 18:01:01 -0700884 for (i=0; i < 64; i++) {
Cody Northrop293d4502015-05-05 09:38:03 -0600885 bool srcWrites = src->outputs_written & (1L << i);
886 bool fsReads = fs->inputs_read & (1L << i);
Cody Northropd75c13e2015-01-02 14:07:20 -0700887
888 if (fsReads) {
Cody Northrop293d4502015-05-05 09:38:03 -0600889 assert(src_out >= 0);
GregF8cd81832014-11-18 18:01:01 -0700890 assert(fs_in < fs->in_count);
Cody Northrop293d4502015-05-05 09:38:03 -0600891 src_slot[fs_in] = src_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700892
Cody Northrop293d4502015-05-05 09:38:03 -0600893 if (!srcWrites) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700894 // If the vertex shader did not write this input, we cannot
895 // program the SBE to read it. Our choices are to allow it to
896 // read junk from a GRF, or get zero. We're choosing zero.
897 if (i >= fs->generic_input_start) {
Cody Northrop293d4502015-05-05 09:38:03 -0600898 src_slot[fs_in] = GEN8_SBE_SWIZ_CONST_0000 |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700899 GEN8_SBE_SWIZ_OVERRIDE_X |
900 GEN8_SBE_SWIZ_OVERRIDE_Y |
901 GEN8_SBE_SWIZ_OVERRIDE_Z |
902 GEN8_SBE_SWIZ_OVERRIDE_W;
Cody Northropd75c13e2015-01-02 14:07:20 -0700903 }
904 }
905
GregF8cd81832014-11-18 18:01:01 -0700906 fs_in += 1;
907 }
Cody Northrop293d4502015-05-05 09:38:03 -0600908 if (srcWrites) {
909 src_out += 1;
GregF8cd81832014-11-18 18:01:01 -0700910 }
911 }
912
913 for (i = 0; i < 8; i++) {
914 uint16_t hi, lo;
915
916 /* no attr swizzles */
917 if (i * 2 + 1 < fs->in_count) {
Cody Northrop293d4502015-05-05 09:38:03 -0600918 lo = src_slot[i * 2];
919 hi = src_slot[i * 2 + 1];
GregF8cd81832014-11-18 18:01:01 -0700920 } else if (i * 2 < fs->in_count) {
Cody Northrop293d4502015-05-05 09:38:03 -0600921 lo = src_slot[i * 2];
GregF8cd81832014-11-18 18:01:01 -0700922 hi = 0;
923 } else {
924 hi = 0;
925 lo = 0;
926 }
927
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700928 body[2 + i] = hi << GEN8_SBE_SWIZ_HIGH__SHIFT | lo;
GregF8cd81832014-11-18 18:01:01 -0700929 }
930
Tony Barbour8205d902015-04-16 15:59:00 -0600931 if (info->ia.topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
Chia-I Wu7f390562015-03-25 08:47:18 +0800932 body[10] = fs->point_sprite_enables;
933 else
934 body[10] = 0;
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800935
GregF8cd81832014-11-18 18:01:01 -0700936 body[11] = 0; /* constant interpolation enables */
937 body[12] = 0; /* WrapShortest enables */
938 body[13] = 0;
939}
940
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800941static void pipeline_build_gs(struct intel_pipeline *pipeline,
942 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600943{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600944 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600945}
946
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800947static void pipeline_build_hs(struct intel_pipeline *pipeline,
948 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600949{
950 const uint8_t cmd_len = 7;
951 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
952 uint32_t *dw;
953
Chia-I Wu509b3f22014-09-02 10:24:05 +0800954 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600955
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800956 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600957 dw[0] = dw0;
958 dw[1] = 0;
959 dw[2] = 0;
960 dw[3] = 0;
961 dw[4] = 0;
962 dw[5] = 0;
963 dw[6] = 0;
964}
965
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800966static void pipeline_build_te(struct intel_pipeline *pipeline,
967 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600968{
969 const uint8_t cmd_len = 4;
970 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
971 uint32_t *dw;
972
Chia-I Wu509b3f22014-09-02 10:24:05 +0800973 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600974
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800975 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600976 dw[0] = dw0;
977 dw[1] = 0;
978 dw[2] = 0;
979 dw[3] = 0;
980}
981
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800982static void pipeline_build_ds(struct intel_pipeline *pipeline,
983 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600984{
985 const uint8_t cmd_len = 6;
986 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
987 uint32_t *dw;
988
Chia-I Wu509b3f22014-09-02 10:24:05 +0800989 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600990
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800991 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600992 dw[0] = dw0;
993 dw[1] = 0;
994 dw[2] = 0;
995 dw[3] = 0;
996 dw[4] = 0;
997 dw[5] = 0;
998}
999
Tony Barbourfa6cac72015-01-16 14:27:35 -07001000static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
1001 const struct intel_pipeline_create_info *info)
1002{
1003 pipeline->cmd_depth_stencil = 0;
1004
1005 if (info->db.stencilTestEnable) {
1006 pipeline->cmd_depth_stencil = 1 << 31 |
Tony Barbour8205d902015-04-16 15:59:00 -06001007 translate_compare_func(info->db.front.stencilCompareOp) << 28 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001008 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
1009 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
1010 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
1011 1 << 15 |
Tony Barbour8205d902015-04-16 15:59:00 -06001012 translate_compare_func(info->db.back.stencilCompareOp) << 12 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001013 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
1014 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
1015 translate_stencil_op(info->db.back.stencilPassOp) << 3;
1016 }
1017
1018 pipeline->stencilTestEnable = info->db.stencilTestEnable;
1019
1020 /*
1021 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
1022 *
1023 * "Enabling the Depth Test function without defining a Depth Buffer is
1024 * UNDEFINED."
1025 *
1026 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
1027 *
1028 * "A Depth Buffer must be defined before enabling writes to it, or
1029 * operation is UNDEFINED."
1030 *
1031 * TODO We do not check these yet.
1032 */
1033 if (info->db.depthTestEnable) {
1034 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
Tony Barbour8205d902015-04-16 15:59:00 -06001035 translate_compare_func(info->db.depthCompareOp) << 27;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001036 } else {
1037 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
1038 }
1039
1040 if (info->db.depthWriteEnable)
1041 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1042}
1043
Tony Barbourfa6cac72015-01-16 14:27:35 -07001044static void pipeline_build_msaa(struct intel_pipeline *pipeline,
1045 const struct intel_pipeline_create_info *info)
1046{
1047 uint32_t cmd, cmd_len;
1048 uint32_t *dw;
1049
1050 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1051
Chia-I Wu8ada4242015-03-02 11:19:33 -07001052 pipeline->sample_count = (info->ms.samples <= 1) ? 1 : info->ms.samples;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001053
1054 /* 3DSTATE_SAMPLE_MASK */
1055 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
1056 cmd_len = 2;
1057
Chia-I Wu8ada4242015-03-02 11:19:33 -07001058 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001059 dw[0] = cmd | (cmd_len - 2);
1060 dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1);
1061 pipeline->cmd_sample_mask = dw[1];
1062}
1063
1064static void pipeline_build_cb(struct intel_pipeline *pipeline,
1065 const struct intel_pipeline_create_info *info)
1066{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001067 uint32_t i;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001068
1069 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1070 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
1071 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
1072
1073 uint32_t *dw = pipeline->cmd_cb;
1074
1075 for (i = 0; i < info->cb.attachmentCount; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001076 const VkPipelineCbAttachmentState *att = &info->cb.pAttachments[i];
Tony Barbourfa6cac72015-01-16 14:27:35 -07001077 uint32_t dw0, dw1;
1078
1079
1080 dw0 = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001081 dw1 = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1082 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1083 GEN6_RT_DW1_POST_BLEND_CLAMP;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001084
1085 if (att->blendEnable) {
1086 dw0 = 1 << 31 |
Tony Barbour8205d902015-04-16 15:59:00 -06001087 translate_blend_func(att->blendOpAlpha) << 26 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001088 translate_blend(att->srcBlendAlpha) << 20 |
1089 translate_blend(att->destBlendAlpha) << 15 |
Tony Barbour8205d902015-04-16 15:59:00 -06001090 translate_blend_func(att->blendOpColor) << 11 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001091 translate_blend(att->srcBlendColor) << 5 |
1092 translate_blend(att->destBlendColor);
1093
Tony Barbour8205d902015-04-16 15:59:00 -06001094 if (att->blendOpAlpha != att->blendOpColor ||
Tony Barbourfa6cac72015-01-16 14:27:35 -07001095 att->srcBlendAlpha != att->srcBlendColor ||
1096 att->destBlendAlpha != att->destBlendColor)
1097 dw0 |= 1 << 30;
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -07001098
1099 pipeline->dual_source_blend_enable = icd_pipeline_cb_att_needs_dual_source_blending(att);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001100 }
1101
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001102 if (info->cb.logicOp != VK_LOGIC_OP_COPY) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07001103 int logicop;
1104
1105 switch (info->cb.logicOp) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001106 case VK_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1107 case VK_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1108 case VK_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1109 case VK_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1110 case VK_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1111 case VK_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1112 case VK_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1113 case VK_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1114 case VK_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1115 case VK_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1116 case VK_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1117 case VK_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1118 case VK_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1119 case VK_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1120 case VK_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001121 default:
1122 assert(!"unknown logic op");
1123 logicop = GEN6_LOGICOP_CLEAR;
1124 break;
1125 }
1126
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001127 dw1 |= GEN6_RT_DW1_LOGICOP_ENABLE |
1128 logicop << GEN6_RT_DW1_LOGICOP_FUNC__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001129 }
1130
1131 if (!(att->channelWriteMask & 0x1))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001132 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_R;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001133 if (!(att->channelWriteMask & 0x2))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001134 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_G;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001135 if (!(att->channelWriteMask & 0x4))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001136 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_B;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001137 if (!(att->channelWriteMask & 0x8))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001138 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001139
1140 dw[2 * i] = dw0;
1141 dw[2 * i + 1] = dw1;
1142 }
1143
1144 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1145 {
1146 dw[2 * i] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001147 dw[2 * i + 1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1148 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1149 GEN6_RT_DW1_POST_BLEND_CLAMP |
1150 GEN6_RT_DW1_WRITE_DISABLE_R |
1151 GEN6_RT_DW1_WRITE_DISABLE_G |
1152 GEN6_RT_DW1_WRITE_DISABLE_B |
1153 GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001154 }
1155
1156}
1157
1158
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001159static VkResult pipeline_build_all(struct intel_pipeline *pipeline,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001160 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001161{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001162 VkResult ret;
Chia-I Wu3efef432014-08-28 15:00:16 +08001163
Chia-I Wu98824592014-09-02 09:42:46 +08001164 ret = pipeline_build_shaders(pipeline, info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001165 if (ret != VK_SUCCESS)
Chia-I Wu98824592014-09-02 09:42:46 +08001166 return ret;
1167
Chia-I Wu1d125092014-10-08 08:49:38 +08001168 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
1169 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001170 return VK_ERROR_BAD_PIPELINE_DATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001171
Chia-I Wu2f455af2015-04-22 15:54:06 +08001172 if (info->vp.clipOrigin != VK_COORDINATE_ORIGIN_UPPER_LEFT) {
1173 assert(!"only VK_COORDINATE_ORIGIN_UPPER_LEFT is supported");
1174 return VK_ERROR_INVALID_VALUE;
1175 }
1176
Chia-I Wue2504cb2015-04-22 14:20:52 +08001177 if (info->vp.depthMode != VK_DEPTH_MODE_ZERO_TO_ONE) {
1178 assert(!"only VK_DEPTH_MODE_ZERO_TO_ONE is supported");
1179 return VK_ERROR_INVALID_VALUE;
1180 }
1181
Chia-I Wu1d125092014-10-08 08:49:38 +08001182 pipeline->vb_count = info->vi.bindingCount;
1183 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1184 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1185
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001186 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wu86a5e0c2015-03-24 11:01:50 +08001187 pipeline_build_fragment_SBE(pipeline, info);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001188 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001189 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001190
Chia-I Wu509b3f22014-09-02 10:24:05 +08001191 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001192 pipeline_build_urb_alloc_gen7(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001193 pipeline_build_gs(pipeline, info);
1194 pipeline_build_hs(pipeline, info);
1195 pipeline_build_te(pipeline, info);
1196 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001197
1198 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1199 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1200 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1201 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1202 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001203 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001204 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001205
1206 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1207 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001208 }
1209
Chia-I Wube0a3d92014-09-02 13:20:59 +08001210 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001211
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001212 if (ret == VK_SUCCESS)
Chia-I Wu6abcb0e2015-03-24 14:38:14 +08001213 ret = pipeline_build_rs_state(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001214
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001215 if (ret == VK_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001216 pipeline->db_format = info->db.format;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001217 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001218 pipeline->cb_state = info->cb;
1219 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001220 }
1221
1222 return ret;
1223}
1224
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001225struct intel_pipeline_create_info_header {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001226 VkStructureType struct_type;
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001227 const struct intel_pipeline_create_info_header *next;
1228};
1229
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001230static VkResult pipeline_create_info_init(struct intel_pipeline_create_info *info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001231 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +08001232{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001233 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001234
Tony Barbourfa6cac72015-01-16 14:27:35 -07001235
1236 /*
1237 * Do we need to set safe defaults in case the app doesn't provide all of
1238 * the necessary create infos?
1239 */
1240 info->ms.samples = 1;
1241 info->ms.sampleMask = 1;
1242
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001243 while (header) {
1244 const void *src = (const void *) header;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001245 size_t size;
Chia-I Wu3efef432014-08-28 15:00:16 +08001246 void *dst;
1247
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001248 switch (header->struct_type) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001249 case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001250 size = sizeof(info->graphics);
1251 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +08001252 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001253 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Chia-I Wu1d125092014-10-08 08:49:38 +08001254 size = sizeof(info->vi);
1255 dst = &info->vi;
1256 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001257 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001258 size = sizeof(info->ia);
1259 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +08001260 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001261 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001262 size = sizeof(info->db);
1263 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +08001264 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001265 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001266 size = sizeof(info->cb);
1267 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +08001268 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001269 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001270 size = sizeof(info->rs);
1271 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001272 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001273 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001274 size = sizeof(info->tess);
1275 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001276 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001277 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tony Barbourfa6cac72015-01-16 14:27:35 -07001278 size = sizeof(info->ms);
1279 dst = &info->ms;
1280 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001281 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tony Barbourfa6cac72015-01-16 14:27:35 -07001282 size = sizeof(info->vp);
1283 dst = &info->vp;
1284 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001285 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Chia-I Wu3efef432014-08-28 15:00:16 +08001286 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001287 const VkPipelineShader *shader =
1288 (const VkPipelineShader *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +08001289
1290 src = (const void *) shader;
1291 size = sizeof(*shader);
1292
1293 switch (shader->stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001294 case VK_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001295 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001296 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001297 case VK_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001298 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001299 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001300 case VK_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001301 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +08001302 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001303 case VK_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001304 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001305 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001306 case VK_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001307 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001308 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001309 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001310 return VK_ERROR_BAD_PIPELINE_DATA;
Chia-I Wu3efef432014-08-28 15:00:16 +08001311 break;
1312 }
1313 }
1314 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001315 case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001316 size = sizeof(info->compute);
1317 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +08001318 break;
1319 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001320 return VK_ERROR_BAD_PIPELINE_DATA;
Chia-I Wu3efef432014-08-28 15:00:16 +08001321 break;
1322 }
1323
1324 memcpy(dst, src, size);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001325 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +08001326 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001327
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001328 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001329}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001330
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001331static VkResult graphics_pipeline_create(struct intel_dev *dev,
1332 const VkGraphicsPipelineCreateInfo *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +08001333 struct intel_pipeline **pipeline_ret)
1334{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001335 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001336 struct intel_pipeline *pipeline;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001337 VkResult ret;
Chia-I Wu3efef432014-08-28 15:00:16 +08001338
Chia-I Wu509b3f22014-09-02 10:24:05 +08001339 ret = pipeline_create_info_init(&info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001340 (const struct intel_pipeline_create_info_header *) info_);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001341 if (ret != VK_SUCCESS)
Chia-I Wu3efef432014-08-28 15:00:16 +08001342 return ret;
1343
Chia-I Wu545c2e12015-02-22 13:19:54 +08001344 pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle,
1345 sizeof(*pipeline), dev->base.dbg,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001346 VK_OBJECT_TYPE_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001347 if (!pipeline)
Tony Barbour8205d902015-04-16 15:59:00 -06001348 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu3efef432014-08-28 15:00:16 +08001349
1350 pipeline->dev = dev;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001351 pipeline->pipeline_layout =
1352 intel_pipeline_layout(info.graphics.layout);
Chia-I Wudf601c42015-04-17 01:58:07 +08001353
Chia-I Wub1024732014-12-19 13:00:29 +08001354 pipeline->obj.base.get_info = pipeline_get_info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001355 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001356
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001357 ret = pipeline_build_all(pipeline, &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001358 if (ret == VK_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001359 ret = pipeline_validate(pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001360 if (ret != VK_SUCCESS) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001361 pipeline_destroy(&pipeline->obj);
1362 return ret;
1363 }
1364
1365 *pipeline_ret = pipeline;
1366
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001367 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001368}
1369
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001370ICD_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(
1371 VkDevice device,
1372 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1373 VkPipeline* pPipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +08001374{
1375 struct intel_dev *dev = intel_dev(device);
1376
1377 return graphics_pipeline_create(dev, pCreateInfo,
1378 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001379}
1380
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001381ICD_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1382 VkDevice device,
1383 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1384 VkPipeline basePipeline,
1385 VkPipeline* pPipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001386{
1387 struct intel_dev *dev = intel_dev(device);
1388
1389 /* TODO: Use basePipeline to optimize creation of derivative */
1390
1391 return graphics_pipeline_create(dev, pCreateInfo,
1392 (struct intel_pipeline **) pPipeline);
1393}
1394
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001395ICD_EXPORT VkResult VKAPI vkCreateComputePipeline(
1396 VkDevice device,
1397 const VkComputePipelineCreateInfo* pCreateInfo,
1398 VkPipeline* pPipeline)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001399{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001400 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001401}
1402
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001403ICD_EXPORT VkResult VKAPI vkStorePipeline(
Mike Stroyan230e6252015-04-17 12:36:38 -06001404 VkDevice device,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001405 VkPipeline pipeline,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001406 size_t* pDataSize,
1407 void* pData)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001408{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001409 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001410}
1411
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001412ICD_EXPORT VkResult VKAPI vkLoadPipeline(
1413 VkDevice device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001414 size_t dataSize,
1415 const void* pData,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001416 VkPipeline* pPipeline)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001417{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001418 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001419}
1420
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001421ICD_EXPORT VkResult VKAPI vkLoadPipelineDerivative(
1422 VkDevice device,
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001423 size_t dataSize,
1424 const void* pData,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001425 VkPipeline basePipeline,
1426 VkPipeline* pPipeline)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001427{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001428 return VK_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001429}