14a49301eSmrg/************************************************************************** 24a49301eSmrg * 3af69d88dSmrg * Copyright 2008 VMware, Inc. 44a49301eSmrg * All Rights Reserved. 54a49301eSmrg * 64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a 74a49301eSmrg * copy of this software and associated documentation files (the 84a49301eSmrg * "Software"), to deal in the Software without restriction, including 94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish, 104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to 114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to 124a49301eSmrg * the following conditions: 134a49301eSmrg * 144a49301eSmrg * The above copyright notice and this permission notice (including the 154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions 164a49301eSmrg * of the Software. 174a49301eSmrg * 184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 254a49301eSmrg * 264a49301eSmrg **************************************************************************/ 274a49301eSmrg 284a49301eSmrg#ifndef TGSI_SCAN_H 294a49301eSmrg#define TGSI_SCAN_H 304a49301eSmrg 314a49301eSmrg 324a49301eSmrg#include "pipe/p_compiler.h" 334a49301eSmrg#include "pipe/p_state.h" 344a49301eSmrg#include "pipe/p_shader_tokens.h" 354a49301eSmrg 3601e04c3fSmrg#ifdef __cplusplus 3701e04c3fSmrgextern "C" { 3801e04c3fSmrg#endif 3901e04c3fSmrg 404a49301eSmrg/** 414a49301eSmrg * Shader summary info 424a49301eSmrg */ 434a49301eSmrgstruct tgsi_shader_info 444a49301eSmrg{ 454a49301eSmrg uint num_tokens; 464a49301eSmrg 474a49301eSmrg ubyte num_inputs; 484a49301eSmrg ubyte num_outputs; 494a49301eSmrg ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */ 504a49301eSmrg ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; 514a49301eSmrg ubyte input_interpolate[PIPE_MAX_SHADER_INPUTS]; 52af69d88dSmrg ubyte input_interpolate_loc[PIPE_MAX_SHADER_INPUTS]; 533464ebd5Sriastradh ubyte input_usage_mask[PIPE_MAX_SHADER_INPUTS]; 544a49301eSmrg ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */ 554a49301eSmrg ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; 5601e04c3fSmrg ubyte output_usagemask[PIPE_MAX_SHADER_OUTPUTS]; 5701e04c3fSmrg ubyte output_streams[PIPE_MAX_SHADER_OUTPUTS]; 584a49301eSmrg 593464ebd5Sriastradh ubyte num_system_values; 603464ebd5Sriastradh ubyte system_value_semantic_name[PIPE_MAX_SHADER_INPUTS]; 613464ebd5Sriastradh 62af69d88dSmrg ubyte processor; 63af69d88dSmrg 644a49301eSmrg uint file_mask[TGSI_FILE_COUNT]; /**< bitmask of declared registers */ 654a49301eSmrg uint file_count[TGSI_FILE_COUNT]; /**< number of declared registers */ 664a49301eSmrg int file_max[TGSI_FILE_COUNT]; /**< highest index of declared registers */ 67af69d88dSmrg int const_file_max[PIPE_MAX_CONSTANT_BUFFERS]; 6801e04c3fSmrg unsigned const_buffers_declared; /**< bitmask of declared const buffers */ 6901e04c3fSmrg unsigned samplers_declared; /**< bitmask of declared samplers */ 7001e04c3fSmrg ubyte sampler_targets[PIPE_MAX_SHADER_SAMPLER_VIEWS]; /**< TGSI_TEXTURE_x values */ 7101e04c3fSmrg ubyte sampler_type[PIPE_MAX_SHADER_SAMPLER_VIEWS]; /**< TGSI_RETURN_TYPE_x */ 7201e04c3fSmrg ubyte num_stream_output_components[4]; 7301e04c3fSmrg 7401e04c3fSmrg ubyte input_array_first[PIPE_MAX_SHADER_INPUTS]; 7501e04c3fSmrg ubyte input_array_last[PIPE_MAX_SHADER_INPUTS]; 7601e04c3fSmrg ubyte output_array_first[PIPE_MAX_SHADER_OUTPUTS]; 7701e04c3fSmrg ubyte output_array_last[PIPE_MAX_SHADER_OUTPUTS]; 7801e04c3fSmrg unsigned array_max[TGSI_FILE_COUNT]; /**< highest index array per register file */ 794a49301eSmrg 804a49301eSmrg uint immediate_count; /**< number of immediates declared */ 813464ebd5Sriastradh uint num_instructions; 8201e04c3fSmrg uint num_memory_instructions; /**< sampler, buffer, and image instructions */ 834a49301eSmrg 844a49301eSmrg uint opcode_count[TGSI_OPCODE_LAST]; /**< opcode histogram */ 854a49301eSmrg 8601e04c3fSmrg /** 8701e04c3fSmrg * If a tessellation control shader reads outputs, this describes which ones. 8801e04c3fSmrg */ 8901e04c3fSmrg boolean reads_pervertex_outputs; 9001e04c3fSmrg boolean reads_perpatch_outputs; 9101e04c3fSmrg boolean reads_tessfactor_outputs; 9201e04c3fSmrg 9301e04c3fSmrg ubyte colors_read; /**< which color components are read by the FS */ 9401e04c3fSmrg ubyte colors_written; 95af69d88dSmrg boolean reads_position; /**< does fragment shader read position? */ 96af69d88dSmrg boolean reads_z; /**< does fragment shader read depth? */ 9701e04c3fSmrg boolean reads_samplemask; /**< does fragment shader read sample mask? */ 9801e04c3fSmrg boolean reads_tess_factors; /**< If TES reads TESSINNER or TESSOUTER */ 994a49301eSmrg boolean writes_z; /**< does fragment shader write Z value? */ 1003464ebd5Sriastradh boolean writes_stencil; /**< does fragment shader write stencil value? */ 10101e04c3fSmrg boolean writes_samplemask; /**< does fragment shader write sample mask? */ 102cdc920a0Smrg boolean writes_edgeflag; /**< vertex shader outputs edgeflag */ 103af69d88dSmrg boolean uses_kill; /**< KILL or KILL_IF instruction used? */ 10401e04c3fSmrg boolean uses_persp_center; 10501e04c3fSmrg boolean uses_persp_centroid; 10601e04c3fSmrg boolean uses_persp_sample; 10701e04c3fSmrg boolean uses_linear_center; 10801e04c3fSmrg boolean uses_linear_centroid; 10901e04c3fSmrg boolean uses_linear_sample; 11001e04c3fSmrg boolean uses_persp_opcode_interp_centroid; 11101e04c3fSmrg boolean uses_persp_opcode_interp_offset; 11201e04c3fSmrg boolean uses_persp_opcode_interp_sample; 11301e04c3fSmrg boolean uses_linear_opcode_interp_centroid; 11401e04c3fSmrg boolean uses_linear_opcode_interp_offset; 11501e04c3fSmrg boolean uses_linear_opcode_interp_sample; 1163464ebd5Sriastradh boolean uses_instanceid; 117af69d88dSmrg boolean uses_vertexid; 11801e04c3fSmrg boolean uses_vertexid_nobase; 11901e04c3fSmrg boolean uses_basevertex; 120361fc4cbSmaya boolean uses_drawid; 121af69d88dSmrg boolean uses_primid; 122af69d88dSmrg boolean uses_frontface; 12301e04c3fSmrg boolean uses_invocationid; 12401e04c3fSmrg boolean uses_thread_id[3]; 12501e04c3fSmrg boolean uses_block_id[3]; 12601e04c3fSmrg boolean uses_block_size; 12701e04c3fSmrg boolean uses_grid_size; 1287ec681f3Smrg boolean uses_subgroup_info; 12901e04c3fSmrg boolean writes_position; 13001e04c3fSmrg boolean writes_psize; 13101e04c3fSmrg boolean writes_clipvertex; 13201e04c3fSmrg boolean writes_primid; 133af69d88dSmrg boolean writes_viewport_index; 134af69d88dSmrg boolean writes_layer; 13501e04c3fSmrg boolean writes_memory; /**< contains stores or atomics to buffers or images */ 13601e04c3fSmrg boolean uses_doubles; /**< uses any of the double instructions */ 13701e04c3fSmrg boolean uses_derivatives; 13801e04c3fSmrg boolean uses_bindless_samplers; 13901e04c3fSmrg boolean uses_bindless_images; 1407ec681f3Smrg boolean uses_fbfetch; 14101e04c3fSmrg unsigned clipdist_writemask; 14201e04c3fSmrg unsigned culldist_writemask; 143af69d88dSmrg unsigned num_written_culldistance; 144af69d88dSmrg unsigned num_written_clipdistance; 14501e04c3fSmrg 14601e04c3fSmrg unsigned images_declared; /**< bitmask of declared images */ 1477ec681f3Smrg unsigned msaa_images_declared; /**< bitmask of declared MSAA images */ 1487ec681f3Smrg 14901e04c3fSmrg /** 15001e04c3fSmrg * Bitmask indicating which declared image is a buffer. 15101e04c3fSmrg */ 15201e04c3fSmrg unsigned images_buffers; 15301e04c3fSmrg unsigned images_load; /**< bitmask of images using loads */ 15401e04c3fSmrg unsigned images_store; /**< bitmask of images using stores */ 15501e04c3fSmrg unsigned images_atomic; /**< bitmask of images using atomics */ 15601e04c3fSmrg unsigned shader_buffers_declared; /**< bitmask of declared shader buffers */ 15701e04c3fSmrg unsigned shader_buffers_load; /**< bitmask of shader buffers using loads */ 15801e04c3fSmrg unsigned shader_buffers_store; /**< bitmask of shader buffers using stores */ 15901e04c3fSmrg unsigned shader_buffers_atomic; /**< bitmask of shader buffers using atomics */ 160361fc4cbSmaya bool uses_bindless_buffer_load; 161361fc4cbSmaya bool uses_bindless_buffer_store; 162361fc4cbSmaya bool uses_bindless_buffer_atomic; 163361fc4cbSmaya bool uses_bindless_image_load; 164361fc4cbSmaya bool uses_bindless_image_store; 165361fc4cbSmaya bool uses_bindless_image_atomic; 166361fc4cbSmaya 1673464ebd5Sriastradh /** 1683464ebd5Sriastradh * Bitmask indicating which register files are accessed with 1693464ebd5Sriastradh * indirect addressing. The bits are (1 << TGSI_FILE_x), etc. 1703464ebd5Sriastradh */ 1713464ebd5Sriastradh unsigned indirect_files; 17201e04c3fSmrg /** 17301e04c3fSmrg * Bitmask indicating which register files are read / written with 17401e04c3fSmrg * indirect addressing. The bits are (1 << TGSI_FILE_x). 17501e04c3fSmrg */ 17601e04c3fSmrg unsigned indirect_files_read; 17701e04c3fSmrg unsigned indirect_files_written; 17801e04c3fSmrg unsigned dim_indirect_files; /**< shader resource indexing */ 17901e04c3fSmrg unsigned const_buffers_indirect; /**< const buffers using indirect addressing */ 18001e04c3fSmrg 18101e04c3fSmrg unsigned properties[TGSI_PROPERTY_COUNT]; /* index with TGSI_PROPERTY_ */ 1824a49301eSmrg 18301e04c3fSmrg /** 18401e04c3fSmrg * Max nesting limit of loops/if's 18501e04c3fSmrg */ 18601e04c3fSmrg unsigned max_depth; 18701e04c3fSmrg}; 18801e04c3fSmrg 18901e04c3fSmrgstruct tgsi_array_info 19001e04c3fSmrg{ 19101e04c3fSmrg /** Whether an array with this ID was declared. */ 19201e04c3fSmrg bool declared; 19301e04c3fSmrg 19401e04c3fSmrg /** The OR of all writemasks used to write to this array. */ 19501e04c3fSmrg ubyte writemask; 19601e04c3fSmrg 19701e04c3fSmrg /** The range with which the array was declared. */ 19801e04c3fSmrg struct tgsi_declaration_range range; 19901e04c3fSmrg}; 20001e04c3fSmrg 20101e04c3fSmrgstruct tgsi_tessctrl_info 20201e04c3fSmrg{ 20301e04c3fSmrg /** Whether all codepaths write tess factors in all invocations. */ 20401e04c3fSmrg bool tessfactors_are_def_in_all_invocs; 205cdc920a0Smrg}; 2064a49301eSmrg 2074a49301eSmrgextern void 2084a49301eSmrgtgsi_scan_shader(const struct tgsi_token *tokens, 2094a49301eSmrg struct tgsi_shader_info *info); 2104a49301eSmrg 21101e04c3fSmrgvoid 21201e04c3fSmrgtgsi_scan_arrays(const struct tgsi_token *tokens, 21301e04c3fSmrg unsigned file, 21401e04c3fSmrg unsigned max_array_id, 21501e04c3fSmrg struct tgsi_array_info *arrays); 2164a49301eSmrg 21701e04c3fSmrgvoid 21801e04c3fSmrgtgsi_scan_tess_ctrl(const struct tgsi_token *tokens, 21901e04c3fSmrg const struct tgsi_shader_info *info, 22001e04c3fSmrg struct tgsi_tessctrl_info *out); 2214a49301eSmrg 22201e04c3fSmrgstatic inline bool 22301e04c3fSmrgtgsi_is_bindless_image_file(unsigned file) 22401e04c3fSmrg{ 22501e04c3fSmrg return file != TGSI_FILE_IMAGE && 22601e04c3fSmrg file != TGSI_FILE_MEMORY && 227993e1d59Smrg file != TGSI_FILE_BUFFER && 228993e1d59Smrg file != TGSI_FILE_CONSTBUF && 229993e1d59Smrg file != TGSI_FILE_HW_ATOMIC; 23001e04c3fSmrg} 23101e04c3fSmrg 23201e04c3fSmrg#ifdef __cplusplus 23301e04c3fSmrg} // extern "C" 23401e04c3fSmrg#endif 2354a49301eSmrg 2364a49301eSmrg#endif /* TGSI_SCAN_H */ 237