xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r600/sfn/sfn_nir.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /* -*- mesa-c++  -*-
2  * Copyright 2019 Collabora LTD
3  * Author: Gert Wollny <[email protected]>
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #ifndef SFN_NIR_H
8 #define SFN_NIR_H
9 
10 #include "gallium/include/pipe/p_state.h"
11 
12 #include "amd_family.h"
13 #include "nir.h"
14 #include "nir_builder.h"
15 
16 #ifdef __cplusplus
17 #include "sfn_shader.h"
18 
19 #include <vector>
20 
21 namespace r600 {
22 
23 class NirLowerInstruction {
24 public:
25    NirLowerInstruction();
26 
27    bool run(nir_shader *shader);
28 
29 private:
30    static bool filter_instr(const nir_instr *instr, const void *data);
31    static nir_def *lower_instr(nir_builder *b, nir_instr *instr, void *data);
32 
set_builder(nir_builder * _b)33    void set_builder(nir_builder *_b) { b = _b; }
34 
35    virtual bool filter(const nir_instr *instr) const = 0;
36    virtual nir_def *lower(nir_instr *instr) = 0;
37 
38 protected:
39    nir_builder *b;
40 };
41 
42 bool
43 r600_lower_scratch_addresses(nir_shader *shader);
44 
45 bool
46 r600_lower_ubo_to_align16(nir_shader *shader);
47 
48 bool
49 r600_nir_split_64bit_io(nir_shader *sh);
50 
51 bool
52 r600_nir_64_to_vec2(nir_shader *sh);
53 
54 bool
55 r600_merge_vec2_stores(nir_shader *shader);
56 
57 bool
58 r600_split_64bit_uniforms_and_ubo(nir_shader *sh);
59 bool
60 r600_lower_64bit_to_vec2(nir_shader *sh);
61 bool
62 r600_split_64bit_alu_and_phi(nir_shader *sh);
63 bool
64 r600_lower_clipvertex_to_clipdist(nir_shader *sh);
65 
66 class AssemblyFromShader {
67 public:
68    virtual ~AssemblyFromShader();
69    bool lower(const Shader& s);
70 
71 private:
72    virtual bool do_lower(const Shader& s) = 0;
73 };
74 
75 } // namespace r600
76 
77 static inline nir_def *
r600_imm_ivec3(nir_builder * build,int x,int y,int z)78 r600_imm_ivec3(nir_builder *build, int x, int y, int z)
79 {
80    nir_const_value v[3] = {
81       nir_const_value_for_int(x, 32),
82       nir_const_value_for_int(y, 32),
83       nir_const_value_for_int(z, 32),
84    };
85 
86    return nir_build_imm(build, 3, 32, v);
87 }
88 
89 bool
90 r600_lower_tess_io(nir_shader *shader, enum mesa_prim prim_type);
91 bool
92 r600_append_tcs_TF_emission(nir_shader *shader, enum mesa_prim prim_type);
93 
94 bool
95 r600_legalize_image_load_store(nir_shader *shader);
96 
97 void
98 r600_finalize_and_optimize_shader(r600::Shader *shader);
99 r600::Shader *
100 r600_schedule_shader(r600::Shader *shader);
101 
102 #else
103 #include "gallium/drivers/r600/r600_shader.h"
104 #endif
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109 
110 bool
111 r600_vectorize_vs_inputs(nir_shader *shader);
112 
113 bool
114 r600_lower_to_scalar_instr_filter(const nir_instr *instr, const void *);
115 
116 void
117 r600_lower_and_optimize_nir(nir_shader *sh,
118                             const union r600_shader_key *key,
119                             enum amd_gfx_level gfx_level,
120                             struct pipe_stream_output_info *so_info);
121 
122 void
123 r600_finalize_nir_common(nir_shader *nir, enum amd_gfx_level gfx_level);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif // SFN_NIR_H
130