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; 42 struct gl_shader_program; 43 struct gl_shader; 44 struct gl_program; 45 struct gl_transform_feedback_info; 46 struct xfb_decl; 47 struct nir_xfb_info; 48 49 struct gl_nir_linker_options { 50 bool fill_parameters; 51 }; 52 53 #define nir_foreach_gl_uniform_variable(var, shader) \ 54 nir_foreach_variable_with_modes(var, shader, nir_var_uniform | \ 55 nir_var_mem_ubo | \ 56 nir_var_mem_ssbo | \ 57 nir_var_image) 58 59 void gl_nir_opts(nir_shader *nir); 60 61 void gl_nir_detect_recursion_linked(struct gl_shader_program *prog, 62 nir_shader *shader); 63 64 bool gl_nir_link_spirv(const struct gl_constants *consts, 65 const struct gl_extensions *exts, 66 struct gl_shader_program *prog, 67 const struct gl_nir_linker_options *options); 68 69 bool gl_nir_link_glsl(struct gl_context *ctx, 70 struct gl_shader_program *prog); 71 72 bool gl_nir_link_function_calls(struct gl_shader_program *prog, 73 struct gl_shader *main, 74 struct gl_linked_shader *linked_sh, 75 struct gl_shader **shader_list, 76 unsigned num_shaders); 77 78 bool gl_nir_link_uniforms(const struct gl_constants *consts, 79 struct gl_shader_program *prog, 80 bool fill_parameters); 81 82 bool gl_nir_link_varyings(const struct gl_constants *consts, 83 const struct gl_extensions *exts, 84 gl_api api, struct gl_shader_program *prog); 85 86 const char * gl_nir_mode_string(const nir_variable *var); 87 88 bool gl_nir_validate_intrastage_arrays(struct gl_shader_program *prog, 89 nir_variable *var, 90 nir_variable *existing, 91 nir_shader *existing_shader, 92 bool match_precision); 93 94 void gl_nir_linker_size_arrays(nir_shader *shader); 95 96 struct nir_xfb_info * 97 gl_to_nir_xfb_info(struct gl_transform_feedback_info *info, void *mem_ctx); 98 99 nir_variable * gl_nir_lower_xfb_varying(nir_shader *shader, 100 const char *old_var_name, 101 nir_variable *toplevel_var); 102 103 void gl_nir_opt_dead_builtin_varyings(const struct gl_constants *consts, 104 gl_api api, 105 struct gl_shader_program *prog, 106 struct gl_linked_shader *producer, 107 struct gl_linked_shader *consumer, 108 unsigned num_tfeedback_decls, 109 struct xfb_decl *tfeedback_decls); 110 111 void gl_nir_set_uniform_initializers(const struct gl_constants *consts, 112 struct gl_shader_program *prog); 113 114 bool nir_add_packed_var_to_resource_list(const struct gl_constants *consts, 115 struct gl_shader_program *shProg, 116 struct set *resource_set, 117 nir_variable *var, 118 unsigned stage, GLenum type); 119 120 void 121 init_program_resource_list(struct gl_shader_program *prog); 122 123 void nir_build_program_resource_list(const struct gl_constants *consts, 124 struct gl_shader_program *prog, 125 bool rebuild_resourse_list); 126 127 void gl_nir_link_assign_atomic_counter_resources(const struct gl_constants *consts, 128 struct gl_shader_program *prog); 129 130 void gl_nir_link_check_atomic_counter_resources(const struct gl_constants *consts, 131 struct gl_shader_program *prog); 132 133 void gl_nir_link_assign_xfb_resources(const struct gl_constants *consts, 134 struct gl_shader_program *prog); 135 136 void gl_nir_validate_interstage_inout_blocks(struct gl_shader_program *prog, 137 const struct gl_linked_shader *producer, 138 const struct gl_linked_shader *consumer); 139 140 void gl_nir_validate_interstage_uniform_blocks(struct gl_shader_program *prog, 141 struct gl_linked_shader **stages); 142 143 bool gl_nir_link_uniform_blocks(const struct gl_constants *consts, 144 struct gl_shader_program *prog); 145 146 void gl_nir_validate_intrastage_interface_blocks(struct gl_shader_program *prog, 147 const struct gl_shader **shader_list, 148 unsigned num_shaders); 149 150 bool 151 gl_nir_can_add_pointsize_to_program(const struct gl_constants *consts, 152 struct gl_program *prog); 153 154 bool 155 gl_nir_add_point_size(struct nir_shader *nir); 156 157 bool lower_packed_varying_needs_lowering(nir_shader *shader, nir_variable *var, 158 bool xfb_enabled, 159 bool disable_xfb_packing, 160 bool disable_varying_packing); 161 162 void 163 gl_nir_lower_optimize_varyings(const struct gl_constants *consts, 164 struct gl_shader_program *prog, bool spirv); 165 166 #ifdef __cplusplus 167 } /* extern "C" */ 168 #endif 169 170 #endif /* GL_NIR_LINKER_H */ 171