blob: c31280f427cfa19eaf86e07bb713f0bfe249d183 [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"
30
Chia-I Wu20983762014-09-02 12:07:28 +080031static struct intel_pipeline_rmap_slot *rmap_get_slot(struct intel_pipeline_rmap *rmap,
32 XGL_DESCRIPTOR_SET_SLOT_TYPE type,
33 XGL_UINT index)
Chia-I Wu1f7540b2014-08-22 13:56:18 +080034{
35 const XGL_UINT resource_offset = rmap->rt_count;
36 const XGL_UINT uav_offset = resource_offset + rmap->resource_count;
37 const XGL_UINT sampler_offset = uav_offset + rmap->uav_count;
Chia-I Wu1d125092014-10-08 08:49:38 +080038 const XGL_UINT ve_offset = sampler_offset + rmap->sampler_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;
Chia-I Wu1d125092014-10-08 08:49:38 +080054 case XGL_SLOT_VERTEX_INPUT:
55 slot = &rmap->slots[ve_offset + index];
56 break;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080057 default:
58 assert(!"unknown rmap slot type");
59 slot = NULL;
60 break;
61 }
62
63 return slot;
64}
65
Chia-I Wu20983762014-09-02 12:07:28 +080066static bool rmap_init_slots_with_path(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +080067 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
68 XGL_UINT *nest_path,
69 XGL_UINT nest_level)
70{
71 XGL_UINT i;
72
73 for (i = 0; i < mapping->descriptorCount; i++) {
74 const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i];
Chia-I Wu20983762014-09-02 12:07:28 +080075 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080076
77 if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) {
78 nest_path[nest_level] = i;
79 if (!rmap_init_slots_with_path(rmap, info->pNextLevelSet,
80 nest_path, nest_level + 1))
81 return false;
82
83 continue;
84 }
85
86 slot = rmap_get_slot(rmap, info->slotObjectType,
87 info->shaderEntityIndex);
88 if (!slot)
89 continue;
90
91 assert(!slot->path_len);
92 slot->path_len = nest_level + 1;
93
94 if (nest_level) {
95 slot->u.path = icd_alloc(sizeof(slot->u.path[0]) *
96 slot->path_len, 0, XGL_SYSTEM_ALLOC_INTERNAL);
97 if (!slot->u.path) {
98 slot->path_len = 0;
99 return false;
100 }
101
102 memcpy(slot->u.path, nest_path,
103 sizeof(slot->u.path[0]) * nest_level);
104 slot->u.path[nest_level] = i;
105 } else {
106 slot->u.index = i;
107 }
108 }
109
110 return true;
111}
112
Chia-I Wu20983762014-09-02 12:07:28 +0800113static bool rmap_init_slots(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800114 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
115 XGL_UINT depth)
116{
117 XGL_UINT *nest_path;
118 bool ok;
119
120 if (depth) {
121 nest_path = icd_alloc(sizeof(nest_path[0]) * depth,
122 0, XGL_SYSTEM_ALLOC_INTERNAL_TEMP);
123 if (!nest_path)
124 return false;
125 } else {
126 nest_path = NULL;
127 }
128
129 ok = rmap_init_slots_with_path(rmap, mapping, nest_path, 0);
130
131 if (nest_path)
132 icd_free(nest_path);
133
134 return ok;
135}
136
Chia-I Wu20983762014-09-02 12:07:28 +0800137static void rmap_update_count(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800138 XGL_DESCRIPTOR_SET_SLOT_TYPE type,
139 XGL_UINT index)
140{
141 switch (type) {
142 case XGL_SLOT_UNUSED:
143 break;
144 case XGL_SLOT_SHADER_RESOURCE:
145 if (rmap->resource_count < index + 1)
146 rmap->resource_count = index + 1;
147 break;
148 case XGL_SLOT_SHADER_UAV:
149 if (rmap->uav_count < index + 1)
150 rmap->uav_count = index + 1;
151 break;
152 case XGL_SLOT_SHADER_SAMPLER:
153 if (rmap->sampler_count < index + 1)
154 rmap->sampler_count = index + 1;
155 break;
Chia-I Wu1d125092014-10-08 08:49:38 +0800156 case XGL_SLOT_VERTEX_INPUT:
157 if (rmap->vb_count < index + 1)
158 rmap->vb_count = index + 1;
159 break;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800160 default:
161 assert(!"unknown rmap slot type");
162 break;
163 }
164}
165
Chia-I Wu20983762014-09-02 12:07:28 +0800166static XGL_UINT rmap_init_counts(struct intel_pipeline_rmap *rmap,
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800167 const XGL_DESCRIPTOR_SET_MAPPING *mapping)
168{
169 XGL_UINT depth = 0;
170 XGL_UINT i;
171
172 for (i = 0; i < mapping->descriptorCount; i++) {
173 const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i];
174
175 if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) {
176 const XGL_UINT d = rmap_init_counts(rmap,
177 info->pNextLevelSet);
178 if (depth < d + 1)
179 depth = d + 1;
180
181 continue;
182 }
183
184 rmap_update_count(rmap, info->slotObjectType,
185 info->shaderEntityIndex);
186 }
187
188 return depth;
189}
190
Chia-I Wu20983762014-09-02 12:07:28 +0800191static void rmap_destroy(struct intel_pipeline_rmap *rmap)
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800192{
193 XGL_UINT i;
194
195 for (i = 0; i < rmap->slot_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +0800196 struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800197
198 switch (slot->path_len) {
199 case 0:
200 case 1:
Chia-I Wu20983762014-09-02 12:07:28 +0800201 case INTEL_PIPELINE_RMAP_SLOT_RT:
202 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800203 break;
204 default:
205 icd_free(slot->u.path);
206 break;
207 }
208 }
209
210 icd_free(rmap->slots);
211 icd_free(rmap);
212}
213
Chia-I Wu20983762014-09-02 12:07:28 +0800214static struct intel_pipeline_rmap *rmap_create(struct intel_dev *dev,
215 const XGL_DESCRIPTOR_SET_MAPPING *mapping,
216 const XGL_DYNAMIC_MEMORY_VIEW_SLOT_INFO *dyn,
217 XGL_UINT rt_count)
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800218{
Chia-I Wu20983762014-09-02 12:07:28 +0800219 struct intel_pipeline_rmap *rmap;
220 struct intel_pipeline_rmap_slot *slot;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800221 XGL_UINT depth, rt;
222
223 rmap = icd_alloc(sizeof(*rmap), 0, XGL_SYSTEM_ALLOC_INTERNAL);
224 if (!rmap)
225 return NULL;
226
227 memset(rmap, 0, sizeof(*rmap));
228
229 depth = rmap_init_counts(rmap, mapping);
230
231 /* add RTs and the dynamic memory view */
232 rmap_update_count(rmap, dyn->slotObjectType, dyn->shaderEntityIndex);
233 rmap->rt_count = rt_count;
234
235 rmap->slot_count = rmap->rt_count + rmap->resource_count +
Chia-I Wu1d125092014-10-08 08:49:38 +0800236 rmap->uav_count + rmap->sampler_count + rmap->vb_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800237
238 rmap->slots = icd_alloc(sizeof(rmap->slots[0]) * rmap->slot_count,
239 0, XGL_SYSTEM_ALLOC_INTERNAL);
240 if (!rmap->slots) {
241 icd_free(rmap);
242 return NULL;
243 }
244
245 memset(rmap->slots, 0, sizeof(rmap->slots[0]) * rmap->slot_count);
246
247 if (!rmap_init_slots(rmap, mapping, depth)) {
Chia-I Wua6d50aa2014-09-02 10:21:34 +0800248 rmap_destroy(rmap);
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800249 return NULL;
250 }
251
252 /* add RTs and the dynamic memory view */
253 slot = rmap_get_slot(rmap, dyn->slotObjectType, dyn->shaderEntityIndex);
254 if (slot) {
Chia-I Wu20983762014-09-02 12:07:28 +0800255 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_DYN;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800256 slot->u.index = 0;
257 }
258 for (rt = 0; rt < rmap->rt_count; rt++) {
259 slot = &rmap->slots[rt];
Chia-I Wu20983762014-09-02 12:07:28 +0800260 slot->path_len = INTEL_PIPELINE_RMAP_SLOT_RT;
Chia-I Wu1f7540b2014-08-22 13:56:18 +0800261 slot->u.index = rt;
262 }
263
264 return rmap;
265}
266
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800267static XGL_RESULT pipeline_shader_copy_ir(struct intel_pipeline_shader *sh,
Chia-I Wu39026c92014-09-02 10:03:19 +0800268 const struct intel_shader *ir)
Chia-I Wu98824592014-09-02 09:42:46 +0800269{
Chia-I Wu39026c92014-09-02 10:03:19 +0800270 sh->pCode = icd_alloc(ir->ir->size, 0, XGL_SYSTEM_ALLOC_INTERNAL_SHADER);
271 if (!sh->pCode)
Chia-I Wu98824592014-09-02 09:42:46 +0800272 return XGL_ERROR_OUT_OF_MEMORY;
273
Chia-I Wu39026c92014-09-02 10:03:19 +0800274 memcpy(sh->pCode, ir->ir->kernel, ir->ir->size);
275 sh->codeSize = ir->ir->size;
Chia-I Wu98824592014-09-02 09:42:46 +0800276
Chia-I Wu39026c92014-09-02 10:03:19 +0800277 sh->uses = ir->uses;
Chia-I Wu98824592014-09-02 09:42:46 +0800278
Chia-I Wu39026c92014-09-02 10:03:19 +0800279 sh->in_count = ir->in_count;
280 sh->out_count = ir->out_count;
281 sh->sampler_count = ir->sampler_count;
282 sh->surface_count = ir->surface_count;
283 sh->urb_grf_start = ir->urb_grf_start;
Chia-I Wu39026c92014-09-02 10:03:19 +0800284 sh->barycentric_interps = ir->barycentric_interps;
285
286 return XGL_SUCCESS;
287}
288
289static XGL_RESULT pipeline_build_vs(struct intel_pipeline *pipeline,
290 const struct intel_pipeline_create_info *info)
291{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800292 struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800293 XGL_RESULT ret;
294
295 ret = pipeline_shader_copy_ir(vs, intel_shader(info->vs.shader));
296 if (ret != XGL_SUCCESS)
297 return ret;
298
Chia-I Wu46809782014-10-07 15:40:38 +0800299 assert(!info->vs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800300
Chia-I Wu39026c92014-09-02 10:03:19 +0800301 vs->rmap = rmap_create(pipeline->dev,
302 &info->vs.descriptorSetMapping[0],
303 &info->vs.dynamicMemoryViewMapping, 0);
304 if (!vs->rmap) {
305 icd_free(vs->pCode);
306 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wu98824592014-09-02 09:42:46 +0800307 }
308
Chia-I Wu39026c92014-09-02 10:03:19 +0800309 pipeline->active_shaders |= SHADER_VERTEX_FLAG;
310
311 return XGL_SUCCESS;
312}
313
314static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline,
315 const struct intel_pipeline_create_info *info)
316{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800317 struct intel_pipeline_shader *tcs = &pipeline->tcs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800318 XGL_RESULT ret;
319
320 ret = pipeline_shader_copy_ir(tcs, intel_shader(info->tcs.shader));
321 if (ret != XGL_SUCCESS)
322 return ret;
323
Chia-I Wu46809782014-10-07 15:40:38 +0800324 assert(!info->tcs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800325
Chia-I Wu39026c92014-09-02 10:03:19 +0800326 pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG;
327
328 return XGL_SUCCESS;
329}
330
331static XGL_RESULT pipeline_build_tes(struct intel_pipeline *pipeline,
332 const struct intel_pipeline_create_info *info)
333{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800334 struct intel_pipeline_shader *tes = &pipeline->tes;
Chia-I Wu39026c92014-09-02 10:03:19 +0800335 XGL_RESULT ret;
336
337 ret = pipeline_shader_copy_ir(tes, intel_shader(info->tes.shader));
338 if (ret != XGL_SUCCESS)
339 return ret;
340
Chia-I Wu46809782014-10-07 15:40:38 +0800341 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800342
Chia-I Wu39026c92014-09-02 10:03:19 +0800343 pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG;
344
345 return XGL_SUCCESS;
346}
347
348static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline,
349 const struct intel_pipeline_create_info *info)
350{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800351 struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800352 XGL_RESULT ret;
353
354 ret = pipeline_shader_copy_ir(gs, intel_shader(info->gs.shader));
355 if (ret != XGL_SUCCESS)
356 return ret;
357
Chia-I Wu46809782014-10-07 15:40:38 +0800358 assert(!info->tes.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800359
Chia-I Wu39026c92014-09-02 10:03:19 +0800360 pipeline->active_shaders |= SHADER_GEOMETRY_FLAG;
361
362 return XGL_SUCCESS;
363}
364
365static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline,
366 const struct intel_pipeline_create_info *info)
367{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800368 struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800369 XGL_RESULT ret;
370
371 ret = pipeline_shader_copy_ir(fs, intel_shader(info->fs.shader));
372 if (ret != XGL_SUCCESS)
373 return ret;
374
Chia-I Wu46809782014-10-07 15:40:38 +0800375 assert(!info->fs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800376
Chia-I Wu39026c92014-09-02 10:03:19 +0800377 /* assuming one RT; need to parse the shader */
378 fs->rmap = rmap_create(pipeline->dev,
379 &info->fs.descriptorSetMapping[0],
380 &info->fs.dynamicMemoryViewMapping, 1);
381 if (!fs->rmap) {
382 icd_free(fs->pCode);
383 return XGL_ERROR_OUT_OF_MEMORY;
384 }
385
Chia-I Wu39026c92014-09-02 10:03:19 +0800386 pipeline->active_shaders |= SHADER_FRAGMENT_FLAG;
387
388 return XGL_SUCCESS;
389}
390
391static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline,
392 const struct intel_pipeline_create_info *info)
393{
Chia-I Wu95959fb2014-09-02 11:01:03 +0800394 struct intel_pipeline_shader *cs = &pipeline->cs;
Chia-I Wu39026c92014-09-02 10:03:19 +0800395 XGL_RESULT ret;
396
397 ret = pipeline_shader_copy_ir(cs, intel_shader(info->compute.cs.shader));
398 if (ret != XGL_SUCCESS)
399 return ret;
400
Chia-I Wu46809782014-10-07 15:40:38 +0800401 assert(!info->compute.cs.linkConstBufferCount);
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800402
Chia-I Wu39026c92014-09-02 10:03:19 +0800403 pipeline->active_shaders |= SHADER_COMPUTE_FLAG;
404
Chia-I Wu98824592014-09-02 09:42:46 +0800405 return XGL_SUCCESS;
406}
407
408XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline,
409 const struct intel_pipeline_create_info *info)
410{
411 XGL_RESULT ret = XGL_SUCCESS;
412
413 if (ret == XGL_SUCCESS && info->vs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800414 ret = pipeline_build_vs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800415 if (ret == XGL_SUCCESS && info->tcs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800416 ret = pipeline_build_tcs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800417 if (ret == XGL_SUCCESS && info->tes.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800418 ret = pipeline_build_tes(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800419 if (ret == XGL_SUCCESS && info->gs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800420 ret = pipeline_build_gs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800421 if (ret == XGL_SUCCESS && info->fs.shader)
Chia-I Wu39026c92014-09-02 10:03:19 +0800422 ret = pipeline_build_fs(pipeline, info);
423
424 if (ret == XGL_SUCCESS && info->compute.cs.shader)
425 ret = pipeline_build_cs(pipeline, info);
Chia-I Wu98824592014-09-02 09:42:46 +0800426
427 return ret;
428}
429
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800430static void pipeline_tear_shader(struct intel_pipeline_shader *sh)
Chia-I Wu39026c92014-09-02 10:03:19 +0800431{
432 icd_free(sh->pCode);
433 if (sh->rmap)
434 rmap_destroy(sh->rmap);
435}
436
Chia-I Wu98824592014-09-02 09:42:46 +0800437void pipeline_tear_shaders(struct intel_pipeline *pipeline)
438{
439 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800440 pipeline_tear_shader(&pipeline->vs);
Chia-I Wu98824592014-09-02 09:42:46 +0800441 }
442
Chia-I Wu39026c92014-09-02 10:03:19 +0800443 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800444 pipeline_tear_shader(&pipeline->tcs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800445 }
446
447 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800448 pipeline_tear_shader(&pipeline->tes);
Chia-I Wu39026c92014-09-02 10:03:19 +0800449 }
450
451 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
452 pipeline_tear_shader(&pipeline->gs);
453 }
454
455 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
Chia-I Wuc3ddee62014-09-02 10:53:20 +0800456 pipeline_tear_shader(&pipeline->fs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800457 }
458
459 if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) {
Chia-I Wu95959fb2014-09-02 11:01:03 +0800460 pipeline_tear_shader(&pipeline->cs);
Chia-I Wu39026c92014-09-02 10:03:19 +0800461 }
Chia-I Wu98824592014-09-02 09:42:46 +0800462}
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800463
464struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
465 enum intel_dev_meta_shader id)
466{
467 static const uint32_t gen6_clear_code[] = {
468 0x00600001, 0x202003be, 0x00000040, 0x00000000, // mov(8) m1<1>F g2<0,1,0>F { align1 1Q };
469 0x00600001, 0x204003be, 0x00000044, 0x00000000, // mov(8) m2<1>F g2.1<0,1,0>F { align1 1Q };
470 0x00600001, 0x206003be, 0x00000048, 0x00000000, // mov(8) m3<1>F g2.2<0,1,0>F { align1 1Q };
471 0x00600001, 0x208003be, 0x0000004c, 0x00000000, // mov(8) m4<1>F g2.3<0,1,0>F { align1 1Q };
472 0x05600032, 0x20001fc8, 0x008d0020, 0x88019400, // sendc(8) null m1<8,8,1>F
473 // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT };
474 };
475 static const uint32_t gen7_clear_code[] = {
476 0x20010b01, 0x00027c00, // mov(8) g124<1>F g2<0,1,0>F { align1 1Q compacted };
477 0x20150b01, 0x00027d00, // mov(8) g125<1>F g2.1<0,1,0>F { align1 1Q compacted };
478 0x20190b01, 0x00027e00, // mov(8) g126<1>F g2.2<0,1,0>F { align1 1Q compacted };
479 0x201d0b01, 0x00027f00, // mov(8) g127<1>F g2.3<0,1,0>F { align1 1Q compacted };
480 0x05600032, 0x20001fa8, 0x008d0f80, 0x88031400, // sendc(8) null g124<8,8,1>F
481 // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT };
482 };
483 static const uint32_t gen6_copy_mem_code[] = {
484 0x00600040, 0x20a06d29, 0x00480028, 0x10101010, // add(8) g5<1>UW g1.4<2,4,0>UW 0x10101010V { align1 1Q };
485 0x00600001, 0x20a00062, 0x00000000, 0x00000000, // mov(8) m5<1>UD 0x00000000UD { align1 1Q };
486 0x00600001, 0x20c0013d, 0x008d00a0, 0x00000000, // mov(8) g6<1>F g5<8,8,1>UW { align1 1Q };
487 0x00600040, 0x20607fbd, 0x008d00c0, 0x3f000000, // add(8) g3<1>F g6<8,8,1>F 0.5F { align1 1Q };
488 0x00600001, 0x204003a5, 0x008d0060, 0x00000000, // mov(8) g2<1>D g3<8,8,1>F { align1 1Q };
489 0x00600040, 0x204014a6, 0x008d0040, 0x00000080, // add(8) m2<1>D g2<8,8,1>D g4<0,1,0>D { align1 1Q };
490 0x02600031, 0x20401fc9, 0x008d0040, 0x08417001, // send(8) g2<1>UW m2<8,8,1>F
491 // sampler (1, 0, 7, 1) mlen 4 rlen 4 { align1 1Q };
492 0x00600001, 0x202003be, 0x008d0040, 0x00000000, // mov(8) m1<1>F g2<8,8,1>F { align1 1Q };
493 0x00600001, 0x204003be, 0x008d0060, 0x00000000, // mov(8) m2<1>F g3<8,8,1>F { align1 1Q };
494 0x00600001, 0x206003be, 0x008d0080, 0x00000000, // mov(8) m3<1>F g4<8,8,1>F { align1 1Q };
495 0x00600001, 0x208003be, 0x008d00a0, 0x00000000, // mov(8) m4<1>F g5<8,8,1>F { align1 1Q };
496 0x05600032, 0x20001fc8, 0x008d0020, 0x88019400, // sendc(8) null m1<8,8,1>F
497 // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT };
498 };
499 static const uint32_t gen7_copy_mem_code[] = {
500 0x00600040, 0x20a06d29, 0x00480028, 0x10101010, // add(8) g5<1>UW g1.4<2,4,0>UW 0x10101010V { align1 1Q };
501 0x00600001, 0x20600065, 0x00000000, 0x00000000, // mov(8) g3<1>D 0x00000000UD { align1 1Q };
502 0x00600001, 0x20c0013d, 0x008d00a0, 0x00000000, // mov(8) g6<1>F g5<8,8,1>UW { align1 1Q };
503 0x00600040, 0x20a07fbd, 0x008d00c0, 0x3f000000, // add(8) g5<1>F g6<8,8,1>F 0.5F { align1 1Q };
504 0x2000eb01, 0x00050707, // mov(8) g7<1>D g5<8,8,1>F { align1 1Q compacted };
505 0x20018b40, 0x04070207, // add(8) g2<1>D g7<8,8,1>D g4<0,1,0>D { align1 1Q compacted };
506 0x02600031, 0x2f801fa9, 0x008d0040, 0x04427001, // send(8) g124<1>UW g2<8,8,1>F
507 // sampler (1, 0, 7, 1) mlen 2 rlen 4 { align1 1Q };
508 0x05600032, 0x20001fa8, 0x008d0f80, 0x88031400, // sendc(8) null g124<8,8,1>F
509 // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT };
510 };
511 XGL_UINT surface_count, urb_grf_start;
512 struct intel_pipeline_shader *sh;
513 const void *code;
514 XGL_SIZE code_size;
515
516 switch (intel_gpu_gen(dev->gpu)) {
517 case INTEL_GEN(6):
518 if (id == INTEL_DEV_META_FS_COPY_MEM) {
519 code = gen6_copy_mem_code;
520 code_size = sizeof(gen6_copy_mem_code);
521 surface_count = 2;
522 urb_grf_start = 4;
523 } else {
524 code = gen6_clear_code;
525 code_size = sizeof(gen6_clear_code);
526 surface_count = 1;
527 urb_grf_start = 2;
528 }
529 break;
530 case INTEL_GEN(7):
531 case INTEL_GEN(7.5):
532 if (id == INTEL_DEV_META_FS_COPY_MEM) {
533 code = gen7_copy_mem_code;
534 code_size = sizeof(gen7_copy_mem_code);
535 surface_count = 2;
536 urb_grf_start = 4;
537 } else {
538 code = gen7_clear_code;
539 code_size = sizeof(gen7_clear_code);
540 surface_count = 1;
541 urb_grf_start = 2;
542 }
543 break;
544 default:
545 code = NULL;
546 break;
547 }
548
549 if (!code)
550 return NULL;
551
552 sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL);
553 if (!sh)
554 return NULL;
555 memset(sh, 0, sizeof(*sh));
556
557 sh->pCode = icd_alloc(code_size, 0, XGL_SYSTEM_ALLOC_INTERNAL);
558 if (!sh->pCode) {
559 icd_free(sh);
560 return NULL;
561 }
562
563 memcpy(sh->pCode, code, code_size);
564 sh->codeSize = code_size;
565
566 sh->out_count = 1;
567 sh->surface_count = surface_count;
568 sh->urb_grf_start = urb_grf_start;
569
570 return sh;
571}
572
573void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh)
574{
575 if (sh->rmap)
576 rmap_destroy(sh->rmap);
577 if (sh->pCode)
578 icd_free(sh->pCode);
579 icd_free(sh);
580}