blob: a97f0b538c394b9bbc5eb2041d55abaf46d1172c [file] [log] [blame]
Chia-I Wu1f7540b2014-08-22 13:56:18 +08001/*
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 * Chia-I Wu <olv@lunarg.com>
Chia-I Wu1f7540b2014-08-22 13:56:18 +080026 */
27
Chia-I Wu98824592014-09-02 09:42:46 +080028#include "shader.h"
Chia-I Wu1f7540b2014-08-22 13:56:18 +080029#include "pipeline_priv.h"
Cody Northropbc851432014-09-23 10:06:32 -060030#include "compiler/pipeline/pipeline_compiler_interface.h"
Chia-I Wu1f7540b2014-08-22 13:56:18 +080031
Chia-I Wu20983762014-09-02 12:07:28 +080032static struct intel_pipeline_rmap_slot *rmap_get_slot(struct intel_pipeline_rmap *rmap,
33 XGL_DESCRIPTOR_SET_SLOT_TYPE type,
34 XGL_UINT index)
Chia-I Wu1f7540b2014-08-22 13:56:18 +080035{
Cody Northrop40316a32014-12-09 19:08:33 -070036 // The ordering of below offsets is important. Textures need to come before
37 // buffers with the current compiler conventions.
38 const XGL_UINT texture_resource_offset = rmap->rt_count;
39 const XGL_UINT resource_offset = texture_resource_offset + rmap->texture_resource_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080040 const XGL_UINT uav_offset = resource_offset + rmap->resource_count;
41 const XGL_UINT sampler_offset = uav_offset + rmap->uav_count;
Chia-I Wu20983762014-09-02 12:07:28 +080042 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080043
44 switch (type) {
45 case XGL_SLOT_UNUSED:
46 slot = NULL;
47 break;
Cody Northrop40316a32014-12-09 19:08:33 -070048 case XGL_SLOT_SHADER_TEXTURE_RESOURCE:
49 slot = &rmap->slots[texture_resource_offset + index];
50 break;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080051 case XGL_SLOT_SHADER_RESOURCE:
52 slot = &rmap->slots[resource_offset + index];
53 break;
54 case XGL_SLOT_SHADER_UAV:
55 slot = &rmap->slots[uav_offset + index];
56 break;
57 case XGL_SLOT_SHADER_SAMPLER:
58 slot = &rmap->slots[sampler_offset + index];
59 break;
60 default:
61 assert(!"unknown rmap slot type");
62 slot = NULL;
63 break;
64 }
65
66 return slot;
67}
68
Chia-I Wu20983762014-09-02 12:07:28 +080069static bool rmap_init_slots_with_path(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +080070 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
71 XGL_UINT *nest_path,
72 XGL_UINT nest_level)
73{
74 XGL_UINT i;
75
76 for (i = 0; i < mapping->descriptorCount; i++) {
77 const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i];
Chia-I Wu20983762014-09-02 12:07:28 +080078 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080079
80 if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) {
81 nest_path[nest_level] = i;
82 if (!rmap_init_slots_with_path(rmap, info->pNextLevelSet,
83 nest_path, nest_level + 1))
84 return false;
85
86 continue;
87 }
88
89 slot = rmap_get_slot(rmap, info->slotObjectType,
90 info->shaderEntityIndex);
Cody Northrope65465a2014-12-10 08:38:23 -070091 if (!slot || slot->path_len)
Chia-I Wu1f7540b2014-08-22 13:56:18 +080092 continue;
93
Chia-I Wu1f7540b2014-08-22 13:56:18 +080094 slot->path_len = nest_level + 1;
95
96 if (nest_level) {
97 slot->u.path = icd_alloc(sizeof(slot->u.path[0]) *
98 slot->path_len, 0, XGL_SYSTEM_ALLOC_INTERNAL);
99 if (!slot->u.path) {
100 slot->path_len = 0;
101 return false;
102 }
103
104 memcpy(slot->u.path, nest_path,
105 sizeof(slot->u.path[0]) * nest_level);
106 slot->u.path[nest_level] = i;
107 } else {
108 slot->u.index = i;
109 }
110 }
111
112 return true;
113}
114
Chia-I Wu20983762014-09-02 12:07:28 +0800115static bool rmap_init_slots(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800116 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
117 XGL_UINT depth)
118{
119 XGL_UINT *nest_path;
120 bool ok;
121
122 if (depth) {
123 nest_path = icd_alloc(sizeof(nest_path[0]) * depth,
124 0, XGL_SYSTEM_ALLOC_INTERNAL_TEMP);
125 if (!nest_path)
126 return false;
127 } else {
128 nest_path = NULL;
129 }
130
131 ok = rmap_init_slots_with_path(rmap, mapping, nest_path, 0);
132
133 if (nest_path)
134 icd_free(nest_path);
135
136 return ok;
137}
138
Chia-I Wu20983762014-09-02 12:07:28 +0800139static void rmap_update_count(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800140 XGL_DESCRIPTOR_SET_SLOT_TYPE type,
Cody Northrope65465a2014-12-10 08:38:23 -0700141 XGL_UINT index, XGL_UINT rt_count, XGL_UINT ubo_start)
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800142{
Cody Northrope65465a2014-12-10 08:38:23 -0700143 rmap->rt_count = rt_count;
144
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800145 switch (type) {
146 case XGL_SLOT_UNUSED:
147 break;
Cody Northrop40316a32014-12-09 19:08:33 -0700148 case XGL_SLOT_SHADER_TEXTURE_RESOURCE:
149 if (rmap->texture_resource_count < index + 1)
Cody Northrope65465a2014-12-10 08:38:23 -0700150 if (index < ubo_start - rt_count)
151 rmap->texture_resource_count = index + 1;
Cody Northrop40316a32014-12-09 19:08:33 -0700152 break;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800153 case XGL_SLOT_SHADER_RESOURCE:
154 if (rmap->resource_count < index + 1)
155 rmap->resource_count = index + 1;
156 break;
157 case XGL_SLOT_SHADER_UAV:
158 if (rmap->uav_count < index + 1)
159 rmap->uav_count = index + 1;
160 break;
161 case XGL_SLOT_SHADER_SAMPLER:
162 if (rmap->sampler_count < index + 1)
163 rmap->sampler_count = index + 1;
164 break;
165 default:
166 assert(!"unknown rmap slot type");
167 break;
168 }
169}
170
Chia-I Wu20983762014-09-02 12:07:28 +0800171static XGL_UINT rmap_init_counts(struct intel_pipeline_rmap *rmap,
Cody Northrope65465a2014-12-10 08:38:23 -0700172 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
173 XGL_UINT rt_count, XGL_UINT ubo_start)
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800174{
175 XGL_UINT depth = 0;
176 XGL_UINT i;
177
178 for (i = 0; i < mapping->descriptorCount; i++) {
179 const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i];
180
181 if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) {
182 const XGL_UINT d = rmap_init_counts(rmap,
Cody Northrope65465a2014-12-10 08:38:23 -0700183 info->pNextLevelSet, rt_count, ubo_start);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800184 if (depth < d + 1)
185 depth = d + 1;
186
187 continue;
188 }
189
190 rmap_update_count(rmap, info->slotObjectType,
Cody Northrope65465a2014-12-10 08:38:23 -0700191 info->shaderEntityIndex, rt_count, ubo_start);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800192 }
193
194 return depth;
195}
196
Chia-I Wu20983762014-09-02 12:07:28 +0800197static void rmap_destroy(struct intel_pipeline_rmap *rmap)
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800198{
199 XGL_UINT i;
200
201 for (i = 0; i < rmap->slot_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +0800202 struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800203
204 switch (slot->path_len) {
205 case 0:
206 case 1:
Chia-I Wu20983762014-09-02 12:07:28 +0800207 case INTEL_PIPELINE_RMAP_SLOT_RT:
208 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800209 break;
210 default:
211 icd_free(slot->u.path);
212 break;
213 }
214 }
215
216 icd_free(rmap->slots);
217 icd_free(rmap);
218}
219
Chia-I Wu20983762014-09-02 12:07:28 +0800220static struct intel_pipeline_rmap *rmap_create(struct intel_dev *dev,
221 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
222 const XGL_DYNAMIC_MEMORY_VIEW_SLOT_INFO *dyn,
Cody Northrope65465a2014-12-10 08:38:23 -0700223 XGL_UINT rt_count, XGL_UINT ubo_start)
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800224{
Chia-I Wu20983762014-09-02 12:07:28 +0800225 struct intel_pipeline_rmap *rmap;
226 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800227 XGL_UINT depth, rt;
228
229 rmap = icd_alloc(sizeof(*rmap), 0, XGL_SYSTEM_ALLOC_INTERNAL);
230 if (!rmap)
231 return NULL;
232
233 memset(rmap, 0, sizeof(*rmap));
234
Cody Northrope65465a2014-12-10 08:38:23 -0700235 depth = rmap_init_counts(rmap, mapping, rt_count, ubo_start);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800236
237 /* add RTs and the dynamic memory view */
Cody Northrope65465a2014-12-10 08:38:23 -0700238 rmap_update_count(rmap, dyn->slotObjectType, dyn->shaderEntityIndex, rt_count, ubo_start);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800239
Cody Northrop40316a32014-12-09 19:08:33 -0700240 rmap->slot_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count +
Chia-I Wu3b04af52014-11-08 10:48:20 +0800241 rmap->uav_count + rmap->sampler_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800242
243 rmap->slots = icd_alloc(sizeof(rmap->slots[0]) * rmap->slot_count,
244 0, XGL_SYSTEM_ALLOC_INTERNAL);
245 if (!rmap->slots) {
246 icd_free(rmap);
247 return NULL;
248 }
249
250 memset(rmap->slots, 0, sizeof(rmap->slots[0]) * rmap->slot_count);
251
252 if (!rmap_init_slots(rmap, mapping, depth)) {
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800253 rmap_destroy(rmap);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800254 return NULL;
255 }
256
257 /* add RTs and the dynamic memory view */
258 slot = rmap_get_slot(rmap, dyn->slotObjectType, dyn->shaderEntityIndex);
259 if (slot) {
Chia-I Wu20983762014-09-02 12:07:28 +0800260 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_DYN;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800261 slot->u.index = 0;
262 }
263 for (rt = 0; rt < rmap->rt_count; rt++) {
264 slot = &rmap->slots[rt];
Chia-I Wu20983762014-09-02 12:07:28 +0800265 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_RT;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800266 slot->u.index = rt;
267 }
268
269 return rmap;
270}
271
Chia-I Wu39026c92014-09-02 10:03:19 +0800272static XGL_RESULT pipeline_build_vs(struct intel_pipeline *pipeline,
273 const struct intel_pipeline_create_info *info)
274{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800275 struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800276 XGL_RESULT ret;
277
Chia-I Wu46809782014-10-07 15:40:38 +0800278 assert(!info->vs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800279
Cody Northrop83e2b032014-09-25 17:00:31 -0600280 // Right here, lower the IR to ISA using NOS
281 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800282 ret = intel_pipeline_shader_compile(vs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800283 intel_shader(info->vs.shader)->ir);
Cody Northrop83e2b032014-09-25 17:00:31 -0600284 if (ret != XGL_SUCCESS)
285 return ret;
286
Chia-I Wu39026c92014-09-02 10:03:19 +0800287 vs->rmap = rmap_create(pipeline->dev,
288 &info->vs.descriptorSetMapping[0],
Cody Northrope65465a2014-12-10 08:38:23 -0700289 &info->vs.dynamicMemoryViewMapping, 0, vs->ubo_start);
Chia-I Wu39026c92014-09-02 10:03:19 +0800290 if (!vs->rmap) {
291 icd_free(vs->pCode);
292 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wu98824592014-09-02 09:42:46 +0800293 }
294
Cody Northrop37c47052014-12-11 09:58:50 -0700295 // Ensure that all textures in descriptor set were consumed
296 // This is temporary until we move resource map building to compiler
297 assert(vs->ubo_start == vs->rmap->texture_resource_count);
298
Chia-I Wu39026c92014-09-02 10:03:19 +0800299 pipeline->active_shaders |= SHADER_VERTEX_FLAG;
300
301 return XGL_SUCCESS;
302}
303
304static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline,
305 const struct intel_pipeline_create_info *info)
306{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800307 struct intel_pipeline_shader *tcs = &pipeline->tcs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800308 XGL_RESULT ret;
309
Chia-I Wu714f0a32014-10-11 14:08:15 +0800310 ret = intel_pipeline_shader_compile(tcs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800311 intel_shader(info->tcs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800312 if (ret != XGL_SUCCESS)
313 return ret;
314
Chia-I Wu46809782014-10-07 15:40:38 +0800315 assert(!info->tcs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800316
Chia-I Wu39026c92014-09-02 10:03:19 +0800317 pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG;
318
319 return XGL_SUCCESS;
320}
321
322static XGL_RESULT pipeline_build_tes(struct intel_pipeline *pipeline,
323 const struct intel_pipeline_create_info *info)
324{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800325 struct intel_pipeline_shader *tes = &pipeline->tes;
Chia-I Wu39026c92014-09-02 10:03:19 +0800326 XGL_RESULT ret;
327
Chia-I Wu714f0a32014-10-11 14:08:15 +0800328 ret = intel_pipeline_shader_compile(tes, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800329 intel_shader(info->tes.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800330 if (ret != XGL_SUCCESS)
331 return ret;
332
Chia-I Wu46809782014-10-07 15:40:38 +0800333 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800334
Chia-I Wu39026c92014-09-02 10:03:19 +0800335 pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG;
336
337 return XGL_SUCCESS;
338}
339
340static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline,
341 const struct intel_pipeline_create_info *info)
342{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800343 struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800344 XGL_RESULT ret;
345
Chia-I Wu714f0a32014-10-11 14:08:15 +0800346 ret = intel_pipeline_shader_compile(gs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800347 intel_shader(info->gs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800348 if (ret != XGL_SUCCESS)
349 return ret;
350
Chia-I Wu46809782014-10-07 15:40:38 +0800351 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800352
Chia-I Wu39026c92014-09-02 10:03:19 +0800353 pipeline->active_shaders |= SHADER_GEOMETRY_FLAG;
354
355 return XGL_SUCCESS;
356}
357
Chia-I Wu787a05b2014-12-05 11:02:20 +0800358static int pipeline_get_last_color_attachment(const struct intel_pipeline *pipeline,
359 const struct intel_pipeline_create_info *info)
360{
361 int idx;
362
363 for (idx = ARRAY_SIZE(info->cb.attachment) - 1; idx >= 0; idx--) {
364 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att =
365 &info->cb.attachment[idx];
366
367 if (!icd_format_is_undef(att->format))
368 break;
369 }
370
371 return idx;
372}
373
Chia-I Wu39026c92014-09-02 10:03:19 +0800374static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline,
375 const struct intel_pipeline_create_info *info)
376{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800377 struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu787a05b2014-12-05 11:02:20 +0800378 int rt_count;
Chia-I Wu39026c92014-09-02 10:03:19 +0800379 XGL_RESULT ret;
380
Chia-I Wu787a05b2014-12-05 11:02:20 +0800381 rt_count = pipeline_get_last_color_attachment(pipeline, info) + 1;
382 /* at least one NULL RT */
383 if (rt_count <= 0)
384 rt_count = 1;
385
Chia-I Wu46809782014-10-07 15:40:38 +0800386 assert(!info->fs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800387
Cody Northropbc851432014-09-23 10:06:32 -0600388 // Right here, lower the IR to ISA using NOS
Cody Northrop83e2b032014-09-25 17:00:31 -0600389 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800390 ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800391 intel_shader(info->fs.shader)->ir);
Cody Northropbc851432014-09-23 10:06:32 -0600392 if (ret != XGL_SUCCESS)
393 return ret;
394
Chia-I Wu39026c92014-09-02 10:03:19 +0800395 fs->rmap = rmap_create(pipeline->dev,
396 &info->fs.descriptorSetMapping[0],
Cody Northrope65465a2014-12-10 08:38:23 -0700397 &info->fs.dynamicMemoryViewMapping, rt_count, fs->ubo_start);
Chia-I Wu39026c92014-09-02 10:03:19 +0800398 if (!fs->rmap) {
399 icd_free(fs->pCode);
400 return XGL_ERROR_OUT_OF_MEMORY;
401 }
402
Cody Northrop37c47052014-12-11 09:58:50 -0700403 // Ensure that all textures in descriptor set were consumed
404 // This is temporary until we move resource map building to compiler
405 assert(fs->ubo_start == fs->rmap->texture_resource_count + fs->rmap->rt_count);
406
Chia-I Wu39026c92014-09-02 10:03:19 +0800407 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
408
409 return XGL_SUCCESS;
410}
411
412static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline,
413 const struct intel_pipeline_create_info *info)
414{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800415 struct intel_pipeline_shader *cs = &pipeline->cs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800416 XGL_RESULT ret;
417
Chia-I Wu714f0a32014-10-11 14:08:15 +0800418 ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800419 intel_shader(info->compute.cs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800420 if (ret != XGL_SUCCESS)
421 return ret;
422
Chia-I Wu46809782014-10-07 15:40:38 +0800423 assert(!info->compute.cs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800424
Chia-I Wu39026c92014-09-02 10:03:19 +0800425 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
426
Chia-I Wu98824592014-09-02 09:42:46 +0800427 return XGL_SUCCESS;
428}
429
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800430static void pipeline_post_build_shader(struct intel_pipeline *pipeline,
431 struct intel_pipeline_shader *sh,
432 const XGL_PIPELINE_SHADER *sh_info)
433{
434 sh->max_threads =
435 intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage);
436}
437
Chia-I Wu98824592014-09-02 09:42:46 +0800438XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
439 const struct intel_pipeline_create_info *info)
440{
441 XGL_RESULT ret = XGL_SUCCESS;
442
443 if (ret == XGL_SUCCESS && info->vs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800444 ret = pipeline_build_vs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800445 if (ret == XGL_SUCCESS && info->tcs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800446 ret = pipeline_build_tcs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800447 if (ret == XGL_SUCCESS && info->tes.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800448 ret = pipeline_build_tes(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800449 if (ret == XGL_SUCCESS && info->gs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800450 ret = pipeline_build_gs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800451 if (ret == XGL_SUCCESS && info->fs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800452 ret = pipeline_build_fs(pipeline, info);
453
454 if (ret == XGL_SUCCESS && info->compute.cs.shader)
455 ret = pipeline_build_cs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800456
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800457 if (pipeline->active_shaders & SHADER_VERTEX_FLAG)
458 pipeline_post_build_shader(pipeline, &pipeline->vs, &info->vs);
459 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG)
460 pipeline_post_build_shader(pipeline, &pipeline->tcs, &info->tcs);
461 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG)
462 pipeline_post_build_shader(pipeline, &pipeline->tes, &info->tes);
463 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG)
464 pipeline_post_build_shader(pipeline, &pipeline->gs, &info->gs);
465 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG)
466 pipeline_post_build_shader(pipeline, &pipeline->fs, &info->fs);
467 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG)
468 pipeline_post_build_shader(pipeline, &pipeline->cs, &info->compute.cs);
469
Chia-I Wu98824592014-09-02 09:42:46 +0800470 return ret;
471}
472
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800473static void pipeline_tear_shader(struct intel_pipeline_shader *sh)
Chia-I Wu39026c92014-09-02 10:03:19 +0800474{
475 icd_free(sh->pCode);
476 if (sh->rmap)
477 rmap_destroy(sh->rmap);
478}
479
Chia-I Wu98824592014-09-02 09:42:46 +0800480void pipeline_tear_shaders(struct intel_pipeline *pipeline)
481{
482 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800483 pipeline_tear_shader(&pipeline->vs);
Chia-I Wu98824592014-09-02 09:42:46 +0800484 }
485
Chia-I Wu39026c92014-09-02 10:03:19 +0800486 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800487 pipeline_tear_shader(&pipeline->tcs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800488 }
489
490 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800491 pipeline_tear_shader(&pipeline->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800492 }
493
494 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
495 pipeline_tear_shader(&pipeline->gs);
496 }
497
498 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800499 pipeline_tear_shader(&pipeline->fs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800500 }
501
502 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800503 pipeline_tear_shader(&pipeline->cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800504 }
Chia-I Wu98824592014-09-02 09:42:46 +0800505}
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800506
507struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
508 enum intel_dev_meta_shader id)
509{
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800510 struct intel_pipeline_shader *sh;
Chia-I Wu005c47c2014-10-22 13:49:13 +0800511 XGL_RESULT ret;
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800512
513 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
514 if (!sh)
515 return NULL;
516 memset(sh, 0, sizeof(*sh));
517
Chia-I Wu005c47c2014-10-22 13:49:13 +0800518 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
519 if (ret != XGL_SUCCESS) {
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800520 icd_free(sh);
521 return NULL;
522 }
523
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800524 switch (id) {
525 case INTEL_DEV_META_VS_FILL_MEM:
526 case INTEL_DEV_META_VS_COPY_MEM:
527 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
528 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
529 XGL_SHADER_STAGE_VERTEX);
530 break;
531 default:
532 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
533 XGL_SHADER_STAGE_FRAGMENT);
534 break;
535 }
536
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800537 return sh;
538}
539
540void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
541{
542 if (sh->rmap)
543 rmap_destroy(sh->rmap);
544 if (sh->pCode)
545 icd_free(sh->pCode);
546 icd_free(sh);
547}