blob: e62c0dd6f87f0d500303546f0f5fd5d2b5799f30 [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;
Courtney Goeltzenleuchter528781d2015-03-03 11:38:12 -0700334 case XGL_TOPOLOGY_TRIANGLE_FAN:
335 pipeline->prim_type = GEN6_3DPRIM_TRIFAN;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600336 break;
337 case XGL_TOPOLOGY_LINE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600338 pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600339 break;
340 case XGL_TOPOLOGY_LINE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600341 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600342 break;
343 case XGL_TOPOLOGY_TRIANGLE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600344 pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600345 break;
346 case XGL_TOPOLOGY_TRIANGLE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600347 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600348 break;
349 case XGL_TOPOLOGY_PATCH:
Chia-I Wube0a3d92014-09-02 13:20:59 +0800350 if (!info->tess.patchControlPoints ||
351 info->tess.patchControlPoints > 32)
352 return XGL_ERROR_BAD_PIPELINE_DATA;
353 pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 +
354 info->tess.patchControlPoints - 1;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600355 break;
356 default:
357 return XGL_ERROR_BAD_PIPELINE_DATA;
358 }
359
Chia-I Wube0a3d92014-09-02 13:20:59 +0800360 if (info->ia.primitiveRestartEnable) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600361 pipeline->primitive_restart = true;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800362 pipeline->primitive_restart_index = info->ia.primitiveRestartIndex;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600363 } else {
364 pipeline->primitive_restart = false;
365 }
366
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600367 return XGL_SUCCESS;
368}
369
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800370static XGL_RESULT pipeline_build_rs_state(struct intel_pipeline *pipeline,
371 const struct intel_pipeline_create_info* info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600372{
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800373 const XGL_PIPELINE_RS_STATE_CREATE_INFO *rs_state = &info->rs;
374 bool ccw;
375
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600376 pipeline->depthClipEnable = rs_state->depthClipEnable;
377 pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable;
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800378 pipeline->use_rs_point_size = !rs_state->programPointSize;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700379
380 if (rs_state->provokingVertex == XGL_PROVOKING_VERTEX_FIRST) {
381 pipeline->provoking_vertex_tri = 0;
382 pipeline->provoking_vertex_trifan = 1;
383 pipeline->provoking_vertex_line = 0;
384 } else {
385 pipeline->provoking_vertex_tri = 2;
386 pipeline->provoking_vertex_trifan = 2;
387 pipeline->provoking_vertex_line = 1;
388 }
389
390 switch (rs_state->fillMode) {
391 case XGL_FILL_POINTS:
392 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT |
393 GEN7_SF_DW1_BACKFACE_POINT;
394 break;
395 case XGL_FILL_WIREFRAME:
396 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME |
397 GEN7_SF_DW1_BACKFACE_WIREFRAME;
398 break;
399 case XGL_FILL_SOLID:
400 default:
401 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID |
402 GEN7_SF_DW1_BACKFACE_SOLID;
403 break;
404 }
405
Chia-I Wu6abcb0e2015-03-24 14:38:14 +0800406 ccw = (rs_state->frontFace == XGL_FRONT_FACE_CCW);
407 /* flip the winding order */
408 if (info->vp.clipOrigin == XGL_COORDINATE_ORIGIN_LOWER_LEFT)
409 ccw = !ccw;
410
411 if (ccw) {
Tony Barbourfa6cac72015-01-16 14:27:35 -0700412 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW;
413 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW;
414 }
415
416 switch (rs_state->cullMode) {
417 case XGL_CULL_NONE:
418 default:
419 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE;
420 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE;
421 break;
422 case XGL_CULL_FRONT:
423 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT;
424 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT;
425 break;
426 case XGL_CULL_BACK:
427 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK;
428 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK;
429 break;
430 case XGL_CULL_FRONT_AND_BACK:
431 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH;
432 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH;
433 break;
434 }
435
436 /* only GEN7+ needs cull mode in 3DSTATE_CLIP */
437 if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
438 pipeline->cmd_clip_cull = 0;
439
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600440 return XGL_SUCCESS;
441}
442
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600443static void pipeline_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600444{
445 struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj);
446
Chia-I Wu3f239832014-12-11 22:57:18 +0800447 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800448 intel_pipeline_shader_cleanup(&pipeline->vs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800449 }
450
451 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800452 intel_pipeline_shader_cleanup(&pipeline->tcs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800453 }
454
455 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800456 intel_pipeline_shader_cleanup(&pipeline->tes, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800457 }
458
459 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800460 intel_pipeline_shader_cleanup(&pipeline->gs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800461 }
462
463 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800464 intel_pipeline_shader_cleanup(&pipeline->fs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800465 }
466
467 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800468 intel_pipeline_shader_cleanup(&pipeline->cs, pipeline->dev->gpu);
Chia-I Wu3f239832014-12-11 22:57:18 +0800469 }
Chia-I Wued833872014-08-23 17:00:35 +0800470
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600471 intel_base_destroy(&pipeline->obj.base);
472}
473
Chia-I Wub1024732014-12-19 13:00:29 +0800474static XGL_RESULT pipeline_get_info(struct intel_base *base, int type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600475 size_t *size, void *data)
Chia-I Wub1024732014-12-19 13:00:29 +0800476{
477 struct intel_pipeline *pipeline = intel_pipeline_from_base(base);
478 XGL_RESULT ret = XGL_SUCCESS;
479
480 switch (type) {
481 case XGL_INFO_TYPE_MEMORY_REQUIREMENTS:
482 {
483 XGL_MEMORY_REQUIREMENTS *mem_req = data;
484
485 *size = sizeof(XGL_MEMORY_REQUIREMENTS);
486 if (data) {
487 mem_req->size = pipeline->scratch_size;
488 mem_req->alignment = 1024;
Jon Ashburnd8031332015-01-22 10:52:13 -0700489 mem_req->memType = XGL_MEMORY_TYPE_OTHER;
Chia-I Wub1024732014-12-19 13:00:29 +0800490 }
491 }
492 break;
493 default:
494 ret = intel_base_get_info(base, type, size, data);
495 break;
496 }
497
498 return ret;
499}
500
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800501static XGL_RESULT pipeline_validate(struct intel_pipeline *pipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +0800502{
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600503 /*
504 * Validate required elements
505 */
506 if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) {
507 // TODO: Log debug message: Vertex Shader required.
Chia-I Wu3efef432014-08-28 15:00:16 +0800508 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600509 }
510
511 /*
512 * Tessalation control and evaluation have to both have a shader defined or
513 * neither should have a shader defined.
514 */
515 if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) !=
516 ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) {
517 // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation
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 if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) &&
522 (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG |
523 SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG |
524 SHADER_FRAGMENT_FLAG))) {
525 // TODO: Log debug message: Can only specify compute shader when doing compute
Chia-I Wu3efef432014-08-28 15:00:16 +0800526 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600527 }
528
529 /*
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600530 * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
531 * Mismatching primitive topology and tessellation fails graphics pipeline creation.
532 */
533 if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) &&
Chia-I Wube0a3d92014-09-02 13:20:59 +0800534 (pipeline->topology != XGL_TOPOLOGY_PATCH)) {
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600535 // TODO: Log debug message: Invalid topology used with tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800536 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600537 }
538
Chia-I Wube0a3d92014-09-02 13:20:59 +0800539 if ((pipeline->topology == XGL_TOPOLOGY_PATCH) &&
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600540 (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) {
541 // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800542 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600543 }
544
Chia-I Wu3efef432014-08-28 15:00:16 +0800545 return XGL_SUCCESS;
546}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600547
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800548static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
549 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800550{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800551 const struct intel_gpu *gpu = pipeline->dev->gpu;
552 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wua4d1b392014-10-10 13:57:29 +0800553 const struct intel_pipeline_shader *vs = &pipeline->vs;
554 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800555 int vs_entry_size, gs_entry_size;
556 int vs_size, gs_size;
557
Chia-I Wu509b3f22014-09-02 10:24:05 +0800558 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800559
560 vs_entry_size = ((vs->in_count >= vs->out_count) ?
561 vs->in_count : vs->out_count);
562 gs_entry_size = (gs) ? gs->out_count : 0;
563
564 /* in bytes */
565 vs_entry_size *= sizeof(float) * 4;
566 gs_entry_size *= sizeof(float) * 4;
567
Chia-I Wua4d1b392014-10-10 13:57:29 +0800568 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800569 vs_size = urb_size / 2;
570 gs_size = vs_size;
571 } else {
572 vs_size = urb_size;
573 gs_size = 0;
574 }
575
576 /* 3DSTATE_URB */
577 {
578 const uint8_t cmd_len = 3;
579 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
580 (cmd_len - 2);
581 int vs_alloc_size, gs_alloc_size;
582 int vs_entry_count, gs_entry_count;
583 uint32_t *dw;
584
585 /* in 1024-bit rows */
586 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
587 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
588
589 /* valid range is [1, 5] */
590 if (!vs_alloc_size)
591 vs_alloc_size = 1;
592 if (!gs_alloc_size)
593 gs_alloc_size = 1;
594 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
595
596 /* valid range is [24, 256], multiples of 4 */
597 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
598 if (vs_entry_count > 256)
599 vs_entry_count = 256;
600 assert(vs_entry_count >= 24);
601
602 /* valid range is [0, 256], multiples of 4 */
603 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
604 if (gs_entry_count > 256)
605 gs_entry_count = 256;
606
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600607 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800608
609 dw[0] = dw0;
610 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
611 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
612 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
613 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
614 }
615}
616
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800617static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
618 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800619{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800620 const struct intel_gpu *gpu = pipeline->dev->gpu;
621 const int urb_size = ((gpu->gt == 3) ? 512 :
622 (gpu->gt == 2) ? 256 : 128) * 1024;
Cody Northrop306ec352014-10-06 15:11:45 -0600623 const struct intel_pipeline_shader *vs = &pipeline->vs;
624 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800625 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800626 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800627 int vs_entry_size, gs_entry_size;
628 int vs_size, gs_size;
629
Chia-I Wu509b3f22014-09-02 10:24:05 +0800630 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800631
632 vs_entry_size = ((vs->in_count >= vs->out_count) ?
633 vs->in_count : vs->out_count);
634 gs_entry_size = (gs) ? gs->out_count : 0;
635
636 /* in bytes */
637 vs_entry_size *= sizeof(float) * 4;
638 gs_entry_size *= sizeof(float) * 4;
639
Chia-I Wua4d1b392014-10-10 13:57:29 +0800640 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800641 vs_size = (urb_size - urb_offset) / 2;
642 gs_size = vs_size;
643 } else {
644 vs_size = urb_size - urb_offset;
645 gs_size = 0;
646 }
647
648 /* 3DSTATE_URB_* */
649 {
650 const uint8_t cmd_len = 2;
651 int vs_alloc_size, gs_alloc_size;
652 int vs_entry_count, gs_entry_count;
653 uint32_t *dw;
654
655 /* in 512-bit rows */
656 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
657 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
658
659 if (!vs_alloc_size)
660 vs_alloc_size = 1;
661 if (!gs_alloc_size)
662 gs_alloc_size = 1;
663
664 /* avoid performance decrease due to banking */
665 if (vs_alloc_size == 5)
666 vs_alloc_size = 6;
667
668 /* in multiples of 8 */
669 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
670 assert(vs_entry_count >= 32);
671
672 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
673
Chia-I Wu509b3f22014-09-02 10:24:05 +0800674 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800675 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800676 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800677 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800678 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800679 if (vs_entry_count >= max_vs_entry_count)
680 vs_entry_count = max_vs_entry_count;
681 if (gs_entry_count >= max_gs_entry_count)
682 gs_entry_count = max_gs_entry_count;
683 } else {
684 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800685 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800686 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800687 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800688 if (vs_entry_count >= max_vs_entry_count)
689 vs_entry_count = max_vs_entry_count;
690 if (gs_entry_count >= max_gs_entry_count)
691 gs_entry_count = max_gs_entry_count;
692 }
693
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600694 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800695 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700696 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
697 (vs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800698 vs_entry_count;
699
700 dw += 2;
701 if (gs_size)
702 urb_offset += vs_size;
703 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700704 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT |
705 (gs_alloc_size - 1) << GEN7_URB_DW1_ENTRY_SIZE__SHIFT |
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800706 gs_entry_count;
707
708 dw += 2;
709 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700710 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800711
712 dw += 2;
713 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700714 dw[1] = (urb_offset / 8192) << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800715 }
716}
717
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800718static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
719 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800720{
Cody Northrop306ec352014-10-06 15:11:45 -0600721 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu1d125092014-10-08 08:49:38 +0800722 uint8_t cmd_len;
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800723 uint32_t *dw;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600724 uint32_t i, j;
725 uint32_t attr_count;
726 uint32_t attrs_processed;
Chia-I Wu1d125092014-10-08 08:49:38 +0800727 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800728
Chia-I Wu509b3f22014-09-02 10:24:05 +0800729 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800730
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600731 attr_count = u_popcountll(vs->inputs_read);
732 cmd_len = 1 + 2 * attr_count;
Chia-I Wu1d125092014-10-08 08:49:38 +0800733 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
734 cmd_len += 2;
735
736 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800737 return;
738
739 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800740
741 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
742 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800743 dw++;
744
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800745 /* VERTEX_ELEMENT_STATE */
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600746 for (i = 0, attrs_processed = 0; attrs_processed < attr_count; i++) {
747 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION *attr = NULL;
748
749 /*
750 * The compiler will pack the shader references and then
751 * indicate which locations are used via the bitmask in
752 * vs->inputs_read.
753 */
754 if (!(vs->inputs_read & (1L << i))) {
GregF2dc40212014-10-31 17:31:47 -0600755 continue;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600756 }
757
758 /*
759 * For each bit set in the vs->inputs_read we'll need
760 * to find the corresponding attribute record and then
761 * set up the next HW vertex element based on that attribute.
762 */
763 for (j = 0; j < info->vi.attributeCount; j++) {
764 if (info->vi.pVertexAttributeDescriptions[j].location == i) {
765 attr = (XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION *) &info->vi.pVertexAttributeDescriptions[j];
766 attrs_processed++;
767 break;
768 }
769 }
770 assert(attr != NULL);
771
Chia-I Wu1d125092014-10-08 08:49:38 +0800772 const int format =
773 intel_format_translate_color(pipeline->dev->gpu, attr->format);
774
775 comps[0] = GEN6_VFCOMP_STORE_0;
776 comps[1] = GEN6_VFCOMP_STORE_0;
777 comps[2] = GEN6_VFCOMP_STORE_0;
778 comps[3] = icd_format_is_int(attr->format) ?
779 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
780
781 switch (icd_format_get_channel_count(attr->format)) {
782 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
783 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
784 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
785 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
786 default:
787 break;
788 }
789
790 assert(attr->offsetInBytes <= 2047);
791
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700792 dw[0] = attr->binding << GEN6_VE_DW0_VB_INDEX__SHIFT |
793 GEN6_VE_DW0_VALID |
794 format << GEN6_VE_DW0_FORMAT__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +0800795 attr->offsetInBytes;
796
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700797 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
798 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
799 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
800 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu1d125092014-10-08 08:49:38 +0800801
802 dw += 2;
803 }
GregF932fcf52014-10-29 17:02:11 -0600804
805 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
806 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
807 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
808 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
809 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
810 comps[2] = GEN6_VFCOMP_NOSTORE;
811 comps[3] = GEN6_VFCOMP_NOSTORE;
812
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700813 dw[0] = GEN6_VE_DW0_VALID;
814 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
815 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
816 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
817 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
GregF932fcf52014-10-29 17:02:11 -0600818
819 dw += 2;
820 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800821}
822
Chia-I Wub6386202015-03-24 11:13:06 +0800823static void pipeline_build_viewport(struct intel_pipeline *pipeline,
824 const struct intel_pipeline_create_info *info)
825{
826 switch (info->vp.depthMode) {
827 case XGL_DEPTH_MODE_ZERO_TO_ONE:
828 pipeline->depth_zero_to_one = true;
829 break;
830 case XGL_DEPTH_MODE_NEGATIVE_ONE_TO_ONE:
831 default:
832 pipeline->depth_zero_to_one = false;
833 break;
834 }
835}
836
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800837static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline,
838 const struct intel_pipeline_create_info *info)
GregF8cd81832014-11-18 18:01:01 -0700839{
840 const struct intel_pipeline_shader *fs = &pipeline->fs;
841 const struct intel_pipeline_shader *vs = &pipeline->vs;
842 uint8_t cmd_len;
843 uint32_t *body;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600844 uint32_t attr_skip, attr_count;
845 uint32_t vue_offset, vue_len;
846 uint32_t i;
GregF8cd81832014-11-18 18:01:01 -0700847
848 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
849
850 cmd_len = 14;
851
Chia-I Wuf85def42015-01-29 00:34:24 +0800852 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7))
853 body = pipeline_cmd_ptr(pipeline, cmd_len);
854 else
855 body = pipeline->cmd_3dstate_sbe;
GregF8cd81832014-11-18 18:01:01 -0700856
GregF8cd81832014-11-18 18:01:01 -0700857 assert(!fs->reads_user_clip || vs->enable_user_clip);
858 attr_skip = vs->outputs_offset;
859 if (vs->enable_user_clip != fs->reads_user_clip) {
860 attr_skip += 2;
861 }
862 assert(vs->out_count >= attr_skip);
863 attr_count = vs->out_count - attr_skip;
864
865 // LUNARG TODO: We currently are only handling 16 attrs;
866 // ultimately, we need to handle 32
867 assert(fs->in_count <= 16);
868 assert(attr_count <= 16);
869
870 vue_offset = attr_skip / 2;
871 vue_len = (attr_count + 1) / 2;
872 if (!vue_len)
873 vue_len = 1;
874
875 body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
876 (cmd_len - 2);
877
878 // LUNARG TODO: If the attrs needed by the FS are exactly
879 // what is written by the VS, we don't need to enable
880 // swizzling, improving performance. Even if we swizzle,
881 // we can improve performance by reducing vue_len to
882 // just include the values needed by the FS:
883 // vue_len = ceiling((max_vs_out + 1)/2)
884
885 body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE |
886 fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
887 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
888 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
889
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800890 switch (info->rs.pointOrigin) {
891 case XGL_COORDINATE_ORIGIN_UPPER_LEFT:
892 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT;
893 break;
894 case XGL_COORDINATE_ORIGIN_LOWER_LEFT:
895 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_LOWERLEFT;
896 break;
897 default:
898 assert(!"unknown point origin");
899 break;
900 }
901
GregF8cd81832014-11-18 18:01:01 -0700902 uint16_t vs_slot[fs->in_count];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600903 int32_t fs_in = 0;
904 int32_t vs_out = - (vue_offset * 2 - vs->outputs_offset);
GregF8cd81832014-11-18 18:01:01 -0700905 for (i=0; i < 64; i++) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700906 bool vsWrites = vs->outputs_written & (1L << i);
907 bool fsReads = fs->inputs_read & (1L << i);
908
909 if (fsReads) {
GregF8cd81832014-11-18 18:01:01 -0700910 assert(vs_out >= 0);
911 assert(fs_in < fs->in_count);
912 vs_slot[fs_in] = vs_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700913
914 if (!vsWrites) {
915 // If the vertex shader did not write this input, we cannot
916 // program the SBE to read it. Our choices are to allow it to
917 // read junk from a GRF, or get zero. We're choosing zero.
918 if (i >= fs->generic_input_start) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700919 vs_slot[fs_in] = GEN8_SBE_SWIZ_CONST_0000 |
920 GEN8_SBE_SWIZ_OVERRIDE_X |
921 GEN8_SBE_SWIZ_OVERRIDE_Y |
922 GEN8_SBE_SWIZ_OVERRIDE_Z |
923 GEN8_SBE_SWIZ_OVERRIDE_W;
Cody Northropd75c13e2015-01-02 14:07:20 -0700924 }
925 }
926
GregF8cd81832014-11-18 18:01:01 -0700927 fs_in += 1;
928 }
Cody Northropd75c13e2015-01-02 14:07:20 -0700929 if (vsWrites) {
GregF8cd81832014-11-18 18:01:01 -0700930 vs_out += 1;
931 }
932 }
933
934 for (i = 0; i < 8; i++) {
935 uint16_t hi, lo;
936
937 /* no attr swizzles */
938 if (i * 2 + 1 < fs->in_count) {
939 lo = vs_slot[i * 2];
940 hi = vs_slot[i * 2 + 1];
941 } else if (i * 2 < fs->in_count) {
942 lo = vs_slot[i * 2];
943 hi = 0;
944 } else {
945 hi = 0;
946 lo = 0;
947 }
948
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700949 body[2 + i] = hi << GEN8_SBE_SWIZ_HIGH__SHIFT | lo;
GregF8cd81832014-11-18 18:01:01 -0700950 }
951
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800952 if (info->ia.topology == XGL_TOPOLOGY_POINT_LIST)
Chia-I Wu7f390562015-03-25 08:47:18 +0800953 body[10] = fs->point_sprite_enables;
954 else
955 body[10] = 0;
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800956
GregF8cd81832014-11-18 18:01:01 -0700957 body[11] = 0; /* constant interpolation enables */
958 body[12] = 0; /* WrapShortest enables */
959 body[13] = 0;
960}
961
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800962static void pipeline_build_gs(struct intel_pipeline *pipeline,
963 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600964{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600965 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600966}
967
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800968static void pipeline_build_hs(struct intel_pipeline *pipeline,
969 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600970{
971 const uint8_t cmd_len = 7;
972 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
973 uint32_t *dw;
974
Chia-I Wu509b3f22014-09-02 10:24:05 +0800975 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600976
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800977 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600978 dw[0] = dw0;
979 dw[1] = 0;
980 dw[2] = 0;
981 dw[3] = 0;
982 dw[4] = 0;
983 dw[5] = 0;
984 dw[6] = 0;
985}
986
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800987static void pipeline_build_te(struct intel_pipeline *pipeline,
988 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600989{
990 const uint8_t cmd_len = 4;
991 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
992 uint32_t *dw;
993
Chia-I Wu509b3f22014-09-02 10:24:05 +0800994 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600995
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800996 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600997 dw[0] = dw0;
998 dw[1] = 0;
999 dw[2] = 0;
1000 dw[3] = 0;
1001}
1002
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001003static void pipeline_build_ds(struct intel_pipeline *pipeline,
1004 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -06001005{
1006 const uint8_t cmd_len = 6;
1007 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
1008 uint32_t *dw;
1009
Chia-I Wu509b3f22014-09-02 10:24:05 +08001010 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -06001011
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001012 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -06001013 dw[0] = dw0;
1014 dw[1] = 0;
1015 dw[2] = 0;
1016 dw[3] = 0;
1017 dw[4] = 0;
1018 dw[5] = 0;
1019}
1020
Tony Barbourfa6cac72015-01-16 14:27:35 -07001021static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
1022 const struct intel_pipeline_create_info *info)
1023{
1024 pipeline->cmd_depth_stencil = 0;
1025
1026 if (info->db.stencilTestEnable) {
1027 pipeline->cmd_depth_stencil = 1 << 31 |
1028 translate_compare_func(info->db.front.stencilFunc) << 28 |
1029 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
1030 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
1031 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
1032 1 << 15 |
1033 translate_compare_func(info->db.back.stencilFunc) << 12 |
1034 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
1035 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
1036 translate_stencil_op(info->db.back.stencilPassOp) << 3;
1037 }
1038
1039 pipeline->stencilTestEnable = info->db.stencilTestEnable;
1040
1041 /*
1042 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
1043 *
1044 * "Enabling the Depth Test function without defining a Depth Buffer is
1045 * UNDEFINED."
1046 *
1047 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
1048 *
1049 * "A Depth Buffer must be defined before enabling writes to it, or
1050 * operation is UNDEFINED."
1051 *
1052 * TODO We do not check these yet.
1053 */
1054 if (info->db.depthTestEnable) {
1055 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
1056 translate_compare_func(info->db.depthFunc) << 27;
1057 } else {
1058 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
1059 }
1060
1061 if (info->db.depthWriteEnable)
1062 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1063}
1064
Tony Barbourfa6cac72015-01-16 14:27:35 -07001065static void pipeline_build_msaa(struct intel_pipeline *pipeline,
1066 const struct intel_pipeline_create_info *info)
1067{
1068 uint32_t cmd, cmd_len;
1069 uint32_t *dw;
1070
1071 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1072
Chia-I Wu8ada4242015-03-02 11:19:33 -07001073 pipeline->sample_count = (info->ms.samples <= 1) ? 1 : info->ms.samples;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001074
1075 /* 3DSTATE_SAMPLE_MASK */
1076 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
1077 cmd_len = 2;
1078
Chia-I Wu8ada4242015-03-02 11:19:33 -07001079 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001080 dw[0] = cmd | (cmd_len - 2);
1081 dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1);
1082 pipeline->cmd_sample_mask = dw[1];
1083}
1084
1085static void pipeline_build_cb(struct intel_pipeline *pipeline,
1086 const struct intel_pipeline_create_info *info)
1087{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001088 uint32_t i;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001089
1090 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1091 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
1092 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
1093
1094 uint32_t *dw = pipeline->cmd_cb;
1095
1096 for (i = 0; i < info->cb.attachmentCount; i++) {
1097 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &info->cb.pAttachments[i];
1098 uint32_t dw0, dw1;
1099
1100
1101 dw0 = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001102 dw1 = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1103 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1104 GEN6_RT_DW1_POST_BLEND_CLAMP;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001105
1106 if (att->blendEnable) {
1107 dw0 = 1 << 31 |
1108 translate_blend_func(att->blendFuncAlpha) << 26 |
1109 translate_blend(att->srcBlendAlpha) << 20 |
1110 translate_blend(att->destBlendAlpha) << 15 |
1111 translate_blend_func(att->blendFuncColor) << 11 |
1112 translate_blend(att->srcBlendColor) << 5 |
1113 translate_blend(att->destBlendColor);
1114
1115 if (att->blendFuncAlpha != att->blendFuncColor ||
1116 att->srcBlendAlpha != att->srcBlendColor ||
1117 att->destBlendAlpha != att->destBlendColor)
1118 dw0 |= 1 << 30;
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -07001119
1120 pipeline->dual_source_blend_enable = icd_pipeline_cb_att_needs_dual_source_blending(att);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001121 }
1122
1123 if (info->cb.logicOp != XGL_LOGIC_OP_COPY) {
1124 int logicop;
1125
1126 switch (info->cb.logicOp) {
1127 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1128 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1129 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1130 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1131 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1132 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1133 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1134 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1135 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1136 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1137 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1138 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1139 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1140 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1141 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1142 default:
1143 assert(!"unknown logic op");
1144 logicop = GEN6_LOGICOP_CLEAR;
1145 break;
1146 }
1147
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001148 dw1 |= GEN6_RT_DW1_LOGICOP_ENABLE |
1149 logicop << GEN6_RT_DW1_LOGICOP_FUNC__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001150 }
1151
1152 if (!(att->channelWriteMask & 0x1))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001153 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_R;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001154 if (!(att->channelWriteMask & 0x2))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001155 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_G;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001156 if (!(att->channelWriteMask & 0x4))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001157 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_B;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001158 if (!(att->channelWriteMask & 0x8))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001159 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001160
1161 dw[2 * i] = dw0;
1162 dw[2 * i + 1] = dw1;
1163 }
1164
1165 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1166 {
1167 dw[2 * i] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001168 dw[2 * i + 1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1169 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1170 GEN6_RT_DW1_POST_BLEND_CLAMP |
1171 GEN6_RT_DW1_WRITE_DISABLE_R |
1172 GEN6_RT_DW1_WRITE_DISABLE_G |
1173 GEN6_RT_DW1_WRITE_DISABLE_B |
1174 GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001175 }
1176
1177}
1178
1179
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001180static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline,
1181 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001182{
1183 XGL_RESULT ret;
1184
Chia-I Wu98824592014-09-02 09:42:46 +08001185 ret = pipeline_build_shaders(pipeline, info);
1186 if (ret != XGL_SUCCESS)
1187 return ret;
1188
Chia-I Wu1d125092014-10-08 08:49:38 +08001189 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
1190 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb))
1191 return XGL_ERROR_BAD_PIPELINE_DATA;
1192
1193 pipeline->vb_count = info->vi.bindingCount;
1194 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1195 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1196
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001197 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wub6386202015-03-24 11:13:06 +08001198 pipeline_build_viewport(pipeline, info);
Chia-I Wu86a5e0c2015-03-24 11:01:50 +08001199 pipeline_build_fragment_SBE(pipeline, info);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001200 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001201 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001202
Chia-I Wu509b3f22014-09-02 10:24:05 +08001203 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001204 pipeline_build_urb_alloc_gen7(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001205 pipeline_build_gs(pipeline, info);
1206 pipeline_build_hs(pipeline, info);
1207 pipeline_build_te(pipeline, info);
1208 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001209
1210 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1211 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1212 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1213 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1214 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001215 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001216 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001217
1218 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1219 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001220 }
1221
Chia-I Wube0a3d92014-09-02 13:20:59 +08001222 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001223
1224 if (ret == XGL_SUCCESS)
Chia-I Wu6abcb0e2015-03-24 14:38:14 +08001225 ret = pipeline_build_rs_state(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001226
Chia-I Wu3efef432014-08-28 15:00:16 +08001227 if (ret == XGL_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001228 pipeline->db_format = info->db.format;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001229 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001230 pipeline->cb_state = info->cb;
1231 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001232 }
1233
1234 return ret;
1235}
1236
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001237struct intel_pipeline_create_info_header {
1238 XGL_STRUCTURE_TYPE struct_type;
1239 const struct intel_pipeline_create_info_header *next;
1240};
1241
1242static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001243 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +08001244{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001245 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001246
Tony Barbourfa6cac72015-01-16 14:27:35 -07001247
1248 /*
1249 * Do we need to set safe defaults in case the app doesn't provide all of
1250 * the necessary create infos?
1251 */
1252 info->ms.samples = 1;
1253 info->ms.sampleMask = 1;
1254
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001255 while (header) {
1256 const void *src = (const void *) header;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001257 size_t size;
Chia-I Wu3efef432014-08-28 15:00:16 +08001258 void *dst;
1259
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001260 switch (header->struct_type) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001261 case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001262 size = sizeof(info->graphics);
1263 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +08001264 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001265 case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
1266 size = sizeof(info->vi);
1267 dst = &info->vi;
1268 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001269 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001270 size = sizeof(info->ia);
1271 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +08001272 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001273 case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001274 size = sizeof(info->db);
1275 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +08001276 break;
1277 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001278 size = sizeof(info->cb);
1279 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +08001280 break;
1281 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001282 size = sizeof(info->rs);
1283 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001284 break;
1285 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001286 size = sizeof(info->tess);
1287 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001288 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001289 case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
1290 size = sizeof(info->ms);
1291 dst = &info->ms;
1292 break;
1293 case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
1294 size = sizeof(info->vp);
1295 dst = &info->vp;
1296 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001297 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
1298 {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001299 const XGL_PIPELINE_SHADER *shader =
1300 (const XGL_PIPELINE_SHADER *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +08001301
1302 src = (const void *) shader;
1303 size = sizeof(*shader);
1304
1305 switch (shader->stage) {
1306 case XGL_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001307 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001308 break;
1309 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001310 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001311 break;
1312 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001313 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +08001314 break;
1315 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001316 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001317 break;
1318 case XGL_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001319 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001320 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001321 default:
1322 return XGL_ERROR_BAD_PIPELINE_DATA;
1323 break;
1324 }
1325 }
1326 break;
1327 case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001328 size = sizeof(info->compute);
1329 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +08001330 break;
1331 default:
1332 return XGL_ERROR_BAD_PIPELINE_DATA;
1333 break;
1334 }
1335
1336 memcpy(dst, src, size);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001337 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +08001338 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001339
1340 return XGL_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001341}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001342
Chia-I Wu3efef432014-08-28 15:00:16 +08001343static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001344 const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +08001345 struct intel_pipeline **pipeline_ret)
1346{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001347 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001348 struct intel_pipeline *pipeline;
1349 XGL_RESULT ret;
1350
Chia-I Wu509b3f22014-09-02 10:24:05 +08001351 ret = pipeline_create_info_init(&info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001352 (const struct intel_pipeline_create_info_header *) info_);
Chia-I Wu3efef432014-08-28 15:00:16 +08001353 if (ret != XGL_SUCCESS)
1354 return ret;
1355
Chia-I Wu545c2e12015-02-22 13:19:54 +08001356 pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle,
1357 sizeof(*pipeline), dev->base.dbg,
1358 XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001359 if (!pipeline)
1360 return XGL_ERROR_OUT_OF_MEMORY;
1361
1362 pipeline->dev = dev;
Chia-I Wub1024732014-12-19 13:00:29 +08001363 pipeline->obj.base.get_info = pipeline_get_info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001364 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001365
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001366 ret = pipeline_build_all(pipeline, &info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001367 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001368 ret = pipeline_validate(pipeline);
Chia-I Wu3efef432014-08-28 15:00:16 +08001369 if (ret != XGL_SUCCESS) {
1370 pipeline_destroy(&pipeline->obj);
1371 return ret;
1372 }
1373
1374 *pipeline_ret = pipeline;
1375
1376 return XGL_SUCCESS;
1377}
1378
Chia-I Wu96177272015-01-03 15:27:41 +08001379ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipeline(
Chia-I Wu3efef432014-08-28 15:00:16 +08001380 XGL_DEVICE device,
1381 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1382 XGL_PIPELINE* pPipeline)
1383{
1384 struct intel_dev *dev = intel_dev(device);
1385
1386 return graphics_pipeline_create(dev, pCreateInfo,
1387 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001388}
1389
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001390ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipelineDerivative(
1391 XGL_DEVICE device,
1392 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1393 XGL_PIPELINE basePipeline,
1394 XGL_PIPELINE* pPipeline)
1395{
1396 struct intel_dev *dev = intel_dev(device);
1397
1398 /* TODO: Use basePipeline to optimize creation of derivative */
1399
1400 return graphics_pipeline_create(dev, pCreateInfo,
1401 (struct intel_pipeline **) pPipeline);
1402}
1403
Chia-I Wu96177272015-01-03 15:27:41 +08001404ICD_EXPORT XGL_RESULT XGLAPI xglCreateComputePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001405 XGL_DEVICE device,
1406 const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo,
1407 XGL_PIPELINE* pPipeline)
1408{
1409 return XGL_ERROR_UNAVAILABLE;
1410}
1411
Chia-I Wu96177272015-01-03 15:27:41 +08001412ICD_EXPORT XGL_RESULT XGLAPI xglStorePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001413 XGL_PIPELINE pipeline,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001414 size_t* pDataSize,
1415 void* pData)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001416{
1417 return XGL_ERROR_UNAVAILABLE;
1418}
1419
Chia-I Wu96177272015-01-03 15:27:41 +08001420ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001421 XGL_DEVICE device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001422 size_t dataSize,
1423 const void* pData,
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001424 XGL_PIPELINE* pPipeline)
1425{
1426 return XGL_ERROR_UNAVAILABLE;
1427}
1428
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001429ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipelineDerivative(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001430 XGL_DEVICE device,
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001431 size_t dataSize,
1432 const void* pData,
1433 XGL_PIPELINE basePipeline,
1434 XGL_PIPELINE* pPipeline)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001435{
1436 return XGL_ERROR_UNAVAILABLE;
1437}