blob: 329bdbaa54676c2666a6336aa0aa5e5094fd317a [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{
36 const XGL_UINT resource_offset = rmap->rt_count;
37 const XGL_UINT uav_offset = resource_offset + rmap->resource_count;
38 const XGL_UINT sampler_offset = uav_offset + rmap->uav_count;
Chia-I Wu20983762014-09-02 12:07:28 +080039 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080040
41 switch (type) {
42 case XGL_SLOT_UNUSED:
43 slot = NULL;
44 break;
45 case XGL_SLOT_SHADER_RESOURCE:
46 slot = &rmap->slots[resource_offset + index];
47 break;
48 case XGL_SLOT_SHADER_UAV:
49 slot = &rmap->slots[uav_offset + index];
50 break;
51 case XGL_SLOT_SHADER_SAMPLER:
52 slot = &rmap->slots[sampler_offset + index];
53 break;
54 default:
55 assert(!"unknown rmap slot type");
56 slot = NULL;
57 break;
58 }
59
60 return slot;
61}
62
Chia-I Wu20983762014-09-02 12:07:28 +080063static bool rmap_init_slots_with_path(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +080064 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
65 XGL_UINT *nest_path,
66 XGL_UINT nest_level)
67{
68 XGL_UINT i;
69
70 for (i = 0; i < mapping->descriptorCount; i++) {
71 const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i];
Chia-I Wu20983762014-09-02 12:07:28 +080072 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080073
74 if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) {
75 nest_path[nest_level] = i;
76 if (!rmap_init_slots_with_path(rmap, info->pNextLevelSet,
77 nest_path, nest_level + 1))
78 return false;
79
80 continue;
81 }
82
83 slot = rmap_get_slot(rmap, info->slotObjectType,
84 info->shaderEntityIndex);
85 if (!slot)
86 continue;
87
88 assert(!slot->path_len);
89 slot->path_len = nest_level + 1;
90
91 if (nest_level) {
92 slot->u.path = icd_alloc(sizeof(slot->u.path[0]) *
93 slot->path_len, 0, XGL_SYSTEM_ALLOC_INTERNAL);
94 if (!slot->u.path) {
95 slot->path_len = 0;
96 return false;
97 }
98
99 memcpy(slot->u.path, nest_path,
100 sizeof(slot->u.path[0]) * nest_level);
101 slot->u.path[nest_level] = i;
102 } else {
103 slot->u.index = i;
104 }
105 }
106
107 return true;
108}
109
Chia-I Wu20983762014-09-02 12:07:28 +0800110static bool rmap_init_slots(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800111 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
112 XGL_UINT depth)
113{
114 XGL_UINT *nest_path;
115 bool ok;
116
117 if (depth) {
118 nest_path = icd_alloc(sizeof(nest_path[0]) * depth,
119 0, XGL_SYSTEM_ALLOC_INTERNAL_TEMP);
120 if (!nest_path)
121 return false;
122 } else {
123 nest_path = NULL;
124 }
125
126 ok = rmap_init_slots_with_path(rmap, mapping, nest_path, 0);
127
128 if (nest_path)
129 icd_free(nest_path);
130
131 return ok;
132}
133
Chia-I Wu20983762014-09-02 12:07:28 +0800134static void rmap_update_count(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800135 XGL_DESCRIPTOR_SET_SLOT_TYPE type,
136 XGL_UINT index)
137{
138 switch (type) {
139 case XGL_SLOT_UNUSED:
140 break;
141 case XGL_SLOT_SHADER_RESOURCE:
142 if (rmap->resource_count < index + 1)
143 rmap->resource_count = index + 1;
144 break;
145 case XGL_SLOT_SHADER_UAV:
146 if (rmap->uav_count < index + 1)
147 rmap->uav_count = index + 1;
148 break;
149 case XGL_SLOT_SHADER_SAMPLER:
150 if (rmap->sampler_count < index + 1)
151 rmap->sampler_count = index + 1;
152 break;
153 default:
154 assert(!"unknown rmap slot type");
155 break;
156 }
157}
158
Chia-I Wu20983762014-09-02 12:07:28 +0800159static XGL_UINT rmap_init_counts(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800160 const XGL_DESCRIPTOR_SET_MAPPING *mapping)
161{
162 XGL_UINT depth = 0;
163 XGL_UINT i;
164
165 for (i = 0; i < mapping->descriptorCount; i++) {
166 const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i];
167
168 if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) {
169 const XGL_UINT d = rmap_init_counts(rmap,
170 info->pNextLevelSet);
171 if (depth < d + 1)
172 depth = d + 1;
173
174 continue;
175 }
176
177 rmap_update_count(rmap, info->slotObjectType,
178 info->shaderEntityIndex);
179 }
180
181 return depth;
182}
183
Chia-I Wu20983762014-09-02 12:07:28 +0800184static void rmap_destroy(struct intel_pipeline_rmap *rmap)
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800185{
186 XGL_UINT i;
187
188 for (i = 0; i < rmap->slot_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +0800189 struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800190
191 switch (slot->path_len) {
192 case 0:
193 case 1:
Chia-I Wu20983762014-09-02 12:07:28 +0800194 case INTEL_PIPELINE_RMAP_SLOT_RT:
195 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800196 break;
197 default:
198 icd_free(slot->u.path);
199 break;
200 }
201 }
202
203 icd_free(rmap->slots);
204 icd_free(rmap);
205}
206
Chia-I Wu20983762014-09-02 12:07:28 +0800207static struct intel_pipeline_rmap *rmap_create(struct intel_dev *dev,
208 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
209 const XGL_DYNAMIC_MEMORY_VIEW_SLOT_INFO *dyn,
210 XGL_UINT rt_count)
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800211{
Chia-I Wu20983762014-09-02 12:07:28 +0800212 struct intel_pipeline_rmap *rmap;
213 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800214 XGL_UINT depth, rt;
215
216 rmap = icd_alloc(sizeof(*rmap), 0, XGL_SYSTEM_ALLOC_INTERNAL);
217 if (!rmap)
218 return NULL;
219
220 memset(rmap, 0, sizeof(*rmap));
221
222 depth = rmap_init_counts(rmap, mapping);
223
224 /* add RTs and the dynamic memory view */
225 rmap_update_count(rmap, dyn->slotObjectType, dyn->shaderEntityIndex);
226 rmap->rt_count = rt_count;
227
228 rmap->slot_count = rmap->rt_count + rmap->resource_count +
Chia-I Wu3b04af52014-11-08 10:48:20 +0800229 rmap->uav_count + rmap->sampler_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800230
231 rmap->slots = icd_alloc(sizeof(rmap->slots[0]) * rmap->slot_count,
232 0, XGL_SYSTEM_ALLOC_INTERNAL);
233 if (!rmap->slots) {
234 icd_free(rmap);
235 return NULL;
236 }
237
238 memset(rmap->slots, 0, sizeof(rmap->slots[0]) * rmap->slot_count);
239
240 if (!rmap_init_slots(rmap, mapping, depth)) {
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800241 rmap_destroy(rmap);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800242 return NULL;
243 }
244
245 /* add RTs and the dynamic memory view */
246 slot = rmap_get_slot(rmap, dyn->slotObjectType, dyn->shaderEntityIndex);
247 if (slot) {
Chia-I Wu20983762014-09-02 12:07:28 +0800248 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_DYN;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800249 slot->u.index = 0;
250 }
251 for (rt = 0; rt < rmap->rt_count; rt++) {
252 slot = &rmap->slots[rt];
Chia-I Wu20983762014-09-02 12:07:28 +0800253 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_RT;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800254 slot->u.index = rt;
255 }
256
257 return rmap;
258}
259
Chia-I Wu39026c92014-09-02 10:03:19 +0800260static XGL_RESULT pipeline_build_vs(struct intel_pipeline *pipeline,
261 const struct intel_pipeline_create_info *info)
262{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800263 struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800264 XGL_RESULT ret;
265
Chia-I Wu46809782014-10-07 15:40:38 +0800266 assert(!info->vs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800267
Cody Northrop83e2b032014-09-25 17:00:31 -0600268 // Right here, lower the IR to ISA using NOS
269 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800270 ret = intel_pipeline_shader_compile(vs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800271 intel_shader(info->vs.shader)->ir);
Cody Northrop83e2b032014-09-25 17:00:31 -0600272 if (ret != XGL_SUCCESS)
273 return ret;
274
Chia-I Wu39026c92014-09-02 10:03:19 +0800275 vs->rmap = rmap_create(pipeline->dev,
276 &info->vs.descriptorSetMapping[0],
277 &info->vs.dynamicMemoryViewMapping, 0);
278 if (!vs->rmap) {
279 icd_free(vs->pCode);
280 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wu98824592014-09-02 09:42:46 +0800281 }
282
Chia-I Wu39026c92014-09-02 10:03:19 +0800283 pipeline->active_shaders |= SHADER_VERTEX_FLAG;
284
285 return XGL_SUCCESS;
286}
287
288static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline,
289 const struct intel_pipeline_create_info *info)
290{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800291 struct intel_pipeline_shader *tcs = &pipeline->tcs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800292 XGL_RESULT ret;
293
Chia-I Wu714f0a32014-10-11 14:08:15 +0800294 ret = intel_pipeline_shader_compile(tcs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800295 intel_shader(info->tcs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800296 if (ret != XGL_SUCCESS)
297 return ret;
298
Chia-I Wu46809782014-10-07 15:40:38 +0800299 assert(!info->tcs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800300
Chia-I Wu39026c92014-09-02 10:03:19 +0800301 pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG;
302
303 return XGL_SUCCESS;
304}
305
306static XGL_RESULT pipeline_build_tes(struct intel_pipeline *pipeline,
307 const struct intel_pipeline_create_info *info)
308{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800309 struct intel_pipeline_shader *tes = &pipeline->tes;
Chia-I Wu39026c92014-09-02 10:03:19 +0800310 XGL_RESULT ret;
311
Chia-I Wu714f0a32014-10-11 14:08:15 +0800312 ret = intel_pipeline_shader_compile(tes, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800313 intel_shader(info->tes.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800314 if (ret != XGL_SUCCESS)
315 return ret;
316
Chia-I Wu46809782014-10-07 15:40:38 +0800317 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800318
Chia-I Wu39026c92014-09-02 10:03:19 +0800319 pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG;
320
321 return XGL_SUCCESS;
322}
323
324static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline,
325 const struct intel_pipeline_create_info *info)
326{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800327 struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800328 XGL_RESULT ret;
329
Chia-I Wu714f0a32014-10-11 14:08:15 +0800330 ret = intel_pipeline_shader_compile(gs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800331 intel_shader(info->gs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800332 if (ret != XGL_SUCCESS)
333 return ret;
334
Chia-I Wu46809782014-10-07 15:40:38 +0800335 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800336
Chia-I Wu39026c92014-09-02 10:03:19 +0800337 pipeline->active_shaders |= SHADER_GEOMETRY_FLAG;
338
339 return XGL_SUCCESS;
340}
341
Chia-I Wu787a05b2014-12-05 11:02:20 +0800342static int pipeline_get_last_color_attachment(const struct intel_pipeline *pipeline,
343 const struct intel_pipeline_create_info *info)
344{
345 int idx;
346
347 for (idx = ARRAY_SIZE(info->cb.attachment) - 1; idx >= 0; idx--) {
348 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att =
349 &info->cb.attachment[idx];
350
351 if (!icd_format_is_undef(att->format))
352 break;
353 }
354
355 return idx;
356}
357
Chia-I Wu39026c92014-09-02 10:03:19 +0800358static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline,
359 const struct intel_pipeline_create_info *info)
360{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800361 struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu787a05b2014-12-05 11:02:20 +0800362 int rt_count;
Chia-I Wu39026c92014-09-02 10:03:19 +0800363 XGL_RESULT ret;
364
Chia-I Wu787a05b2014-12-05 11:02:20 +0800365 rt_count = pipeline_get_last_color_attachment(pipeline, info) + 1;
366 /* at least one NULL RT */
367 if (rt_count <= 0)
368 rt_count = 1;
369
Chia-I Wu46809782014-10-07 15:40:38 +0800370 assert(!info->fs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800371
Cody Northropbc851432014-09-23 10:06:32 -0600372 // Right here, lower the IR to ISA using NOS
Cody Northrop83e2b032014-09-25 17:00:31 -0600373 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800374 ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800375 intel_shader(info->fs.shader)->ir);
Cody Northropbc851432014-09-23 10:06:32 -0600376 if (ret != XGL_SUCCESS)
377 return ret;
378
Chia-I Wu39026c92014-09-02 10:03:19 +0800379 fs->rmap = rmap_create(pipeline->dev,
380 &info->fs.descriptorSetMapping[0],
Chia-I Wu787a05b2014-12-05 11:02:20 +0800381 &info->fs.dynamicMemoryViewMapping, rt_count);
Chia-I Wu39026c92014-09-02 10:03:19 +0800382 if (!fs->rmap) {
383 icd_free(fs->pCode);
384 return XGL_ERROR_OUT_OF_MEMORY;
385 }
386
Chia-I Wu39026c92014-09-02 10:03:19 +0800387 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
388
389 return XGL_SUCCESS;
390}
391
392static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline,
393 const struct intel_pipeline_create_info *info)
394{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800395 struct intel_pipeline_shader *cs = &pipeline->cs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800396 XGL_RESULT ret;
397
Chia-I Wu714f0a32014-10-11 14:08:15 +0800398 ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800399 intel_shader(info->compute.cs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800400 if (ret != XGL_SUCCESS)
401 return ret;
402
Chia-I Wu46809782014-10-07 15:40:38 +0800403 assert(!info->compute.cs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800404
Chia-I Wu39026c92014-09-02 10:03:19 +0800405 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
406
Chia-I Wu98824592014-09-02 09:42:46 +0800407 return XGL_SUCCESS;
408}
409
410XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
411 const struct intel_pipeline_create_info *info)
412{
413 XGL_RESULT ret = XGL_SUCCESS;
414
415 if (ret == XGL_SUCCESS && info->vs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800416 ret = pipeline_build_vs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800417 if (ret == XGL_SUCCESS && info->tcs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800418 ret = pipeline_build_tcs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800419 if (ret == XGL_SUCCESS && info->tes.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800420 ret = pipeline_build_tes(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800421 if (ret == XGL_SUCCESS && info->gs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800422 ret = pipeline_build_gs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800423 if (ret == XGL_SUCCESS && info->fs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800424 ret = pipeline_build_fs(pipeline, info);
425
426 if (ret == XGL_SUCCESS && info->compute.cs.shader)
427 ret = pipeline_build_cs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800428
429 return ret;
430}
431
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800432static void pipeline_tear_shader(struct intel_pipeline_shader *sh)
Chia-I Wu39026c92014-09-02 10:03:19 +0800433{
434 icd_free(sh->pCode);
435 if (sh->rmap)
436 rmap_destroy(sh->rmap);
437}
438
Chia-I Wu98824592014-09-02 09:42:46 +0800439void pipeline_tear_shaders(struct intel_pipeline *pipeline)
440{
441 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800442 pipeline_tear_shader(&pipeline->vs);
Chia-I Wu98824592014-09-02 09:42:46 +0800443 }
444
Chia-I Wu39026c92014-09-02 10:03:19 +0800445 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800446 pipeline_tear_shader(&pipeline->tcs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800447 }
448
449 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800450 pipeline_tear_shader(&pipeline->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800451 }
452
453 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
454 pipeline_tear_shader(&pipeline->gs);
455 }
456
457 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800458 pipeline_tear_shader(&pipeline->fs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800459 }
460
461 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800462 pipeline_tear_shader(&pipeline->cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800463 }
Chia-I Wu98824592014-09-02 09:42:46 +0800464}
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800465
466struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
467 enum intel_dev_meta_shader id)
468{
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800469 struct intel_pipeline_shader *sh;
Chia-I Wu005c47c2014-10-22 13:49:13 +0800470 XGL_RESULT ret;
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800471
472 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
473 if (!sh)
474 return NULL;
475 memset(sh, 0, sizeof(*sh));
476
Chia-I Wu005c47c2014-10-22 13:49:13 +0800477 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
478 if (ret != XGL_SUCCESS) {
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800479 icd_free(sh);
480 return NULL;
481 }
482
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800483 return sh;
484}
485
486void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
487{
488 if (sh->rmap)
489 rmap_destroy(sh->rmap);
490 if (sh->pCode)
491 icd_free(sh->pCode);
492 icd_free(sh);
493}