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