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 "main/glheader.h"
31#include "main/menums.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37struct gl_constants;
38struct gl_extensions;
39struct gl_linked_shader;
40struct gl_shader_program;
41struct gl_transform_feedback_info;
42struct xfb_decl;
43struct nir_xfb_info;
44
45struct gl_nir_linker_options {
46   bool fill_parameters;
47};
48
49#define nir_foreach_gl_uniform_variable(var, shader) \
50   nir_foreach_variable_with_modes(var, shader, nir_var_uniform | \
51                                                nir_var_mem_ubo | \
52                                                nir_var_mem_ssbo | \
53                                                nir_var_image)
54
55void gl_nir_opts(nir_shader *nir);
56
57bool gl_nir_link_spirv(const struct gl_constants *consts,
58                       struct gl_shader_program *prog,
59                       const struct gl_nir_linker_options *options);
60
61bool gl_nir_link_glsl(const struct gl_constants *consts,
62                      const struct gl_extensions *exts,
63                      gl_api api,
64                      struct gl_shader_program *prog);
65
66bool gl_nir_link_uniforms(const struct gl_constants *consts,
67                          struct gl_shader_program *prog,
68                          bool fill_parameters);
69
70bool gl_nir_link_varyings(const struct gl_constants *consts,
71                          const struct gl_extensions *exts,
72                          gl_api api, struct gl_shader_program *prog);
73
74struct nir_xfb_info *
75gl_to_nir_xfb_info(struct gl_transform_feedback_info *info, void *mem_ctx);
76
77nir_variable * gl_nir_lower_xfb_varying(nir_shader *shader,
78                                        const char *old_var_name,
79                                        nir_variable *toplevel_var);
80
81void gl_nir_opt_dead_builtin_varyings(const struct gl_constants *consts,
82                                      gl_api api,
83                                      struct gl_shader_program *prog,
84                                      struct gl_linked_shader *producer,
85                                      struct gl_linked_shader *consumer,
86                                      unsigned num_tfeedback_decls,
87                                      struct xfb_decl *tfeedback_decls);
88
89void gl_nir_set_uniform_initializers(const struct gl_constants *consts,
90                                     struct gl_shader_program *prog);
91
92bool nir_add_packed_var_to_resource_list(const struct gl_constants *consts,
93                                         struct gl_shader_program *shProg,
94                                         struct set *resource_set,
95                                         nir_variable *var,
96                                         unsigned stage, GLenum type);
97
98void
99init_program_resource_list(struct gl_shader_program *prog);
100
101void nir_build_program_resource_list(const struct gl_constants *consts,
102                                     struct gl_shader_program *prog,
103                                     bool rebuild_resourse_list);
104
105void gl_nir_link_assign_atomic_counter_resources(const struct gl_constants *consts,
106                                                 struct gl_shader_program *prog);
107
108void gl_nir_link_check_atomic_counter_resources(const struct gl_constants *consts,
109                                                struct gl_shader_program *prog);
110
111void gl_nir_link_assign_xfb_resources(const struct gl_constants *consts,
112                                      struct gl_shader_program *prog);
113
114bool gl_nir_link_uniform_blocks(struct gl_shader_program *prog);
115
116#ifdef __cplusplus
117} /* extern "C" */
118#endif
119
120#endif /* GL_NIR_LINKER_H */
121