1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef TGSI_SCAN_H
29 #define TGSI_SCAN_H
30
31
32 #include "util/compiler.h"
33 #include "pipe/p_state.h"
34 #include "pipe/p_shader_tokens.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /**
41 * Shader summary info
42 */
43 struct tgsi_shader_info
44 {
45 uint8_t num_inputs;
46 uint8_t num_outputs;
47 uint8_t input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */
48 uint8_t input_semantic_index[PIPE_MAX_SHADER_INPUTS];
49 uint8_t input_interpolate[PIPE_MAX_SHADER_INPUTS];
50 uint8_t input_interpolate_loc[PIPE_MAX_SHADER_INPUTS];
51 uint8_t input_usage_mask[PIPE_MAX_SHADER_INPUTS];
52 uint8_t output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */
53 uint8_t output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
54 uint8_t output_usagemask[PIPE_MAX_SHADER_OUTPUTS];
55 uint8_t output_streams[PIPE_MAX_SHADER_OUTPUTS];
56
57 uint8_t num_system_values;
58 uint8_t system_value_semantic_name[PIPE_MAX_SHADER_INPUTS];
59
60 uint8_t processor;
61
62 uint32_t file_mask[TGSI_FILE_COUNT]; /**< bitmask of declared registers */
63 unsigned file_count[TGSI_FILE_COUNT]; /**< number of declared registers */
64 int file_max[TGSI_FILE_COUNT]; /**< highest index of declared registers */
65 int const_file_max[PIPE_MAX_CONSTANT_BUFFERS];
66 unsigned const_buffers_declared; /**< bitmask of declared const buffers */
67 unsigned samplers_declared; /**< bitmask of declared samplers */
68 uint8_t sampler_targets[PIPE_MAX_SHADER_SAMPLER_VIEWS]; /**< TGSI_TEXTURE_x values */
69 uint8_t sampler_type[PIPE_MAX_SHADER_SAMPLER_VIEWS]; /**< TGSI_RETURN_TYPE_x */
70 uint8_t num_stream_output_components[4];
71
72 uint8_t input_array_first[PIPE_MAX_SHADER_INPUTS];
73 uint8_t output_array_first[PIPE_MAX_SHADER_OUTPUTS];
74
75 unsigned immediate_count; /**< number of immediates declared */
76 unsigned num_instructions;
77
78 unsigned opcode_count[TGSI_OPCODE_LAST]; /**< opcode histogram */
79
80 /**
81 * If a tessellation control shader reads outputs, this describes which ones.
82 */
83 bool reads_pervertex_outputs;
84 bool reads_perpatch_outputs;
85 bool reads_tessfactor_outputs;
86
87 bool reads_z; /**< does fragment shader read depth? */
88 bool writes_z; /**< does fragment shader write Z value? */
89 bool writes_stencil; /**< does fragment shader write stencil value? */
90 bool writes_samplemask; /**< does fragment shader write sample mask? */
91 bool writes_edgeflag; /**< vertex shader outputs edgeflag */
92 bool uses_kill; /**< KILL or KILL_IF instruction used? */
93 bool uses_instanceid;
94 bool uses_vertexid;
95 bool uses_vertexid_nobase;
96 bool uses_basevertex;
97 bool uses_primid;
98 bool uses_frontface;
99 bool uses_invocationid;
100 bool uses_grid_size;
101 bool writes_position;
102 bool writes_psize;
103 bool writes_clipvertex;
104 bool writes_viewport_index;
105 bool writes_layer;
106 bool writes_memory; /**< contains stores or atomics to buffers or images */
107 bool uses_fbfetch;
108 unsigned num_written_culldistance;
109 unsigned num_written_clipdistance;
110
111 unsigned images_declared; /**< bitmask of declared images */
112 unsigned msaa_images_declared; /**< bitmask of declared MSAA images */
113
114 /**
115 * Bitmask indicating which declared image is a buffer.
116 */
117 unsigned images_buffers;
118 unsigned shader_buffers_declared; /**< bitmask of declared shader buffers */
119 unsigned shader_buffers_load; /**< bitmask of shader buffers using loads */
120 unsigned shader_buffers_store; /**< bitmask of shader buffers using stores */
121 unsigned shader_buffers_atomic; /**< bitmask of shader buffers using atomics */
122
123 unsigned hw_atomic_declared; /**< bitmask of declared atomic_counter */
124 /**
125 * Bitmask indicating which register files are accessed with
126 * indirect addressing. The bits are (1 << TGSI_FILE_x), etc.
127 */
128 unsigned indirect_files;
129 /**
130 * Bitmask indicating which register files are read / written with
131 * indirect addressing. The bits are (1 << TGSI_FILE_x).
132 */
133 unsigned dim_indirect_files; /**< shader resource indexing */
134
135 unsigned properties[TGSI_PROPERTY_COUNT]; /* index with TGSI_PROPERTY_ */
136 };
137
138 extern void
139 tgsi_scan_shader(const struct tgsi_token *tokens,
140 struct tgsi_shader_info *info);
141
142 static inline bool
tgsi_is_bindless_image_file(enum tgsi_file_type file)143 tgsi_is_bindless_image_file(enum tgsi_file_type file)
144 {
145 return file != TGSI_FILE_IMAGE &&
146 file != TGSI_FILE_MEMORY &&
147 file != TGSI_FILE_BUFFER &&
148 file != TGSI_FILE_CONSTBUF &&
149 file != TGSI_FILE_HW_ATOMIC;
150 }
151
152 #ifdef __cplusplus
153 } // extern "C"
154 #endif
155
156 #endif /* TGSI_SCAN_H */
157