radv/ac: eliminate unused vertex shader outputs. (v2)
[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 vs_output_param_offset[VARYING_SLOT_MAX];
125 uint8_t clip_dist_mask;
126 uint8_t cull_dist_mask;
127 uint8_t param_exports;
128 bool writes_pointsize;
129 bool writes_layer;
130 bool writes_viewport_index;
131 uint32_t export_mask;
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 struct ac_shader_info info;
142 unsigned num_user_sgprs;
143 unsigned num_input_sgprs;
144 unsigned num_input_vgprs;
145 bool need_indirect_descriptor_sets;
146 union {
147 struct {
148 struct ac_vs_output_info outinfo;
149 struct ac_es_output_info es_info;
150 unsigned vgpr_comp_cnt;
151 bool as_es;
152 bool as_ls;
153 uint64_t outputs_written;
154 } vs;
155 struct {
156 unsigned num_interp;
157 uint32_t input_mask;
158 unsigned output_mask;
159 uint32_t flat_shaded_mask;
160 bool has_pcoord;
161 bool can_discard;
162 bool writes_z;
163 bool writes_stencil;
164 bool writes_sample_mask;
165 bool early_fragment_test;
166 bool writes_memory;
167 bool force_persample;
168 bool prim_id_input;
169 bool layer_input;
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 */