1af69d88dSmrg/********************************************************** 2af69d88dSmrg * Copyright 2008-2012 VMware, Inc. All rights reserved. 3af69d88dSmrg * 4af69d88dSmrg * Permission is hereby granted, free of charge, to any person 5af69d88dSmrg * obtaining a copy of this software and associated documentation 6af69d88dSmrg * files (the "Software"), to deal in the Software without 7af69d88dSmrg * restriction, including without limitation the rights to use, copy, 8af69d88dSmrg * modify, merge, publish, distribute, sublicense, and/or sell copies 9af69d88dSmrg * of the Software, and to permit persons to whom the Software is 10af69d88dSmrg * furnished to do so, subject to the following conditions: 11af69d88dSmrg * 12af69d88dSmrg * The above copyright notice and this permission notice shall be 13af69d88dSmrg * included in all copies or substantial portions of the Software. 14af69d88dSmrg * 15af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16af69d88dSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17af69d88dSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18af69d88dSmrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19af69d88dSmrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20af69d88dSmrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21af69d88dSmrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22af69d88dSmrg * SOFTWARE. 23af69d88dSmrg * 24af69d88dSmrg **********************************************************/ 25af69d88dSmrg 26af69d88dSmrg#ifndef SVGA_SHADER_H 27af69d88dSmrg#define SVGA_SHADER_H 28af69d88dSmrg 29af69d88dSmrg#include "svga3d_reg.h" 3001e04c3fSmrg#include "svga_context.h" 3101e04c3fSmrg#include "svga_streamout.h" 32af69d88dSmrg 3301e04c3fSmrg 3401e04c3fSmrg/** 3501e04c3fSmrg * We use a 64-bit mask to keep track of the generic indexes. 3601e04c3fSmrg * This is the maximum semantic index for a TGSI GENERIC[i] register. 3701e04c3fSmrg */ 3801e04c3fSmrg#define MAX_GENERIC_VARYING 64 3901e04c3fSmrg 4001e04c3fSmrg 4101e04c3fSmrgstruct svga_context; 4201e04c3fSmrg 4301e04c3fSmrg 4401e04c3fSmrgstruct svga_compile_key 4501e04c3fSmrg{ 4601e04c3fSmrg /* vertex shader only */ 4701e04c3fSmrg struct { 4801e04c3fSmrg uint64_t fs_generic_inputs; 4901e04c3fSmrg unsigned passthrough:1; 5001e04c3fSmrg unsigned need_prescale:1; 5101e04c3fSmrg unsigned undo_viewport:1; 5201e04c3fSmrg unsigned allow_psiz:1; 537ec681f3Smrg unsigned need_vertex_id_bias:1; 547ec681f3Smrg 5501e04c3fSmrg /** The following are all 32-bit bitmasks (per VS input) */ 5601e04c3fSmrg unsigned adjust_attrib_range; 5701e04c3fSmrg unsigned attrib_is_pure_int; 5801e04c3fSmrg unsigned adjust_attrib_w_1; 5901e04c3fSmrg unsigned adjust_attrib_itof; 6001e04c3fSmrg unsigned adjust_attrib_utof; 6101e04c3fSmrg unsigned attrib_is_bgra; 6201e04c3fSmrg unsigned attrib_puint_to_snorm; 6301e04c3fSmrg unsigned attrib_puint_to_uscaled; 6401e04c3fSmrg unsigned attrib_puint_to_sscaled; 6501e04c3fSmrg } vs; 6601e04c3fSmrg 6701e04c3fSmrg /* geometry shader only */ 6801e04c3fSmrg struct { 6901e04c3fSmrg uint64_t vs_generic_outputs; 7001e04c3fSmrg unsigned need_prescale:1; 7101e04c3fSmrg unsigned writes_psize:1; 7201e04c3fSmrg unsigned wide_point:1; 737ec681f3Smrg unsigned writes_viewport_index:1; 747ec681f3Smrg unsigned num_prescale:5; 7501e04c3fSmrg } gs; 7601e04c3fSmrg 7701e04c3fSmrg /* fragment shader only */ 7801e04c3fSmrg struct { 7901e04c3fSmrg uint64_t vs_generic_outputs; 8001e04c3fSmrg uint64_t gs_generic_outputs; 8101e04c3fSmrg unsigned light_twoside:1; 8201e04c3fSmrg unsigned front_ccw:1; 8301e04c3fSmrg unsigned white_fragments:1; 8401e04c3fSmrg unsigned alpha_to_one:1; 8501e04c3fSmrg unsigned flatshade:1; 8601e04c3fSmrg unsigned pstipple:1; 8701e04c3fSmrg unsigned alpha_func:4; /**< SVGA3D_CMP_x */ 8801e04c3fSmrg unsigned write_color0_to_n_cbufs:4; 8901e04c3fSmrg unsigned aa_point:1; 907ec681f3Smrg unsigned layer_to_zero:1; 9101e04c3fSmrg int aa_point_coord_index; 9201e04c3fSmrg float alpha_ref; 9301e04c3fSmrg } fs; 9401e04c3fSmrg 957ec681f3Smrg /* tessellation control shader */ 967ec681f3Smrg struct { 977ec681f3Smrg unsigned vertices_per_patch:8; 987ec681f3Smrg unsigned vertices_out:8; 997ec681f3Smrg enum pipe_prim_type prim_mode:8; 1007ec681f3Smrg enum pipe_tess_spacing spacing:3; 1017ec681f3Smrg unsigned vertices_order_cw:1; 1027ec681f3Smrg unsigned point_mode:1; 1037ec681f3Smrg unsigned passthrough:1; 1047ec681f3Smrg } tcs; 1057ec681f3Smrg 1067ec681f3Smrg /* tessellation evaluation shader */ 1077ec681f3Smrg struct { 1087ec681f3Smrg unsigned vertices_per_patch:8; 1097ec681f3Smrg unsigned tessfactor_index:8; 1107ec681f3Smrg unsigned need_prescale:1; 1117ec681f3Smrg unsigned need_tessouter:1; 1127ec681f3Smrg unsigned need_tessinner:1; 1137ec681f3Smrg } tes; 1147ec681f3Smrg 1157ec681f3Smrg /* compute shader */ 1167ec681f3Smrg struct { 1177ec681f3Smrg unsigned grid_size[3]; 1187ec681f3Smrg } cs; 1197ec681f3Smrg 12001e04c3fSmrg /* any shader type */ 12101e04c3fSmrg int8_t generic_remap_table[MAX_GENERIC_VARYING]; 12201e04c3fSmrg unsigned num_textures:8; 12301e04c3fSmrg unsigned num_unnormalized_coords:8; 12401e04c3fSmrg unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES; 1257ec681f3Smrg unsigned last_vertex_stage:1; 1267ec681f3Smrg unsigned clamp_vertex_color:1; 12701e04c3fSmrg unsigned sprite_origin_lower_left:1; 12801e04c3fSmrg uint16_t sprite_coord_enable; 12901e04c3fSmrg struct { 13001e04c3fSmrg unsigned compare_mode:1; 13101e04c3fSmrg unsigned compare_func:3; 13201e04c3fSmrg unsigned unnormalized:1; 13301e04c3fSmrg unsigned texel_bias:1; 13401e04c3fSmrg unsigned width_height_idx:5; /**< texture unit */ 13501e04c3fSmrg unsigned is_array:1; 13601e04c3fSmrg unsigned swizzle_r:3; 13701e04c3fSmrg unsigned swizzle_g:3; 13801e04c3fSmrg unsigned swizzle_b:3; 13901e04c3fSmrg unsigned swizzle_a:3; 14001e04c3fSmrg unsigned num_samples:5; /**< Up to 16 samples */ 1417ec681f3Smrg unsigned target:4; 1427ec681f3Smrg unsigned sampler_return_type:4; 1437ec681f3Smrg unsigned sampler_view:1; 14401e04c3fSmrg } tex[PIPE_MAX_SAMPLERS]; 14501e04c3fSmrg /* Note: svga_compile_keys_equal() depends on the variable-size 14601e04c3fSmrg * tex[] array being at the end of this structure. 14701e04c3fSmrg */ 14801e04c3fSmrg}; 14901e04c3fSmrg 15001e04c3fSmrg/* A key for a variant of token string of a shader */ 15101e04c3fSmrgstruct svga_token_key { 15201e04c3fSmrg struct { 15301e04c3fSmrg unsigned sprite_coord_enable:24; 15401e04c3fSmrg unsigned sprite_origin_upper_left:1; 15501e04c3fSmrg unsigned point_pos_stream_out:1; 15601e04c3fSmrg unsigned writes_psize:1; 15701e04c3fSmrg unsigned aa_point:1; 15801e04c3fSmrg } gs; 1597ec681f3Smrg struct { 1607ec681f3Smrg unsigned write_position:1; 1617ec681f3Smrg } vs; 1627ec681f3Smrg unsigned dynamic_indexing:1; 16301e04c3fSmrg}; 16401e04c3fSmrg 16501e04c3fSmrg/** 16601e04c3fSmrg * A single TGSI shader may be compiled into different variants of 16701e04c3fSmrg * SVGA3D shaders depending on the compile key. Each user shader 16801e04c3fSmrg * will have a linked list of these variants. 16901e04c3fSmrg */ 17001e04c3fSmrgstruct svga_shader_variant 17101e04c3fSmrg{ 17201e04c3fSmrg const struct svga_shader *shader; 17301e04c3fSmrg 17401e04c3fSmrg /** Parameters used to generate this variant */ 17501e04c3fSmrg struct svga_compile_key key; 17601e04c3fSmrg 1779f464c52Smaya /* svga shader type */ 1789f464c52Smaya SVGA3dShaderType type; 1799f464c52Smaya 18001e04c3fSmrg /* Compiled shader tokens: 18101e04c3fSmrg */ 18201e04c3fSmrg const unsigned *tokens; 18301e04c3fSmrg unsigned nr_tokens; 18401e04c3fSmrg 1857ec681f3Smrg /* shader signature */ 1867ec681f3Smrg unsigned signatureLen; 1877ec681f3Smrg SVGA3dDXShaderSignatureHeader *signature; 1887ec681f3Smrg 18901e04c3fSmrg /** Per-context shader identifier used with SVGA_3D_CMD_SHADER_DEFINE, 19001e04c3fSmrg * SVGA_3D_CMD_SET_SHADER and SVGA_3D_CMD_SHADER_DESTROY. 19101e04c3fSmrg */ 19201e04c3fSmrg unsigned id; 19301e04c3fSmrg 19401e04c3fSmrg /** Start of extra constants (number of float[4] constants) */ 19501e04c3fSmrg unsigned extra_const_start; 19601e04c3fSmrg 19701e04c3fSmrg /* GB object buffer containing the bytecode */ 19801e04c3fSmrg struct svga_winsys_gb_shader *gb_shader; 19901e04c3fSmrg 2007ec681f3Smrg /** Next variant */ 2017ec681f3Smrg struct svga_shader_variant *next; 2027ec681f3Smrg}; 2037ec681f3Smrg 2047ec681f3Smrg 2057ec681f3Smrg/** 2067ec681f3Smrg * Shader variant for fragment shader 2077ec681f3Smrg */ 2087ec681f3Smrgstruct svga_fs_variant 2097ec681f3Smrg{ 2107ec681f3Smrg struct svga_shader_variant base; 2117ec681f3Smrg 21201e04c3fSmrg boolean uses_flat_interp; /** TRUE if flat interpolation qualifier is 21301e04c3fSmrg * applied to any of the varyings. 21401e04c3fSmrg */ 21501e04c3fSmrg 21601e04c3fSmrg /** Is the color output just a constant value? (fragment shader only) */ 21701e04c3fSmrg boolean constant_color_output; 21801e04c3fSmrg 21901e04c3fSmrg /** Bitmask indicating which texture units are doing the shadow 22001e04c3fSmrg * comparison test in the shader rather than the sampler state. 22101e04c3fSmrg */ 22201e04c3fSmrg unsigned fs_shadow_compare_units; 22301e04c3fSmrg 22401e04c3fSmrg /** For FS-based polygon stipple */ 22501e04c3fSmrg unsigned pstipple_sampler_unit; 2267ec681f3Smrg}; 22701e04c3fSmrg 2287ec681f3Smrg 2297ec681f3Smrg/** 2307ec681f3Smrg * Shader variant for geometry shader 2317ec681f3Smrg */ 2327ec681f3Smrgstruct svga_gs_variant 2337ec681f3Smrg{ 2347ec681f3Smrg struct svga_shader_variant base; 2357ec681f3Smrg}; 2367ec681f3Smrg 2377ec681f3Smrg 2387ec681f3Smrg/** 2397ec681f3Smrg * Shader variant for vertex shader 2407ec681f3Smrg */ 2417ec681f3Smrgstruct svga_vs_variant 2427ec681f3Smrg{ 2437ec681f3Smrg struct svga_shader_variant base; 2447ec681f3Smrg}; 2457ec681f3Smrg 2467ec681f3Smrg 2477ec681f3Smrg/** 2487ec681f3Smrg * Shader variant for tessellation evaluation shader 2497ec681f3Smrg */ 2507ec681f3Smrgstruct svga_tes_variant 2517ec681f3Smrg{ 2527ec681f3Smrg struct svga_shader_variant base; 2537ec681f3Smrg 2547ec681f3Smrg enum pipe_prim_type prim_mode:8; 2557ec681f3Smrg enum pipe_tess_spacing spacing:3; 2567ec681f3Smrg unsigned vertices_order_cw:1; 2577ec681f3Smrg unsigned point_mode:1; 2587ec681f3Smrg}; 2597ec681f3Smrg 2607ec681f3Smrg 2617ec681f3Smrg/** 2627ec681f3Smrg * Shader variant for tessellation control shader 2637ec681f3Smrg */ 2647ec681f3Smrgstruct svga_tcs_variant 2657ec681f3Smrg{ 2667ec681f3Smrg struct svga_shader_variant base; 2677ec681f3Smrg}; 2687ec681f3Smrg 2697ec681f3Smrg 2707ec681f3Smrg/** 2717ec681f3Smrg * Shader variant for compute shader 2727ec681f3Smrg */ 2737ec681f3Smrgstruct svga_cs_variant 2747ec681f3Smrg{ 2757ec681f3Smrg struct svga_shader_variant base; 27601e04c3fSmrg}; 27701e04c3fSmrg 27801e04c3fSmrg 27901e04c3fSmrgstruct svga_shader 28001e04c3fSmrg{ 28101e04c3fSmrg const struct tgsi_token *tokens; 28201e04c3fSmrg struct svga_token_key token_key; /* token key for the token string */ 28301e04c3fSmrg struct tgsi_shader_info info; 28401e04c3fSmrg 28501e04c3fSmrg /* List of shaders with tokens derived from the same token string */ 28601e04c3fSmrg struct svga_shader *next; 28701e04c3fSmrg struct svga_shader *parent; /* shader with the original token string */ 28801e04c3fSmrg 28901e04c3fSmrg struct svga_stream_output *stream_output; 29001e04c3fSmrg 29101e04c3fSmrg /** Head of linked list of compiled variants */ 29201e04c3fSmrg struct svga_shader_variant *variants; 29301e04c3fSmrg 29401e04c3fSmrg unsigned id; /**< for debugging only */ 29501e04c3fSmrg}; 29601e04c3fSmrg 29701e04c3fSmrg 29801e04c3fSmrgstruct svga_fragment_shader 29901e04c3fSmrg{ 30001e04c3fSmrg struct svga_shader base; 30101e04c3fSmrg 30201e04c3fSmrg struct draw_fragment_shader *draw_shader; 30301e04c3fSmrg 30401e04c3fSmrg /** Mask of which generic varying variables are read by this shader */ 30501e04c3fSmrg uint64_t generic_inputs; 30601e04c3fSmrg 30701e04c3fSmrg /** Table mapping original TGSI generic indexes to low integers */ 30801e04c3fSmrg int8_t generic_remap_table[MAX_GENERIC_VARYING]; 30901e04c3fSmrg}; 31001e04c3fSmrg 31101e04c3fSmrg 31201e04c3fSmrgstruct svga_vertex_shader 31301e04c3fSmrg{ 31401e04c3fSmrg struct svga_shader base; 31501e04c3fSmrg 31601e04c3fSmrg struct draw_vertex_shader *draw_shader; 31701e04c3fSmrg 31801e04c3fSmrg /** Mask of which generic varying variables are written by this shader */ 31901e04c3fSmrg uint64_t generic_outputs; 32001e04c3fSmrg 32101e04c3fSmrg /** Generated geometry shader that goes with this vertex shader */ 32201e04c3fSmrg struct svga_geometry_shader *gs; 32301e04c3fSmrg}; 32401e04c3fSmrg 32501e04c3fSmrg 32601e04c3fSmrgstruct svga_geometry_shader 32701e04c3fSmrg{ 32801e04c3fSmrg struct svga_shader base; 32901e04c3fSmrg 33001e04c3fSmrg struct draw_geometry_shader *draw_shader; 33101e04c3fSmrg 33201e04c3fSmrg /** Table mapping original TGSI generic indexes to low integers */ 33301e04c3fSmrg int8_t generic_remap_table[MAX_GENERIC_VARYING]; 33401e04c3fSmrg uint64_t generic_outputs; 33501e04c3fSmrg 33601e04c3fSmrg unsigned aa_point_coord_index; /* generic index for aa point coord */ 33701e04c3fSmrg 33801e04c3fSmrg unsigned wide_point:1; /* set if the shader emulates wide point */ 33901e04c3fSmrg}; 34001e04c3fSmrg 34101e04c3fSmrg 3427ec681f3Smrgstruct svga_tcs_shader 3437ec681f3Smrg{ 3447ec681f3Smrg struct svga_shader base; 3457ec681f3Smrg 3467ec681f3Smrg /** Mask of which generic varying variables are written by this shader */ 3477ec681f3Smrg uint64_t generic_outputs; 3487ec681f3Smrg}; 3497ec681f3Smrg 3507ec681f3Smrg 3517ec681f3Smrgstruct svga_tes_shader 3527ec681f3Smrg{ 3537ec681f3Smrg struct svga_shader base; 3547ec681f3Smrg 3557ec681f3Smrg /** Mask of which generic varying variables are written by this shader */ 3567ec681f3Smrg uint64_t generic_inputs; 3577ec681f3Smrg}; 3587ec681f3Smrg 3597ec681f3Smrg 3607ec681f3Smrgstruct svga_compute_shader 3617ec681f3Smrg{ 3627ec681f3Smrg struct svga_shader base; 3637ec681f3Smrg}; 3647ec681f3Smrg 3657ec681f3Smrg 36601e04c3fSmrgstatic inline boolean 36701e04c3fSmrgsvga_compile_keys_equal(const struct svga_compile_key *a, 36801e04c3fSmrg const struct svga_compile_key *b) 36901e04c3fSmrg{ 37001e04c3fSmrg unsigned key_size = 37101e04c3fSmrg (const char *) &a->tex[a->num_textures] - (const char *) a; 37201e04c3fSmrg 37301e04c3fSmrg return memcmp(a, b, key_size) == 0; 37401e04c3fSmrg} 37501e04c3fSmrg 37601e04c3fSmrg 37701e04c3fSmrguint64_t 37801e04c3fSmrgsvga_get_generic_inputs_mask(const struct tgsi_shader_info *info); 37901e04c3fSmrg 38001e04c3fSmrguint64_t 38101e04c3fSmrgsvga_get_generic_outputs_mask(const struct tgsi_shader_info *info); 38201e04c3fSmrg 38301e04c3fSmrgvoid 38401e04c3fSmrgsvga_remap_generics(uint64_t generics_mask, 38501e04c3fSmrg int8_t remap_table[MAX_GENERIC_VARYING]); 38601e04c3fSmrg 38701e04c3fSmrgint 38801e04c3fSmrgsvga_remap_generic_index(int8_t remap_table[MAX_GENERIC_VARYING], 38901e04c3fSmrg int generic_index); 39001e04c3fSmrg 39101e04c3fSmrgvoid 39201e04c3fSmrgsvga_init_shader_key_common(const struct svga_context *svga, 3937ec681f3Smrg enum pipe_shader_type shader_type, 3947ec681f3Smrg const struct svga_shader *shader, 39501e04c3fSmrg struct svga_compile_key *key); 39601e04c3fSmrg 39701e04c3fSmrgstruct svga_shader_variant * 39801e04c3fSmrgsvga_search_shader_key(const struct svga_shader *shader, 39901e04c3fSmrg const struct svga_compile_key *key); 40001e04c3fSmrg 40101e04c3fSmrgstruct svga_shader * 40201e04c3fSmrgsvga_search_shader_token_key(struct svga_shader *shader, 40301e04c3fSmrg const struct svga_token_key *key); 404af69d88dSmrg 405af69d88dSmrgenum pipe_error 406af69d88dSmrgsvga_define_shader(struct svga_context *svga, 407af69d88dSmrg struct svga_shader_variant *variant); 408af69d88dSmrg 409af69d88dSmrgenum pipe_error 41001e04c3fSmrgsvga_set_shader(struct svga_context *svga, 41101e04c3fSmrg SVGA3dShaderType type, 41201e04c3fSmrg struct svga_shader_variant *variant); 41301e04c3fSmrg 41401e04c3fSmrgstruct svga_shader_variant * 4159f464c52Smayasvga_new_shader_variant(struct svga_context *svga, enum pipe_shader_type type); 41601e04c3fSmrg 41701e04c3fSmrgvoid 418af69d88dSmrgsvga_destroy_shader_variant(struct svga_context *svga, 419af69d88dSmrg struct svga_shader_variant *variant); 420af69d88dSmrg 42101e04c3fSmrgenum pipe_error 42201e04c3fSmrgsvga_rebind_shaders(struct svga_context *svga); 423af69d88dSmrg 424af69d88dSmrg/** 425af69d88dSmrg * Check if a shader's bytecode exceeds the device limits. 426af69d88dSmrg */ 42701e04c3fSmrgstatic inline boolean 428af69d88dSmrgsvga_shader_too_large(const struct svga_context *svga, 429af69d88dSmrg const struct svga_shader_variant *variant) 430af69d88dSmrg{ 431af69d88dSmrg if (svga_have_gb_objects(svga)) { 432af69d88dSmrg return FALSE; 433af69d88dSmrg } 434af69d88dSmrg 435af69d88dSmrg if (variant->nr_tokens * sizeof(variant->tokens[0]) 436af69d88dSmrg + sizeof(SVGA3dCmdDefineShader) + sizeof(SVGA3dCmdHeader) 437af69d88dSmrg < SVGA_CB_MAX_COMMAND_SIZE) { 438af69d88dSmrg return FALSE; 439af69d88dSmrg } 440af69d88dSmrg 441af69d88dSmrg return TRUE; 442af69d88dSmrg} 443af69d88dSmrg 444af69d88dSmrg 44501e04c3fSmrg/** 44601e04c3fSmrg * Convert from PIPE_SHADER_* to SVGA3D_SHADERTYPE_* 44701e04c3fSmrg */ 44801e04c3fSmrgstatic inline SVGA3dShaderType 44901e04c3fSmrgsvga_shader_type(enum pipe_shader_type shader) 45001e04c3fSmrg{ 45101e04c3fSmrg switch (shader) { 45201e04c3fSmrg case PIPE_SHADER_VERTEX: 45301e04c3fSmrg return SVGA3D_SHADERTYPE_VS; 45401e04c3fSmrg case PIPE_SHADER_GEOMETRY: 45501e04c3fSmrg return SVGA3D_SHADERTYPE_GS; 45601e04c3fSmrg case PIPE_SHADER_FRAGMENT: 45701e04c3fSmrg return SVGA3D_SHADERTYPE_PS; 4587ec681f3Smrg case PIPE_SHADER_TESS_CTRL: 4597ec681f3Smrg return SVGA3D_SHADERTYPE_HS; 4607ec681f3Smrg case PIPE_SHADER_TESS_EVAL: 4617ec681f3Smrg return SVGA3D_SHADERTYPE_DS; 4627ec681f3Smrg case PIPE_SHADER_COMPUTE: 4637ec681f3Smrg return SVGA3D_SHADERTYPE_CS; 46401e04c3fSmrg default: 46501e04c3fSmrg assert(!"Invalid shader type"); 46601e04c3fSmrg return SVGA3D_SHADERTYPE_VS; 46701e04c3fSmrg } 46801e04c3fSmrg} 46901e04c3fSmrg 47001e04c3fSmrg 47101e04c3fSmrg/** Does the current VS have stream output? */ 47201e04c3fSmrgstatic inline boolean 47301e04c3fSmrgsvga_have_vs_streamout(const struct svga_context *svga) 47401e04c3fSmrg{ 47501e04c3fSmrg return svga->curr.vs != NULL && svga->curr.vs->base.stream_output != NULL; 47601e04c3fSmrg} 47701e04c3fSmrg 47801e04c3fSmrg 47901e04c3fSmrg/** Does the current GS have stream output? */ 48001e04c3fSmrgstatic inline boolean 48101e04c3fSmrgsvga_have_gs_streamout(const struct svga_context *svga) 48201e04c3fSmrg{ 48301e04c3fSmrg return svga->curr.gs != NULL && svga->curr.gs->base.stream_output != NULL; 48401e04c3fSmrg} 48501e04c3fSmrg 48601e04c3fSmrg 4877ec681f3Smrgstatic inline struct svga_fs_variant * 4887ec681f3Smrgsvga_fs_variant(struct svga_shader_variant *variant) 4897ec681f3Smrg{ 4907ec681f3Smrg assert(!variant || variant->type == SVGA3D_SHADERTYPE_PS); 4917ec681f3Smrg return (struct svga_fs_variant *)variant; 4927ec681f3Smrg} 4937ec681f3Smrg 4947ec681f3Smrg 4957ec681f3Smrgstatic inline struct svga_tes_variant * 4967ec681f3Smrgsvga_tes_variant(struct svga_shader_variant *variant) 4977ec681f3Smrg{ 4987ec681f3Smrg assert(!variant || variant->type == SVGA3D_SHADERTYPE_DS); 4997ec681f3Smrg return (struct svga_tes_variant *)variant; 5007ec681f3Smrg} 5017ec681f3Smrg 5027ec681f3Smrg 5037ec681f3Smrgstatic inline struct svga_cs_variant * 5047ec681f3Smrgsvga_cs_variant(struct svga_shader_variant *variant) 5057ec681f3Smrg{ 5067ec681f3Smrg assert(!variant || variant->type == SVGA3D_SHADERTYPE_CS); 5077ec681f3Smrg return (struct svga_cs_variant *)variant; 5087ec681f3Smrg} 5097ec681f3Smrg 5107ec681f3Smrg 5117ec681f3Smrg/* Returns TRUE if we are currently using flat shading. 5127ec681f3Smrg */ 5137ec681f3Smrgstatic inline boolean 5147ec681f3Smrgsvga_is_using_flat_shading(const struct svga_context *svga) 5157ec681f3Smrg{ 5167ec681f3Smrg return 5177ec681f3Smrg svga->state.hw_draw.fs ? 5187ec681f3Smrg svga_fs_variant(svga->state.hw_draw.fs)->uses_flat_interp : FALSE; 5197ec681f3Smrg} 5207ec681f3Smrg 5217ec681f3Smrg 522af69d88dSmrg#endif /* SVGA_SHADER_H */ 523