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 int semantic_name; 58 int semantic_index; 59 int interpolate; 60 unsigned location; 61 }; 62 63 struct vrend_array { 64 int first; 65 int array_size; 66 }; 67 68 struct vrend_layout_info { 69 unsigned name; 70 int sid; 71 int location; 72 int array_id; 73 int usage_mask; 74 }; 75 76 struct vrend_shader_info { 77 uint32_t samplers_used_mask; 78 uint32_t images_used_mask; 79 uint32_t ubo_used_mask; 80 uint32_t ssbo_used_mask; 81 uint32_t num_generic_and_patch_outputs; 82 bool has_pervertex_in; 83 bool guest_sent_io_arrays; 84 struct vrend_layout_info generic_outputs_layout[64]; 85 int num_consts; 86 int num_inputs; 87 int num_interps; 88 int num_outputs; 89 bool ubo_indirect; 90 uint8_t num_indirect_generic_outputs; 91 uint8_t num_indirect_patch_outputs; 92 uint8_t num_indirect_generic_inputs; 93 uint8_t num_indirect_patch_inputs; 94 uint32_t generic_inputs_emitted_mask; 95 int num_ucp; 96 int glsl_ver; 97 bool has_sample_input; 98 uint8_t num_clip_out; 99 uint8_t num_cull_out; 100 uint32_t shadow_samp_mask; 101 int gs_out_prim; 102 int tes_prim; 103 bool tes_point_mode; 104 uint32_t attrib_input_mask; 105 uint32_t fs_blend_equation_advanced; 106 107 struct vrend_array *sampler_arrays; 108 int num_sampler_arrays; 109 110 struct vrend_array *image_arrays; 111 int num_image_arrays; 112 113 struct pipe_stream_output_info so_info; 114 115 struct vrend_interp_info *interpinfo; 116 char **so_names; 117 uint64_t invariant_outputs; 118 }; 119 120 struct vrend_shader_key { 121 bool fs_prim_is_points; 122 uint32_t coord_replace; 123 bool invert_fs_origin; 124 bool pstipple_tex; 125 bool add_alpha_test; 126 bool color_two_side; 127 uint8_t alpha_test; 128 uint8_t clip_plane_enable; 129 bool gs_present; 130 bool tcs_present; 131 bool tes_present; 132 bool flatshade; 133 bool guest_sent_io_arrays; 134 bool fs_logicop_enabled; 135 bool fs_logicop_emulate_coherent; 136 enum pipe_logicop fs_logicop_func; 137 uint8_t surface_component_bits[PIPE_MAX_COLOR_BUFS]; 138 139 uint32_t num_prev_generic_and_patch_outputs; 140 struct vrend_layout_info prev_stage_generic_and_patch_outputs_layout[64]; 141 142 uint8_t prev_stage_num_clip_out; 143 uint8_t prev_stage_num_cull_out; 144 bool next_stage_pervertex_in; 145 uint32_t cbufs_are_a8_bitmask; 146 uint32_t cbufs_signed_int_bitmask; 147 uint32_t cbufs_unsigned_int_bitmask; 148 uint32_t attrib_signed_int_bitmask; 149 uint32_t attrib_unsigned_int_bitmask; 150 uint8_t num_indirect_generic_outputs; 151 uint8_t num_indirect_patch_outputs; 152 uint8_t num_indirect_generic_inputs; 153 uint8_t num_indirect_patch_inputs; 154 uint32_t generic_outputs_expected_mask; 155 uint8_t fs_swizzle_output_rgb_to_bgr; 156 uint64_t force_invariant_inputs; 157 158 uint32_t compiled_fs_uid; 159 struct vrend_shader_info *fs_info; 160 }; 161 162 struct vrend_shader_cfg { 163 int glsl_version; 164 int max_draw_buffers; 165 bool use_gles; 166 bool use_core_profile; 167 bool use_explicit_locations; 168 bool has_arrays_of_arrays; 169 bool has_gpu_shader5; 170 bool has_es31_compat; 171 bool has_conservative_depth; 172 bool use_integer; 173 bool has_dual_src_blend; 174 }; 175 176 struct vrend_context; 177 178 #define SHADER_MAX_STRINGS 3 179 #define SHADER_STRING_VER_EXT 0 180 #define SHADER_STRING_HDR 1 181 182 bool vrend_convert_shader(const struct vrend_context *rctx, 183 const struct vrend_shader_cfg *cfg, 184 const struct tgsi_token *tokens, 185 uint32_t req_local_mem, 186 const struct vrend_shader_key *key, 187 struct vrend_shader_info *sinfo, 188 struct vrend_strarray *shader); 189 190 const char *vrend_shader_samplertypeconv(bool use_gles, int sampler_type); 191 192 char vrend_shader_samplerreturnconv(enum tgsi_return_type type); 193 194 int vrend_shader_lookup_sampler_array(const struct vrend_shader_info *sinfo, int index); 195 196 bool vrend_shader_create_passthrough_tcs(const struct vrend_context *ctx, 197 const struct vrend_shader_cfg *cfg, 198 const struct tgsi_token *vs_info, 199 const struct vrend_shader_key *key, 200 const float tess_factors[6], 201 struct vrend_shader_info *sinfo, 202 struct vrend_strarray *shader, 203 int vertices_per_patch); 204 205 bool vrend_shader_needs_alpha_func(const struct vrend_shader_key *key); 206 207 #endif 208