1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2021 Valve Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef AC_NIR_H
27bf215546Sopenharmony_ci#define AC_NIR_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "nir.h"
30bf215546Sopenharmony_ci#include "ac_shader_args.h"
31bf215546Sopenharmony_ci#include "ac_shader_util.h"
32bf215546Sopenharmony_ci#include "amd_family.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#ifdef __cplusplus
35bf215546Sopenharmony_ciextern "C" {
36bf215546Sopenharmony_ci#endif
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cienum
39bf215546Sopenharmony_ci{
40bf215546Sopenharmony_ci   /* SPI_PS_INPUT_CNTL_i.OFFSET[0:4] */
41bf215546Sopenharmony_ci   AC_EXP_PARAM_OFFSET_0 = 0,
42bf215546Sopenharmony_ci   AC_EXP_PARAM_OFFSET_31 = 31,
43bf215546Sopenharmony_ci   /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL[0:1] */
44bf215546Sopenharmony_ci   AC_EXP_PARAM_DEFAULT_VAL_0000 = 64,
45bf215546Sopenharmony_ci   AC_EXP_PARAM_DEFAULT_VAL_0001,
46bf215546Sopenharmony_ci   AC_EXP_PARAM_DEFAULT_VAL_1110,
47bf215546Sopenharmony_ci   AC_EXP_PARAM_DEFAULT_VAL_1111,
48bf215546Sopenharmony_ci   AC_EXP_PARAM_UNDEFINED = 255, /* deprecated, use AC_EXP_PARAM_DEFAULT_VAL_0000 instead */
49bf215546Sopenharmony_ci};
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci/* Maps I/O semantics to the actual location used by the lowering pass. */
52bf215546Sopenharmony_citypedef unsigned (*ac_nir_map_io_driver_location)(unsigned semantic);
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci/* Forward declaration of nir_builder so we don't have to include nir_builder.h here */
55bf215546Sopenharmony_cistruct nir_builder;
56bf215546Sopenharmony_citypedef struct nir_builder nir_builder;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_cinir_ssa_def *
59bf215546Sopenharmony_ciac_nir_load_arg(nir_builder *b, const struct ac_shader_args *ac_args, struct ac_arg arg);
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cinir_ssa_def *
62bf215546Sopenharmony_ciac_nir_calc_io_offset(nir_builder *b,
63bf215546Sopenharmony_ci                      nir_intrinsic_instr *intrin,
64bf215546Sopenharmony_ci                      nir_ssa_def *base_stride,
65bf215546Sopenharmony_ci                      unsigned component_stride,
66bf215546Sopenharmony_ci                      ac_nir_map_io_driver_location map_io);
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_cibool ac_nir_optimize_outputs(nir_shader *nir, bool sprite_tex_disallowed,
69bf215546Sopenharmony_ci                             int8_t slot_remap[NUM_TOTAL_VARYING_SLOTS],
70bf215546Sopenharmony_ci                             uint8_t param_export_index[NUM_TOTAL_VARYING_SLOTS]);
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_civoid
73bf215546Sopenharmony_ciac_nir_lower_ls_outputs_to_mem(nir_shader *ls,
74bf215546Sopenharmony_ci                               ac_nir_map_io_driver_location map,
75bf215546Sopenharmony_ci                               bool tcs_in_out_eq,
76bf215546Sopenharmony_ci                               uint64_t tcs_temp_only_inputs);
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_civoid
79bf215546Sopenharmony_ciac_nir_lower_hs_inputs_to_mem(nir_shader *shader,
80bf215546Sopenharmony_ci                              ac_nir_map_io_driver_location map,
81bf215546Sopenharmony_ci                              bool tcs_in_out_eq);
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_civoid
84bf215546Sopenharmony_ciac_nir_lower_hs_outputs_to_mem(nir_shader *shader,
85bf215546Sopenharmony_ci                               ac_nir_map_io_driver_location map,
86bf215546Sopenharmony_ci                               enum amd_gfx_level gfx_level,
87bf215546Sopenharmony_ci                               bool tes_reads_tessfactors,
88bf215546Sopenharmony_ci                               uint64_t tes_inputs_read,
89bf215546Sopenharmony_ci                               uint64_t tes_patch_inputs_read,
90bf215546Sopenharmony_ci                               unsigned num_reserved_tcs_outputs,
91bf215546Sopenharmony_ci                               unsigned num_reserved_tcs_patch_outputs,
92bf215546Sopenharmony_ci                               unsigned wave_size,
93bf215546Sopenharmony_ci                               bool no_inputs_in_lds,
94bf215546Sopenharmony_ci                               bool pass_tessfactors_by_reg,
95bf215546Sopenharmony_ci                               bool emit_tess_factor_write);
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_civoid
98bf215546Sopenharmony_ciac_nir_lower_tes_inputs_to_mem(nir_shader *shader,
99bf215546Sopenharmony_ci                               ac_nir_map_io_driver_location map);
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_civoid
102bf215546Sopenharmony_ciac_nir_lower_es_outputs_to_mem(nir_shader *shader,
103bf215546Sopenharmony_ci                               ac_nir_map_io_driver_location map,
104bf215546Sopenharmony_ci                               enum amd_gfx_level gfx_level,
105bf215546Sopenharmony_ci                               unsigned esgs_itemsize);
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_civoid
108bf215546Sopenharmony_ciac_nir_lower_gs_inputs_to_mem(nir_shader *shader,
109bf215546Sopenharmony_ci                              ac_nir_map_io_driver_location map,
110bf215546Sopenharmony_ci                              enum amd_gfx_level gfx_level,
111bf215546Sopenharmony_ci                              bool triangle_strip_adjacency_fix);
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_cibool
114bf215546Sopenharmony_ciac_nir_lower_indirect_derefs(nir_shader *shader,
115bf215546Sopenharmony_ci                             enum amd_gfx_level gfx_level);
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_civoid
118bf215546Sopenharmony_ciac_nir_lower_ngg_nogs(nir_shader *shader,
119bf215546Sopenharmony_ci                      enum radeon_family family,
120bf215546Sopenharmony_ci                      unsigned max_num_es_vertices,
121bf215546Sopenharmony_ci                      unsigned num_vertices_per_primitive,
122bf215546Sopenharmony_ci                      unsigned max_workgroup_size,
123bf215546Sopenharmony_ci                      unsigned wave_size,
124bf215546Sopenharmony_ci                      bool can_cull,
125bf215546Sopenharmony_ci                      bool early_prim_export,
126bf215546Sopenharmony_ci                      bool passthrough,
127bf215546Sopenharmony_ci                      bool export_prim_id,
128bf215546Sopenharmony_ci                      bool provoking_vtx_last,
129bf215546Sopenharmony_ci                      bool use_edgeflags,
130bf215546Sopenharmony_ci                      bool has_prim_query,
131bf215546Sopenharmony_ci                      uint32_t instance_rate_inputs);
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_civoid
134bf215546Sopenharmony_ciac_nir_lower_ngg_gs(nir_shader *shader,
135bf215546Sopenharmony_ci                    unsigned wave_size,
136bf215546Sopenharmony_ci                    unsigned max_workgroup_size,
137bf215546Sopenharmony_ci                    unsigned esgs_ring_lds_bytes,
138bf215546Sopenharmony_ci                    unsigned gs_out_vtx_bytes,
139bf215546Sopenharmony_ci                    unsigned gs_total_out_vtx_bytes,
140bf215546Sopenharmony_ci                    bool provoking_vtx_last);
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_civoid
143bf215546Sopenharmony_ciac_nir_lower_ngg_ms(nir_shader *shader,
144bf215546Sopenharmony_ci                    bool *out_needs_scratch_ring,
145bf215546Sopenharmony_ci                    unsigned wave_size,
146bf215546Sopenharmony_ci                    bool multiview);
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_civoid
149bf215546Sopenharmony_ciac_nir_apply_first_task_to_task_shader(nir_shader *shader);
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_civoid
152bf215546Sopenharmony_ciac_nir_lower_task_outputs_to_mem(nir_shader *shader,
153bf215546Sopenharmony_ci                                 unsigned task_payload_entry_bytes,
154bf215546Sopenharmony_ci                                 unsigned task_num_entries);
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_civoid
157bf215546Sopenharmony_ciac_nir_lower_mesh_inputs_to_mem(nir_shader *shader,
158bf215546Sopenharmony_ci                                unsigned task_payload_entry_bytes,
159bf215546Sopenharmony_ci                                unsigned task_num_entries);
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_cinir_ssa_def *
162bf215546Sopenharmony_ciac_nir_cull_triangle(nir_builder *b,
163bf215546Sopenharmony_ci                     nir_ssa_def *initially_accepted,
164bf215546Sopenharmony_ci                     nir_ssa_def *pos[3][4]);
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_cibool
167bf215546Sopenharmony_ciac_nir_lower_global_access(nir_shader *shader);
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci#ifdef __cplusplus
170bf215546Sopenharmony_ci}
171bf215546Sopenharmony_ci#endif
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci#endif /* AC_NIR_H */
174