Path: blob/21.2-virgl/src/compiler/shader_info.h
4545 views
/*1* Copyright © 2016 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22*/2324#ifndef SHADER_INFO_H25#define SHADER_INFO_H2627#include "util/bitset.h"28#include "shader_enums.h"29#include <stdint.h>3031#ifdef __cplusplus32extern "C" {33#endif3435#define MAX_INLINABLE_UNIFORMS 43637struct spirv_supported_capabilities {38bool address;39bool atomic_storage;40bool demote_to_helper_invocation;41bool derivative_group;42bool descriptor_array_dynamic_indexing;43bool descriptor_array_non_uniform_indexing;44bool descriptor_indexing;45bool device_group;46bool draw_parameters;47bool float16_atomic_min_max;48bool float32_atomic_add;49bool float32_atomic_min_max;50bool float64;51bool float64_atomic_add;52bool float64_atomic_min_max;53bool fragment_shader_sample_interlock;54bool fragment_shader_pixel_interlock;55bool fragment_shading_rate;56bool generic_pointers;57bool geometry_streams;58bool image_ms_array;59bool image_read_without_format;60bool image_write_without_format;61bool image_atomic_int64;62bool int8;63bool int16;64bool int64;65bool int64_atomics;66bool integer_functions2;67bool kernel;68bool kernel_image;69bool kernel_image_read_write;70bool literal_sampler;71bool min_lod;72bool multiview;73bool physical_storage_buffer_address;74bool post_depth_coverage;75bool printf;76bool ray_tracing;77bool ray_query;78bool ray_traversal_primitive_culling;79bool runtime_descriptor_array;80bool float_controls;81bool shader_clock;82bool shader_viewport_index_layer;83bool sparse_residency;84bool stencil_export;85bool storage_8bit;86bool storage_16bit;87bool storage_image_ms;88bool subgroup_arithmetic;89bool subgroup_ballot;90bool subgroup_basic;91bool subgroup_quad;92bool subgroup_shuffle;93bool subgroup_uniform_control_flow;94bool subgroup_vote;95bool tessellation;96bool transform_feedback;97bool variable_pointers;98bool vk_memory_model;99bool vk_memory_model_device_scope;100bool workgroup_memory_explicit_layout;101bool float16;102bool amd_fragment_mask;103bool amd_gcn_shader;104bool amd_shader_ballot;105bool amd_trinary_minmax;106bool amd_image_read_write_lod;107bool amd_shader_explicit_vertex_parameter;108bool amd_image_gather_bias_lod;109110bool intel_subgroup_shuffle;111bool intel_subgroup_buffer_block_io;112};113114typedef struct shader_info {115const char *name;116117/* Descriptive name provided by the client; may be NULL */118const char *label;119120/* Shader is internal, and should be ignored by things like NIR_PRINT */121bool internal;122123/** The shader stage, such as MESA_SHADER_VERTEX. */124gl_shader_stage stage:8;125126/** The shader stage in a non SSO linked program that follows this stage,127* such as MESA_SHADER_FRAGMENT.128*/129gl_shader_stage next_stage:8;130131/* Number of textures used by this shader */132uint8_t num_textures;133/* Number of uniform buffers used by this shader */134uint8_t num_ubos;135/* Number of atomic buffers used by this shader */136uint8_t num_abos;137/* Number of shader storage buffers (max .driver_location + 1) used by this138* shader. In the case of nir_lower_atomics_to_ssbo being used, this will139* be the number of actual SSBOs in gl_program->info, and the lowered SSBOs140* and atomic counters in nir_shader->info.141*/142uint8_t num_ssbos;143/* Number of images used by this shader */144uint8_t num_images;145146/* Which inputs are actually read */147uint64_t inputs_read;148/* Which outputs are actually written */149uint64_t outputs_written;150/* Which outputs are actually read */151uint64_t outputs_read;152/* Which system values are actually read */153BITSET_DECLARE(system_values_read, SYSTEM_VALUE_MAX);154155/* Which 16-bit inputs and outputs are used corresponding to156* VARYING_SLOT_VARn_16BIT.157*/158uint16_t inputs_read_16bit;159uint16_t outputs_written_16bit;160uint16_t outputs_read_16bit;161uint16_t inputs_read_indirectly_16bit;162uint16_t outputs_accessed_indirectly_16bit;163164/* Which patch inputs are actually read */165uint32_t patch_inputs_read;166/* Which patch outputs are actually written */167uint32_t patch_outputs_written;168/* Which patch outputs are read */169uint32_t patch_outputs_read;170171/* Which inputs are read indirectly (subset of inputs_read) */172uint64_t inputs_read_indirectly;173/* Which outputs are read or written indirectly */174uint64_t outputs_accessed_indirectly;175/* Which patch inputs are read indirectly (subset of patch_inputs_read) */176uint64_t patch_inputs_read_indirectly;177/* Which patch outputs are read or written indirectly */178uint64_t patch_outputs_accessed_indirectly;179180/** Bitfield of which textures are used */181BITSET_DECLARE(textures_used, 32);182183/** Bitfield of which textures are used by texelFetch() */184BITSET_DECLARE(textures_used_by_txf, 32);185186/** Bitfield of which images are used */187uint32_t images_used;188/** Bitfield of which images are buffers. */189uint32_t image_buffers;190/** Bitfield of which images are MSAA. */191uint32_t msaa_images;192193/* SPV_KHR_float_controls: execution mode for floating point ops */194uint16_t float_controls_execution_mode;195196/**197* Size of shared variables accessed by compute/task/mesh shaders.198*/199unsigned shared_size;200201/**202* Local workgroup size used by compute/task/mesh shaders.203*/204uint16_t workgroup_size[3];205206uint16_t inlinable_uniform_dw_offsets[MAX_INLINABLE_UNIFORMS];207uint8_t num_inlinable_uniforms:4;208209/* The size of the gl_ClipDistance[] array, if declared. */210uint8_t clip_distance_array_size:4;211212/* The size of the gl_CullDistance[] array, if declared. */213uint8_t cull_distance_array_size:4;214215/* Whether or not this shader ever uses textureGather() */216bool uses_texture_gather:1;217218/**219* True if this shader uses the fddx/fddy opcodes.220*221* Note that this does not include the "fine" and "coarse" variants.222*/223bool uses_fddx_fddy:1;224225/* Bitmask of bit-sizes used with ALU instructions. */226uint8_t bit_sizes_float;227uint8_t bit_sizes_int;228229/* Whether the first UBO is the default uniform buffer, i.e. uniforms. */230bool first_ubo_is_default_ubo:1;231232/* Whether or not separate shader objects were used */233bool separate_shader:1;234235/** Was this shader linked with any transform feedback varyings? */236bool has_transform_feedback_varyings:1;237238/* Whether flrp has been lowered. */239bool flrp_lowered:1;240241/* Whether nir_lower_io has been called to lower derefs.242* nir_variables for inputs and outputs might not be present in the IR.243*/244bool io_lowered:1;245246/* Whether the shader writes memory, including transform feedback. */247bool writes_memory:1;248249/* Whether gl_Layer is viewport-relative */250bool layer_viewport_relative:1;251252/* Whether explicit barriers are used */253bool uses_control_barrier : 1;254bool uses_memory_barrier : 1;255256/**257* Shared memory types have explicit layout set. Used for258* SPV_KHR_workgroup_storage_explicit_layout.259*/260bool shared_memory_explicit_layout:1;261262/**263* Used for VK_KHR_zero_initialize_workgroup_memory.264*/265bool zero_initialize_shared_memory:1;266267/**268* Used for ARB_compute_variable_group_size.269*/270bool workgroup_size_variable:1;271272union {273struct {274/* Which inputs are doubles */275uint64_t double_inputs;276277/* For AMD-specific driver-internal shaders. It replaces vertex278* buffer loads with code generating VS inputs from scalar registers.279*280* Valid values: SI_VS_BLIT_SGPRS_POS_*281*/282uint8_t blit_sgprs_amd:4;283284/* True if the shader writes position in window space coordinates pre-transform */285bool window_space_position:1;286} vs;287288struct {289/** The output primitive type (GL enum value) */290uint16_t output_primitive;291292/** The input primitive type (GL enum value) */293uint16_t input_primitive;294295/** The maximum number of vertices the geometry shader might write. */296uint16_t vertices_out;297298/** 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS */299uint8_t invocations;300301/** The number of vertices received per input primitive (max. 6) */302uint8_t vertices_in:3;303304/** Whether or not this shader uses EndPrimitive */305bool uses_end_primitive:1;306307/** The streams used in this shaders (max. 4) */308uint8_t active_stream_mask:4;309} gs;310311struct {312bool uses_discard:1;313bool uses_demote:1;314bool uses_fbfetch_output:1;315bool color_is_dual_source:1;316317/**318* True if this fragment shader requires helper invocations. This319* can be caused by the use of ALU derivative ops, texture320* instructions which do implicit derivatives, and the use of quad321* subgroup operations.322*/323bool needs_quad_helper_invocations:1;324325/**326* True if this fragment shader requires helper invocations for327* all subgroup operations, not just quad ops and derivatives.328*/329bool needs_all_helper_invocations:1;330331/**332* Whether any inputs are declared with the "sample" qualifier.333*/334bool uses_sample_qualifier:1;335336/**337* Whether sample shading is used.338*/339bool uses_sample_shading:1;340341/**342* Whether early fragment tests are enabled as defined by343* ARB_shader_image_load_store.344*/345bool early_fragment_tests:1;346347/**348* Defined by INTEL_conservative_rasterization.349*/350bool inner_coverage:1;351352bool post_depth_coverage:1;353354/**355* \name ARB_fragment_coord_conventions356* @{357*/358bool pixel_center_integer:1;359bool origin_upper_left:1;360/*@}*/361362bool pixel_interlock_ordered:1;363bool pixel_interlock_unordered:1;364bool sample_interlock_ordered:1;365bool sample_interlock_unordered:1;366367/**368* Flags whether NIR's base types on the FS color outputs should be369* ignored.370*371* GLSL requires that fragment shader output base types match the372* render target's base types for the behavior to be defined. From373* the GL 4.6 spec:374*375* "If the values written by the fragment shader do not match the376* format(s) of the corresponding color buffer(s), the result is377* undefined."378*379* However, for NIR shaders translated from TGSI, we don't have the380* output types any more, so the driver will need to do whatever381* fixups are necessary to handle effectively untyped data being382* output from the FS.383*/384bool untyped_color_outputs:1;385386/** gl_FragDepth layout for ARB_conservative_depth. */387enum gl_frag_depth_layout depth_layout:3;388389/**390* Interpolation qualifiers for drivers that lowers color inputs391* to system values.392*/393unsigned color0_interp:3; /* glsl_interp_mode */394bool color0_sample:1;395bool color0_centroid:1;396unsigned color1_interp:3; /* glsl_interp_mode */397bool color1_sample:1;398bool color1_centroid:1;399} fs;400401struct {402uint16_t workgroup_size_hint[3];403404uint8_t user_data_components_amd:3;405406/*407* Arrangement of invocations used to calculate derivatives in a compute408* shader. From NV_compute_shader_derivatives.409*/410enum gl_derivative_group derivative_group:2;411412/**413* pointer size is:414* AddressingModelLogical: 0 (default)415* AddressingModelPhysical32: 32416* AddressingModelPhysical64: 64417*/418unsigned ptr_size;419420/**421* Uses subgroup intrinsics which can communicate across a quad.422*/423bool uses_wide_subgroup_intrinsics;424} cs;425426/* Applies to both TCS and TES. */427struct {428uint16_t primitive_mode; /* GL_TRIANGLES, GL_QUADS or GL_ISOLINES */429430/** The number of vertices in the TCS output patch. */431uint8_t tcs_vertices_out;432enum gl_tess_spacing spacing:2;433434/** Is the vertex order counterclockwise? */435bool ccw:1;436bool point_mode:1;437438/* Bit mask of TCS per-vertex inputs (VS outputs) that are used439* with a vertex index that is NOT the invocation id440*/441uint64_t tcs_cross_invocation_inputs_read;442443/* Bit mask of TCS per-vertex outputs that are used444* with a vertex index that is NOT the invocation id445*/446uint64_t tcs_cross_invocation_outputs_read;447} tess;448};449} shader_info;450451#ifdef __cplusplus452}453#endif454455#endif /* SHADER_INFO_H */456457458