blob: 25669e1d78fc277b42d4f2fbf794450075f4e9ab [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};
130struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
131 enum intel_dev_meta_shader id)
132{
133 struct intel_pipeline_shader *sh;
134 XGL_RESULT ret;
135
136 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
137 if (!sh)
138 return NULL;
139 memset(sh, 0, sizeof(*sh));
140
141 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
142 if (ret != XGL_SUCCESS) {
143 icd_free(sh);
144 return NULL;
145 }
146
147 switch (id) {
148 case INTEL_DEV_META_VS_FILL_MEM:
149 case INTEL_DEV_META_VS_COPY_MEM:
150 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
151 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
152 XGL_SHADER_STAGE_VERTEX);
153 break;
154 default:
155 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
156 XGL_SHADER_STAGE_FRAGMENT);
157 break;
158 }
159
160 return sh;
161}
162
163void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
164{
165 intel_pipeline_shader_cleanup(sh);
166 icd_free(sh);
167}
168
169static XGL_RESULT pipeline_build_shader(struct intel_pipeline *pipeline,
Chia-I Wuf8385062015-01-04 16:27:24 +0800170 const struct intel_desc_layout *layout,
171 const XGL_PIPELINE_SHADER *sh_info,
172 struct intel_pipeline_shader *sh)
Chia-I Wu3f239832014-12-11 22:57:18 +0800173{
174 XGL_RESULT ret;
175
Chia-I Wuf8385062015-01-04 16:27:24 +0800176 ret = intel_pipeline_shader_compile(sh,
177 pipeline->dev->gpu, layout, sh_info);
Chia-I Wu3f239832014-12-11 22:57:18 +0800178 if (ret != XGL_SUCCESS)
179 return ret;
180
181 sh->max_threads =
182 intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage);
183
184 /* 1KB aligned */
185 sh->scratch_offset = u_align(pipeline->scratch_size, 1024);
186 pipeline->scratch_size = sh->scratch_offset +
187 sh->per_thread_scratch_size * sh->max_threads;
188
189 pipeline->active_shaders |= 1 << sh_info->stage;
190
191 return XGL_SUCCESS;
192}
193
194static XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
195 const struct intel_pipeline_create_info *info)
196{
Chia-I Wuf8385062015-01-04 16:27:24 +0800197 const struct intel_desc_layout *layout =
198 intel_desc_layout(info->graphics.lastSetLayout);
Chia-I Wu3f239832014-12-11 22:57:18 +0800199 XGL_RESULT ret = XGL_SUCCESS;
200
Chia-I Wuf8385062015-01-04 16:27:24 +0800201 if (ret == XGL_SUCCESS && info->vs.shader) {
202 ret = pipeline_build_shader(pipeline, layout,
203 &info->vs, &pipeline->vs);
204 }
205 if (ret == XGL_SUCCESS && info->tcs.shader) {
206 ret = pipeline_build_shader(pipeline, layout,
207 &info->tcs,&pipeline->tcs);
208 }
209 if (ret == XGL_SUCCESS && info->tes.shader) {
210 ret = pipeline_build_shader(pipeline, layout,
211 &info->tes,&pipeline->tes);
212 }
213 if (ret == XGL_SUCCESS && info->gs.shader) {
214 ret = pipeline_build_shader(pipeline, layout,
215 &info->gs, &pipeline->gs);
216 }
217 if (ret == XGL_SUCCESS && info->fs.shader) {
218 ret = pipeline_build_shader(pipeline, layout,
219 &info->fs, &pipeline->fs);
220 }
Chia-I Wu3f239832014-12-11 22:57:18 +0800221
Chia-I Wuf8385062015-01-04 16:27:24 +0800222 if (ret == XGL_SUCCESS && info->compute.cs.shader) {
223 layout = intel_desc_layout(info->compute.lastSetLayout);
224 ret = pipeline_build_shader(pipeline, layout,
225 &info->compute.cs, &pipeline->cs);
226 }
Chia-I Wu3f239832014-12-11 22:57:18 +0800227
228 return ret;
229}
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600230static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len)
231{
232 uint32_t *ptr;
233
234 assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES);
235 ptr = &pipeline->cmds[pipeline->cmd_len];
236 pipeline->cmd_len += cmd_len;
237 return ptr;
238}
239
Chia-I Wube0a3d92014-09-02 13:20:59 +0800240static XGL_RESULT pipeline_build_ia(struct intel_pipeline *pipeline,
241 const struct intel_pipeline_create_info* info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600242{
Chia-I Wube0a3d92014-09-02 13:20:59 +0800243 pipeline->topology = info->ia.topology;
244 pipeline->disable_vs_cache = info->ia.disableVertexReuse;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600245
Chia-I Wube0a3d92014-09-02 13:20:59 +0800246 switch (info->ia.topology) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600247 case XGL_TOPOLOGY_POINT_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600248 pipeline->prim_type = GEN6_3DPRIM_POINTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600249 break;
250 case XGL_TOPOLOGY_LINE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600251 pipeline->prim_type = GEN6_3DPRIM_LINELIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600252 break;
253 case XGL_TOPOLOGY_LINE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600254 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600255 break;
256 case XGL_TOPOLOGY_TRIANGLE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600257 pipeline->prim_type = GEN6_3DPRIM_TRILIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600258 break;
259 case XGL_TOPOLOGY_TRIANGLE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600260 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600261 break;
262 case XGL_TOPOLOGY_RECT_LIST:
263 /*
264 * TODO: Rect lists are special in XGL, do we need to do
265 * something special here?
266 * XGL Guide:
267 * The rectangle list is a special geometry primitive type
268 * that can be used for implementing post-processing techniques
269 * or efficient copy operations. There are some special limitations
270 * for rectangle primitives. They cannot be clipped, must
271 * be axis aligned and cannot have depth gradient.
272 * Failure to comply with these restrictions results in
273 * undefined rendering results.
274 */
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600275 pipeline->prim_type = GEN6_3DPRIM_RECTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600276 break;
277 case XGL_TOPOLOGY_QUAD_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600278 pipeline->prim_type = GEN6_3DPRIM_QUADLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600279 break;
280 case XGL_TOPOLOGY_QUAD_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600281 pipeline->prim_type = GEN6_3DPRIM_QUADSTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600282 break;
283 case XGL_TOPOLOGY_LINE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600284 pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600285 break;
286 case XGL_TOPOLOGY_LINE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600287 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600288 break;
289 case XGL_TOPOLOGY_TRIANGLE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600290 pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600291 break;
292 case XGL_TOPOLOGY_TRIANGLE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600293 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600294 break;
295 case XGL_TOPOLOGY_PATCH:
Chia-I Wube0a3d92014-09-02 13:20:59 +0800296 if (!info->tess.patchControlPoints ||
297 info->tess.patchControlPoints > 32)
298 return XGL_ERROR_BAD_PIPELINE_DATA;
299 pipeline->prim_type = GEN7_3DPRIM_PATCHLIST_1 +
300 info->tess.patchControlPoints - 1;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600301 break;
302 default:
303 return XGL_ERROR_BAD_PIPELINE_DATA;
304 }
305
Chia-I Wube0a3d92014-09-02 13:20:59 +0800306 if (info->ia.primitiveRestartEnable) {
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600307 pipeline->primitive_restart = true;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800308 pipeline->primitive_restart_index = info->ia.primitiveRestartIndex;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600309 } else {
310 pipeline->primitive_restart = false;
311 }
312
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600313 return XGL_SUCCESS;
314}
315
Chia-I Wu3efef432014-08-28 15:00:16 +0800316static XGL_RESULT pipeline_rs_state(struct intel_pipeline *pipeline,
317 const XGL_PIPELINE_RS_STATE_CREATE_INFO* rs_state)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600318{
319 pipeline->depthClipEnable = rs_state->depthClipEnable;
320 pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700321
322 if (rs_state->provokingVertex == XGL_PROVOKING_VERTEX_FIRST) {
323 pipeline->provoking_vertex_tri = 0;
324 pipeline->provoking_vertex_trifan = 1;
325 pipeline->provoking_vertex_line = 0;
326 } else {
327 pipeline->provoking_vertex_tri = 2;
328 pipeline->provoking_vertex_trifan = 2;
329 pipeline->provoking_vertex_line = 1;
330 }
331
332 switch (rs_state->fillMode) {
333 case XGL_FILL_POINTS:
334 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT |
335 GEN7_SF_DW1_BACKFACE_POINT;
336 break;
337 case XGL_FILL_WIREFRAME:
338 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME |
339 GEN7_SF_DW1_BACKFACE_WIREFRAME;
340 break;
341 case XGL_FILL_SOLID:
342 default:
343 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID |
344 GEN7_SF_DW1_BACKFACE_SOLID;
345 break;
346 }
347
348 if (rs_state->frontFace == XGL_FRONT_FACE_CCW) {
349 pipeline->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW;
350 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW;
351 }
352
353 switch (rs_state->cullMode) {
354 case XGL_CULL_NONE:
355 default:
356 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE;
357 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE;
358 break;
359 case XGL_CULL_FRONT:
360 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT;
361 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT;
362 break;
363 case XGL_CULL_BACK:
364 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK;
365 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK;
366 break;
367 case XGL_CULL_FRONT_AND_BACK:
368 pipeline->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH;
369 pipeline->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH;
370 break;
371 }
372
373 /* only GEN7+ needs cull mode in 3DSTATE_CLIP */
374 if (intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
375 pipeline->cmd_clip_cull = 0;
376
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600377 return XGL_SUCCESS;
378}
379
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600380static void pipeline_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600381{
382 struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj);
383
Chia-I Wu3f239832014-12-11 22:57:18 +0800384 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
385 intel_pipeline_shader_cleanup(&pipeline->vs);
386 }
387
388 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
389 intel_pipeline_shader_cleanup(&pipeline->tcs);
390 }
391
392 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
393 intel_pipeline_shader_cleanup(&pipeline->tes);
394 }
395
396 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
397 intel_pipeline_shader_cleanup(&pipeline->gs);
398 }
399
400 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
401 intel_pipeline_shader_cleanup(&pipeline->fs);
402 }
403
404 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
405 intel_pipeline_shader_cleanup(&pipeline->cs);
406 }
Chia-I Wued833872014-08-23 17:00:35 +0800407
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600408 intel_base_destroy(&pipeline->obj.base);
409}
410
Chia-I Wub1024732014-12-19 13:00:29 +0800411static XGL_RESULT pipeline_get_info(struct intel_base *base, int type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600412 size_t *size, void *data)
Chia-I Wub1024732014-12-19 13:00:29 +0800413{
414 struct intel_pipeline *pipeline = intel_pipeline_from_base(base);
415 XGL_RESULT ret = XGL_SUCCESS;
416
417 switch (type) {
418 case XGL_INFO_TYPE_MEMORY_REQUIREMENTS:
419 {
420 XGL_MEMORY_REQUIREMENTS *mem_req = data;
421
422 *size = sizeof(XGL_MEMORY_REQUIREMENTS);
423 if (data) {
424 mem_req->size = pipeline->scratch_size;
425 mem_req->alignment = 1024;
Jon Ashburnd8031332015-01-22 10:52:13 -0700426 mem_req->memType = XGL_MEMORY_TYPE_OTHER;
Chia-I Wub1024732014-12-19 13:00:29 +0800427 }
428 }
429 break;
430 default:
431 ret = intel_base_get_info(base, type, size, data);
432 break;
433 }
434
435 return ret;
436}
437
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800438static XGL_RESULT pipeline_validate(struct intel_pipeline *pipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +0800439{
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600440 /*
441 * Validate required elements
442 */
443 if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) {
444 // TODO: Log debug message: Vertex Shader required.
Chia-I Wu3efef432014-08-28 15:00:16 +0800445 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600446 }
447
448 /*
449 * Tessalation control and evaluation have to both have a shader defined or
450 * neither should have a shader defined.
451 */
452 if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) !=
453 ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) {
454 // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation
Chia-I Wu3efef432014-08-28 15:00:16 +0800455 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600456 }
457
458 if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) &&
459 (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG |
460 SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG |
461 SHADER_FRAGMENT_FLAG))) {
462 // TODO: Log debug message: Can only specify compute shader when doing compute
Chia-I Wu3efef432014-08-28 15:00:16 +0800463 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600464 }
465
466 /*
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600467 * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
468 * Mismatching primitive topology and tessellation fails graphics pipeline creation.
469 */
470 if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) &&
Chia-I Wube0a3d92014-09-02 13:20:59 +0800471 (pipeline->topology != XGL_TOPOLOGY_PATCH)) {
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600472 // TODO: Log debug message: Invalid topology used with tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800473 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600474 }
475
Chia-I Wube0a3d92014-09-02 13:20:59 +0800476 if ((pipeline->topology == XGL_TOPOLOGY_PATCH) &&
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600477 (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) {
478 // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800479 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600480 }
481
Chia-I Wu3efef432014-08-28 15:00:16 +0800482 return XGL_SUCCESS;
483}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600484
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800485static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
486 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800487{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800488 const struct intel_gpu *gpu = pipeline->dev->gpu;
489 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wua4d1b392014-10-10 13:57:29 +0800490 const struct intel_pipeline_shader *vs = &pipeline->vs;
491 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800492 int vs_entry_size, gs_entry_size;
493 int vs_size, gs_size;
494
Chia-I Wu509b3f22014-09-02 10:24:05 +0800495 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800496
497 vs_entry_size = ((vs->in_count >= vs->out_count) ?
498 vs->in_count : vs->out_count);
499 gs_entry_size = (gs) ? gs->out_count : 0;
500
501 /* in bytes */
502 vs_entry_size *= sizeof(float) * 4;
503 gs_entry_size *= sizeof(float) * 4;
504
Chia-I Wua4d1b392014-10-10 13:57:29 +0800505 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800506 vs_size = urb_size / 2;
507 gs_size = vs_size;
508 } else {
509 vs_size = urb_size;
510 gs_size = 0;
511 }
512
513 /* 3DSTATE_URB */
514 {
515 const uint8_t cmd_len = 3;
516 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
517 (cmd_len - 2);
518 int vs_alloc_size, gs_alloc_size;
519 int vs_entry_count, gs_entry_count;
520 uint32_t *dw;
521
522 /* in 1024-bit rows */
523 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
524 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
525
526 /* valid range is [1, 5] */
527 if (!vs_alloc_size)
528 vs_alloc_size = 1;
529 if (!gs_alloc_size)
530 gs_alloc_size = 1;
531 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
532
533 /* valid range is [24, 256], multiples of 4 */
534 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
535 if (vs_entry_count > 256)
536 vs_entry_count = 256;
537 assert(vs_entry_count >= 24);
538
539 /* valid range is [0, 256], multiples of 4 */
540 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
541 if (gs_entry_count > 256)
542 gs_entry_count = 256;
543
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600544 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800545
546 dw[0] = dw0;
547 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
548 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
549 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
550 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
551 }
552}
553
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800554static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
555 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800556{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800557 const struct intel_gpu *gpu = pipeline->dev->gpu;
558 const int urb_size = ((gpu->gt == 3) ? 512 :
559 (gpu->gt == 2) ? 256 : 128) * 1024;
Cody Northrop306ec352014-10-06 15:11:45 -0600560 const struct intel_pipeline_shader *vs = &pipeline->vs;
561 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800562 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800563 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800564 int vs_entry_size, gs_entry_size;
565 int vs_size, gs_size;
566
Chia-I Wu509b3f22014-09-02 10:24:05 +0800567 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800568
569 vs_entry_size = ((vs->in_count >= vs->out_count) ?
570 vs->in_count : vs->out_count);
571 gs_entry_size = (gs) ? gs->out_count : 0;
572
573 /* in bytes */
574 vs_entry_size *= sizeof(float) * 4;
575 gs_entry_size *= sizeof(float) * 4;
576
Chia-I Wua4d1b392014-10-10 13:57:29 +0800577 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800578 vs_size = (urb_size - urb_offset) / 2;
579 gs_size = vs_size;
580 } else {
581 vs_size = urb_size - urb_offset;
582 gs_size = 0;
583 }
584
585 /* 3DSTATE_URB_* */
586 {
587 const uint8_t cmd_len = 2;
588 int vs_alloc_size, gs_alloc_size;
589 int vs_entry_count, gs_entry_count;
590 uint32_t *dw;
591
592 /* in 512-bit rows */
593 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
594 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
595
596 if (!vs_alloc_size)
597 vs_alloc_size = 1;
598 if (!gs_alloc_size)
599 gs_alloc_size = 1;
600
601 /* avoid performance decrease due to banking */
602 if (vs_alloc_size == 5)
603 vs_alloc_size = 6;
604
605 /* in multiples of 8 */
606 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
607 assert(vs_entry_count >= 32);
608
609 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
610
Chia-I Wu509b3f22014-09-02 10:24:05 +0800611 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800612 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800613 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800614 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800615 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800616 if (vs_entry_count >= max_vs_entry_count)
617 vs_entry_count = max_vs_entry_count;
618 if (gs_entry_count >= max_gs_entry_count)
619 gs_entry_count = max_gs_entry_count;
620 } else {
621 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800622 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800623 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800624 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800625 if (vs_entry_count >= max_vs_entry_count)
626 vs_entry_count = max_vs_entry_count;
627 if (gs_entry_count >= max_gs_entry_count)
628 gs_entry_count = max_gs_entry_count;
629 }
630
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600631 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800632 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
633 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
634 (vs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
635 vs_entry_count;
636
637 dw += 2;
638 if (gs_size)
639 urb_offset += vs_size;
640 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
641 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
642 (gs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
643 gs_entry_count;
644
645 dw += 2;
646 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
647 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
648
649 dw += 2;
650 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
651 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
652 }
653}
654
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800655static void pipeline_build_push_const_alloc_gen7(struct intel_pipeline *pipeline,
656 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600657{
658 const uint8_t cmd_len = 2;
659 uint32_t offset = 0;
660 uint32_t size = 8192;
661 uint32_t *dw;
662 int end;
663
Chia-I Wu509b3f22014-09-02 10:24:05 +0800664 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600665
666 /*
667 * From the Ivy Bridge PRM, volume 2 part 1, page 68:
668 *
669 * "(A table that says the maximum size of each constant buffer is
670 * 16KB")
671 *
672 * From the Ivy Bridge PRM, volume 2 part 1, page 115:
673 *
674 * "The sum of the Constant Buffer Offset and the Constant Buffer Size
675 * may not exceed the maximum value of the Constant Buffer Size."
676 *
677 * Thus, the valid range of buffer end is [0KB, 16KB].
678 */
679 end = (offset + size) / 1024;
680 if (end > 16) {
681 assert(!"invalid constant buffer end");
682 end = 16;
683 }
684
685 /* the valid range of buffer offset is [0KB, 15KB] */
686 offset = (offset + 1023) / 1024;
687 if (offset > 15) {
688 assert(!"invalid constant buffer offset");
689 offset = 15;
690 }
691
692 if (offset > end) {
693 assert(!size);
694 offset = end;
695 }
696
697 /* the valid range of buffer size is [0KB, 15KB] */
698 size = end - offset;
699 if (size > 15) {
700 assert(!"invalid constant buffer size");
701 size = 15;
702 }
703
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800704 dw = pipeline_cmd_ptr(pipeline, cmd_len * 5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600705 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
706 dw[1] = offset << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
707 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
708
709 dw += 2;
710 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
711 dw[1] = size << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
712 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
713
714 dw += 2;
715 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
716 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
717 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
718
719 dw += 2;
720 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
721 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
722 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
723
724 dw += 2;
725 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
726 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
727 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu8370b402014-08-29 12:28:37 +0800728
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600729 // gen7_wa_pipe_control_cs_stall(p, true, true);
730 // looks equivalent to: gen6_wa_wm_multisample_flush - this does more
731 // than the documentation seems to imply
732}
733
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800734static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
735 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800736{
Cody Northrop306ec352014-10-06 15:11:45 -0600737 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu1d125092014-10-08 08:49:38 +0800738 uint8_t cmd_len;
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800739 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600740 uint32_t i;
Chia-I Wu1d125092014-10-08 08:49:38 +0800741 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800742
Chia-I Wu509b3f22014-09-02 10:24:05 +0800743 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800744
GregF8cd81832014-11-18 18:01:01 -0700745 cmd_len = 1 + 2 * u_popcountll(vs->inputs_read);
Chia-I Wu1d125092014-10-08 08:49:38 +0800746 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
747 cmd_len += 2;
748
749 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800750 return;
751
752 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800753
754 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
755 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800756 dw++;
757
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800758 /* VERTEX_ELEMENT_STATE */
Chia-I Wu1d125092014-10-08 08:49:38 +0800759 for (i = 0; i < info->vi.attributeCount; i++) {
GregF8cd81832014-11-18 18:01:01 -0700760 if (!(vs->inputs_read & (1L << i)))
GregF2dc40212014-10-31 17:31:47 -0600761 continue;
Chia-I Wu1d125092014-10-08 08:49:38 +0800762 const XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION *attr =
763 &info->vi.pVertexAttributeDescriptions[i];
764 const int format =
765 intel_format_translate_color(pipeline->dev->gpu, attr->format);
766
767 comps[0] = GEN6_VFCOMP_STORE_0;
768 comps[1] = GEN6_VFCOMP_STORE_0;
769 comps[2] = GEN6_VFCOMP_STORE_0;
770 comps[3] = icd_format_is_int(attr->format) ?
771 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
772
773 switch (icd_format_get_channel_count(attr->format)) {
774 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
775 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
776 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
777 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
778 default:
779 break;
780 }
781
782 assert(attr->offsetInBytes <= 2047);
783
784 dw[0] = attr->binding << GEN6_VE_STATE_DW0_VB_INDEX__SHIFT |
785 GEN6_VE_STATE_DW0_VALID |
786 format << GEN6_VE_STATE_DW0_FORMAT__SHIFT |
787 attr->offsetInBytes;
788
789 dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT |
790 comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT |
791 comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT |
792 comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT;
793
794 dw += 2;
795 }
GregF932fcf52014-10-29 17:02:11 -0600796
797 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
798 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
799 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
800 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
801 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
802 comps[2] = GEN6_VFCOMP_NOSTORE;
803 comps[3] = GEN6_VFCOMP_NOSTORE;
804
805 dw[0] = GEN6_VE_STATE_DW0_VALID;
806 dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT |
807 comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT |
808 comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT |
809 comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT;
810
811 dw += 2;
812 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800813}
814
GregF8cd81832014-11-18 18:01:01 -0700815static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline)
816{
817 const struct intel_pipeline_shader *fs = &pipeline->fs;
818 const struct intel_pipeline_shader *vs = &pipeline->vs;
819 uint8_t cmd_len;
820 uint32_t *body;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600821 uint32_t attr_skip, attr_count;
822 uint32_t vue_offset, vue_len;
823 uint32_t i;
GregF8cd81832014-11-18 18:01:01 -0700824
825 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
826
827 cmd_len = 14;
828
Chia-I Wuf85def42015-01-29 00:34:24 +0800829 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7))
830 body = pipeline_cmd_ptr(pipeline, cmd_len);
831 else
832 body = pipeline->cmd_3dstate_sbe;
GregF8cd81832014-11-18 18:01:01 -0700833
834 /* VS outputs VUE header and position additionally */
835 assert(vs->out_count >= fs->in_count + 2);
836 assert(!fs->reads_user_clip || vs->enable_user_clip);
837 attr_skip = vs->outputs_offset;
838 if (vs->enable_user_clip != fs->reads_user_clip) {
839 attr_skip += 2;
840 }
841 assert(vs->out_count >= attr_skip);
842 attr_count = vs->out_count - attr_skip;
843
844 // LUNARG TODO: We currently are only handling 16 attrs;
845 // ultimately, we need to handle 32
846 assert(fs->in_count <= 16);
847 assert(attr_count <= 16);
848
849 vue_offset = attr_skip / 2;
850 vue_len = (attr_count + 1) / 2;
851 if (!vue_len)
852 vue_len = 1;
853
854 body[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
855 (cmd_len - 2);
856
857 // LUNARG TODO: If the attrs needed by the FS are exactly
858 // what is written by the VS, we don't need to enable
859 // swizzling, improving performance. Even if we swizzle,
860 // we can improve performance by reducing vue_len to
861 // just include the values needed by the FS:
862 // vue_len = ceiling((max_vs_out + 1)/2)
863
864 body[1] = GEN7_SBE_DW1_ATTR_SWIZZLE_ENABLE |
865 fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
866 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
867 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
868
869 uint16_t vs_slot[fs->in_count];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600870 int32_t fs_in = 0;
871 int32_t vs_out = - (vue_offset * 2 - vs->outputs_offset);
GregF8cd81832014-11-18 18:01:01 -0700872 for (i=0; i < 64; i++) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700873 bool vsWrites = vs->outputs_written & (1L << i);
874 bool fsReads = fs->inputs_read & (1L << i);
875
876 if (fsReads) {
GregF8cd81832014-11-18 18:01:01 -0700877 assert(vs_out >= 0);
878 assert(fs_in < fs->in_count);
879 vs_slot[fs_in] = vs_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700880
881 if (!vsWrites) {
882 // If the vertex shader did not write this input, we cannot
883 // program the SBE to read it. Our choices are to allow it to
884 // read junk from a GRF, or get zero. We're choosing zero.
885 if (i >= fs->generic_input_start) {
886 vs_slot[fs_in] = GEN7_SBE_ATTR_CONST_0000 |
887 GEN7_SBE_ATTR_OVERRIDE_X |
888 GEN7_SBE_ATTR_OVERRIDE_Y |
889 GEN7_SBE_ATTR_OVERRIDE_Z |
890 GEN7_SBE_ATTR_OVERRIDE_W;
891 }
892 }
893
GregF8cd81832014-11-18 18:01:01 -0700894 fs_in += 1;
895 }
Cody Northropd75c13e2015-01-02 14:07:20 -0700896 if (vsWrites) {
GregF8cd81832014-11-18 18:01:01 -0700897 vs_out += 1;
898 }
899 }
900
901 for (i = 0; i < 8; i++) {
902 uint16_t hi, lo;
903
904 /* no attr swizzles */
905 if (i * 2 + 1 < fs->in_count) {
906 lo = vs_slot[i * 2];
907 hi = vs_slot[i * 2 + 1];
908 } else if (i * 2 < fs->in_count) {
909 lo = vs_slot[i * 2];
910 hi = 0;
911 } else {
912 hi = 0;
913 lo = 0;
914 }
915
916 body[2 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
917 }
918
919 body[10] = 0; /* point sprite enables */
920 body[11] = 0; /* constant interpolation enables */
921 body[12] = 0; /* WrapShortest enables */
922 body[13] = 0;
923}
924
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800925static void pipeline_build_gs(struct intel_pipeline *pipeline,
926 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600927{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600928 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600929}
930
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800931static void pipeline_build_hs(struct intel_pipeline *pipeline,
932 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600933{
934 const uint8_t cmd_len = 7;
935 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
936 uint32_t *dw;
937
Chia-I Wu509b3f22014-09-02 10:24:05 +0800938 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600939
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800940 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600941 dw[0] = dw0;
942 dw[1] = 0;
943 dw[2] = 0;
944 dw[3] = 0;
945 dw[4] = 0;
946 dw[5] = 0;
947 dw[6] = 0;
948}
949
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800950static void pipeline_build_te(struct intel_pipeline *pipeline,
951 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600952{
953 const uint8_t cmd_len = 4;
954 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
955 uint32_t *dw;
956
Chia-I Wu509b3f22014-09-02 10:24:05 +0800957 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600958
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800959 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600960 dw[0] = dw0;
961 dw[1] = 0;
962 dw[2] = 0;
963 dw[3] = 0;
964}
965
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800966static void pipeline_build_ds(struct intel_pipeline *pipeline,
967 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600968{
969 const uint8_t cmd_len = 6;
970 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
971 uint32_t *dw;
972
Chia-I Wu509b3f22014-09-02 10:24:05 +0800973 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600974
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800975 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600976 dw[0] = dw0;
977 dw[1] = 0;
978 dw[2] = 0;
979 dw[3] = 0;
980 dw[4] = 0;
981 dw[5] = 0;
982}
983
Tony Barbourfa6cac72015-01-16 14:27:35 -0700984static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
985 const struct intel_pipeline_create_info *info)
986{
987 pipeline->cmd_depth_stencil = 0;
988
989 if (info->db.stencilTestEnable) {
990 pipeline->cmd_depth_stencil = 1 << 31 |
991 translate_compare_func(info->db.front.stencilFunc) << 28 |
992 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
993 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
994 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
995 1 << 15 |
996 translate_compare_func(info->db.back.stencilFunc) << 12 |
997 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
998 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
999 translate_stencil_op(info->db.back.stencilPassOp) << 3;
1000 }
1001
1002 pipeline->stencilTestEnable = info->db.stencilTestEnable;
1003
1004 /*
1005 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
1006 *
1007 * "Enabling the Depth Test function without defining a Depth Buffer is
1008 * UNDEFINED."
1009 *
1010 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
1011 *
1012 * "A Depth Buffer must be defined before enabling writes to it, or
1013 * operation is UNDEFINED."
1014 *
1015 * TODO We do not check these yet.
1016 */
1017 if (info->db.depthTestEnable) {
1018 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
1019 translate_compare_func(info->db.depthFunc) << 27;
1020 } else {
1021 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
1022 }
1023
1024 if (info->db.depthWriteEnable)
1025 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1026}
1027
1028static void pipeline_init_sample_pattern(struct intel_pipeline *pipeline,
1029 uint8_t *samples)
1030{
1031 struct sample {
1032 int x, y;
1033 };
1034 static const struct sample default_pattern_2x[2] = {
1035 { -4, -4 },
1036 { 4, 4 },
1037 };
1038 static const struct sample default_pattern_4x[4] = {
1039 { -2, -6 },
1040 { 6, -2 },
1041 { -6, 2 },
1042 { 2, 6 },
1043 };
1044 static const struct sample default_pattern_8x[8] = {
1045 { 1, -3 },
1046 { -1, 3 },
1047 { 5, 1 },
1048 { -3, -5 },
1049 { -5, 5 },
1050 { -7, -1 },
1051 { 3, 7 },
1052 { 7, -7 },
1053 };
1054
1055 const struct sample *pattern;
1056 int i;
1057
1058 switch (pipeline->sample_count) {
1059 case 2:
1060 pattern = default_pattern_2x;
1061 break;
1062 case 4:
1063 pattern = default_pattern_4x;
1064 break;
1065 case 8:
1066 pattern = default_pattern_8x;
1067 break;
1068 default:
1069 memset(samples, 0, pipeline->sample_count);
1070 return;
1071 break;
1072 }
1073
1074 for (i = 0; i < pipeline->sample_count; i++)
1075 samples[i] = (pattern[i].x + 8) << 4 | (pattern[i].y + 8);
1076}
1077
1078static void pipeline_build_msaa(struct intel_pipeline *pipeline,
1079 const struct intel_pipeline_create_info *info)
1080{
1081 uint32_t cmd, cmd_len;
1082 uint32_t *dw;
1083
1084 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1085
1086
1087 pipeline->sample_count = (info->ms.samples <= 1)?1:info->ms.samples;
1088
1089 /* 3DSTATE_MULTISAMPLE */
1090 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE);
1091 cmd_len = (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) ? 4 : 3;
1092 dw = pipeline_cmd_ptr(pipeline, cmd_len + 2);
1093 dw[0] = cmd | (cmd_len - 2);
1094 if (pipeline->sample_count <= 1)
1095 dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
1096 else if (pipeline->sample_count <= 4 || intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
1097 dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
1098 else
1099 dw[1] = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
1100
1101 pipeline_init_sample_pattern(pipeline, (uint8_t *) &dw[2]);
1102
1103 dw += cmd_len;
1104
1105 /* 3DSTATE_SAMPLE_MASK */
1106 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
1107 cmd_len = 2;
1108
1109 dw[0] = cmd | (cmd_len - 2);
1110 dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1);
1111 pipeline->cmd_sample_mask = dw[1];
1112}
1113
1114static void pipeline_build_cb(struct intel_pipeline *pipeline,
1115 const struct intel_pipeline_create_info *info)
1116{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001117 uint32_t i;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001118
1119 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1120 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
1121 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
1122
1123 uint32_t *dw = pipeline->cmd_cb;
1124
1125 for (i = 0; i < info->cb.attachmentCount; i++) {
1126 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &info->cb.pAttachments[i];
1127 uint32_t dw0, dw1;
1128
1129
1130 dw0 = 0;
1131 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
1132 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
1133 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
1134
1135 if (att->blendEnable) {
1136 dw0 = 1 << 31 |
1137 translate_blend_func(att->blendFuncAlpha) << 26 |
1138 translate_blend(att->srcBlendAlpha) << 20 |
1139 translate_blend(att->destBlendAlpha) << 15 |
1140 translate_blend_func(att->blendFuncColor) << 11 |
1141 translate_blend(att->srcBlendColor) << 5 |
1142 translate_blend(att->destBlendColor);
1143
1144 if (att->blendFuncAlpha != att->blendFuncColor ||
1145 att->srcBlendAlpha != att->srcBlendColor ||
1146 att->destBlendAlpha != att->destBlendColor)
1147 dw0 |= 1 << 30;
1148 }
1149
1150 if (info->cb.logicOp != XGL_LOGIC_OP_COPY) {
1151 int logicop;
1152
1153 switch (info->cb.logicOp) {
1154 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1155 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1156 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1157 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1158 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1159 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1160 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1161 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1162 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1163 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1164 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1165 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1166 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1167 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1168 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1169 default:
1170 assert(!"unknown logic op");
1171 logicop = GEN6_LOGICOP_CLEAR;
1172 break;
1173 }
1174
1175 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1176 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1177 }
1178
1179 if (!(att->channelWriteMask & 0x1))
1180 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1181 if (!(att->channelWriteMask & 0x2))
1182 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1183 if (!(att->channelWriteMask & 0x4))
1184 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1185 if (!(att->channelWriteMask & 0x8))
1186 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1187
1188 dw[2 * i] = dw0;
1189 dw[2 * i + 1] = dw1;
1190 }
1191
1192 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1193 {
1194 dw[2 * i] = 0;
1195 dw[2 * i + 1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
1196 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
1197 GEN6_BLEND_DW1_POST_BLEND_CLAMP |
1198 GEN6_BLEND_DW1_WRITE_DISABLE_R |
1199 GEN6_BLEND_DW1_WRITE_DISABLE_G |
1200 GEN6_BLEND_DW1_WRITE_DISABLE_B |
1201 GEN6_BLEND_DW1_WRITE_DISABLE_A;
1202 }
1203
1204}
1205
1206
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001207static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline,
1208 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001209{
1210 XGL_RESULT ret;
1211
Chia-I Wu98824592014-09-02 09:42:46 +08001212 ret = pipeline_build_shaders(pipeline, info);
1213 if (ret != XGL_SUCCESS)
1214 return ret;
1215
Chia-I Wu1d125092014-10-08 08:49:38 +08001216 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
1217 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb))
1218 return XGL_ERROR_BAD_PIPELINE_DATA;
1219
1220 pipeline->vb_count = info->vi.bindingCount;
1221 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1222 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1223
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001224 pipeline_build_vertex_elements(pipeline, info);
GregF8cd81832014-11-18 18:01:01 -07001225 pipeline_build_fragment_SBE(pipeline);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001226 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001227 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001228
Chia-I Wu509b3f22014-09-02 10:24:05 +08001229 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001230 pipeline_build_urb_alloc_gen7(pipeline, info);
1231 pipeline_build_push_const_alloc_gen7(pipeline, info);
1232 pipeline_build_gs(pipeline, info);
1233 pipeline_build_hs(pipeline, info);
1234 pipeline_build_te(pipeline, info);
1235 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001236
1237 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1238 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1239 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1240 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1241 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001242 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001243 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001244
1245 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1246 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001247 }
1248
Chia-I Wube0a3d92014-09-02 13:20:59 +08001249 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001250
1251 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001252 ret = pipeline_rs_state(pipeline, &info->rs);
Chia-I Wu3efef432014-08-28 15:00:16 +08001253
Chia-I Wu3efef432014-08-28 15:00:16 +08001254 if (ret == XGL_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001255 pipeline->db_format = info->db.format;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001256 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001257 pipeline->cb_state = info->cb;
1258 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001259 }
1260
Tony Barbourfa6cac72015-01-16 14:27:35 -07001261 pipeline->scissor_enable = info->vp.scissorEnable;
1262
Chia-I Wu3efef432014-08-28 15:00:16 +08001263 return ret;
1264}
1265
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001266struct intel_pipeline_create_info_header {
1267 XGL_STRUCTURE_TYPE struct_type;
1268 const struct intel_pipeline_create_info_header *next;
1269};
1270
1271static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001272 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +08001273{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001274 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001275
Tony Barbourfa6cac72015-01-16 14:27:35 -07001276
1277 /*
1278 * Do we need to set safe defaults in case the app doesn't provide all of
1279 * the necessary create infos?
1280 */
1281 info->ms.samples = 1;
1282 info->ms.sampleMask = 1;
1283
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001284 while (header) {
1285 const void *src = (const void *) header;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001286 size_t size;
Chia-I Wu3efef432014-08-28 15:00:16 +08001287 void *dst;
1288
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001289 switch (header->struct_type) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001290 case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001291 size = sizeof(info->graphics);
1292 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +08001293 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001294 case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
1295 size = sizeof(info->vi);
1296 dst = &info->vi;
1297 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001298 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001299 size = sizeof(info->ia);
1300 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +08001301 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001302 case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001303 size = sizeof(info->db);
1304 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +08001305 break;
1306 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001307 size = sizeof(info->cb);
1308 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +08001309 break;
1310 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001311 size = sizeof(info->rs);
1312 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001313 break;
1314 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001315 size = sizeof(info->tess);
1316 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001317 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001318 case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
1319 size = sizeof(info->ms);
1320 dst = &info->ms;
1321 break;
1322 case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
1323 size = sizeof(info->vp);
1324 dst = &info->vp;
1325 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001326 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
1327 {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001328 const XGL_PIPELINE_SHADER *shader =
1329 (const XGL_PIPELINE_SHADER *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +08001330
1331 src = (const void *) shader;
1332 size = sizeof(*shader);
1333
1334 switch (shader->stage) {
1335 case XGL_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001336 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001337 break;
1338 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001339 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001340 break;
1341 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001342 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +08001343 break;
1344 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001345 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001346 break;
1347 case XGL_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001348 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001349 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001350 default:
1351 return XGL_ERROR_BAD_PIPELINE_DATA;
1352 break;
1353 }
1354 }
1355 break;
1356 case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001357 size = sizeof(info->compute);
1358 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +08001359 break;
1360 default:
1361 return XGL_ERROR_BAD_PIPELINE_DATA;
1362 break;
1363 }
1364
1365 memcpy(dst, src, size);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001366 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +08001367 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001368
1369 return XGL_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001370}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001371
Chia-I Wu3efef432014-08-28 15:00:16 +08001372static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001373 const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +08001374 struct intel_pipeline **pipeline_ret)
1375{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001376 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001377 struct intel_pipeline *pipeline;
1378 XGL_RESULT ret;
1379
Chia-I Wu509b3f22014-09-02 10:24:05 +08001380 ret = pipeline_create_info_init(&info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001381 (const struct intel_pipeline_create_info_header *) info_);
Chia-I Wu3efef432014-08-28 15:00:16 +08001382 if (ret != XGL_SUCCESS)
1383 return ret;
1384
1385 pipeline = (struct intel_pipeline *)
1386 intel_base_create(dev, sizeof(*pipeline), dev->base.dbg,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001387 XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001388 if (!pipeline)
1389 return XGL_ERROR_OUT_OF_MEMORY;
1390
1391 pipeline->dev = dev;
Chia-I Wub1024732014-12-19 13:00:29 +08001392 pipeline->obj.base.get_info = pipeline_get_info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001393 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001394
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001395 ret = pipeline_build_all(pipeline, &info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001396 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001397 ret = pipeline_validate(pipeline);
Chia-I Wu3efef432014-08-28 15:00:16 +08001398 if (ret != XGL_SUCCESS) {
1399 pipeline_destroy(&pipeline->obj);
1400 return ret;
1401 }
1402
1403 *pipeline_ret = pipeline;
1404
1405 return XGL_SUCCESS;
1406}
1407
Chia-I Wu96177272015-01-03 15:27:41 +08001408ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipeline(
Chia-I Wu3efef432014-08-28 15:00:16 +08001409 XGL_DEVICE device,
1410 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1411 XGL_PIPELINE* pPipeline)
1412{
1413 struct intel_dev *dev = intel_dev(device);
1414
1415 return graphics_pipeline_create(dev, pCreateInfo,
1416 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001417}
1418
Chia-I Wu96177272015-01-03 15:27:41 +08001419ICD_EXPORT XGL_RESULT XGLAPI xglCreateComputePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001420 XGL_DEVICE device,
1421 const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo,
1422 XGL_PIPELINE* pPipeline)
1423{
1424 return XGL_ERROR_UNAVAILABLE;
1425}
1426
Chia-I Wu96177272015-01-03 15:27:41 +08001427ICD_EXPORT XGL_RESULT XGLAPI xglStorePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001428 XGL_PIPELINE pipeline,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001429 size_t* pDataSize,
1430 void* pData)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001431{
1432 return XGL_ERROR_UNAVAILABLE;
1433}
1434
Chia-I Wu96177272015-01-03 15:27:41 +08001435ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001436 XGL_DEVICE device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001437 size_t dataSize,
1438 const void* pData,
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001439 XGL_PIPELINE* pPipeline)
1440{
1441 return XGL_ERROR_UNAVAILABLE;
1442}
1443
Chia-I Wu96177272015-01-03 15:27:41 +08001444ICD_EXPORT XGL_RESULT XGLAPI xglCreatePipelineDelta(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001445 XGL_DEVICE device,
1446 XGL_PIPELINE p1,
1447 XGL_PIPELINE p2,
1448 XGL_PIPELINE_DELTA* delta)
1449{
1450 return XGL_ERROR_UNAVAILABLE;
1451}