blob: 73dfbc43a51193e321b45e5c5011c54c4ef3a209 [file] [log] [blame]
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I 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 Barbourfa6cac72015-01-16 14:27:35 -070036static int translate_blend_func(XGL_BLEND_FUNC func)
37{
38 switch (func) {
39 case XGL_BLEND_FUNC_ADD: return GEN6_BLENDFUNCTION_ADD;
40 case XGL_BLEND_FUNC_SUBTRACT: return GEN6_BLENDFUNCTION_SUBTRACT;
41 case XGL_BLEND_FUNC_REVERSE_SUBTRACT: return GEN6_BLENDFUNCTION_REVERSE_SUBTRACT;
42 case XGL_BLEND_FUNC_MIN: return GEN6_BLENDFUNCTION_MIN;
43 case XGL_BLEND_FUNC_MAX: return GEN6_BLENDFUNCTION_MAX;
44 default:
45 assert(!"unknown blend func");
46 return GEN6_BLENDFUNCTION_ADD;
47 };
48}
49
50static int translate_blend(XGL_BLEND blend)
51{
52 switch (blend) {
53 case XGL_BLEND_ZERO: return GEN6_BLENDFACTOR_ZERO;
54 case XGL_BLEND_ONE: return GEN6_BLENDFACTOR_ONE;
55 case XGL_BLEND_SRC_COLOR: return GEN6_BLENDFACTOR_SRC_COLOR;
56 case XGL_BLEND_ONE_MINUS_SRC_COLOR: return GEN6_BLENDFACTOR_INV_SRC_COLOR;
57 case XGL_BLEND_DEST_COLOR: return GEN6_BLENDFACTOR_DST_COLOR;
58 case XGL_BLEND_ONE_MINUS_DEST_COLOR: return GEN6_BLENDFACTOR_INV_DST_COLOR;
59 case XGL_BLEND_SRC_ALPHA: return GEN6_BLENDFACTOR_SRC_ALPHA;
60 case XGL_BLEND_ONE_MINUS_SRC_ALPHA: return GEN6_BLENDFACTOR_INV_SRC_ALPHA;
61 case XGL_BLEND_DEST_ALPHA: return GEN6_BLENDFACTOR_DST_ALPHA;
62 case XGL_BLEND_ONE_MINUS_DEST_ALPHA: return GEN6_BLENDFACTOR_INV_DST_ALPHA;
63 case XGL_BLEND_CONSTANT_COLOR: return GEN6_BLENDFACTOR_CONST_COLOR;
64 case XGL_BLEND_ONE_MINUS_CONSTANT_COLOR: return GEN6_BLENDFACTOR_INV_CONST_COLOR;
65 case XGL_BLEND_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_CONST_ALPHA;
66 case XGL_BLEND_ONE_MINUS_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_INV_CONST_ALPHA;
67 case XGL_BLEND_SRC_ALPHA_SATURATE: return GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE;
68 case XGL_BLEND_SRC1_COLOR: return GEN6_BLENDFACTOR_SRC1_COLOR;
69 case XGL_BLEND_ONE_MINUS_SRC1_COLOR: return GEN6_BLENDFACTOR_INV_SRC1_COLOR;
70 case XGL_BLEND_SRC1_ALPHA: return GEN6_BLENDFACTOR_SRC1_ALPHA;
71 case XGL_BLEND_ONE_MINUS_SRC1_ALPHA: return GEN6_BLENDFACTOR_INV_SRC1_ALPHA;
72 default:
73 assert(!"unknown blend factor");
74 return GEN6_BLENDFACTOR_ONE;
75 };
76}
77
78static int translate_compare_func(XGL_COMPARE_FUNC func)
79{
80 switch (func) {
81 case XGL_COMPARE_NEVER: return GEN6_COMPAREFUNCTION_NEVER;
82 case XGL_COMPARE_LESS: return GEN6_COMPAREFUNCTION_LESS;
83 case XGL_COMPARE_EQUAL: return GEN6_COMPAREFUNCTION_EQUAL;
84 case XGL_COMPARE_LESS_EQUAL: return GEN6_COMPAREFUNCTION_LEQUAL;
85 case XGL_COMPARE_GREATER: return GEN6_COMPAREFUNCTION_GREATER;
86 case XGL_COMPARE_NOT_EQUAL: return GEN6_COMPAREFUNCTION_NOTEQUAL;
87 case XGL_COMPARE_GREATER_EQUAL: return GEN6_COMPAREFUNCTION_GEQUAL;
88 case XGL_COMPARE_ALWAYS: return GEN6_COMPAREFUNCTION_ALWAYS;
89 default:
90 assert(!"unknown compare_func");
91 return GEN6_COMPAREFUNCTION_NEVER;
92 }
93}
94
95static int translate_stencil_op(XGL_STENCIL_OP op)
96{
97 switch (op) {
98 case XGL_STENCIL_OP_KEEP: return GEN6_STENCILOP_KEEP;
99 case XGL_STENCIL_OP_ZERO: return GEN6_STENCILOP_ZERO;
100 case XGL_STENCIL_OP_REPLACE: return GEN6_STENCILOP_REPLACE;
101 case XGL_STENCIL_OP_INC_CLAMP: return GEN6_STENCILOP_INCRSAT;
102 case XGL_STENCIL_OP_DEC_CLAMP: return GEN6_STENCILOP_DECRSAT;
103 case XGL_STENCIL_OP_INVERT: return GEN6_STENCILOP_INVERT;
104 case XGL_STENCIL_OP_INC_WRAP: return GEN6_STENCILOP_INCR;
105 case XGL_STENCIL_OP_DEC_WRAP: return GEN6_STENCILOP_DECR;
106 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 {
113 XGL_GRAPHICS_PIPELINE_CREATE_INFO graphics;
114 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi;
115 XGL_PIPELINE_IA_STATE_CREATE_INFO ia;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700116 XGL_PIPELINE_DS_STATE_CREATE_INFO db;
117 XGL_PIPELINE_CB_STATE_CREATE_INFO cb;
Chia-I Wu3f239832014-12-11 22:57:18 +0800118 XGL_PIPELINE_RS_STATE_CREATE_INFO rs;
119 XGL_PIPELINE_TESS_STATE_CREATE_INFO tess;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700120 XGL_PIPELINE_MS_STATE_CREATE_INFO ms;
121 XGL_PIPELINE_VP_STATE_CREATE_INFO vp;
Chia-I Wu3f239832014-12-11 22:57:18 +0800122 XGL_PIPELINE_SHADER vs;
123 XGL_PIPELINE_SHADER tcs;
124 XGL_PIPELINE_SHADER tes;
125 XGL_PIPELINE_SHADER gs;
126 XGL_PIPELINE_SHADER fs;
127
128 XGL_COMPUTE_PIPELINE_CREATE_INFO compute;
129};
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;
205 XGL_RESULT ret;
206
Chia-I Wuf9c81ef2015-02-22 13:49:15 +0800207 sh = intel_alloc(dev, sizeof(*sh), 0, XGL_SYSTEM_ALLOC_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);
213 if (ret != XGL_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,
223 XGL_SHADER_STAGE_VERTEX);
224 break;
225 default:
226 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
227 XGL_SHADER_STAGE_FRAGMENT);
228 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
241static XGL_RESULT pipeline_build_shader(struct intel_pipeline *pipeline,
Chia-I Wuf8385062015-01-04 16:27:24 +0800242 const struct intel_desc_layout *layout,
243 const XGL_PIPELINE_SHADER *sh_info,
244 struct intel_pipeline_shader *sh)
Chia-I Wu3f239832014-12-11 22:57:18 +0800245{
246 XGL_RESULT ret;
247
Chia-I Wuf8385062015-01-04 16:27:24 +0800248 ret = intel_pipeline_shader_compile(sh,
249 pipeline->dev->gpu, layout, sh_info);
Chia-I Wu3f239832014-12-11 22:57:18 +0800250 if (ret != XGL_SUCCESS)
251 return ret;
252
253 sh->max_threads =
254 intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage);
255
256 /* 1KB aligned */
257 sh->scratch_offset = u_align(pipeline->scratch_size, 1024);
258 pipeline->scratch_size = sh->scratch_offset +
259 sh->per_thread_scratch_size * sh->max_threads;
260
261 pipeline->active_shaders |= 1 << sh_info->stage;
262
263 return XGL_SUCCESS;
264}
265
266static XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
267 const struct intel_pipeline_create_info *info)
268{
Chia-I Wuf8385062015-01-04 16:27:24 +0800269 const struct intel_desc_layout *layout =
270 intel_desc_layout(info->graphics.lastSetLayout);
Chia-I Wu3f239832014-12-11 22:57:18 +0800271 XGL_RESULT ret = XGL_SUCCESS;
272
Chia-I Wuf8385062015-01-04 16:27:24 +0800273 if (ret == XGL_SUCCESS && info->vs.shader) {
274 ret = pipeline_build_shader(pipeline, layout,
275 &info->vs, &pipeline->vs);
276 }
277 if (ret == XGL_SUCCESS && info->tcs.shader) {
278 ret = pipeline_build_shader(pipeline, layout,
279 &info->tcs,&pipeline->tcs);
280 }
281 if (ret == XGL_SUCCESS && info->tes.shader) {
282 ret = pipeline_build_shader(pipeline, layout,
283 &info->tes,&pipeline->tes);
284 }
285 if (ret == XGL_SUCCESS && info->gs.shader) {
286 ret = pipeline_build_shader(pipeline, layout,
287 &info->gs, &pipeline->gs);
288 }
289 if (ret == XGL_SUCCESS && info->fs.shader) {
290 ret = pipeline_build_shader(pipeline, layout,
291 &info->fs, &pipeline->fs);
292 }
Chia-I Wu3f239832014-12-11 22:57:18 +0800293
Chia-I Wuf8385062015-01-04 16:27:24 +0800294 if (ret == XGL_SUCCESS && info->compute.cs.shader) {
295 layout = intel_desc_layout(info->compute.lastSetLayout);
296 ret = pipeline_build_shader(pipeline, layout,
297 &info->compute.cs, &pipeline->cs);
298 }
Chia-I Wu3f239832014-12-11 22:57:18 +0800299
300 return ret;
301}
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600302static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len)
303{
304 uint32_t *ptr;
305
306 assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES);
307 ptr = &pipeline->cmds[pipeline->cmd_len];
308 pipeline->cmd_len += cmd_len;
309 return ptr;
310}
311
Chia-I Wube0a3d92014-09-02 13:20:59 +0800312static XGL_RESULT pipeline_build_ia(struct intel_pipeline *pipeline,
313 const struct intel_pipeline_create_info* info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600314{
Chia-I Wube0a3d92014-09-02 13:20:59 +0800315 pipeline->topology = info->ia.topology;
316 pipeline->disable_vs_cache = info->ia.disableVertexReuse;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600317
Chia-I Wube0a3d92014-09-02 13:20:59 +0800318 switch (info->ia.topology) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600319 case XGL_TOPOLOGY_POINT_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600320 pipeline->prim_type = GEN6_3DPRIM_POINTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600321 break;
322 case XGL_TOPOLOGY_LINE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600323 pipeline->prim_type = GEN6_3DPRIM_LINELIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600324 break;
325 case XGL_TOPOLOGY_LINE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600326 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600327 break;
328 case XGL_TOPOLOGY_TRIANGLE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600329 pipeline->prim_type = GEN6_3DPRIM_TRILIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600330 break;
331 case XGL_TOPOLOGY_TRIANGLE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600332 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600333 break;
334 case XGL_TOPOLOGY_RECT_LIST:
335 /*
336 * TODO: Rect lists are special in XGL, do we need to do
337 * something special here?
338 * XGL Guide:
339 * The rectangle list is a special geometry primitive type
340 * that can be used for implementing post-processing techniques
341 * or efficient copy operations. There are some special limitations
342 * for rectangle primitives. They cannot be clipped, must
343 * be axis aligned and cannot have depth gradient.
344 * Failure to comply with these restrictions results in
345 * undefined rendering results.
346 */
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600347 pipeline->prim_type = GEN6_3DPRIM_RECTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600348 break;
349 case XGL_TOPOLOGY_QUAD_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600350 pipeline->prim_type = GEN6_3DPRIM_QUADLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600351 break;
352 case XGL_TOPOLOGY_QUAD_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600353 pipeline->prim_type = GEN6_3DPRIM_QUADSTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600354 break;
355 case XGL_TOPOLOGY_LINE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600356 pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600357 break;
358 case XGL_TOPOLOGY_LINE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600359 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600360 break;
361 case XGL_TOPOLOGY_TRIANGLE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600362 pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600363 break;
364 case XGL_TOPOLOGY_TRIANGLE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600365 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600366 break;
367 case XGL_TOPOLOGY_PATCH:
Chia-I Wube0a3d92014-09-02 13:20:59 +0800368 if (!info->tess.patchControlPoints ||
369 info->tess.patchControlPoints > 32)
370 return XGL_ERROR_BAD_PIPELINE_DATA;
371 pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 +
372 info->tess.patchControlPoints - 1;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600373 break;
374 default:
375 return XGL_ERROR_BAD_PIPELINE_DATA;
376 }
377
Chia-I Wube0a3d92014-09-02 13:20:59 +0800378 if (info->ia.primitiveRestartEnable) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600379 pipeline->primitive_restart = true;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800380 pipeline->primitive_restart_index = info->ia.primitiveRestartIndex;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600381 } else {
382 pipeline->primitive_restart = false;
383 }
384
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600385 return XGL_SUCCESS;
386}
387
Chia-I Wu3efef432014-08-28 15:00:16 +0800388static XGL_RESULT pipeline_rs_state(struct intel_pipeline *pipeline,
389 const XGL_PIPELINE_RS_STATE_CREATE_INFO* rs_state)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600390{
391 pipeline->depthClipEnable = rs_state->depthClipEnable;
392 pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable;
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800393 pipeline->use_rs_point_size = !rs_state->programPointSize;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700394
395 if (rs_state->provokingVertex == XGL_PROVOKING_VERTEX_FIRST) {
396 pipeline->provoking_vertex_tri = 0;
397 pipeline->provoking_vertex_trifan = 1;
398 pipeline->provoking_vertex_line = 0;
399 } else {
400 pipeline->provoking_vertex_tri = 2;
401 pipeline->provoking_vertex_trifan = 2;
402 pipeline->provoking_vertex_line = 1;
403 }
404
405 switch (rs_state->fillMode) {
406 case XGL_FILL_POINTS:
407 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT |
408 GEN7_SF_DW1_BACKFACE_POINT;
409 break;
410 case XGL_FILL_WIREFRAME:
411 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME |
412 GEN7_SF_DW1_BACKFACE_WIREFRAME;
413 break;
414 case XGL_FILL_SOLID:
415 default:
416 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID |
417 GEN7_SF_DW1_BACKFACE_SOLID;
418 break;
419 }
420
421 if (rs_state->frontFace == XGL_FRONT_FACE_CCW) {
422 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW;
423 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW;
424 }
425
426 switch (rs_state->cullMode) {
427 case XGL_CULL_NONE:
428 default:
429 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE;
430 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE;
431 break;
432 case XGL_CULL_FRONT:
433 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT;
434 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT;
435 break;
436 case XGL_CULL_BACK:
437 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK;
438 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK;
439 break;
440 case XGL_CULL_FRONT_AND_BACK:
441 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH;
442 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH;
443 break;
444 }
445
446 /* only GEN7+ needs cull mode in 3DSTATE_CLIP */
447 if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
448 pipeline->cmd_clip_cull = 0;
449
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600450 return XGL_SUCCESS;
451}
452
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600453static void pipeline_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600454{
455 struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj);
456
Chia-I Wu3f239832014-12-11 22:57:18 +0800457 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800458 intel_pipeline_shader_cleanup(&pipeline->vs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800459 }
460
461 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800462 intel_pipeline_shader_cleanup(&pipeline->tcs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800463 }
464
465 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800466 intel_pipeline_shader_cleanup(&pipeline->tes, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800467 }
468
469 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800470 intel_pipeline_shader_cleanup(&pipeline->gs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800471 }
472
473 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800474 intel_pipeline_shader_cleanup(&pipeline->fs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800475 }
476
477 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800478 intel_pipeline_shader_cleanup(&pipeline->cs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800479 }
Chia-I Wued833872014-08-23 17:00:35 +0800480
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600481 intel_base_destroy(&pipeline->obj.base);
482}
483
Chia-I Wub1024732014-12-19 13:00:29 +0800484static XGL_RESULT pipeline_get_info(struct intel_base *base, int type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600485 size_t *size, void *data)
Chia-I Wub1024732014-12-19 13:00:29 +0800486{
487 struct intel_pipeline *pipeline = intel_pipeline_from_base(base);
488 XGL_RESULT ret = XGL_SUCCESS;
489
490 switch (type) {
491 case XGL_INFO_TYPE_MEMORY_REQUIREMENTS:
492 {
493 XGL_MEMORY_REQUIREMENTS *mem_req = data;
494
495 *size = sizeof(XGL_MEMORY_REQUIREMENTS);
496 if (data) {
497 mem_req->size = pipeline->scratch_size;
498 mem_req->alignment = 1024;
Jon Ashburnd8031332015-01-22 10:52:13 -0700499 mem_req->memType = XGL_MEMORY_TYPE_OTHER;
Chia-I Wub1024732014-12-19 13:00:29 +0800500 }
501 }
502 break;
503 default:
504 ret = intel_base_get_info(base, type, size, data);
505 break;
506 }
507
508 return ret;
509}
510
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800511static XGL_RESULT pipeline_validate(struct intel_pipeline *pipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +0800512{
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600513 /*
514 * Validate required elements
515 */
516 if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) {
517 // TODO: Log debug message: Vertex Shader required.
Chia-I Wu3efef432014-08-28 15:00:16 +0800518 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600519 }
520
521 /*
522 * Tessalation control and evaluation have to both have a shader defined or
523 * neither should have a shader defined.
524 */
525 if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) !=
526 ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) {
527 // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation
Chia-I Wu3efef432014-08-28 15:00:16 +0800528 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600529 }
530
531 if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) &&
532 (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG |
533 SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG |
534 SHADER_FRAGMENT_FLAG))) {
535 // TODO: Log debug message: Can only specify compute shader when doing compute
Chia-I Wu3efef432014-08-28 15:00:16 +0800536 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600537 }
538
539 /*
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600540 * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
541 * Mismatching primitive topology and tessellation fails graphics pipeline creation.
542 */
543 if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) &&
Chia-I Wube0a3d92014-09-02 13:20:59 +0800544 (pipeline->topology != XGL_TOPOLOGY_PATCH)) {
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600545 // TODO: Log debug message: Invalid topology used with tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800546 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600547 }
548
Chia-I Wube0a3d92014-09-02 13:20:59 +0800549 if ((pipeline->topology == XGL_TOPOLOGY_PATCH) &&
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600550 (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) {
551 // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800552 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600553 }
554
Chia-I Wu3efef432014-08-28 15:00:16 +0800555 return XGL_SUCCESS;
556}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600557
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800558static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
559 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800560{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800561 const struct intel_gpu *gpu = pipeline->dev->gpu;
562 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wua4d1b392014-10-10 13:57:29 +0800563 const struct intel_pipeline_shader *vs = &pipeline->vs;
564 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800565 int vs_entry_size, gs_entry_size;
566 int vs_size, gs_size;
567
Chia-I Wu509b3f22014-09-02 10:24:05 +0800568 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800569
570 vs_entry_size = ((vs->in_count >= vs->out_count) ?
571 vs->in_count : vs->out_count);
572 gs_entry_size = (gs) ? gs->out_count : 0;
573
574 /* in bytes */
575 vs_entry_size *= sizeof(float) * 4;
576 gs_entry_size *= sizeof(float) * 4;
577
Chia-I Wua4d1b392014-10-10 13:57:29 +0800578 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800579 vs_size = urb_size / 2;
580 gs_size = vs_size;
581 } else {
582 vs_size = urb_size;
583 gs_size = 0;
584 }
585
586 /* 3DSTATE_URB */
587 {
588 const uint8_t cmd_len = 3;
589 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
590 (cmd_len - 2);
591 int vs_alloc_size, gs_alloc_size;
592 int vs_entry_count, gs_entry_count;
593 uint32_t *dw;
594
595 /* in 1024-bit rows */
596 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
597 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
598
599 /* valid range is [1, 5] */
600 if (!vs_alloc_size)
601 vs_alloc_size = 1;
602 if (!gs_alloc_size)
603 gs_alloc_size = 1;
604 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
605
606 /* valid range is [24, 256], multiples of 4 */
607 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
608 if (vs_entry_count > 256)
609 vs_entry_count = 256;
610 assert(vs_entry_count >= 24);
611
612 /* valid range is [0, 256], multiples of 4 */
613 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
614 if (gs_entry_count > 256)
615 gs_entry_count = 256;
616
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600617 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800618
619 dw[0] = dw0;
620 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
621 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
622 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
623 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
624 }
625}
626
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800627static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
628 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800629{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800630 const struct intel_gpu *gpu = pipeline->dev->gpu;
631 const int urb_size = ((gpu->gt == 3) ? 512 :
632 (gpu->gt == 2) ? 256 : 128) * 1024;
Cody Northrop306ec352014-10-06 15:11:45 -0600633 const struct intel_pipeline_shader *vs = &pipeline->vs;
634 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800635 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800636 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800637 int vs_entry_size, gs_entry_size;
638 int vs_size, gs_size;
639
Chia-I Wu509b3f22014-09-02 10:24:05 +0800640 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800641
642 vs_entry_size = ((vs->in_count >= vs->out_count) ?
643 vs->in_count : vs->out_count);
644 gs_entry_size = (gs) ? gs->out_count : 0;
645
646 /* in bytes */
647 vs_entry_size *= sizeof(float) * 4;
648 gs_entry_size *= sizeof(float) * 4;
649
Chia-I Wua4d1b392014-10-10 13:57:29 +0800650 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800651 vs_size = (urb_size - urb_offset) / 2;
652 gs_size = vs_size;
653 } else {
654 vs_size = urb_size - urb_offset;
655 gs_size = 0;
656 }
657
658 /* 3DSTATE_URB_* */
659 {
660 const uint8_t cmd_len = 2;
661 int vs_alloc_size, gs_alloc_size;
662 int vs_entry_count, gs_entry_count;
663 uint32_t *dw;
664
665 /* in 512-bit rows */
666 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
667 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
668
669 if (!vs_alloc_size)
670 vs_alloc_size = 1;
671 if (!gs_alloc_size)
672 gs_alloc_size = 1;
673
674 /* avoid performance decrease due to banking */
675 if (vs_alloc_size == 5)
676 vs_alloc_size = 6;
677
678 /* in multiples of 8 */
679 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
680 assert(vs_entry_count >= 32);
681
682 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
683
Chia-I Wu509b3f22014-09-02 10:24:05 +0800684 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800685 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800686 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800687 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800688 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800689 if (vs_entry_count >= max_vs_entry_count)
690 vs_entry_count = max_vs_entry_count;
691 if (gs_entry_count >= max_gs_entry_count)
692 gs_entry_count = max_gs_entry_count;
693 } else {
694 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800695 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800696 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800697 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800698 if (vs_entry_count >= max_vs_entry_count)
699 vs_entry_count = max_vs_entry_count;
700 if (gs_entry_count >= max_gs_entry_count)
701 gs_entry_count = max_gs_entry_count;
702 }
703
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600704 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800705 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700706 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
707 (vs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800708 vs_entry_count;
709
710 dw += 2;
711 if (gs_size)
712 urb_offset += vs_size;
713 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700714 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
715 (gs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800716 gs_entry_count;
717
718 dw += 2;
719 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700720 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800721
722 dw += 2;
723 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700724 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800725 }
726}
727
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800728static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
729 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800730{
Cody Northrop306ec352014-10-06 15:11:45 -0600731 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu1d125092014-10-08 08:49:38 +0800732 uint8_t cmd_len;
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800733 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600734 uint32_t i;
Chia-I Wu1d125092014-10-08 08:49:38 +0800735 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800736
Chia-I Wu509b3f22014-09-02 10:24:05 +0800737 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800738
GregF8cd81832014-11-18 18:01:01 -0700739 cmd_len = 1 + 2 * u_popcountll(vs->inputs_read);
Chia-I Wu1d125092014-10-08 08:49:38 +0800740 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
741 cmd_len += 2;
742
743 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800744 return;
745
746 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800747
748 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
749 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800750 dw++;
751
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800752 /* VERTEX_ELEMENT_STATE */
Chia-I Wu1d125092014-10-08 08:49:38 +0800753 for (i = 0; i < info->vi.attributeCount; i++) {
GregF8cd81832014-11-18 18:01:01 -0700754 if (!(vs->inputs_read & (1L << i)))
GregF2dc40212014-10-31 17:31:47 -0600755 continue;
Chia-I Wu1d125092014-10-08 08:49:38 +0800756 const XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION *attr =
757 &info->vi.pVertexAttributeDescriptions[i];
758 const int format =
759 intel_format_translate_color(pipeline->dev->gpu, attr->format);
760
761 comps[0] = GEN6_VFCOMP_STORE_0;
762 comps[1] = GEN6_VFCOMP_STORE_0;
763 comps[2] = GEN6_VFCOMP_STORE_0;
764 comps[3] = icd_format_is_int(attr->format) ?
765 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
766
767 switch (icd_format_get_channel_count(attr->format)) {
768 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
769 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
770 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
771 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
772 default:
773 break;
774 }
775
776 assert(attr->offsetInBytes <= 2047);
777
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700778 dw[0] = attr->binding << GEN6_VE_DW0_VB_INDEX__SHIFT |
779 GEN6_VE_DW0_VALID |
780 format << GEN6_VE_DW0_FORMAT__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +0800781 attr->offsetInBytes;
782
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700783 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
784 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
785 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
786 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu1d125092014-10-08 08:49:38 +0800787
788 dw += 2;
789 }
GregF932fcf52014-10-29 17:02:11 -0600790
791 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
792 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
793 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
794 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
795 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
796 comps[2] = GEN6_VFCOMP_NOSTORE;
797 comps[3] = GEN6_VFCOMP_NOSTORE;
798
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700799 dw[0] = GEN6_VE_DW0_VALID;
800 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
801 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
802 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
803 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
GregF932fcf52014-10-29 17:02:11 -0600804
805 dw += 2;
806 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800807}
808
Chia-I Wub6386202015-03-24 11:13:06 +0800809static void pipeline_build_viewport(struct intel_pipeline *pipeline,
810 const struct intel_pipeline_create_info *info)
811{
812 switch (info->vp.depthMode) {
813 case XGL_DEPTH_MODE_ZERO_TO_ONE:
814 pipeline->depth_zero_to_one = true;
815 break;
816 case XGL_DEPTH_MODE_NEGATIVE_ONE_TO_ONE:
817 default:
818 pipeline->depth_zero_to_one = false;
819 break;
820 }
821}
822
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800823static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline,
824 const struct intel_pipeline_create_info *info)
GregF8cd81832014-11-18 18:01:01 -0700825{
826 const struct intel_pipeline_shader *fs = &pipeline->fs;
827 const struct intel_pipeline_shader *vs = &pipeline->vs;
828 uint8_t cmd_len;
829 uint32_t *body;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600830 uint32_t attr_skip, attr_count;
831 uint32_t vue_offset, vue_len;
832 uint32_t i;
GregF8cd81832014-11-18 18:01:01 -0700833
834 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
835
836 cmd_len = 14;
837
Chia-I Wuf85def42015-01-29 00:34:24 +0800838 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7))
839 body = pipeline_cmd_ptr(pipeline, cmd_len);
840 else
841 body = pipeline->cmd_3dstate_sbe;
GregF8cd81832014-11-18 18:01:01 -0700842
843 /* VS outputs VUE header and position additionally */
844 assert(vs->out_count >= fs->in_count + 2);
845 assert(!fs->reads_user_clip || vs->enable_user_clip);
846 attr_skip = vs->outputs_offset;
847 if (vs->enable_user_clip != fs->reads_user_clip) {
848 attr_skip += 2;
849 }
850 assert(vs->out_count >= attr_skip);
851 attr_count = vs->out_count - attr_skip;
852
853 // LUNARG TODO: We currently are only handling 16 attrs;
854 // ultimately, we need to handle 32
855 assert(fs->in_count <= 16);
856 assert(attr_count <= 16);
857
858 vue_offset = attr_skip / 2;
859 vue_len = (attr_count + 1) / 2;
860 if (!vue_len)
861 vue_len = 1;
862
863 body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
864 (cmd_len - 2);
865
866 // LUNARG TODO: If the attrs needed by the FS are exactly
867 // what is written by the VS, we don't need to enable
868 // swizzling, improving performance. Even if we swizzle,
869 // we can improve performance by reducing vue_len to
870 // just include the values needed by the FS:
871 // vue_len = ceiling((max_vs_out + 1)/2)
872
873 body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE |
874 fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
875 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
876 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
877
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800878 switch (info->rs.pointOrigin) {
879 case XGL_COORDINATE_ORIGIN_UPPER_LEFT:
880 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT;
881 break;
882 case XGL_COORDINATE_ORIGIN_LOWER_LEFT:
883 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_LOWERLEFT;
884 break;
885 default:
886 assert(!"unknown point origin");
887 break;
888 }
889
GregF8cd81832014-11-18 18:01:01 -0700890 uint16_t vs_slot[fs->in_count];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600891 int32_t fs_in = 0;
892 int32_t vs_out = - (vue_offset * 2 - vs->outputs_offset);
GregF8cd81832014-11-18 18:01:01 -0700893 for (i=0; i < 64; i++) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700894 bool vsWrites = vs->outputs_written & (1L << i);
895 bool fsReads = fs->inputs_read & (1L << i);
896
897 if (fsReads) {
GregF8cd81832014-11-18 18:01:01 -0700898 assert(vs_out >= 0);
899 assert(fs_in < fs->in_count);
900 vs_slot[fs_in] = vs_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700901
902 if (!vsWrites) {
903 // If the vertex shader did not write this input, we cannot
904 // program the SBE to read it. Our choices are to allow it to
905 // read junk from a GRF, or get zero. We're choosing zero.
906 if (i >= fs->generic_input_start) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700907 vs_slot[fs_in] = GEN8_SBE_SWIZ_CONST_0000 |
908 GEN8_SBE_SWIZ_OVERRIDE_X |
909 GEN8_SBE_SWIZ_OVERRIDE_Y |
910 GEN8_SBE_SWIZ_OVERRIDE_Z |
911 GEN8_SBE_SWIZ_OVERRIDE_W;
Cody Northropd75c13e2015-01-02 14:07:20 -0700912 }
913 }
914
GregF8cd81832014-11-18 18:01:01 -0700915 fs_in += 1;
916 }
Cody Northropd75c13e2015-01-02 14:07:20 -0700917 if (vsWrites) {
GregF8cd81832014-11-18 18:01:01 -0700918 vs_out += 1;
919 }
920 }
921
922 for (i = 0; i < 8; i++) {
923 uint16_t hi, lo;
924
925 /* no attr swizzles */
926 if (i * 2 + 1 < fs->in_count) {
927 lo = vs_slot[i * 2];
928 hi = vs_slot[i * 2 + 1];
929 } else if (i * 2 < fs->in_count) {
930 lo = vs_slot[i * 2];
931 hi = 0;
932 } else {
933 hi = 0;
934 lo = 0;
935 }
936
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700937 body[2 + i] = hi << GEN8_SBE_SWIZ_HIGH__SHIFT | lo;
GregF8cd81832014-11-18 18:01:01 -0700938 }
939
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800940 if (info->ia.topology == XGL_TOPOLOGY_POINT_LIST)
941 body[10] = 0xffffffffu; /* point sprite enables */
942
GregF8cd81832014-11-18 18:01:01 -0700943 body[11] = 0; /* constant interpolation enables */
944 body[12] = 0; /* WrapShortest enables */
945 body[13] = 0;
946}
947
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800948static void pipeline_build_gs(struct intel_pipeline *pipeline,
949 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600950{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600951 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600952}
953
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800954static void pipeline_build_hs(struct intel_pipeline *pipeline,
955 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600956{
957 const uint8_t cmd_len = 7;
958 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
959 uint32_t *dw;
960
Chia-I Wu509b3f22014-09-02 10:24:05 +0800961 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600962
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800963 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600964 dw[0] = dw0;
965 dw[1] = 0;
966 dw[2] = 0;
967 dw[3] = 0;
968 dw[4] = 0;
969 dw[5] = 0;
970 dw[6] = 0;
971}
972
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800973static void pipeline_build_te(struct intel_pipeline *pipeline,
974 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600975{
976 const uint8_t cmd_len = 4;
977 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
978 uint32_t *dw;
979
Chia-I Wu509b3f22014-09-02 10:24:05 +0800980 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600981
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800982 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600983 dw[0] = dw0;
984 dw[1] = 0;
985 dw[2] = 0;
986 dw[3] = 0;
987}
988
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800989static void pipeline_build_ds(struct intel_pipeline *pipeline,
990 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600991{
992 const uint8_t cmd_len = 6;
993 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
994 uint32_t *dw;
995
Chia-I Wu509b3f22014-09-02 10:24:05 +0800996 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600997
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800998 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600999 dw[0] = dw0;
1000 dw[1] = 0;
1001 dw[2] = 0;
1002 dw[3] = 0;
1003 dw[4] = 0;
1004 dw[5] = 0;
1005}
1006
Tony Barbourfa6cac72015-01-16 14:27:35 -07001007static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
1008 const struct intel_pipeline_create_info *info)
1009{
1010 pipeline->cmd_depth_stencil = 0;
1011
1012 if (info->db.stencilTestEnable) {
1013 pipeline->cmd_depth_stencil = 1 << 31 |
1014 translate_compare_func(info->db.front.stencilFunc) << 28 |
1015 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
1016 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
1017 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
1018 1 << 15 |
1019 translate_compare_func(info->db.back.stencilFunc) << 12 |
1020 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
1021 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
1022 translate_stencil_op(info->db.back.stencilPassOp) << 3;
1023 }
1024
1025 pipeline->stencilTestEnable = info->db.stencilTestEnable;
1026
1027 /*
1028 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
1029 *
1030 * "Enabling the Depth Test function without defining a Depth Buffer is
1031 * UNDEFINED."
1032 *
1033 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
1034 *
1035 * "A Depth Buffer must be defined before enabling writes to it, or
1036 * operation is UNDEFINED."
1037 *
1038 * TODO We do not check these yet.
1039 */
1040 if (info->db.depthTestEnable) {
1041 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
1042 translate_compare_func(info->db.depthFunc) << 27;
1043 } else {
1044 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
1045 }
1046
1047 if (info->db.depthWriteEnable)
1048 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1049}
1050
Tony Barbourfa6cac72015-01-16 14:27:35 -07001051static void pipeline_build_msaa(struct intel_pipeline *pipeline,
1052 const struct intel_pipeline_create_info *info)
1053{
1054 uint32_t cmd, cmd_len;
1055 uint32_t *dw;
1056
1057 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1058
Chia-I Wu8ada4242015-03-02 11:19:33 -07001059 pipeline->sample_count = (info->ms.samples <= 1) ? 1 : info->ms.samples;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001060
1061 /* 3DSTATE_SAMPLE_MASK */
1062 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
1063 cmd_len = 2;
1064
Chia-I Wu8ada4242015-03-02 11:19:33 -07001065 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001066 dw[0] = cmd | (cmd_len - 2);
1067 dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1);
1068 pipeline->cmd_sample_mask = dw[1];
1069}
1070
1071static void pipeline_build_cb(struct intel_pipeline *pipeline,
1072 const struct intel_pipeline_create_info *info)
1073{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001074 uint32_t i;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001075
1076 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1077 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
1078 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
1079
1080 uint32_t *dw = pipeline->cmd_cb;
1081
1082 for (i = 0; i < info->cb.attachmentCount; i++) {
1083 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &info->cb.pAttachments[i];
1084 uint32_t dw0, dw1;
1085
1086
1087 dw0 = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001088 dw1 = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1089 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1090 GEN6_RT_DW1_POST_BLEND_CLAMP;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001091
1092 if (att->blendEnable) {
1093 dw0 = 1 << 31 |
1094 translate_blend_func(att->blendFuncAlpha) << 26 |
1095 translate_blend(att->srcBlendAlpha) << 20 |
1096 translate_blend(att->destBlendAlpha) << 15 |
1097 translate_blend_func(att->blendFuncColor) << 11 |
1098 translate_blend(att->srcBlendColor) << 5 |
1099 translate_blend(att->destBlendColor);
1100
1101 if (att->blendFuncAlpha != att->blendFuncColor ||
1102 att->srcBlendAlpha != att->srcBlendColor ||
1103 att->destBlendAlpha != att->destBlendColor)
1104 dw0 |= 1 << 30;
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -07001105
1106 pipeline->dual_source_blend_enable = icd_pipeline_cb_att_needs_dual_source_blending(att);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001107 }
1108
1109 if (info->cb.logicOp != XGL_LOGIC_OP_COPY) {
1110 int logicop;
1111
1112 switch (info->cb.logicOp) {
1113 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1114 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1115 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1116 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1117 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1118 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1119 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1120 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1121 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1122 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1123 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1124 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1125 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1126 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1127 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1128 default:
1129 assert(!"unknown logic op");
1130 logicop = GEN6_LOGICOP_CLEAR;
1131 break;
1132 }
1133
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001134 dw1 |= GEN6_RT_DW1_LOGICOP_ENABLE |
1135 logicop << GEN6_RT_DW1_LOGICOP_FUNC__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001136 }
1137
1138 if (!(att->channelWriteMask & 0x1))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001139 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_R;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001140 if (!(att->channelWriteMask & 0x2))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001141 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_G;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001142 if (!(att->channelWriteMask & 0x4))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001143 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_B;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001144 if (!(att->channelWriteMask & 0x8))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001145 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001146
1147 dw[2 * i] = dw0;
1148 dw[2 * i + 1] = dw1;
1149 }
1150
1151 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1152 {
1153 dw[2 * i] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001154 dw[2 * i + 1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1155 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1156 GEN6_RT_DW1_POST_BLEND_CLAMP |
1157 GEN6_RT_DW1_WRITE_DISABLE_R |
1158 GEN6_RT_DW1_WRITE_DISABLE_G |
1159 GEN6_RT_DW1_WRITE_DISABLE_B |
1160 GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001161 }
1162
1163}
1164
1165
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001166static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline,
1167 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001168{
1169 XGL_RESULT ret;
1170
Chia-I Wu98824592014-09-02 09:42:46 +08001171 ret = pipeline_build_shaders(pipeline, info);
1172 if (ret != XGL_SUCCESS)
1173 return ret;
1174
Chia-I Wu1d125092014-10-08 08:49:38 +08001175 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
1176 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb))
1177 return XGL_ERROR_BAD_PIPELINE_DATA;
1178
1179 pipeline->vb_count = info->vi.bindingCount;
1180 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1181 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1182
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001183 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wub6386202015-03-24 11:13:06 +08001184 pipeline_build_viewport(pipeline, info);
Chia-I Wu86a5e0c2015-03-24 11:01:50 +08001185 pipeline_build_fragment_SBE(pipeline, info);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001186 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001187 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001188
Chia-I Wu509b3f22014-09-02 10:24:05 +08001189 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001190 pipeline_build_urb_alloc_gen7(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001191 pipeline_build_gs(pipeline, info);
1192 pipeline_build_hs(pipeline, info);
1193 pipeline_build_te(pipeline, info);
1194 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001195
1196 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1197 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1198 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1199 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1200 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001201 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001202 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001203
1204 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1205 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001206 }
1207
Chia-I Wube0a3d92014-09-02 13:20:59 +08001208 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001209
1210 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001211 ret = pipeline_rs_state(pipeline, &info->rs);
Chia-I Wu3efef432014-08-28 15:00:16 +08001212
Chia-I Wu3efef432014-08-28 15:00:16 +08001213 if (ret == XGL_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001214 pipeline->db_format = info->db.format;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001215 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001216 pipeline->cb_state = info->cb;
1217 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001218 }
1219
1220 return ret;
1221}
1222
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001223struct intel_pipeline_create_info_header {
1224 XGL_STRUCTURE_TYPE struct_type;
1225 const struct intel_pipeline_create_info_header *next;
1226};
1227
1228static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001229 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +08001230{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001231 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001232
Tony Barbourfa6cac72015-01-16 14:27:35 -07001233
1234 /*
1235 * Do we need to set safe defaults in case the app doesn't provide all of
1236 * the necessary create infos?
1237 */
1238 info->ms.samples = 1;
1239 info->ms.sampleMask = 1;
1240
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001241 while (header) {
1242 const void *src = (const void *) header;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001243 size_t size;
Chia-I Wu3efef432014-08-28 15:00:16 +08001244 void *dst;
1245
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001246 switch (header->struct_type) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001247 case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001248 size = sizeof(info->graphics);
1249 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +08001250 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001251 case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
1252 size = sizeof(info->vi);
1253 dst = &info->vi;
1254 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001255 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001256 size = sizeof(info->ia);
1257 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +08001258 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001259 case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001260 size = sizeof(info->db);
1261 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +08001262 break;
1263 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001264 size = sizeof(info->cb);
1265 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +08001266 break;
1267 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001268 size = sizeof(info->rs);
1269 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001270 break;
1271 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001272 size = sizeof(info->tess);
1273 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001274 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001275 case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
1276 size = sizeof(info->ms);
1277 dst = &info->ms;
1278 break;
1279 case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
1280 size = sizeof(info->vp);
1281 dst = &info->vp;
1282 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001283 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
1284 {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001285 const XGL_PIPELINE_SHADER *shader =
1286 (const XGL_PIPELINE_SHADER *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +08001287
1288 src = (const void *) shader;
1289 size = sizeof(*shader);
1290
1291 switch (shader->stage) {
1292 case XGL_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001293 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001294 break;
1295 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001296 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001297 break;
1298 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001299 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +08001300 break;
1301 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001302 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001303 break;
1304 case XGL_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001305 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001306 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001307 default:
1308 return XGL_ERROR_BAD_PIPELINE_DATA;
1309 break;
1310 }
1311 }
1312 break;
1313 case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001314 size = sizeof(info->compute);
1315 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +08001316 break;
1317 default:
1318 return XGL_ERROR_BAD_PIPELINE_DATA;
1319 break;
1320 }
1321
1322 memcpy(dst, src, size);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001323 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +08001324 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001325
1326 return XGL_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001327}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001328
Chia-I Wu3efef432014-08-28 15:00:16 +08001329static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001330 const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +08001331 struct intel_pipeline **pipeline_ret)
1332{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001333 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001334 struct intel_pipeline *pipeline;
1335 XGL_RESULT ret;
1336
Chia-I Wu509b3f22014-09-02 10:24:05 +08001337 ret = pipeline_create_info_init(&info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001338 (const struct intel_pipeline_create_info_header *) info_);
Chia-I Wu3efef432014-08-28 15:00:16 +08001339 if (ret != XGL_SUCCESS)
1340 return ret;
1341
Chia-I Wu545c2e12015-02-22 13:19:54 +08001342 pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle,
1343 sizeof(*pipeline), dev->base.dbg,
1344 XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001345 if (!pipeline)
1346 return XGL_ERROR_OUT_OF_MEMORY;
1347
1348 pipeline->dev = dev;
Chia-I Wub1024732014-12-19 13:00:29 +08001349 pipeline->obj.base.get_info = pipeline_get_info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001350 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001351
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001352 ret = pipeline_build_all(pipeline, &info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001353 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001354 ret = pipeline_validate(pipeline);
Chia-I Wu3efef432014-08-28 15:00:16 +08001355 if (ret != XGL_SUCCESS) {
1356 pipeline_destroy(&pipeline->obj);
1357 return ret;
1358 }
1359
1360 *pipeline_ret = pipeline;
1361
1362 return XGL_SUCCESS;
1363}
1364
Chia-I Wu96177272015-01-03 15:27:41 +08001365ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipeline(
Chia-I Wu3efef432014-08-28 15:00:16 +08001366 XGL_DEVICE device,
1367 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1368 XGL_PIPELINE* pPipeline)
1369{
1370 struct intel_dev *dev = intel_dev(device);
1371
1372 return graphics_pipeline_create(dev, pCreateInfo,
1373 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001374}
1375
Chia-I Wu96177272015-01-03 15:27:41 +08001376ICD_EXPORT XGL_RESULT XGLAPI xglCreateComputePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001377 XGL_DEVICE device,
1378 const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo,
1379 XGL_PIPELINE* pPipeline)
1380{
1381 return XGL_ERROR_UNAVAILABLE;
1382}
1383
Chia-I Wu96177272015-01-03 15:27:41 +08001384ICD_EXPORT XGL_RESULT XGLAPI xglStorePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001385 XGL_PIPELINE pipeline,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001386 size_t* pDataSize,
1387 void* pData)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001388{
1389 return XGL_ERROR_UNAVAILABLE;
1390}
1391
Chia-I Wu96177272015-01-03 15:27:41 +08001392ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001393 XGL_DEVICE device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001394 size_t dataSize,
1395 const void* pData,
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001396 XGL_PIPELINE* pPipeline)
1397{
1398 return XGL_ERROR_UNAVAILABLE;
1399}
1400
Chia-I Wu96177272015-01-03 15:27:41 +08001401ICD_EXPORT XGL_RESULT XGLAPI xglCreatePipelineDelta(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001402 XGL_DEVICE device,
1403 XGL_PIPELINE p1,
1404 XGL_PIPELINE p2,
1405 XGL_PIPELINE_DELTA* delta)
1406{
1407 return XGL_ERROR_UNAVAILABLE;
1408}