1 /*
2 * Copyright © 2023 Valve Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include "nir.h"
8 #include "nir_builder.h"
9 #include "radv_nir.h"
10 #include "radv_pipeline_graphics.h"
11
12 static bool
radv_should_lower_poly_line_smooth(nir_shader * nir,const struct radv_graphics_state_key * gfx_state)13 radv_should_lower_poly_line_smooth(nir_shader *nir, const struct radv_graphics_state_key *gfx_state)
14 {
15 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
16
17 if (!gfx_state->dynamic_line_rast_mode)
18 return false;
19
20 nir_foreach_block (block, impl) {
21 nir_foreach_instr (instr, block) {
22 if (instr->type != nir_instr_type_intrinsic)
23 continue;
24
25 nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
26 if (intr->intrinsic != nir_intrinsic_store_output)
27 continue;
28
29 /* Line smooth lowering is only valid for vec4. */
30 if (intr->num_components != 4)
31 return false;
32 }
33 }
34
35 return true;
36 }
37
38 void
radv_nir_lower_poly_line_smooth(nir_shader * nir,const struct radv_graphics_state_key * gfx_state)39 radv_nir_lower_poly_line_smooth(nir_shader *nir, const struct radv_graphics_state_key *gfx_state)
40 {
41 bool progress = false;
42
43 if (!radv_should_lower_poly_line_smooth(nir, gfx_state))
44 return;
45
46 NIR_PASS(progress, nir, nir_lower_poly_line_smooth, RADV_NUM_SMOOTH_AA_SAMPLES);
47 if (progress)
48 nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
49 }
50