1 /* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 2012-2013 LunarG, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: 25 * Chia-I Wu <olv (at) lunarg.com> 26 */ 27 28 #ifndef ILO_SHADER_INTERNAL_H 29 #define ILO_SHADER_INTERNAL_H 30 31 #include "core/ilo_state_sbe.h" 32 #include "core/ilo_state_sol.h" 33 34 #include "ilo_common.h" 35 #include "ilo_state.h" 36 #include "ilo_shader.h" 37 38 /* XXX The interface needs to be reworked */ 39 40 /** 41 * A shader variant. It consists of non-orthogonal states of the pipe context 42 * affecting the compilation of a shader. 43 */ 44 struct ilo_shader_variant { 45 union { 46 struct { 47 bool rasterizer_discard; 48 int num_ucps; 49 } vs; 50 51 struct { 52 bool rasterizer_discard; 53 int num_inputs; 54 int semantic_names[PIPE_MAX_SHADER_INPUTS]; 55 int semantic_indices[PIPE_MAX_SHADER_INPUTS]; 56 } gs; 57 58 struct { 59 bool flatshade; 60 int fb_height; 61 int num_cbufs; 62 } fs; 63 } u; 64 65 bool use_pcb; 66 67 int num_sampler_views; 68 struct { 69 unsigned r:3; 70 unsigned g:3; 71 unsigned b:3; 72 unsigned a:3; 73 } sampler_view_swizzles[ILO_MAX_SAMPLER_VIEWS]; 74 75 uint32_t saturate_tex_coords[3]; 76 }; 77 78 struct ilo_kernel_routing { 79 bool initialized; 80 81 bool is_point; 82 bool light_twoside; 83 uint32_t sprite_coord_enable; 84 int sprite_coord_mode; 85 int src_len; 86 int src_semantics[PIPE_MAX_SHADER_OUTPUTS]; 87 int src_indices[PIPE_MAX_SHADER_OUTPUTS]; 88 89 struct ilo_state_sbe sbe; 90 }; 91 92 /** 93 * A compiled shader. 94 */ 95 struct ilo_shader { 96 struct ilo_shader_variant variant; 97 98 union ilo_shader_cso cso; 99 100 struct { 101 int semantic_names[PIPE_MAX_SHADER_INPUTS]; 102 int semantic_indices[PIPE_MAX_SHADER_INPUTS]; 103 int interp[PIPE_MAX_SHADER_INPUTS]; 104 bool centroid[PIPE_MAX_SHADER_INPUTS]; 105 int count; 106 107 int start_grf; 108 bool has_pos; 109 bool has_linear_interp; 110 int barycentric_interpolation_mode; 111 uint32_t const_interp_enable; 112 bool discard_adj; 113 } in; 114 115 struct { 116 int register_indices[PIPE_MAX_SHADER_OUTPUTS]; 117 int semantic_names[PIPE_MAX_SHADER_OUTPUTS]; 118 int semantic_indices[PIPE_MAX_SHADER_OUTPUTS]; 119 int count; 120 121 bool has_pos; 122 } out; 123 124 bool skip_cbuf0_upload; 125 126 bool has_kill; 127 bool dispatch_16; 128 129 bool stream_output; 130 int svbi_post_inc; 131 132 uint32_t sol_data[PIPE_MAX_SO_OUTPUTS][2]; 133 struct ilo_state_sol sol; 134 135 /* for VS stream output / rasterizer discard */ 136 int gs_offsets[3]; 137 int gs_start_grf; 138 int gs_bt_so_count; 139 140 void *kernel; 141 int kernel_size; 142 int per_thread_scratch_size; 143 144 struct ilo_kernel_routing routing; 145 struct ilo_state_ps_params_info ps_params; 146 147 /* what does the push constant buffer consist of? */ 148 struct { 149 int cbuf0_size; 150 int clip_state_size; 151 } pcb; 152 153 /* binding table */ 154 struct { 155 int rt_base, rt_count; 156 int tex_base, tex_count; 157 int const_base, const_count; 158 int res_base, res_count; 159 160 int gen6_so_base, gen6_so_count; 161 162 int global_base, global_count; 163 164 int total_count; 165 } bt; 166 167 struct list_head list; 168 169 /* managed by shader cache */ 170 bool uploaded; 171 uint32_t cache_offset; 172 }; 173 174 /** 175 * Information about a shader state. 176 */ 177 struct ilo_shader_info { 178 const struct ilo_dev *dev; 179 int type; 180 181 const struct tgsi_token *tokens; 182 183 struct pipe_stream_output_info stream_output; 184 struct { 185 unsigned req_local_mem; 186 unsigned req_private_mem; 187 unsigned req_input_mem; 188 } compute; 189 190 uint32_t non_orthogonal_states; 191 192 bool has_color_interp; 193 bool has_pos; 194 bool has_vertexid; 195 bool has_instanceid; 196 bool fs_color0_writes_all_cbufs; 197 198 int edgeflag_in; 199 int edgeflag_out; 200 201 uint32_t shadow_samplers; 202 int num_samplers; 203 204 int constant_buffer_count; 205 }; 206 207 /** 208 * A shader state. 209 */ 210 struct ilo_shader_state { 211 struct ilo_shader_info info; 212 213 struct list_head variants; 214 int num_variants, total_size; 215 216 struct ilo_shader *shader; 217 218 /* managed by shader cache */ 219 struct ilo_shader_cache *cache; 220 struct list_head list; 221 }; 222 223 void 224 ilo_shader_variant_init(struct ilo_shader_variant *variant, 225 const struct ilo_shader_info *info, 226 const struct ilo_state_vector *vec); 227 228 bool 229 ilo_shader_state_use_variant(struct ilo_shader_state *state, 230 const struct ilo_shader_variant *variant); 231 232 struct ilo_shader * 233 ilo_shader_compile_vs(const struct ilo_shader_state *state, 234 const struct ilo_shader_variant *variant); 235 236 struct ilo_shader * 237 ilo_shader_compile_gs(const struct ilo_shader_state *state, 238 const struct ilo_shader_variant *variant); 239 240 bool 241 ilo_shader_compile_gs_passthrough(const struct ilo_shader_state *vs_state, 242 const struct ilo_shader_variant *vs_variant, 243 const int *so_mapping, 244 struct ilo_shader *vs); 245 246 struct ilo_shader * 247 ilo_shader_compile_fs(const struct ilo_shader_state *state, 248 const struct ilo_shader_variant *variant); 249 250 struct ilo_shader * 251 ilo_shader_compile_cs(const struct ilo_shader_state *state, 252 const struct ilo_shader_variant *variant); 253 254 static inline void 255 ilo_shader_destroy_kernel(struct ilo_shader *sh) 256 { 257 FREE(sh->kernel); 258 FREE(sh); 259 } 260 261 #endif /* ILO_SHADER_INTERNAL_H */ 262