3d0b456f9f563da87af623dec695552ba1d3090d
[mesa.git] / src / amd / common / ac_nir_to_llvm.h
1 /*
2 * Copyright © 2016 Bas Nieuwenhuizen
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef AC_NIR_TO_LLVM_H
25 #define AC_NIR_TO_LLVM_H
26
27 #include <stdbool.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
33 #include "shader_enums.h"
34 struct ac_shader_binary;
35 struct ac_shader_config;
36 struct nir_shader;
37 struct radv_pipeline_layout;
38
39
40 struct ac_vs_variant_key {
41 uint32_t instance_rate_inputs;
42 uint32_t as_es:1;
43 uint32_t as_ls:1;
44 };
45
46 struct ac_tes_variant_key {
47 uint32_t as_es:1;
48 };
49
50 struct ac_tcs_variant_key {
51 unsigned primitive_mode;
52 unsigned input_vertices;
53 };
54
55 struct ac_fs_variant_key {
56 uint32_t col_format;
57 uint32_t is_int8;
58 };
59
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;
65 };
66
67 struct ac_nir_compiler_options {
68 struct radv_pipeline_layout *layout;
69 union ac_shader_variant_key key;
70 bool unsafe_math;
71 bool supports_spill;
72 enum radeon_family family;
73 enum chip_class chip_class;
74 };
75
76 struct ac_userdata_info {
77 int8_t sgpr_idx;
78 uint8_t num_sgprs;
79 bool indirect;
80 uint32_t indirect_offset;
81 };
82
83 enum ac_ud_index {
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,
90 AC_UD_VS_MAX_UD,
91 AC_UD_PS_SAMPLE_POS_OFFSET = AC_UD_SHADER_START,
92 AC_UD_PS_MAX_UD,
93 AC_UD_CS_GRID_SIZE = AC_UD_SHADER_START,
94 AC_UD_CS_MAX_UD,
95 AC_UD_GS_VS_RING_STRIDE_ENTRIES = AC_UD_SHADER_START,
96 AC_UD_GS_MAX_UD,
97 AC_UD_TCS_OFFCHIP_LAYOUT = AC_UD_SHADER_START,
98 AC_UD_TCS_MAX_UD,
99 AC_UD_TES_OFFCHIP_LAYOUT = AC_UD_SHADER_START,
100 AC_UD_TES_MAX_UD,
101 AC_UD_MAX_UD = AC_UD_VS_MAX_UD,
102 };
103
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
110 #define RING_HS_TESS_FACTOR 5
111 #define RING_HS_TESS_OFFCHIP 6
112 #define RING_PS_SAMPLE_POSITIONS 7
113
114 // Match MAX_SETS from radv_descriptor_set.h
115 #define AC_UD_MAX_SETS MAX_SETS
116
117 struct ac_userdata_locations {
118 struct ac_userdata_info descriptor_sets[AC_UD_MAX_SETS];
119 struct ac_userdata_info shader_data[AC_UD_MAX_UD];
120 };
121
122 struct ac_vs_output_info {
123 uint8_t clip_dist_mask;
124 uint8_t cull_dist_mask;
125 bool writes_pointsize;
126 bool writes_layer;
127 bool writes_viewport_index;
128 uint32_t prim_id_output;
129 uint32_t layer_output;
130 uint32_t export_mask;
131 unsigned param_exports;
132 unsigned pos_exports;
133 };
134
135 struct ac_es_output_info {
136 uint32_t esgs_itemsize;
137 };
138
139 struct ac_shader_variant_info {
140 struct ac_userdata_locations user_sgprs_locs;
141 unsigned num_user_sgprs;
142 unsigned num_input_sgprs;
143 unsigned num_input_vgprs;
144
145 union {
146 struct {
147 struct ac_vs_output_info outinfo;
148 struct ac_es_output_info es_info;
149 unsigned vgpr_comp_cnt;
150 bool as_es;
151 bool as_ls;
152 uint64_t outputs_written;
153 } vs;
154 struct {
155 unsigned num_interp;
156 uint32_t input_mask;
157 unsigned output_mask;
158 uint32_t flat_shaded_mask;
159 bool has_pcoord;
160 bool can_discard;
161 bool writes_z;
162 bool writes_stencil;
163 bool writes_sample_mask;
164 bool early_fragment_test;
165 bool writes_memory;
166 bool force_persample;
167 bool prim_id_input;
168 bool layer_input;
169 bool uses_sample_positions;
170 } fs;
171 struct {
172 unsigned block_size[3];
173 } cs;
174 struct {
175 unsigned vertices_in;
176 unsigned vertices_out;
177 unsigned output_prim;
178 unsigned invocations;
179 unsigned gsvs_vertex_size;
180 unsigned max_gsvs_emit_size;
181 } gs;
182 struct {
183 bool uses_prim_id;
184 unsigned tcs_vertices_out;
185 /* Which outputs are actually written */
186 uint64_t outputs_written;
187 /* Which patch outputs are actually written */
188 uint32_t patch_outputs_written;
189
190 } tcs;
191 struct {
192 struct ac_vs_output_info outinfo;
193 struct ac_es_output_info es_info;
194 bool as_es;
195 unsigned primitive_mode;
196 enum gl_tess_spacing spacing;
197 bool ccw;
198 bool point_mode;
199 bool uses_prim_id;
200 } tes;
201 };
202 };
203
204 void ac_compile_nir_shader(LLVMTargetMachineRef tm,
205 struct ac_shader_binary *binary,
206 struct ac_shader_config *config,
207 struct ac_shader_variant_info *shader_info,
208 struct nir_shader *nir,
209 const struct ac_nir_compiler_options *options,
210 bool dump_shader);
211
212 void ac_create_gs_copy_shader(LLVMTargetMachineRef tm,
213 struct nir_shader *geom_shader,
214 struct ac_shader_binary *binary,
215 struct ac_shader_config *config,
216 struct ac_shader_variant_info *shader_info,
217 const struct ac_nir_compiler_options *options,
218 bool dump_shader);
219
220 #endif /* AC_NIR_TO_LLVM_H */