blob: 171d5db318cb69053db0d25185596474ea8a7fe9 [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"
30
31#include "cmd.h"
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -060032#include "shader.h"
Chia-I Wued833872014-08-23 17:00:35 +080033#include "pipeline_priv.h"
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060034
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -060035static uint32_t *pipeline_cmd_ptr(struct intel_pipeline *pipeline, int cmd_len)
36{
37 uint32_t *ptr;
38
39 assert(pipeline->cmd_len + cmd_len < INTEL_PSO_CMD_ENTRIES);
40 ptr = &pipeline->cmds[pipeline->cmd_len];
41 pipeline->cmd_len += cmd_len;
42 return ptr;
43}
44
Chia-I Wu3efef432014-08-28 15:00:16 +080045static XGL_RESULT pipeline_ia_state(struct intel_pipeline *pipeline,
46 const XGL_PIPELINE_IA_STATE_CREATE_INFO* ia_state)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060047{
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -060048 pipeline->ia_state = *ia_state;
49
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060050 if (ia_state->provokingVertex == XGL_PROVOKING_VERTEX_FIRST) {
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060051 pipeline->provoking_vertex_tri = 0;
52 pipeline->provoking_vertex_trifan = 1;
53 pipeline->provoking_vertex_line = 0;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060054 } else {
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060055 pipeline->provoking_vertex_tri = 2;
56 pipeline->provoking_vertex_trifan = 2;
57 pipeline->provoking_vertex_line = 1;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060058 }
59
60 switch (ia_state->topology) {
61 case XGL_TOPOLOGY_POINT_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060062 pipeline->prim_type = GEN6_3DPRIM_POINTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060063 break;
64 case XGL_TOPOLOGY_LINE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060065 pipeline->prim_type = GEN6_3DPRIM_LINELIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060066 break;
67 case XGL_TOPOLOGY_LINE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060068 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060069 break;
70 case XGL_TOPOLOGY_TRIANGLE_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060071 pipeline->prim_type = GEN6_3DPRIM_TRILIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060072 break;
73 case XGL_TOPOLOGY_TRIANGLE_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060074 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060075 break;
76 case XGL_TOPOLOGY_RECT_LIST:
77 /*
78 * TODO: Rect lists are special in XGL, do we need to do
79 * something special here?
80 * XGL Guide:
81 * The rectangle list is a special geometry primitive type
82 * that can be used for implementing post-processing techniques
83 * or efficient copy operations. There are some special limitations
84 * for rectangle primitives. They cannot be clipped, must
85 * be axis aligned and cannot have depth gradient.
86 * Failure to comply with these restrictions results in
87 * undefined rendering results.
88 */
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060089 pipeline->prim_type = GEN6_3DPRIM_RECTLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060090 break;
91 case XGL_TOPOLOGY_QUAD_LIST:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060092 pipeline->prim_type = GEN6_3DPRIM_QUADLIST;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060093 break;
94 case XGL_TOPOLOGY_QUAD_STRIP:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060095 pipeline->prim_type = GEN6_3DPRIM_QUADSTRIP;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060096 break;
97 case XGL_TOPOLOGY_LINE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -060098 pipeline->prim_type = GEN6_3DPRIM_LINELIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060099 break;
100 case XGL_TOPOLOGY_LINE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600101 pipeline->prim_type = GEN6_3DPRIM_LINESTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600102 break;
103 case XGL_TOPOLOGY_TRIANGLE_LIST_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600104 pipeline->prim_type = GEN6_3DPRIM_TRILIST_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600105 break;
106 case XGL_TOPOLOGY_TRIANGLE_STRIP_ADJ:
Courtney Goeltzenleuchter8a3de592014-08-22 09:09:46 -0600107 pipeline->prim_type = GEN6_3DPRIM_TRISTRIP_ADJ;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600108 break;
109 case XGL_TOPOLOGY_PATCH:
110 // TODO: implement something here
111 break;
112 default:
113 return XGL_ERROR_BAD_PIPELINE_DATA;
114 }
115
116 if (ia_state->primitiveRestartEnable) {
117 pipeline->primitive_restart = true;
118 pipeline->primitive_restart_index = ia_state->primitiveRestartIndex;
119 } else {
120 pipeline->primitive_restart = false;
121 }
122
123 if (ia_state->disableVertexReuse) {
124 // TODO: What do we do to disable vertex reuse?
125 }
126
127 return XGL_SUCCESS;
128}
129
Chia-I Wu3efef432014-08-28 15:00:16 +0800130static XGL_RESULT pipeline_rs_state(struct intel_pipeline *pipeline,
131 const XGL_PIPELINE_RS_STATE_CREATE_INFO* rs_state)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600132{
133 pipeline->depthClipEnable = rs_state->depthClipEnable;
134 pipeline->rasterizerDiscardEnable = rs_state->rasterizerDiscardEnable;
135 pipeline->pointSize = rs_state->pointSize;
136 return XGL_SUCCESS;
137}
138
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600139static void pipeline_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600140{
141 struct intel_pipeline *pipeline = intel_pipeline_from_obj(obj);
142
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600143 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wu282d3bc2014-08-28 15:36:44 +0800144 icd_free(pipeline->intel_vs.pCode);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600145 }
146 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
Chia-I Wu282d3bc2014-08-28 15:36:44 +0800147 icd_free(pipeline->gs.pCode);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600148 }
149 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wu282d3bc2014-08-28 15:36:44 +0800150 icd_free(pipeline->intel_fs.pCode);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600151 }
152 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu282d3bc2014-08-28 15:36:44 +0800153 icd_free(pipeline->tess_control.pCode);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600154 }
155 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu282d3bc2014-08-28 15:36:44 +0800156 icd_free(pipeline->tess_eval.pCode);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600157 }
158
Chia-I Wued833872014-08-23 17:00:35 +0800159 if (pipeline->vs_rmap)
160 intel_rmap_destroy(pipeline->vs_rmap);
161 if (pipeline->fs_rmap)
162 intel_rmap_destroy(pipeline->fs_rmap);
163
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600164 intel_base_destroy(&pipeline->obj.base);
165}
166
Chia-I Wue3467672014-09-02 13:06:11 +0800167static void intel_pipe_shader_init(struct intel_shader *sh,
168 struct intel_pipe_shader *pipe_sh)
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600169{
170 pipe_sh->in_count = sh->in_count;
171 pipe_sh->out_count = sh->out_count;
172 pipe_sh->sampler_count = sh->sampler_count;
173 pipe_sh->surface_count = sh->surface_count;
174 pipe_sh->barycentric_interps = sh->barycentric_interps;
175 pipe_sh->urb_read_length = sh->urb_read_length;
176 pipe_sh->urb_grf_start = sh->urb_grf_start;
177 pipe_sh->uses = sh->uses;
178}
179
Chia-I Wu3efef432014-08-28 15:00:16 +0800180static XGL_RESULT pipeline_shader(struct intel_pipeline *pipeline,
181 const XGL_PIPELINE_SHADER *info)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600182{
Chia-I Wu3efef432014-08-28 15:00:16 +0800183 struct intel_shader *sh = intel_shader(info->shader);
184 void *kernel;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600185
Chia-I Wu3efef432014-08-28 15:00:16 +0800186 // TODO: process shader object and include in pipeline
187 // For now that processing is simply a copy so that the app
188 // can destroy the original shader object after pipeline creation.
189 kernel = icd_alloc(sh->ir->size, 0, XGL_SYSTEM_ALLOC_INTERNAL_SHADER);
190 if (!kernel)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600191 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wu3efef432014-08-28 15:00:16 +0800192
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600193 // TODO: This should be a compile step
194 memcpy(kernel, sh->ir->kernel, sh->ir->size);
195
Chia-I Wu3efef432014-08-28 15:00:16 +0800196 switch (info->stage) {
197 case XGL_SHADER_STAGE_VERTEX:
198 /*
199 * TODO: What should we do here?
200 * shader_state (XGL_PIPELINE_SHADER) contains links
201 * to application memory in the pLinkConstBufferInfo and
202 * it's pBufferData pointers. Do we need to bring all that
203 * into the driver or is it okay to rely on those references
204 * holding good data. In OpenGL we'd make a driver copy. Not
205 * as clear for XGL.
206 * For now, use the app pointers.
207 */
208 pipeline->vs = *info;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600209
210 /*
211 * Grab what we need from the intel_shader object as that
212 * could go away after the pipeline is created.
213 */
Chia-I Wue3467672014-09-02 13:06:11 +0800214 intel_pipe_shader_init(sh, &pipeline->intel_vs);
Chia-I Wu3efef432014-08-28 15:00:16 +0800215 pipeline->intel_vs.pCode = kernel;
216 pipeline->intel_vs.codeSize = sh->ir->size;
217 pipeline->active_shaders |= SHADER_VERTEX_FLAG;
218 pipeline->vs_rmap = intel_rmap_create(pipeline->dev,
219 &info->descriptorSetMapping[0],
220 &info->dynamicMemoryViewMapping, 0);
221 if (!pipeline->vs_rmap) {
222 icd_free(kernel);
223 return XGL_ERROR_OUT_OF_MEMORY;
224 }
225 break;
226 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wue3467672014-09-02 13:06:11 +0800227 intel_pipe_shader_init(sh, &pipeline->gs);
Chia-I Wu3efef432014-08-28 15:00:16 +0800228 pipeline->gs.pCode = kernel;
229 pipeline->gs.codeSize = sh->ir->size;
230 pipeline->active_shaders |= SHADER_GEOMETRY_FLAG;
231 break;
232 case XGL_SHADER_STAGE_FRAGMENT:
233 pipeline->fs = *info;
Chia-I Wue3467672014-09-02 13:06:11 +0800234 intel_pipe_shader_init(sh, &pipeline->intel_fs);
Chia-I Wu3efef432014-08-28 15:00:16 +0800235 pipeline->intel_fs.pCode = kernel;
236 pipeline->intel_fs.codeSize = sh->ir->size;
237 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
238 /* assuming one RT; need to parse the shader */
239 pipeline->fs_rmap = intel_rmap_create(pipeline->dev,
240 &info->descriptorSetMapping[0],
241 &info->dynamicMemoryViewMapping, 1);
242 if (!pipeline->fs_rmap) {
243 icd_free(kernel);
244 return XGL_ERROR_OUT_OF_MEMORY;
245 }
246 break;
247 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wue3467672014-09-02 13:06:11 +0800248 intel_pipe_shader_init(sh, &pipeline->tess_control);
Chia-I Wu3efef432014-08-28 15:00:16 +0800249 pipeline->tess_control.pCode = kernel;
250 pipeline->tess_control.codeSize = sh->ir->size;
251 pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG;
252 break;
253 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wue3467672014-09-02 13:06:11 +0800254 intel_pipe_shader_init(sh, &pipeline->tess_eval);
Chia-I Wu3efef432014-08-28 15:00:16 +0800255 pipeline->tess_eval.pCode = kernel;
256 pipeline->tess_eval.codeSize = sh->ir->size;
257 pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG;
258 break;
259 case XGL_SHADER_STAGE_COMPUTE:
Chia-I Wue3467672014-09-02 13:06:11 +0800260 intel_pipe_shader_init(sh, &pipeline->compute);
Chia-I Wu3efef432014-08-28 15:00:16 +0800261 pipeline->compute.pCode = kernel;
262 pipeline->compute.codeSize = sh->ir->size;
263 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
264 break;
265 default:
266 assert(!"unknown shader stage");
267 break;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600268 }
269
Chia-I Wu3efef432014-08-28 15:00:16 +0800270 return XGL_SUCCESS;
271}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600272
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800273static XGL_RESULT pipeline_validate(struct intel_pipeline *pipeline)
Chia-I Wu3efef432014-08-28 15:00:16 +0800274{
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600275 /*
276 * Validate required elements
277 */
278 if (!(pipeline->active_shaders & SHADER_VERTEX_FLAG)) {
279 // TODO: Log debug message: Vertex Shader required.
Chia-I Wu3efef432014-08-28 15:00:16 +0800280 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600281 }
282
283 /*
284 * Tessalation control and evaluation have to both have a shader defined or
285 * neither should have a shader defined.
286 */
287 if (((pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) == 0) !=
288 ((pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) == 0) ) {
289 // TODO: Log debug message: Both Tess control and Tess eval are required to use tessalation
Chia-I Wu3efef432014-08-28 15:00:16 +0800290 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600291 }
292
293 if ((pipeline->active_shaders & SHADER_COMPUTE_FLAG) &&
294 (pipeline->active_shaders & (SHADER_VERTEX_FLAG | SHADER_TESS_CONTROL_FLAG |
295 SHADER_TESS_EVAL_FLAG | SHADER_GEOMETRY_FLAG |
296 SHADER_FRAGMENT_FLAG))) {
297 // TODO: Log debug message: Can only specify compute shader when doing compute
Chia-I Wu3efef432014-08-28 15:00:16 +0800298 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600299 }
300
301 /*
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600302 * XGL_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
303 * Mismatching primitive topology and tessellation fails graphics pipeline creation.
304 */
305 if (pipeline->active_shaders & (SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG) &&
306 (pipeline->ia_state.topology != XGL_TOPOLOGY_PATCH)) {
307 // TODO: Log debug message: Invalid topology used with tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800308 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600309 }
310
311 if ((pipeline->ia_state.topology == XGL_TOPOLOGY_PATCH) &&
312 (pipeline->active_shaders & ~(SHADER_TESS_CONTROL_FLAG | SHADER_TESS_EVAL_FLAG))) {
313 // TODO: Log debug message: Cannot use TOPOLOGY_PATCH on non-tessalation shader.
Chia-I Wu3efef432014-08-28 15:00:16 +0800314 return XGL_ERROR_BAD_PIPELINE_DATA;
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600315 }
316
Chia-I Wu3efef432014-08-28 15:00:16 +0800317 return XGL_SUCCESS;
318}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600319
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800320static void pipeline_build_urb_alloc_gen6(struct intel_pipeline *pipeline,
321 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800322{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800323 const struct intel_gpu *gpu = pipeline->dev->gpu;
324 const int urb_size = ((gpu->gt == 2) ? 64 : 32) * 1024;
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800325 const struct intel_shader *vs = intel_shader(info->vs.shader);
326 const struct intel_shader *gs = intel_shader(info->gs.shader);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800327 int vs_entry_size, gs_entry_size;
328 int vs_size, gs_size;
329
Chia-I Wu509b3f22014-09-02 10:24:05 +0800330 INTEL_GPU_ASSERT(gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800331
332 vs_entry_size = ((vs->in_count >= vs->out_count) ?
333 vs->in_count : vs->out_count);
334 gs_entry_size = (gs) ? gs->out_count : 0;
335
336 /* in bytes */
337 vs_entry_size *= sizeof(float) * 4;
338 gs_entry_size *= sizeof(float) * 4;
339
340 if (gs) {
341 vs_size = urb_size / 2;
342 gs_size = vs_size;
343 } else {
344 vs_size = urb_size;
345 gs_size = 0;
346 }
347
348 /* 3DSTATE_URB */
349 {
350 const uint8_t cmd_len = 3;
351 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
352 (cmd_len - 2);
353 int vs_alloc_size, gs_alloc_size;
354 int vs_entry_count, gs_entry_count;
355 uint32_t *dw;
356
357 /* in 1024-bit rows */
358 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
359 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
360
361 /* valid range is [1, 5] */
362 if (!vs_alloc_size)
363 vs_alloc_size = 1;
364 if (!gs_alloc_size)
365 gs_alloc_size = 1;
366 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
367
368 /* valid range is [24, 256], multiples of 4 */
369 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
370 if (vs_entry_count > 256)
371 vs_entry_count = 256;
372 assert(vs_entry_count >= 24);
373
374 /* valid range is [0, 256], multiples of 4 */
375 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
376 if (gs_entry_count > 256)
377 gs_entry_count = 256;
378
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600379 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800380
381 dw[0] = dw0;
382 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
383 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
384 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
385 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
386 }
387}
388
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800389static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
390 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800391{
Chia-I Wu509b3f22014-09-02 10:24:05 +0800392 const struct intel_gpu *gpu = pipeline->dev->gpu;
393 const int urb_size = ((gpu->gt == 3) ? 512 :
394 (gpu->gt == 2) ? 256 : 128) * 1024;
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800395 const struct intel_shader *vs = intel_shader(info->vs.shader);
396 const struct intel_shader *gs = intel_shader(info->gs.shader);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800397 /* some space is reserved for PCBs */
Chia-I Wu509b3f22014-09-02 10:24:05 +0800398 int urb_offset = ((gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800399 int vs_entry_size, gs_entry_size;
400 int vs_size, gs_size;
401
Chia-I Wu509b3f22014-09-02 10:24:05 +0800402 INTEL_GPU_ASSERT(gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800403
404 vs_entry_size = ((vs->in_count >= vs->out_count) ?
405 vs->in_count : vs->out_count);
406 gs_entry_size = (gs) ? gs->out_count : 0;
407
408 /* in bytes */
409 vs_entry_size *= sizeof(float) * 4;
410 gs_entry_size *= sizeof(float) * 4;
411
412 if (gs) {
413 vs_size = (urb_size - urb_offset) / 2;
414 gs_size = vs_size;
415 } else {
416 vs_size = urb_size - urb_offset;
417 gs_size = 0;
418 }
419
420 /* 3DSTATE_URB_* */
421 {
422 const uint8_t cmd_len = 2;
423 int vs_alloc_size, gs_alloc_size;
424 int vs_entry_count, gs_entry_count;
425 uint32_t *dw;
426
427 /* in 512-bit rows */
428 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
429 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
430
431 if (!vs_alloc_size)
432 vs_alloc_size = 1;
433 if (!gs_alloc_size)
434 gs_alloc_size = 1;
435
436 /* avoid performance decrease due to banking */
437 if (vs_alloc_size == 5)
438 vs_alloc_size = 6;
439
440 /* in multiples of 8 */
441 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
442 assert(vs_entry_count >= 32);
443
444 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
445
Chia-I Wu509b3f22014-09-02 10:24:05 +0800446 if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800447 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800448 (gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800449 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800450 (gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800451 if (vs_entry_count >= max_vs_entry_count)
452 vs_entry_count = max_vs_entry_count;
453 if (gs_entry_count >= max_gs_entry_count)
454 gs_entry_count = max_gs_entry_count;
455 } else {
456 const int max_vs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800457 (gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800458 const int max_gs_entry_count =
Chia-I Wu509b3f22014-09-02 10:24:05 +0800459 (gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800460 if (vs_entry_count >= max_vs_entry_count)
461 vs_entry_count = max_vs_entry_count;
462 if (gs_entry_count >= max_gs_entry_count)
463 gs_entry_count = max_gs_entry_count;
464 }
465
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600466 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800467 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
468 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
469 (vs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
470 vs_entry_count;
471
472 dw += 2;
473 if (gs_size)
474 urb_offset += vs_size;
475 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
476 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
477 (gs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
478 gs_entry_count;
479
480 dw += 2;
481 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
482 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
483
484 dw += 2;
485 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
486 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
487 }
488}
489
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800490static void pipeline_build_push_const_alloc_gen7(struct intel_pipeline *pipeline,
491 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600492{
493 const uint8_t cmd_len = 2;
494 uint32_t offset = 0;
495 uint32_t size = 8192;
496 uint32_t *dw;
497 int end;
498
Chia-I Wu509b3f22014-09-02 10:24:05 +0800499 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600500
501 /*
502 * From the Ivy Bridge PRM, volume 2 part 1, page 68:
503 *
504 * "(A table that says the maximum size of each constant buffer is
505 * 16KB")
506 *
507 * From the Ivy Bridge PRM, volume 2 part 1, page 115:
508 *
509 * "The sum of the Constant Buffer Offset and the Constant Buffer Size
510 * may not exceed the maximum value of the Constant Buffer Size."
511 *
512 * Thus, the valid range of buffer end is [0KB, 16KB].
513 */
514 end = (offset + size) / 1024;
515 if (end > 16) {
516 assert(!"invalid constant buffer end");
517 end = 16;
518 }
519
520 /* the valid range of buffer offset is [0KB, 15KB] */
521 offset = (offset + 1023) / 1024;
522 if (offset > 15) {
523 assert(!"invalid constant buffer offset");
524 offset = 15;
525 }
526
527 if (offset > end) {
528 assert(!size);
529 offset = end;
530 }
531
532 /* the valid range of buffer size is [0KB, 15KB] */
533 size = end - offset;
534 if (size > 15) {
535 assert(!"invalid constant buffer size");
536 size = 15;
537 }
538
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800539 dw = pipeline_cmd_ptr(pipeline, cmd_len * 5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600540 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
541 dw[1] = offset << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
542 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
543
544 dw += 2;
545 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
546 dw[1] = size << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
547 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
548
549 dw += 2;
550 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
551 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
552 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
553
554 dw += 2;
555 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
556 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
557 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
558
559 dw += 2;
560 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
561 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
562 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu8370b402014-08-29 12:28:37 +0800563
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600564 // gen7_wa_pipe_control_cs_stall(p, true, true);
565 // looks equivalent to: gen6_wa_wm_multisample_flush - this does more
566 // than the documentation seems to imply
567}
568
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800569static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
570 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800571{
572 const uint8_t cmd_len = 3;
573 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
574 (cmd_len - 2);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800575 const struct intel_shader *vs = intel_shader(info->vs.shader);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800576 int comps[4] = { GEN6_VFCOMP_NOSTORE, GEN6_VFCOMP_NOSTORE,
577 GEN6_VFCOMP_NOSTORE, GEN6_VFCOMP_NOSTORE };
578 uint32_t *dw;
579
Chia-I Wu509b3f22014-09-02 10:24:05 +0800580 INTEL_GPU_ASSERT(pipeline->dev->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800581
582 if (!(vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)))
583 return;
584
585 dw = pipeline_cmd_ptr(pipeline, cmd_len);
586 dw[0] = dw0;
587 dw++;
588
589 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
590 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
591 if (vs->uses & INTEL_SHADER_USE_IID)
592 comps[1] = GEN6_VFCOMP_STORE_IID;
593
594 /* VERTEX_ELEMENT_STATE */
595 dw[0] = GEN6_VE_STATE_DW0_VALID;
596 dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT |
597 comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT |
598 comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT |
599 comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT;
600}
601
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800602static void pipeline_build_gs(struct intel_pipeline *pipeline,
603 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600604{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600605 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600606}
607
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800608static void pipeline_build_hs(struct intel_pipeline *pipeline,
609 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600610{
611 const uint8_t cmd_len = 7;
612 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
613 uint32_t *dw;
614
Chia-I Wu509b3f22014-09-02 10:24:05 +0800615 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600616
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800617 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600618 dw[0] = dw0;
619 dw[1] = 0;
620 dw[2] = 0;
621 dw[3] = 0;
622 dw[4] = 0;
623 dw[5] = 0;
624 dw[6] = 0;
625}
626
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800627static void pipeline_build_te(struct intel_pipeline *pipeline,
628 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600629{
630 const uint8_t cmd_len = 4;
631 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
632 uint32_t *dw;
633
Chia-I Wu509b3f22014-09-02 10:24:05 +0800634 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600635
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800636 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600637 dw[0] = dw0;
638 dw[1] = 0;
639 dw[2] = 0;
640 dw[3] = 0;
641}
642
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800643static void pipeline_build_ds(struct intel_pipeline *pipeline,
644 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600645{
646 const uint8_t cmd_len = 6;
647 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
648 uint32_t *dw;
649
Chia-I Wu509b3f22014-09-02 10:24:05 +0800650 INTEL_GPU_ASSERT(pipeline->dev->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600651
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800652 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600653 dw[0] = dw0;
654 dw[1] = 0;
655 dw[2] = 0;
656 dw[3] = 0;
657 dw[4] = 0;
658 dw[5] = 0;
659}
660
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800661static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline,
662 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +0800663{
664 XGL_RESULT ret;
665
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800666 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800667
Chia-I Wu509b3f22014-09-02 10:24:05 +0800668 if (intel_gpu_gen(pipeline->dev->gpu) >= INTEL_GEN(7)) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800669 pipeline_build_urb_alloc_gen7(pipeline, info);
670 pipeline_build_push_const_alloc_gen7(pipeline, info);
671 pipeline_build_gs(pipeline, info);
672 pipeline_build_hs(pipeline, info);
673 pipeline_build_te(pipeline, info);
674 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +0800675
676 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
677 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
678 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
679 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
680 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800681 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800682 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +0800683
684 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
685 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800686 }
687
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800688 ret = pipeline_ia_state(pipeline, &info->ia);
Chia-I Wu3efef432014-08-28 15:00:16 +0800689
690 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800691 ret = pipeline_rs_state(pipeline, &info->rs);
Chia-I Wu3efef432014-08-28 15:00:16 +0800692
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800693 if (ret == XGL_SUCCESS && info->vs.shader)
694 ret = pipeline_shader(pipeline, &info->vs);
695 if (ret == XGL_SUCCESS && info->tcs.shader)
696 ret = pipeline_shader(pipeline, &info->tcs);
697 if (ret == XGL_SUCCESS && info->tes.shader)
698 ret = pipeline_shader(pipeline, &info->tes);
699 if (ret == XGL_SUCCESS && info->gs.shader)
700 ret = pipeline_shader(pipeline, &info->gs);
701 if (ret == XGL_SUCCESS && info->fs.shader)
702 ret = pipeline_shader(pipeline, &info->fs);
Chia-I Wu3efef432014-08-28 15:00:16 +0800703
704 if (ret == XGL_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800705 pipeline->db_format = info->db.format;
706 pipeline->cb_state = info->cb;
707 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +0800708 }
709
710 return ret;
711}
712
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800713struct intel_pipeline_create_info_header {
714 XGL_STRUCTURE_TYPE struct_type;
715 const struct intel_pipeline_create_info_header *next;
716};
717
718static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800719 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +0800720{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800721 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +0800722
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800723 while (header) {
724 const void *src = (const void *) header;
Chia-I Wu3efef432014-08-28 15:00:16 +0800725 XGL_SIZE size;
726 void *dst;
727
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800728 switch (header->struct_type) {
Chia-I Wu3efef432014-08-28 15:00:16 +0800729 case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800730 size = sizeof(info->graphics);
731 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +0800732 break;
733 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800734 size = sizeof(info->ia);
735 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +0800736 break;
737 case XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800738 size = sizeof(info->db);
739 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +0800740 break;
741 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800742 size = sizeof(info->cb);
743 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +0800744 break;
745 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800746 size = sizeof(info->rs);
747 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800748 break;
749 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800750 size = sizeof(info->tess);
751 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +0800752 break;
753 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
754 {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800755 const XGL_PIPELINE_SHADER *shader =
756 (const XGL_PIPELINE_SHADER *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +0800757
758 src = (const void *) shader;
759 size = sizeof(*shader);
760
761 switch (shader->stage) {
762 case XGL_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800763 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800764 break;
765 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800766 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800767 break;
768 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800769 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +0800770 break;
771 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800772 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800773 break;
774 case XGL_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800775 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800776 break;
777 case XGL_SHADER_STAGE_COMPUTE:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800778 dst = &info->cs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800779 break;
780 default:
781 return XGL_ERROR_BAD_PIPELINE_DATA;
782 break;
783 }
784 }
785 break;
786 case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800787 size = sizeof(info->compute);
788 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +0800789 break;
790 default:
791 return XGL_ERROR_BAD_PIPELINE_DATA;
792 break;
793 }
794
795 memcpy(dst, src, size);
796
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800797 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +0800798 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600799
800 return XGL_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +0800801}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600802
Chia-I Wu3efef432014-08-28 15:00:16 +0800803static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800804 const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +0800805 struct intel_pipeline **pipeline_ret)
806{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800807 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +0800808 struct intel_pipeline *pipeline;
809 XGL_RESULT ret;
810
Chia-I Wu509b3f22014-09-02 10:24:05 +0800811 ret = pipeline_create_info_init(&info,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800812 (const struct intel_pipeline_create_info_header *) info_);
Chia-I Wu3efef432014-08-28 15:00:16 +0800813 if (ret != XGL_SUCCESS)
814 return ret;
815
816 pipeline = (struct intel_pipeline *)
817 intel_base_create(dev, sizeof(*pipeline), dev->base.dbg,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800818 XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +0800819 if (!pipeline)
820 return XGL_ERROR_OUT_OF_MEMORY;
821
822 pipeline->dev = dev;
823 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +0800824
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800825 ret = pipeline_build_all(pipeline, &info);
Chia-I Wu3efef432014-08-28 15:00:16 +0800826 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800827 ret = pipeline_validate(pipeline);
Chia-I Wu3efef432014-08-28 15:00:16 +0800828 if (ret != XGL_SUCCESS) {
829 pipeline_destroy(&pipeline->obj);
830 return ret;
831 }
832
833 *pipeline_ret = pipeline;
834
835 return XGL_SUCCESS;
836}
837
838XGL_RESULT XGLAPI intelCreateGraphicsPipeline(
839 XGL_DEVICE device,
840 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
841 XGL_PIPELINE* pPipeline)
842{
843 struct intel_dev *dev = intel_dev(device);
844
845 return graphics_pipeline_create(dev, pCreateInfo,
846 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600847}
848
849XGL_RESULT XGLAPI intelCreateComputePipeline(
850 XGL_DEVICE device,
851 const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo,
852 XGL_PIPELINE* pPipeline)
853{
854 return XGL_ERROR_UNAVAILABLE;
855}
856
857XGL_RESULT XGLAPI intelStorePipeline(
858 XGL_PIPELINE pipeline,
859 XGL_SIZE* pDataSize,
860 XGL_VOID* pData)
861{
862 return XGL_ERROR_UNAVAILABLE;
863}
864
865XGL_RESULT XGLAPI intelLoadPipeline(
866 XGL_DEVICE device,
867 XGL_SIZE dataSize,
868 const XGL_VOID* pData,
869 XGL_PIPELINE* pPipeline)
870{
871 return XGL_ERROR_UNAVAILABLE;
872}
873
874XGL_RESULT XGLAPI intelCreatePipelineDelta(
875 XGL_DEVICE device,
876 XGL_PIPELINE p1,
877 XGL_PIPELINE p2,
878 XGL_PIPELINE_DELTA* delta)
879{
880 return XGL_ERROR_UNAVAILABLE;
881}