blob: 391feffb6797851b88db19894e065872211772ac [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
Courtney Goeltzenleuchter7db1fed2015-09-02 13:07:51 -0600286 if (ret == VK_SUCCESS && info->compute.stage.shader.handle) {
Chia-I Wudf601c42015-04-17 01:58:07 +0800287 ret = pipeline_build_shader(pipeline,
Courtney Goeltzenleuchter7db1fed2015-09-02 13:07:51 -0600288 &info->compute.stage, &pipeline->cs);
Chia-I Wuf8385062015-01-04 16:27:24 +0800289 }
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;
Courtney Goeltzenleuchter99349ec2015-07-12 15:35:40 -0600307 pipeline->disable_vs_cache = false;
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 pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 +
342 info->tess.patchControlPoints - 1;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600343 break;
344 default:
Tobin Ehlis20693172015-09-17 08:46:18 -0600345 assert(!"unsupported primitive topology format");
346 break;
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;
Courtney Goeltzenleuchtera7281c22015-07-12 15:42:02 -0600351 pipeline->primitive_restart_index = 0;
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{
Tony Barboure307f582015-07-10 15:29:03 -0600362 const VkPipelineRasterStateCreateInfo *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;
Cody Northropf5bd2252015-08-17 11:10:49 -0600367 pipeline->depthBiasEnable = rs_state->depthBiasEnable;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700368
Tony Barbourfa6cac72015-01-16 14:27:35 -0700369 switch (rs_state->fillMode) {
Tony Barbour8205d902015-04-16 15:59:00 -0600370 case VK_FILL_MODE_POINTS:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700371 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT |
372 GEN7_SF_DW1_BACKFACE_POINT;
373 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600374 case VK_FILL_MODE_WIREFRAME:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700375 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME |
376 GEN7_SF_DW1_BACKFACE_WIREFRAME;
377 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600378 case VK_FILL_MODE_SOLID:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700379 default:
380 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID |
381 GEN7_SF_DW1_BACKFACE_SOLID;
382 break;
383 }
384
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600385 ccw = (rs_state->frontFace == VK_FRONT_FACE_CCW);
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800386 /* flip the winding order */
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800387
388 if (ccw) {
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW;
390 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW;
391 }
392
393 switch (rs_state->cullMode) {
Tony Barbour8205d902015-04-16 15:59:00 -0600394 case VK_CULL_MODE_NONE:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700395 default:
396 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE;
397 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE;
398 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600399 case VK_CULL_MODE_FRONT:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700400 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT;
401 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT;
402 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600403 case VK_CULL_MODE_BACK:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700404 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK;
405 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK;
406 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600407 case VK_CULL_MODE_FRONT_AND_BACK:
Tony Barbourfa6cac72015-01-16 14:27:35 -0700408 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH;
409 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH;
410 break;
411 }
412
413 /* only GEN7+ needs cull mode in 3DSTATE_CLIP */
414 if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
415 pipeline->cmd_clip_cull = 0;
416
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600417 return VK_SUCCESS;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600418}
419
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600420static void pipeline_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600421{
422 struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj);
423
Chia-I Wu3f239832014-12-11 22:57:18 +0800424 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800425 intel_pipeline_shader_cleanup(&pipeline->vs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800426 }
427
428 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800429 intel_pipeline_shader_cleanup(&pipeline->tcs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800430 }
431
432 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800433 intel_pipeline_shader_cleanup(&pipeline->tes, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800434 }
435
436 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800437 intel_pipeline_shader_cleanup(&pipeline->gs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800438 }
439
440 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800441 intel_pipeline_shader_cleanup(&pipeline->fs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800442 }
443
444 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800445 intel_pipeline_shader_cleanup(&pipeline->cs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800446 }
Chia-I Wued833872014-08-23 17:00:35 +0800447
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600448 intel_base_destroy(&pipeline->obj.base);
449}
450
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800451static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
452 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800453{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800454 const struct intel_gpu *gpu = pipeline->dev->gpu;
455 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wua4d1b392014-10-10 13:57:29 +0800456 const struct intel_pipeline_shader *vs = &pipeline->vs;
457 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800458 int vs_entry_size, gs_entry_size;
459 int vs_size, gs_size;
460
Chia-I Wu509b3f22014-09-02 10:24:05 +0800461 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800462
463 vs_entry_size = ((vs->in_count >= vs->out_count) ?
464 vs->in_count : vs->out_count);
465 gs_entry_size = (gs) ? gs->out_count : 0;
466
467 /* in bytes */
468 vs_entry_size *= sizeof(float) * 4;
469 gs_entry_size *= sizeof(float) * 4;
470
Chia-I Wua4d1b392014-10-10 13:57:29 +0800471 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800472 vs_size = urb_size / 2;
473 gs_size = vs_size;
474 } else {
475 vs_size = urb_size;
476 gs_size = 0;
477 }
478
479 /* 3DSTATE_URB */
480 {
481 const uint8_t cmd_len = 3;
482 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
483 (cmd_len - 2);
484 int vs_alloc_size, gs_alloc_size;
485 int vs_entry_count, gs_entry_count;
486 uint32_t *dw;
487
488 /* in 1024-bit rows */
489 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
490 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
491
492 /* valid range is [1, 5] */
493 if (!vs_alloc_size)
494 vs_alloc_size = 1;
495 if (!gs_alloc_size)
496 gs_alloc_size = 1;
497 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
498
499 /* valid range is [24, 256], multiples of 4 */
500 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
501 if (vs_entry_count > 256)
502 vs_entry_count = 256;
503 assert(vs_entry_count >= 24);
504
505 /* valid range is [0, 256], multiples of 4 */
506 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
507 if (gs_entry_count > 256)
508 gs_entry_count = 256;
509
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600510 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800511
512 dw[0] = dw0;
513 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
514 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
515 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
516 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
517 }
518}
519
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800520static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
521 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800522{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800523 const struct intel_gpu *gpu = pipeline->dev->gpu;
524 const int urb_size = ((gpu->gt == 3) ? 512 :
525 (gpu->gt == 2) ? 256 : 128) * 1024;
Cody Northrop306ec352014-10-06 15:11:45 -0600526 const struct intel_pipeline_shader *vs = &pipeline->vs;
527 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800528 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800529 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800530 int vs_entry_size, gs_entry_size;
531 int vs_size, gs_size;
532
Chia-I Wu509b3f22014-09-02 10:24:05 +0800533 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800534
535 vs_entry_size = ((vs->in_count >= vs->out_count) ?
536 vs->in_count : vs->out_count);
537 gs_entry_size = (gs) ? gs->out_count : 0;
538
539 /* in bytes */
540 vs_entry_size *= sizeof(float) * 4;
541 gs_entry_size *= sizeof(float) * 4;
542
Chia-I Wua4d1b392014-10-10 13:57:29 +0800543 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800544 vs_size = (urb_size - urb_offset) / 2;
545 gs_size = vs_size;
546 } else {
547 vs_size = urb_size - urb_offset;
548 gs_size = 0;
549 }
550
551 /* 3DSTATE_URB_* */
552 {
553 const uint8_t cmd_len = 2;
554 int vs_alloc_size, gs_alloc_size;
555 int vs_entry_count, gs_entry_count;
556 uint32_t *dw;
557
558 /* in 512-bit rows */
559 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
560 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
561
562 if (!vs_alloc_size)
563 vs_alloc_size = 1;
564 if (!gs_alloc_size)
565 gs_alloc_size = 1;
566
567 /* avoid performance decrease due to banking */
568 if (vs_alloc_size == 5)
569 vs_alloc_size = 6;
570
571 /* in multiples of 8 */
572 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
573 assert(vs_entry_count >= 32);
574
575 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
576
Chia-I Wu509b3f22014-09-02 10:24:05 +0800577 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800578 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800579 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800580 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800581 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800582 if (vs_entry_count >= max_vs_entry_count)
583 vs_entry_count = max_vs_entry_count;
584 if (gs_entry_count >= max_gs_entry_count)
585 gs_entry_count = max_gs_entry_count;
586 } else {
587 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800588 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800589 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800590 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800591 if (vs_entry_count >= max_vs_entry_count)
592 vs_entry_count = max_vs_entry_count;
593 if (gs_entry_count >= max_gs_entry_count)
594 gs_entry_count = max_gs_entry_count;
595 }
596
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600597 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800598 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700599 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
600 (vs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800601 vs_entry_count;
602
603 dw += 2;
604 if (gs_size)
605 urb_offset += vs_size;
606 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700607 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
608 (gs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800609 gs_entry_count;
610
611 dw += 2;
612 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700613 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800614
615 dw += 2;
616 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700617 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800618 }
619}
620
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800621static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
622 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800623{
Cody Northrop306ec352014-10-06 15:11:45 -0600624 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu1d125092014-10-08 08:49:38 +0800625 uint8_t cmd_len;
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800626 uint32_t *dw;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600627 uint32_t i, j;
628 uint32_t attr_count;
629 uint32_t attrs_processed;
Chia-I Wu1d125092014-10-08 08:49:38 +0800630 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800631
Chia-I Wu509b3f22014-09-02 10:24:05 +0800632 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800633
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600634 attr_count = u_popcountll(vs->inputs_read);
635 cmd_len = 1 + 2 * attr_count;
Chia-I Wu1d125092014-10-08 08:49:38 +0800636 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
637 cmd_len += 2;
638
639 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800640 return;
641
642 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800643
644 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
645 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800646 dw++;
647
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800648 /* VERTEX_ELEMENT_STATE */
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600649 for (i = 0, attrs_processed = 0; attrs_processed < attr_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600650 VkVertexInputAttributeDescription *attr = NULL;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600651
652 /*
653 * The compiler will pack the shader references and then
654 * indicate which locations are used via the bitmask in
655 * vs->inputs_read.
656 */
657 if (!(vs->inputs_read & (1L << i))) {
GregF2dc40212014-10-31 17:31:47 -0600658 continue;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600659 }
660
661 /*
662 * For each bit set in the vs->inputs_read we'll need
663 * to find the corresponding attribute record and then
664 * set up the next HW vertex element based on that attribute.
665 */
666 for (j = 0; j < info->vi.attributeCount; j++) {
667 if (info->vi.pVertexAttributeDescriptions[j].location == i) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600668 attr = (VkVertexInputAttributeDescription *) &info->vi.pVertexAttributeDescriptions[j];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600669 attrs_processed++;
670 break;
671 }
672 }
673 assert(attr != NULL);
674
Chia-I Wu1d125092014-10-08 08:49:38 +0800675 const int format =
676 intel_format_translate_color(pipeline->dev->gpu, attr->format);
677
678 comps[0] = GEN6_VFCOMP_STORE_0;
679 comps[1] = GEN6_VFCOMP_STORE_0;
680 comps[2] = GEN6_VFCOMP_STORE_0;
681 comps[3] = icd_format_is_int(attr->format) ?
682 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
683
684 switch (icd_format_get_channel_count(attr->format)) {
685 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
686 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
687 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
688 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
689 default:
690 break;
691 }
692
693 assert(attr->offsetInBytes <= 2047);
694
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700695 dw[0] = attr->binding << GEN6_VE_DW0_VB_INDEX__SHIFT |
696 GEN6_VE_DW0_VALID |
697 format << GEN6_VE_DW0_FORMAT__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +0800698 attr->offsetInBytes;
699
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700700 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
701 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
702 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
703 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu1d125092014-10-08 08:49:38 +0800704
705 dw += 2;
706 }
GregF932fcf52014-10-29 17:02:11 -0600707
708 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
709 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
710 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
711 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
712 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
713 comps[2] = GEN6_VFCOMP_NOSTORE;
714 comps[3] = GEN6_VFCOMP_NOSTORE;
715
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700716 dw[0] = GEN6_VE_DW0_VALID;
717 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
718 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
719 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
720 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
GregF932fcf52014-10-29 17:02:11 -0600721
722 dw += 2;
723 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800724}
725
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800726static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline,
727 const struct intel_pipeline_create_info *info)
GregF8cd81832014-11-18 18:01:01 -0700728{
729 const struct intel_pipeline_shader *fs = &pipeline->fs;
GregF8cd81832014-11-18 18:01:01 -0700730 uint8_t cmd_len;
731 uint32_t *body;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600732 uint32_t attr_skip, attr_count;
733 uint32_t vue_offset, vue_len;
734 uint32_t i;
GregF8cd81832014-11-18 18:01:01 -0700735
Cody Northrop293d4502015-05-05 09:38:03 -0600736 // If GS is active, use its outputs
737 const struct intel_pipeline_shader *src =
738 (pipeline->active_shaders & SHADER_GEOMETRY_FLAG)
739 ? &pipeline->gs
740 : &pipeline->vs;
741
GregF8cd81832014-11-18 18:01:01 -0700742 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
743
744 cmd_len = 14;
745
Chia-I Wuf85def42015-01-29 00:34:24 +0800746 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7))
747 body = pipeline_cmd_ptr(pipeline, cmd_len);
748 else
749 body = pipeline->cmd_3dstate_sbe;
GregF8cd81832014-11-18 18:01:01 -0700750
Cody Northrop293d4502015-05-05 09:38:03 -0600751 assert(!fs->reads_user_clip || src->enable_user_clip);
752 attr_skip = src->outputs_offset;
753 if (src->enable_user_clip != fs->reads_user_clip) {
GregF8cd81832014-11-18 18:01:01 -0700754 attr_skip += 2;
755 }
Cody Northrop293d4502015-05-05 09:38:03 -0600756 assert(src->out_count >= attr_skip);
757 attr_count = src->out_count - attr_skip;
GregF8cd81832014-11-18 18:01:01 -0700758
759 // LUNARG TODO: We currently are only handling 16 attrs;
760 // ultimately, we need to handle 32
761 assert(fs->in_count <= 16);
762 assert(attr_count <= 16);
763
764 vue_offset = attr_skip / 2;
765 vue_len = (attr_count + 1) / 2;
766 if (!vue_len)
767 vue_len = 1;
768
769 body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
770 (cmd_len - 2);
771
772 // LUNARG TODO: If the attrs needed by the FS are exactly
773 // what is written by the VS, we don't need to enable
774 // swizzling, improving performance. Even if we swizzle,
775 // we can improve performance by reducing vue_len to
776 // just include the values needed by the FS:
777 // vue_len = ceiling((max_vs_out + 1)/2)
778
779 body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE |
780 fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
781 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
782 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
783
Courtney Goeltzenleuchter9c057f52015-07-12 14:53:14 -0600784 /* Vulkan default is point origin upper left */
785 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT;
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800786
Cody Northrop293d4502015-05-05 09:38:03 -0600787 uint16_t src_slot[fs->in_count];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600788 int32_t fs_in = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600789 int32_t src_out = - (vue_offset * 2 - src->outputs_offset);
GregF8cd81832014-11-18 18:01:01 -0700790 for (i=0; i < 64; i++) {
Cody Northrop293d4502015-05-05 09:38:03 -0600791 bool srcWrites = src->outputs_written & (1L << i);
792 bool fsReads = fs->inputs_read & (1L << i);
Cody Northropd75c13e2015-01-02 14:07:20 -0700793
794 if (fsReads) {
Cody Northrop293d4502015-05-05 09:38:03 -0600795 assert(src_out >= 0);
GregF8cd81832014-11-18 18:01:01 -0700796 assert(fs_in < fs->in_count);
Cody Northrop293d4502015-05-05 09:38:03 -0600797 src_slot[fs_in] = src_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700798
Cody Northrop293d4502015-05-05 09:38:03 -0600799 if (!srcWrites) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700800 // If the vertex shader did not write this input, we cannot
801 // program the SBE to read it. Our choices are to allow it to
802 // read junk from a GRF, or get zero. We're choosing zero.
803 if (i >= fs->generic_input_start) {
Cody Northrop293d4502015-05-05 09:38:03 -0600804 src_slot[fs_in] = GEN8_SBE_SWIZ_CONST_0000 |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700805 GEN8_SBE_SWIZ_OVERRIDE_X |
806 GEN8_SBE_SWIZ_OVERRIDE_Y |
807 GEN8_SBE_SWIZ_OVERRIDE_Z |
808 GEN8_SBE_SWIZ_OVERRIDE_W;
Cody Northropd75c13e2015-01-02 14:07:20 -0700809 }
810 }
811
GregF8cd81832014-11-18 18:01:01 -0700812 fs_in += 1;
813 }
Cody Northrop293d4502015-05-05 09:38:03 -0600814 if (srcWrites) {
815 src_out += 1;
GregF8cd81832014-11-18 18:01:01 -0700816 }
817 }
818
819 for (i = 0; i < 8; i++) {
820 uint16_t hi, lo;
821
822 /* no attr swizzles */
823 if (i * 2 + 1 < fs->in_count) {
Cody Northrop293d4502015-05-05 09:38:03 -0600824 lo = src_slot[i * 2];
825 hi = src_slot[i * 2 + 1];
GregF8cd81832014-11-18 18:01:01 -0700826 } else if (i * 2 < fs->in_count) {
Cody Northrop293d4502015-05-05 09:38:03 -0600827 lo = src_slot[i * 2];
GregF8cd81832014-11-18 18:01:01 -0700828 hi = 0;
829 } else {
830 hi = 0;
831 lo = 0;
832 }
833
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700834 body[2 + i] = hi << GEN8_SBE_SWIZ_HIGH__SHIFT | lo;
GregF8cd81832014-11-18 18:01:01 -0700835 }
836
Tony Barbour8205d902015-04-16 15:59:00 -0600837 if (info->ia.topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
Chia-I Wu7f390562015-03-25 08:47:18 +0800838 body[10] = fs->point_sprite_enables;
839 else
840 body[10] = 0;
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800841
GregF8cd81832014-11-18 18:01:01 -0700842 body[11] = 0; /* constant interpolation enables */
843 body[12] = 0; /* WrapShortest enables */
844 body[13] = 0;
845}
846
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800847static void pipeline_build_gs(struct intel_pipeline *pipeline,
848 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600849{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600850 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600851}
852
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800853static void pipeline_build_hs(struct intel_pipeline *pipeline,
854 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600855{
856 const uint8_t cmd_len = 7;
857 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
858 uint32_t *dw;
859
Chia-I Wu509b3f22014-09-02 10:24:05 +0800860 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600861
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800862 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600863 dw[0] = dw0;
864 dw[1] = 0;
865 dw[2] = 0;
866 dw[3] = 0;
867 dw[4] = 0;
868 dw[5] = 0;
869 dw[6] = 0;
870}
871
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800872static void pipeline_build_te(struct intel_pipeline *pipeline,
873 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600874{
875 const uint8_t cmd_len = 4;
876 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
877 uint32_t *dw;
878
Chia-I Wu509b3f22014-09-02 10:24:05 +0800879 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600880
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800881 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600882 dw[0] = dw0;
883 dw[1] = 0;
884 dw[2] = 0;
885 dw[3] = 0;
886}
887
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800888static void pipeline_build_ds(struct intel_pipeline *pipeline,
889 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600890{
891 const uint8_t cmd_len = 6;
892 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
893 uint32_t *dw;
894
Chia-I Wu509b3f22014-09-02 10:24:05 +0800895 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600896
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800897 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600898 dw[0] = dw0;
899 dw[1] = 0;
900 dw[2] = 0;
901 dw[3] = 0;
902 dw[4] = 0;
903 dw[5] = 0;
904}
905
Tony Barbourfa6cac72015-01-16 14:27:35 -0700906static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
907 const struct intel_pipeline_create_info *info)
908{
909 pipeline->cmd_depth_stencil = 0;
910
911 if (info->db.stencilTestEnable) {
912 pipeline->cmd_depth_stencil = 1 << 31 |
Tony Barbour8205d902015-04-16 15:59:00 -0600913 translate_compare_func(info->db.front.stencilCompareOp) << 28 |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700914 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
915 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
916 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
917 1 << 15 |
Tony Barbour8205d902015-04-16 15:59:00 -0600918 translate_compare_func(info->db.back.stencilCompareOp) << 12 |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700919 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
920 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
921 translate_stencil_op(info->db.back.stencilPassOp) << 3;
922 }
923
924 pipeline->stencilTestEnable = info->db.stencilTestEnable;
925
926 /*
927 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
928 *
929 * "Enabling the Depth Test function without defining a Depth Buffer is
930 * UNDEFINED."
931 *
932 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
933 *
934 * "A Depth Buffer must be defined before enabling writes to it, or
935 * operation is UNDEFINED."
936 *
937 * TODO We do not check these yet.
938 */
939 if (info->db.depthTestEnable) {
940 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
Tony Barbour8205d902015-04-16 15:59:00 -0600941 translate_compare_func(info->db.depthCompareOp) << 27;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700942 } else {
943 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
944 }
945
946 if (info->db.depthWriteEnable)
947 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
948}
949
Tony Barbourfa6cac72015-01-16 14:27:35 -0700950static void pipeline_build_msaa(struct intel_pipeline *pipeline,
951 const struct intel_pipeline_create_info *info)
952{
953 uint32_t cmd, cmd_len;
954 uint32_t *dw;
955
956 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
957
Tony Barboure094edf2015-06-26 10:18:34 -0600958 pipeline->sample_count = (info->ms.rasterSamples <= 1) ? 1 : info->ms.rasterSamples;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700959
960 /* 3DSTATE_SAMPLE_MASK */
961 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
962 cmd_len = 2;
963
Chia-I Wu8ada4242015-03-02 11:19:33 -0700964 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700965 dw[0] = cmd | (cmd_len - 2);
Cody Northrope9825b72015-08-04 14:34:54 -0600966 if (info->ms.pSampleMask) {
967 /* "Bit B of mask word M corresponds to sample 32*M + B."
968 * "The array is sized to a length of ceil(rasterSamples / 32) words."
969 * "If pSampleMask is NULL, it is treated as if the mask has all bits enabled,"
970 * "i.e. no coverage is removed from primitives."
971 */
972 assert(pipeline->sample_count / 32 == 0);
973 dw[1] = *info->ms.pSampleMask & ((1 << pipeline->sample_count) - 1);
974 } else {
975 dw[1] = (1 << pipeline->sample_count) - 1;
976 }
977
Tony Barbourfa6cac72015-01-16 14:27:35 -0700978 pipeline->cmd_sample_mask = dw[1];
979}
980
981static void pipeline_build_cb(struct intel_pipeline *pipeline,
982 const struct intel_pipeline_create_info *info)
983{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600984 uint32_t i;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700985
986 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
987 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
988 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
989
990 uint32_t *dw = pipeline->cmd_cb;
991
992 for (i = 0; i < info->cb.attachmentCount; i++) {
Tony Barboure307f582015-07-10 15:29:03 -0600993 const VkPipelineColorBlendAttachmentState *att = &info->cb.pAttachments[i];
Tony Barbourfa6cac72015-01-16 14:27:35 -0700994 uint32_t dw0, dw1;
995
996
997 dw0 = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700998 dw1 = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
999 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1000 GEN6_RT_DW1_POST_BLEND_CLAMP;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001001
1002 if (att->blendEnable) {
1003 dw0 = 1 << 31 |
Tony Barbour8205d902015-04-16 15:59:00 -06001004 translate_blend_func(att->blendOpAlpha) << 26 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001005 translate_blend(att->srcBlendAlpha) << 20 |
1006 translate_blend(att->destBlendAlpha) << 15 |
Tony Barbour8205d902015-04-16 15:59:00 -06001007 translate_blend_func(att->blendOpColor) << 11 |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001008 translate_blend(att->srcBlendColor) << 5 |
1009 translate_blend(att->destBlendColor);
1010
Tony Barbour8205d902015-04-16 15:59:00 -06001011 if (att->blendOpAlpha != att->blendOpColor ||
Tony Barbourfa6cac72015-01-16 14:27:35 -07001012 att->srcBlendAlpha != att->srcBlendColor ||
1013 att->destBlendAlpha != att->destBlendColor)
1014 dw0 |= 1 << 30;
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -07001015
1016 pipeline->dual_source_blend_enable = icd_pipeline_cb_att_needs_dual_source_blending(att);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001017 }
1018
Courtney Goeltzenleuchter72af13a2015-06-26 17:45:23 -06001019 if (info->cb.logicOpEnable && info->cb.logicOp != VK_LOGIC_OP_COPY) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07001020 int logicop;
1021
1022 switch (info->cb.logicOp) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001023 case VK_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1024 case VK_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1025 case VK_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1026 case VK_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1027 case VK_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1028 case VK_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1029 case VK_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1030 case VK_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1031 case VK_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1032 case VK_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1033 case VK_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1034 case VK_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1035 case VK_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1036 case VK_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1037 case VK_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001038 default:
1039 assert(!"unknown logic op");
1040 logicop = GEN6_LOGICOP_CLEAR;
1041 break;
1042 }
1043
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001044 dw1 |= GEN6_RT_DW1_LOGICOP_ENABLE |
1045 logicop << GEN6_RT_DW1_LOGICOP_FUNC__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001046 }
1047
1048 if (!(att->channelWriteMask & 0x1))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001049 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_R;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001050 if (!(att->channelWriteMask & 0x2))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001051 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_G;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001052 if (!(att->channelWriteMask & 0x4))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001053 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_B;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001054 if (!(att->channelWriteMask & 0x8))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001055 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001056
1057 dw[2 * i] = dw0;
1058 dw[2 * i + 1] = dw1;
1059 }
1060
1061 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1062 {
1063 dw[2 * i] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001064 dw[2 * i + 1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1065 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1066 GEN6_RT_DW1_POST_BLEND_CLAMP |
1067 GEN6_RT_DW1_WRITE_DISABLE_R |
1068 GEN6_RT_DW1_WRITE_DISABLE_G |
1069 GEN6_RT_DW1_WRITE_DISABLE_B |
1070 GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001071 }
1072
1073}
1074
1075
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001076static VkResult pipeline_build_all(struct intel_pipeline *pipeline,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001077 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001078{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001079 VkResult ret;
Chia-I Wu3efef432014-08-28 15:00:16 +08001080
Chia-I Wu98824592014-09-02 09:42:46 +08001081 ret = pipeline_build_shaders(pipeline, info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001082 if (ret != VK_SUCCESS)
Chia-I Wu98824592014-09-02 09:42:46 +08001083 return ret;
1084
Tobin Ehlis20693172015-09-17 08:46:18 -06001085 /* TODOVV: Move test to validation layer
1086 * This particular test is based on a limit imposed by
1087 * INTEL_MAX_VERTEX_BINDING_COUNT, which should be migrated
1088 * to API-defined maxVertexInputBindings setting and then
1089 * this check can be in DeviceLimits layer
1090 */
Chia-I Wu1d125092014-10-08 08:49:38 +08001091 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001092 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb)) {
Tobin Ehlis5b8e2bb2015-09-21 11:46:16 -06001093 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001094 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001095
1096 pipeline->vb_count = info->vi.bindingCount;
1097 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1098 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1099
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001100 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wu86a5e0c2015-03-24 11:01:50 +08001101 pipeline_build_fragment_SBE(pipeline, info);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001102 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001103 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001104
Chia-I Wu509b3f22014-09-02 10:24:05 +08001105 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001106 pipeline_build_urb_alloc_gen7(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001107 pipeline_build_gs(pipeline, info);
1108 pipeline_build_hs(pipeline, info);
1109 pipeline_build_te(pipeline, info);
1110 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001111
1112 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1113 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1114 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1115 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1116 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001117 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001118 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001119
1120 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1121 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001122 }
1123
Chia-I Wube0a3d92014-09-02 13:20:59 +08001124 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001125
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001126 if (ret == VK_SUCCESS)
Chia-I Wu6abcb0e2015-03-24 14:38:14 +08001127 ret = pipeline_build_rs_state(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001128
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001129 if (ret == VK_SUCCESS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07001130 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001131 pipeline->cb_state = info->cb;
1132 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001133 }
1134
1135 return ret;
1136}
1137
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001138static VkResult pipeline_create_info_init(struct intel_pipeline_create_info *info,
1139 const VkGraphicsPipelineCreateInfo *vkinfo)
Chia-I Wu3efef432014-08-28 15:00:16 +08001140{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001141 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001142
Tony Barbourfa6cac72015-01-16 14:27:35 -07001143 /*
1144 * Do we need to set safe defaults in case the app doesn't provide all of
1145 * the necessary create infos?
1146 */
Tony Barboure094edf2015-06-26 10:18:34 -06001147 info->ms.rasterSamples = 1;
Cody Northrope9825b72015-08-04 14:34:54 -06001148 info->ms.pSampleMask = NULL;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001149
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001150 memcpy(&info->graphics, vkinfo, sizeof (info->graphics));
Chia-I Wu3efef432014-08-28 15:00:16 +08001151
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001152 void *dst;
1153 for (uint32_t i = 0; i < vkinfo->stageCount; i++) {
1154 const VkPipelineShaderStageCreateInfo *thisStage = &vkinfo->pStages[i];
1155 switch (thisStage->stage) {
1156 case VK_SHADER_STAGE_VERTEX:
1157 dst = &info->vs;
1158 break;
1159 case VK_SHADER_STAGE_TESS_CONTROL:
1160 dst = &info->tcs;
1161 break;
1162 case VK_SHADER_STAGE_TESS_EVALUATION:
1163 dst = &info->tes;
1164 break;
1165 case VK_SHADER_STAGE_GEOMETRY:
1166 dst = &info->gs;
1167 break;
1168 case VK_SHADER_STAGE_FRAGMENT:
1169 dst = &info->fs;
1170 break;
1171 case VK_SHADER_STAGE_COMPUTE:
1172 dst = &info->compute;
1173 break;
1174 default:
Tobin Ehlis20693172015-09-17 08:46:18 -06001175 assert(!"unsupported shader stage");
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001176 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001177 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001178 memcpy(dst, thisStage, sizeof(VkPipelineShaderStageCreateInfo));
1179 }
Chia-I Wu3efef432014-08-28 15:00:16 +08001180
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001181 if (vkinfo->pVertexInputState != NULL) {
1182 memcpy(&info->vi, vkinfo->pVertexInputState, sizeof (info->vi));
1183 }
Tony Barboure307f582015-07-10 15:29:03 -06001184 if (vkinfo->pInputAssemblyState != NULL) {
1185 memcpy(&info->ia, vkinfo->pInputAssemblyState, sizeof (info->ia));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001186 }
Tony Barboure307f582015-07-10 15:29:03 -06001187 if (vkinfo->pDepthStencilState != NULL) {
1188 memcpy(&info->db, vkinfo->pDepthStencilState, sizeof (info->db));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001189 }
Tony Barboure307f582015-07-10 15:29:03 -06001190 if (vkinfo->pColorBlendState != NULL) {
1191 memcpy(&info->cb, vkinfo->pColorBlendState, sizeof (info->cb));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001192 }
Tony Barboure307f582015-07-10 15:29:03 -06001193 if (vkinfo->pRasterState != NULL) {
1194 memcpy(&info->rs, vkinfo->pRasterState, sizeof (info->rs));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001195 }
Tony Barboure307f582015-07-10 15:29:03 -06001196 if (vkinfo->pTessellationState != NULL) {
1197 memcpy(&info->tess, vkinfo->pTessellationState, sizeof (info->tess));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001198 }
Tony Barboure307f582015-07-10 15:29:03 -06001199 if (vkinfo->pMultisampleState != NULL) {
1200 memcpy(&info->ms, vkinfo->pMultisampleState, sizeof (info->ms));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001201 }
Tony Barboure307f582015-07-10 15:29:03 -06001202 if (vkinfo->pViewportState != NULL) {
1203 memcpy(&info->vp, vkinfo->pViewportState, sizeof (info->vp));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001204 }
Tony Barboure307f582015-07-10 15:29:03 -06001205 if (vkinfo->pViewportState != NULL) {
1206 memcpy(&info->vp, vkinfo->pViewportState, sizeof (info->vp));
Chia-I Wu3efef432014-08-28 15:00:16 +08001207 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001208
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001209 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001210}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001211
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001212static VkResult graphics_pipeline_create(struct intel_dev *dev,
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001213 const VkGraphicsPipelineCreateInfo *info_,
1214 struct intel_pipeline **pipeline_ret)
Chia-I Wu3efef432014-08-28 15:00:16 +08001215{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001216 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001217 struct intel_pipeline *pipeline;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001218 VkResult ret;
Chia-I Wu3efef432014-08-28 15:00:16 +08001219
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -06001220 ret = pipeline_create_info_init(&info, info_);
1221
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001222 if (ret != VK_SUCCESS)
Chia-I Wu3efef432014-08-28 15:00:16 +08001223 return ret;
1224
Chia-I Wu545c2e12015-02-22 13:19:54 +08001225 pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle,
Jon Ashburn0d60d272015-07-09 15:02:25 -06001226 sizeof (*pipeline), dev->base.dbg,
1227 VK_OBJECT_TYPE_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001228 if (!pipeline)
Tony Barbour8205d902015-04-16 15:59:00 -06001229 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu3efef432014-08-28 15:00:16 +08001230
1231 pipeline->dev = dev;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001232 pipeline->pipeline_layout = intel_pipeline_layout(info.graphics.layout);
Chia-I Wudf601c42015-04-17 01:58:07 +08001233
Chia-I Wu3efef432014-08-28 15:00:16 +08001234 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001235
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001236 ret = pipeline_build_all(pipeline, &info);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001237 if (ret != VK_SUCCESS) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001238 pipeline_destroy(&pipeline->obj);
1239 return ret;
1240 }
1241
Tony Barbour2094dc72015-07-09 15:26:32 -06001242 VkMemoryAllocInfo mem_reqs;
1243 mem_reqs.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
1244 mem_reqs.allocationSize = pipeline->scratch_size;
1245 mem_reqs.pNext = NULL;
1246 mem_reqs.memoryTypeIndex = 0;
1247 intel_mem_alloc(dev, &mem_reqs, &pipeline->obj.mem);
1248
Chia-I Wu3efef432014-08-28 15:00:16 +08001249 *pipeline_ret = pipeline;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001250 return VK_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001251}
1252
Jon Ashburn0d60d272015-07-09 15:02:25 -06001253ICD_EXPORT VkResult VKAPI vkCreatePipelineCache(
1254 VkDevice device,
1255 const VkPipelineCacheCreateInfo* pCreateInfo,
1256 VkPipelineCache* pPipelineCache)
Chia-I Wu3efef432014-08-28 15:00:16 +08001257{
Chia-I Wu3efef432014-08-28 15:00:16 +08001258
Jon Ashburn0d60d272015-07-09 15:02:25 -06001259 // non-dispatchable objects only need to be 64 bits currently
1260 *((uint64_t *)pPipelineCache) = 1;
1261 return VK_SUCCESS;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001262}
1263
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001264void VKAPI vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06001265 VkDevice device,
1266 VkPipelineCache pipelineCache)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001267{
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001268}
1269
Jon Ashburn0d60d272015-07-09 15:02:25 -06001270ICD_EXPORT size_t VKAPI vkGetPipelineCacheSize(
1271 VkDevice device,
1272 VkPipelineCache pipelineCache)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001273{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06001274 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001275}
1276
Jon Ashburn0d60d272015-07-09 15:02:25 -06001277ICD_EXPORT VkResult VKAPI vkGetPipelineCacheData(
1278 VkDevice device,
1279 VkPipelineCache pipelineCache,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001280 void* pData)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001281{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06001282 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001283}
1284
Jon Ashburn0d60d272015-07-09 15:02:25 -06001285ICD_EXPORT VkResult VKAPI vkMergePipelineCaches(
1286 VkDevice device,
1287 VkPipelineCache destCache,
1288 uint32_t srcCacheCount,
1289 const VkPipelineCache* pSrcCaches)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001290{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06001291 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001292}
1293
Jon Ashburn0d60d272015-07-09 15:02:25 -06001294ICD_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001295 VkDevice device,
Jon Ashburn0d60d272015-07-09 15:02:25 -06001296 VkPipelineCache pipelineCache,
1297 uint32_t count,
1298 const VkGraphicsPipelineCreateInfo* pCreateInfos,
1299 VkPipeline* pPipelines)
1300{
1301 struct intel_dev *dev = intel_dev(device);
1302 uint32_t i;
Tony Barbour9687cb12015-07-14 13:34:05 -06001303 VkResult res = VK_SUCCESS;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001304 bool one_succeeded = false;
1305
1306 for (i = 0; i < count; i++) {
1307 res = graphics_pipeline_create(dev, &(pCreateInfos[i]),
1308 (struct intel_pipeline **) &(pPipelines[i]));
1309 //return NULL handle for unsuccessful creates
1310 if (res != VK_SUCCESS)
Tony Barbourde4124d2015-07-03 10:33:54 -06001311 pPipelines[i].handle = 0;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001312 else
1313 one_succeeded = true;
1314 }
1315 //return VK_SUCCESS if any of count creates succeeded
1316 if (one_succeeded)
1317 return VK_SUCCESS;
1318 else
1319 return res;
1320}
1321
1322ICD_EXPORT VkResult VKAPI vkCreateComputePipelines(
1323 VkDevice device,
1324 VkPipelineCache pipelineCache,
1325 uint32_t count,
1326 const VkComputePipelineCreateInfo* pCreateInfos,
1327 VkPipeline* pPipelines)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001328{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06001329 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001330}
Tony Barbourde4124d2015-07-03 10:33:54 -06001331
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001332ICD_EXPORT void VKAPI vkDestroyPipeline(
Tony Barbourde4124d2015-07-03 10:33:54 -06001333 VkDevice device,
1334 VkPipeline pipeline)
1335
1336 {
1337 struct intel_obj *obj = intel_obj(pipeline.handle);
1338
Tony Barbour2094dc72015-07-09 15:26:32 -06001339 intel_mem_free(obj->mem);
Tony Barbourde4124d2015-07-03 10:33:54 -06001340 obj->destroy(obj);
Tony Barbourde4124d2015-07-03 10:33:54 -06001341 }