2 * Copyright © 2017 Red Hat
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:
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
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
24 #include "ac_shader_info.h"
25 #include "ac_nir_to_llvm.h"
27 static void mark_sampler_desc(nir_variable
*var
, struct ac_shader_info
*info
)
29 info
->desc_set_used_mask
= (1 << var
->data
.descriptor_set
);
33 gather_intrinsic_info(nir_intrinsic_instr
*instr
, struct ac_shader_info
*info
)
35 switch (instr
->intrinsic
) {
36 case nir_intrinsic_interp_var_at_sample
:
37 info
->ps
.needs_sample_positions
= true;
39 case nir_intrinsic_load_draw_id
:
40 info
->vs
.needs_draw_id
= true;
42 case nir_intrinsic_load_instance_id
:
43 info
->vs
.needs_instance_id
= true;
45 case nir_intrinsic_load_num_work_groups
:
46 info
->cs
.grid_components_used
= instr
->num_components
;
48 case nir_intrinsic_load_sample_id
:
49 info
->ps
.force_persample
= true;
51 case nir_intrinsic_load_sample_pos
:
52 info
->ps
.force_persample
= true;
54 case nir_intrinsic_load_view_index
:
55 info
->needs_multiview_view_index
= true;
57 case nir_intrinsic_vulkan_resource_index
:
58 info
->desc_set_used_mask
|= (1 << nir_intrinsic_desc_set(instr
));
60 case nir_intrinsic_image_load
:
61 case nir_intrinsic_image_store
:
62 case nir_intrinsic_image_atomic_add
:
63 case nir_intrinsic_image_atomic_min
:
64 case nir_intrinsic_image_atomic_max
:
65 case nir_intrinsic_image_atomic_and
:
66 case nir_intrinsic_image_atomic_or
:
67 case nir_intrinsic_image_atomic_xor
:
68 case nir_intrinsic_image_atomic_exchange
:
69 case nir_intrinsic_image_atomic_comp_swap
:
70 case nir_intrinsic_image_size
: {
71 const struct glsl_type
*type
= instr
->variables
[0]->var
->type
;
72 if(instr
->variables
[0]->deref
.child
)
73 type
= instr
->variables
[0]->deref
.child
->type
;
75 enum glsl_sampler_dim dim
= glsl_get_sampler_dim(type
);
76 if (dim
== GLSL_SAMPLER_DIM_SUBPASS
||
77 dim
== GLSL_SAMPLER_DIM_SUBPASS_MS
)
78 info
->ps
.uses_input_attachments
= true;
79 mark_sampler_desc(instr
->variables
[0]->var
, info
);
88 gather_tex_info(nir_tex_instr
*instr
, struct ac_shader_info
*info
)
91 mark_sampler_desc(instr
->sampler
->var
, info
);
93 mark_sampler_desc(instr
->texture
->var
, info
);
97 gather_info_block(nir_block
*block
, struct ac_shader_info
*info
)
99 nir_foreach_instr(instr
, block
) {
100 switch (instr
->type
) {
101 case nir_instr_type_intrinsic
:
102 gather_intrinsic_info(nir_instr_as_intrinsic(instr
), info
);
104 case nir_instr_type_tex
:
105 gather_tex_info(nir_instr_as_tex(instr
), info
);
114 gather_info_input_decl(nir_shader
*nir
,
115 const struct ac_nir_compiler_options
*options
,
117 struct ac_shader_info
*info
)
119 switch (nir
->stage
) {
120 case MESA_SHADER_VERTEX
:
121 info
->vs
.has_vertex_buffers
= true;
129 ac_nir_shader_info_pass(struct nir_shader
*nir
,
130 const struct ac_nir_compiler_options
*options
,
131 struct ac_shader_info
*info
)
133 struct nir_function
*func
= (struct nir_function
*)exec_list_get_head(&nir
->functions
);
135 info
->needs_push_constants
= true;
136 if (!options
->layout
)
137 info
->needs_push_constants
= false;
138 else if (!options
->layout
->push_constant_size
&&
139 !options
->layout
->dynamic_offset_count
)
140 info
->needs_push_constants
= false;
142 nir_foreach_variable(variable
, &nir
->inputs
)
143 gather_info_input_decl(nir
, options
, variable
, info
);
145 nir_foreach_block(block
, func
->impl
) {
146 gather_info_block(block
, info
);