1bf215546Sopenharmony_ci/********************************************************** 2bf215546Sopenharmony_ci * Copyright 2008-2022 VMware, Inc. All rights reserved. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person 5bf215546Sopenharmony_ci * obtaining a copy of this software and associated documentation 6bf215546Sopenharmony_ci * files (the "Software"), to deal in the Software without 7bf215546Sopenharmony_ci * restriction, including without limitation the rights to use, copy, 8bf215546Sopenharmony_ci * modify, merge, publish, distribute, sublicense, and/or sell copies 9bf215546Sopenharmony_ci * of the Software, and to permit persons to whom the Software is 10bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be 13bf215546Sopenharmony_ci * included in all copies or substantial portions of the Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18bf215546Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19bf215546Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20bf215546Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21bf215546Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22bf215546Sopenharmony_ci * SOFTWARE. 23bf215546Sopenharmony_ci * 24bf215546Sopenharmony_ci **********************************************************/ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef SVGA_SHADER_H 27bf215546Sopenharmony_ci#define SVGA_SHADER_H 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "svga3d_reg.h" 30bf215546Sopenharmony_ci#include "svga_context.h" 31bf215546Sopenharmony_ci#include "svga_streamout.h" 32bf215546Sopenharmony_ci#include "compiler/shader_enums.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci/** 36bf215546Sopenharmony_ci * We use a 64-bit mask to keep track of the generic indexes. 37bf215546Sopenharmony_ci * This is the maximum semantic index for a TGSI GENERIC[i] register. 38bf215546Sopenharmony_ci */ 39bf215546Sopenharmony_ci#define MAX_GENERIC_VARYING 64 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_cistruct svga_context; 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_cistruct svga_compile_key 46bf215546Sopenharmony_ci{ 47bf215546Sopenharmony_ci /* vertex shader only */ 48bf215546Sopenharmony_ci struct { 49bf215546Sopenharmony_ci uint64_t fs_generic_inputs; 50bf215546Sopenharmony_ci unsigned passthrough:1; 51bf215546Sopenharmony_ci unsigned need_prescale:1; 52bf215546Sopenharmony_ci unsigned undo_viewport:1; 53bf215546Sopenharmony_ci unsigned allow_psiz:1; 54bf215546Sopenharmony_ci unsigned need_vertex_id_bias:1; 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci /** The following are all 32-bit bitmasks (per VS input) */ 57bf215546Sopenharmony_ci unsigned adjust_attrib_range; 58bf215546Sopenharmony_ci unsigned attrib_is_pure_int; 59bf215546Sopenharmony_ci unsigned adjust_attrib_w_1; 60bf215546Sopenharmony_ci unsigned adjust_attrib_itof; 61bf215546Sopenharmony_ci unsigned adjust_attrib_utof; 62bf215546Sopenharmony_ci unsigned attrib_is_bgra; 63bf215546Sopenharmony_ci unsigned attrib_puint_to_snorm; 64bf215546Sopenharmony_ci unsigned attrib_puint_to_uscaled; 65bf215546Sopenharmony_ci unsigned attrib_puint_to_sscaled; 66bf215546Sopenharmony_ci } vs; 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci /* geometry shader only */ 69bf215546Sopenharmony_ci struct { 70bf215546Sopenharmony_ci uint64_t vs_generic_outputs; 71bf215546Sopenharmony_ci unsigned need_prescale:1; 72bf215546Sopenharmony_ci unsigned writes_psize:1; 73bf215546Sopenharmony_ci unsigned wide_point:1; 74bf215546Sopenharmony_ci unsigned writes_viewport_index:1; 75bf215546Sopenharmony_ci unsigned num_prescale:5; 76bf215546Sopenharmony_ci } gs; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci /* fragment shader only */ 79bf215546Sopenharmony_ci struct { 80bf215546Sopenharmony_ci uint64_t vs_generic_outputs; 81bf215546Sopenharmony_ci uint64_t gs_generic_outputs; 82bf215546Sopenharmony_ci unsigned light_twoside:1; 83bf215546Sopenharmony_ci unsigned front_ccw:1; 84bf215546Sopenharmony_ci unsigned white_fragments:1; 85bf215546Sopenharmony_ci unsigned alpha_to_one:1; 86bf215546Sopenharmony_ci unsigned flatshade:1; 87bf215546Sopenharmony_ci unsigned pstipple:1; 88bf215546Sopenharmony_ci unsigned alpha_func:4; /**< SVGA3D_CMP_x */ 89bf215546Sopenharmony_ci unsigned write_color0_to_n_cbufs:4; 90bf215546Sopenharmony_ci unsigned aa_point:1; 91bf215546Sopenharmony_ci unsigned layer_to_zero:1; 92bf215546Sopenharmony_ci int aa_point_coord_index; 93bf215546Sopenharmony_ci float alpha_ref; 94bf215546Sopenharmony_ci } fs; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci /* tessellation control shader */ 97bf215546Sopenharmony_ci struct { 98bf215546Sopenharmony_ci unsigned vertices_per_patch:8; 99bf215546Sopenharmony_ci unsigned vertices_out:8; 100bf215546Sopenharmony_ci enum pipe_prim_type prim_mode:8; 101bf215546Sopenharmony_ci enum pipe_tess_spacing spacing:3; 102bf215546Sopenharmony_ci unsigned vertices_order_cw:1; 103bf215546Sopenharmony_ci unsigned point_mode:1; 104bf215546Sopenharmony_ci unsigned passthrough:1; 105bf215546Sopenharmony_ci } tcs; 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci /* tessellation evaluation shader */ 108bf215546Sopenharmony_ci struct { 109bf215546Sopenharmony_ci unsigned vertices_per_patch:8; 110bf215546Sopenharmony_ci unsigned tessfactor_index:8; 111bf215546Sopenharmony_ci unsigned need_prescale:1; 112bf215546Sopenharmony_ci unsigned need_tessouter:1; 113bf215546Sopenharmony_ci unsigned need_tessinner:1; 114bf215546Sopenharmony_ci } tes; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci /* compute shader */ 117bf215546Sopenharmony_ci struct { 118bf215546Sopenharmony_ci unsigned grid_size[3]; 119bf215546Sopenharmony_ci unsigned mem_size; 120bf215546Sopenharmony_ci } cs; 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci /* any shader type */ 123bf215546Sopenharmony_ci int8_t generic_remap_table[MAX_GENERIC_VARYING]; 124bf215546Sopenharmony_ci unsigned num_textures:8; 125bf215546Sopenharmony_ci unsigned num_samplers:8; 126bf215546Sopenharmony_ci unsigned num_unnormalized_coords:8; 127bf215546Sopenharmony_ci unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES; 128bf215546Sopenharmony_ci unsigned last_vertex_stage:1; 129bf215546Sopenharmony_ci unsigned clamp_vertex_color:1; 130bf215546Sopenharmony_ci unsigned sampler_state_mapping:1; /* Set if use sampler state mapping */ 131bf215546Sopenharmony_ci unsigned sprite_origin_lower_left:1; 132bf215546Sopenharmony_ci uint16_t sprite_coord_enable; 133bf215546Sopenharmony_ci struct { 134bf215546Sopenharmony_ci unsigned compare_mode:1; 135bf215546Sopenharmony_ci unsigned compare_func:3; 136bf215546Sopenharmony_ci unsigned compare_in_shader:1; 137bf215546Sopenharmony_ci unsigned unnormalized:1; 138bf215546Sopenharmony_ci unsigned texel_bias:1; 139bf215546Sopenharmony_ci unsigned width_height_idx:5; /**< texture unit */ 140bf215546Sopenharmony_ci unsigned is_array:1; 141bf215546Sopenharmony_ci unsigned swizzle_r:3; 142bf215546Sopenharmony_ci unsigned swizzle_g:3; 143bf215546Sopenharmony_ci unsigned swizzle_b:3; 144bf215546Sopenharmony_ci unsigned swizzle_a:3; 145bf215546Sopenharmony_ci unsigned num_samples:5; /**< Up to 16 samples */ 146bf215546Sopenharmony_ci unsigned target:4; 147bf215546Sopenharmony_ci unsigned sampler_return_type:4; 148bf215546Sopenharmony_ci unsigned sampler_view:1; 149bf215546Sopenharmony_ci unsigned sampler_index:5; 150bf215546Sopenharmony_ci } tex[PIPE_MAX_SAMPLERS]; 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci unsigned uav_splice_index:4; /* starting uav index */ 153bf215546Sopenharmony_ci unsigned srv_raw_buf_index:8; /* start index for srv raw buffers */ 154bf215546Sopenharmony_ci unsigned image_size_used:1; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci uint16_t raw_buffers; /* bitmask of raw buffers */ 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci struct { 159bf215546Sopenharmony_ci enum tgsi_return_type return_type; 160bf215546Sopenharmony_ci enum pipe_texture_target resource_target; 161bf215546Sopenharmony_ci unsigned is_array:1; 162bf215546Sopenharmony_ci unsigned is_single_layer:1; 163bf215546Sopenharmony_ci unsigned uav_index; 164bf215546Sopenharmony_ci } images[PIPE_MAX_SHADER_IMAGES]; 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci uint32_t shader_buf_uav_index[PIPE_MAX_SHADER_BUFFERS]; 167bf215546Sopenharmony_ci uint32_t atomic_buf_uav_index[PIPE_MAX_HW_ATOMIC_BUFFERS]; 168bf215546Sopenharmony_ci}; 169bf215546Sopenharmony_ci 170bf215546Sopenharmony_ci/* A key for a variant of token string of a shader */ 171bf215546Sopenharmony_cistruct svga_token_key { 172bf215546Sopenharmony_ci struct { 173bf215546Sopenharmony_ci unsigned sprite_coord_enable:24; 174bf215546Sopenharmony_ci unsigned sprite_origin_upper_left:1; 175bf215546Sopenharmony_ci unsigned point_pos_stream_out:1; 176bf215546Sopenharmony_ci unsigned writes_psize:1; 177bf215546Sopenharmony_ci unsigned aa_point:1; 178bf215546Sopenharmony_ci } gs; 179bf215546Sopenharmony_ci struct { 180bf215546Sopenharmony_ci unsigned write_position:1; 181bf215546Sopenharmony_ci } vs; 182bf215546Sopenharmony_ci unsigned dynamic_indexing:1; 183bf215546Sopenharmony_ci}; 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_ci/** 186bf215546Sopenharmony_ci * A single TGSI shader may be compiled into different variants of 187bf215546Sopenharmony_ci * SVGA3D shaders depending on the compile key. Each user shader 188bf215546Sopenharmony_ci * will have a linked list of these variants. 189bf215546Sopenharmony_ci */ 190bf215546Sopenharmony_cistruct svga_shader_variant 191bf215546Sopenharmony_ci{ 192bf215546Sopenharmony_ci const struct svga_shader *shader; 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci /** Parameters used to generate this variant */ 195bf215546Sopenharmony_ci struct svga_compile_key key; 196bf215546Sopenharmony_ci 197bf215546Sopenharmony_ci /* svga shader type */ 198bf215546Sopenharmony_ci SVGA3dShaderType type; 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci /* Compiled shader tokens: 201bf215546Sopenharmony_ci */ 202bf215546Sopenharmony_ci const unsigned *tokens; 203bf215546Sopenharmony_ci unsigned nr_tokens; 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_ci /* shader signature */ 206bf215546Sopenharmony_ci unsigned signatureLen; 207bf215546Sopenharmony_ci SVGA3dDXShaderSignatureHeader *signature; 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_ci /** Per-context shader identifier used with SVGA_3D_CMD_SHADER_DEFINE, 210bf215546Sopenharmony_ci * SVGA_3D_CMD_SET_SHADER and SVGA_3D_CMD_SHADER_DESTROY. 211bf215546Sopenharmony_ci */ 212bf215546Sopenharmony_ci unsigned id; 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci /** Start of extra constants (number of float[4] constants) */ 215bf215546Sopenharmony_ci unsigned extra_const_start; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci /* GB object buffer containing the bytecode */ 218bf215546Sopenharmony_ci struct svga_winsys_gb_shader *gb_shader; 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_ci /** Next variant */ 221bf215546Sopenharmony_ci struct svga_shader_variant *next; 222bf215546Sopenharmony_ci}; 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci 225bf215546Sopenharmony_ci/** 226bf215546Sopenharmony_ci * Shader variant for fragment shader 227bf215546Sopenharmony_ci */ 228bf215546Sopenharmony_cistruct svga_fs_variant 229bf215546Sopenharmony_ci{ 230bf215546Sopenharmony_ci struct svga_shader_variant base; 231bf215546Sopenharmony_ci 232bf215546Sopenharmony_ci boolean uses_flat_interp; /** TRUE if flat interpolation qualifier is 233bf215546Sopenharmony_ci * applied to any of the varyings. 234bf215546Sopenharmony_ci */ 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci /** Is the color output just a constant value? (fragment shader only) */ 237bf215546Sopenharmony_ci boolean constant_color_output; 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci /** Bitmask indicating which texture units are doing the shadow 240bf215546Sopenharmony_ci * comparison test in the shader rather than the sampler state. 241bf215546Sopenharmony_ci */ 242bf215546Sopenharmony_ci unsigned fs_shadow_compare_units; 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_ci /** For FS-based polygon stipple */ 245bf215546Sopenharmony_ci unsigned pstipple_sampler_unit:8; 246bf215546Sopenharmony_ci unsigned pstipple_sampler_state_index:8; 247bf215546Sopenharmony_ci}; 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci/** 251bf215546Sopenharmony_ci * Shader variant for geometry shader 252bf215546Sopenharmony_ci */ 253bf215546Sopenharmony_cistruct svga_gs_variant 254bf215546Sopenharmony_ci{ 255bf215546Sopenharmony_ci struct svga_shader_variant base; 256bf215546Sopenharmony_ci}; 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci/** 260bf215546Sopenharmony_ci * Shader variant for vertex shader 261bf215546Sopenharmony_ci */ 262bf215546Sopenharmony_cistruct svga_vs_variant 263bf215546Sopenharmony_ci{ 264bf215546Sopenharmony_ci struct svga_shader_variant base; 265bf215546Sopenharmony_ci}; 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci/** 269bf215546Sopenharmony_ci * Shader variant for tessellation evaluation shader 270bf215546Sopenharmony_ci */ 271bf215546Sopenharmony_cistruct svga_tes_variant 272bf215546Sopenharmony_ci{ 273bf215546Sopenharmony_ci struct svga_shader_variant base; 274bf215546Sopenharmony_ci 275bf215546Sopenharmony_ci enum pipe_prim_type prim_mode:8; 276bf215546Sopenharmony_ci enum pipe_tess_spacing spacing:3; 277bf215546Sopenharmony_ci unsigned vertices_order_cw:1; 278bf215546Sopenharmony_ci unsigned point_mode:1; 279bf215546Sopenharmony_ci}; 280bf215546Sopenharmony_ci 281bf215546Sopenharmony_ci 282bf215546Sopenharmony_ci/** 283bf215546Sopenharmony_ci * Shader variant for tessellation control shader 284bf215546Sopenharmony_ci */ 285bf215546Sopenharmony_cistruct svga_tcs_variant 286bf215546Sopenharmony_ci{ 287bf215546Sopenharmony_ci struct svga_shader_variant base; 288bf215546Sopenharmony_ci}; 289bf215546Sopenharmony_ci 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci/** 292bf215546Sopenharmony_ci * Shader variant for compute shader 293bf215546Sopenharmony_ci */ 294bf215546Sopenharmony_cistruct svga_cs_variant 295bf215546Sopenharmony_ci{ 296bf215546Sopenharmony_ci struct svga_shader_variant base; 297bf215546Sopenharmony_ci}; 298bf215546Sopenharmony_ci 299bf215546Sopenharmony_ci 300bf215546Sopenharmony_cistruct svga_shader_info 301bf215546Sopenharmony_ci{ 302bf215546Sopenharmony_ci ubyte num_inputs; 303bf215546Sopenharmony_ci ubyte num_outputs; 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_ci ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; 306bf215546Sopenharmony_ci ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; 307bf215546Sopenharmony_ci ubyte input_usage_mask[PIPE_MAX_SHADER_INPUTS]; 308bf215546Sopenharmony_ci ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; 309bf215546Sopenharmony_ci ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; 310bf215546Sopenharmony_ci ubyte output_usage_mask[PIPE_MAX_SHADER_OUTPUTS]; 311bf215546Sopenharmony_ci 312bf215546Sopenharmony_ci uint64_t generic_inputs_mask; 313bf215546Sopenharmony_ci uint64_t generic_outputs_mask; 314bf215546Sopenharmony_ci 315bf215546Sopenharmony_ci boolean writes_edgeflag; 316bf215546Sopenharmony_ci boolean writes_layer; 317bf215546Sopenharmony_ci boolean writes_position; 318bf215546Sopenharmony_ci boolean writes_psize; 319bf215546Sopenharmony_ci boolean writes_viewport_index; 320bf215546Sopenharmony_ci 321bf215546Sopenharmony_ci boolean uses_grid_size; 322bf215546Sopenharmony_ci boolean uses_const_buffers; 323bf215546Sopenharmony_ci boolean uses_hw_atomic; 324bf215546Sopenharmony_ci boolean uses_images; 325bf215546Sopenharmony_ci boolean uses_image_size; 326bf215546Sopenharmony_ci boolean uses_shader_buffers; 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_ci unsigned const_buffers_declared; /* bitmask of declared const buffers */ 329bf215546Sopenharmony_ci unsigned constbuf0_num_uniforms; /* number of uniforms in constbuf0 */ 330bf215546Sopenharmony_ci 331bf215546Sopenharmony_ci struct { 332bf215546Sopenharmony_ci boolean color0_writes_all_cbufs; 333bf215546Sopenharmony_ci } fs; 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci struct { 336bf215546Sopenharmony_ci enum pipe_prim_type in_prim; 337bf215546Sopenharmony_ci enum pipe_prim_type out_prim; 338bf215546Sopenharmony_ci } gs; 339bf215546Sopenharmony_ci 340bf215546Sopenharmony_ci struct { 341bf215546Sopenharmony_ci unsigned vertices_out; /* number of vertices in tcs patch */ 342bf215546Sopenharmony_ci boolean writes_tess_factor; 343bf215546Sopenharmony_ci } tcs; 344bf215546Sopenharmony_ci 345bf215546Sopenharmony_ci struct { 346bf215546Sopenharmony_ci enum pipe_prim_type prim_mode; 347bf215546Sopenharmony_ci boolean reads_control_point; 348bf215546Sopenharmony_ci boolean reads_tess_factor; 349bf215546Sopenharmony_ci } tes; 350bf215546Sopenharmony_ci}; 351bf215546Sopenharmony_ci 352bf215546Sopenharmony_ci 353bf215546Sopenharmony_cistruct svga_shader 354bf215546Sopenharmony_ci{ 355bf215546Sopenharmony_ci enum pipe_shader_ir type; /* IR type */ 356bf215546Sopenharmony_ci enum pipe_shader_type stage; /* shader stage */ 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci struct svga_shader_info info; /* shader info */ 359bf215546Sopenharmony_ci 360bf215546Sopenharmony_ci /* TGSI */ 361bf215546Sopenharmony_ci const struct tgsi_token *tokens; 362bf215546Sopenharmony_ci struct svga_token_key token_key; /* token key for the token string */ 363bf215546Sopenharmony_ci struct tgsi_shader_info tgsi_info; 364bf215546Sopenharmony_ci 365bf215546Sopenharmony_ci /* List of shaders with tokens derived from the same token string */ 366bf215546Sopenharmony_ci struct svga_shader *next; 367bf215546Sopenharmony_ci struct svga_shader *parent; /* shader with the original token string */ 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci struct svga_stream_output *stream_output; 370bf215546Sopenharmony_ci 371bf215546Sopenharmony_ci /** Head of linked list of compiled variants */ 372bf215546Sopenharmony_ci struct svga_shader_variant *variants; 373bf215546Sopenharmony_ci 374bf215546Sopenharmony_ci /* Get dummy shader variant */ 375bf215546Sopenharmony_ci struct svga_shader_variant *(*get_dummy_shader)(struct svga_context *, 376bf215546Sopenharmony_ci struct svga_shader *, 377bf215546Sopenharmony_ci const struct svga_compile_key *); 378bf215546Sopenharmony_ci 379bf215546Sopenharmony_ci unsigned id; /**< for debugging only */ 380bf215546Sopenharmony_ci}; 381bf215546Sopenharmony_ci 382bf215546Sopenharmony_ci 383bf215546Sopenharmony_cistruct svga_fragment_shader 384bf215546Sopenharmony_ci{ 385bf215546Sopenharmony_ci struct svga_shader base; 386bf215546Sopenharmony_ci 387bf215546Sopenharmony_ci struct draw_fragment_shader *draw_shader; 388bf215546Sopenharmony_ci 389bf215546Sopenharmony_ci /** Mask of which generic varying variables are read by this shader */ 390bf215546Sopenharmony_ci uint64_t generic_inputs; 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_ci /** Table mapping original TGSI generic indexes to low integers */ 393bf215546Sopenharmony_ci int8_t generic_remap_table[MAX_GENERIC_VARYING]; 394bf215546Sopenharmony_ci}; 395bf215546Sopenharmony_ci 396bf215546Sopenharmony_ci 397bf215546Sopenharmony_cistruct svga_vertex_shader 398bf215546Sopenharmony_ci{ 399bf215546Sopenharmony_ci struct svga_shader base; 400bf215546Sopenharmony_ci 401bf215546Sopenharmony_ci struct draw_vertex_shader *draw_shader; 402bf215546Sopenharmony_ci 403bf215546Sopenharmony_ci /** Mask of which generic varying variables are written by this shader */ 404bf215546Sopenharmony_ci uint64_t generic_outputs; 405bf215546Sopenharmony_ci 406bf215546Sopenharmony_ci /** Generated geometry shader that goes with this vertex shader */ 407bf215546Sopenharmony_ci struct svga_geometry_shader *gs; 408bf215546Sopenharmony_ci}; 409bf215546Sopenharmony_ci 410bf215546Sopenharmony_ci 411bf215546Sopenharmony_cistruct svga_geometry_shader 412bf215546Sopenharmony_ci{ 413bf215546Sopenharmony_ci struct svga_shader base; 414bf215546Sopenharmony_ci 415bf215546Sopenharmony_ci struct draw_geometry_shader *draw_shader; 416bf215546Sopenharmony_ci 417bf215546Sopenharmony_ci /** Table mapping original TGSI generic indexes to low integers */ 418bf215546Sopenharmony_ci int8_t generic_remap_table[MAX_GENERIC_VARYING]; 419bf215546Sopenharmony_ci uint64_t generic_outputs; 420bf215546Sopenharmony_ci 421bf215546Sopenharmony_ci unsigned aa_point_coord_index; /* generic index for aa point coord */ 422bf215546Sopenharmony_ci 423bf215546Sopenharmony_ci unsigned wide_point:1; /* set if the shader emulates wide point */ 424bf215546Sopenharmony_ci}; 425bf215546Sopenharmony_ci 426bf215546Sopenharmony_ci 427bf215546Sopenharmony_cistruct svga_tcs_shader 428bf215546Sopenharmony_ci{ 429bf215546Sopenharmony_ci struct svga_shader base; 430bf215546Sopenharmony_ci 431bf215546Sopenharmony_ci /** Mask of which generic varying variables are written by this shader */ 432bf215546Sopenharmony_ci uint64_t generic_outputs; 433bf215546Sopenharmony_ci}; 434bf215546Sopenharmony_ci 435bf215546Sopenharmony_ci 436bf215546Sopenharmony_cistruct svga_tes_shader 437bf215546Sopenharmony_ci{ 438bf215546Sopenharmony_ci struct svga_shader base; 439bf215546Sopenharmony_ci 440bf215546Sopenharmony_ci /** Mask of which generic varying variables are written by this shader */ 441bf215546Sopenharmony_ci uint64_t generic_inputs; 442bf215546Sopenharmony_ci}; 443bf215546Sopenharmony_ci 444bf215546Sopenharmony_ci 445bf215546Sopenharmony_cistruct svga_compute_shader 446bf215546Sopenharmony_ci{ 447bf215546Sopenharmony_ci struct svga_shader base; 448bf215546Sopenharmony_ci unsigned shared_mem_size; 449bf215546Sopenharmony_ci}; 450bf215546Sopenharmony_ci 451bf215546Sopenharmony_ci 452bf215546Sopenharmony_cistatic inline boolean 453bf215546Sopenharmony_cisvga_compile_keys_equal(const struct svga_compile_key *a, 454bf215546Sopenharmony_ci const struct svga_compile_key *b) 455bf215546Sopenharmony_ci{ 456bf215546Sopenharmony_ci unsigned key_size = sizeof(*a); 457bf215546Sopenharmony_ci 458bf215546Sopenharmony_ci return memcmp(a, b, key_size) == 0; 459bf215546Sopenharmony_ci} 460bf215546Sopenharmony_ci 461bf215546Sopenharmony_ci 462bf215546Sopenharmony_ciuint64_t 463bf215546Sopenharmony_cisvga_get_generic_inputs_mask(const struct tgsi_shader_info *info); 464bf215546Sopenharmony_ci 465bf215546Sopenharmony_ciuint64_t 466bf215546Sopenharmony_cisvga_get_generic_outputs_mask(const struct tgsi_shader_info *info); 467bf215546Sopenharmony_ci 468bf215546Sopenharmony_civoid 469bf215546Sopenharmony_cisvga_remap_generics(uint64_t generics_mask, 470bf215546Sopenharmony_ci int8_t remap_table[MAX_GENERIC_VARYING]); 471bf215546Sopenharmony_ci 472bf215546Sopenharmony_ciint 473bf215546Sopenharmony_cisvga_remap_generic_index(int8_t remap_table[MAX_GENERIC_VARYING], 474bf215546Sopenharmony_ci int generic_index); 475bf215546Sopenharmony_ci 476bf215546Sopenharmony_civoid 477bf215546Sopenharmony_cisvga_init_shader_key_common(const struct svga_context *svga, 478bf215546Sopenharmony_ci enum pipe_shader_type shader_type, 479bf215546Sopenharmony_ci const struct svga_shader *shader, 480bf215546Sopenharmony_ci struct svga_compile_key *key); 481bf215546Sopenharmony_ci 482bf215546Sopenharmony_cistruct svga_shader_variant * 483bf215546Sopenharmony_cisvga_search_shader_key(const struct svga_shader *shader, 484bf215546Sopenharmony_ci const struct svga_compile_key *key); 485bf215546Sopenharmony_ci 486bf215546Sopenharmony_cistruct svga_shader * 487bf215546Sopenharmony_cisvga_search_shader_token_key(struct svga_shader *shader, 488bf215546Sopenharmony_ci const struct svga_token_key *key); 489bf215546Sopenharmony_ci 490bf215546Sopenharmony_cistruct svga_shader * 491bf215546Sopenharmony_cisvga_create_shader(struct pipe_context *pipe, 492bf215546Sopenharmony_ci const struct pipe_shader_state *templ, 493bf215546Sopenharmony_ci enum pipe_shader_type stage, 494bf215546Sopenharmony_ci unsigned len); 495bf215546Sopenharmony_ci 496bf215546Sopenharmony_cienum pipe_error 497bf215546Sopenharmony_cisvga_compile_shader(struct svga_context *svga, 498bf215546Sopenharmony_ci struct svga_shader *shader, 499bf215546Sopenharmony_ci const struct svga_compile_key *key, 500bf215546Sopenharmony_ci struct svga_shader_variant **out_variant); 501bf215546Sopenharmony_ci 502bf215546Sopenharmony_cienum pipe_error 503bf215546Sopenharmony_cisvga_define_shader(struct svga_context *svga, 504bf215546Sopenharmony_ci struct svga_shader_variant *variant); 505bf215546Sopenharmony_ci 506bf215546Sopenharmony_cienum pipe_error 507bf215546Sopenharmony_cisvga_set_shader(struct svga_context *svga, 508bf215546Sopenharmony_ci SVGA3dShaderType type, 509bf215546Sopenharmony_ci struct svga_shader_variant *variant); 510bf215546Sopenharmony_ci 511bf215546Sopenharmony_cistruct svga_shader_variant * 512bf215546Sopenharmony_cisvga_new_shader_variant(struct svga_context *svga, enum pipe_shader_type type); 513bf215546Sopenharmony_ci 514bf215546Sopenharmony_civoid 515bf215546Sopenharmony_cisvga_destroy_shader_variant(struct svga_context *svga, 516bf215546Sopenharmony_ci struct svga_shader_variant *variant); 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_cienum pipe_error 519bf215546Sopenharmony_cisvga_rebind_shaders(struct svga_context *svga); 520bf215546Sopenharmony_ci 521bf215546Sopenharmony_ci/** 522bf215546Sopenharmony_ci * Check if a shader's bytecode exceeds the device limits. 523bf215546Sopenharmony_ci */ 524bf215546Sopenharmony_cistatic inline boolean 525bf215546Sopenharmony_cisvga_shader_too_large(const struct svga_context *svga, 526bf215546Sopenharmony_ci const struct svga_shader_variant *variant) 527bf215546Sopenharmony_ci{ 528bf215546Sopenharmony_ci if (svga_have_gb_objects(svga)) { 529bf215546Sopenharmony_ci return FALSE; 530bf215546Sopenharmony_ci } 531bf215546Sopenharmony_ci 532bf215546Sopenharmony_ci if (variant->nr_tokens * sizeof(variant->tokens[0]) 533bf215546Sopenharmony_ci + sizeof(SVGA3dCmdDefineShader) + sizeof(SVGA3dCmdHeader) 534bf215546Sopenharmony_ci < SVGA_CB_MAX_COMMAND_SIZE) { 535bf215546Sopenharmony_ci return FALSE; 536bf215546Sopenharmony_ci } 537bf215546Sopenharmony_ci 538bf215546Sopenharmony_ci return TRUE; 539bf215546Sopenharmony_ci} 540bf215546Sopenharmony_ci 541bf215546Sopenharmony_ci 542bf215546Sopenharmony_ci/** 543bf215546Sopenharmony_ci * Convert from PIPE_SHADER_* to SVGA3D_SHADERTYPE_* 544bf215546Sopenharmony_ci */ 545bf215546Sopenharmony_cistatic inline SVGA3dShaderType 546bf215546Sopenharmony_cisvga_shader_type(enum pipe_shader_type shader) 547bf215546Sopenharmony_ci{ 548bf215546Sopenharmony_ci switch (shader) { 549bf215546Sopenharmony_ci case PIPE_SHADER_VERTEX: 550bf215546Sopenharmony_ci return SVGA3D_SHADERTYPE_VS; 551bf215546Sopenharmony_ci case PIPE_SHADER_GEOMETRY: 552bf215546Sopenharmony_ci return SVGA3D_SHADERTYPE_GS; 553bf215546Sopenharmony_ci case PIPE_SHADER_FRAGMENT: 554bf215546Sopenharmony_ci return SVGA3D_SHADERTYPE_PS; 555bf215546Sopenharmony_ci case PIPE_SHADER_TESS_CTRL: 556bf215546Sopenharmony_ci return SVGA3D_SHADERTYPE_HS; 557bf215546Sopenharmony_ci case PIPE_SHADER_TESS_EVAL: 558bf215546Sopenharmony_ci return SVGA3D_SHADERTYPE_DS; 559bf215546Sopenharmony_ci case PIPE_SHADER_COMPUTE: 560bf215546Sopenharmony_ci return SVGA3D_SHADERTYPE_CS; 561bf215546Sopenharmony_ci default: 562bf215546Sopenharmony_ci assert(!"Invalid shader type"); 563bf215546Sopenharmony_ci return SVGA3D_SHADERTYPE_VS; 564bf215546Sopenharmony_ci } 565bf215546Sopenharmony_ci} 566bf215546Sopenharmony_ci 567bf215546Sopenharmony_ci 568bf215546Sopenharmony_ci/** Does the current VS have stream output? */ 569bf215546Sopenharmony_cistatic inline boolean 570bf215546Sopenharmony_cisvga_have_vs_streamout(const struct svga_context *svga) 571bf215546Sopenharmony_ci{ 572bf215546Sopenharmony_ci return svga->curr.vs != NULL && svga->curr.vs->base.stream_output != NULL; 573bf215546Sopenharmony_ci} 574bf215546Sopenharmony_ci 575bf215546Sopenharmony_ci 576bf215546Sopenharmony_ci/** Does the current GS have stream output? */ 577bf215546Sopenharmony_cistatic inline boolean 578bf215546Sopenharmony_cisvga_have_gs_streamout(const struct svga_context *svga) 579bf215546Sopenharmony_ci{ 580bf215546Sopenharmony_ci return svga->curr.gs != NULL && svga->curr.gs->base.stream_output != NULL; 581bf215546Sopenharmony_ci} 582bf215546Sopenharmony_ci 583bf215546Sopenharmony_ci 584bf215546Sopenharmony_cistatic inline struct svga_fs_variant * 585bf215546Sopenharmony_cisvga_fs_variant(struct svga_shader_variant *variant) 586bf215546Sopenharmony_ci{ 587bf215546Sopenharmony_ci assert(!variant || variant->type == SVGA3D_SHADERTYPE_PS); 588bf215546Sopenharmony_ci return (struct svga_fs_variant *)variant; 589bf215546Sopenharmony_ci} 590bf215546Sopenharmony_ci 591bf215546Sopenharmony_ci 592bf215546Sopenharmony_cistatic inline struct svga_tes_variant * 593bf215546Sopenharmony_cisvga_tes_variant(struct svga_shader_variant *variant) 594bf215546Sopenharmony_ci{ 595bf215546Sopenharmony_ci assert(!variant || variant->type == SVGA3D_SHADERTYPE_DS); 596bf215546Sopenharmony_ci return (struct svga_tes_variant *)variant; 597bf215546Sopenharmony_ci} 598bf215546Sopenharmony_ci 599bf215546Sopenharmony_ci 600bf215546Sopenharmony_cistatic inline struct svga_cs_variant * 601bf215546Sopenharmony_cisvga_cs_variant(struct svga_shader_variant *variant) 602bf215546Sopenharmony_ci{ 603bf215546Sopenharmony_ci assert(!variant || variant->type == SVGA3D_SHADERTYPE_CS); 604bf215546Sopenharmony_ci return (struct svga_cs_variant *)variant; 605bf215546Sopenharmony_ci} 606bf215546Sopenharmony_ci 607bf215546Sopenharmony_ci 608bf215546Sopenharmony_ci/* Returns TRUE if we are currently using flat shading. 609bf215546Sopenharmony_ci */ 610bf215546Sopenharmony_cistatic inline boolean 611bf215546Sopenharmony_cisvga_is_using_flat_shading(const struct svga_context *svga) 612bf215546Sopenharmony_ci{ 613bf215546Sopenharmony_ci return 614bf215546Sopenharmony_ci svga->state.hw_draw.fs ? 615bf215546Sopenharmony_ci svga_fs_variant(svga->state.hw_draw.fs)->uses_flat_interp : FALSE; 616bf215546Sopenharmony_ci} 617bf215546Sopenharmony_ci 618bf215546Sopenharmony_cistruct svga_shader_variant * 619bf215546Sopenharmony_cisvga_get_compiled_dummy_vertex_shader(struct svga_context *svga, 620bf215546Sopenharmony_ci struct svga_shader *shader, 621bf215546Sopenharmony_ci const struct svga_compile_key *key); 622bf215546Sopenharmony_ci 623bf215546Sopenharmony_ci 624bf215546Sopenharmony_cistruct svga_shader_variant * 625bf215546Sopenharmony_cisvga_get_compiled_dummy_fragment_shader(struct svga_context *svga, 626bf215546Sopenharmony_ci struct svga_shader *shader, 627bf215546Sopenharmony_ci const struct svga_compile_key *key); 628bf215546Sopenharmony_ci 629bf215546Sopenharmony_cistruct svga_shader_variant * 630bf215546Sopenharmony_cisvga_get_compiled_dummy_geometry_shader(struct svga_context *svga, 631bf215546Sopenharmony_ci struct svga_shader *shader, 632bf215546Sopenharmony_ci const struct svga_compile_key *key); 633bf215546Sopenharmony_ci 634bf215546Sopenharmony_ci#endif /* SVGA_SHADER_H */ 635