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"
33 #include "shader_enums.h"
34 struct ac_shader_binary
;
35 struct ac_shader_config
;
37 struct radv_pipeline_layout
;
40 struct ac_vs_variant_key
{
41 uint32_t instance_rate_inputs
;
46 struct ac_tes_variant_key
{
50 struct ac_tcs_variant_key
{
51 unsigned primitive_mode
;
52 unsigned input_vertices
;
55 struct ac_fs_variant_key
{
60 union ac_shader_variant_key
{
61 struct ac_vs_variant_key vs
;
62 struct ac_fs_variant_key fs
;
63 struct ac_tes_variant_key tes
;
64 struct ac_tcs_variant_key tcs
;
67 struct ac_nir_compiler_options
{
68 struct radv_pipeline_layout
*layout
;
69 union ac_shader_variant_key key
;
72 enum radeon_family family
;
73 enum chip_class chip_class
;
76 struct ac_userdata_info
{
80 uint32_t indirect_offset
;
84 AC_UD_SCRATCH_RING_OFFSETS
= 0,
85 AC_UD_PUSH_CONSTANTS
= 1,
86 AC_UD_SHADER_START
= 2,
87 AC_UD_VS_VERTEX_BUFFERS
= AC_UD_SHADER_START
,
88 AC_UD_VS_BASE_VERTEX_START_INSTANCE
,
89 AC_UD_VS_LS_TCS_IN_LAYOUT
,
91 AC_UD_PS_SAMPLE_POS
= AC_UD_SHADER_START
,
93 AC_UD_CS_GRID_SIZE
= AC_UD_SHADER_START
,
95 AC_UD_GS_VS_RING_STRIDE_ENTRIES
= AC_UD_SHADER_START
,
97 AC_UD_TCS_OFFCHIP_LAYOUT
= AC_UD_SHADER_START
,
99 AC_UD_TES_OFFCHIP_LAYOUT
= AC_UD_SHADER_START
,
101 AC_UD_MAX_UD
= AC_UD_VS_MAX_UD
,
104 /* descriptor index into scratch ring offsets */
105 #define RING_SCRATCH 0
106 #define RING_ESGS_VS 1
107 #define RING_ESGS_GS 2
108 #define RING_GSVS_VS 3
109 #define RING_GSVS_GS 4
111 // Match MAX_SETS from radv_descriptor_set.h
112 #define AC_UD_MAX_SETS MAX_SETS
114 struct ac_userdata_locations
{
115 struct ac_userdata_info descriptor_sets
[AC_UD_MAX_SETS
];
116 struct ac_userdata_info shader_data
[AC_UD_MAX_UD
];
119 struct ac_vs_output_info
{
120 uint8_t clip_dist_mask
;
121 uint8_t cull_dist_mask
;
122 bool writes_pointsize
;
124 bool writes_viewport_index
;
125 uint32_t prim_id_output
;
126 uint32_t layer_output
;
127 uint32_t export_mask
;
128 unsigned param_exports
;
129 unsigned pos_exports
;
132 struct ac_es_output_info
{
133 uint32_t esgs_itemsize
;
136 struct ac_shader_variant_info
{
137 struct ac_userdata_locations user_sgprs_locs
;
138 unsigned num_user_sgprs
;
139 unsigned num_input_sgprs
;
140 unsigned num_input_vgprs
;
144 struct ac_vs_output_info outinfo
;
145 struct ac_es_output_info es_info
;
146 unsigned vgpr_comp_cnt
;
149 uint64_t outputs_written
;
154 unsigned output_mask
;
155 uint32_t flat_shaded_mask
;
160 bool writes_sample_mask
;
161 bool early_fragment_test
;
163 bool force_persample
;
168 unsigned block_size
[3];
171 unsigned vertices_in
;
172 unsigned vertices_out
;
173 unsigned output_prim
;
174 unsigned invocations
;
175 unsigned gsvs_vertex_size
;
176 unsigned max_gsvs_emit_size
;
180 unsigned tcs_vertices_out
;
181 /* Which outputs are actually written */
182 uint64_t outputs_written
;
183 /* Which patch outputs are actually written */
184 uint32_t patch_outputs_written
;
188 struct ac_vs_output_info outinfo
;
189 struct ac_es_output_info es_info
;
191 unsigned primitive_mode
;
192 enum gl_tess_spacing spacing
;
200 void ac_compile_nir_shader(LLVMTargetMachineRef tm
,
201 struct ac_shader_binary
*binary
,
202 struct ac_shader_config
*config
,
203 struct ac_shader_variant_info
*shader_info
,
204 struct nir_shader
*nir
,
205 const struct ac_nir_compiler_options
*options
,
208 void ac_create_gs_copy_shader(LLVMTargetMachineRef tm
,
209 struct nir_shader
*geom_shader
,
210 struct ac_shader_binary
*binary
,
211 struct ac_shader_config
*config
,
212 struct ac_shader_variant_info
*shader_info
,
213 const struct ac_nir_compiler_options
*options
,
216 #endif /* AC_NIR_TO_LLVM_H */