blob: b66c00f2adcaec30035564631ed0c04db47fd136 [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);
91 if (!slot)
92 continue;
93
94 assert(!slot->path_len);
95 slot->path_len = nest_level + 1;
96
97 if (nest_level) {
98 slot->u.path = icd_alloc(sizeof(slot->u.path[0]) *
99 slot->path_len, 0, XGL_SYSTEM_ALLOC_INTERNAL);
100 if (!slot->u.path) {
101 slot->path_len = 0;
102 return false;
103 }
104
105 memcpy(slot->u.path, nest_path,
106 sizeof(slot->u.path[0]) * nest_level);
107 slot->u.path[nest_level] = i;
108 } else {
109 slot->u.index = i;
110 }
111 }
112
113 return true;
114}
115
Chia-I Wu20983762014-09-02 12:07:28 +0800116static bool rmap_init_slots(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800117 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
118 XGL_UINT depth)
119{
120 XGL_UINT *nest_path;
121 bool ok;
122
123 if (depth) {
124 nest_path = icd_alloc(sizeof(nest_path[0]) * depth,
125 0, XGL_SYSTEM_ALLOC_INTERNAL_TEMP);
126 if (!nest_path)
127 return false;
128 } else {
129 nest_path = NULL;
130 }
131
132 ok = rmap_init_slots_with_path(rmap, mapping, nest_path, 0);
133
134 if (nest_path)
135 icd_free(nest_path);
136
137 return ok;
138}
139
Chia-I Wu20983762014-09-02 12:07:28 +0800140static void rmap_update_count(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800141 XGL_DESCRIPTOR_SET_SLOT_TYPE type,
142 XGL_UINT index)
143{
144 switch (type) {
145 case XGL_SLOT_UNUSED:
146 break;
Cody Northrop40316a32014-12-09 19:08:33 -0700147 case XGL_SLOT_SHADER_TEXTURE_RESOURCE:
148 if (rmap->texture_resource_count < index + 1)
149 rmap->texture_resource_count = index + 1;
150 break;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800151 case XGL_SLOT_SHADER_RESOURCE:
152 if (rmap->resource_count < index + 1)
153 rmap->resource_count = index + 1;
154 break;
155 case XGL_SLOT_SHADER_UAV:
156 if (rmap->uav_count < index + 1)
157 rmap->uav_count = index + 1;
158 break;
159 case XGL_SLOT_SHADER_SAMPLER:
160 if (rmap->sampler_count < index + 1)
161 rmap->sampler_count = index + 1;
162 break;
163 default:
164 assert(!"unknown rmap slot type");
165 break;
166 }
167}
168
Chia-I Wu20983762014-09-02 12:07:28 +0800169static XGL_UINT rmap_init_counts(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800170 const XGL_DESCRIPTOR_SET_MAPPING *mapping)
171{
172 XGL_UINT depth = 0;
173 XGL_UINT i;
174
175 for (i = 0; i < mapping->descriptorCount; i++) {
176 const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i];
177
178 if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) {
179 const XGL_UINT d = rmap_init_counts(rmap,
180 info->pNextLevelSet);
181 if (depth < d + 1)
182 depth = d + 1;
183
184 continue;
185 }
186
187 rmap_update_count(rmap, info->slotObjectType,
188 info->shaderEntityIndex);
189 }
190
191 return depth;
192}
193
Chia-I Wu20983762014-09-02 12:07:28 +0800194static void rmap_destroy(struct intel_pipeline_rmap *rmap)
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800195{
196 XGL_UINT i;
197
198 for (i = 0; i < rmap->slot_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +0800199 struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800200
201 switch (slot->path_len) {
202 case 0:
203 case 1:
Chia-I Wu20983762014-09-02 12:07:28 +0800204 case INTEL_PIPELINE_RMAP_SLOT_RT:
205 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800206 break;
207 default:
208 icd_free(slot->u.path);
209 break;
210 }
211 }
212
213 icd_free(rmap->slots);
214 icd_free(rmap);
215}
216
Chia-I Wu20983762014-09-02 12:07:28 +0800217static struct intel_pipeline_rmap *rmap_create(struct intel_dev *dev,
218 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
219 const XGL_DYNAMIC_MEMORY_VIEW_SLOT_INFO *dyn,
220 XGL_UINT rt_count)
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800221{
Chia-I Wu20983762014-09-02 12:07:28 +0800222 struct intel_pipeline_rmap *rmap;
223 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800224 XGL_UINT depth, rt;
225
226 rmap = icd_alloc(sizeof(*rmap), 0, XGL_SYSTEM_ALLOC_INTERNAL);
227 if (!rmap)
228 return NULL;
229
230 memset(rmap, 0, sizeof(*rmap));
231
232 depth = rmap_init_counts(rmap, mapping);
233
234 /* add RTs and the dynamic memory view */
235 rmap_update_count(rmap, dyn->slotObjectType, dyn->shaderEntityIndex);
236 rmap->rt_count = rt_count;
237
Cody Northrop40316a32014-12-09 19:08:33 -0700238 rmap->slot_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count +
Chia-I Wu3b04af52014-11-08 10:48:20 +0800239 rmap->uav_count + rmap->sampler_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800240
241 rmap->slots = icd_alloc(sizeof(rmap->slots[0]) * rmap->slot_count,
242 0, XGL_SYSTEM_ALLOC_INTERNAL);
243 if (!rmap->slots) {
244 icd_free(rmap);
245 return NULL;
246 }
247
248 memset(rmap->slots, 0, sizeof(rmap->slots[0]) * rmap->slot_count);
249
250 if (!rmap_init_slots(rmap, mapping, depth)) {
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800251 rmap_destroy(rmap);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800252 return NULL;
253 }
254
255 /* add RTs and the dynamic memory view */
256 slot = rmap_get_slot(rmap, dyn->slotObjectType, dyn->shaderEntityIndex);
257 if (slot) {
Chia-I Wu20983762014-09-02 12:07:28 +0800258 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_DYN;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800259 slot->u.index = 0;
260 }
261 for (rt = 0; rt < rmap->rt_count; rt++) {
262 slot = &rmap->slots[rt];
Chia-I Wu20983762014-09-02 12:07:28 +0800263 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_RT;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800264 slot->u.index = rt;
265 }
266
267 return rmap;
268}
269
Chia-I Wu39026c92014-09-02 10:03:19 +0800270static XGL_RESULT pipeline_build_vs(struct intel_pipeline *pipeline,
271 const struct intel_pipeline_create_info *info)
272{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800273 struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800274 XGL_RESULT ret;
275
Chia-I Wu46809782014-10-07 15:40:38 +0800276 assert(!info->vs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800277
Cody Northrop83e2b032014-09-25 17:00:31 -0600278 // Right here, lower the IR to ISA using NOS
279 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800280 ret = intel_pipeline_shader_compile(vs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800281 intel_shader(info->vs.shader)->ir);
Cody Northrop83e2b032014-09-25 17:00:31 -0600282 if (ret != XGL_SUCCESS)
283 return ret;
284
Chia-I Wu39026c92014-09-02 10:03:19 +0800285 vs->rmap = rmap_create(pipeline->dev,
286 &info->vs.descriptorSetMapping[0],
287 &info->vs.dynamicMemoryViewMapping, 0);
288 if (!vs->rmap) {
289 icd_free(vs->pCode);
290 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wu98824592014-09-02 09:42:46 +0800291 }
292
Chia-I Wu39026c92014-09-02 10:03:19 +0800293 pipeline->active_shaders |= SHADER_VERTEX_FLAG;
294
295 return XGL_SUCCESS;
296}
297
298static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline,
299 const struct intel_pipeline_create_info *info)
300{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800301 struct intel_pipeline_shader *tcs = &pipeline->tcs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800302 XGL_RESULT ret;
303
Chia-I Wu714f0a32014-10-11 14:08:15 +0800304 ret = intel_pipeline_shader_compile(tcs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800305 intel_shader(info->tcs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800306 if (ret != XGL_SUCCESS)
307 return ret;
308
Chia-I Wu46809782014-10-07 15:40:38 +0800309 assert(!info->tcs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800310
Chia-I Wu39026c92014-09-02 10:03:19 +0800311 pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG;
312
313 return XGL_SUCCESS;
314}
315
316static XGL_RESULT pipeline_build_tes(struct intel_pipeline *pipeline,
317 const struct intel_pipeline_create_info *info)
318{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800319 struct intel_pipeline_shader *tes = &pipeline->tes;
Chia-I Wu39026c92014-09-02 10:03:19 +0800320 XGL_RESULT ret;
321
Chia-I Wu714f0a32014-10-11 14:08:15 +0800322 ret = intel_pipeline_shader_compile(tes, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800323 intel_shader(info->tes.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800324 if (ret != XGL_SUCCESS)
325 return ret;
326
Chia-I Wu46809782014-10-07 15:40:38 +0800327 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800328
Chia-I Wu39026c92014-09-02 10:03:19 +0800329 pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG;
330
331 return XGL_SUCCESS;
332}
333
334static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline,
335 const struct intel_pipeline_create_info *info)
336{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800337 struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800338 XGL_RESULT ret;
339
Chia-I Wu714f0a32014-10-11 14:08:15 +0800340 ret = intel_pipeline_shader_compile(gs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800341 intel_shader(info->gs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800342 if (ret != XGL_SUCCESS)
343 return ret;
344
Chia-I Wu46809782014-10-07 15:40:38 +0800345 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800346
Chia-I Wu39026c92014-09-02 10:03:19 +0800347 pipeline->active_shaders |= SHADER_GEOMETRY_FLAG;
348
349 return XGL_SUCCESS;
350}
351
Chia-I Wu787a05b2014-12-05 11:02:20 +0800352static int pipeline_get_last_color_attachment(const struct intel_pipeline *pipeline,
353 const struct intel_pipeline_create_info *info)
354{
355 int idx;
356
357 for (idx = ARRAY_SIZE(info->cb.attachment) - 1; idx >= 0; idx--) {
358 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att =
359 &info->cb.attachment[idx];
360
361 if (!icd_format_is_undef(att->format))
362 break;
363 }
364
365 return idx;
366}
367
Chia-I Wu39026c92014-09-02 10:03:19 +0800368static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline,
369 const struct intel_pipeline_create_info *info)
370{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800371 struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu787a05b2014-12-05 11:02:20 +0800372 int rt_count;
Chia-I Wu39026c92014-09-02 10:03:19 +0800373 XGL_RESULT ret;
374
Chia-I Wu787a05b2014-12-05 11:02:20 +0800375 rt_count = pipeline_get_last_color_attachment(pipeline, info) + 1;
376 /* at least one NULL RT */
377 if (rt_count <= 0)
378 rt_count = 1;
379
Chia-I Wu46809782014-10-07 15:40:38 +0800380 assert(!info->fs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800381
Cody Northropbc851432014-09-23 10:06:32 -0600382 // Right here, lower the IR to ISA using NOS
Cody Northrop83e2b032014-09-25 17:00:31 -0600383 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800384 ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800385 intel_shader(info->fs.shader)->ir);
Cody Northropbc851432014-09-23 10:06:32 -0600386 if (ret != XGL_SUCCESS)
387 return ret;
388
Chia-I Wu39026c92014-09-02 10:03:19 +0800389 fs->rmap = rmap_create(pipeline->dev,
390 &info->fs.descriptorSetMapping[0],
Chia-I Wu787a05b2014-12-05 11:02:20 +0800391 &info->fs.dynamicMemoryViewMapping, rt_count);
Chia-I Wu39026c92014-09-02 10:03:19 +0800392 if (!fs->rmap) {
393 icd_free(fs->pCode);
394 return XGL_ERROR_OUT_OF_MEMORY;
395 }
396
Chia-I Wu39026c92014-09-02 10:03:19 +0800397 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
398
399 return XGL_SUCCESS;
400}
401
402static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline,
403 const struct intel_pipeline_create_info *info)
404{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800405 struct intel_pipeline_shader *cs = &pipeline->cs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800406 XGL_RESULT ret;
407
Chia-I Wu714f0a32014-10-11 14:08:15 +0800408 ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800409 intel_shader(info->compute.cs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800410 if (ret != XGL_SUCCESS)
411 return ret;
412
Chia-I Wu46809782014-10-07 15:40:38 +0800413 assert(!info->compute.cs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800414
Chia-I Wu39026c92014-09-02 10:03:19 +0800415 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
416
Chia-I Wu98824592014-09-02 09:42:46 +0800417 return XGL_SUCCESS;
418}
419
420XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
421 const struct intel_pipeline_create_info *info)
422{
423 XGL_RESULT ret = XGL_SUCCESS;
424
425 if (ret == XGL_SUCCESS && info->vs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800426 ret = pipeline_build_vs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800427 if (ret == XGL_SUCCESS && info->tcs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800428 ret = pipeline_build_tcs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800429 if (ret == XGL_SUCCESS && info->tes.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800430 ret = pipeline_build_tes(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800431 if (ret == XGL_SUCCESS && info->gs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800432 ret = pipeline_build_gs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800433 if (ret == XGL_SUCCESS && info->fs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800434 ret = pipeline_build_fs(pipeline, info);
435
436 if (ret == XGL_SUCCESS && info->compute.cs.shader)
437 ret = pipeline_build_cs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800438
439 return ret;
440}
441
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800442static void pipeline_tear_shader(struct intel_pipeline_shader *sh)
Chia-I Wu39026c92014-09-02 10:03:19 +0800443{
444 icd_free(sh->pCode);
445 if (sh->rmap)
446 rmap_destroy(sh->rmap);
447}
448
Chia-I Wu98824592014-09-02 09:42:46 +0800449void pipeline_tear_shaders(struct intel_pipeline *pipeline)
450{
451 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800452 pipeline_tear_shader(&pipeline->vs);
Chia-I Wu98824592014-09-02 09:42:46 +0800453 }
454
Chia-I Wu39026c92014-09-02 10:03:19 +0800455 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800456 pipeline_tear_shader(&pipeline->tcs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800457 }
458
459 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800460 pipeline_tear_shader(&pipeline->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800461 }
462
463 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
464 pipeline_tear_shader(&pipeline->gs);
465 }
466
467 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800468 pipeline_tear_shader(&pipeline->fs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800469 }
470
471 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800472 pipeline_tear_shader(&pipeline->cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800473 }
Chia-I Wu98824592014-09-02 09:42:46 +0800474}
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800475
476struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
477 enum intel_dev_meta_shader id)
478{
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800479 struct intel_pipeline_shader *sh;
Chia-I Wu005c47c2014-10-22 13:49:13 +0800480 XGL_RESULT ret;
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800481
482 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
483 if (!sh)
484 return NULL;
485 memset(sh, 0, sizeof(*sh));
486
Chia-I Wu005c47c2014-10-22 13:49:13 +0800487 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
488 if (ret != XGL_SUCCESS) {
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800489 icd_free(sh);
490 return NULL;
491 }
492
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800493 return sh;
494}
495
496void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
497{
498 if (sh->rmap)
499 rmap_destroy(sh->rmap);
500 if (sh->pCode)
501 icd_free(sh->pCode);
502 icd_free(sh);
503}