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
;
37 struct radv_pipeline_layout
;
39 struct ac_llvm_context
;
42 struct ac_vs_variant_key
{
43 uint32_t instance_rate_inputs
;
46 uint32_t export_prim_id
:1;
49 struct ac_tes_variant_key
{
51 uint32_t export_prim_id
:1;
54 struct ac_tcs_variant_key
{
55 struct ac_vs_variant_key vs_key
;
56 unsigned primitive_mode
;
57 unsigned input_vertices
;
60 struct ac_fs_variant_key
{
64 uint32_t multisample
: 1;
67 struct ac_shader_variant_key
{
69 struct ac_vs_variant_key vs
;
70 struct ac_fs_variant_key fs
;
71 struct ac_tes_variant_key tes
;
72 struct ac_tcs_variant_key tcs
;
74 bool has_multiview_view_index
;
77 struct ac_nir_compiler_options
{
78 struct radv_pipeline_layout
*layout
;
79 struct ac_shader_variant_key key
;
82 bool clamp_shadow_reference
;
83 enum radeon_family family
;
84 enum chip_class chip_class
;
87 struct ac_userdata_info
{
91 uint32_t indirect_offset
;
95 AC_UD_SCRATCH_RING_OFFSETS
= 0,
96 AC_UD_PUSH_CONSTANTS
= 1,
97 AC_UD_INDIRECT_DESCRIPTOR_SETS
= 2,
99 AC_UD_SHADER_START
= 4,
100 AC_UD_VS_VERTEX_BUFFERS
= AC_UD_SHADER_START
,
101 AC_UD_VS_BASE_VERTEX_START_INSTANCE
,
102 AC_UD_VS_LS_TCS_IN_LAYOUT
,
104 AC_UD_PS_SAMPLE_POS_OFFSET
= AC_UD_SHADER_START
,
106 AC_UD_CS_GRID_SIZE
= AC_UD_SHADER_START
,
108 AC_UD_GS_VS_RING_STRIDE_ENTRIES
= AC_UD_VS_MAX_UD
,
110 AC_UD_TCS_OFFCHIP_LAYOUT
= AC_UD_VS_MAX_UD
,
112 AC_UD_TES_OFFCHIP_LAYOUT
= AC_UD_SHADER_START
,
114 AC_UD_MAX_UD
= AC_UD_TCS_MAX_UD
,
117 /* descriptor index into scratch ring offsets */
118 #define RING_SCRATCH 0
119 #define RING_ESGS_VS 1
120 #define RING_ESGS_GS 2
121 #define RING_GSVS_VS 3
122 #define RING_GSVS_GS 4
123 #define RING_HS_TESS_FACTOR 5
124 #define RING_HS_TESS_OFFCHIP 6
125 #define RING_PS_SAMPLE_POSITIONS 7
127 // Match MAX_SETS from radv_descriptor_set.h
128 #define AC_UD_MAX_SETS MAX_SETS
130 struct ac_userdata_locations
{
131 struct ac_userdata_info descriptor_sets
[AC_UD_MAX_SETS
];
132 struct ac_userdata_info shader_data
[AC_UD_MAX_UD
];
135 struct ac_vs_output_info
{
136 uint8_t vs_output_param_offset
[VARYING_SLOT_MAX
];
137 uint8_t clip_dist_mask
;
138 uint8_t cull_dist_mask
;
139 uint8_t param_exports
;
140 bool writes_pointsize
;
142 bool writes_viewport_index
;
144 uint32_t export_mask
;
145 unsigned pos_exports
;
148 struct ac_es_output_info
{
149 uint32_t esgs_itemsize
;
152 struct ac_shader_variant_info
{
153 struct ac_userdata_locations user_sgprs_locs
;
154 struct ac_shader_info info
;
155 unsigned num_user_sgprs
;
156 unsigned num_input_sgprs
;
157 unsigned num_input_vgprs
;
158 bool need_indirect_descriptor_sets
;
161 struct ac_vs_output_info outinfo
;
162 struct ac_es_output_info es_info
;
163 unsigned vgpr_comp_cnt
;
166 uint64_t outputs_written
;
171 uint32_t flat_shaded_mask
;
176 bool writes_sample_mask
;
177 bool early_fragment_test
;
183 unsigned block_size
[3];
186 unsigned vertices_in
;
187 unsigned vertices_out
;
188 unsigned output_prim
;
189 unsigned invocations
;
190 unsigned gsvs_vertex_size
;
191 unsigned max_gsvs_emit_size
;
192 unsigned es_type
; /* GFX9: VS or TES */
195 unsigned tcs_vertices_out
;
196 /* Which outputs are actually written */
197 uint64_t outputs_written
;
198 /* Which patch outputs are actually written */
199 uint32_t patch_outputs_written
;
203 struct ac_vs_output_info outinfo
;
204 struct ac_es_output_info es_info
;
206 unsigned primitive_mode
;
207 enum gl_tess_spacing spacing
;
214 void ac_compile_nir_shader(LLVMTargetMachineRef tm
,
215 struct ac_shader_binary
*binary
,
216 struct ac_shader_config
*config
,
217 struct ac_shader_variant_info
*shader_info
,
218 struct nir_shader
*const *nir
,
220 const struct ac_nir_compiler_options
*options
,
223 void ac_create_gs_copy_shader(LLVMTargetMachineRef tm
,
224 struct nir_shader
*geom_shader
,
225 struct ac_shader_binary
*binary
,
226 struct ac_shader_config
*config
,
227 struct ac_shader_variant_info
*shader_info
,
228 const struct ac_nir_compiler_options
*options
,
231 struct nir_to_llvm_context
;
232 void ac_nir_translate(struct ac_llvm_context
*ac
, struct ac_shader_abi
*abi
,
233 struct nir_shader
*nir
, struct nir_to_llvm_context
*nctx
);
235 #endif /* AC_NIR_TO_LLVM_H */