nir: Collect if shader uses cross-invocation or indirect I/O.
[mesa.git] / src / compiler / shader_info.h
1 /*
2 * Copyright © 2016 Intel Corporation
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
25 #ifndef SHADER_INFO_H
26 #define SHADER_INFO_H
27
28 #include "shader_enums.h"
29 #include <stdint.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 struct spirv_supported_capabilities {
36 bool address;
37 bool atomic_storage;
38 bool demote_to_helper_invocation;
39 bool derivative_group;
40 bool descriptor_array_dynamic_indexing;
41 bool descriptor_array_non_uniform_indexing;
42 bool descriptor_indexing;
43 bool device_group;
44 bool draw_parameters;
45 bool float64;
46 bool fragment_shader_sample_interlock;
47 bool fragment_shader_pixel_interlock;
48 bool geometry_streams;
49 bool image_ms_array;
50 bool image_read_without_format;
51 bool image_write_without_format;
52 bool int8;
53 bool int16;
54 bool int64;
55 bool int64_atomics;
56 bool integer_functions2;
57 bool kernel;
58 bool min_lod;
59 bool multiview;
60 bool physical_storage_buffer_address;
61 bool post_depth_coverage;
62 bool runtime_descriptor_array;
63 bool float_controls;
64 bool shader_clock;
65 bool shader_viewport_index_layer;
66 bool stencil_export;
67 bool storage_8bit;
68 bool storage_16bit;
69 bool storage_image_ms;
70 bool subgroup_arithmetic;
71 bool subgroup_ballot;
72 bool subgroup_basic;
73 bool subgroup_quad;
74 bool subgroup_shuffle;
75 bool subgroup_vote;
76 bool tessellation;
77 bool transform_feedback;
78 bool variable_pointers;
79 bool vk_memory_model;
80 bool vk_memory_model_device_scope;
81 bool float16;
82 bool amd_fragment_mask;
83 bool amd_gcn_shader;
84 bool amd_shader_ballot;
85 bool amd_trinary_minmax;
86 bool amd_image_read_write_lod;
87 bool amd_shader_explicit_vertex_parameter;
88 };
89
90 typedef struct shader_info {
91 const char *name;
92
93 /* Descriptive name provided by the client; may be NULL */
94 const char *label;
95
96 /** The shader stage, such as MESA_SHADER_VERTEX. */
97 gl_shader_stage stage:8;
98
99 /** The shader stage in a non SSO linked program that follows this stage,
100 * such as MESA_SHADER_FRAGMENT.
101 */
102 gl_shader_stage next_stage:8;
103
104 /* Number of textures used by this shader */
105 uint8_t num_textures;
106 /* Number of uniform buffers used by this shader */
107 uint8_t num_ubos;
108 /* Number of atomic buffers used by this shader */
109 uint8_t num_abos;
110 /* Number of shader storage buffers (max .driver_location + 1) used by this
111 * shader. In the case of nir_lower_atomics_to_ssbo being used, this will
112 * be the number of actual SSBOs in gl_program->info, and the lowered SSBOs
113 * and atomic counters in nir_shader->info.
114 */
115 uint8_t num_ssbos;
116 /* Number of images used by this shader */
117 uint8_t num_images;
118 /* Index of the last MSAA image. */
119 int8_t last_msaa_image;
120
121 /* Which inputs are actually read */
122 uint64_t inputs_read;
123 /* Which outputs are actually written */
124 uint64_t outputs_written;
125 /* Which outputs are actually read */
126 uint64_t outputs_read;
127 /* Which system values are actually read */
128 uint64_t system_values_read;
129
130 /* Which patch inputs are actually read */
131 uint32_t patch_inputs_read;
132 /* Which patch outputs are actually written */
133 uint32_t patch_outputs_written;
134 /* Which patch outputs are read */
135 uint32_t patch_outputs_read;
136
137 /* Which inputs are read indirectly (subset of inputs_read) */
138 uint64_t inputs_read_indirectly;
139 /* Which outputs are read or written indirectly */
140 uint64_t outputs_accessed_indirectly;
141 /* Which patch inputs are read indirectly (subset of patch_inputs_read) */
142 uint64_t patch_inputs_read_indirectly;
143 /* Which patch outputs are read or written indirectly */
144 uint64_t patch_outputs_accessed_indirectly;
145
146 /** Bitfield of which textures are used */
147 uint32_t textures_used;
148
149 /** Bitfield of which textures are used by texelFetch() */
150 uint32_t textures_used_by_txf;
151
152 /** Bitfield of which images are used */
153 uint32_t images_used;
154
155 /* SPV_KHR_float_controls: execution mode for floating point ops */
156 uint16_t float_controls_execution_mode;
157
158 /* The size of the gl_ClipDistance[] array, if declared. */
159 uint8_t clip_distance_array_size:4;
160
161 /* The size of the gl_CullDistance[] array, if declared. */
162 uint8_t cull_distance_array_size:4;
163
164 /* Whether or not this shader ever uses textureGather() */
165 bool uses_texture_gather:1;
166
167 /**
168 * True if this shader uses the fddx/fddy opcodes.
169 *
170 * Note that this does not include the "fine" and "coarse" variants.
171 */
172 bool uses_fddx_fddy:1;
173
174 /**
175 * True if this shader uses 64-bit ALU operations
176 */
177 bool uses_64bit:1;
178
179 /* Whether the first UBO is the default uniform buffer, i.e. uniforms. */
180 bool first_ubo_is_default_ubo:1;
181
182 /* Whether or not separate shader objects were used */
183 bool separate_shader:1;
184
185 /** Was this shader linked with any transform feedback varyings? */
186 bool has_transform_feedback_varyings:1;
187
188 /* Whether flrp has been lowered. */
189 bool flrp_lowered:1;
190
191 /* Whether the shader writes memory, including transform feedback. */
192 bool writes_memory:1;
193
194 union {
195 struct {
196 /* Which inputs are doubles */
197 uint64_t double_inputs;
198
199 /* For AMD-specific driver-internal shaders. It replaces vertex
200 * buffer loads with code generating VS inputs from scalar registers.
201 *
202 * Valid values: SI_VS_BLIT_SGPRS_POS_*
203 */
204 uint8_t blit_sgprs_amd:4;
205
206 /* True if the shader writes position in window space coordinates pre-transform */
207 bool window_space_position:1;
208 } vs;
209
210 struct {
211 /** The output primitive type (GL enum value) */
212 uint16_t output_primitive;
213
214 /** The input primitive type (GL enum value) */
215 uint16_t input_primitive;
216
217 /** The maximum number of vertices the geometry shader might write. */
218 uint16_t vertices_out;
219
220 /** 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS */
221 uint8_t invocations;
222
223 /** The number of vertices recieves per input primitive (max. 6) */
224 uint8_t vertices_in:3;
225
226 /** Whether or not this shader uses EndPrimitive */
227 bool uses_end_primitive:1;
228
229 /** Whether or not this shader uses non-zero streams */
230 bool uses_streams:1;
231 } gs;
232
233 struct {
234 bool uses_discard:1;
235 bool uses_demote:1;
236
237 /**
238 * True if this fragment shader requires helper invocations. This
239 * can be caused by the use of ALU derivative ops, texture
240 * instructions which do implicit derivatives, and the use of quad
241 * subgroup operations.
242 */
243 bool needs_helper_invocations:1;
244
245 /**
246 * Whether any inputs are declared with the "sample" qualifier.
247 */
248 bool uses_sample_qualifier:1;
249
250 /**
251 * Whether early fragment tests are enabled as defined by
252 * ARB_shader_image_load_store.
253 */
254 bool early_fragment_tests:1;
255
256 /**
257 * Defined by INTEL_conservative_rasterization.
258 */
259 bool inner_coverage:1;
260
261 bool post_depth_coverage:1;
262
263 /**
264 * \name ARB_fragment_coord_conventions
265 * @{
266 */
267 bool pixel_center_integer:1;
268 bool origin_upper_left:1;
269 /*@}*/
270
271 bool pixel_interlock_ordered:1;
272 bool pixel_interlock_unordered:1;
273 bool sample_interlock_ordered:1;
274 bool sample_interlock_unordered:1;
275
276 /**
277 * Flags whether NIR's base types on the FS color outputs should be
278 * ignored.
279 *
280 * GLSL requires that fragment shader output base types match the
281 * render target's base types for the behavior to be defined. From
282 * the GL 4.6 spec:
283 *
284 * "If the values written by the fragment shader do not match the
285 * format(s) of the corresponding color buffer(s), the result is
286 * undefined."
287 *
288 * However, for NIR shaders translated from TGSI, we don't have the
289 * output types any more, so the driver will need to do whatever
290 * fixups are necessary to handle effectively untyped data being
291 * output from the FS.
292 */
293 bool untyped_color_outputs:1;
294
295 /** gl_FragDepth layout for ARB_conservative_depth. */
296 enum gl_frag_depth_layout depth_layout:3;
297 } fs;
298
299 struct {
300 uint16_t local_size[3];
301
302 bool local_size_variable:1;
303 uint8_t user_data_components_amd:3;
304
305 /*
306 * Arrangement of invocations used to calculate derivatives in a compute
307 * shader. From NV_compute_shader_derivatives.
308 */
309 enum gl_derivative_group derivative_group:2;
310
311 /**
312 * Size of shared variables accessed by the compute shader.
313 */
314 unsigned shared_size;
315
316 /**
317 * pointer size is:
318 * AddressingModelLogical: 0 (default)
319 * AddressingModelPhysical32: 32
320 * AddressingModelPhysical64: 64
321 */
322 unsigned ptr_size;
323 } cs;
324
325 /* Applies to both TCS and TES. */
326 struct {
327 uint16_t primitive_mode; /* GL_TRIANGLES, GL_QUADS or GL_ISOLINES */
328
329 /** The number of vertices in the TCS output patch. */
330 uint8_t tcs_vertices_out;
331 enum gl_tess_spacing spacing:2;
332
333 /* Bit mask of TCS per-vertex inputs (VS outputs) that are used
334 * with a vertex index that is NOT the invocation id
335 */
336 uint64_t tcs_cross_invocation_inputs_read;
337
338 /* Bit mask of TCS per-vertex outputs that are used
339 * with a vertex index that is NOT the invocation id
340 */
341 uint64_t tcs_cross_invocation_outputs_read;
342
343 /** Is the vertex order counterclockwise? */
344 bool ccw:1;
345 bool point_mode:1;
346 } tess;
347 };
348 } shader_info;
349
350 #ifdef __cplusplus
351 }
352 #endif
353
354 #endif /* SHADER_INFO_H */