1 /********************************************************** 2 * Copyright 2008-2009 VMware, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 **********************************************************/ 25 26 #ifndef SVGA_TGSI_H 27 #define SVGA_TGSI_H 28 29 #include "pipe/p_state.h" 30 31 #include "svga_hw_reg.h" 32 33 34 /** 35 * We use a 32-bit mask to keep track of the generic indexes. 36 */ 37 #define MAX_GENERIC_VARYING 32 38 39 40 struct svga_fragment_shader; 41 struct svga_vertex_shader; 42 struct svga_shader; 43 struct tgsi_shader_info; 44 struct tgsi_token; 45 46 47 struct svga_vs_compile_key 48 { 49 unsigned fs_generic_inputs; 50 unsigned need_prescale:1; 51 unsigned allow_psiz:1; 52 }; 53 54 struct svga_fs_compile_key 55 { 56 unsigned light_twoside:1; 57 unsigned front_ccw:1; 58 unsigned white_fragments:1; 59 unsigned num_textures:8; 60 unsigned num_unnormalized_coords:8; 61 unsigned sprite_origin_lower_left:1; 62 struct { 63 unsigned compare_mode:1; 64 unsigned compare_func:3; 65 unsigned unnormalized:1; 66 unsigned width_height_idx:7; 67 unsigned texture_target:8; 68 unsigned sprite_texgen:1; 69 unsigned swizzle_r:3; 70 unsigned swizzle_g:3; 71 unsigned swizzle_b:3; 72 unsigned swizzle_a:3; 73 } tex[PIPE_MAX_SAMPLERS]; 74 }; 75 76 struct svga_compile_key { 77 struct svga_vs_compile_key vkey; 78 struct svga_fs_compile_key fkey; 79 int8_t generic_remap_table[MAX_GENERIC_VARYING]; 80 }; 81 82 83 /** 84 * A single TGSI shader may be compiled into different variants of 85 * SVGA3D shaders depending on the compile key. Each user shader 86 * will have a linked list of these results. 87 */ 88 struct svga_shader_result 89 { 90 const struct svga_shader *shader; 91 92 /* Parameters used to generate this compilation result: 93 */ 94 struct svga_compile_key key; 95 96 /* Compiled shader tokens: 97 */ 98 const unsigned *tokens; 99 unsigned nr_tokens; 100 101 /** Per-context shader identifier used with SVGA_3D_CMD_SHADER_DEFINE, 102 * SVGA_3D_CMD_SET_SHADER and SVGA_3D_CMD_SHADER_DESTROY. 103 */ 104 unsigned id; 105 106 /* Next compilation result: 107 */ 108 struct svga_shader_result *next; 109 }; 110 111 112 /* TGSI doesn't provide use with VS input semantics (they're actually 113 * pretty meaningless), so we just generate some plausible ones here. 114 * This is called both from within the TGSI translator and when 115 * building vdecls to ensure they match up. 116 * 117 * The real use of this information is matching vertex elements to 118 * fragment shader inputs in the case where vertex shader is disabled. 119 */ 120 static INLINE void svga_generate_vdecl_semantics( unsigned idx, 121 unsigned *usage, 122 unsigned *usage_index ) 123 { 124 if (idx == 0) { 125 *usage = SVGA3D_DECLUSAGE_POSITION; 126 *usage_index = 0; 127 } 128 else { 129 *usage = SVGA3D_DECLUSAGE_TEXCOORD; 130 *usage_index = idx - 1; 131 } 132 } 133 134 135 136 static INLINE unsigned svga_vs_key_size( const struct svga_vs_compile_key *key ) 137 { 138 return sizeof *key; 139 } 140 141 static INLINE unsigned svga_fs_key_size( const struct svga_fs_compile_key *key ) 142 { 143 return (const char *)&key->tex[key->num_textures] - (const char *)key; 144 } 145 146 struct svga_shader_result * 147 svga_translate_fragment_program( const struct svga_fragment_shader *fs, 148 const struct svga_fs_compile_key *fkey ); 149 150 struct svga_shader_result * 151 svga_translate_vertex_program( const struct svga_vertex_shader *fs, 152 const struct svga_vs_compile_key *vkey ); 153 154 155 void svga_destroy_shader_result( struct svga_shader_result *result ); 156 157 unsigned 158 svga_get_generic_inputs_mask(const struct tgsi_shader_info *info); 159 160 unsigned 161 svga_get_generic_outputs_mask(const struct tgsi_shader_info *info); 162 163 void 164 svga_remap_generics(unsigned generics_mask, 165 int8_t remap_table[MAX_GENERIC_VARYING]); 166 167 int 168 svga_remap_generic_index(int8_t remap_table[MAX_GENERIC_VARYING], 169 int generic_index); 170 171 #endif 172