xref: /aosp_15_r20/external/mesa3d/src/compiler/glsl/gl_nir_linker.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2017 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 DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef GL_NIR_LINKER_H
25 #define GL_NIR_LINKER_H
26 
27 #include <stdbool.h>
28 
29 #include "nir.h"
30 #include "util/glheader.h"
31 #include "main/menums.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 struct gl_constants;
38 struct gl_context;
39 struct gl_extensions;
40 struct gl_linked_shader;
41 struct gl_shader_program;
42 struct gl_program;
43 struct gl_transform_feedback_info;
44 struct xfb_decl;
45 struct nir_xfb_info;
46 
47 struct gl_nir_linker_options {
48    bool fill_parameters;
49 };
50 
51 #define nir_foreach_gl_uniform_variable(var, shader) \
52    nir_foreach_variable_with_modes(var, shader, nir_var_uniform | \
53                                                 nir_var_mem_ubo | \
54                                                 nir_var_mem_ssbo | \
55                                                 nir_var_image)
56 
57 void gl_nir_opts(nir_shader *nir);
58 
59 void gl_nir_detect_recursion_linked(struct gl_shader_program *prog,
60                                     nir_shader *shader);
61 
62 bool gl_nir_link_spirv(const struct gl_constants *consts,
63                        const struct gl_extensions *exts,
64                        struct gl_shader_program *prog,
65                        const struct gl_nir_linker_options *options);
66 
67 bool gl_nir_link_glsl(struct gl_context *ctx,
68                       struct gl_shader_program *prog);
69 
70 bool gl_nir_link_uniforms(const struct gl_constants *consts,
71                           struct gl_shader_program *prog,
72                           bool fill_parameters);
73 
74 bool gl_nir_link_varyings(const struct gl_constants *consts,
75                           const struct gl_extensions *exts,
76                           gl_api api, struct gl_shader_program *prog);
77 
78 const char * gl_nir_mode_string(const nir_variable *var);
79 
80 bool gl_nir_validate_intrastage_arrays(struct gl_shader_program *prog,
81                                        nir_variable *var,
82                                        nir_variable *existing,
83                                        unsigned existing_stage,
84                                        bool match_precision);
85 
86 struct nir_xfb_info *
87 gl_to_nir_xfb_info(struct gl_transform_feedback_info *info, void *mem_ctx);
88 
89 nir_variable * gl_nir_lower_xfb_varying(nir_shader *shader,
90                                         const char *old_var_name,
91                                         nir_variable *toplevel_var);
92 
93 void gl_nir_opt_dead_builtin_varyings(const struct gl_constants *consts,
94                                       gl_api api,
95                                       struct gl_shader_program *prog,
96                                       struct gl_linked_shader *producer,
97                                       struct gl_linked_shader *consumer,
98                                       unsigned num_tfeedback_decls,
99                                       struct xfb_decl *tfeedback_decls);
100 
101 void gl_nir_set_uniform_initializers(const struct gl_constants *consts,
102                                      struct gl_shader_program *prog);
103 
104 bool nir_add_packed_var_to_resource_list(const struct gl_constants *consts,
105                                          struct gl_shader_program *shProg,
106                                          struct set *resource_set,
107                                          nir_variable *var,
108                                          unsigned stage, GLenum type);
109 
110 void
111 init_program_resource_list(struct gl_shader_program *prog);
112 
113 void nir_build_program_resource_list(const struct gl_constants *consts,
114                                      struct gl_shader_program *prog,
115                                      bool rebuild_resourse_list);
116 
117 void gl_nir_link_assign_atomic_counter_resources(const struct gl_constants *consts,
118                                                  struct gl_shader_program *prog);
119 
120 void gl_nir_link_check_atomic_counter_resources(const struct gl_constants *consts,
121                                                 struct gl_shader_program *prog);
122 
123 void gl_nir_link_assign_xfb_resources(const struct gl_constants *consts,
124                                       struct gl_shader_program *prog);
125 
126 void gl_nir_validate_interstage_inout_blocks(struct gl_shader_program *prog,
127                                              const struct gl_linked_shader *producer,
128                                              const struct gl_linked_shader *consumer);
129 
130 void gl_nir_validate_interstage_uniform_blocks(struct gl_shader_program *prog,
131                                                struct gl_linked_shader **stages);
132 
133 bool gl_nir_link_uniform_blocks(const struct gl_constants *consts,
134                                 struct gl_shader_program *prog);
135 
136 bool
137 gl_nir_can_add_pointsize_to_program(const struct gl_constants *consts,
138                                     struct gl_program *prog);
139 
140 bool
141 gl_nir_add_point_size(struct nir_shader *nir);
142 
143 bool lower_packed_varying_needs_lowering(nir_shader *shader, nir_variable *var,
144                                          bool xfb_enabled,
145                                          bool disable_xfb_packing,
146                                          bool disable_varying_packing);
147 
148 void
149 gl_nir_lower_optimize_varyings(const struct gl_constants *consts,
150                                struct gl_shader_program *prog, bool spirv);
151 
152 #ifdef __cplusplus
153 } /* extern "C" */
154 #endif
155 
156 #endif /* GL_NIR_LINKER_H */
157