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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef GLSL_LINKER_UTIL_H
25 #define GLSL_LINKER_UTIL_H
26
27 #include "util/bitset.h"
28 #include "util/glheader.h"
29 #include "compiler/glsl/list.h"
30 #include "compiler/glsl_types.h"
31 #include "main/mtypes.h"
32 #include "main/shader_types.h"
33
34 struct gl_constants;
35 struct gl_shader_program;
36 struct gl_uniform_storage;
37 struct set;
38
39 /**
40 * Built-in / reserved GL variables names start with "gl_"
41 */
42 static inline bool
is_gl_identifier(const char * s)43 is_gl_identifier(const char *s)
44 {
45 return s && s[0] == 'g' && s[1] == 'l' && s[2] == '_';
46 }
47
48 static inline GLenum
glsl_get_gl_type(const struct glsl_type * t)49 glsl_get_gl_type(const struct glsl_type *t)
50 {
51 return t->gl_type;
52 }
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 /**
59 * Sometimes there are empty slots left over in UniformRemapTable after we
60 * allocate slots to explicit locations. This struct represents a single
61 * continouous block of empty slots in UniformRemapTable.
62 */
63 struct empty_uniform_block {
64 struct exec_node link;
65 /* The start location of the block */
66 unsigned start;
67 /* The number of slots in the block */
68 unsigned slots;
69 };
70
71 /**
72 * Describes an access of an array element or an access of the whole array
73 */
74 struct array_deref_range {
75 /**
76 * Index that was accessed.
77 *
78 * All valid array indices are less than the size of the array. If index
79 * is equal to the size of the array, this means the entire array has been
80 * accessed (e.g., due to use of a non-constant index).
81 */
82 unsigned index;
83
84 /** Size of the array. Used for offset calculations. */
85 unsigned size;
86 };
87
88 void
89 link_shaders_init(struct gl_context *ctx, struct gl_shader_program *prog);
90
91 void
92 linker_error(struct gl_shader_program *prog, const char *fmt, ...);
93
94 void
95 linker_warning(struct gl_shader_program *prog, const char *fmt, ...);
96
97 long
98 link_util_parse_program_resource_name(const GLchar *name, const size_t len,
99 const GLchar **out_base_name_end);
100
101 bool
102 link_util_should_add_buffer_variable(struct gl_shader_program *prog,
103 struct gl_uniform_storage *uniform,
104 int top_level_array_base_offset,
105 int top_level_array_size_in_bytes,
106 int second_element_offset,
107 int block_index);
108
109 bool
110 link_util_add_program_resource(struct gl_shader_program *prog,
111 struct set *resource_set,
112 GLenum type, const void *data, uint8_t stages);
113
114 int
115 link_util_find_empty_block(struct gl_shader_program *prog,
116 struct gl_uniform_storage *uniform);
117
118 void
119 link_util_update_empty_uniform_locations(struct gl_shader_program *prog);
120
121 void
122 link_util_check_subroutine_resources(struct gl_shader_program *prog);
123
124 void
125 link_util_check_uniform_resources(const struct gl_constants *consts,
126 struct gl_shader_program *prog);
127
128 void
129 link_util_calculate_subroutine_compat(struct gl_shader_program *prog);
130
131 void
132 link_util_mark_array_elements_referenced(const struct array_deref_range *dr,
133 unsigned count, unsigned array_depth,
134 BITSET_WORD *bits);
135
136 void
137 resource_name_updated(struct gl_resource_name *name);
138
139 /**
140 * Get the string value for an interpolation qualifier
141 *
142 * \return The string that would be used in a shader to specify \c
143 * mode will be returned.
144 *
145 * This function is used to generate error messages of the form "shader
146 * uses %s interpolation qualifier", so in the case where there is no
147 * interpolation qualifier, it returns "no".
148 *
149 * This function should only be used on a shader input or output variable.
150 */
151 const char *interpolation_string(unsigned interpolation);
152
153 /**
154 * \brief Can \c from be implicitly converted to \c desired
155 *
156 * \return True if the types are identical or if \c from type can be converted
157 * to \c desired according to Section 4.1.10 of the GLSL spec.
158 *
159 * \verbatim
160 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
161 * Implicit Conversions:
162 *
163 * In some situations, an expression and its type will be implicitly
164 * converted to a different type. The following table shows all allowed
165 * implicit conversions:
166 *
167 * Type of expression | Can be implicitly converted to
168 * --------------------------------------------------
169 * int float
170 * uint
171 *
172 * ivec2 vec2
173 * uvec2
174 *
175 * ivec3 vec3
176 * uvec3
177 *
178 * ivec4 vec4
179 * uvec4
180 *
181 * There are no implicit array or structure conversions. For example,
182 * an array of int cannot be implicitly converted to an array of float.
183 * There are no implicit conversions between signed and unsigned
184 * integers.
185 * \endverbatim
186 */
187 extern bool _mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desired,
188 bool has_implicit_conversions,
189 bool has_implicit_int_to_uint_conversion);
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif /* GLSL_LINKER_UTIL_H */
196