radv/ac: move needs_push_constants to shader info.
[mesa.git] / src / amd / common / ac_shader_info.c
1 /*
2 * Copyright © 2017 Red Hat
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 #include "nir.h"
24 #include "ac_shader_info.h"
25 #include "ac_nir_to_llvm.h"
26 static void
27 gather_intrinsic_info(nir_intrinsic_instr *instr, struct ac_shader_info *info)
28 {
29 switch (instr->intrinsic) {
30 case nir_intrinsic_interp_var_at_sample:
31 info->ps.needs_sample_positions = true;
32 break;
33 case nir_intrinsic_load_draw_id:
34 info->vs.needs_draw_id = true;
35 break;
36 case nir_intrinsic_load_num_work_groups:
37 info->cs.grid_components_used = instr->num_components;
38 break;
39 default:
40 break;
41 }
42 }
43
44 static void
45 gather_info_block(nir_block *block, struct ac_shader_info *info)
46 {
47 nir_foreach_instr(instr, block) {
48 switch (instr->type) {
49 case nir_instr_type_intrinsic:
50 gather_intrinsic_info(nir_instr_as_intrinsic(instr), info);
51 break;
52 default:
53 break;
54 }
55 }
56 }
57
58 static void
59 gather_info_input_decl(nir_shader *nir,
60 const struct ac_nir_compiler_options *options,
61 nir_variable *var,
62 struct ac_shader_info *info)
63 {
64 switch (nir->stage) {
65 case MESA_SHADER_VERTEX:
66 info->vs.has_vertex_buffers = true;
67 break;
68 default:
69 break;
70 }
71 }
72
73 void
74 ac_nir_shader_info_pass(struct nir_shader *nir,
75 const struct ac_nir_compiler_options *options,
76 struct ac_shader_info *info)
77 {
78 struct nir_function *func = (struct nir_function *)exec_list_get_head(&nir->functions);
79
80 info->needs_push_constants = true;
81 if (!options->layout)
82 info->needs_push_constants = false;
83 else if (!options->layout->push_constant_size &&
84 !options->layout->dynamic_offset_count)
85 info->needs_push_constants = false;
86
87 nir_foreach_variable(variable, &nir->inputs)
88 gather_info_input_decl(nir, options, variable, info);
89
90 nir_foreach_block(block, func->impl) {
91 gather_info_block(block, info);
92 }
93 }