1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifndef TGSI_SCAN_H 29bf215546Sopenharmony_ci#define TGSI_SCAN_H 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 33bf215546Sopenharmony_ci#include "pipe/p_state.h" 34bf215546Sopenharmony_ci#include "pipe/p_shader_tokens.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#ifdef __cplusplus 37bf215546Sopenharmony_ciextern "C" { 38bf215546Sopenharmony_ci#endif 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci/** 41bf215546Sopenharmony_ci * Shader summary info 42bf215546Sopenharmony_ci */ 43bf215546Sopenharmony_cistruct tgsi_shader_info 44bf215546Sopenharmony_ci{ 45bf215546Sopenharmony_ci uint num_tokens; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci ubyte num_inputs; 48bf215546Sopenharmony_ci ubyte num_outputs; 49bf215546Sopenharmony_ci ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */ 50bf215546Sopenharmony_ci ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; 51bf215546Sopenharmony_ci ubyte input_interpolate[PIPE_MAX_SHADER_INPUTS]; 52bf215546Sopenharmony_ci ubyte input_interpolate_loc[PIPE_MAX_SHADER_INPUTS]; 53bf215546Sopenharmony_ci ubyte input_usage_mask[PIPE_MAX_SHADER_INPUTS]; 54bf215546Sopenharmony_ci ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */ 55bf215546Sopenharmony_ci ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; 56bf215546Sopenharmony_ci ubyte output_usagemask[PIPE_MAX_SHADER_OUTPUTS]; 57bf215546Sopenharmony_ci ubyte output_streams[PIPE_MAX_SHADER_OUTPUTS]; 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci ubyte num_system_values; 60bf215546Sopenharmony_ci ubyte system_value_semantic_name[PIPE_MAX_SHADER_INPUTS]; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci ubyte processor; 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci uint file_mask[TGSI_FILE_COUNT]; /**< bitmask of declared registers */ 65bf215546Sopenharmony_ci uint file_count[TGSI_FILE_COUNT]; /**< number of declared registers */ 66bf215546Sopenharmony_ci int file_max[TGSI_FILE_COUNT]; /**< highest index of declared registers */ 67bf215546Sopenharmony_ci int const_file_max[PIPE_MAX_CONSTANT_BUFFERS]; 68bf215546Sopenharmony_ci unsigned const_buffers_declared; /**< bitmask of declared const buffers */ 69bf215546Sopenharmony_ci unsigned samplers_declared; /**< bitmask of declared samplers */ 70bf215546Sopenharmony_ci ubyte sampler_targets[PIPE_MAX_SHADER_SAMPLER_VIEWS]; /**< TGSI_TEXTURE_x values */ 71bf215546Sopenharmony_ci ubyte sampler_type[PIPE_MAX_SHADER_SAMPLER_VIEWS]; /**< TGSI_RETURN_TYPE_x */ 72bf215546Sopenharmony_ci ubyte num_stream_output_components[4]; 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci ubyte input_array_first[PIPE_MAX_SHADER_INPUTS]; 75bf215546Sopenharmony_ci ubyte output_array_first[PIPE_MAX_SHADER_OUTPUTS]; 76bf215546Sopenharmony_ci unsigned array_max[TGSI_FILE_COUNT]; /**< highest index array per register file */ 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci uint immediate_count; /**< number of immediates declared */ 79bf215546Sopenharmony_ci uint num_instructions; 80bf215546Sopenharmony_ci uint num_memory_instructions; /**< sampler, buffer, and image instructions */ 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci uint opcode_count[TGSI_OPCODE_LAST]; /**< opcode histogram */ 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci /** 85bf215546Sopenharmony_ci * If a tessellation control shader reads outputs, this describes which ones. 86bf215546Sopenharmony_ci */ 87bf215546Sopenharmony_ci boolean reads_pervertex_outputs; 88bf215546Sopenharmony_ci boolean reads_perpatch_outputs; 89bf215546Sopenharmony_ci boolean reads_tessfactor_outputs; 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci ubyte colors_read; /**< which color components are read by the FS */ 92bf215546Sopenharmony_ci ubyte colors_written; 93bf215546Sopenharmony_ci boolean reads_position; /**< does fragment shader read position? */ 94bf215546Sopenharmony_ci boolean reads_z; /**< does fragment shader read depth? */ 95bf215546Sopenharmony_ci boolean reads_samplemask; /**< does fragment shader read sample mask? */ 96bf215546Sopenharmony_ci boolean reads_tess_factors; /**< If TES reads TESSINNER or TESSOUTER */ 97bf215546Sopenharmony_ci boolean writes_z; /**< does fragment shader write Z value? */ 98bf215546Sopenharmony_ci boolean writes_stencil; /**< does fragment shader write stencil value? */ 99bf215546Sopenharmony_ci boolean writes_samplemask; /**< does fragment shader write sample mask? */ 100bf215546Sopenharmony_ci boolean writes_edgeflag; /**< vertex shader outputs edgeflag */ 101bf215546Sopenharmony_ci boolean uses_kill; /**< KILL or KILL_IF instruction used? */ 102bf215546Sopenharmony_ci boolean uses_persp_center; 103bf215546Sopenharmony_ci boolean uses_persp_centroid; 104bf215546Sopenharmony_ci boolean uses_persp_sample; 105bf215546Sopenharmony_ci boolean uses_linear_center; 106bf215546Sopenharmony_ci boolean uses_linear_centroid; 107bf215546Sopenharmony_ci boolean uses_linear_sample; 108bf215546Sopenharmony_ci boolean uses_persp_opcode_interp_centroid; 109bf215546Sopenharmony_ci boolean uses_persp_opcode_interp_offset; 110bf215546Sopenharmony_ci boolean uses_persp_opcode_interp_sample; 111bf215546Sopenharmony_ci boolean uses_linear_opcode_interp_centroid; 112bf215546Sopenharmony_ci boolean uses_linear_opcode_interp_offset; 113bf215546Sopenharmony_ci boolean uses_linear_opcode_interp_sample; 114bf215546Sopenharmony_ci boolean uses_instanceid; 115bf215546Sopenharmony_ci boolean uses_vertexid; 116bf215546Sopenharmony_ci boolean uses_vertexid_nobase; 117bf215546Sopenharmony_ci boolean uses_basevertex; 118bf215546Sopenharmony_ci boolean uses_drawid; 119bf215546Sopenharmony_ci boolean uses_primid; 120bf215546Sopenharmony_ci boolean uses_frontface; 121bf215546Sopenharmony_ci boolean uses_invocationid; 122bf215546Sopenharmony_ci boolean uses_thread_id[3]; 123bf215546Sopenharmony_ci boolean uses_block_id[3]; 124bf215546Sopenharmony_ci boolean uses_block_size; 125bf215546Sopenharmony_ci boolean uses_grid_size; 126bf215546Sopenharmony_ci boolean uses_subgroup_info; 127bf215546Sopenharmony_ci boolean writes_position; 128bf215546Sopenharmony_ci boolean writes_psize; 129bf215546Sopenharmony_ci boolean writes_clipvertex; 130bf215546Sopenharmony_ci boolean writes_primid; 131bf215546Sopenharmony_ci boolean writes_viewport_index; 132bf215546Sopenharmony_ci boolean writes_layer; 133bf215546Sopenharmony_ci boolean writes_memory; /**< contains stores or atomics to buffers or images */ 134bf215546Sopenharmony_ci boolean uses_doubles; /**< uses any of the double instructions */ 135bf215546Sopenharmony_ci boolean uses_derivatives; 136bf215546Sopenharmony_ci boolean uses_bindless_samplers; 137bf215546Sopenharmony_ci boolean uses_bindless_images; 138bf215546Sopenharmony_ci boolean uses_fbfetch; 139bf215546Sopenharmony_ci unsigned clipdist_writemask; 140bf215546Sopenharmony_ci unsigned culldist_writemask; 141bf215546Sopenharmony_ci unsigned num_written_culldistance; 142bf215546Sopenharmony_ci unsigned num_written_clipdistance; 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci unsigned images_declared; /**< bitmask of declared images */ 145bf215546Sopenharmony_ci unsigned msaa_images_declared; /**< bitmask of declared MSAA images */ 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci /** 148bf215546Sopenharmony_ci * Bitmask indicating which declared image is a buffer. 149bf215546Sopenharmony_ci */ 150bf215546Sopenharmony_ci unsigned images_buffers; 151bf215546Sopenharmony_ci unsigned images_load; /**< bitmask of images using loads */ 152bf215546Sopenharmony_ci unsigned images_store; /**< bitmask of images using stores */ 153bf215546Sopenharmony_ci unsigned images_atomic; /**< bitmask of images using atomics */ 154bf215546Sopenharmony_ci unsigned shader_buffers_declared; /**< bitmask of declared shader buffers */ 155bf215546Sopenharmony_ci unsigned shader_buffers_load; /**< bitmask of shader buffers using loads */ 156bf215546Sopenharmony_ci unsigned shader_buffers_store; /**< bitmask of shader buffers using stores */ 157bf215546Sopenharmony_ci unsigned shader_buffers_atomic; /**< bitmask of shader buffers using atomics */ 158bf215546Sopenharmony_ci bool uses_bindless_buffer_load; 159bf215546Sopenharmony_ci bool uses_bindless_buffer_store; 160bf215546Sopenharmony_ci bool uses_bindless_buffer_atomic; 161bf215546Sopenharmony_ci bool uses_bindless_image_load; 162bf215546Sopenharmony_ci bool uses_bindless_image_store; 163bf215546Sopenharmony_ci bool uses_bindless_image_atomic; 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci unsigned hw_atomic_declared; /**< bitmask of declared atomic_counter */ 166bf215546Sopenharmony_ci /** 167bf215546Sopenharmony_ci * Bitmask indicating which register files are accessed with 168bf215546Sopenharmony_ci * indirect addressing. The bits are (1 << TGSI_FILE_x), etc. 169bf215546Sopenharmony_ci */ 170bf215546Sopenharmony_ci unsigned indirect_files; 171bf215546Sopenharmony_ci /** 172bf215546Sopenharmony_ci * Bitmask indicating which register files are read / written with 173bf215546Sopenharmony_ci * indirect addressing. The bits are (1 << TGSI_FILE_x). 174bf215546Sopenharmony_ci */ 175bf215546Sopenharmony_ci unsigned indirect_files_read; 176bf215546Sopenharmony_ci unsigned indirect_files_written; 177bf215546Sopenharmony_ci unsigned dim_indirect_files; /**< shader resource indexing */ 178bf215546Sopenharmony_ci unsigned const_buffers_indirect; /**< const buffers using indirect addressing */ 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci unsigned properties[TGSI_PROPERTY_COUNT]; /* index with TGSI_PROPERTY_ */ 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci /** 183bf215546Sopenharmony_ci * Max nesting limit of loops/if's 184bf215546Sopenharmony_ci */ 185bf215546Sopenharmony_ci unsigned max_depth; 186bf215546Sopenharmony_ci}; 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_cistruct tgsi_array_info 189bf215546Sopenharmony_ci{ 190bf215546Sopenharmony_ci /** Whether an array with this ID was declared. */ 191bf215546Sopenharmony_ci bool declared; 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci /** The OR of all writemasks used to write to this array. */ 194bf215546Sopenharmony_ci ubyte writemask; 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci /** The range with which the array was declared. */ 197bf215546Sopenharmony_ci struct tgsi_declaration_range range; 198bf215546Sopenharmony_ci}; 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_cistruct tgsi_tessctrl_info 201bf215546Sopenharmony_ci{ 202bf215546Sopenharmony_ci /** Whether all codepaths write tess factors in all invocations. */ 203bf215546Sopenharmony_ci bool tessfactors_are_def_in_all_invocs; 204bf215546Sopenharmony_ci}; 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ciextern void 207bf215546Sopenharmony_citgsi_scan_shader(const struct tgsi_token *tokens, 208bf215546Sopenharmony_ci struct tgsi_shader_info *info); 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_civoid 211bf215546Sopenharmony_citgsi_scan_arrays(const struct tgsi_token *tokens, 212bf215546Sopenharmony_ci unsigned file, 213bf215546Sopenharmony_ci unsigned max_array_id, 214bf215546Sopenharmony_ci struct tgsi_array_info *arrays); 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_civoid 217bf215546Sopenharmony_citgsi_scan_tess_ctrl(const struct tgsi_token *tokens, 218bf215546Sopenharmony_ci const struct tgsi_shader_info *info, 219bf215546Sopenharmony_ci struct tgsi_tessctrl_info *out); 220bf215546Sopenharmony_ci 221bf215546Sopenharmony_cistatic inline bool 222bf215546Sopenharmony_citgsi_is_bindless_image_file(unsigned file) 223bf215546Sopenharmony_ci{ 224bf215546Sopenharmony_ci return file != TGSI_FILE_IMAGE && 225bf215546Sopenharmony_ci file != TGSI_FILE_MEMORY && 226bf215546Sopenharmony_ci file != TGSI_FILE_BUFFER && 227bf215546Sopenharmony_ci file != TGSI_FILE_CONSTBUF && 228bf215546Sopenharmony_ci file != TGSI_FILE_HW_ATOMIC; 229bf215546Sopenharmony_ci} 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ci#ifdef __cplusplus 232bf215546Sopenharmony_ci} // extern "C" 233bf215546Sopenharmony_ci#endif 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_ci#endif /* TGSI_SCAN_H */ 236