blob: 6ce79103d1dc9744d58eb0aeed8682bac7e0bd2c [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 Wu00c84362014-12-11 10:14:40 +0800282 ret = intel_pipeline_shader_compile(vs, pipeline->dev->gpu, &info->vs);
Cody Northrop83e2b032014-09-25 17:00:31 -0600283 if (ret != XGL_SUCCESS)
284 return ret;
285
Chia-I Wu39026c92014-09-02 10:03:19 +0800286 vs->rmap = rmap_create(pipeline->dev,
287 &info->vs.descriptorSetMapping[0],
Cody Northrope65465a2014-12-10 08:38:23 -0700288 &info->vs.dynamicMemoryViewMapping, 0, vs->ubo_start);
Chia-I Wu39026c92014-09-02 10:03:19 +0800289 if (!vs->rmap) {
290 icd_free(vs->pCode);
291 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wu98824592014-09-02 09:42:46 +0800292 }
293
Cody Northrop37c47052014-12-11 09:58:50 -0700294 // Ensure that all textures in descriptor set were consumed
295 // This is temporary until we move resource map building to compiler
296 assert(vs->ubo_start == vs->rmap->texture_resource_count);
297
Chia-I Wu39026c92014-09-02 10:03:19 +0800298 pipeline->active_shaders |= SHADER_VERTEX_FLAG;
299
300 return XGL_SUCCESS;
301}
302
303static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline,
304 const struct intel_pipeline_create_info *info)
305{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800306 struct intel_pipeline_shader *tcs = &pipeline->tcs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800307 XGL_RESULT ret;
308
Chia-I Wu00c84362014-12-11 10:14:40 +0800309 ret = intel_pipeline_shader_compile(tcs, pipeline->dev->gpu, &info->tcs);
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 Wu00c84362014-12-11 10:14:40 +0800326 ret = intel_pipeline_shader_compile(tes, pipeline->dev->gpu, &info->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800327 if (ret != XGL_SUCCESS)
328 return ret;
329
Chia-I Wu46809782014-10-07 15:40:38 +0800330 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800331
Chia-I Wu39026c92014-09-02 10:03:19 +0800332 pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG;
333
334 return XGL_SUCCESS;
335}
336
337static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline,
338 const struct intel_pipeline_create_info *info)
339{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800340 struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800341 XGL_RESULT ret;
342
Chia-I Wu00c84362014-12-11 10:14:40 +0800343 ret = intel_pipeline_shader_compile(gs, pipeline->dev->gpu, &info->gs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800344 if (ret != XGL_SUCCESS)
345 return ret;
346
Chia-I Wu46809782014-10-07 15:40:38 +0800347 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800348
Chia-I Wu39026c92014-09-02 10:03:19 +0800349 pipeline->active_shaders |= SHADER_GEOMETRY_FLAG;
350
351 return XGL_SUCCESS;
352}
353
Chia-I Wu787a05b2014-12-05 11:02:20 +0800354static int pipeline_get_last_color_attachment(const struct intel_pipeline *pipeline,
355 const struct intel_pipeline_create_info *info)
356{
357 int idx;
358
359 for (idx = ARRAY_SIZE(info->cb.attachment) - 1; idx >= 0; idx--) {
360 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att =
361 &info->cb.attachment[idx];
362
363 if (!icd_format_is_undef(att->format))
364 break;
365 }
366
367 return idx;
368}
369
Chia-I Wu39026c92014-09-02 10:03:19 +0800370static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline,
371 const struct intel_pipeline_create_info *info)
372{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800373 struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu787a05b2014-12-05 11:02:20 +0800374 int rt_count;
Chia-I Wu39026c92014-09-02 10:03:19 +0800375 XGL_RESULT ret;
376
Chia-I Wu787a05b2014-12-05 11:02:20 +0800377 rt_count = pipeline_get_last_color_attachment(pipeline, info) + 1;
378 /* at least one NULL RT */
379 if (rt_count <= 0)
380 rt_count = 1;
381
Chia-I Wu46809782014-10-07 15:40:38 +0800382 assert(!info->fs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800383
Cody Northropbc851432014-09-23 10:06:32 -0600384 // Right here, lower the IR to ISA using NOS
Cody Northrop83e2b032014-09-25 17:00:31 -0600385 // This must be after assignment of pipeline constant buffer
Chia-I Wu00c84362014-12-11 10:14:40 +0800386 ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu, &info->fs);
Cody Northropbc851432014-09-23 10:06:32 -0600387 if (ret != XGL_SUCCESS)
388 return ret;
389
Chia-I Wu39026c92014-09-02 10:03:19 +0800390 fs->rmap = rmap_create(pipeline->dev,
391 &info->fs.descriptorSetMapping[0],
Cody Northrope65465a2014-12-10 08:38:23 -0700392 &info->fs.dynamicMemoryViewMapping, rt_count, fs->ubo_start);
Chia-I Wu39026c92014-09-02 10:03:19 +0800393 if (!fs->rmap) {
394 icd_free(fs->pCode);
395 return XGL_ERROR_OUT_OF_MEMORY;
396 }
397
Cody Northrop37c47052014-12-11 09:58:50 -0700398 // Ensure that all textures in descriptor set were consumed
399 // This is temporary until we move resource map building to compiler
400 assert(fs->ubo_start == fs->rmap->texture_resource_count + fs->rmap->rt_count);
401
Chia-I Wu39026c92014-09-02 10:03:19 +0800402 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
403
404 return XGL_SUCCESS;
405}
406
407static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline,
408 const struct intel_pipeline_create_info *info)
409{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800410 struct intel_pipeline_shader *cs = &pipeline->cs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800411 XGL_RESULT ret;
412
Chia-I Wu00c84362014-12-11 10:14:40 +0800413 ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu, &info->compute.cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800414 if (ret != XGL_SUCCESS)
415 return ret;
416
Chia-I Wu46809782014-10-07 15:40:38 +0800417 assert(!info->compute.cs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800418
Chia-I Wu39026c92014-09-02 10:03:19 +0800419 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
420
Chia-I Wu98824592014-09-02 09:42:46 +0800421 return XGL_SUCCESS;
422}
423
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800424static void pipeline_post_build_shader(struct intel_pipeline *pipeline,
425 struct intel_pipeline_shader *sh,
426 const XGL_PIPELINE_SHADER *sh_info)
427{
428 sh->max_threads =
429 intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage);
Chia-I Wub1024732014-12-19 13:00:29 +0800430
431 /* 1KB aligned */
432 sh->scratch_offset = u_align(pipeline->scratch_size, 1024);
433 pipeline->scratch_size = sh->scratch_offset +
434 sh->per_thread_scratch_size * sh->max_threads;
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800435}
436
Chia-I Wu98824592014-09-02 09:42:46 +0800437XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
438 const struct intel_pipeline_create_info *info)
439{
440 XGL_RESULT ret = XGL_SUCCESS;
441
442 if (ret == XGL_SUCCESS && info->vs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800443 ret = pipeline_build_vs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800444 if (ret == XGL_SUCCESS && info->tcs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800445 ret = pipeline_build_tcs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800446 if (ret == XGL_SUCCESS && info->tes.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800447 ret = pipeline_build_tes(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800448 if (ret == XGL_SUCCESS && info->gs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800449 ret = pipeline_build_gs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800450 if (ret == XGL_SUCCESS && info->fs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800451 ret = pipeline_build_fs(pipeline, info);
452
453 if (ret == XGL_SUCCESS && info->compute.cs.shader)
454 ret = pipeline_build_cs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800455
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800456 if (pipeline->active_shaders & SHADER_VERTEX_FLAG)
457 pipeline_post_build_shader(pipeline, &pipeline->vs, &info->vs);
458 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG)
459 pipeline_post_build_shader(pipeline, &pipeline->tcs, &info->tcs);
460 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG)
461 pipeline_post_build_shader(pipeline, &pipeline->tes, &info->tes);
462 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG)
463 pipeline_post_build_shader(pipeline, &pipeline->gs, &info->gs);
464 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG)
465 pipeline_post_build_shader(pipeline, &pipeline->fs, &info->fs);
466 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG)
467 pipeline_post_build_shader(pipeline, &pipeline->cs, &info->compute.cs);
468
Chia-I Wu98824592014-09-02 09:42:46 +0800469 return ret;
470}
471
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800472static void pipeline_tear_shader(struct intel_pipeline_shader *sh)
Chia-I Wu39026c92014-09-02 10:03:19 +0800473{
474 icd_free(sh->pCode);
475 if (sh->rmap)
476 rmap_destroy(sh->rmap);
477}
478
Chia-I Wu98824592014-09-02 09:42:46 +0800479void pipeline_tear_shaders(struct intel_pipeline *pipeline)
480{
481 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800482 pipeline_tear_shader(&pipeline->vs);
Chia-I Wu98824592014-09-02 09:42:46 +0800483 }
484
Chia-I Wu39026c92014-09-02 10:03:19 +0800485 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800486 pipeline_tear_shader(&pipeline->tcs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800487 }
488
489 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800490 pipeline_tear_shader(&pipeline->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800491 }
492
493 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
494 pipeline_tear_shader(&pipeline->gs);
495 }
496
497 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800498 pipeline_tear_shader(&pipeline->fs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800499 }
500
501 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800502 pipeline_tear_shader(&pipeline->cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800503 }
Chia-I Wu98824592014-09-02 09:42:46 +0800504}
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800505
506struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
507 enum intel_dev_meta_shader id)
508{
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800509 struct intel_pipeline_shader *sh;
Chia-I Wu005c47c2014-10-22 13:49:13 +0800510 XGL_RESULT ret;
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800511
512 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
513 if (!sh)
514 return NULL;
515 memset(sh, 0, sizeof(*sh));
516
Chia-I Wu005c47c2014-10-22 13:49:13 +0800517 ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id);
518 if (ret != XGL_SUCCESS) {
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800519 icd_free(sh);
520 return NULL;
521 }
522
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800523 switch (id) {
524 case INTEL_DEV_META_VS_FILL_MEM:
525 case INTEL_DEV_META_VS_COPY_MEM:
526 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
527 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
528 XGL_SHADER_STAGE_VERTEX);
529 break;
530 default:
531 sh->max_threads = intel_gpu_get_max_threads(dev->gpu,
532 XGL_SHADER_STAGE_FRAGMENT);
533 break;
534 }
535
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800536 return sh;
537}
538
539void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
540{
541 if (sh->rmap)
542 rmap_destroy(sh->rmap);
543 if (sh->pCode)
544 icd_free(sh->pCode);
545 icd_free(sh);
546}