2 * Copyright © 2013 Intel Corporation
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:
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
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
21 * DEALINGS IN THE SOFTWARE.
25 * \file link_interface_blocks.cpp
26 * Linker support for GLSL's interface blocks.
30 #include "glsl_symbol_table.h"
32 #include "main/macros.h"
35 validate_intrastage_interface_blocks(struct gl_shader_program
*prog
,
36 const gl_shader
**shader_list
,
39 glsl_symbol_table interfaces
;
41 for (unsigned int i
= 0; i
< num_shaders
; i
++) {
42 if (shader_list
[i
] == NULL
)
45 foreach_list(node
, shader_list
[i
]->ir
) {
46 ir_variable
*var
= ((ir_instruction
*) node
)->as_variable();
50 const glsl_type
*iface_type
= var
->interface_type
;
52 if (iface_type
== NULL
)
55 const glsl_type
*old_iface_type
=
56 interfaces
.get_interface(iface_type
->name
,
57 (enum ir_variable_mode
) var
->mode
);
59 if (old_iface_type
== NULL
) {
60 /* This is the first time we've seen the interface, so save
61 * it into our symbol table.
63 interfaces
.add_interface(iface_type
->name
, iface_type
,
64 (enum ir_variable_mode
) var
->mode
);
65 } else if (old_iface_type
!= iface_type
) {
66 linker_error(prog
, "definitions of interface block `%s' do not"
67 " match\n", iface_type
->name
);
77 validate_interstage_interface_blocks(const gl_shader
*producer
,
78 const gl_shader
*consumer
)
80 glsl_symbol_table interfaces
;
82 /* Add non-output interfaces from the consumer to the symbol table. */
83 foreach_list(node
, consumer
->ir
) {
84 ir_variable
*var
= ((ir_instruction
*) node
)->as_variable();
85 if (!var
|| !var
->interface_type
|| var
->mode
== ir_var_shader_out
)
88 interfaces
.add_interface(var
->interface_type
->name
,
90 (enum ir_variable_mode
) var
->mode
);
93 /* Verify that the producer's interfaces match. */
94 foreach_list(node
, producer
->ir
) {
95 ir_variable
*var
= ((ir_instruction
*) node
)->as_variable();
96 if (!var
|| !var
->interface_type
|| var
->mode
== ir_var_shader_in
)
99 enum ir_variable_mode consumer_mode
=
100 var
->mode
== ir_var_uniform
? ir_var_uniform
: ir_var_shader_in
;
101 const glsl_type
*expected_type
=
102 interfaces
.get_interface(var
->interface_type
->name
, consumer_mode
);
104 /* The consumer doesn't use this output block. Ignore it. */
105 if (expected_type
== NULL
)
108 if (var
->interface_type
!= expected_type
)