blob: 2b167c608112da60db19ee1600e3548bbe01723e [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
Cody Northrop37c47052014-12-11 09:58:50 -0700293 // Ensure that all textures in descriptor set were consumed
294 // This is temporary until we move resource map building to compiler
295 assert(vs->ubo_start == vs->rmap->texture_resource_count);
296
Chia-I Wu39026c92014-09-02 10:03:19 +0800297 pipeline->active_shaders |= SHADER_VERTEX_FLAG;
298
299 return XGL_SUCCESS;
300}
301
302static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline,
303 const struct intel_pipeline_create_info *info)
304{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800305 struct intel_pipeline_shader *tcs = &pipeline->tcs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800306 XGL_RESULT ret;
307
Chia-I Wu714f0a32014-10-11 14:08:15 +0800308 ret = intel_pipeline_shader_compile(tcs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800309 intel_shader(info->tcs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800310 if (ret != XGL_SUCCESS)
311 return ret;
312
Chia-I Wu46809782014-10-07 15:40:38 +0800313 assert(!info->tcs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800314
Chia-I Wu39026c92014-09-02 10:03:19 +0800315 pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG;
316
317 return XGL_SUCCESS;
318}
319
320static XGL_RESULT pipeline_build_tes(struct intel_pipeline *pipeline,
321 const struct intel_pipeline_create_info *info)
322{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800323 struct intel_pipeline_shader *tes = &pipeline->tes;
Chia-I Wu39026c92014-09-02 10:03:19 +0800324 XGL_RESULT ret;
325
Chia-I Wu714f0a32014-10-11 14:08:15 +0800326 ret = intel_pipeline_shader_compile(tes, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800327 intel_shader(info->tes.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800328 if (ret != XGL_SUCCESS)
329 return ret;
330
Chia-I Wu46809782014-10-07 15:40:38 +0800331 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800332
Chia-I Wu39026c92014-09-02 10:03:19 +0800333 pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG;
334
335 return XGL_SUCCESS;
336}
337
338static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline,
339 const struct intel_pipeline_create_info *info)
340{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800341 struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800342 XGL_RESULT ret;
343
Chia-I Wu714f0a32014-10-11 14:08:15 +0800344 ret = intel_pipeline_shader_compile(gs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800345 intel_shader(info->gs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800346 if (ret != XGL_SUCCESS)
347 return ret;
348
Chia-I Wu46809782014-10-07 15:40:38 +0800349 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800350
Chia-I Wu39026c92014-09-02 10:03:19 +0800351 pipeline->active_shaders |= SHADER_GEOMETRY_FLAG;
352
353 return XGL_SUCCESS;
354}
355
Chia-I Wu787a05b2014-12-05 11:02:20 +0800356static int pipeline_get_last_color_attachment(const struct intel_pipeline *pipeline,
357 const struct intel_pipeline_create_info *info)
358{
359 int idx;
360
361 for (idx = ARRAY_SIZE(info->cb.attachment) - 1; idx >= 0; idx--) {
362 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att =
363 &info->cb.attachment[idx];
364
365 if (!icd_format_is_undef(att->format))
366 break;
367 }
368
369 return idx;
370}
371
Chia-I Wu39026c92014-09-02 10:03:19 +0800372static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline,
373 const struct intel_pipeline_create_info *info)
374{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800375 struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu787a05b2014-12-05 11:02:20 +0800376 int rt_count;
Chia-I Wu39026c92014-09-02 10:03:19 +0800377 XGL_RESULT ret;
378
Chia-I Wu787a05b2014-12-05 11:02:20 +0800379 rt_count = pipeline_get_last_color_attachment(pipeline, info) + 1;
380 /* at least one NULL RT */
381 if (rt_count <= 0)
382 rt_count = 1;
383
Chia-I Wu46809782014-10-07 15:40:38 +0800384 assert(!info->fs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800385
Cody Northropbc851432014-09-23 10:06:32 -0600386 // Right here, lower the IR to ISA using NOS
Cody Northrop83e2b032014-09-25 17:00:31 -0600387 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800388 ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800389 intel_shader(info->fs.shader)->ir);
Cody Northropbc851432014-09-23 10:06:32 -0600390 if (ret != XGL_SUCCESS)
391 return ret;
392
Chia-I Wu39026c92014-09-02 10:03:19 +0800393 fs->rmap = rmap_create(pipeline->dev,
394 &info->fs.descriptorSetMapping[0],
Chia-I Wu787a05b2014-12-05 11:02:20 +0800395 &info->fs.dynamicMemoryViewMapping, rt_count);
Chia-I Wu39026c92014-09-02 10:03:19 +0800396 if (!fs->rmap) {
397 icd_free(fs->pCode);
398 return XGL_ERROR_OUT_OF_MEMORY;
399 }
400
Cody Northrop37c47052014-12-11 09:58:50 -0700401 // Ensure that all textures in descriptor set were consumed
402 // This is temporary until we move resource map building to compiler
403 assert(fs->ubo_start == fs->rmap->texture_resource_count + fs->rmap->rt_count);
404
Chia-I Wu39026c92014-09-02 10:03:19 +0800405 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
406
407 return XGL_SUCCESS;
408}
409
410static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline,
411 const struct intel_pipeline_create_info *info)
412{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800413 struct intel_pipeline_shader *cs = &pipeline->cs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800414 XGL_RESULT ret;
415
Chia-I Wu714f0a32014-10-11 14:08:15 +0800416 ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800417 intel_shader(info->compute.cs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800418 if (ret != XGL_SUCCESS)
419 return ret;
420
Chia-I Wu46809782014-10-07 15:40:38 +0800421 assert(!info->compute.cs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800422
Chia-I Wu39026c92014-09-02 10:03:19 +0800423 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
424
Chia-I Wu98824592014-09-02 09:42:46 +0800425 return XGL_SUCCESS;
426}
427
428XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
429 const struct intel_pipeline_create_info *info)
430{
431 XGL_RESULT ret = XGL_SUCCESS;
432
433 if (ret == XGL_SUCCESS && info->vs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800434 ret = pipeline_build_vs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800435 if (ret == XGL_SUCCESS && info->tcs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800436 ret = pipeline_build_tcs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800437 if (ret == XGL_SUCCESS && info->tes.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800438 ret = pipeline_build_tes(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800439 if (ret == XGL_SUCCESS && info->gs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800440 ret = pipeline_build_gs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800441 if (ret == XGL_SUCCESS && info->fs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800442 ret = pipeline_build_fs(pipeline, info);
443
444 if (ret == XGL_SUCCESS && info->compute.cs.shader)
445 ret = pipeline_build_cs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800446
447 return ret;
448}
449
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800450static void pipeline_tear_shader(struct intel_pipeline_shader *sh)
Chia-I Wu39026c92014-09-02 10:03:19 +0800451{
452 icd_free(sh->pCode);
453 if (sh->rmap)
454 rmap_destroy(sh->rmap);
455}
456
Chia-I Wu98824592014-09-02 09:42:46 +0800457void pipeline_tear_shaders(struct intel_pipeline *pipeline)
458{
459 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800460 pipeline_tear_shader(&pipeline->vs);
Chia-I Wu98824592014-09-02 09:42:46 +0800461 }
462
Chia-I Wu39026c92014-09-02 10:03:19 +0800463 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800464 pipeline_tear_shader(&pipeline->tcs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800465 }
466
467 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800468 pipeline_tear_shader(&pipeline->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800469 }
470
471 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
472 pipeline_tear_shader(&pipeline->gs);
473 }
474
475 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800476 pipeline_tear_shader(&pipeline->fs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800477 }
478
479 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800480 pipeline_tear_shader(&pipeline->cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800481 }
Chia-I Wu98824592014-09-02 09:42:46 +0800482}
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800483
484struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
485 enum intel_dev_meta_shader id)
486{
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800487 struct intel_pipeline_shader *sh;
Chia-I Wu005c47c2014-10-22 13:49:13 +0800488 XGL_RESULT ret;
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800489
490 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
491 if (!sh)
492 return NULL;
493 memset(sh, 0, sizeof(*sh));
494
Chia-I Wu005c47c2014-10-22 13:49:13 +0800495 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
496 if (ret != XGL_SUCCESS) {
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800497 icd_free(sh);
498 return NULL;
499 }
500
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800501 return sh;
502}
503
504void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
505{
506 if (sh->rmap)
507 rmap_destroy(sh->rmap);
508 if (sh->pCode)
509 icd_free(sh->pCode);
510 icd_free(sh);
511}