68ecc7e5851a7c9ead7069cf4e412c5a6849d9fc
[mesa.git] / src / compiler / glsl / gl_nir_linker.c
1 /*
2 * Copyright © 2018 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "nir.h"
25 #include "gl_nir.h"
26 #include "gl_nir_linker.h"
27 #include "linker_util.h"
28 #include "main/mtypes.h"
29 #include "main/shaderobj.h"
30 #include "ir_uniform.h" /* for gl_uniform_storage */
31
32 /**
33 * This file included general link methods, using NIR, instead of IR as
34 * the counter-part glsl/linker.cpp
35 */
36
37 static bool
38 can_remove_uniform(nir_variable *var)
39 {
40 /* Section 2.11.6 (Uniform Variables) of the OpenGL ES 3.0.3 spec
41 * says:
42 *
43 * "All members of a named uniform block declared with a shared or
44 * std140 layout qualifier are considered active, even if they are not
45 * referenced in any shader in the program. The uniform block itself is
46 * also considered active, even if no member of the block is
47 * referenced."
48 *
49 * Although the spec doesn't state it std430 layouts are expect to behave
50 * the same way. If the variable is in a uniform block with one of those
51 * layouts, do not eliminate it.
52 */
53 if (nir_variable_is_in_block(var) &&
54 (glsl_get_ifc_packing(var->interface_type) !=
55 GLSL_INTERFACE_PACKING_PACKED))
56 return false;
57
58 if (glsl_get_base_type(glsl_without_array(var->type)) ==
59 GLSL_TYPE_SUBROUTINE)
60 return false;
61
62 /* Uniform initializers could get used by another stage */
63 if (var->constant_initializer)
64 return false;
65
66 return true;
67 }
68
69 /**
70 * Built-in / reserved GL variables names start with "gl_"
71 */
72 static inline bool
73 is_gl_identifier(const char *s)
74 {
75 return s && s[0] == 'g' && s[1] == 'l' && s[2] == '_';
76 }
77
78 static bool
79 inout_has_same_location(const nir_variable *var, unsigned stage)
80 {
81 if (!var->data.patch &&
82 ((var->data.mode == nir_var_shader_out &&
83 stage == MESA_SHADER_TESS_CTRL) ||
84 (var->data.mode == nir_var_shader_in &&
85 (stage == MESA_SHADER_TESS_CTRL || stage == MESA_SHADER_TESS_EVAL ||
86 stage == MESA_SHADER_GEOMETRY))))
87 return true;
88 else
89 return false;
90 }
91
92 /**
93 * Create gl_shader_variable from nir_variable.
94 */
95 static struct gl_shader_variable *
96 create_shader_variable(struct gl_shader_program *shProg,
97 const nir_variable *in,
98 const char *name, const struct glsl_type *type,
99 const struct glsl_type *interface_type,
100 bool use_implicit_location, int location,
101 const struct glsl_type *outermost_struct_type)
102 {
103 /* Allocate zero-initialized memory to ensure that bitfield padding
104 * is zero.
105 */
106 struct gl_shader_variable *out = rzalloc(shProg,
107 struct gl_shader_variable);
108 if (!out)
109 return NULL;
110
111 /* Since gl_VertexID may be lowered to gl_VertexIDMESA, but applications
112 * expect to see gl_VertexID in the program resource list. Pretend.
113 */
114 if (in->data.mode == nir_var_system_value &&
115 in->data.location == SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) {
116 out->name = ralloc_strdup(shProg, "gl_VertexID");
117 } else if ((in->data.mode == nir_var_shader_out &&
118 in->data.location == VARYING_SLOT_TESS_LEVEL_OUTER) ||
119 (in->data.mode == nir_var_system_value &&
120 in->data.location == SYSTEM_VALUE_TESS_LEVEL_OUTER)) {
121 out->name = ralloc_strdup(shProg, "gl_TessLevelOuter");
122 type = glsl_array_type(glsl_float_type(), 4, 0);
123 } else if ((in->data.mode == nir_var_shader_out &&
124 in->data.location == VARYING_SLOT_TESS_LEVEL_INNER) ||
125 (in->data.mode == nir_var_system_value &&
126 in->data.location == SYSTEM_VALUE_TESS_LEVEL_INNER)) {
127 out->name = ralloc_strdup(shProg, "gl_TessLevelInner");
128 type = glsl_array_type(glsl_float_type(), 2, 0);
129 } else {
130 out->name = ralloc_strdup(shProg, name);
131 }
132
133 if (!out->name)
134 return NULL;
135
136 /* The ARB_program_interface_query spec says:
137 *
138 * "Not all active variables are assigned valid locations; the
139 * following variables will have an effective location of -1:
140 *
141 * * uniforms declared as atomic counters;
142 *
143 * * members of a uniform block;
144 *
145 * * built-in inputs, outputs, and uniforms (starting with "gl_"); and
146 *
147 * * inputs or outputs not declared with a "location" layout
148 * qualifier, except for vertex shader inputs and fragment shader
149 * outputs."
150 */
151 if (glsl_get_base_type(in->type) == GLSL_TYPE_ATOMIC_UINT ||
152 is_gl_identifier(in->name) ||
153 !(in->data.explicit_location || use_implicit_location)) {
154 out->location = -1;
155 } else {
156 out->location = location;
157 }
158
159 out->type = type;
160 out->outermost_struct_type = outermost_struct_type;
161 out->interface_type = interface_type;
162 out->component = in->data.location_frac;
163 out->index = in->data.index;
164 out->patch = in->data.patch;
165 out->mode = in->data.mode;
166 out->interpolation = in->data.interpolation;
167 out->precision = in->data.precision;
168 out->explicit_location = in->data.explicit_location;
169
170 return out;
171 }
172
173 static bool
174 add_shader_variable(const struct gl_context *ctx,
175 struct gl_shader_program *shProg,
176 struct set *resource_set,
177 unsigned stage_mask,
178 GLenum programInterface, nir_variable *var,
179 const char *name, const struct glsl_type *type,
180 bool use_implicit_location, int location,
181 bool inouts_share_location,
182 const struct glsl_type *outermost_struct_type)
183 {
184 const struct glsl_type *interface_type = var->interface_type;
185
186 if (outermost_struct_type == NULL) {
187 if (var->data.from_named_ifc_block) {
188 const char *interface_name = glsl_get_type_name(interface_type);
189
190 if (glsl_type_is_array(interface_type)) {
191 /* Issue #16 of the ARB_program_interface_query spec says:
192 *
193 * "* If a variable is a member of an interface block without an
194 * instance name, it is enumerated using just the variable name.
195 *
196 * * If a variable is a member of an interface block with an
197 * instance name, it is enumerated as "BlockName.Member", where
198 * "BlockName" is the name of the interface block (not the
199 * instance name) and "Member" is the name of the variable."
200 *
201 * In particular, it indicates that it should be "BlockName",
202 * not "BlockName[array length]". The conformance suite and
203 * dEQP both require this behavior.
204 *
205 * Here, we unwrap the extra array level added by named interface
206 * block array lowering so we have the correct variable type. We
207 * also unwrap the interface type when constructing the name.
208 *
209 * We leave interface_type the same so that ES 3.x SSO pipeline
210 * validation can enforce the rules requiring array length to
211 * match on interface blocks.
212 */
213 type = glsl_get_array_element(type);
214
215 interface_name =
216 glsl_get_type_name(glsl_get_array_element(interface_type));
217 }
218
219 name = ralloc_asprintf(shProg, "%s.%s", interface_name, name);
220 }
221 }
222
223 switch (glsl_get_base_type(type)) {
224 case GLSL_TYPE_STRUCT: {
225 /* The ARB_program_interface_query spec says:
226 *
227 * "For an active variable declared as a structure, a separate entry
228 * will be generated for each active structure member. The name of
229 * each entry is formed by concatenating the name of the structure,
230 * the "." character, and the name of the structure member. If a
231 * structure member to enumerate is itself a structure or array,
232 * these enumeration rules are applied recursively."
233 */
234 if (outermost_struct_type == NULL)
235 outermost_struct_type = type;
236
237 unsigned field_location = location;
238 for (unsigned i = 0; i < glsl_get_length(type); i++) {
239 const struct glsl_type *field_type = glsl_get_struct_field(type, i);
240 const struct glsl_struct_field *field =
241 glsl_get_struct_field_data(type, i);
242
243 char *field_name = ralloc_asprintf(shProg, "%s.%s", name, field->name);
244 if (!add_shader_variable(ctx, shProg, resource_set,
245 stage_mask, programInterface,
246 var, field_name, field_type,
247 use_implicit_location, field_location,
248 false, outermost_struct_type))
249 return false;
250
251 field_location += glsl_count_attribute_slots(field_type, false);
252 }
253 return true;
254 }
255
256 case GLSL_TYPE_ARRAY: {
257 /* The ARB_program_interface_query spec says:
258 *
259 * "For an active variable declared as an array of basic types, a
260 * single entry will be generated, with its name string formed by
261 * concatenating the name of the array and the string "[0]"."
262 *
263 * "For an active variable declared as an array of an aggregate data
264 * type (structures or arrays), a separate entry will be generated
265 * for each active array element, unless noted immediately below.
266 * The name of each entry is formed by concatenating the name of
267 * the array, the "[" character, an integer identifying the element
268 * number, and the "]" character. These enumeration rules are
269 * applied recursively, treating each enumerated array element as a
270 * separate active variable."
271 */
272 const struct glsl_type *array_type = glsl_get_array_element(type);
273 if (glsl_get_base_type(array_type) == GLSL_TYPE_STRUCT ||
274 glsl_get_base_type(array_type) == GLSL_TYPE_ARRAY) {
275 unsigned elem_location = location;
276 unsigned stride = inouts_share_location ? 0 :
277 glsl_count_attribute_slots(array_type, false);
278 for (unsigned i = 0; i < glsl_get_length(type); i++) {
279 char *elem = ralloc_asprintf(shProg, "%s[%d]", name, i);
280 if (!add_shader_variable(ctx, shProg, resource_set,
281 stage_mask, programInterface,
282 var, elem, array_type,
283 use_implicit_location, elem_location,
284 false, outermost_struct_type))
285 return false;
286 elem_location += stride;
287 }
288 return true;
289 }
290 }
291 /* fallthrough */
292
293 default: {
294 /* The ARB_program_interface_query spec says:
295 *
296 * "For an active variable declared as a single instance of a basic
297 * type, a single entry will be generated, using the variable name
298 * from the shader source."
299 */
300 struct gl_shader_variable *sha_v =
301 create_shader_variable(shProg, var, name, type, interface_type,
302 use_implicit_location, location,
303 outermost_struct_type);
304 if (!sha_v)
305 return false;
306
307 return link_util_add_program_resource(shProg, resource_set,
308 programInterface, sha_v, stage_mask);
309 }
310 }
311 }
312
313 static bool
314 add_vars_with_mode(const struct gl_context *ctx,
315 struct gl_shader_program *prog, struct set *resource_set,
316 nir_shader *nir, nir_variable_mode mode,
317 unsigned stage, GLenum programInterface)
318 {
319 nir_foreach_variable_with_modes(var, nir, mode) {
320 if (var->data.how_declared == nir_var_hidden)
321 continue;
322
323 int loc_bias = 0;
324 switch(var->data.mode) {
325 case nir_var_system_value:
326 case nir_var_shader_in:
327 if (programInterface != GL_PROGRAM_INPUT)
328 continue;
329 loc_bias = (stage == MESA_SHADER_VERTEX) ? VERT_ATTRIB_GENERIC0
330 : VARYING_SLOT_VAR0;
331 break;
332 case nir_var_shader_out:
333 if (programInterface != GL_PROGRAM_OUTPUT)
334 continue;
335 loc_bias = (stage == MESA_SHADER_FRAGMENT) ? FRAG_RESULT_DATA0
336 : VARYING_SLOT_VAR0;
337 break;
338 default:
339 continue;
340 }
341
342 if (var->data.patch)
343 loc_bias = VARYING_SLOT_PATCH0;
344
345 if (prog->data->spirv) {
346 struct gl_shader_variable *sh_var =
347 rzalloc(prog, struct gl_shader_variable);
348
349 /* In the ARB_gl_spirv spec, names are considered optional debug info, so
350 * the linker needs to work without them. Returning them is optional.
351 * For simplicity, we ignore names.
352 */
353 sh_var->name = NULL;
354 sh_var->type = var->type;
355 sh_var->location = var->data.location - loc_bias;
356 sh_var->index = var->data.index;
357
358 if (!link_util_add_program_resource(prog, resource_set,
359 programInterface,
360 sh_var, 1 << stage)) {
361 return false;
362 }
363 } else {
364 /* Skip packed varyings, packed varyings are handled separately
365 * by add_packed_varyings in the GLSL IR
366 * build_program_resource_list() call.
367 * TODO: handle packed varyings here instead. We likely want a NIR
368 * based packing pass first.
369 */
370 if (strncmp(var->name, "packed:", 7) == 0)
371 continue;
372
373 const bool vs_input_or_fs_output =
374 (stage == MESA_SHADER_VERTEX &&
375 var->data.mode == nir_var_shader_in) ||
376 (stage == MESA_SHADER_FRAGMENT &&
377 var->data.mode == nir_var_shader_out);
378
379 if (!add_shader_variable(ctx, prog, resource_set,
380 1 << stage, programInterface,
381 var, var->name, var->type,
382 vs_input_or_fs_output,
383 var->data.location - loc_bias,
384 inout_has_same_location(var, stage),
385 NULL))
386 return false;
387 }
388 }
389
390 return true;
391 }
392
393 static bool
394 add_interface_variables(const struct gl_context *ctx,
395 struct gl_shader_program *prog,
396 struct set *resource_set,
397 unsigned stage, GLenum programInterface)
398 {
399 struct gl_linked_shader *sh = prog->_LinkedShaders[stage];
400 if (!sh)
401 return true;
402
403 nir_shader *nir = sh->Program->nir;
404 assert(nir);
405
406 switch (programInterface) {
407 case GL_PROGRAM_INPUT: {
408 bool result = add_vars_with_mode(ctx, prog, resource_set,
409 nir, nir_var_shader_in,
410 stage, programInterface);
411 result &= add_vars_with_mode(ctx, prog, resource_set,
412 nir, nir_var_system_value,
413 stage, programInterface);
414 return result;
415 }
416 case GL_PROGRAM_OUTPUT:
417 return add_vars_with_mode(ctx, prog, resource_set,
418 nir, nir_var_shader_out,
419 stage, programInterface);
420 default:
421 assert("!Should not get here");
422 break;
423 }
424
425 return false;
426 }
427
428 /* TODO: as we keep adding features, this method is becoming more and more
429 * similar to its GLSL counterpart at linker.cpp. Eventually it would be good
430 * to check if they could be refactored, and reduce code duplication somehow
431 */
432 void
433 nir_build_program_resource_list(struct gl_context *ctx,
434 struct gl_shader_program *prog,
435 bool rebuild_resourse_list)
436 {
437 /* Rebuild resource list. */
438 if (prog->data->ProgramResourceList && rebuild_resourse_list) {
439 ralloc_free(prog->data->ProgramResourceList);
440 prog->data->ProgramResourceList = NULL;
441 prog->data->NumProgramResourceList = 0;
442 }
443
444 int input_stage = MESA_SHADER_STAGES, output_stage = 0;
445
446 /* Determine first input and final output stage. These are used to
447 * detect which variables should be enumerated in the resource list
448 * for GL_PROGRAM_INPUT and GL_PROGRAM_OUTPUT.
449 */
450 for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
451 if (!prog->_LinkedShaders[i])
452 continue;
453 if (input_stage == MESA_SHADER_STAGES)
454 input_stage = i;
455 output_stage = i;
456 }
457
458 /* Empty shader, no resources. */
459 if (input_stage == MESA_SHADER_STAGES && output_stage == 0)
460 return;
461
462 struct set *resource_set = _mesa_pointer_set_create(NULL);
463
464 /* Add inputs and outputs to the resource list. */
465 if (!add_interface_variables(ctx, prog, resource_set, input_stage,
466 GL_PROGRAM_INPUT)) {
467 return;
468 }
469
470 if (!add_interface_variables(ctx, prog, resource_set, output_stage,
471 GL_PROGRAM_OUTPUT)) {
472 return;
473 }
474
475 /* Add transform feedback varyings and buffers. */
476 if (prog->last_vert_prog) {
477 struct gl_transform_feedback_info *linked_xfb =
478 prog->last_vert_prog->sh.LinkedTransformFeedback;
479
480 /* Add varyings. */
481 if (linked_xfb->NumVarying > 0) {
482 for (int i = 0; i < linked_xfb->NumVarying; i++) {
483 if (!link_util_add_program_resource(prog, resource_set,
484 GL_TRANSFORM_FEEDBACK_VARYING,
485 &linked_xfb->Varyings[i], 0))
486 return;
487 }
488 }
489
490 /* Add buffers. */
491 for (unsigned i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) {
492 if ((linked_xfb->ActiveBuffers >> i) & 1) {
493 linked_xfb->Buffers[i].Binding = i;
494 if (!link_util_add_program_resource(prog, resource_set,
495 GL_TRANSFORM_FEEDBACK_BUFFER,
496 &linked_xfb->Buffers[i], 0))
497 return;
498 }
499 }
500 }
501
502 /* Add uniforms
503 *
504 * Here, it is expected that nir_link_uniforms() has already been
505 * called, so that UniformStorage table is already available.
506 */
507 int top_level_array_base_offset = -1;
508 int top_level_array_size_in_bytes = -1;
509 int second_element_offset = -1;
510 int block_index = -1;
511 for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
512 struct gl_uniform_storage *uniform = &prog->data->UniformStorage[i];
513
514 if (uniform->hidden) {
515 for (int j = MESA_SHADER_VERTEX; j < MESA_SHADER_STAGES; j++) {
516 if (!uniform->opaque[j].active ||
517 glsl_get_base_type(uniform->type) != GLSL_TYPE_SUBROUTINE)
518 continue;
519
520 GLenum type =
521 _mesa_shader_stage_to_subroutine_uniform((gl_shader_stage)j);
522 /* add shader subroutines */
523 if (!link_util_add_program_resource(prog, resource_set,
524 type, uniform, 0))
525 return;
526 }
527
528 continue;
529 }
530
531 if (!link_util_should_add_buffer_variable(prog, uniform,
532 top_level_array_base_offset,
533 top_level_array_size_in_bytes,
534 second_element_offset, block_index))
535 continue;
536
537
538 if (prog->data->UniformStorage[i].offset >= second_element_offset) {
539 top_level_array_base_offset =
540 prog->data->UniformStorage[i].offset;
541
542 top_level_array_size_in_bytes =
543 prog->data->UniformStorage[i].top_level_array_size *
544 prog->data->UniformStorage[i].top_level_array_stride;
545
546 /* Set or reset the second element offset. For non arrays this
547 * will be set to -1.
548 */
549 second_element_offset = top_level_array_size_in_bytes ?
550 top_level_array_base_offset +
551 prog->data->UniformStorage[i].top_level_array_stride : -1;
552 }
553 block_index = uniform->block_index;
554
555
556 GLenum interface = uniform->is_shader_storage ? GL_BUFFER_VARIABLE : GL_UNIFORM;
557 if (!link_util_add_program_resource(prog, resource_set, interface, uniform,
558 uniform->active_shader_mask)) {
559 return;
560 }
561 }
562
563
564 for (unsigned i = 0; i < prog->data->NumUniformBlocks; i++) {
565 if (!link_util_add_program_resource(prog, resource_set, GL_UNIFORM_BLOCK,
566 &prog->data->UniformBlocks[i],
567 prog->data->UniformBlocks[i].stageref))
568 return;
569 }
570
571 for (unsigned i = 0; i < prog->data->NumShaderStorageBlocks; i++) {
572 if (!link_util_add_program_resource(prog, resource_set, GL_SHADER_STORAGE_BLOCK,
573 &prog->data->ShaderStorageBlocks[i],
574 prog->data->ShaderStorageBlocks[i].stageref))
575 return;
576 }
577
578 /* Add atomic counter buffers. */
579 for (unsigned i = 0; i < prog->data->NumAtomicBuffers; i++) {
580 if (!link_util_add_program_resource(prog, resource_set, GL_ATOMIC_COUNTER_BUFFER,
581 &prog->data->AtomicBuffers[i], 0))
582 return;
583 }
584
585 unsigned mask = prog->data->linked_stages;
586 while (mask) {
587 const int i = u_bit_scan(&mask);
588 struct gl_program *p = prog->_LinkedShaders[i]->Program;
589
590 GLuint type = _mesa_shader_stage_to_subroutine((gl_shader_stage)i);
591 for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
592 if (!link_util_add_program_resource(prog, resource_set,
593 type,
594 &p->sh.SubroutineFunctions[j],
595 0))
596 return;
597 }
598 }
599
600 _mesa_set_destroy(resource_set, NULL);
601 }
602
603 bool
604 gl_nir_link_spirv(struct gl_context *ctx, struct gl_shader_program *prog,
605 const struct gl_nir_linker_options *options)
606 {
607 for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
608 struct gl_linked_shader *shader = prog->_LinkedShaders[i];
609 if (shader) {
610 nir_remove_dead_variables(shader->Program->nir, nir_var_uniform,
611 &can_remove_uniform);
612 }
613 }
614
615 if (!gl_nir_link_uniform_blocks(ctx, prog))
616 return false;
617
618 if (!gl_nir_link_uniforms(ctx, prog, options->fill_parameters))
619 return false;
620
621 gl_nir_link_assign_atomic_counter_resources(ctx, prog);
622 gl_nir_link_assign_xfb_resources(ctx, prog);
623
624 return true;
625 }
626
627 /**
628 * Validate shader image resources.
629 */
630 static void
631 check_image_resources(struct gl_context *ctx, struct gl_shader_program *prog)
632 {
633 unsigned total_image_units = 0;
634 unsigned fragment_outputs = 0;
635 unsigned total_shader_storage_blocks = 0;
636
637 if (!ctx->Extensions.ARB_shader_image_load_store)
638 return;
639
640 for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
641 struct gl_linked_shader *sh = prog->_LinkedShaders[i];
642 if (!sh)
643 continue;
644
645 total_image_units += sh->Program->info.num_images;
646 total_shader_storage_blocks += sh->Program->info.num_ssbos;
647 }
648
649 if (total_image_units > ctx->Const.MaxCombinedImageUniforms)
650 linker_error(prog, "Too many combined image uniforms\n");
651
652 struct gl_linked_shader *frag_sh =
653 prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
654 if (frag_sh) {
655 uint64_t frag_outputs_written = frag_sh->Program->info.outputs_written;
656 fragment_outputs = util_bitcount64(frag_outputs_written);
657 }
658
659 if (total_image_units + fragment_outputs + total_shader_storage_blocks >
660 ctx->Const.MaxCombinedShaderOutputResources)
661 linker_error(prog, "Too many combined image uniforms, shader storage "
662 " buffers and fragment outputs\n");
663 }
664
665 bool
666 gl_nir_link_glsl(struct gl_context *ctx, struct gl_shader_program *prog)
667 {
668 for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
669 struct gl_linked_shader *shader = prog->_LinkedShaders[i];
670 if (shader) {
671 nir_remove_dead_variables(shader->Program->nir, nir_var_uniform,
672 &can_remove_uniform);
673 }
674 }
675
676 if (!gl_nir_link_uniforms(ctx, prog, true))
677 return false;
678
679 link_util_calculate_subroutine_compat(prog);
680 link_util_check_uniform_resources(ctx, prog);
681 link_util_check_subroutine_resources(prog);
682 check_image_resources(ctx, prog);
683 gl_nir_link_assign_atomic_counter_resources(ctx, prog);
684 gl_nir_link_check_atomic_counter_resources(ctx, prog);
685
686 if (prog->data->LinkStatus == LINKING_FAILURE)
687 return false;
688
689 return true;
690 }