1 /* -*- mesa-c++ -*-
2 *
3 * Copyright (c) 2019 Collabora LTD
4 *
5 * Author: Gert Wollny <gert.wollny@collabora.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #ifndef SFN_NIR_H
28 #define SFN_NIR_H
29
30 #include "gallium/include/pipe/p_state.h"
31
32 #include "amd_family.h"
33 #include "nir.h"
34 #include "nir_builder.h"
35
36 #ifdef __cplusplus
37 #include "sfn_shader.h"
38
39 #include <vector>
40
41 namespace r600 {
42
43 class NirLowerInstruction {
44 public:
45 NirLowerInstruction();
46
47 bool run(nir_shader *shader);
48
49 private:
50 static bool filter_instr(const nir_instr *instr, const void *data);
51 static nir_def *lower_instr(nir_builder *b, nir_instr *instr, void *data);
52
set_builder(nir_builder * _b)53 void set_builder(nir_builder *_b) { b = _b; }
54
55 virtual bool filter(const nir_instr *instr) const = 0;
56 virtual nir_def *lower(nir_instr *instr) = 0;
57
58 protected:
59 nir_builder *b;
60 };
61
62 bool
63 r600_lower_scratch_addresses(nir_shader *shader);
64
65 bool
66 r600_lower_ubo_to_align16(nir_shader *shader);
67
68 bool
69 r600_nir_split_64bit_io(nir_shader *sh);
70
71 bool
72 r600_nir_64_to_vec2(nir_shader *sh);
73
74 bool
75 r600_merge_vec2_stores(nir_shader *shader);
76
77 bool
78 r600_split_64bit_uniforms_and_ubo(nir_shader *sh);
79 bool
80 r600_lower_64bit_to_vec2(nir_shader *sh);
81 bool
82 r600_split_64bit_alu_and_phi(nir_shader *sh);
83 bool
84 r600_lower_clipvertex_to_clipdist(nir_shader *sh);
85
86 class AssemblyFromShader {
87 public:
88 virtual ~AssemblyFromShader();
89 bool lower(const Shader& s);
90
91 private:
92 virtual bool do_lower(const Shader& s) = 0;
93 };
94
95 } // namespace r600
96
97 static inline nir_def *
r600_imm_ivec3(nir_builder * build,int x,int y,int z)98 r600_imm_ivec3(nir_builder *build, int x, int y, int z)
99 {
100 nir_const_value v[3] = {
101 nir_const_value_for_int(x, 32),
102 nir_const_value_for_int(y, 32),
103 nir_const_value_for_int(z, 32),
104 };
105
106 return nir_build_imm(build, 3, 32, v);
107 }
108
109 bool
110 r600_lower_tess_io(nir_shader *shader, enum mesa_prim prim_type);
111 bool
112 r600_append_tcs_TF_emission(nir_shader *shader, enum mesa_prim prim_type);
113
114 bool
115 r600_legalize_image_load_store(nir_shader *shader);
116
117 void
118 r600_finalize_and_optimize_shader(r600::Shader *shader);
119 r600::Shader *
120 r600_schedule_shader(r600::Shader *shader);
121
122 #else
123 #include "gallium/drivers/r600/r600_shader.h"
124 #endif
125
126 #ifdef __cplusplus
127 extern "C" {
128 #endif
129
130 bool
131 r600_vectorize_vs_inputs(nir_shader *shader);
132
133 bool
134 r600_lower_to_scalar_instr_filter(const nir_instr *instr, const void *);
135
136 void
137 r600_lower_and_optimize_nir(nir_shader *sh,
138 const union r600_shader_key *key,
139 enum amd_gfx_level gfx_level,
140 struct pipe_stream_output_info *so_info);
141
142 void
143 r600_finalize_nir_common(nir_shader *nir, enum amd_gfx_level gfx_level);
144
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif // SFN_NIR_H
150