blob: 6e9375d988ab82711fe1745c49375cd2f8e60d5c [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 Wuf90ff0c2014-09-02 09:32:46 +0800323 const int urb_size = ((info->gpu->gt == 2) ? 64 : 32) * 1024;
324 const struct intel_shader *vs = intel_shader(info->vs.shader);
325 const struct intel_shader *gs = intel_shader(info->gs.shader);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800326 int vs_entry_size, gs_entry_size;
327 int vs_size, gs_size;
328
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800329 INTEL_GPU_ASSERT(info->gpu, 6, 6);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800330
331 vs_entry_size = ((vs->in_count >= vs->out_count) ?
332 vs->in_count : vs->out_count);
333 gs_entry_size = (gs) ? gs->out_count : 0;
334
335 /* in bytes */
336 vs_entry_size *= sizeof(float) * 4;
337 gs_entry_size *= sizeof(float) * 4;
338
339 if (gs) {
340 vs_size = urb_size / 2;
341 gs_size = vs_size;
342 } else {
343 vs_size = urb_size;
344 gs_size = 0;
345 }
346
347 /* 3DSTATE_URB */
348 {
349 const uint8_t cmd_len = 3;
350 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_URB) |
351 (cmd_len - 2);
352 int vs_alloc_size, gs_alloc_size;
353 int vs_entry_count, gs_entry_count;
354 uint32_t *dw;
355
356 /* in 1024-bit rows */
357 vs_alloc_size = (vs_entry_size + 128 - 1) / 128;
358 gs_alloc_size = (gs_entry_size + 128 - 1) / 128;
359
360 /* valid range is [1, 5] */
361 if (!vs_alloc_size)
362 vs_alloc_size = 1;
363 if (!gs_alloc_size)
364 gs_alloc_size = 1;
365 assert(vs_alloc_size <= 5 && gs_alloc_size <= 5);
366
367 /* valid range is [24, 256], multiples of 4 */
368 vs_entry_count = (vs_size / 128 / vs_alloc_size) & ~3;
369 if (vs_entry_count > 256)
370 vs_entry_count = 256;
371 assert(vs_entry_count >= 24);
372
373 /* valid range is [0, 256], multiples of 4 */
374 gs_entry_count = (gs_size / 128 / gs_alloc_size) & ~3;
375 if (gs_entry_count > 256)
376 gs_entry_count = 256;
377
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600378 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800379
380 dw[0] = dw0;
381 dw[1] = (vs_alloc_size - 1) << GEN6_URB_DW1_VS_ENTRY_SIZE__SHIFT |
382 vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
383 dw[2] = gs_entry_count << GEN6_URB_DW2_GS_ENTRY_COUNT__SHIFT |
384 (gs_alloc_size - 1) << GEN6_URB_DW2_GS_ENTRY_SIZE__SHIFT;
385 }
386}
387
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800388static void pipeline_build_urb_alloc_gen7(struct intel_pipeline *pipeline,
389 const struct intel_pipeline_create_info *info)
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800390{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800391 const int urb_size = ((info->gpu->gt == 3) ? 512 :
392 (info->gpu->gt == 2) ? 256 : 128) * 1024;
393 const struct intel_shader *vs = intel_shader(info->vs.shader);
394 const struct intel_shader *gs = intel_shader(info->gs.shader);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800395 /* some space is reserved for PCBs */
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800396 int urb_offset = ((info->gpu->gt == 3) ? 32 : 16) * 1024;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800397 int vs_entry_size, gs_entry_size;
398 int vs_size, gs_size;
399
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800400 INTEL_GPU_ASSERT(info->gpu, 7, 7.5);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800401
402 vs_entry_size = ((vs->in_count >= vs->out_count) ?
403 vs->in_count : vs->out_count);
404 gs_entry_size = (gs) ? gs->out_count : 0;
405
406 /* in bytes */
407 vs_entry_size *= sizeof(float) * 4;
408 gs_entry_size *= sizeof(float) * 4;
409
410 if (gs) {
411 vs_size = (urb_size - urb_offset) / 2;
412 gs_size = vs_size;
413 } else {
414 vs_size = urb_size - urb_offset;
415 gs_size = 0;
416 }
417
418 /* 3DSTATE_URB_* */
419 {
420 const uint8_t cmd_len = 2;
421 int vs_alloc_size, gs_alloc_size;
422 int vs_entry_count, gs_entry_count;
423 uint32_t *dw;
424
425 /* in 512-bit rows */
426 vs_alloc_size = (vs_entry_size + 64 - 1) / 64;
427 gs_alloc_size = (gs_entry_size + 64 - 1) / 64;
428
429 if (!vs_alloc_size)
430 vs_alloc_size = 1;
431 if (!gs_alloc_size)
432 gs_alloc_size = 1;
433
434 /* avoid performance decrease due to banking */
435 if (vs_alloc_size == 5)
436 vs_alloc_size = 6;
437
438 /* in multiples of 8 */
439 vs_entry_count = (vs_size / 64 / vs_alloc_size) & ~7;
440 assert(vs_entry_count >= 32);
441
442 gs_entry_count = (gs_size / 64 / gs_alloc_size) & ~7;
443
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800444 if (intel_gpu_gen(info->gpu) >= INTEL_GEN(7.5)) {
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800445 const int max_vs_entry_count =
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800446 (info->gpu->gt >= 2) ? 1664 : 640;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800447 const int max_gs_entry_count =
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800448 (info->gpu->gt >= 2) ? 640 : 256;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800449 if (vs_entry_count >= max_vs_entry_count)
450 vs_entry_count = max_vs_entry_count;
451 if (gs_entry_count >= max_gs_entry_count)
452 gs_entry_count = max_gs_entry_count;
453 } else {
454 const int max_vs_entry_count =
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800455 (info->gpu->gt == 2) ? 704 : 512;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800456 const int max_gs_entry_count =
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800457 (info->gpu->gt == 2) ? 320 : 192;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800458 if (vs_entry_count >= max_vs_entry_count)
459 vs_entry_count = max_vs_entry_count;
460 if (gs_entry_count >= max_gs_entry_count)
461 gs_entry_count = max_gs_entry_count;
462 }
463
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600464 dw = pipeline_cmd_ptr(pipeline, cmd_len*4);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800465 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (cmd_len - 2);
466 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
467 (vs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
468 vs_entry_count;
469
470 dw += 2;
471 if (gs_size)
472 urb_offset += vs_size;
473 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (cmd_len - 2);
474 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
475 (gs_alloc_size - 1) << GEN7_URB_ANY_DW1_ENTRY_SIZE__SHIFT |
476 gs_entry_count;
477
478 dw += 2;
479 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (cmd_len - 2);
480 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
481
482 dw += 2;
483 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (cmd_len - 2);
484 dw[1] = (urb_offset / 8192) << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
485 }
486}
487
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800488static void pipeline_build_push_const_alloc_gen7(struct intel_pipeline *pipeline,
489 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600490{
491 const uint8_t cmd_len = 2;
492 uint32_t offset = 0;
493 uint32_t size = 8192;
494 uint32_t *dw;
495 int end;
496
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800497 INTEL_GPU_ASSERT(info->gpu, 7, 7.5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600498
499 /*
500 * From the Ivy Bridge PRM, volume 2 part 1, page 68:
501 *
502 * "(A table that says the maximum size of each constant buffer is
503 * 16KB")
504 *
505 * From the Ivy Bridge PRM, volume 2 part 1, page 115:
506 *
507 * "The sum of the Constant Buffer Offset and the Constant Buffer Size
508 * may not exceed the maximum value of the Constant Buffer Size."
509 *
510 * Thus, the valid range of buffer end is [0KB, 16KB].
511 */
512 end = (offset + size) / 1024;
513 if (end > 16) {
514 assert(!"invalid constant buffer end");
515 end = 16;
516 }
517
518 /* the valid range of buffer offset is [0KB, 15KB] */
519 offset = (offset + 1023) / 1024;
520 if (offset > 15) {
521 assert(!"invalid constant buffer offset");
522 offset = 15;
523 }
524
525 if (offset > end) {
526 assert(!size);
527 offset = end;
528 }
529
530 /* the valid range of buffer size is [0KB, 15KB] */
531 size = end - offset;
532 if (size > 15) {
533 assert(!"invalid constant buffer size");
534 size = 15;
535 }
536
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800537 dw = pipeline_cmd_ptr(pipeline, cmd_len * 5);
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600538 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
539 dw[1] = offset << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
540 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
541
542 dw += 2;
543 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
544 dw[1] = size << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
545 size << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
546
547 dw += 2;
548 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
549 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
550 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
551
552 dw += 2;
553 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
554 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
555 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
556
557 dw += 2;
558 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
559 dw[1] = 0 << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
560 0 << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu8370b402014-08-29 12:28:37 +0800561
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600562 // gen7_wa_pipe_control_cs_stall(p, true, true);
563 // looks equivalent to: gen6_wa_wm_multisample_flush - this does more
564 // than the documentation seems to imply
565}
566
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800567static void pipeline_build_vertex_elements(struct intel_pipeline *pipeline,
568 const struct intel_pipeline_create_info *info)
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800569{
570 const uint8_t cmd_len = 3;
571 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) |
572 (cmd_len - 2);
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800573 const struct intel_shader *vs = intel_shader(info->vs.shader);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800574 int comps[4] = { GEN6_VFCOMP_NOSTORE, GEN6_VFCOMP_NOSTORE,
575 GEN6_VFCOMP_NOSTORE, GEN6_VFCOMP_NOSTORE };
576 uint32_t *dw;
577
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800578 INTEL_GPU_ASSERT(info->gpu, 6, 7.5);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800579
580 if (!(vs->uses & (INTEL_SHADER_USE_VID | INTEL_SHADER_USE_IID)))
581 return;
582
583 dw = pipeline_cmd_ptr(pipeline, cmd_len);
584 dw[0] = dw0;
585 dw++;
586
587 comps[0] = (vs->uses & INTEL_SHADER_USE_VID) ?
588 GEN6_VFCOMP_STORE_VID : GEN6_VFCOMP_STORE_0;
589 if (vs->uses & INTEL_SHADER_USE_IID)
590 comps[1] = GEN6_VFCOMP_STORE_IID;
591
592 /* VERTEX_ELEMENT_STATE */
593 dw[0] = GEN6_VE_STATE_DW0_VALID;
594 dw[1] = comps[0] << GEN6_VE_STATE_DW1_COMP0__SHIFT |
595 comps[1] << GEN6_VE_STATE_DW1_COMP1__SHIFT |
596 comps[2] << GEN6_VE_STATE_DW1_COMP2__SHIFT |
597 comps[3] << GEN6_VE_STATE_DW1_COMP3__SHIFT;
598}
599
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800600static void pipeline_build_gs(struct intel_pipeline *pipeline,
601 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600602{
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600603 // gen7_emit_3DSTATE_GS done by cmd_pipeline
Courtney Goeltzenleuchterb2867702014-08-28 17:44:05 -0600604}
605
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800606static void pipeline_build_hs(struct intel_pipeline *pipeline,
607 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600608{
609 const uint8_t cmd_len = 7;
610 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (cmd_len - 2);
611 uint32_t *dw;
612
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800613 INTEL_GPU_ASSERT(info->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600614
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800615 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600616 dw[0] = dw0;
617 dw[1] = 0;
618 dw[2] = 0;
619 dw[3] = 0;
620 dw[4] = 0;
621 dw[5] = 0;
622 dw[6] = 0;
623}
624
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800625static void pipeline_build_te(struct intel_pipeline *pipeline,
626 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600627{
628 const uint8_t cmd_len = 4;
629 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (cmd_len - 2);
630 uint32_t *dw;
631
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800632 INTEL_GPU_ASSERT(info->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600633
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800634 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600635 dw[0] = dw0;
636 dw[1] = 0;
637 dw[2] = 0;
638 dw[3] = 0;
639}
640
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800641static void pipeline_build_ds(struct intel_pipeline *pipeline,
642 const struct intel_pipeline_create_info *info)
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600643{
644 const uint8_t cmd_len = 6;
645 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (cmd_len - 2);
646 uint32_t *dw;
647
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800648 INTEL_GPU_ASSERT(info->gpu, 7, 7.5);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600649
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800650 dw = pipeline_cmd_ptr(pipeline, cmd_len);
Courtney Goeltzenleuchterdee81a62014-08-28 18:05:24 -0600651 dw[0] = dw0;
652 dw[1] = 0;
653 dw[2] = 0;
654 dw[3] = 0;
655 dw[4] = 0;
656 dw[5] = 0;
657}
658
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800659static XGL_RESULT pipeline_build_all(struct intel_pipeline *pipeline,
660 const struct intel_pipeline_create_info *info)
Chia-I Wu3efef432014-08-28 15:00:16 +0800661{
662 XGL_RESULT ret;
663
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800664 pipeline_build_vertex_elements(pipeline, info);
Chia-I Wu4d9ad912014-08-29 14:20:36 +0800665
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800666 if (intel_gpu_gen(info->gpu) >= INTEL_GEN(7)) {
667 pipeline_build_urb_alloc_gen7(pipeline, info);
668 pipeline_build_push_const_alloc_gen7(pipeline, info);
669 pipeline_build_gs(pipeline, info);
670 pipeline_build_hs(pipeline, info);
671 pipeline_build_te(pipeline, info);
672 pipeline_build_ds(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +0800673
674 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
675 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL |
676 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE |
677 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL |
678 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800679 } else {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800680 pipeline_build_urb_alloc_gen6(pipeline, info);
Chia-I Wu8370b402014-08-29 12:28:37 +0800681
682 pipeline->wa_flags = INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE |
683 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +0800684 }
685
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800686 ret = pipeline_ia_state(pipeline, &info->ia);
Chia-I Wu3efef432014-08-28 15:00:16 +0800687
688 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800689 ret = pipeline_rs_state(pipeline, &info->rs);
Chia-I Wu3efef432014-08-28 15:00:16 +0800690
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800691 if (ret == XGL_SUCCESS && info->vs.shader)
692 ret = pipeline_shader(pipeline, &info->vs);
693 if (ret == XGL_SUCCESS && info->tcs.shader)
694 ret = pipeline_shader(pipeline, &info->tcs);
695 if (ret == XGL_SUCCESS && info->tes.shader)
696 ret = pipeline_shader(pipeline, &info->tes);
697 if (ret == XGL_SUCCESS && info->gs.shader)
698 ret = pipeline_shader(pipeline, &info->gs);
699 if (ret == XGL_SUCCESS && info->fs.shader)
700 ret = pipeline_shader(pipeline, &info->fs);
Chia-I Wu3efef432014-08-28 15:00:16 +0800701
702 if (ret == XGL_SUCCESS) {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800703 pipeline->db_format = info->db.format;
704 pipeline->cb_state = info->cb;
705 pipeline->tess_state = info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +0800706 }
707
708 return ret;
709}
710
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800711struct intel_pipeline_create_info_header {
712 XGL_STRUCTURE_TYPE struct_type;
713 const struct intel_pipeline_create_info_header *next;
714};
715
716static XGL_RESULT pipeline_create_info_init(struct intel_pipeline_create_info *info,
717 const struct intel_gpu *gpu,
718 const struct intel_pipeline_create_info_header *header)
Chia-I Wu3efef432014-08-28 15:00:16 +0800719{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800720 memset(info, 0, sizeof(*info));
Chia-I Wu3efef432014-08-28 15:00:16 +0800721
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800722 info->gpu = gpu;
Chia-I Wu3efef432014-08-28 15:00:16 +0800723
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800724 while (header) {
725 const void *src = (const void *) header;
Chia-I Wu3efef432014-08-28 15:00:16 +0800726 XGL_SIZE size;
727 void *dst;
728
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800729 switch (header->struct_type) {
Chia-I Wu3efef432014-08-28 15:00:16 +0800730 case XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800731 size = sizeof(info->graphics);
732 dst = &info->graphics;
Chia-I Wu3efef432014-08-28 15:00:16 +0800733 break;
734 case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800735 size = sizeof(info->ia);
736 dst = &info->ia;
Chia-I Wu3efef432014-08-28 15:00:16 +0800737 break;
738 case XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800739 size = sizeof(info->db);
740 dst = &info->db;
Chia-I Wu3efef432014-08-28 15:00:16 +0800741 break;
742 case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800743 size = sizeof(info->cb);
744 dst = &info->cb;
Chia-I Wu3efef432014-08-28 15:00:16 +0800745 break;
746 case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800747 size = sizeof(info->rs);
748 dst = &info->rs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800749 break;
750 case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800751 size = sizeof(info->tess);
752 dst = &info->tess;
Chia-I Wu3efef432014-08-28 15:00:16 +0800753 break;
754 case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
755 {
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800756 const XGL_PIPELINE_SHADER *shader =
757 (const XGL_PIPELINE_SHADER *) (header + 1);
Chia-I Wu3efef432014-08-28 15:00:16 +0800758
759 src = (const void *) shader;
760 size = sizeof(*shader);
761
762 switch (shader->stage) {
763 case XGL_SHADER_STAGE_VERTEX:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800764 dst = &info->vs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800765 break;
766 case XGL_SHADER_STAGE_TESS_CONTROL:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800767 dst = &info->tcs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800768 break;
769 case XGL_SHADER_STAGE_TESS_EVALUATION:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800770 dst = &info->tes;
Chia-I Wu3efef432014-08-28 15:00:16 +0800771 break;
772 case XGL_SHADER_STAGE_GEOMETRY:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800773 dst = &info->gs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800774 break;
775 case XGL_SHADER_STAGE_FRAGMENT:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800776 dst = &info->fs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800777 break;
778 case XGL_SHADER_STAGE_COMPUTE:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800779 dst = &info->cs;
Chia-I Wu3efef432014-08-28 15:00:16 +0800780 break;
781 default:
782 return XGL_ERROR_BAD_PIPELINE_DATA;
783 break;
784 }
785 }
786 break;
787 case XGL_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800788 size = sizeof(info->compute);
789 dst = &info->compute;
Chia-I Wu3efef432014-08-28 15:00:16 +0800790 break;
791 default:
792 return XGL_ERROR_BAD_PIPELINE_DATA;
793 break;
794 }
795
796 memcpy(dst, src, size);
797
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800798 header = header->next;
Chia-I Wu3efef432014-08-28 15:00:16 +0800799 }
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600800
801 return XGL_SUCCESS;
Chia-I Wu3efef432014-08-28 15:00:16 +0800802}
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600803
Chia-I Wu3efef432014-08-28 15:00:16 +0800804static XGL_RESULT graphics_pipeline_create(struct intel_dev *dev,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800805 const XGL_GRAPHICS_PIPELINE_CREATE_INFO *info_,
Chia-I Wu3efef432014-08-28 15:00:16 +0800806 struct intel_pipeline **pipeline_ret)
807{
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800808 struct intel_pipeline_create_info info;
Chia-I Wu3efef432014-08-28 15:00:16 +0800809 struct intel_pipeline *pipeline;
810 XGL_RESULT ret;
811
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800812 ret = pipeline_create_info_init(&info, dev->gpu,
813 (const struct intel_pipeline_create_info_header *) info_);
Chia-I Wu3efef432014-08-28 15:00:16 +0800814 if (ret != XGL_SUCCESS)
815 return ret;
816
817 pipeline = (struct intel_pipeline *)
818 intel_base_create(dev, sizeof(*pipeline), dev->base.dbg,
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800819 XGL_DBG_OBJECT_GRAPHICS_PIPELINE, info_, 0);
Chia-I Wu3efef432014-08-28 15:00:16 +0800820 if (!pipeline)
821 return XGL_ERROR_OUT_OF_MEMORY;
822
823 pipeline->dev = dev;
824 pipeline->obj.destroy = pipeline_destroy;
Chia-I Wu3efef432014-08-28 15:00:16 +0800825
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800826 ret = pipeline_build_all(pipeline, &info);
Chia-I Wu3efef432014-08-28 15:00:16 +0800827 if (ret == XGL_SUCCESS)
Chia-I Wuf90ff0c2014-09-02 09:32:46 +0800828 ret = pipeline_validate(pipeline);
Chia-I Wu3efef432014-08-28 15:00:16 +0800829 if (ret != XGL_SUCCESS) {
830 pipeline_destroy(&pipeline->obj);
831 return ret;
832 }
833
834 *pipeline_ret = pipeline;
835
836 return XGL_SUCCESS;
837}
838
839XGL_RESULT XGLAPI intelCreateGraphicsPipeline(
840 XGL_DEVICE device,
841 const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pCreateInfo,
842 XGL_PIPELINE* pPipeline)
843{
844 struct intel_dev *dev = intel_dev(device);
845
846 return graphics_pipeline_create(dev, pCreateInfo,
847 (struct intel_pipeline **) pPipeline);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600848}
849
850XGL_RESULT XGLAPI intelCreateComputePipeline(
851 XGL_DEVICE device,
852 const XGL_COMPUTE_PIPELINE_CREATE_INFO* pCreateInfo,
853 XGL_PIPELINE* pPipeline)
854{
855 return XGL_ERROR_UNAVAILABLE;
856}
857
858XGL_RESULT XGLAPI intelStorePipeline(
859 XGL_PIPELINE pipeline,
860 XGL_SIZE* pDataSize,
861 XGL_VOID* pData)
862{
863 return XGL_ERROR_UNAVAILABLE;
864}
865
866XGL_RESULT XGLAPI intelLoadPipeline(
867 XGL_DEVICE device,
868 XGL_SIZE dataSize,
869 const XGL_VOID* pData,
870 XGL_PIPELINE* pPipeline)
871{
872 return XGL_ERROR_UNAVAILABLE;
873}
874
875XGL_RESULT XGLAPI intelCreatePipelineDelta(
876 XGL_DEVICE device,
877 XGL_PIPELINE p1,
878 XGL_PIPELINE p2,
879 XGL_PIPELINE_DELTA* delta)
880{
881 return XGL_ERROR_UNAVAILABLE;
882}