1 /************************************************************************** 2 * 3 * Copyright (C) 2014 Red Hat Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included 13 * in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 **************************************************************************/ 24 25 #ifndef VREND_SHADER_H 26 #define VREND_SHADER_H 27 28 #include "pipe/p_state.h" 29 #include "pipe/p_shader_tokens.h" 30 31 #include "vrend_strbuf.h" 32 33 enum gl_advanced_blend_mode 34 { 35 BLEND_NONE = 0, 36 BLEND_MULTIPLY, 37 BLEND_SCREEN, 38 BLEND_OVERLAY, 39 BLEND_DARKEN, 40 BLEND_LIGHTEN, 41 BLEND_COLORDODGE, 42 BLEND_COLORBURN, 43 BLEND_HARDLIGHT, 44 BLEND_SOFTLIGHT, 45 BLEND_DIFFERENCE, 46 BLEND_EXCLUSION, 47 BLEND_HSL_HUE, 48 BLEND_HSL_SATURATION, 49 BLEND_HSL_COLOR, 50 BLEND_HSL_LUMINOSITY, 51 BLEND_ALL 52 }; 53 54 55 /* need to store patching info for interpolation */ 56 struct vrend_interp_info { 57 unsigned semantic_name : 6; 58 unsigned semantic_index : 16; 59 unsigned interpolate : 3; 60 unsigned location : 3; 61 }; 62 63 struct vrend_array { 64 int first; 65 int array_size; 66 }; 67 68 struct vrend_layout_info { 69 unsigned name : 6; 70 unsigned sid : 16 ; 71 unsigned location : 16 ; 72 unsigned array_id : 16 ; 73 unsigned usage_mask : 5; 74 }; 75 76 struct vrend_fs_shader_info { 77 int num_interps; 78 int glsl_ver; 79 bool has_sample_input; 80 struct vrend_interp_info interpinfo[PIPE_MAX_SHADER_INPUTS]; 81 }; 82 83 struct vrend_shader_info_out { 84 uint64_t num_indirect_generic : 8; 85 uint64_t num_indirect_patch : 8; 86 uint64_t num_generic_and_patch : 8; 87 uint64_t guest_sent_io_arrays : 1; 88 }; 89 90 struct vrend_shader_info_in { 91 uint64_t generic_emitted_mask; 92 uint32_t num_indirect_generic : 8; 93 uint32_t num_indirect_patch : 8; 94 uint32_t use_pervertex : 1; 95 }; 96 97 98 struct vrend_shader_info { 99 uint64_t invariant_outputs; 100 struct vrend_shader_info_out out; 101 struct vrend_shader_info_in in; 102 103 struct vrend_layout_info generic_outputs_layout[64]; 104 struct vrend_array *sampler_arrays; 105 struct vrend_array *image_arrays; 106 char **so_names; 107 struct pipe_stream_output_info so_info; 108 109 uint32_t samplers_used_mask; 110 uint32_t images_used_mask; 111 uint32_t ubo_used_mask; 112 uint32_t ssbo_used_mask; 113 uint32_t shadow_samp_mask; 114 uint32_t attrib_input_mask; 115 uint32_t fs_blend_equation_advanced; 116 uint32_t fog_input_mask; 117 uint32_t fog_output_mask; 118 119 int num_consts; 120 int num_inputs; 121 int num_outputs; 122 int gs_out_prim; 123 int tes_prim; 124 int num_sampler_arrays; 125 int num_image_arrays; 126 127 uint8_t ubo_indirect : 1; 128 uint8_t tes_point_mode : 1; 129 uint8_t gles_use_tex_query_level : 1; 130 }; 131 132 struct vrend_variable_shader_info { 133 struct vrend_fs_shader_info fs_info; 134 int num_ucp; 135 int num_clip; 136 int num_cull; 137 }; 138 139 struct vrend_shader_key { 140 uint64_t force_invariant_inputs; 141 142 struct vrend_fs_shader_info *fs_info; 143 struct vrend_shader_info_out input; 144 struct vrend_shader_info_in output; 145 struct vrend_layout_info prev_stage_generic_and_patch_outputs_layout[64]; 146 147 union { 148 struct { 149 uint8_t surface_component_bits[PIPE_MAX_COLOR_BUFS]; 150 uint32_t coord_replace; 151 uint8_t swizzle_output_rgb_to_bgr; 152 uint8_t convert_linear_to_srgb_on_write; 153 uint8_t cbufs_are_a8_bitmask; 154 uint8_t cbufs_signed_int_bitmask; 155 uint8_t cbufs_unsigned_int_bitmask; 156 uint32_t logicop_func : 4; 157 uint32_t logicop_enabled : 1; 158 uint32_t prim_is_points : 1; 159 uint32_t invert_origin : 1; 160 } fs; 161 162 struct { 163 uint32_t attrib_signed_int_bitmask; 164 uint32_t attrib_unsigned_int_bitmask; 165 uint32_t fog_fixup_mask; 166 } vs; 167 }; 168 169 uint32_t compiled_fs_uid; 170 171 uint8_t alpha_test; 172 uint8_t clip_plane_enable; 173 uint8_t num_cull : 4; 174 uint8_t num_clip : 4; 175 uint8_t pstipple_tex : 1; 176 uint8_t add_alpha_test : 1; 177 uint8_t color_two_side : 1; 178 uint8_t gs_present : 1; 179 uint8_t tcs_present : 1; 180 uint8_t tes_present : 1; 181 uint8_t flatshade : 1; 182 183 }; 184 185 struct vrend_shader_cfg { 186 uint32_t glsl_version : 12; 187 uint32_t max_draw_buffers : 4; 188 uint32_t use_gles : 1; 189 uint32_t use_core_profile : 1; 190 uint32_t use_explicit_locations : 1; 191 uint32_t has_arrays_of_arrays : 1; 192 uint32_t has_gpu_shader5 : 1; 193 uint32_t has_es31_compat : 1; 194 uint32_t has_conservative_depth : 1; 195 uint32_t use_integer : 1; 196 uint32_t has_dual_src_blend : 1; 197 uint32_t has_fbfetch_coherent : 1; 198 }; 199 200 struct vrend_context; 201 202 #define SHADER_MAX_STRINGS 3 203 #define SHADER_STRING_VER_EXT 0 204 #define SHADER_STRING_HDR 1 205 206 bool vrend_convert_shader(const struct vrend_context *rctx, 207 const struct vrend_shader_cfg *cfg, 208 const struct tgsi_token *tokens, 209 uint32_t req_local_mem, 210 const struct vrend_shader_key *key, 211 struct vrend_shader_info *sinfo, 212 struct vrend_variable_shader_info *var_sinfo, 213 struct vrend_strarray *shader); 214 215 const char *vrend_shader_samplertypeconv(bool use_gles, int sampler_type); 216 217 char vrend_shader_samplerreturnconv(enum tgsi_return_type type); 218 219 int vrend_shader_lookup_sampler_array(const struct vrend_shader_info *sinfo, int index); 220 221 bool vrend_shader_create_passthrough_tcs(const struct vrend_context *ctx, 222 const struct vrend_shader_cfg *cfg, 223 const struct tgsi_token *vs_info, 224 const struct vrend_shader_key *key, 225 const float tess_factors[6], 226 struct vrend_shader_info *sinfo, 227 struct vrend_strarray *shader, 228 int vertices_per_patch); 229 230 bool vrend_shader_needs_alpha_func(const struct vrend_shader_key *key); 231 232 #endif 233