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
32 struct gl_constants;
33 struct gl_shader_program;
34 struct gl_uniform_storage;
35 struct set;
36
37 /**
38 * Built-in / reserved GL variables names start with "gl_"
39 */
40 static inline bool
is_gl_identifier(const char * s)41 is_gl_identifier(const char *s)
42 {
43 return s && s[0] == 'g' && s[1] == 'l' && s[2] == '_';
44 }
45
46 static inline GLenum
glsl_get_gl_type(const struct glsl_type * t)47 glsl_get_gl_type(const struct glsl_type *t)
48 {
49 return t->gl_type;
50 }
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 /**
57 * Sometimes there are empty slots left over in UniformRemapTable after we
58 * allocate slots to explicit locations. This struct represents a single
59 * continouous block of empty slots in UniformRemapTable.
60 */
61 struct empty_uniform_block {
62 struct exec_node link;
63 /* The start location of the block */
64 unsigned start;
65 /* The number of slots in the block */
66 unsigned slots;
67 };
68
69 /**
70 * Describes an access of an array element or an access of the whole array
71 */
72 struct array_deref_range {
73 /**
74 * Index that was accessed.
75 *
76 * All valid array indices are less than the size of the array. If index
77 * is equal to the size of the array, this means the entire array has been
78 * accessed (e.g., due to use of a non-constant index).
79 */
80 unsigned index;
81
82 /** Size of the array. Used for offset calculations. */
83 unsigned size;
84 };
85
86 void
87 linker_error(struct gl_shader_program *prog, const char *fmt, ...);
88
89 void
90 linker_warning(struct gl_shader_program *prog, const char *fmt, ...);
91
92 long
93 link_util_parse_program_resource_name(const GLchar *name, const size_t len,
94 const GLchar **out_base_name_end);
95
96 bool
97 link_util_should_add_buffer_variable(struct gl_shader_program *prog,
98 struct gl_uniform_storage *uniform,
99 int top_level_array_base_offset,
100 int top_level_array_size_in_bytes,
101 int second_element_offset,
102 int block_index);
103
104 bool
105 link_util_add_program_resource(struct gl_shader_program *prog,
106 struct set *resource_set,
107 GLenum type, const void *data, uint8_t stages);
108
109 int
110 link_util_find_empty_block(struct gl_shader_program *prog,
111 struct gl_uniform_storage *uniform);
112
113 void
114 link_util_update_empty_uniform_locations(struct gl_shader_program *prog);
115
116 void
117 link_util_check_subroutine_resources(struct gl_shader_program *prog);
118
119 void
120 link_util_check_uniform_resources(const struct gl_constants *consts,
121 struct gl_shader_program *prog);
122
123 void
124 link_util_calculate_subroutine_compat(struct gl_shader_program *prog);
125
126 void
127 link_util_mark_array_elements_referenced(const struct array_deref_range *dr,
128 unsigned count, unsigned array_depth,
129 BITSET_WORD *bits);
130
131 /**
132 * Get the string value for an interpolation qualifier
133 *
134 * \return The string that would be used in a shader to specify \c
135 * mode will be returned.
136 *
137 * This function is used to generate error messages of the form "shader
138 * uses %s interpolation qualifier", so in the case where there is no
139 * interpolation qualifier, it returns "no".
140 *
141 * This function should only be used on a shader input or output variable.
142 */
143 const char *interpolation_string(unsigned interpolation);
144
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif /* GLSL_LINKER_UTIL_H */
150