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
);
75 validate_interstage_interface_blocks(struct gl_shader_program
*prog
,
76 const gl_shader
*producer
,
77 const gl_shader
*consumer
)
79 glsl_symbol_table interfaces
;
81 /* Add non-output interfaces from the consumer to the symbol table. */
82 foreach_list(node
, consumer
->ir
) {
83 ir_variable
*var
= ((ir_instruction
*) node
)->as_variable();
84 if (!var
|| !var
->interface_type
|| var
->mode
== ir_var_shader_out
)
87 interfaces
.add_interface(var
->interface_type
->name
,
89 (enum ir_variable_mode
) var
->mode
);
92 /* Verify that the producer's interfaces match. */
93 foreach_list(node
, producer
->ir
) {
94 ir_variable
*var
= ((ir_instruction
*) node
)->as_variable();
95 if (!var
|| !var
->interface_type
|| var
->mode
== ir_var_shader_in
)
98 enum ir_variable_mode consumer_mode
=
99 var
->mode
== ir_var_uniform
? ir_var_uniform
: ir_var_shader_in
;
100 const glsl_type
*expected_type
=
101 interfaces
.get_interface(var
->interface_type
->name
, consumer_mode
);
103 /* The consumer doesn't use this output block. Ignore it. */
104 if (expected_type
== NULL
)
107 if (var
->interface_type
!= expected_type
) {
108 linker_error(prog
, "definitions of interface block `%s' do not "
109 "match\n", var
->interface_type
->name
);