1 /*
2 * Copyright 2023 Pavel Ondračka <pavel.ondracka@gmail.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef R300_NIR_H
24 #define R300_NIR_H
25
26 #include "pipe/p_screen.h"
27 #include "compiler/nir/nir.h"
28
29 static inline bool
is_ubo_or_input(UNUSED struct hash_table * ht,const nir_alu_instr * instr,unsigned src,unsigned num_components,const uint8_t * swizzle)30 is_ubo_or_input(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
31 unsigned src, unsigned num_components,
32 const uint8_t *swizzle)
33 {
34 nir_instr *parent = instr->src[src].src.ssa->parent_instr;
35 if (parent->type != nir_instr_type_intrinsic)
36 return false;
37
38 nir_intrinsic_instr *intrinsic = nir_instr_as_intrinsic(parent);
39
40 switch (intrinsic->intrinsic) {
41 case nir_intrinsic_load_ubo_vec4:
42 case nir_intrinsic_load_input:
43 case nir_intrinsic_load_interpolated_input:
44 return true;
45 default:
46 return false;
47 }
48 }
49
50 static inline bool
is_not_used_in_single_if(const nir_alu_instr * instr)51 is_not_used_in_single_if(const nir_alu_instr *instr)
52 {
53 unsigned if_uses = 0;
54 nir_foreach_use(src, &instr->def) {
55 if (nir_src_is_if(src))
56 if_uses++;
57 else
58 return true;
59 }
60 return if_uses != 1;
61 }
62
63 static inline bool
is_only_used_by_load_ubo_vec4(const nir_alu_instr * instr)64 is_only_used_by_load_ubo_vec4(const nir_alu_instr *instr)
65 {
66 nir_foreach_use(src, &instr->def) {
67 if (nir_src_is_if(src))
68 return false;
69 nir_instr *user_instr = nir_src_parent_instr(src);
70 if (user_instr->type != nir_instr_type_intrinsic)
71 return false;
72
73 const nir_intrinsic_instr *const user_intrinsic = nir_instr_as_intrinsic(user_instr);
74
75 if (user_intrinsic->intrinsic != nir_intrinsic_load_ubo_vec4)
76 return false;
77 }
78 return true;
79 }
80
81 bool r300_is_only_used_as_float(const nir_alu_instr *instr);
82
83 char *r300_finalize_nir(struct pipe_screen *pscreen, void *nir);
84
85 extern bool r300_transform_vs_trig_input(struct nir_shader *shader);
86
87 extern bool r300_transform_fs_trig_input(struct nir_shader *shader);
88
89 extern bool r300_nir_fuse_fround_d3d9(struct nir_shader *shader);
90
91 extern bool r300_nir_lower_bool_to_float(struct nir_shader *shader);
92
93 extern bool r300_nir_lower_bool_to_float_fs(struct nir_shader *shader);
94
95 extern bool r300_nir_prepare_presubtract(struct nir_shader *shader);
96
97 extern bool r300_nir_opt_algebraic_late(struct nir_shader *shader);
98
99 extern bool r300_nir_post_integer_lowering(struct nir_shader *shader);
100
101 extern bool r300_nir_lower_fcsel_r500(nir_shader *shader);
102
103 extern bool r300_nir_lower_fcsel_r300(nir_shader *shader);
104
105 extern bool r300_nir_lower_flrp(nir_shader *shader);
106
107 extern bool r300_nir_lower_comparison_fs(nir_shader *shader);
108
109 #endif /* R300_NIR_H */
110