blob: be21b4289f8c768a68e8ff3ab11613d36643fbb1 [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;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600724 uint32_t i;
Chia-I Wu1d125092014-10-08 08:49:38 +0800725 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800726
Chia-I Wu509b3f22014-09-02 10:24:05 +0800727 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800728
GregF8cd81832014-11-18 18:01:01 -0700729 cmd_len = 1 + 2 * u_popcountll(vs->inputs_read);
Chia-I Wu1d125092014-10-08 08:49:38 +0800730 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
731 cmd_len += 2;
732
733 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800734 return;
735
736 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800737
738 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
739 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800740 dw++;
741
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800742 /* VERTEX_ELEMENT_STATE */
Chia-I Wu1d125092014-10-08 08:49:38 +0800743 for (i = 0; i < info->vi.attributeCount; i++) {
GregF8cd81832014-11-18 18:01:01 -0700744 if (!(vs->inputs_read & (1L << i)))
GregF2dc40212014-10-31 17:31:47 -0600745 continue;
Chia-I Wu1d125092014-10-08 08:49:38 +0800746 const XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION *attr =
747 &info->vi.pVertexAttributeDescriptions[i];
748 const int format =
749 intel_format_translate_color(pipeline->dev->gpu, attr->format);
750
751 comps[0] = GEN6_VFCOMP_STORE_0;
752 comps[1] = GEN6_VFCOMP_STORE_0;
753 comps[2] = GEN6_VFCOMP_STORE_0;
754 comps[3] = icd_format_is_int(attr->format) ?
755 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
756
757 switch (icd_format_get_channel_count(attr->format)) {
758 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
759 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
760 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
761 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
762 default:
763 break;
764 }
765
766 assert(attr->offsetInBytes <= 2047);
767
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700768 dw[0] = attr->binding << GEN6_VE_DW0_VB_INDEX__SHIFT |
769 GEN6_VE_DW0_VALID |
770 format << GEN6_VE_DW0_FORMAT__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +0800771 attr->offsetInBytes;
772
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700773 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
774 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
775 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
776 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu1d125092014-10-08 08:49:38 +0800777
778 dw += 2;
779 }
GregF932fcf52014-10-29 17:02:11 -0600780
781 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
782 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
783 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
784 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
785 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
786 comps[2] = GEN6_VFCOMP_NOSTORE;
787 comps[3] = GEN6_VFCOMP_NOSTORE;
788
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700789 dw[0] = GEN6_VE_DW0_VALID;
790 dw[1] = comps[0] << GEN6_VE_DW1_COMP0__SHIFT |
791 comps[1] << GEN6_VE_DW1_COMP1__SHIFT |
792 comps[2] << GEN6_VE_DW1_COMP2__SHIFT |
793 comps[3] << GEN6_VE_DW1_COMP3__SHIFT;
GregF932fcf52014-10-29 17:02:11 -0600794
795 dw += 2;
796 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800797}
798
Chia-I Wub6386202015-03-24 11:13:06 +0800799static void pipeline_build_viewport(struct intel_pipeline *pipeline,
800 const struct intel_pipeline_create_info *info)
801{
802 switch (info->vp.depthMode) {
803 case XGL_DEPTH_MODE_ZERO_TO_ONE:
804 pipeline->depth_zero_to_one = true;
805 break;
806 case XGL_DEPTH_MODE_NEGATIVE_ONE_TO_ONE:
807 default:
808 pipeline->depth_zero_to_one = false;
809 break;
810 }
811}
812
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800813static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline,
814 const struct intel_pipeline_create_info *info)
GregF8cd81832014-11-18 18:01:01 -0700815{
816 const struct intel_pipeline_shader *fs = &pipeline->fs;
817 const struct intel_pipeline_shader *vs = &pipeline->vs;
818 uint8_t cmd_len;
819 uint32_t *body;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600820 uint32_t attr_skip, attr_count;
821 uint32_t vue_offset, vue_len;
822 uint32_t i;
GregF8cd81832014-11-18 18:01:01 -0700823
824 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
825
826 cmd_len = 14;
827
Chia-I Wuf85def42015-01-29 00:34:24 +0800828 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7))
829 body = pipeline_cmd_ptr(pipeline, cmd_len);
830 else
831 body = pipeline->cmd_3dstate_sbe;
GregF8cd81832014-11-18 18:01:01 -0700832
GregF8cd81832014-11-18 18:01:01 -0700833 assert(!fs->reads_user_clip || vs->enable_user_clip);
834 attr_skip = vs->outputs_offset;
835 if (vs->enable_user_clip != fs->reads_user_clip) {
836 attr_skip += 2;
837 }
838 assert(vs->out_count >= attr_skip);
839 attr_count = vs->out_count - attr_skip;
840
841 // LUNARG TODO: We currently are only handling 16 attrs;
842 // ultimately, we need to handle 32
843 assert(fs->in_count <= 16);
844 assert(attr_count <= 16);
845
846 vue_offset = attr_skip / 2;
847 vue_len = (attr_count + 1) / 2;
848 if (!vue_len)
849 vue_len = 1;
850
851 body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
852 (cmd_len - 2);
853
854 // LUNARG TODO: If the attrs needed by the FS are exactly
855 // what is written by the VS, we don't need to enable
856 // swizzling, improving performance. Even if we swizzle,
857 // we can improve performance by reducing vue_len to
858 // just include the values needed by the FS:
859 // vue_len = ceiling((max_vs_out + 1)/2)
860
861 body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE |
862 fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
863 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
864 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
865
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800866 switch (info->rs.pointOrigin) {
867 case XGL_COORDINATE_ORIGIN_UPPER_LEFT:
868 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_UPPERLEFT;
869 break;
870 case XGL_COORDINATE_ORIGIN_LOWER_LEFT:
871 body[1] |= GEN7_SBE_DW1_POINT_SPRITE_TEXCOORD_LOWERLEFT;
872 break;
873 default:
874 assert(!"unknown point origin");
875 break;
876 }
877
GregF8cd81832014-11-18 18:01:01 -0700878 uint16_t vs_slot[fs->in_count];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600879 int32_t fs_in = 0;
880 int32_t vs_out = - (vue_offset * 2 - vs->outputs_offset);
GregF8cd81832014-11-18 18:01:01 -0700881 for (i=0; i < 64; i++) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700882 bool vsWrites = vs->outputs_written & (1L << i);
883 bool fsReads = fs->inputs_read & (1L << i);
884
885 if (fsReads) {
GregF8cd81832014-11-18 18:01:01 -0700886 assert(vs_out >= 0);
887 assert(fs_in < fs->in_count);
888 vs_slot[fs_in] = vs_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700889
890 if (!vsWrites) {
891 // If the vertex shader did not write this input, we cannot
892 // program the SBE to read it. Our choices are to allow it to
893 // read junk from a GRF, or get zero. We're choosing zero.
894 if (i >= fs->generic_input_start) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700895 vs_slot[fs_in] = GEN8_SBE_SWIZ_CONST_0000 |
896 GEN8_SBE_SWIZ_OVERRIDE_X |
897 GEN8_SBE_SWIZ_OVERRIDE_Y |
898 GEN8_SBE_SWIZ_OVERRIDE_Z |
899 GEN8_SBE_SWIZ_OVERRIDE_W;
Cody Northropd75c13e2015-01-02 14:07:20 -0700900 }
901 }
902
GregF8cd81832014-11-18 18:01:01 -0700903 fs_in += 1;
904 }
Cody Northropd75c13e2015-01-02 14:07:20 -0700905 if (vsWrites) {
GregF8cd81832014-11-18 18:01:01 -0700906 vs_out += 1;
907 }
908 }
909
910 for (i = 0; i < 8; i++) {
911 uint16_t hi, lo;
912
913 /* no attr swizzles */
914 if (i * 2 + 1 < fs->in_count) {
915 lo = vs_slot[i * 2];
916 hi = vs_slot[i * 2 + 1];
917 } else if (i * 2 < fs->in_count) {
918 lo = vs_slot[i * 2];
919 hi = 0;
920 } else {
921 hi = 0;
922 lo = 0;
923 }
924
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700925 body[2 + i] = hi << GEN8_SBE_SWIZ_HIGH__SHIFT | lo;
GregF8cd81832014-11-18 18:01:01 -0700926 }
927
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800928 if (info->ia.topology == XGL_TOPOLOGY_POINT_LIST)
Chia-I Wu7f390562015-03-25 08:47:18 +0800929 body[10] = fs->point_sprite_enables;
930 else
931 body[10] = 0;
Chia-I Wu86a5e0c2015-03-24 11:01:50 +0800932
GregF8cd81832014-11-18 18:01:01 -0700933 body[11] = 0; /* constant interpolation enables */
934 body[12] = 0; /* WrapShortest enables */
935 body[13] = 0;
936}
937
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800938static void pipeline_build_gs(struct intel_pipeline *pipeline,
939 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600940{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600941 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600942}
943
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800944static void pipeline_build_hs(struct intel_pipeline *pipeline,
945 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600946{
947 const uint8_t cmd_len = 7;
948 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
949 uint32_t *dw;
950
Chia-I Wu509b3f22014-09-02 10:24:05 +0800951 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600952
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800953 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600954 dw[0] = dw0;
955 dw[1] = 0;
956 dw[2] = 0;
957 dw[3] = 0;
958 dw[4] = 0;
959 dw[5] = 0;
960 dw[6] = 0;
961}
962
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800963static void pipeline_build_te(struct intel_pipeline *pipeline,
964 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600965{
966 const uint8_t cmd_len = 4;
967 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
968 uint32_t *dw;
969
Chia-I Wu509b3f22014-09-02 10:24:05 +0800970 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600971
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800972 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600973 dw[0] = dw0;
974 dw[1] = 0;
975 dw[2] = 0;
976 dw[3] = 0;
977}
978
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800979static void pipeline_build_ds(struct intel_pipeline *pipeline,
980 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600981{
982 const uint8_t cmd_len = 6;
983 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
984 uint32_t *dw;
985
Chia-I Wu509b3f22014-09-02 10:24:05 +0800986 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600987
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800988 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600989 dw[0] = dw0;
990 dw[1] = 0;
991 dw[2] = 0;
992 dw[3] = 0;
993 dw[4] = 0;
994 dw[5] = 0;
995}
996
Tony Barbourfa6cac72015-01-16 14:27:35 -0700997static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
998 const struct intel_pipeline_create_info *info)
999{
1000 pipeline->cmd_depth_stencil = 0;
1001
1002 if (info->db.stencilTestEnable) {
1003 pipeline->cmd_depth_stencil = 1 << 31 |
1004 translate_compare_func(info->db.front.stencilFunc) << 28 |
1005 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
1006 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
1007 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
1008 1 << 15 |
1009 translate_compare_func(info->db.back.stencilFunc) << 12 |
1010 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
1011 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
1012 translate_stencil_op(info->db.back.stencilPassOp) << 3;
1013 }
1014
1015 pipeline->stencilTestEnable = info->db.stencilTestEnable;
1016
1017 /*
1018 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
1019 *
1020 * "Enabling the Depth Test function without defining a Depth Buffer is
1021 * UNDEFINED."
1022 *
1023 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
1024 *
1025 * "A Depth Buffer must be defined before enabling writes to it, or
1026 * operation is UNDEFINED."
1027 *
1028 * TODO We do not check these yet.
1029 */
1030 if (info->db.depthTestEnable) {
1031 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
1032 translate_compare_func(info->db.depthFunc) << 27;
1033 } else {
1034 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
1035 }
1036
1037 if (info->db.depthWriteEnable)
1038 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1039}
1040
Tony Barbourfa6cac72015-01-16 14:27:35 -07001041static void pipeline_build_msaa(struct intel_pipeline *pipeline,
1042 const struct intel_pipeline_create_info *info)
1043{
1044 uint32_t cmd, cmd_len;
1045 uint32_t *dw;
1046
1047 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1048
Chia-I Wu8ada4242015-03-02 11:19:33 -07001049 pipeline->sample_count = (info->ms.samples <= 1) ? 1 : info->ms.samples;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001050
1051 /* 3DSTATE_SAMPLE_MASK */
1052 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
1053 cmd_len = 2;
1054
Chia-I Wu8ada4242015-03-02 11:19:33 -07001055 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001056 dw[0] = cmd | (cmd_len - 2);
1057 dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1);
1058 pipeline->cmd_sample_mask = dw[1];
1059}
1060
1061static void pipeline_build_cb(struct intel_pipeline *pipeline,
1062 const struct intel_pipeline_create_info *info)
1063{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001064 uint32_t i;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001065
1066 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1067 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
1068 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
1069
1070 uint32_t *dw = pipeline->cmd_cb;
1071
1072 for (i = 0; i < info->cb.attachmentCount; i++) {
1073 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &info->cb.pAttachments[i];
1074 uint32_t dw0, dw1;
1075
1076
1077 dw0 = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001078 dw1 = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1079 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1080 GEN6_RT_DW1_POST_BLEND_CLAMP;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001081
1082 if (att->blendEnable) {
1083 dw0 = 1 << 31 |
1084 translate_blend_func(att->blendFuncAlpha) << 26 |
1085 translate_blend(att->srcBlendAlpha) << 20 |
1086 translate_blend(att->destBlendAlpha) << 15 |
1087 translate_blend_func(att->blendFuncColor) << 11 |
1088 translate_blend(att->srcBlendColor) << 5 |
1089 translate_blend(att->destBlendColor);
1090
1091 if (att->blendFuncAlpha != att->blendFuncColor ||
1092 att->srcBlendAlpha != att->srcBlendColor ||
1093 att->destBlendAlpha != att->destBlendColor)
1094 dw0 |= 1 << 30;
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -07001095
1096 pipeline->dual_source_blend_enable = icd_pipeline_cb_att_needs_dual_source_blending(att);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001097 }
1098
1099 if (info->cb.logicOp != XGL_LOGIC_OP_COPY) {
1100 int logicop;
1101
1102 switch (info->cb.logicOp) {
1103 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1104 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1105 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1106 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1107 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1108 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1109 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1110 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1111 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1112 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1113 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1114 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1115 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1116 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1117 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1118 default:
1119 assert(!"unknown logic op");
1120 logicop = GEN6_LOGICOP_CLEAR;
1121 break;
1122 }
1123
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001124 dw1 |= GEN6_RT_DW1_LOGICOP_ENABLE |
1125 logicop << GEN6_RT_DW1_LOGICOP_FUNC__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001126 }
1127
1128 if (!(att->channelWriteMask & 0x1))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001129 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_R;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001130 if (!(att->channelWriteMask & 0x2))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001131 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_G;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001132 if (!(att->channelWriteMask & 0x4))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001133 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_B;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001134 if (!(att->channelWriteMask & 0x8))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001135 dw1 |= GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001136
1137 dw[2 * i] = dw0;
1138 dw[2 * i + 1] = dw1;
1139 }
1140
1141 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1142 {
1143 dw[2 * i] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001144 dw[2 * i + 1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT |
1145 GEN6_RT_DW1_PRE_BLEND_CLAMP |
1146 GEN6_RT_DW1_POST_BLEND_CLAMP |
1147 GEN6_RT_DW1_WRITE_DISABLE_R |
1148 GEN6_RT_DW1_WRITE_DISABLE_G |
1149 GEN6_RT_DW1_WRITE_DISABLE_B |
1150 GEN6_RT_DW1_WRITE_DISABLE_A;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001151 }
1152
1153}
1154
1155
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001156static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline,
1157 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001158{
1159 XGL_RESULT ret;
1160
Chia-I Wu98824592014-09-02 09:42:46 +08001161 ret = pipeline_build_shaders(pipeline, info);
1162 if (ret != XGL_SUCCESS)
1163 return ret;
1164
Chia-I Wu1d125092014-10-08 08:49:38 +08001165 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
1166 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb))
1167 return XGL_ERROR_BAD_PIPELINE_DATA;
1168
1169 pipeline->vb_count = info->vi.bindingCount;
1170 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1171 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1172
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001173 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wub6386202015-03-24 11:13:06 +08001174 pipeline_build_viewport(pipeline, info);
Chia-I Wu86a5e0c2015-03-24 11:01:50 +08001175 pipeline_build_fragment_SBE(pipeline, info);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001176 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001177 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001178
Chia-I Wu509b3f22014-09-02 10:24:05 +08001179 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001180 pipeline_build_urb_alloc_gen7(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001181 pipeline_build_gs(pipeline, info);
1182 pipeline_build_hs(pipeline, info);
1183 pipeline_build_te(pipeline, info);
1184 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001185
1186 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1187 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1188 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1189 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1190 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001191 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001192 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001193
1194 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1195 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001196 }
1197
Chia-I Wube0a3d92014-09-02 13:20:59 +08001198 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001199
1200 if (ret == XGL_SUCCESS)
Chia-I Wu6abcb0e2015-03-24 14:38:14 +08001201 ret = pipeline_build_rs_state(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001202
Chia-I Wu3efef432014-08-28 15:00:16 +08001203 if (ret == XGL_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001204 pipeline->db_format = info->db.format;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001205 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001206 pipeline->cb_state = info->cb;
1207 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001208 }
1209
1210 return ret;
1211}
1212
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001213struct intel_pipeline_create_info_header {
1214 XGL_STRUCTURE_TYPE struct_type;
1215 const struct intel_pipeline_create_info_header *next;
1216};
1217
1218static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001219 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +08001220{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001221 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001222
Tony Barbourfa6cac72015-01-16 14:27:35 -07001223
1224 /*
1225 * Do we need to set safe defaults in case the app doesn't provide all of
1226 * the necessary create infos?
1227 */
1228 info->ms.samples = 1;
1229 info->ms.sampleMask = 1;
1230
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001231 while (header) {
1232 const void *src = (const void *) header;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001233 size_t size;
Chia-I Wu3efef432014-08-28 15:00:16 +08001234 void *dst;
1235
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001236 switch (header->struct_type) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001237 case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001238 size = sizeof(info->graphics);
1239 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +08001240 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001241 case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
1242 size = sizeof(info->vi);
1243 dst = &info->vi;
1244 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001245 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001246 size = sizeof(info->ia);
1247 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +08001248 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001249 case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001250 size = sizeof(info->db);
1251 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +08001252 break;
1253 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001254 size = sizeof(info->cb);
1255 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +08001256 break;
1257 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001258 size = sizeof(info->rs);
1259 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001260 break;
1261 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001262 size = sizeof(info->tess);
1263 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001264 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001265 case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
1266 size = sizeof(info->ms);
1267 dst = &info->ms;
1268 break;
1269 case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
1270 size = sizeof(info->vp);
1271 dst = &info->vp;
1272 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001273 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
1274 {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001275 const XGL_PIPELINE_SHADER *shader =
1276 (const XGL_PIPELINE_SHADER *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +08001277
1278 src = (const void *) shader;
1279 size = sizeof(*shader);
1280
1281 switch (shader->stage) {
1282 case XGL_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001283 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001284 break;
1285 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001286 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001287 break;
1288 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001289 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +08001290 break;
1291 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001292 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001293 break;
1294 case XGL_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001295 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001296 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001297 default:
1298 return XGL_ERROR_BAD_PIPELINE_DATA;
1299 break;
1300 }
1301 }
1302 break;
1303 case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001304 size = sizeof(info->compute);
1305 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +08001306 break;
1307 default:
1308 return XGL_ERROR_BAD_PIPELINE_DATA;
1309 break;
1310 }
1311
1312 memcpy(dst, src, size);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001313 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +08001314 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001315
1316 return XGL_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001317}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001318
Chia-I Wu3efef432014-08-28 15:00:16 +08001319static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001320 const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +08001321 struct intel_pipeline **pipeline_ret)
1322{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001323 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001324 struct intel_pipeline *pipeline;
1325 XGL_RESULT ret;
1326
Chia-I Wu509b3f22014-09-02 10:24:05 +08001327 ret = pipeline_create_info_init(&info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001328 (const struct intel_pipeline_create_info_header *) info_);
Chia-I Wu3efef432014-08-28 15:00:16 +08001329 if (ret != XGL_SUCCESS)
1330 return ret;
1331
Chia-I Wu545c2e12015-02-22 13:19:54 +08001332 pipeline = (struct intel_pipeline *) intel_base_create(&dev->base.handle,
1333 sizeof(*pipeline), dev->base.dbg,
1334 XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001335 if (!pipeline)
1336 return XGL_ERROR_OUT_OF_MEMORY;
1337
1338 pipeline->dev = dev;
Chia-I Wub1024732014-12-19 13:00:29 +08001339 pipeline->obj.base.get_info = pipeline_get_info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001340 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001341
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001342 ret = pipeline_build_all(pipeline, &info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001343 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001344 ret = pipeline_validate(pipeline);
Chia-I Wu3efef432014-08-28 15:00:16 +08001345 if (ret != XGL_SUCCESS) {
1346 pipeline_destroy(&pipeline->obj);
1347 return ret;
1348 }
1349
1350 *pipeline_ret = pipeline;
1351
1352 return XGL_SUCCESS;
1353}
1354
Chia-I Wu96177272015-01-03 15:27:41 +08001355ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipeline(
Chia-I Wu3efef432014-08-28 15:00:16 +08001356 XGL_DEVICE device,
1357 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1358 XGL_PIPELINE* pPipeline)
1359{
1360 struct intel_dev *dev = intel_dev(device);
1361
1362 return graphics_pipeline_create(dev, pCreateInfo,
1363 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001364}
1365
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001366ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipelineDerivative(
1367 XGL_DEVICE device,
1368 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1369 XGL_PIPELINE basePipeline,
1370 XGL_PIPELINE* pPipeline)
1371{
1372 struct intel_dev *dev = intel_dev(device);
1373
1374 /* TODO: Use basePipeline to optimize creation of derivative */
1375
1376 return graphics_pipeline_create(dev, pCreateInfo,
1377 (struct intel_pipeline **) pPipeline);
1378}
1379
Chia-I Wu96177272015-01-03 15:27:41 +08001380ICD_EXPORT XGL_RESULT XGLAPI xglCreateComputePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001381 XGL_DEVICE device,
1382 const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo,
1383 XGL_PIPELINE* pPipeline)
1384{
1385 return XGL_ERROR_UNAVAILABLE;
1386}
1387
Chia-I Wu96177272015-01-03 15:27:41 +08001388ICD_EXPORT XGL_RESULT XGLAPI xglStorePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001389 XGL_PIPELINE pipeline,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001390 size_t* pDataSize,
1391 void* pData)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001392{
1393 return XGL_ERROR_UNAVAILABLE;
1394}
1395
Chia-I Wu96177272015-01-03 15:27:41 +08001396ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001397 XGL_DEVICE device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001398 size_t dataSize,
1399 const void* pData,
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001400 XGL_PIPELINE* pPipeline)
1401{
1402 return XGL_ERROR_UNAVAILABLE;
1403}
1404
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001405ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipelineDerivative(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001406 XGL_DEVICE device,
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001407 size_t dataSize,
1408 const void* pData,
1409 XGL_PIPELINE basePipeline,
1410 XGL_PIPELINE* pPipeline)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001411{
1412 return XGL_ERROR_UNAVAILABLE;
1413}