blob: 7e1bbce079d09aae6cfc868db074970af8977e0a [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,
412 XGL_SIZE *size, XGL_VOID *data)
413{
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;
Chia-I Wub1024732014-12-19 13:00:29 +0800426 }
427 }
428 break;
429 default:
430 ret = intel_base_get_info(base, type, size, data);
431 break;
432 }
433
434 return ret;
435}
436
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800437static XGL_RESULT pipeline_validate(struct intel_pipeline *pipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +0800438{
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600439 /*
440 * Validate required elements
441 */
442 if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) {
443 // TODO: Log debug message: Vertex Shader required.
Chia-I Wu3efef432014-08-28 15:00:16 +0800444 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600445 }
446
447 /*
448 * Tessalation control and evaluation have to both have a shader defined or
449 * neither should have a shader defined.
450 */
451 if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) !=
452 ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) {
453 // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation
Chia-I Wu3efef432014-08-28 15:00:16 +0800454 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600455 }
456
457 if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) &&
458 (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG |
459 SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG |
460 SHADER_FRAGMENT_FLAG))) {
461 // TODO: Log debug message: Can only specify compute shader when doing compute
Chia-I Wu3efef432014-08-28 15:00:16 +0800462 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600463 }
464
465 /*
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600466 * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
467 * Mismatching primitive topology and tessellation fails graphics pipeline creation.
468 */
469 if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) &&
Chia-I Wube0a3d92014-09-02 13:20:59 +0800470 (pipeline->topology != XGL_TOPOLOGY_PATCH)) {
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600471 // TODO: Log debug message: Invalid topology used with tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800472 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600473 }
474
Chia-I Wube0a3d92014-09-02 13:20:59 +0800475 if ((pipeline->topology == XGL_TOPOLOGY_PATCH) &&
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600476 (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) {
477 // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800478 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600479 }
480
Chia-I Wu3efef432014-08-28 15:00:16 +0800481 return XGL_SUCCESS;
482}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600483
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800484static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
485 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800486{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800487 const struct intel_gpu *gpu = pipeline->dev->gpu;
488 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wua4d1b392014-10-10 13:57:29 +0800489 const struct intel_pipeline_shader *vs = &pipeline->vs;
490 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800491 int vs_entry_size, gs_entry_size;
492 int vs_size, gs_size;
493
Chia-I Wu509b3f22014-09-02 10:24:05 +0800494 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800495
496 vs_entry_size = ((vs->in_count >= vs->out_count) ?
497 vs->in_count : vs->out_count);
498 gs_entry_size = (gs) ? gs->out_count : 0;
499
500 /* in bytes */
501 vs_entry_size *= sizeof(float) * 4;
502 gs_entry_size *= sizeof(float) * 4;
503
Chia-I Wua4d1b392014-10-10 13:57:29 +0800504 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800505 vs_size = urb_size / 2;
506 gs_size = vs_size;
507 } else {
508 vs_size = urb_size;
509 gs_size = 0;
510 }
511
512 /* 3DSTATE_URB */
513 {
514 const uint8_t cmd_len = 3;
515 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
516 (cmd_len - 2);
517 int vs_alloc_size, gs_alloc_size;
518 int vs_entry_count, gs_entry_count;
519 uint32_t *dw;
520
521 /* in 1024-bit rows */
522 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
523 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
524
525 /* valid range is [1, 5] */
526 if (!vs_alloc_size)
527 vs_alloc_size = 1;
528 if (!gs_alloc_size)
529 gs_alloc_size = 1;
530 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
531
532 /* valid range is [24, 256], multiples of 4 */
533 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
534 if (vs_entry_count > 256)
535 vs_entry_count = 256;
536 assert(vs_entry_count >= 24);
537
538 /* valid range is [0, 256], multiples of 4 */
539 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
540 if (gs_entry_count > 256)
541 gs_entry_count = 256;
542
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600543 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800544
545 dw[0] = dw0;
546 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
547 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
548 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
549 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
550 }
551}
552
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800553static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
554 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800555{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800556 const struct intel_gpu *gpu = pipeline->dev->gpu;
557 const int urb_size = ((gpu->gt == 3) ? 512 :
558 (gpu->gt == 2) ? 256 : 128) * 1024;
Cody Northrop306ec352014-10-06 15:11:45 -0600559 const struct intel_pipeline_shader *vs = &pipeline->vs;
560 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800561 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800562 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800563 int vs_entry_size, gs_entry_size;
564 int vs_size, gs_size;
565
Chia-I Wu509b3f22014-09-02 10:24:05 +0800566 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800567
568 vs_entry_size = ((vs->in_count >= vs->out_count) ?
569 vs->in_count : vs->out_count);
570 gs_entry_size = (gs) ? gs->out_count : 0;
571
572 /* in bytes */
573 vs_entry_size *= sizeof(float) * 4;
574 gs_entry_size *= sizeof(float) * 4;
575
Chia-I Wua4d1b392014-10-10 13:57:29 +0800576 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800577 vs_size = (urb_size - urb_offset) / 2;
578 gs_size = vs_size;
579 } else {
580 vs_size = urb_size - urb_offset;
581 gs_size = 0;
582 }
583
584 /* 3DSTATE_URB_* */
585 {
586 const uint8_t cmd_len = 2;
587 int vs_alloc_size, gs_alloc_size;
588 int vs_entry_count, gs_entry_count;
589 uint32_t *dw;
590
591 /* in 512-bit rows */
592 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
593 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
594
595 if (!vs_alloc_size)
596 vs_alloc_size = 1;
597 if (!gs_alloc_size)
598 gs_alloc_size = 1;
599
600 /* avoid performance decrease due to banking */
601 if (vs_alloc_size == 5)
602 vs_alloc_size = 6;
603
604 /* in multiples of 8 */
605 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
606 assert(vs_entry_count >= 32);
607
608 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
609
Chia-I Wu509b3f22014-09-02 10:24:05 +0800610 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800611 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800612 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800613 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800614 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800615 if (vs_entry_count >= max_vs_entry_count)
616 vs_entry_count = max_vs_entry_count;
617 if (gs_entry_count >= max_gs_entry_count)
618 gs_entry_count = max_gs_entry_count;
619 } else {
620 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800621 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800622 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800623 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800624 if (vs_entry_count >= max_vs_entry_count)
625 vs_entry_count = max_vs_entry_count;
626 if (gs_entry_count >= max_gs_entry_count)
627 gs_entry_count = max_gs_entry_count;
628 }
629
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600630 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800631 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
632 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
633 (vs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
634 vs_entry_count;
635
636 dw += 2;
637 if (gs_size)
638 urb_offset += vs_size;
639 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
640 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
641 (gs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
642 gs_entry_count;
643
644 dw += 2;
645 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
646 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
647
648 dw += 2;
649 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
650 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
651 }
652}
653
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800654static void pipeline_build_push_const_alloc_gen7(struct intel_pipeline *pipeline,
655 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600656{
657 const uint8_t cmd_len = 2;
658 uint32_t offset = 0;
659 uint32_t size = 8192;
660 uint32_t *dw;
661 int end;
662
Chia-I Wu509b3f22014-09-02 10:24:05 +0800663 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600664
665 /*
666 * From the Ivy Bridge PRM, volume 2 part 1, page 68:
667 *
668 * "(A table that says the maximum size of each constant buffer is
669 * 16KB")
670 *
671 * From the Ivy Bridge PRM, volume 2 part 1, page 115:
672 *
673 * "The sum of the Constant Buffer Offset and the Constant Buffer Size
674 * may not exceed the maximum value of the Constant Buffer Size."
675 *
676 * Thus, the valid range of buffer end is [0KB, 16KB].
677 */
678 end = (offset + size) / 1024;
679 if (end > 16) {
680 assert(!"invalid constant buffer end");
681 end = 16;
682 }
683
684 /* the valid range of buffer offset is [0KB, 15KB] */
685 offset = (offset + 1023) / 1024;
686 if (offset > 15) {
687 assert(!"invalid constant buffer offset");
688 offset = 15;
689 }
690
691 if (offset > end) {
692 assert(!size);
693 offset = end;
694 }
695
696 /* the valid range of buffer size is [0KB, 15KB] */
697 size = end - offset;
698 if (size > 15) {
699 assert(!"invalid constant buffer size");
700 size = 15;
701 }
702
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800703 dw = pipeline_cmd_ptr(pipeline, cmd_len * 5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600704 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
705 dw[1] = offset << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
706 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
707
708 dw += 2;
709 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
710 dw[1] = size << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
711 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
712
713 dw += 2;
714 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
715 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
716 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
717
718 dw += 2;
719 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
720 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
721 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
722
723 dw += 2;
724 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
725 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
726 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu8370b402014-08-29 12:28:37 +0800727
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600728 // gen7_wa_pipe_control_cs_stall(p, true, true);
729 // looks equivalent to: gen6_wa_wm_multisample_flush - this does more
730 // than the documentation seems to imply
731}
732
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800733static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
734 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800735{
Cody Northrop306ec352014-10-06 15:11:45 -0600736 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu1d125092014-10-08 08:49:38 +0800737 uint8_t cmd_len;
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800738 uint32_t *dw;
Chia-I Wu1d125092014-10-08 08:49:38 +0800739 XGL_UINT i;
740 int comps[4];
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800741
Chia-I Wu509b3f22014-09-02 10:24:05 +0800742 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800743
GregF8cd81832014-11-18 18:01:01 -0700744 cmd_len = 1 + 2 * u_popcountll(vs->inputs_read);
Chia-I Wu1d125092014-10-08 08:49:38 +0800745 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID))
746 cmd_len += 2;
747
748 if (cmd_len == 1)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800749 return;
750
751 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wu1d125092014-10-08 08:49:38 +0800752
753 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
754 (cmd_len - 2);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800755 dw++;
756
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800757 /* VERTEX_ELEMENT_STATE */
Chia-I Wu1d125092014-10-08 08:49:38 +0800758 for (i = 0; i < info->vi.attributeCount; i++) {
GregF8cd81832014-11-18 18:01:01 -0700759 if (!(vs->inputs_read & (1L << i)))
GregF2dc40212014-10-31 17:31:47 -0600760 continue;
Chia-I Wu1d125092014-10-08 08:49:38 +0800761 const XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION *attr =
762 &info->vi.pVertexAttributeDescriptions[i];
763 const int format =
764 intel_format_translate_color(pipeline->dev->gpu, attr->format);
765
766 comps[0] = GEN6_VFCOMP_STORE_0;
767 comps[1] = GEN6_VFCOMP_STORE_0;
768 comps[2] = GEN6_VFCOMP_STORE_0;
769 comps[3] = icd_format_is_int(attr->format) ?
770 GEN6_VFCOMP_STORE_1_INT : GEN6_VFCOMP_STORE_1_FP;
771
772 switch (icd_format_get_channel_count(attr->format)) {
773 case 4: comps[3] = GEN6_VFCOMP_STORE_SRC; /* fall through */
774 case 3: comps[2] = GEN6_VFCOMP_STORE_SRC; /* fall through */
775 case 2: comps[1] = GEN6_VFCOMP_STORE_SRC; /* fall through */
776 case 1: comps[0] = GEN6_VFCOMP_STORE_SRC; break;
777 default:
778 break;
779 }
780
781 assert(attr->offsetInBytes <= 2047);
782
783 dw[0] = attr->binding << GEN6_VE_STATE_DW0_VB_INDEX__SHIFT |
784 GEN6_VE_STATE_DW0_VALID |
785 format << GEN6_VE_STATE_DW0_FORMAT__SHIFT |
786 attr->offsetInBytes;
787
788 dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT |
789 comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT |
790 comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT |
791 comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT;
792
793 dw += 2;
794 }
GregF932fcf52014-10-29 17:02:11 -0600795
796 if (vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)) {
797 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
798 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
799 comps[1] = (vs->uses & INTEL_SHADER_USE_IID) ?
800 GEN6_VFCOMP_STORE_IID : GEN6_VFCOMP_NOSTORE;
801 comps[2] = GEN6_VFCOMP_NOSTORE;
802 comps[3] = GEN6_VFCOMP_NOSTORE;
803
804 dw[0] = GEN6_VE_STATE_DW0_VALID;
805 dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT |
806 comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT |
807 comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT |
808 comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT;
809
810 dw += 2;
811 }
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800812}
813
GregF8cd81832014-11-18 18:01:01 -0700814static void pipeline_build_fragment_SBE(struct intel_pipeline *pipeline)
815{
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;
820 XGL_UINT attr_skip, attr_count;
821 XGL_UINT vue_offset, vue_len;
822 XGL_UINT i;
823
824 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
825
826 cmd_len = 14;
827
828 body = pipeline_cmd_ptr(pipeline, cmd_len);
829 pipeline->cmd_sbe_body_offset = body - pipeline->cmds + 1;
830
831 /* VS outputs VUE header and position additionally */
832 assert(vs->out_count >= fs->in_count + 2);
833 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
866 uint16_t vs_slot[fs->in_count];
867 XGL_INT fs_in = 0;
868 XGL_INT vs_out = - (vue_offset * 2 - vs->outputs_offset);
869 for (i=0; i < 64; i++) {
Cody Northropd75c13e2015-01-02 14:07:20 -0700870 bool vsWrites = vs->outputs_written & (1L << i);
871 bool fsReads = fs->inputs_read & (1L << i);
872
873 if (fsReads) {
GregF8cd81832014-11-18 18:01:01 -0700874 assert(vs_out >= 0);
875 assert(fs_in < fs->in_count);
876 vs_slot[fs_in] = vs_out;
Cody Northropd75c13e2015-01-02 14:07:20 -0700877
878 if (!vsWrites) {
879 // If the vertex shader did not write this input, we cannot
880 // program the SBE to read it. Our choices are to allow it to
881 // read junk from a GRF, or get zero. We're choosing zero.
882 if (i >= fs->generic_input_start) {
883 vs_slot[fs_in] = GEN7_SBE_ATTR_CONST_0000 |
884 GEN7_SBE_ATTR_OVERRIDE_X |
885 GEN7_SBE_ATTR_OVERRIDE_Y |
886 GEN7_SBE_ATTR_OVERRIDE_Z |
887 GEN7_SBE_ATTR_OVERRIDE_W;
888 }
889 }
890
GregF8cd81832014-11-18 18:01:01 -0700891 fs_in += 1;
892 }
Cody Northropd75c13e2015-01-02 14:07:20 -0700893 if (vsWrites) {
GregF8cd81832014-11-18 18:01:01 -0700894 vs_out += 1;
895 }
896 }
897
898 for (i = 0; i < 8; i++) {
899 uint16_t hi, lo;
900
901 /* no attr swizzles */
902 if (i * 2 + 1 < fs->in_count) {
903 lo = vs_slot[i * 2];
904 hi = vs_slot[i * 2 + 1];
905 } else if (i * 2 < fs->in_count) {
906 lo = vs_slot[i * 2];
907 hi = 0;
908 } else {
909 hi = 0;
910 lo = 0;
911 }
912
913 body[2 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
914 }
915
916 body[10] = 0; /* point sprite enables */
917 body[11] = 0; /* constant interpolation enables */
918 body[12] = 0; /* WrapShortest enables */
919 body[13] = 0;
920}
921
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800922static void pipeline_build_gs(struct intel_pipeline *pipeline,
923 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600924{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600925 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600926}
927
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800928static void pipeline_build_hs(struct intel_pipeline *pipeline,
929 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600930{
931 const uint8_t cmd_len = 7;
932 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
933 uint32_t *dw;
934
Chia-I Wu509b3f22014-09-02 10:24:05 +0800935 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600936
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800937 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600938 dw[0] = dw0;
939 dw[1] = 0;
940 dw[2] = 0;
941 dw[3] = 0;
942 dw[4] = 0;
943 dw[5] = 0;
944 dw[6] = 0;
945}
946
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800947static void pipeline_build_te(struct intel_pipeline *pipeline,
948 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600949{
950 const uint8_t cmd_len = 4;
951 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
952 uint32_t *dw;
953
Chia-I Wu509b3f22014-09-02 10:24:05 +0800954 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600955
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800956 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600957 dw[0] = dw0;
958 dw[1] = 0;
959 dw[2] = 0;
960 dw[3] = 0;
961}
962
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800963static void pipeline_build_ds(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 = 6;
967 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (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 dw[4] = 0;
978 dw[5] = 0;
979}
980
Tony Barbourfa6cac72015-01-16 14:27:35 -0700981static void pipeline_build_depth_stencil(struct intel_pipeline *pipeline,
982 const struct intel_pipeline_create_info *info)
983{
984 pipeline->cmd_depth_stencil = 0;
985
986 if (info->db.stencilTestEnable) {
987 pipeline->cmd_depth_stencil = 1 << 31 |
988 translate_compare_func(info->db.front.stencilFunc) << 28 |
989 translate_stencil_op(info->db.front.stencilFailOp) << 25 |
990 translate_stencil_op(info->db.front.stencilDepthFailOp) << 22 |
991 translate_stencil_op(info->db.front.stencilPassOp) << 19 |
992 1 << 15 |
993 translate_compare_func(info->db.back.stencilFunc) << 12 |
994 translate_stencil_op(info->db.back.stencilFailOp) << 9 |
995 translate_stencil_op(info->db.back.stencilDepthFailOp) << 6 |
996 translate_stencil_op(info->db.back.stencilPassOp) << 3;
997 }
998
999 pipeline->stencilTestEnable = info->db.stencilTestEnable;
1000
1001 /*
1002 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
1003 *
1004 * "Enabling the Depth Test function without defining a Depth Buffer is
1005 * UNDEFINED."
1006 *
1007 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
1008 *
1009 * "A Depth Buffer must be defined before enabling writes to it, or
1010 * operation is UNDEFINED."
1011 *
1012 * TODO We do not check these yet.
1013 */
1014 if (info->db.depthTestEnable) {
1015 pipeline->cmd_depth_test = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
1016 translate_compare_func(info->db.depthFunc) << 27;
1017 } else {
1018 pipeline->cmd_depth_test = GEN6_COMPAREFUNCTION_ALWAYS << 27;
1019 }
1020
1021 if (info->db.depthWriteEnable)
1022 pipeline->cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1023}
1024
1025static void pipeline_init_sample_pattern(struct intel_pipeline *pipeline,
1026 uint8_t *samples)
1027{
1028 struct sample {
1029 int x, y;
1030 };
1031 static const struct sample default_pattern_2x[2] = {
1032 { -4, -4 },
1033 { 4, 4 },
1034 };
1035 static const struct sample default_pattern_4x[4] = {
1036 { -2, -6 },
1037 { 6, -2 },
1038 { -6, 2 },
1039 { 2, 6 },
1040 };
1041 static const struct sample default_pattern_8x[8] = {
1042 { 1, -3 },
1043 { -1, 3 },
1044 { 5, 1 },
1045 { -3, -5 },
1046 { -5, 5 },
1047 { -7, -1 },
1048 { 3, 7 },
1049 { 7, -7 },
1050 };
1051
1052 const struct sample *pattern;
1053 int i;
1054
1055 switch (pipeline->sample_count) {
1056 case 2:
1057 pattern = default_pattern_2x;
1058 break;
1059 case 4:
1060 pattern = default_pattern_4x;
1061 break;
1062 case 8:
1063 pattern = default_pattern_8x;
1064 break;
1065 default:
1066 memset(samples, 0, pipeline->sample_count);
1067 return;
1068 break;
1069 }
1070
1071 for (i = 0; i < pipeline->sample_count; i++)
1072 samples[i] = (pattern[i].x + 8) << 4 | (pattern[i].y + 8);
1073}
1074
1075static void pipeline_build_msaa(struct intel_pipeline *pipeline,
1076 const struct intel_pipeline_create_info *info)
1077{
1078 uint32_t cmd, cmd_len;
1079 uint32_t *dw;
1080
1081 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1082
1083
1084 pipeline->sample_count = (info->ms.samples <= 1)?1:info->ms.samples;
1085
1086 /* 3DSTATE_MULTISAMPLE */
1087 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE);
1088 cmd_len = (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) ? 4 : 3;
1089 dw = pipeline_cmd_ptr(pipeline, cmd_len + 2);
1090 dw[0] = cmd | (cmd_len - 2);
1091 if (pipeline->sample_count <= 1)
1092 dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
1093 else if (pipeline->sample_count <= 4 || intel_gpu_gen(pipeline->dev->gpu) == INTEL_GEN(6))
1094 dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
1095 else
1096 dw[1] = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
1097
1098 pipeline_init_sample_pattern(pipeline, (uint8_t *) &dw[2]);
1099
1100 dw += cmd_len;
1101
1102 /* 3DSTATE_SAMPLE_MASK */
1103 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
1104 cmd_len = 2;
1105
1106 dw[0] = cmd | (cmd_len - 2);
1107 dw[1] = info->ms.sampleMask & ((1 << pipeline->sample_count) - 1);
1108 pipeline->cmd_sample_mask = dw[1];
1109}
1110
1111static void pipeline_build_cb(struct intel_pipeline *pipeline,
1112 const struct intel_pipeline_create_info *info)
1113{
1114 XGL_UINT i;
1115
1116 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
1117 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS*2);
1118 assert(info->cb.attachmentCount <= INTEL_MAX_RENDER_TARGETS);
1119
1120 uint32_t *dw = pipeline->cmd_cb;
1121
1122 for (i = 0; i < info->cb.attachmentCount; i++) {
1123 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &info->cb.pAttachments[i];
1124 uint32_t dw0, dw1;
1125
1126
1127 dw0 = 0;
1128 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
1129 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
1130 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
1131
1132 if (att->blendEnable) {
1133 dw0 = 1 << 31 |
1134 translate_blend_func(att->blendFuncAlpha) << 26 |
1135 translate_blend(att->srcBlendAlpha) << 20 |
1136 translate_blend(att->destBlendAlpha) << 15 |
1137 translate_blend_func(att->blendFuncColor) << 11 |
1138 translate_blend(att->srcBlendColor) << 5 |
1139 translate_blend(att->destBlendColor);
1140
1141 if (att->blendFuncAlpha != att->blendFuncColor ||
1142 att->srcBlendAlpha != att->srcBlendColor ||
1143 att->destBlendAlpha != att->destBlendColor)
1144 dw0 |= 1 << 30;
1145 }
1146
1147 if (info->cb.logicOp != XGL_LOGIC_OP_COPY) {
1148 int logicop;
1149
1150 switch (info->cb.logicOp) {
1151 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1152 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1153 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1154 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1155 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1156 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1157 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1158 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1159 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1160 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1161 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1162 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1163 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1164 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1165 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1166 default:
1167 assert(!"unknown logic op");
1168 logicop = GEN6_LOGICOP_CLEAR;
1169 break;
1170 }
1171
1172 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1173 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1174 }
1175
1176 if (!(att->channelWriteMask & 0x1))
1177 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1178 if (!(att->channelWriteMask & 0x2))
1179 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1180 if (!(att->channelWriteMask & 0x4))
1181 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1182 if (!(att->channelWriteMask & 0x8))
1183 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1184
1185 dw[2 * i] = dw0;
1186 dw[2 * i + 1] = dw1;
1187 }
1188
1189 for (i=info->cb.attachmentCount; i < INTEL_MAX_RENDER_TARGETS; i++)
1190 {
1191 dw[2 * i] = 0;
1192 dw[2 * i + 1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
1193 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
1194 GEN6_BLEND_DW1_POST_BLEND_CLAMP |
1195 GEN6_BLEND_DW1_WRITE_DISABLE_R |
1196 GEN6_BLEND_DW1_WRITE_DISABLE_G |
1197 GEN6_BLEND_DW1_WRITE_DISABLE_B |
1198 GEN6_BLEND_DW1_WRITE_DISABLE_A;
1199 }
1200
1201}
1202
1203
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001204static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline,
1205 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +08001206{
1207 XGL_RESULT ret;
1208
Chia-I Wu98824592014-09-02 09:42:46 +08001209 ret = pipeline_build_shaders(pipeline, info);
1210 if (ret != XGL_SUCCESS)
1211 return ret;
1212
Chia-I Wu1d125092014-10-08 08:49:38 +08001213 if (info->vi.bindingCount > ARRAY_SIZE(pipeline->vb) ||
1214 info->vi.attributeCount > ARRAY_SIZE(pipeline->vb))
1215 return XGL_ERROR_BAD_PIPELINE_DATA;
1216
1217 pipeline->vb_count = info->vi.bindingCount;
1218 memcpy(pipeline->vb, info->vi.pVertexBindingDescriptions,
1219 sizeof(pipeline->vb[0]) * pipeline->vb_count);
1220
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001221 pipeline_build_vertex_elements(pipeline, info);
GregF8cd81832014-11-18 18:01:01 -07001222 pipeline_build_fragment_SBE(pipeline);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001223 pipeline_build_msaa(pipeline, info);
Chia-I Wu5bdb0962015-01-24 12:49:28 +08001224 pipeline_build_depth_stencil(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +08001225
Chia-I Wu509b3f22014-09-02 10:24:05 +08001226 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001227 pipeline_build_urb_alloc_gen7(pipeline, info);
1228 pipeline_build_push_const_alloc_gen7(pipeline, info);
1229 pipeline_build_gs(pipeline, info);
1230 pipeline_build_hs(pipeline, info);
1231 pipeline_build_te(pipeline, info);
1232 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001233
1234 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1235 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
1236 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
1237 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
1238 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001239 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001240 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +08001241
1242 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
1243 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001244 }
1245
Chia-I Wube0a3d92014-09-02 13:20:59 +08001246 ret = pipeline_build_ia(pipeline, info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001247
1248 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001249 ret = pipeline_rs_state(pipeline, &info->rs);
Chia-I Wu3efef432014-08-28 15:00:16 +08001250
Chia-I Wu3efef432014-08-28 15:00:16 +08001251 if (ret == XGL_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001252 pipeline->db_format = info->db.format;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001253 pipeline_build_cb(pipeline, info);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001254 pipeline->cb_state = info->cb;
1255 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001256 }
1257
Tony Barbourfa6cac72015-01-16 14:27:35 -07001258 pipeline->scissor_enable = info->vp.scissorEnable;
1259
Chia-I Wu3efef432014-08-28 15:00:16 +08001260 return ret;
1261}
1262
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001263struct intel_pipeline_create_info_header {
1264 XGL_STRUCTURE_TYPE struct_type;
1265 const struct intel_pipeline_create_info_header *next;
1266};
1267
1268static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001269 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +08001270{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001271 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +08001272
Tony Barbourfa6cac72015-01-16 14:27:35 -07001273
1274 /*
1275 * Do we need to set safe defaults in case the app doesn't provide all of
1276 * the necessary create infos?
1277 */
1278 info->ms.samples = 1;
1279 info->ms.sampleMask = 1;
1280
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001281 while (header) {
1282 const void *src = (const void *) header;
Chia-I Wu3efef432014-08-28 15:00:16 +08001283 XGL_SIZE size;
1284 void *dst;
1285
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001286 switch (header->struct_type) {
Chia-I Wu3efef432014-08-28 15:00:16 +08001287 case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001288 size = sizeof(info->graphics);
1289 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +08001290 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001291 case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
1292 size = sizeof(info->vi);
1293 dst = &info->vi;
1294 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001295 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001296 size = sizeof(info->ia);
1297 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +08001298 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001299 case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001300 size = sizeof(info->db);
1301 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +08001302 break;
1303 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001304 size = sizeof(info->cb);
1305 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +08001306 break;
1307 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001308 size = sizeof(info->rs);
1309 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001310 break;
1311 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001312 size = sizeof(info->tess);
1313 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +08001314 break;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001315 case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
1316 size = sizeof(info->ms);
1317 dst = &info->ms;
1318 break;
1319 case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
1320 size = sizeof(info->vp);
1321 dst = &info->vp;
1322 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001323 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
1324 {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001325 const XGL_PIPELINE_SHADER *shader =
1326 (const XGL_PIPELINE_SHADER *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +08001327
1328 src = (const void *) shader;
1329 size = sizeof(*shader);
1330
1331 switch (shader->stage) {
1332 case XGL_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001333 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001334 break;
1335 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001336 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001337 break;
1338 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001339 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +08001340 break;
1341 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001342 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001343 break;
1344 case XGL_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001345 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +08001346 break;
Chia-I Wu3efef432014-08-28 15:00:16 +08001347 default:
1348 return XGL_ERROR_BAD_PIPELINE_DATA;
1349 break;
1350 }
1351 }
1352 break;
1353 case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001354 size = sizeof(info->compute);
1355 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +08001356 break;
1357 default:
1358 return XGL_ERROR_BAD_PIPELINE_DATA;
1359 break;
1360 }
1361
1362 memcpy(dst, src, size);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001363 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +08001364 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001365
1366 return XGL_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +08001367}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001368
Chia-I Wu3efef432014-08-28 15:00:16 +08001369static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001370 const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +08001371 struct intel_pipeline **pipeline_ret)
1372{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001373 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001374 struct intel_pipeline *pipeline;
1375 XGL_RESULT ret;
1376
Chia-I Wu509b3f22014-09-02 10:24:05 +08001377 ret = pipeline_create_info_init(&info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001378 (const struct intel_pipeline_create_info_header *) info_);
Chia-I Wu3efef432014-08-28 15:00:16 +08001379 if (ret != XGL_SUCCESS)
1380 return ret;
1381
1382 pipeline = (struct intel_pipeline *)
1383 intel_base_create(dev, sizeof(*pipeline), dev->base.dbg,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001384 XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +08001385 if (!pipeline)
1386 return XGL_ERROR_OUT_OF_MEMORY;
1387
1388 pipeline->dev = dev;
Chia-I Wub1024732014-12-19 13:00:29 +08001389 pipeline->obj.base.get_info = pipeline_get_info;
Chia-I Wu3efef432014-08-28 15:00:16 +08001390 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +08001391
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001392 ret = pipeline_build_all(pipeline, &info);
Chia-I Wu3efef432014-08-28 15:00:16 +08001393 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +08001394 ret = pipeline_validate(pipeline);
Chia-I Wu3efef432014-08-28 15:00:16 +08001395 if (ret != XGL_SUCCESS) {
1396 pipeline_destroy(&pipeline->obj);
1397 return ret;
1398 }
1399
1400 *pipeline_ret = pipeline;
1401
1402 return XGL_SUCCESS;
1403}
1404
Chia-I Wu96177272015-01-03 15:27:41 +08001405ICD_EXPORT XGL_RESULT XGLAPI xglCreateGraphicsPipeline(
Chia-I Wu3efef432014-08-28 15:00:16 +08001406 XGL_DEVICE device,
1407 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
1408 XGL_PIPELINE* pPipeline)
1409{
1410 struct intel_dev *dev = intel_dev(device);
1411
1412 return graphics_pipeline_create(dev, pCreateInfo,
1413 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001414}
1415
Chia-I Wu96177272015-01-03 15:27:41 +08001416ICD_EXPORT XGL_RESULT XGLAPI xglCreateComputePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001417 XGL_DEVICE device,
1418 const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo,
1419 XGL_PIPELINE* pPipeline)
1420{
1421 return XGL_ERROR_UNAVAILABLE;
1422}
1423
Chia-I Wu96177272015-01-03 15:27:41 +08001424ICD_EXPORT XGL_RESULT XGLAPI xglStorePipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001425 XGL_PIPELINE pipeline,
1426 XGL_SIZE* pDataSize,
1427 XGL_VOID* pData)
1428{
1429 return XGL_ERROR_UNAVAILABLE;
1430}
1431
Chia-I Wu96177272015-01-03 15:27:41 +08001432ICD_EXPORT XGL_RESULT XGLAPI xglLoadPipeline(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001433 XGL_DEVICE device,
1434 XGL_SIZE dataSize,
1435 const XGL_VOID* pData,
1436 XGL_PIPELINE* pPipeline)
1437{
1438 return XGL_ERROR_UNAVAILABLE;
1439}
1440
Chia-I Wu96177272015-01-03 15:27:41 +08001441ICD_EXPORT XGL_RESULT XGLAPI xglCreatePipelineDelta(
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001442 XGL_DEVICE device,
1443 XGL_PIPELINE p1,
1444 XGL_PIPELINE p2,
1445 XGL_PIPELINE_DELTA* delta)
1446{
1447 return XGL_ERROR_UNAVAILABLE;
1448}