radv/ac: add support for indirect access of descriptor sets.
[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 #include "ac_shader_info.h"
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_INDIRECT_DESCRIPTOR_SETS = 2,
87 AC_UD_SHADER_START = 3,
88 AC_UD_VS_VERTEX_BUFFERS = AC_UD_SHADER_START,
89 AC_UD_VS_BASE_VERTEX_START_INSTANCE,
90 AC_UD_VS_LS_TCS_IN_LAYOUT,
91 AC_UD_VS_MAX_UD,
92 AC_UD_PS_SAMPLE_POS_OFFSET = AC_UD_SHADER_START,
93 AC_UD_PS_MAX_UD,
94 AC_UD_CS_GRID_SIZE = AC_UD_SHADER_START,
95 AC_UD_CS_MAX_UD,
96 AC_UD_GS_VS_RING_STRIDE_ENTRIES = AC_UD_SHADER_START,
97 AC_UD_GS_MAX_UD,
98 AC_UD_TCS_OFFCHIP_LAYOUT = AC_UD_SHADER_START,
99 AC_UD_TCS_MAX_UD,
100 AC_UD_TES_OFFCHIP_LAYOUT = AC_UD_SHADER_START,
101 AC_UD_TES_MAX_UD,
102 AC_UD_MAX_UD = AC_UD_VS_MAX_UD,
103 };
104
105 /* descriptor index into scratch ring offsets */
106 #define RING_SCRATCH 0
107 #define RING_ESGS_VS 1
108 #define RING_ESGS_GS 2
109 #define RING_GSVS_VS 3
110 #define RING_GSVS_GS 4
111 #define RING_HS_TESS_FACTOR 5
112 #define RING_HS_TESS_OFFCHIP 6
113 #define RING_PS_SAMPLE_POSITIONS 7
114
115 // Match MAX_SETS from radv_descriptor_set.h
116 #define AC_UD_MAX_SETS MAX_SETS
117
118 struct ac_userdata_locations {
119 struct ac_userdata_info descriptor_sets[AC_UD_MAX_SETS];
120 struct ac_userdata_info shader_data[AC_UD_MAX_UD];
121 };
122
123 struct ac_vs_output_info {
124 uint8_t clip_dist_mask;
125 uint8_t cull_dist_mask;
126 bool writes_pointsize;
127 bool writes_layer;
128 bool writes_viewport_index;
129 uint32_t prim_id_output;
130 uint32_t layer_output;
131 uint32_t export_mask;
132 unsigned param_exports;
133 unsigned pos_exports;
134 };
135
136 struct ac_es_output_info {
137 uint32_t esgs_itemsize;
138 };
139
140 struct ac_shader_variant_info {
141 struct ac_userdata_locations user_sgprs_locs;
142 struct ac_shader_info info;
143 unsigned num_user_sgprs;
144 unsigned num_input_sgprs;
145 unsigned num_input_vgprs;
146 bool need_indirect_descriptor_sets;
147 union {
148 struct {
149 struct ac_vs_output_info outinfo;
150 struct ac_es_output_info es_info;
151 unsigned vgpr_comp_cnt;
152 bool as_es;
153 bool as_ls;
154 uint64_t outputs_written;
155 } vs;
156 struct {
157 unsigned num_interp;
158 uint32_t input_mask;
159 unsigned output_mask;
160 uint32_t flat_shaded_mask;
161 bool has_pcoord;
162 bool can_discard;
163 bool writes_z;
164 bool writes_stencil;
165 bool writes_sample_mask;
166 bool early_fragment_test;
167 bool writes_memory;
168 bool force_persample;
169 bool prim_id_input;
170 bool layer_input;
171 } fs;
172 struct {
173 unsigned block_size[3];
174 } cs;
175 struct {
176 unsigned vertices_in;
177 unsigned vertices_out;
178 unsigned output_prim;
179 unsigned invocations;
180 unsigned gsvs_vertex_size;
181 unsigned max_gsvs_emit_size;
182 } gs;
183 struct {
184 bool uses_prim_id;
185 unsigned tcs_vertices_out;
186 /* Which outputs are actually written */
187 uint64_t outputs_written;
188 /* Which patch outputs are actually written */
189 uint32_t patch_outputs_written;
190
191 } tcs;
192 struct {
193 struct ac_vs_output_info outinfo;
194 struct ac_es_output_info es_info;
195 bool as_es;
196 unsigned primitive_mode;
197 enum gl_tess_spacing spacing;
198 bool ccw;
199 bool point_mode;
200 bool uses_prim_id;
201 } tes;
202 };
203 };
204
205 void ac_compile_nir_shader(LLVMTargetMachineRef tm,
206 struct ac_shader_binary *binary,
207 struct ac_shader_config *config,
208 struct ac_shader_variant_info *shader_info,
209 struct nir_shader *nir,
210 const struct ac_nir_compiler_options *options,
211 bool dump_shader);
212
213 void ac_create_gs_copy_shader(LLVMTargetMachineRef tm,
214 struct nir_shader *geom_shader,
215 struct ac_shader_binary *binary,
216 struct ac_shader_config *config,
217 struct ac_shader_variant_info *shader_info,
218 const struct ac_nir_compiler_options *options,
219 bool dump_shader);
220
221 #endif /* AC_NIR_TO_LLVM_H */