blob: 41a39b2fbd1705090704bf66b2a50b1bbcf728b9 [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
342static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline,
343 const struct intel_pipeline_create_info *info)
344{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800345 struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800346 XGL_RESULT ret;
347
Chia-I Wu46809782014-10-07 15:40:38 +0800348 assert(!info->fs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800349
Cody Northropbc851432014-09-23 10:06:32 -0600350 // Right here, lower the IR to ISA using NOS
Cody Northrop83e2b032014-09-25 17:00:31 -0600351 // This must be after assignment of pipeline constant buffer
Chia-I Wu714f0a32014-10-11 14:08:15 +0800352 ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800353 intel_shader(info->fs.shader)->ir);
Cody Northropbc851432014-09-23 10:06:32 -0600354 if (ret != XGL_SUCCESS)
355 return ret;
356
Chia-I Wu39026c92014-09-02 10:03:19 +0800357 /* assuming one RT; need to parse the shader */
358 fs->rmap = rmap_create(pipeline->dev,
359 &info->fs.descriptorSetMapping[0],
360 &info->fs.dynamicMemoryViewMapping, 1);
361 if (!fs->rmap) {
362 icd_free(fs->pCode);
363 return XGL_ERROR_OUT_OF_MEMORY;
364 }
365
Chia-I Wu39026c92014-09-02 10:03:19 +0800366 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
367
368 return XGL_SUCCESS;
369}
370
371static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline,
372 const struct intel_pipeline_create_info *info)
373{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800374 struct intel_pipeline_shader *cs = &pipeline->cs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800375 XGL_RESULT ret;
376
Chia-I Wu714f0a32014-10-11 14:08:15 +0800377 ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu,
Chia-I Wua4d1b392014-10-10 13:57:29 +0800378 intel_shader(info->compute.cs.shader)->ir);
Chia-I Wu39026c92014-09-02 10:03:19 +0800379 if (ret != XGL_SUCCESS)
380 return ret;
381
Chia-I Wu46809782014-10-07 15:40:38 +0800382 assert(!info->compute.cs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800383
Chia-I Wu39026c92014-09-02 10:03:19 +0800384 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
385
Chia-I Wu98824592014-09-02 09:42:46 +0800386 return XGL_SUCCESS;
387}
388
389XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
390 const struct intel_pipeline_create_info *info)
391{
392 XGL_RESULT ret = XGL_SUCCESS;
393
394 if (ret == XGL_SUCCESS && info->vs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800395 ret = pipeline_build_vs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800396 if (ret == XGL_SUCCESS && info->tcs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800397 ret = pipeline_build_tcs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800398 if (ret == XGL_SUCCESS && info->tes.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800399 ret = pipeline_build_tes(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800400 if (ret == XGL_SUCCESS && info->gs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800401 ret = pipeline_build_gs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800402 if (ret == XGL_SUCCESS && info->fs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800403 ret = pipeline_build_fs(pipeline, info);
404
405 if (ret == XGL_SUCCESS && info->compute.cs.shader)
406 ret = pipeline_build_cs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800407
408 return ret;
409}
410
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800411static void pipeline_tear_shader(struct intel_pipeline_shader *sh)
Chia-I Wu39026c92014-09-02 10:03:19 +0800412{
413 icd_free(sh->pCode);
414 if (sh->rmap)
415 rmap_destroy(sh->rmap);
416}
417
Chia-I Wu98824592014-09-02 09:42:46 +0800418void pipeline_tear_shaders(struct intel_pipeline *pipeline)
419{
420 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800421 pipeline_tear_shader(&pipeline->vs);
Chia-I Wu98824592014-09-02 09:42:46 +0800422 }
423
Chia-I Wu39026c92014-09-02 10:03:19 +0800424 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800425 pipeline_tear_shader(&pipeline->tcs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800426 }
427
428 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800429 pipeline_tear_shader(&pipeline->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800430 }
431
432 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
433 pipeline_tear_shader(&pipeline->gs);
434 }
435
436 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800437 pipeline_tear_shader(&pipeline->fs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800438 }
439
440 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800441 pipeline_tear_shader(&pipeline->cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800442 }
Chia-I Wu98824592014-09-02 09:42:46 +0800443}
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800444
445struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
446 enum intel_dev_meta_shader id)
447{
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800448 struct intel_pipeline_shader *sh;
Chia-I Wu005c47c2014-10-22 13:49:13 +0800449 XGL_RESULT ret;
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800450
451 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
452 if (!sh)
453 return NULL;
454 memset(sh, 0, sizeof(*sh));
455
Chia-I Wu005c47c2014-10-22 13:49:13 +0800456 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
457 if (ret != XGL_SUCCESS) {
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800458 icd_free(sh);
459 return NULL;
460 }
461
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800462 return sh;
463}
464
465void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
466{
467 if (sh->rmap)
468 rmap_destroy(sh->rmap);
469 if (sh->pCode)
470 icd_free(sh->pCode);
471 icd_free(sh);
472}