2 * Copyright © 2016 Bas Nieuwenhuizen
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
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
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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #ifndef AC_NIR_TO_LLVM_H
25 #define AC_NIR_TO_LLVM_H
28 #include "llvm-c/Core.h"
29 #include "llvm-c/TargetMachine.h"
30 #include "amd_family.h"
31 #include "../vulkan/radv_descriptor_set.h"
32 #include "ac_shader_info.h"
33 #include "compiler/shader_enums.h"
34 struct ac_shader_binary
;
35 struct ac_shader_config
;
38 struct radv_pipeline_layout
;
40 struct ac_llvm_context
;
43 struct ac_vs_variant_key
{
44 uint32_t instance_rate_inputs
;
47 uint32_t export_prim_id
:1;
50 struct ac_tes_variant_key
{
52 uint32_t export_prim_id
:1;
55 struct ac_tcs_variant_key
{
56 struct ac_vs_variant_key vs_key
;
57 unsigned primitive_mode
;
58 unsigned input_vertices
;
59 uint32_t tes_reads_tess_factors
:1;
62 struct ac_fs_variant_key
{
64 uint8_t log2_ps_iter_samples
;
65 uint8_t log2_num_samples
;
68 uint32_t multisample
: 1;
71 struct ac_shader_variant_key
{
73 struct ac_vs_variant_key vs
;
74 struct ac_fs_variant_key fs
;
75 struct ac_tes_variant_key tes
;
76 struct ac_tcs_variant_key tcs
;
78 bool has_multiview_view_index
;
81 struct ac_nir_compiler_options
{
82 struct radv_pipeline_layout
*layout
;
83 struct ac_shader_variant_key key
;
86 bool clamp_shadow_reference
;
88 enum radeon_family family
;
89 enum chip_class chip_class
;
92 struct ac_userdata_info
{
96 uint32_t indirect_offset
;
100 AC_UD_SCRATCH_RING_OFFSETS
= 0,
101 AC_UD_PUSH_CONSTANTS
= 1,
102 AC_UD_INDIRECT_DESCRIPTOR_SETS
= 2,
103 AC_UD_VIEW_INDEX
= 3,
104 AC_UD_SHADER_START
= 4,
105 AC_UD_VS_VERTEX_BUFFERS
= AC_UD_SHADER_START
,
106 AC_UD_VS_BASE_VERTEX_START_INSTANCE
,
107 AC_UD_VS_LS_TCS_IN_LAYOUT
,
109 AC_UD_PS_SAMPLE_POS_OFFSET
= AC_UD_SHADER_START
,
111 AC_UD_CS_GRID_SIZE
= AC_UD_SHADER_START
,
113 AC_UD_GS_VS_RING_STRIDE_ENTRIES
= AC_UD_VS_MAX_UD
,
115 AC_UD_TCS_OFFCHIP_LAYOUT
= AC_UD_VS_MAX_UD
,
117 AC_UD_TES_OFFCHIP_LAYOUT
= AC_UD_SHADER_START
,
119 AC_UD_MAX_UD
= AC_UD_TCS_MAX_UD
,
122 /* Interpolation locations */
123 #define INTERP_CENTER 0
124 #define INTERP_CENTROID 1
125 #define INTERP_SAMPLE 2
127 /* descriptor index into scratch ring offsets */
128 #define RING_SCRATCH 0
129 #define RING_ESGS_VS 1
130 #define RING_ESGS_GS 2
131 #define RING_GSVS_VS 3
132 #define RING_GSVS_GS 4
133 #define RING_HS_TESS_FACTOR 5
134 #define RING_HS_TESS_OFFCHIP 6
135 #define RING_PS_SAMPLE_POSITIONS 7
137 // Match MAX_SETS from radv_descriptor_set.h
138 #define AC_UD_MAX_SETS MAX_SETS
140 struct ac_userdata_locations
{
141 struct ac_userdata_info descriptor_sets
[AC_UD_MAX_SETS
];
142 struct ac_userdata_info shader_data
[AC_UD_MAX_UD
];
145 struct ac_vs_output_info
{
146 uint8_t vs_output_param_offset
[VARYING_SLOT_MAX
];
147 uint8_t clip_dist_mask
;
148 uint8_t cull_dist_mask
;
149 uint8_t param_exports
;
150 bool writes_pointsize
;
152 bool writes_viewport_index
;
154 unsigned pos_exports
;
157 struct ac_es_output_info
{
158 uint32_t esgs_itemsize
;
161 struct ac_shader_variant_info
{
162 struct ac_userdata_locations user_sgprs_locs
;
163 struct ac_shader_info info
;
164 unsigned num_user_sgprs
;
165 unsigned num_input_sgprs
;
166 unsigned num_input_vgprs
;
167 unsigned private_mem_vgprs
;
168 bool need_indirect_descriptor_sets
;
171 struct ac_vs_output_info outinfo
;
172 struct ac_es_output_info es_info
;
173 unsigned vgpr_comp_cnt
;
176 uint64_t outputs_written
;
181 uint32_t flat_shaded_mask
;
183 bool early_fragment_test
;
186 unsigned block_size
[3];
189 unsigned vertices_in
;
190 unsigned vertices_out
;
191 unsigned output_prim
;
192 unsigned invocations
;
193 unsigned gsvs_vertex_size
;
194 unsigned max_gsvs_emit_size
;
195 unsigned es_type
; /* GFX9: VS or TES */
198 unsigned tcs_vertices_out
;
199 /* Which outputs are actually written */
200 uint64_t outputs_written
;
201 /* Which patch outputs are actually written */
202 uint32_t patch_outputs_written
;
206 struct ac_vs_output_info outinfo
;
207 struct ac_es_output_info es_info
;
209 unsigned primitive_mode
;
210 enum gl_tess_spacing spacing
;
217 void ac_compile_nir_shader(LLVMTargetMachineRef tm
,
218 struct ac_shader_binary
*binary
,
219 struct ac_shader_config
*config
,
220 struct ac_shader_variant_info
*shader_info
,
221 struct nir_shader
*const *nir
,
223 const struct ac_nir_compiler_options
*options
,
226 void ac_create_gs_copy_shader(LLVMTargetMachineRef tm
,
227 struct nir_shader
*geom_shader
,
228 struct ac_shader_binary
*binary
,
229 struct ac_shader_config
*config
,
230 struct ac_shader_variant_info
*shader_info
,
231 const struct ac_nir_compiler_options
*options
,
234 void ac_lower_indirect_derefs(struct nir_shader
*nir
, enum chip_class
);
236 void ac_nir_translate(struct ac_llvm_context
*ac
, struct ac_shader_abi
*abi
,
237 struct nir_shader
*nir
);
240 ac_handle_shader_output_decl(struct ac_llvm_context
*ctx
,
241 struct ac_shader_abi
*abi
,
242 struct nir_shader
*nir
,
243 struct nir_variable
*variable
,
244 gl_shader_stage stage
);
246 bool ac_lower_subgroups(struct nir_shader
*shader
);
248 #endif /* AC_NIR_TO_LLVM_H */